Changeset 85

Show
Ignore:
Timestamp:
03/07/05 22:35:32 (3 years ago)
Author:
tfelker2
Message:

indentation fixes, ability to have null backgroundmap, proper resizing on backgroundmap change

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/JGraphViewer.java

    r65 r85  
    4444 
    4545        public JGraphViewer(Graph graph, double scaleX, double scaleY, BackgroundMap backgroundMap) { 
    46                 // Note - most of our members get initialized where they're 
     46               // Note - most of our members get initialized where they're 
    4747                // declared - cool, huh?  Yay Java. 
    4848 
    49                 // we must use a borderlayout, or else the scrollPane doesn't 
     49               // we must use a borderlayout, or else the scrollPane doesn't 
    5050                // get resized when we do.  Alternately, we could derive from 
    5151                // the scrollpane instead of containing it, but that might let 
     
    147147 
    148148 
    149         // not sure if overriding this instead of making my own function is best 
     149       // not sure if overriding this instead of making my own function is best 
    150150        public void setBackground(Color bg) { 
    151151                if(drawingPane != null) drawingPane.setBackground(bg); 
     
    163163        public Object getSelectedObject() { return selectedObject; } 
    164164        public void setSelectedObject(Object object) { 
    165                 selectedObject = object; 
     165               selectedObject = object; 
    166166                objectsToPainters = null; 
    167167                drawingPane.repaint(); 
     
    172172        public void setBackgroundMap(BackgroundMap backgroundMap) { 
    173173                this.backgroundMap = backgroundMap; 
     174                graphRectangle = null; 
    174175                drawingPane.repaint(); 
    175176        } 
     
    331332                paintersToObjectLists = null; 
    332333                //assert objectsToPainters != null; 
    333                  
     334 
    334335                return false; 
    335336        } 
     
    382383        private boolean updateGraphRectangle() { 
    383384 
    384                 // return early if we're up-to-date 
     385               // return early if we're up-to-date 
    385386                boolean upToDate = true; 
    386387                upToDate &= (graphRectangle != null); 
     
    388389 
    389390                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); 
    393395                return false; // because we weren't already up-to-date. 
    394396        } 
     
    400402         */ 
    401403        private boolean updateRealToScreen() { 
    402                 // return early if we're up-to-date 
     404               // return early if we're up-to-date 
    403405                boolean upToDate = true; 
    404406                upToDate &= updateGraphRectangle(); 
    405                 upToDate &= (realToScreen != null); 
     407               upToDate &= (realToScreen != null); 
    406408 
    407409                if(upToDate) return true; 
     
    415417                )); 
    416418 
    417                 // update our scrollbars's unit scroll 
     419               // update our scrollbars's unit scroll 
    418420                // the size of our visible area, I think. 
    419421                Dimension viewportSize = ((JViewport)drawingPane.getParent()).getSize(); 
     
    516518                        // redraw images that have loaded while we're scrolling. 
    517519 
    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                                                } 
    529533                                        } 
    530                                 } 
    531  
    532                         }); 
     534 
     535                                }); 
     536                        } 
    533537 
    534538                        // draw all the objects 
     
    633637        }; 
    634638 
    635         /// here's the graph we refer to 
     639       /// here's the graph we refer to 
    636640        private Graph graph; 
    637641 
     
    641645        /// slide the coordinates so they're all positive 
    642646        private AffineTransform scale; 
    643         /// tells us how to translate stuff to the screen so it's positive 
     647       /// tells us how to translate stuff to the screen so it's positive 
    644648        private AffineTransform realToScreen; 
    645649 
     
    666670        private PhysicalEdgePainter pathEdgePainter = new PhysicalEdgePainter(Color.BLUE, 5); 
    667671 
    668         /// The currently selected object 
     672       /// The currently selected object 
    669673        private Object selectedObject; 
    670674        /// How to draw it, depending on what type of thing it is 
     
    672676        private PhysicalEdgePainter selectedEdgePainter = new PhysicalEdgePainter(Color.RED, 7); 
    673677 
    674         /// Custom drawing commands 
     678       /// Custom drawing commands 
    675679        private Map objectsToCustomPainters [] = {new HashMap(), new HashMap(), new HashMap()}; 
    676680 
     
    678682        private Collection pointListeners = new LinkedList(); 
    679683 
    680         /// the backgroundmaps we draw 
     684       /// the backgroundmaps we draw 
    681685        private BackgroundMap backgroundMap; 
    682686}