Changeset 85
- Timestamp:
- 03/07/05 22:35:32 (3 years ago)
- Files:
-
- trunk/JGraphViewer.java (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/JGraphViewer.java
r65 r85 44 44 45 45 public JGraphViewer(Graph graph, double scaleX, double scaleY, BackgroundMap backgroundMap) { 46 // Note - most of our members get initialized where they're46 // Note - most of our members get initialized where they're 47 47 // declared - cool, huh? Yay Java. 48 48 49 // we must use a borderlayout, or else the scrollPane doesn't49 // we must use a borderlayout, or else the scrollPane doesn't 50 50 // get resized when we do. Alternately, we could derive from 51 51 // the scrollpane instead of containing it, but that might let … … 147 147 148 148 149 // not sure if overriding this instead of making my own function is best149 // not sure if overriding this instead of making my own function is best 150 150 public void setBackground(Color bg) { 151 151 if(drawingPane != null) drawingPane.setBackground(bg); … … 163 163 public Object getSelectedObject() { return selectedObject; } 164 164 public void setSelectedObject(Object object) { 165 selectedObject = object;165 selectedObject = object; 166 166 objectsToPainters = null; 167 167 drawingPane.repaint(); … … 172 172 public void setBackgroundMap(BackgroundMap backgroundMap) { 173 173 this.backgroundMap = backgroundMap; 174 graphRectangle = null; 174 175 drawingPane.repaint(); 175 176 } … … 331 332 paintersToObjectLists = null; 332 333 //assert objectsToPainters != null; 333 334 334 335 return false; 335 336 } … … 382 383 private boolean updateGraphRectangle() { 383 384 384 // return early if we're up-to-date385 // return early if we're up-to-date 385 386 boolean upToDate = true; 386 387 upToDate &= (graphRectangle != null); … … 388 389 389 390 graphRectangle = new Rectangle2D.Double(); 390 graphRectangle.setRect(backgroundMap.getRealBoundingRectangle()); 391 392 // assert(graphRectangle != null); 391 if(backgroundMap != null) 392 graphRectangle.setRect(backgroundMap.getRealBoundingRectangle()); 393 394 // assert(graphRectangle != null); 393 395 return false; // because we weren't already up-to-date. 394 396 } … … 400 402 */ 401 403 private boolean updateRealToScreen() { 402 // return early if we're up-to-date404 // return early if we're up-to-date 403 405 boolean upToDate = true; 404 406 upToDate &= updateGraphRectangle(); 405 upToDate &= (realToScreen != null);407 upToDate &= (realToScreen != null); 406 408 407 409 if(upToDate) return true; … … 415 417 )); 416 418 417 // update our scrollbars's unit scroll419 // update our scrollbars's unit scroll 418 420 // the size of our visible area, I think. 419 421 Dimension viewportSize = ((JViewport)drawingPane.getParent()).getSize(); … … 516 518 // redraw images that have loaded while we're scrolling. 517 519 518 backgroundMap.paint(g, realToScreen, new ImageObserver() { 519 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 520 if(infoflags == ImageObserver.ALLBITS) { 521 SwingUtilities.invokeLater(new Runnable() { 522 public void run() { 523 repaint(); 524 } 525 }); 526 return false; 527 } else { 528 return true; 520 if(backgroundMap != null) { 521 backgroundMap.paint(g, realToScreen, new ImageObserver() { 522 public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { 523 if(infoflags == ImageObserver.ALLBITS) { 524 SwingUtilities.invokeLater(new Runnable() { 525 public void run() { 526 repaint(); 527 } 528 }); 529 return false; 530 } else { 531 return true; 532 } 529 533 } 530 } 531 532 } );534 535 }); 536 } 533 537 534 538 // draw all the objects … … 633 637 }; 634 638 635 /// here's the graph we refer to639 /// here's the graph we refer to 636 640 private Graph graph; 637 641 … … 641 645 /// slide the coordinates so they're all positive 642 646 private AffineTransform scale; 643 /// tells us how to translate stuff to the screen so it's positive647 /// tells us how to translate stuff to the screen so it's positive 644 648 private AffineTransform realToScreen; 645 649 … … 666 670 private PhysicalEdgePainter pathEdgePainter = new PhysicalEdgePainter(Color.BLUE, 5); 667 671 668 /// The currently selected object672 /// The currently selected object 669 673 private Object selectedObject; 670 674 /// How to draw it, depending on what type of thing it is … … 672 676 private PhysicalEdgePainter selectedEdgePainter = new PhysicalEdgePainter(Color.RED, 7); 673 677 674 /// Custom drawing commands678 /// Custom drawing commands 675 679 private Map objectsToCustomPainters [] = {new HashMap(), new HashMap(), new HashMap()}; 676 680 … … 678 682 private Collection pointListeners = new LinkedList(); 679 683 680 /// the backgroundmaps we draw684 /// the backgroundmaps we draw 681 685 private BackgroundMap backgroundMap; 682 686 }
