package org.infosec.ismp.applet.manager.component.panel.reflash; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.List; import javax.swing.SwingUtilities; import javax.swing.Timer; import org.infosec.ismp.applet.manager.application.dynamicInfo.DynamicInfo; import org.infosec.ismp.applet.manager.component.panel.info.cpu.CPUPanel; import org.infosec.ismp.applet.manager.component.panel.info.file.FileElement; import org.infosec.ismp.applet.manager.component.panel.info.file.FilePanel; import org.infosec.ismp.applet.manager.component.panel.info.memory.MemoryPanel; import org.infosec.ismp.applet.manager.component.panel.info.netport.NetPort; import org.infosec.ismp.applet.manager.component.panel.info.netport.NetPortScrollPanel; import org.infosec.ismp.applet.manager.component.panel.info.waitqueue.WaitQueuePanel; import org.infosec.ismp.applet.manager.component.panel.progress.ProcessPanel; import org.infosec.ismp.applet.manager.component.panel.view.asset.AssetDevicePanel; import org.infosec.ismp.applet.manager.component.panel.view.infoview.CPUViewPanel; import org.infosec.ismp.applet.manager.component.panel.view.infoview.DiskViewPanel; import org.infosec.ismp.applet.manager.component.panel.view.infoview.MemoryViewPanel; import org.infosec.ismp.applet.manager.component.panel.view.network.NetworkStatusPanel; import org.infosec.ismp.applet.manager.model.NodeModel; import org.infosec.ismp.applet.manager.utilities.NullFilter; import org.infosec.ismp.manager.rmi.snmp.model.host.NetworkStatus; import twaver.Element; import twaver.TDataBox; /** * 刷新界面数据 * * @author 肖高峰 * */ public class HostRefreshPanelUI { private NullFilter data; /** * 构造一个带数据源的面板刷新定时器 * @param data */ public HostRefreshPanelUI(NullFilter data) { if (data == null) { } else { this.data = data; } } public void refreshIsActive(final NodeModel node, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { if(data.isHostActive()) { node.setImage(node.activeBigICO()); node.setIcon(node.activeSmallICO()); } else { node.setImage(""); node.setIcon(""); } } catch (Exception e) { System.out.println("设备基本信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新Device 基本信息 public void refreshDevice(final org.infosec.ismp.applet.manager.component.panel.view.device.DeviceInfoPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.setDeviceInfo(data.getDeviceInfo()); } catch (Exception e) { System.out.println("设备基本信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } //资产信息 public void refreshAsset(final AssetDevicePanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.setAssetDevice(data.getAssetDevice()); } catch (Exception e) { System.out.println("资产基本信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } int networkLength = 0; List<NetworkStatus> networksTemp = null; // 刷新 接口基本信息 public void refreshNetwork(final NetworkStatusPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { List<org.infosec.ismp.applet.manager.component.panel.view.network.NetworkStatus> networks = data.getHostNetworkStatusAll(); if(networks == null || networks.size() == 0) { return; } panel.clearStatusList(); panel.setStatusList(networks); } catch (Exception e) { System.out.println("主机网络接口中间信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新详细信息 硬盘底图形 public void refreshHardDisk(final DiskViewPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.setDiskCount(data.getHostHardDiskSize()); panel.setUsedDisk(data.getHostHardDiskUsed()); } catch (Exception e) { System.out.println("主机硬盘底部信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新详细信息 内存底图形 public void refreshMemory(final MemoryViewPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.setMemoryCount(data.getHostMemorySize()); panel.setUsedMemeory(data.getHostMemoryUsed()); } catch (Exception e) { System.out.println("主机内存底部信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新详细信息 CPU底图形 public void refreshCPU(final CPUViewPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.getDataBox().clear(); panel.getDataBox().addElements(data.getHostCPUs()); } catch (Exception e) { System.out.println("主机CPU底部信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } int cpusLength = 0; List<Element> cpus = null; // 刷新动态面板CPU public void refreshMidCPUs(final CPUPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { List<Element> elements = data.getHostCPUs(); if(elements == null || elements.size() == 0) { return; } //如果CPU的块数不一样 if(cpusLength != elements.size()) { panel.clearCpuList(); panel.setCpuList(elements); cpusLength = elements.size(); cpus = elements; } //设置值 for(int i = 0; i < elements.size(); i++) { panel.setValue(cpus.get(i), elements.get(i).getChartValue()); } } catch (Exception e) { System.out.println("主机CPU中间信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新动态面板内存。 public void refreshMidMemory(final MemoryPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.setValue((data.getHostMemoryUsed()/data.getHostMemorySize())*100); } catch (Exception e) { System.out.println("主机内存中间信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新动态面板硬盘 public void refreshMidHardDisk(final FilePanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.clearFiles(); for(FileElement f : data.getHostFileElements()) { panel.addFile(f); } } catch (Exception e) { System.out.println("主机硬盘中间信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新动态面板网接口 public void refreshMidNetwork(final NetPortScrollPanel panel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { panel.clearPortList(); for(org.infosec.ismp.applet.manager.component.panel.view.network.NetworkStatus e : data.getHostNetworkStatusAll()) { NetPort port1 = new NetPort(); port1.setName(e.getDescription()); port1.setSendSpeed(e.getOutBytes()); port1.setReceiveSpeed(e.getInBytes()); panel.addNetPort(port1); } } catch (Exception e) { System.out.println("主机网络接口中间信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } // 刷新进程 public void refreshProcess(final ProcessPanel panel,final WaitQueuePanel processPanel, int frequency) { Timer timer = new Timer(frequency, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("unchecked") public void run() { try { List<org.infosec.ismp.applet.manager.component.panel.progress.Process> pro =data.getHostProcessAll(); if(pro == null) return; TDataBox box = panel.getProcessBox(); box.clear(); box.addElements(pro); panel.setBox(box); processPanel.setProcessCount(pro.size()); } catch (Exception e) { System.out.println("主机线程信息刷新发生错误!..."); e.printStackTrace(); } } }); } }); timer.start(); DynamicInfo.addDynameTimer(data.getDevice().getNodeId(), timer); } }