From: <mar...@us...> - 2007-11-07 21:56:16
|
Revision: 79 http://gridsim.svn.sourceforge.net/gridsim/?rev=79&view=rev Author: marcos_dias Date: 2007-11-07 13:56:19 -0800 (Wed, 07 Nov 2007) Log Message: ----------- A problem that prevented the ResourceWindow from updating its components properly when resized has been fixed. This problem could be noticed on Windows machines. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-11-07 03:40:40 UTC (rev 78) +++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2007-11-07 21:56:19 UTC (rev 79) @@ -130,17 +130,19 @@ // the jobs or advance reservations displayed by this window private ArrayList<ScheduleItem> scheduledItems_; - // time unit used to display information on the screen - private int timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; - // the settings object private GUISettings settings_; + + // time unit used to display information on the screen + private int timeUnit_ = GridSimVisualizer.TIME_UNIT_SECOND; private static final int WINDOW_WIDTH = 1100; private static final int WINDOW_HEIGHT = 300; private static final int SHIFT_X = 30; private static final int SHIFT_Y = 25; private static final int SHIFT_BOTTOM = 15; + private static final float PROPORTION_LEFT_PANEL = 0.6f; + private static final float PROPORTION_RIGHT_PANEL = 1f - PROPORTION_LEFT_PANEL; /** * Creates the scheduling window. @@ -163,7 +165,6 @@ // initialise the left and right panels initPanels(); ResizeFrame adapter = new ResizeFrame(); - adapter.frame_ = this; super.addComponentListener(adapter); super.setLocation(DefaultGridSimVisualizer.WINDOW_WIDTH, windowId * 200); @@ -193,28 +194,32 @@ switch(type){ case AllocationAction.ITEM_ARRIVED: - case AllocationAction.ITEM_STATUS_CHANGED: for(ScheduleItem item : list){ - itemPanel_.updateItem(item); + itemPanel_.insertNewItem(item); } updateResourceWindow(); break; + case AllocationAction.ITEM_STATUS_CHANGED: + itemPanel_.updateItem(list.getLast()); + updateResourceWindow(); + break; + case AllocationAction.ITEM_SCHEDULED: for(ScheduleItem item : list){ scheduledItems_.add(item); double finishTime = item.getFinishTime(); settings_.setTimeSpan(finishTime); - itemPanel_.updateItem(item); } + itemPanel_.updateItem(list.getLast()); updateResourceWindow(); break; case AllocationAction.ITEM_CANCELLED: for(ScheduleItem item : list){ - itemPanel_.updateItem(item); scheduledItems_.remove(item); } + itemPanel_.updateItem(list.getLast()); updateResourceWindow(); break; @@ -263,10 +268,9 @@ // calculates the size of the two panels // to be added to the window - int leftPanelWidth = (int)((super.getWidth()/3.5) * 2.3); - int leftPanelHeight = (int)((super.getHeight()) - 20); - int gridletPanelWidth = (int)((super.getWidth()/3.5) * 1.2); - int gridletPanelHeight = leftPanelHeight; + int leftPanelWidth = (int)((super.getWidth()) * PROPORTION_LEFT_PANEL); + int panelsHeight = (int)((super.getHeight()) - 20); + int gridletPanelWidth = (int)((super.getWidth()) * PROPORTION_RIGHT_PANEL) - 10; int leftPanelXPos = 0; int gridletPanelXPos = leftPanelXPos + leftPanelWidth; @@ -274,7 +278,7 @@ leftPanel_.setOpaque(true); leftPanel_.setLayout(new BorderLayout()); leftPanel_.setLocation(leftPanelXPos, 0); - leftPanel_.setSize(leftPanelWidth, leftPanelHeight); + leftPanel_.setSize(leftPanelWidth, panelsHeight); Border raisedetched = BorderFactory.createEtchedBorder(EtchedBorder.RAISED); JPanel instructionPanel = new JPanel(); @@ -361,7 +365,7 @@ itemPanel_ = new ItemPanel(); itemPanel_.setLocation(gridletPanelXPos, 0); - itemPanel_.setSize(gridletPanelWidth, gridletPanelHeight); + itemPanel_.setSize(gridletPanelWidth, panelsHeight); this.getContentPane().add(leftPanel_); this.getContentPane().add(itemPanel_); @@ -390,30 +394,28 @@ * that compose the resource window interface */ class ResizeFrame extends ComponentAdapter { - JFrame frame_ = null; public ResizeFrame() { super(); } public void componentResized(ComponentEvent evt) { - if(evt.getSource() == frame_) { - int windowWidth = frame_.getWidth(); - int windowHeight = frame_.getHeight(); + + // 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 gridletPanelWidth = (int)((ResourceWindow.this.getWidth()) * PROPORTION_RIGHT_PANEL) - 10; + int leftPanelXPos = 0; + int gridletPanelXPos = leftPanelXPos + leftPanelWidth; + + leftPanel_.setLocation(leftPanelXPos, 0); + leftPanel_.setSize(leftPanelWidth, panelsHeight); + leftPanel_.updateUI(); - int leftPanelWidth = (int)((windowWidth/3.5) * 2.3); - int leftPanelHeight = (int)((windowHeight) - 20); - int gridletPanelWidth = (int)((windowWidth/3.5) * 1.2); - int gridletPanelHeight = leftPanelHeight; - int leftPanelXPos = 0; - int gridletPanelXPos = leftPanelXPos + leftPanelWidth; - - leftPanel_.setLocation(leftPanelXPos, 0); - leftPanel_.setSize(leftPanelWidth, leftPanelHeight); - - itemPanel_.setLocation(gridletPanelXPos, 0); - itemPanel_.setSize(gridletPanelWidth, gridletPanelHeight); - } + itemPanel_.setLocation(gridletPanelXPos, 0); + itemPanel_.setSize(gridletPanelWidth, panelsHeight); + itemPanel_.updateUI(); } } @@ -461,13 +463,12 @@ // been selected ScheduleItem highlightedItem_ = null; - public DrawingPanel(){ + public DrawingPanel() { super(); super.setBackground(backgroundColor_); } protected synchronized void paintComponent(Graphics g2) { - super.paintComponent(g2); Graphics2D g2D = (Graphics2D)g2; g2D.setFont(graphFont_); @@ -487,7 +488,7 @@ (int) ((numPE_) * scaleY_) + SHIFT_Y + SHIFT_BOTTOM)); drawSchedulingQueue(g2D); - drawGridsAndAxes(timeSpan, g2D); + drawGridsAndAxes(g2D); super.revalidate(); } @@ -496,8 +497,10 @@ * @param timeSpan the time span of the simulation * @param g2D the graphics 2D context */ - private void drawGridsAndAxes(double timeSpan, Graphics2D g2D) { + private void drawGridsAndAxes(Graphics2D g2D) { + double timeSpan = settings_.getTimeSpan(); + String text = null; g2D.setColor(timeGridColor_); g2D.setStroke(dashedStroke_); @@ -775,6 +778,32 @@ } /** + * Inserts a Gridlet to the JList and the vector of Gridlets + * @param insertItem the item to be inserted in the vector of + * schedule items and the JList + */ + public void insertNewItem(ScheduleItem insertItem) { + if(insertItem == null) + return; + + DefaultListModel listModel; + + int index = items_.size(); + items_.add(index, insertItem); + + listModel = (DefaultListModel)itemQueueJList_.getModel(); + listModel.add(index, itemSummary(insertItem)); + try { + itemQueueJList_.ensureIndexIsVisible(index); + itemQueueJList_.setSelectedIndex(index); + } + catch(Exception ex) { + // cannot happen + } + updateItemDetails(insertItem); + } + + /** * Updates information in the list. This method checks whether * the Item is already in the list or not. If it is, just update * the details window. Otherwise, inserts the item in @@ -782,16 +811,17 @@ * @param item the item whose information has to be updated */ protected void updateItem(ScheduleItem item) { + if(item == null) + return; + int position = getPosition(item.getID(), item.getSenderID(), item.isAdvanceReservation()); - if(position < 0) { - position = insertNewItem(item); - } + int selectedIndex = (int) itemQueueJList_.getSelectedIndex(); - itemQueueJList_.ensureIndexIsVisible(position); - itemQueueJList_.setSelectedIndex(position); - updateItemDetails(item); + if(selectedIndex == position) { + updateItemDetails(item); + } } /** @@ -903,43 +933,6 @@ } return -1; } - - /** - * Inserts a Gridlet to the JList and the vector of Gridlets - * @param insertItem the item to be inserted in the vector of - * schedule items and the JList - */ - private int insertNewItem(ScheduleItem insertItem) { - int sizeVector = items_.size(); - double submittedTime = insertItem.getSubmissionTime(); - int i; - - ScheduleItem item; - DefaultListModel listModel; - - for(i=0; i<sizeVector; i++) { - item = items_.get(i); - - if(submittedTime < item.getSubmissionTime()) { - items_.add(i, insertItem); - break; - } - - if(submittedTime == item.getSubmissionTime() - && insertItem.getID() == item.getID() - && insertItem.isAdvanceReservation() == item.isAdvanceReservation() - && insertItem.getSenderID() == item.getSenderID() ) { - return i; - } - } - - if(i == sizeVector) - items_.add(insertItem); - - listModel = (DefaultListModel)itemQueueJList_.getModel(); - listModel.add(i, itemSummary(insertItem)); - return i; - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |