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. |