From: <mar...@us...> - 2007-11-07 03:40:37
|
Revision: 78 http://gridsim.svn.sourceforge.net/gridsim/?rev=78&view=rev Author: marcos_dias Date: 2007-11-06 19:40:40 -0800 (Tue, 06 Nov 2007) Log Message: ----------- This update contains a small improvement: + All the resource windows show the same time span, which makes the visualisation and debugging processes easier. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-11-05 01:07:03 UTC (rev 77) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2007-11-07 03:40:40 UTC (rev 78) @@ -99,6 +99,9 @@ private HashMap<String, ResourceWindow> resourceWindows_ = null; private ArrayList<GridResource> resources_ = null; + // the GUISettings object used to store settings of windows + private static GUISettings settings_ = GUISettings.getInstance(); + // a list of all the allocation listeners in the system private static LinkedHashMap<Integer, AllocationListener> listeners_; @@ -317,6 +320,7 @@ * simulation time */ private static void informListenersAboutTime() { + settings_.setTimeSpan(GridSim.clock()); Iterator<AllocationListener> iterListener = listeners_.values().iterator(); while(iterListener.hasNext()) { AllocationListener listener = iterListener.next(); Added: branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/gui/GUISettings.java 2007-11-07 03:40:40 UTC (rev 78) @@ -0,0 +1,57 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.gui; + +/** + * This class stores settings shared by all the windows of the graphical + * user interface. + * + * @author Marcos Dias de Assuncao + */ + +public class GUISettings { + + // the time span used by the windows + private double timeSpan = 200; + private static GUISettings settingsInstance_ = null; + + /** + * Returns the single instance of the {@link GUISettings} + * object, creating it if it has not already been instantiated. + * @return the InterGridParameters instance. + */ + public static synchronized GUISettings getInstance() { + if( settingsInstance_ == null) + settingsInstance_ = new GUISettings(); + + return settingsInstance_; + } + + /** + * Gets the time span for the GUI components + * @return the time span for the GUI components + */ + public double getTimeSpan() { + return timeSpan; + } + + /** + * Sets the time span for the GUI components + * @param timeSpan the time span for the GUI components + * @return <tt>true</tt> if the time span has been updated + * or <tt>false</tt> otherwise. + */ + public boolean setTimeSpan(double timeSpan) { + if(timeSpan > this.timeSpan) { + this.timeSpan = timeSpan; + return true; + } + else + return false; + } +} Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-11-05 01:07:03 UTC (rev 77) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-11-07 03:40:40 UTC (rev 78) @@ -123,7 +123,6 @@ private JScrollPane scroller_; private DrawingPanel drawingPanel_; private long currentTime_; - private double timeSpan_ = 200; // the panel that shows the list of gridlets or advance reservations private ItemPanel itemPanel_; @@ -133,6 +132,9 @@ // time unit used to display information on the screen private int timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; + + // the settings object + private GUISettings settings_; private static final int WINDOW_WIDTH = 1100; private static final int WINDOW_HEIGHT = 300; @@ -148,6 +150,7 @@ public ResourceWindow(GridResource resource, int windowId) { resource_ = resource; numPE_ = resource_.getResourceCharacteristics().getNumPE(); + settings_ = GUISettings.getInstance(); // sets layout to null as the components are resized // by a component adaptor triggered by resizing the window @@ -185,6 +188,7 @@ public boolean allocationActionPerformed(AllocationAction action) { int type = action.getActionType(); LinkedList<ScheduleItem> list = action.getScheduleItems(); + long previousTime = currentTime_; currentTime_ = (long) GridSim.clock(); switch(type){ @@ -200,7 +204,7 @@ for(ScheduleItem item : list){ scheduledItems_.add(item); double finishTime = item.getFinishTime(); - updateTimeSpan(finishTime); + settings_.setTimeSpan(finishTime); itemPanel_.updateItem(item); } updateResourceWindow(); @@ -215,7 +219,7 @@ break; case AllocationAction.SIMULATION_TIME_CHANGED: - if(updateTimeSpan(currentTime_)) + if(currentTime_ > previousTime) updateResourceWindow(); break; @@ -366,18 +370,6 @@ (int)(super.getMaximumSize().height))); } - /** - * Updates the time span, that is, the time frame shown in the window - */ - private boolean updateTimeSpan(double time) { - if(time > timeSpan_) { - timeSpan_ = time; - return true; - } - else - return false; - } - private void updateResourceWindow(){ drawingPanel_.repaint(); } @@ -475,24 +467,27 @@ } protected synchronized void paintComponent(Graphics g2) { + super.paintComponent(g2); Graphics2D g2D = (Graphics2D)g2; g2D.setFont(graphFont_); + + double timeSpan = settings_.getTimeSpan(); panelHeight_ = leftPanel_.getHeight() - 100 - SHIFT_Y - SHIFT_BOTTOM; panelWidth_ = leftPanel_.getWidth() - 50 - 2 * SHIFT_X; scaleY_ = panelHeight_ / (float) numPE_; - scaleX_ = panelWidth_ / (float) (timeSpan_); + scaleX_ = panelWidth_ / (float) (timeSpan); scaleY_ = scaleY_ * sliderY_.getValue() * (float) 0.1; scaleX_ = scaleX_ * sliderX_.getValue() * (float) 0.1; - super.setPreferredSize(new Dimension((int) (timeSpan_ * scaleX_) + 2 * SHIFT_X, + super.setPreferredSize(new Dimension((int) (timeSpan * scaleX_) + 2 * SHIFT_X, (int) ((numPE_) * scaleY_) + SHIFT_Y + SHIFT_BOTTOM)); drawSchedulingQueue(g2D); - drawGridsAndAxes(g2D); + drawGridsAndAxes(timeSpan, g2D); super.revalidate(); } @@ -501,7 +496,7 @@ * @param timeSpan the time span of the simulation * @param g2D the graphics 2D context */ - private void drawGridsAndAxes(Graphics2D g2D) { + private void drawGridsAndAxes(double timeSpan, Graphics2D g2D) { String text = null; g2D.setColor(timeGridColor_); @@ -511,7 +506,7 @@ g2D.setComposite(transpComp_); int heightGph = (int)(numPE_ * scaleY_); - int widthGph = (int) (timeSpan_ * scaleX_); + int widthGph = (int) (timeSpan * scaleX_); int x, y; for(int i=0; i<=widthGph; i+=50) { @@ -542,7 +537,7 @@ g2D.drawString(text, SHIFT_X + (int)(currentTime_ * scaleX_) - (text.length() * 5), SHIFT_Y - 10); - text = "Time Span: " + (int)(convertTime(timeSpan_)); + text = "Time Span: " + (int)(convertTime(timeSpan)); y = SHIFT_Y + (text.length() * 6); x = widthGph + SHIFT_X + 15; g2D.rotate(-1.571, x, y); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-08 01:57:19
|
Revision: 90 http://gridsim.svn.sourceforge.net/gridsim/?rev=90&view=rev Author: marcos_dias Date: 2008-02-07 17:57:22 -0800 (Thu, 07 Feb 2008) Log Message: ----------- Small changes in the GUI. The user can now define the size for the sliding window (i.e. the size of the portion shown by the scheduling graph. In this case, the graph is not automatically adjuested to fit the window. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-07 10:53:15 UTC (rev 89) +++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-08 01:57:22 UTC (rev 90) @@ -121,6 +121,7 @@ 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)); Border simulationBorder = BorderFactory.createTitledBorder( @@ -129,6 +130,9 @@ JPanel executionPanel = new JPanel(new GridLayout(3,0)); executionPanel.setBorder(new TitledBorder("Execution")); + + JPanel pausePanel = new JPanel(new GridLayout(3,0)); + pausePanel.setBorder(new TitledBorder("Pause Condition")); btStep_ = new JButton("Step by Step"); btRun_ = new JButton("Run"); @@ -143,7 +147,7 @@ executionPanel.add(btSlowMotion_); ArrayList<String> resourceNames = new ArrayList<String>(); - for(GridResource resource : resources_){ + for(GridResource resource : resources_) { resourceNames.add(resource.get_name()); } @@ -158,6 +162,7 @@ resourcePanel.add(scrollResourcePanel); simulationPanel.add(executionPanel); +// simulationPanel.add(pausePanel); simulationPanel.add(resourcePanel); jlResourceInfo_ = new JTextArea(); Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-07 10:53:15 UTC (rev 89) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-08 01:57:22 UTC (rev 90) @@ -25,6 +25,7 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridLayout; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -41,15 +42,20 @@ import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; -import javax.swing.JCheckBox; +import javax.swing.JButton; +import javax.swing.JCheckBoxMenuItem; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import javax.swing.JRadioButton; +import javax.swing.JRadioButtonMenuItem; import javax.swing.JScrollPane; import javax.swing.JSlider; import javax.swing.JTextArea; +import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.border.BevelBorder; import javax.swing.border.Border; @@ -98,12 +104,16 @@ // default control options included in the left side of the window private JSlider sliderX_; private JSlider sliderY_; - private JCheckBox cbShowID_; - private JRadioButton btSecond_; - private JRadioButton btMinute_; - private JRadioButton btHour_; + private JRadioButtonMenuItem btSecond_; + private JRadioButtonMenuItem btMinute_; + private JRadioButtonMenuItem btHour_; private boolean drawID_ = true; + private boolean autoScroll_ = true; + private JButton btSetSdWindowSize_; + private JTextField fdSdWindowSize_; + private double slidingWindowSize_ = Double.MAX_VALUE; + // the left panel itself, the scroller for the scheduling queue panel // and the panel where the jobs are drawn private JComponent pnLeft_; @@ -133,7 +143,7 @@ private Color[] colorsARInProgress; private static final int WINDOW_WIDTH = 900; - private static final int WINDOW_HEIGHT = 300; + private static final int WINDOW_HEIGHT = 350; private static final int SHIFT_X = 30; private static final int SHIFT_Y = 25; private static final int SHIFT_BOTTOM = 15; @@ -254,7 +264,32 @@ else if (e.getSource() == btHour_ && btHour_.isSelected()) { timeUnit_ = GridSimVisualizer.TIME_UNIT_HOUR; } + else if(e.getSource() == btSetSdWindowSize_) { + double newSize; boolean success = true; + try { + newSize = Double.parseDouble(fdSdWindowSize_.getText()); + if(newSize >= 60) + slidingWindowSize_ = newSize; + else + success = false; + } + catch (NumberFormatException nfe) { + success = false; + } + if(!success) { + String message = "The value informed for the size of the " + + "sliding window is invalid.\nThe " + + ((slidingWindowSize_ == Double.MAX_VALUE) ? "default" : "current") + + " value will be used instead.\n\n" + + "Note: the minimum size is 60 seconds."; + + JOptionPane.showMessageDialog(this, message, + "Error Setting the Sliding Window Size", + JOptionPane.ERROR_MESSAGE); + } + } + if(scheduledItems_.size() > 0) pnItem_.updatePanel(); @@ -273,7 +308,7 @@ // calculates the size of the two panels // to be added to the window int leftPanelWidth = (int)((super.getWidth()) * PROPORTION_LEFT_PANEL); - int panelsHeight = (int)((super.getHeight()) - 20); + int panelsHeight = (int)((super.getHeight()) - 40); int gridletPanelWidth = (int)((super.getWidth()) * PROPORTION_RIGHT_PANEL) - 10; int leftPanelXPos = 0; int gridletPanelXPos = leftPanelXPos + leftPanelWidth; @@ -289,25 +324,6 @@ instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); instructionPanel.setBorder(raisedetched); - JPanel checkPanel = new JPanel(new GridLayout(1, 1)); - checkPanel.setBorder(new TitledBorder("Gridlet Info")); - - cbShowID_ = new JCheckBox("Show ID "); - cbShowID_.setSelected(true); - checkPanel.add(cbShowID_); - - cbShowID_.addItemListener(new ItemListener(){ - public void itemStateChanged(ItemEvent e){ - if (e.getStateChange() == ItemEvent.DESELECTED){ - drawID_ = false; - } - else if (e.getStateChange() == ItemEvent.SELECTED){ - drawID_ = true; - } - pnGraph_.repaint(); - } - }); - JPanel sliderPanel = new JPanel(new GridLayout(1, 2)); sliderPanel.setBorder(new TitledBorder("Scale X and Y Axes")); sliderX_ = new JSlider(10, 100, 10); @@ -324,35 +340,18 @@ sliderPanel.add(sliderX_); sliderPanel.add(sliderY_); - JPanel timePanel = new JPanel(new GridLayout(1, 3)); - timePanel.setBorder(new TitledBorder("Time unit")); + JPanel pnWindowProp = new JPanel(new GridLayout(1, 2)); + pnWindowProp.setBorder(new TitledBorder("Sliding Window Size (Sec.):")); - btSecond_ = new JRadioButton("Second"); - btSecond_.setActionCommand("time_second"); - btSecond_.setSelected(true); - - btMinute_ = new JRadioButton("Minute"); - btMinute_.setActionCommand("time_minutes"); - - btHour_ = new JRadioButton("Hour"); - btHour_.setActionCommand("time_hour"); - - ButtonGroup timeButtonGroup = new ButtonGroup(); - timeButtonGroup.add(btSecond_); - timeButtonGroup.add(btMinute_); - timeButtonGroup.add(btHour_); + fdSdWindowSize_ = new JTextField(8); + pnWindowProp.add(fdSdWindowSize_); - btSecond_.addActionListener(this); - btMinute_.addActionListener(this); - btHour_.addActionListener(this); + btSetSdWindowSize_ = new JButton("Change"); + btSetSdWindowSize_.addActionListener(this); + pnWindowProp.add(btSetSdWindowSize_); - timePanel.add(btSecond_); - timePanel.add(btMinute_); - timePanel.add(btHour_); - - instructionPanel.add(checkPanel); instructionPanel.add(sliderPanel); - instructionPanel.add(timePanel); + instructionPanel.add(pnWindowProp); //Set up the drawing area. pnGraph_ = new GraphPanel(); @@ -379,12 +378,100 @@ this.getContentPane().add(pnItem_); this.getContentPane().add(pnColor_); + createMenuBar(); + pnItem_.setMinimumSize(new Dimension( (int)(WINDOW_WIDTH/2.7), (int)(super.getMaximumSize().height))); } + /** + * Creates the menu bar of the main window + */ + private void createMenuBar() { + JMenuBar menuBar = new JMenuBar(); + JMenu menuCommand = new JMenu("Options"); + + JMenu mnGridlet = new JMenu("Gridlet"); + JCheckBoxMenuItem miShowGridID = new JCheckBoxMenuItem("Show ID"); + miShowGridID.setSelected(true); + mnGridlet.add(miShowGridID); + + miShowGridID.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent e){ + if (e.getStateChange() == ItemEvent.DESELECTED){ + drawID_ = false; + } + else if (e.getStateChange() == ItemEvent.SELECTED){ + drawID_ = true; + } + pnGraph_.repaint(); + } + }); + + menuCommand.add(mnGridlet); + + JMenu mnTime = new JMenu("Time Unit"); + btSecond_ = new JRadioButtonMenuItem("Second"); + btSecond_.setActionCommand("time_second"); + btSecond_.setSelected(true); + + btMinute_ = new JRadioButtonMenuItem("Minute"); + btMinute_.setActionCommand("time_minutes"); + + btHour_ = new JRadioButtonMenuItem("Hour"); + btHour_.setActionCommand("time_hour"); + + ButtonGroup timeButtonGroup = new ButtonGroup(); + timeButtonGroup.add(btSecond_); + timeButtonGroup.add(btMinute_); + timeButtonGroup.add(btHour_); + + btSecond_.addActionListener(this); + btMinute_.addActionListener(this); + btHour_.addActionListener(this); + + mnTime.add(btSecond_); + mnTime.add(btMinute_); + mnTime.add(btHour_); + + menuCommand.add(mnTime); + + JMenu mnScroll = new JMenu("Scrolling"); + + JCheckBoxMenuItem miAutoScroll = new JCheckBoxMenuItem("Auto Scroll to End of Queue"); + miAutoScroll.setSelected(true); + mnScroll.add(miAutoScroll); + + miAutoScroll.addItemListener(new ItemListener(){ + public void itemStateChanged(ItemEvent e){ + if (e.getStateChange() == ItemEvent.DESELECTED){ + autoScroll_ = false; + } + else if (e.getStateChange() == ItemEvent.SELECTED){ + autoScroll_ = true; + } + updateResourceWindow(); + } + }); + + menuCommand.add(mnScroll); + menuBar.add(menuCommand); + setJMenuBar(menuBar); + } + private void updateResourceWindow(){ pnGraph_.repaint(); + + if(slidingWindowSize_ != Double.MAX_VALUE) { + int max = sclGraph_.getHorizontalScrollBar().getMaximum(); + if(autoScroll_) { + Rectangle visRect = sclGraph_.getVisibleRect(); + Rectangle rect = new Rectangle(max - visRect.width, + 0, visRect.width, sclGraph_.getHeight()); + sclGraph_.getHorizontalScrollBar().setValue(max - visRect.width); + sclGraph_.scrollRectToVisible(rect); + } + } } /** @@ -413,7 +500,7 @@ // calculates the size of the two panels // to be added to the window int leftPanelWidth = (int)((ResourceWindow.this.getWidth()) * PROPORTION_LEFT_PANEL); - int panelsHeight = (int)((ResourceWindow.this.getHeight()) - 20); + int panelsHeight = (int)((ResourceWindow.this.getHeight()) - 40); int gridletPanelWidth = (int)((ResourceWindow.this.getWidth()) * PROPORTION_RIGHT_PANEL) - 10; int leftPanelXPos = 0; int gridletPanelXPos = leftPanelXPos + leftPanelWidth; @@ -475,7 +562,15 @@ double timeSpan = settings_.getTimeSpan(); panelHeight_ = pnLeft_.getHeight() - 100 - SHIFT_Y - SHIFT_BOTTOM; - panelWidth_ = pnLeft_.getWidth() - 50 - 2 * SHIFT_X; + int minWidth = pnLeft_.getWidth() - 50 - 2 * SHIFT_X; + panelWidth_ = minWidth; + + double sdWindowSize = ResourceWindow.this.slidingWindowSize_; + if(sdWindowSize != Double.MAX_VALUE) + panelWidth_ = (int)( minWidth * (settings_.getTimeSpan() / sdWindowSize)); + + if(panelWidth_ < minWidth) + panelWidth_ = minWidth; scaleY_ = panelHeight_ / (float) numPE_; scaleX_ = panelWidth_ / (float) (timeSpan); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |