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