Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: gef/src/org/tigris/gef/graph/presentation JGraph.java

gef
Discussion topic

Back to topic list

CVS update: gef/src/org/tigris/gef/graph/presentation JGraph.java

Reply

Author toby
Full name Toby Baier
Date 2001-04-05 04:33:38 PDT
Message User: toby
  Date: 01/04/05 04:33:38

  Modified: src/org/tigris/gef/g​raph/presentation JGraph.java
  Log:
  some enhancements
  Submitted by:someone unknown
  Reviewed by:Toby
  
  Revision Changes Path
  1.2 +84 -10 gef/src/org/tigris/g​ef/graph/presentatio​n/JGraph.java
  
  Index: JGraph.java
  ====================​====================​====================​=======
  RCS file: /cvs/gef/src/org/tig​ris/gef/graph/presen​tation/JGraph.java,v​
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JGraph.java 2000/09/04 12:38:50 1.1
  +++ JGraph.java 2001/04/05 11:33:37 1.2
  @@ -21,6 +21,8 @@
   // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
   // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
   
  +
  +
   package org.tigris.gef.graph​.presentation;
   
   import java.util.*;
  @@ -30,10 +32,11 @@
   import javax.swing.border.*;
   import javax.swing.event.*;
   
  +import org.tigris.gef.ui.*;
  +import org.tigris.gef.graph.*;
  +import org.tigris.gef.event.*;
   import org.tigris.gef.base.*;
   import org.tigris.gef.presentation.*;
  -import org.tigris.gef.event.*;
  -import org.tigris.gef.graph.*;
   
   /** JGraph is a Swing component that displays a connected graph and
    * allows interactive editing. In many ways this class serves as a
  @@ -49,13 +52,13 @@
     protected Editor _editor;
     protected JGraphInternalPane _drawingPane;
     protected JScrollPane _scroll;
  + protected Dimension _defaultSize = new Dimension(1000,1000);
   
     ////////////////////​////////////////////​////////////////////​////
     // constructor
   
     /** Make a new JGraph with a new DefaultGraphModel.
  - * @see org.tigris.gef.graph​.presentation.Defaul​tGraphModel
  - */
  + * @see uci.graph.DefaultGraphModel */
     public JGraph() { this(new DefaultGraphModel()); }
   
     /** Make a new JGraph with a the GraphModel and Layer from the given
  @@ -71,7 +74,7 @@
       super(false); // not double buffered. I do my own flicker-free redraw.
       _editor = ed;
       _drawingPane = new JGraphInternalPane(_editor);
  - setDrawingSize(1500, 1500);
  + setDrawingSize(getDe​faultSize());
   
       _scroll = new JScrollPane(_drawingPane);
       _scroll.setBorder(null);
  @@ -90,6 +93,11 @@
       //invalidate();
       validate();
       //revalidate();
  +
  + Vector layerManagerContent = ed.getLayerManager()​.getContents();
  + if ( layerManagerContent != null ) {
  + updateDrawingSizeToI​ncludeAllFigs(layerM​anagerContent.elemen​ts());
  + } // end if
     }
   
     public void addMouseListener(MouseListener listener) {
  @@ -168,26 +176,77 @@
     /** Get the Editor that is being displayed */
     public Editor getEditor() { return _editor; }
   
  + protected Hashtable _viewPortPositions = new Hashtable();
  + protected String _currentDiagramId = null;
  +
     /** Set the Diagram that should be displayed by setting the
      * GraphModel and Layer that the Editor is using. */
     public void setDiagram(Diagram d) {
       if (d == null) return;
  + if ( _currentDiagramId != null ) {
  + _viewPortPositions.p​ut(_currentDiagramId​,_scroll.getViewport​().getViewRect());
  + } // end if
  + setDrawingSize(getDe​faultSize());
  + updateDrawingSizeToI​ncludeAllFigs(d.elem​ents());
       _editor.getLayerMana​ger().replaceActiveL​ayer(d.getLayer());
       _editor.setGraphMode​l(d.getGraphModel())​;
       _editor.getSelection​Manager().deselectAl​l();
       _editor.damageAll();
  + String newDiagramId = Integer.toString(d.hashCode());
  + if ( newDiagramId.equals(​_currentDiagramId) ) return;
  + _currentDiagramId = newDiagramId;
  + if ( _viewPortPositions.g​et(_currentDiagramId​) != null ) {
  + Rectangle rect = (Rectangle)_viewPort​Positions.get(_curre​ntDiagramId);
  + _scroll.getViewport(​).setViewPosition(ne​w Point(rect.x,rect.y));
  + } else {
  + _scroll.getViewport(​).setViewPosition(ne​w Point());
  + } // end else if
     }
   
  + /**
  + * Enlarges the JGraphInternalPane dimensions as necessary to
  + * insure that all the contained Figs are visible.
  + */
  + protected void updateDrawingSizeToI​ncludeAllFigs(Enumer​ation enum) {
  + if ( enum == null ) {
  + return;
  + } // end if
  + Dimension drawingSize = _drawingPane.getSize();
  + boolean recalSize = false;
  + while( enum.hasMoreElements() ) {
  + Fig fig = (Fig)enum.nextElement();
  + Rectangle rect = fig.getBounds();
  + Point point = rect.getLocation();
  + Dimension dim = rect.getSize();
  + if( (point.x + dim.width + 5) > drawingSize.width ) {
  + drawingSize.setSize(point.x + dim.width + 5, drawingSize.height);
  + recalSize = true;;
  + } // end if
  + if( (point.y + dim.height + 5) > drawingSize.height ) {
  + drawingSize.setSize( drawingSize.width, point.y + dim.height + 5);
  + recalSize = true;;
  + } // end if
  + } // end while
  + if ( recalSize ) {
  + setDrawingSize(drawi​ngSize.width,drawing​Size.height);
  + } // end if
  + } // end updateDrawingSizeToI​ncludeAllFigs()
  +
     public void setDrawingSize(int width, int height) {
  - _drawingPane.setPref​erredSize(new Dimension(width, height));
  + setDrawingSize(new Dimension(width, height));
     }
   
  + public void setDrawingSize(Dimension dim) {
  + _drawingPane.setPref​erredSize(dim);
  + _drawingPane.revalidate();
  + }
  +
     /** Get and set the GraphModel the Editor is using. */
     public void setGraphModel(GraphModel gm) { _editor.setGraphModel(gm); }
     public GraphModel getGraphModel() { return _editor.getGraphModel(); }
   
     /** Get and set the Renderer used to make FigNodes for nodes in the
  - * GraphModel. */
  + * GraphModel. */
     public void setGraphNodeRenderer​(GraphNodeRenderer r) {
       _editor.setGraphNode​Renderer(r);
     }
  @@ -196,7 +255,7 @@
     }
   
     /** Get and set the Renderer used to make FigEdges for edges in the
  - * GraphModel. */
  + * GraphModel. */
     public void setGraphEdgeRenderer​(GraphEdgeRenderer r) {
       _editor.setGraphEdge​Renderer(r); }
     public GraphEdgeRenderer getGraphEdgeRenderer() {
  @@ -311,12 +370,24 @@
   // public Dimension getMinimumSize() { return new Dimension(1000, 1000); }
   
   // public Dimension getSize() { return new Dimension(1000, 1000); }
  +
  + public void setDefaultSize(int width, int height) {
  + _defaultSize = new Dimension(width, height);
  + }
  + public void setDefaultSize(Dimension dim) {
  + _defaultSize = dim;
  + }
  + public Dimension getDefaultSize() {
  + return _defaultSize;
  + }
  + static final long serialVersionUID = -5459241816919316496L;
  +
   } /* end class JGraph */
   
   
   
   class JGraphInternalPane extends JPanel {
  -//implements FocusListener
  +//implements FocusListener
     protected Editor _editor;
   
     public JGraphInternalPane(Editor e) {
  @@ -369,6 +440,9 @@
     public boolean isManagingFocus() { return true; }
   
     /** Tell Swing/AWT that JGraph can be tabbed into. */
  - public boolean isFocusTraversable() { return true; }
  + public boolean isFocusTraversable() { return true; }
  +
  + static final long serialVersionUID = -5067026168452437942L;
  +
   } /* end class JGraphInternalPane */

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: gef/src/org/tigris/gef/graph/presentation JGraph.java toby Toby Baier 2001-04-05 04:33:38 PDT
Messages per page: