From: <mar...@us...> - 2008-02-08 03:25:17
|
Revision: 91 http://gridsim.svn.sourceforge.net/gridsim/?rev=91&view=rev Author: marcos_dias Date: 2008-02-07 19:25:23 -0800 (Thu, 07 Feb 2008) Log Message: ----------- This update allows the user to pause the simulation at a given simulation time. If the user sets the simulation to run until 50000 seconds and clicks the run button, the simulation will run continuously until 50000 and stop at the first even whose time is >= to 50000. Modified Paths: -------------- branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java Modified: branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java =================================================================== --- branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java 2008-02-08 01:57:22 UTC (rev 90) +++ branches/gridsim4.0-branch3/source/eduni/simjava/Sim_system.java 2008-02-08 03:25:23 UTC (rev 91) @@ -77,6 +77,7 @@ // ADDED BY MARCOS - 2007-09-07 private static boolean paused = false; + private static double pauseAt = Double.MAX_VALUE; private static Object syncObj = new Object(); /** @@ -534,7 +535,12 @@ // ADDED BY MARCOS TO ALLOW THE // SIMULATION TO BE PAUSED + synchronized(syncObj){ + + if(clock >= pauseAt) + paused = true; + while(paused){ try { syncObj.wait(); @@ -710,6 +716,23 @@ return paused; } } + + /** + * This method is called if one wants to pause the simulation + * at a given time + * @time the time at which the simulation has to be paused + * @return <tt>true</tt>if the simulation has been paused + * or <tt>false</tt> otherwise. + */ + public static synchronized boolean pauseSimulation(double time) { + synchronized(syncObj){ + if(time <= clock) + return false; + else + pauseAt = time; + } + return true; + } /** * This method is called if one wants to resume the simulation @@ -720,6 +743,10 @@ public static synchronized boolean resumeSimulation() { synchronized(syncObj){ paused = false; + + if(pauseAt <= clock) + pauseAt = Double.MAX_VALUE; + syncObj.notify(); return !paused; } Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-02-08 01:57:22 UTC (rev 90) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-02-08 03:25:23 UTC (rev 91) @@ -825,6 +825,17 @@ } /** + * Pauses the simulation at a given simulation time. This method + * should be used for debugging purposes only + * @param time the time when the simulation should be paused + * @return <tt>true</tt> if the simulation can be paused or + * <tt>false</tt> otherwise. + */ + public static boolean pauseSimulation(double time){ + return Sim_system.pauseSimulation(time); + } + + /** * Resumes the simulation. This method should be used for * debugging purposes only * @return <tt>true</tt> if the simulation has been resumed or Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-08 01:57:22 UTC (rev 90) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-08 03:25:23 UTC (rev 91) @@ -26,13 +26,16 @@ import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; +import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.JTextField; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; @@ -64,12 +67,16 @@ GridSimVisualizer { private static final long serialVersionUID = 2059324063853260682L; - public static final int WINDOW_WIDTH = 400; + public static final int WINDOW_WIDTH = 450; public static final int WINDOW_HEIGHT = 350; private JButton btStep_; private JButton btRun_; private JButton btSlowMotion_; + + private JButton btChangePause_; + private JTextField tfRunUntil_; + private JList jlResource_; private JTextArea jlResourceInfo_; @@ -121,17 +128,16 @@ super.setTitle("GridSim Turbo Alpha 0.1 Visualizer"); JPanel mainPanel = new JPanel(new GridLayout(0, 1)); -// JPanel simulationPanel = new JPanel(new GridLayout(0, 3)); - JPanel simulationPanel = new JPanel(new GridLayout(0, 2)); + JPanel simulationPanel = new JPanel(new GridLayout(0, 3)); Border simulationBorder = BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(EtchedBorder.RAISED), "Simulation"); simulationPanel.setBorder(simulationBorder); - - JPanel executionPanel = new JPanel(new GridLayout(3,0)); + + JPanel executionPanel = new JPanel(new GridLayout(3,1)); executionPanel.setBorder(new TitledBorder("Execution")); - JPanel pausePanel = new JPanel(new GridLayout(3,0)); + JPanel pausePanel = new JPanel(new GridLayout(3,1)); pausePanel.setBorder(new TitledBorder("Pause Condition")); btStep_ = new JButton("Step by Step"); @@ -142,10 +148,21 @@ btRun_.addActionListener(this); btSlowMotion_.addActionListener(this); + JLabel lbRunUntil = new JLabel(" Pause at (Seconds):"); + lbRunUntil.setAlignmentY(JTextField.CENTER_ALIGNMENT); + + tfRunUntil_ = new JTextField(10); + btChangePause_ = new JButton("Change"); executionPanel.add(btStep_); + + pausePanel.add(lbRunUntil); + pausePanel.add(tfRunUntil_); + pausePanel.add(btChangePause_); + + btChangePause_.addActionListener(this); + executionPanel.add(btSlowMotion_); executionPanel.add(btRun_); - executionPanel.add(btSlowMotion_); - + ArrayList<String> resourceNames = new ArrayList<String>(); for(GridResource resource : resources_) { resourceNames.add(resource.get_name()); @@ -162,7 +179,7 @@ resourcePanel.add(scrollResourcePanel); simulationPanel.add(executionPanel); -// simulationPanel.add(pausePanel); + simulationPanel.add(pausePanel); simulationPanel.add(resourcePanel); jlResourceInfo_ = new JTextArea(); @@ -234,7 +251,30 @@ public void actionPerformed(ActionEvent e){ String cmd = e.getActionCommand(); - if(e.getSource() == btStep_){ + if(e.getSource() == btChangePause_) { + double newPause; + boolean success = true; + try { + newPause = Double.parseDouble(tfRunUntil_.getText()); + if(newPause >= GridSim.clock()) + GridSim.pauseSimulation(newPause); + else + success = false; + } + catch (NumberFormatException nfe) { + success = false; + } + if(!success) { + String message = "The value informed to pause the simulation " + + "is invalid.\nThe current simulation time is " + GridSim.clock() + "."; + + JOptionPane.showMessageDialog(this, message, + "Error While Setting the Time", + JOptionPane.ERROR_MESSAGE); + + } + } + else if(e.getSource() == btStep_){ GridSim.enableStepByStepMode(); GridSim.disableSlowMotionMode(); Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-08 01:57:22 UTC (rev 90) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-08 03:25:23 UTC (rev 91) @@ -109,6 +109,7 @@ private JRadioButtonMenuItem btHour_; private boolean drawID_ = true; private boolean autoScroll_ = true; + private boolean animate_ = true; private JButton btSetSdWindowSize_; private JTextField fdSdWindowSize_; @@ -329,7 +330,7 @@ sliderX_ = new JSlider(10, 100, 10); sliderY_ = new JSlider(10, 100, 10); - ChangeListener graphResizer = new ChangeListener(){ + ChangeListener graphResizer = new ChangeListener() { synchronized public void stateChanged(ChangeEvent e) { pnGraph_.repaint(); } @@ -453,13 +454,33 @@ updateResourceWindow(); } }); - + menuCommand.add(mnScroll); + + JMenu mnAnimation = new JMenu("Animation"); + JCheckBoxMenuItem miAnimation = new JCheckBoxMenuItem("Animate this Window"); + miAnimation.setSelected(true); + mnAnimation.add(miAnimation); + + miAnimation.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent e){ + if (e.getStateChange() == ItemEvent.DESELECTED){ + animate_ = false; + } + else if (e.getStateChange() == ItemEvent.SELECTED){ + animate_ = true; + } + updateResourceWindow(); + } + }); + + menuCommand.add(mnAnimation); + menuBar.add(menuCommand); setJMenuBar(menuBar); } - private void updateResourceWindow(){ + private void updateResourceWindow() { pnGraph_.repaint(); if(slidingWindowSize_ != Double.MAX_VALUE) { @@ -555,6 +576,9 @@ } protected synchronized void paintComponent(Graphics g2) { + if(!animate_) + return; + super.paintComponent(g2); Graphics2D g2D = (Graphics2D)g2; g2D.setFont(graphFont_); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java 2008-02-08 01:57:22 UTC (rev 90) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARMessage.java 2008-02-08 03:25:23 UTC (rev 91) @@ -21,7 +21,6 @@ */ public class ARMessage { - private int srcId_; // id of the entity that sent the message private int dstId_; // id of the entity that will receive the message private int msgId_; // a unique id for the message This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |