public void itemStateChanged(ItemEvent e) { Object source = e.getItemSelectable(); if (source == branchOverloadMonitorCheckbox) { if (e.getStateChange() == ItemEvent.SELECTED) overloadMonitorParams.setStatus(true); else overloadMonitorParams.setStatus(false); } }
private void initializeDisplay() { myself = this; overloadMonitorParams = new BranchOverloadMonitorParameters(true, 50); setLayout(new BorderLayout()); setBackground(Color.WHITE); setupPowerSystem(); ps.saveState(); add(circuitpanel, BorderLayout.CENTER); JPanel mainFrameControlPanel = new JPanel(); mainFrameControlPanel.setLayout(new FlowLayout()); mainFrameControlPanel.setBackground(Color.WHITE); branchOverloadMonitorCheckbox = new JCheckBox("Monitor branch overloads"); branchOverloadMonitorCheckbox.setSelected(overloadMonitorParams.getStatus()); branchOverloadMonitorCheckbox.addItemListener(this); branchOverloadMonitorCheckbox.setBackground(Color.WHITE); mainFrameControlPanel.add(branchOverloadMonitorCheckbox, BorderLayout.WEST); // Set up simulation start/stop/reset buttons on SimControlPanel SimControlPanel = new JPanel(); StartSim = new JButton("Start Time"); StartSim.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { totalloadplot.startIntegration(); StartSim.setEnabled(false); StopSim.setEnabled(true); tlabel.setPaused(false); loadCommercial.setPaused(false); loadIndustrial.setPaused(false); loadResidential.setPaused(false); } }); StopSim = new JButton("Pause Time"); StopSim.setEnabled(false); StopSim.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { totalloadplot.stopIntegration(); StartSim.setEnabled(true); StopSim.setEnabled(false); tlabel.setPaused(true); loadCommercial.setPaused(true); loadIndustrial.setPaused(true); loadResidential.setPaused(true); } }); ResetSim = new JButton("Reset Time"); ResetSim.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { totalloadplot.resettime(); tlabel.resettime(); loadCommercial.resettime(); loadResidential.resettime(); loadIndustrial.resettime(); if (totalloadplot.getIntegrationStatus() == totalloadplot.STOPPED) StartSim.setEnabled(true); } }); SimControlPanel.setLayout(new FlowLayout()); SimControlPanel.add(StartSim); SimControlPanel.add(StopSim); SimControlPanel.add(ResetSim); SimControlPanel.setBackground(Color.WHITE); totalloadplotContainer = new AnimatedPanel(725, 310, period, 16, true); controlAndPlotFrame = new JFrame("Plot and time controls"); controlAndPlotFrame.getContentPane().setBackground(Color.WHITE); controlAndPlotFrame.setSize(725, 310); controlAndPlotFrame.setLayout(new BorderLayout()); controlAndPlotFrame.setBackground(Color.WHITE); controlAndPlotFrame.setResizable(false); totalloadplotContainer.getTopLayerRenderables().add(totalloadplot); totalloadplotContainer.getAnimatables().add(totalloadplot); totalloadplotContainer.startGame(); controlAndPlotFrame.add(totalloadplotContainer, BorderLayout.CENTER); controlAndPlotFrame.add(SimControlPanel, BorderLayout.SOUTH); controlAndPlotFrame.setVisible(false); ShowPlotWindow = new JButton("Open Plot and Time Controls Window"); ShowPlotWindow.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controlAndPlotFrame.setVisible(true); } }); mainFrameControlPanel.add(ShowPlotWindow, BorderLayout.EAST); ResetState = new JButton("Reset Simulation"); ResetState.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { totalloadplot.stopIntegration(); StartSim.setEnabled(true); StopSim.setEnabled(false); loadCommercial.setPaused(true); loadIndustrial.setPaused(true); loadResidential.setPaused(true); ps.restoreState(); totalloadplot.resettime(); tlabel.resettime(); loadCommercial.resettime(); loadResidential.resettime(); loadIndustrial.resettime(); } }); mainFrameControlPanel.add(ResetState, BorderLayout.CENTER); JButton AttackButton = new JButton("Cyber-Attack!"); AttackButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // HashMap<CyberAttack,SwitchDisplayWithDistanceInfo> cyberAttackToSwitchMap int arrayIdx = (int) (Math.floor(Math.random() * (attackableSwitches.size() - 1e-10))); CyberAttack newattack; try { SwitchDisplayWithDistanceInfo attackSwitch = attackableSwitches.get(arrayIdx); double halfSwitchLength = attackSwitch.getLength() / 2; Point2D.Double toPoint = DrawUtilities.getPointAtDistanceOnLine(attackSwitch, halfSwitchLength); newattack = new CyberAttack(new Point2D.Double(736, 59), toPoint, 50); cyberAttackToSwitchMap.put(newattack, attackSwitch); newattack.addActionListener(myself); circuitpanel.getTopLayerRenderables().add(newattack); circuitpanel.getAnimatables().add(newattack); cyberattacks.add(newattack); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); mainFrameControlPanel.add(AttackButton, BorderLayout.EAST); add(mainFrameControlPanel, BorderLayout.SOUTH); // start with it stopped totalloadplot.stopIntegration(); StartSim.setEnabled(true); StopSim.setEnabled(false); tlabel.setPaused(true); loadCommercial.setPaused(true); loadIndustrial.setPaused(true); loadResidential.setPaused(true); }