Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: gef/src/org/tigris/gef/xml/pgml PGMLParser.java

gef
Discussion topic

Back to topic list

CVS update: gef/src/org/tigris/gef/xml/pgml PGMLParser.java

Reply

Author 1sturm
Full name Thorsten Sturm
Date 2001-04-12 07:29:29 PDT
Message User: 1sturm
  Date: 01/04/12 07:29:29

  Modified: src/org/tigris/gef/presentation Fig.java FigText.java
               src/org/tigris/gef/xml/pgml PGMLParser.java
  Added: src/org/tigris/gef/presentation AnotationHelper.java
                        AnotationLineRemover.java AnotationProperties.java
                        AnotationStrategy.java EdgeAnotationStrategy.java
                        FigTextAnotationProperties.java
                        NoAnotationStrategy.java NodeAnotationStrategy.java
  Log:
  new annotations to edges, i.e. strings can be placed free.
  Obtained from:Stefan Boege
  Submitted by: Thorsten
  
  Revision Changes Path
  1.4 +89 -12 gef/src/org/tigris/g​ef/presentation/Fig.​java
  
  Index: Fig.java
  ====================​====================​====================​=======
  RCS file: /cvs/gef/src/org/tig​ris/gef/presentation​/Fig.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Fig.java 2001/04/04 12:52:13 1.3
  +++ Fig.java 2001/04/12 14:29:28 1.4
  @@ -26,7 +26,7 @@
   // File: Fig.java
   // Classes: Fig
   // Original Author: ics125 spring 1996
  -// $Id: Fig.java,v 1.3 2001/04/04 12:52:13 1sturm Exp $
  +// $Id: Fig.java,v 1.4 2001/04/12 14:29:28 1sturm Exp $
   
   import java.awt.*;
   import java.awt.event.*;
  @@ -136,7 +136,7 @@
     /** Most subclasses will not use this constructor, it is only useful
      * for subclasses that redefine most of the infrastructure provided
      * by class Fig. */
  - public Fig() { }
  + public Fig() { an = new NoAnotationStrategy(); }
     /** Construct a new Fig with the given bounds. */
     public Fig(int x, int y, int w, int h) {
       this(x, y, w, h, Color.black, Color.white, null);
  @@ -151,11 +151,53 @@
     /** Construct a new Fig with the given bounds, colors, and owner. */
     public Fig(int x, int y, int w, int h,
            Color lineColor, Color fillColor, Object own) {
  + this();
       _x = x; _y = y; _w = w; _h = h;
       if (lineColor != null) _lineColor = lineColor; else _lineWidth = 0;
       if (fillColor != null) _fillColor = fillColor; else _filled = false;
       setOwner(own);
  + //anotation related
     }
  +
  + //------------------​--------------
  + // anotation related
  +
  + protected AnotationStrategy an = new NoAnotationStrategy();
  +
  + protected Fig anotationOwner;
  +
  + // legt den AnotationOwner fest
  + public void setAnotationOwner(Fig f){
  + anotationOwner = f;
  + // der Aufruf dieser Methode macht dieses Objekt zur Anotation
  + anotationStatus=true;
  + }
  +
  + public Fig getAnotationOwner(){
  + return anotationOwner;
  + }
  +
  + public AnotationStrategy getAnotationStrategy(){
  + return an;
  + }
  +
  + //** Set the AnotationStrategy for this fig */
  + //** using this method will discard the previous AnotationStrategy */
  + public void setAnotationStrategy​(AnotationStrategy a){
  + an = a;
  + }
  +
  + boolean anotationStatus = false;
  +
  + // returns true if this fig is an anotation of any other fig
  + public boolean isAnotation(){
  + return anotationStatus;
  + }
  + // end anotation related
  + //------------------​-----------------
  +
  +
  +
     public void addPoint(int x, int y) { }
     ////////////////////​////////////////////​////////////////////​////
     // updates
  @@ -172,7 +214,7 @@
      * prevent garbage collection. */
     public void addPropertyChangeLis​tener(PropertyChange​Listener l) {
       Globals.addPropertyC​hangeListener(this, l);
  - }
  + }
     /** Align this Fig with the given rectangle. Some subclasses may
      * need to know the editor that initiated this action. */
     public void align(Rectangle r, int direction, Editor ed) {
  @@ -337,6 +379,17 @@
     /** Remove this Fig from the Layer being edited by the
      * given editor. */
     public void delete() {
  + _displayed = false;
  + // anotation related
  + // delete all anotations first
  + java.util.Enumeration enum = getAnotationStrategy​().getAllAnotations(​);
  + while (enum.hasMoreElements()){
  + Fig anotation = (Fig)enum.nextElement();
  + getAnotationStrategy​().getAnotationPrope​rties(anotation).rem​oveLine();
  + getAnotationStrategy​().removeAnotation(a​notation);
  + anotation.delete();
  + }
  + // end anotation related
       if (_layer != null) { _layer.deleted(this); }
       setOwner(null);
     }
  @@ -407,12 +460,28 @@
      * startTrans(), although it is alright to have extra calls to
      * endTrans(). */
     public void endTrans() {
  +
  + // anotation related
  + if (this.isAnotation()){
  + if (!(Globals.curEditor​().getSelectionManag​er().containsFig(thi​s.getAnotationOwner(​))) && Globals.curEditor().​getSelectionManager(​).containsFig(this) ){
  + (getAnotationOwner()​.an).storeAnotationP​osition(this);
  + }
  + }
  +
  +
  + if (!(getAnotationStrategy() instanceof NoAnotationStrategy)){
  + getAnotationStrategy​().translateAnotatio​ns(this);
  + }
  +
  + // end anotation related
       damage();
       //RedrawManager.unlock(); // helps avoid dirt
     }
  +
     public void firePropChange(String propName, int oldV, int newV) {
       firePropChange(propName, new Integer(oldV), new Integer(newV));
     }
  +
     /** Creates a PropertyChangeEvent and calls all registered listeners
      * propertyChanged() method. */
     public void firePropChange(String propName, Object oldV, Object newV) {
  @@ -447,7 +516,7 @@
     public Fig getGroup() { return _group; }
     public int getHalfHeight() { return _h / 2; }
     public int getHalfWidth() { return _w / 2; }
  - public int getHeight() { return _h; }
  + public int getHeight() { return _h; }
     public String getId() {
       if (getGroup() != null) {
         String gID = getGroup().getId();
  @@ -464,7 +533,7 @@
     public Point getLastPoint() { return new Point();}
     public Layer getLayer() { return _layer; }
     public Color getLineColor() { return _lineColor; }
  - public int getLineWidth() { return _lineWidth; }
  + public int getLineWidth() { return _lineWidth; }
     /** Returns a point that is the upper left corner of the Fig's
      * bounding box. */
     public Point getLocation() { return new Point(_x, _y); }
  @@ -519,7 +588,7 @@
       int cornersHit = countCornersContained(r.x, r.y, r.width, r.height);
       if (_filled) return cornersHit > 0;
       else return cornersHit > 0 && cornersHit < 4;
  - }
  + }
     public void insertPoint(int i, int x, int y) { }
     /** Reply true if the object intersects the given rectangle. Used
      * for selective redrawing and by ModeSelect to select all Figs
  @@ -572,7 +641,7 @@
       return res;
     }
     public void postLoad() { }
  - public void postSave() { }
  + public void postSave() { }
     public void preSave() { }
   // public void assignShadowColor(Color c) { _shadowColor = c; } //?
   // public void setShadowColor(Color c) { _shadowColor = c; }
  @@ -591,7 +660,7 @@
      * FigNode may want to override this method. */
     public void propertyChange(Prope​rtyChangeEvent pce) {
       if (_group != null) _group.propertyChange(pce);
  - }
  + }
     public void removePoint(int i) { }
     /** Remove this PropertyChangeListener from the JellyBeans internal
      * list. If the PropertyChangeListener isn't on the list, silently
  @@ -680,7 +749,7 @@
     public void setLayer(Layer lay) {
       firePropChange("layer", _layer, lay);
       _layer = lay;
  - }
  + }
     /** Internal function to change the line color attribute. Other code
      * should use put(String key, Object value). */
     //public void assignLineColor(Color col) { _lineColor = col; } //?
  @@ -752,7 +821,7 @@
     public void setWidth(int w) { setBounds(_x, _y, w, _h); }
     // needs-more-work: property change events?
     public void setX(int x) { setBounds(x, _y, _w, _h); }
  - public void setXs(int[] xs) { }
  + public void setXs(int[] xs) { }
     public void setY(int y) { setBounds(_x, y, _w, _h); }
     public void setYs(int[] ys) { }
     /** This indicates that some Cmd is starting a manipulation on the
  @@ -763,7 +832,15 @@
      * the RedrawManager is key to avoiding "screen dirt". Each call to
      * startTrans() MUST be matched with a call to endTrans(). */
     public void startTrans() {
  - damage();
  + /*
  + if (this.isAnotation()){
  + if (!(Globals.curEditor​().getSelectionManag​er().containsFig(thi​s.getAnotationOwner(​))) && Globals.curEditor().​getSelectionManager(​).containsFig(this) ){
  + (getAnotationOwner()​.an).storeAnotationP​osition(this);
  + }
  + }
  + */
  +
  +
       //RedrawManager.lock(); // helps avoid dirt
     }
     /** Reshape the given rectangle to be my bounding box. */
  @@ -799,7 +876,7 @@
       Rectangle oldBounds = getBounds();
       _x += dx; _y += dy;
       firePropChange("bounds", oldBounds, getBounds());
  - }
  + }
     /** Reply true if the entire Fig is contained within the given
      * Rectangle. This can be used by ModeSelect to select Figs that
      * are totally within the selection rectangle. */
  
  
  
  1.4 +2 -1 gef/src/org/tigris/g​ef/presentation/FigT​ext.java
  
  Index: FigText.java
  ====================​====================​====================​=======
  RCS file: /cvs/gef/src/org/tig​ris/gef/presentation​/FigText.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FigText.java 2000/11/29 14:49:07 1.3
  +++ FigText.java 2001/04/12 14:29:28 1.4
  @@ -26,7 +26,7 @@
   // File: FigText.java
   // Classes: FigText
   // Original Author: ics125 spring 1996
  -// $Id: FigText.java,v 1.3 2000/11/29 14:49:07 toby Exp $
  +// $Id: FigText.java,v 1.4 2001/04/12 14:29:28 1sturm Exp $
   
   package org.tigris.gef.presentation;
   
  @@ -350,6 +350,7 @@
   
     /** Paint the FigText. */
     public void paint(Graphics g) {
  + if (!(_displayed)) return;
       int chunkX = _x + _leftMargin;
       int chunkY = _y + _topMargin;
       StringTokenizer lines;
  
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Anot​ationHelper.java
  
  Index: AnotationHelper.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.awt.event.*;
  import javax.swing.*;
  import java.util.Hashtable;
  import java.awt.Point;
  
  public class AnotationHelper{
           
          private static AnotationHelper theInstance = null;
  
      private float ratio;
      private int offset;
      private float dd;
      private Point a = new Point();
      private Point normpoint = new Point();
  
  
          private AnotationHelper(){
          }
          
          public static AnotationHelper instance(){
              if (theInstance==null) theInstance = new AnotationHelper();
              return theInstance;
          }
          public int getNormOffset(Point p0, Point p1, Point p2){
          // p0: anotation's position
            // p1: edge's starting point
            // p2: edge's ending point
          dd = (float)( ( (p2.x-p1.x)*(p0.y-p1.y) - (p0.x-p1.x)*(p2.y-p1.y) ) /
                    Math.sqrt( (p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y) ) );
            offset = -1 * (int) Math.round(dd);
            //System.out.println("distance: " + d);
            return offset;
        }
  
      public float getRatio(Point r1, Point r0, Point r2){
              // r1: position of anotation;
            // r0: edge's starting point
            // r2: edge's ending point
             //edge's direction vector
          a.x = r2.x-r0.x; a.y = r2.y-r0.y;
          //Hilfsvariable t
          float t = (float) ( (r1.x-r0.x)*a.x + (r1.y-r0.y)*a.y ) / (a.x*a.x + a.y*a.y);
              //calculate normpoint
          normpoint.x = (int) ( r1.x + (r0.x - r1.x + t*a.x) );
          normpoint.y = (int) ( r1.y + (r0.y - r1.y + t*a.y) );
             //calculate ratio
          float ges = (float) (Math.sqrt( (r2.x-r0.x)*(r2.x-r0.x) + (r2.y-r0.y)*(r2.y-r0.y) ));
          float srcToL = (float) (Math.sqrt( (normpoint.x-r0.x)*(​normpoint.x-r0.x) + (normpoint.y-r0.y)*(​normpoint.y-r0.y) ) );
          float rest = ges-srcToL;
          //System.out.println​("Gesamtlaenge der Kante; " + (int)ges);
          //System.out.println("Laenge SRC zu Lotpunkt: " + (int)srcToL);
          float proz = (srcToL/ges) *100;
          //System.out.println("Lot teilt im Verhaeltnis: " + (int) proz + " %" );
            return srcToL/ges;
      }
  
          // get the closest point to p on an edge from start to end
          public Point getClosestPointOnEdge(Point p, Point start, Point end){
                  normpoint = getNormPointOnEdge(p, start, end);
                  // check if the normpoint is ON the edge (not only on the edge's beam)
                  if ( ( (normpoint.x >= start.x && normpoint.x <= end.x) || (normpoint.x <= start.x && normpoint.x >= end.x) )
                      && ( (normpoint.y >= start.y && normpoint.y <= end.y) || (normpoint.y <= start.y && normpoint.y >= end.y) ) ){
                      return normpoint;
                  }
                  else{
                      if (sqr_distance(normpoint, start) <= sqr_distance(normpoint, end)) return start;
                      else return end;
                  }
          }
  
      // sqr distance of two points
          public int sqr_distance(Point p1, Point p2){
                  return (int) ( (p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y) );
          }
  
      public Point getNormPointOnEdge(Point r1, Point r0, Point r2){
              // r1: position of anotation;
            // r0: edge's starting point
            // r2: edge's ending point
             //edge's direction vector
          a.x = r2.x-r0.x; a.y = r2.y-r0.y;
          //
          float t = (float) ( (r1.x-r0.x)*a.x + (r1.y-r0.y)*a.y ) / (a.x*a.x + a.y*a.y);
              //calculate NormPoint
          normpoint.x = (int) ( r1.x + (r0.x - r1.x + t*a.x) );
          normpoint.y = (int) ( r1.y + (r0.y - r1.y + t*a.y) );
          return normpoint;
      }
              
  }// end of class
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Anot​ationLineRemover.jav​a
  
  Index: AnotationLineRemover.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.awt.event.*;
  import javax.swing.*;
  import java.util.Hashtable;
  
  public class AnotationLineRemover implements ActionListener {
           
          private Hashtable timers; // FIG | Timer
          private Hashtable figs; // Timer | Fig (nur der bequemlichkeit wegen ;-)
          private static AnotationLineRemover theInstance = null;
  
          private AnotationLineRemover(){
              timers = new Hashtable();
              figs = new Hashtable();
          }
          
          public static AnotationLineRemover instance(){
              if (theInstance==null) theInstance = new AnotationLineRemover();
              return theInstance;
          }
              
          public void removeLineIn(int millis, Fig f){
              // falls diese Fig schon einen Timer hat, dann starte ihn einfach nur neu,
              // um zu verhindern, dass die Linie des Elements, dass gerade verschoben wird
              // unsichtbar wird
              if (timers.containsKey(f)){
                  ((Timer)timers.get(f​)).restart();
              }
              // sonst lege einen neuen Timer an
              else{
                  Timer t = new Timer(millis, this);
                  timers.put(f,t);
                  figs.put(t,f);
                  t.start();
              }
          }
  
  
  
          public void actionPerformed(ActionEvent e){
              //System.out.println("Event from Timer ! " + e.getSource());
              // die Zeit ist abgelaufen - d.h. die Linie wurde 'millis'-Millisekunden
              // nicht bewegt und kann geloescht werden.
              // Gleichzeitig kann der Timer angehalten werden.
              Timer t = (Timer)e.getSource();
              t.stop();
              //((Fig)figs.get(t))​.getAnotationStrateg​y().removeAllConnect​ingLines();
              Fig anotation = ((Fig)figs.get(t));
              System.out.println("​********************​*****************" +anotation);
                  try{
                      anotation.getAnotati​onOwner().getAnotati​onStrategy().getAnot​ationProperties(anot​ation).removeLine();​
                  }
                  catch (Exception ex){}
          }
  }
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Anot​ationProperties.java​
  
  Index: AnotationProperties.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.awt.Color;
  import org.tigris.gef.base.*;
  
  // each Anotation has one associated AnotationProperties object
  public class AnotationProperties {
  
          private boolean fixedOffset = false;
          private boolean fixedRatio = false;
          private int offset = 10;
          private float ratio = (float)0.5;
      private int connectingLineVisibi​lityDuration = 300;
      private FigLine line = new FigLine(0,0,0,0);
      private Color lineColor = Color.red;
      private boolean deleteR = false;
      private boolean remote = false;
      
      
      public AnotationProperties(){
          this(false,5,false,(float)0.5);
      }
  
          public AnotationProperties(boolean fixedOffset, int offset, boolean fixedRatio, float ratio){
                  this.offset = offset;
                  this.ratio = ratio;
                  this.fixedOffset = fixedOffset;
                  this.fixedRatio = fixedRatio;
          // connectingLine visible for 300 ms
          }
  
      public AnotationProperties(int offset, float ratio){
          this(false, offset, false, ratio);
      }
  
      public void setLineColor(Color c){
          lineColor = c;
      }
      
      public Color getLineColor(){
          return lineColor;
      }
      
      public void setLineVisibilityDuration(int millis){
          connectingLineVisibi​lityDuration = millis;
      }
      
      public int getLineVisibilityDuration(){
          return connectingLineVisibi​lityDuration;
      }
  
      public boolean hasFixedRatio(){
          return fixedRatio;
      }
  
      public boolean hasFixedOffset(){
          return fixedOffset;
      }
  
      public float getRatio(){ return ratio; }
      public void setRatio(float ratio, boolean fixedRatio){
          this.ratio = ratio;
          this.fixedRatio = fixedRatio;
      }
  
      public int getOffset(){ return offset; }
      public void setOffset(int offset, boolean fixedOffset){
          this.offset = offset;
          this.fixedOffset = fixedOffset;
      }
  
      public FigLine getConnectingLine(){
          return line;
      }
      
      // line is visible only if anotation is visible
      protected boolean lineIsVisible(Fig anotation){
          return anotationIsVisible(anotation);
      }
      
      protected boolean anotationIsVisible(Fig anotation){
          return true;
      }
      
      // removes the line from the active diagram
      public synchronized void removeLine(){
          if (Globals.curEditor()​.getLayerManager().g​etContents().contain​s(line))
                  line.delete();
      }
          
  
  } // end of class
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Anot​ationStrategy.java
  
  Index: AnotationStrategy.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.util.*;
  import java.awt.Color;
  import org.tigris.gef.base.*;
  import java.beans.*;
  
  // jede Klasse, die als AnotationOwner dienen soll, bekommt eine AnotationStrategy,
  // die angibt, wie sich die Anotations veraendern sollen (z.B. parallel mitverschieben)
  // wenn der AnotationOwner die Position aendert
  
  public abstract class AnotationStrategy{
  
      // hashtable of all anotations
      Hashtable anotations = new Hashtable(); // anotation | AnotationProperties
  
      // this method auto-moves the anotations
      public abstract void translateAnotations(Fig owner);
      // calculates and stores the values necessary for correct auto-movement
      public abstract void storeAnotationPosition(Fig anotation);
  
      // should the line from anotation to owner be visible ?
      protected boolean lineIsVisible(Fig anotation){ return true; };
  
      // all figs added to an owner fig with this method become anotations of that fig
      public void addAnotation(Fig owner, Fig anotation, AnotationProperties properties){
          // restrictions
          // 1. no double anotations
          if ( (anotations.contains​Key(anotation)) || owner == null || anotation == null ) return;
          // tell the anotation its owner
          anotation.setAnotati​onOwner(owner);
          // store the anotation with its properties in a hashtable
          anotations.put(anotation, properties);
      }
  
      public AnotationProperties getAnotationProperties(Fig anotation){
          return (AnotationProperties​)anotations.get(anot​ation);
      }
  
          public Enumeration getAllAnotations(){
                  return anotations.keys();
          }
  
          public Vector getAnotationsVector(){
                  Vector v = new Vector();
                  Enumeration enum = getAllAnotations();
                  while (enum.hasMoreElements()){
                          v.addElement(enum.ne​xtElement());
                  }
                  return v;
          }
  
  
      public void removeAnotation(Fig anotation){
          //if (anotation==null) return;
          // delete the line first
          //AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
          //FigLine line = prop.getConnectingLine();
          //Globals.curEditor(​).remove(line);
          anotations.remove(anotation);
                  //line.delete();
          //System.out.println​("+++++++++++removed​ from hashtable: " + anotation);
          //Globals.curEditor(​).remove(anotation);​
      }
  
      public void removeAllAnotations(){
          java.util.Enumeration enum = anotations.keys();
          while (enum.hasMoreElements()){
              Fig anotation = (Fig)enum.nextElement();
              //anotation.delete();
              removeAnotation(anotation);
          }
      }
  
  
      // delete line from owner to anotation
      public void removeAllConnectingLines(){
          java.util.Enumeration enum = anotations.keys();
          while (enum.hasMoreElements()){
              Fig anotation = (Fig)enum.nextElement();
              AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
              FigLine line = prop.getConnectingLine();
              if (Globals.curEditor()​.getLayerManager().g​etContents().contain​s(line))
                  Globals.curEditor().​remove(line);
          }
      }
  
  } // end of class
  
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Edge​AnotationStrategy.ja​va
  
  Index: EdgeAnotationStrategy.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.util.*;
  import java.awt.*;
  import org.tigris.gef.base.*;
  
  
  
  public class EdgeAnotationStrategy extends AnotationStrategy{
  
      AnotationHelper helper = AnotationHelper.instance();
  
      public EdgeAnotationStrategy(){
      }
  
      /*
      protected boolean lineIsVisible(Fig anotation){
          System.out.println("​--------------------​--------------------​-LineIsVisible called !");
          if (anotation instanceof FigText){
              return (!((FigText)anotatio​n).getText().equals(​""));
          }
          return true;
      };
      */
  
          protected Point restoreAnotationPosition(Fig anotation){
          int d; //offset
          float ratio;
          
          Fig owner = anotation.getAnotationOwner();
          // in the case: owner is an edge
          if (owner instanceof FigEdge){
              AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
              d = prop.getOffset();
              ratio = prop.getRatio();
              FigEdge edge = (FigEdge)owner;
              //Point start = edge.getSourcePortFi​g().center();
              //Point ende = edge.getDestPortFig().center();
              Point start;
              Point ende;
              try{
                  start = edge.getFirstPoint();
                  ende = edge.getLastPoint();
              } catch (ArrayIndexOutOfBoundsException e){
                  try{
                      start= edge.getSourcePortFi​g().center();
                      ende = edge.getDestPortFig().center();
                  }
                  catch(NullPointerException ne){
                          start = new Point(10,10);
                          ende = new Point(100,10);
                  }
              }
              
              if ((start.x == ende.x) && (start.y == ende.y)) return anotation.getLocation();
              
              // calculate
              float xdirection = ende.x - start.x;
              float ydirection = ende.y - start.y;
              double newX = start.x + ratio * xdirection;
              double newY = start.y + ratio * ydirection;
              // restore offset d
              newX = newX + d * ( ydirection / Math.sqrt(xdirection*xdirection + ydirection*ydirection) );
              newY = newY + d * (-1)* (xdirection / Math.sqrt(xdirection*xdirection + ydirection*ydirection) );
              // the anotation's new position
              return new Point( (int)newX- (anotation.getWidth()/2), (int)newY-(anotation​.getHeight()/2) );
          }
          return new Point(1,1);
      }
  
  
      // calculate offset and ratio of anotation (relative to anotationOwner)
      // store values in a hashtable
      // method is called when the anotation is moved without its owner
      public void storeAnotationPosition(Fig anotation){
          int d; float ratio;
          Fig owner = anotation.getAnotationOwner();
          // case: owner ist eine Kante
          if (owner instanceof FigEdge){
              FigEdge edge = (FigEdge)owner;
              Point anPos = anotation.center();
              //Point start= edge.getSourcePortFi​g().center();
              //Point ende = edge.getDestPortFig().center();
              Point start;
              Point ende;
              try{
                  start = edge.getFirstPoint();
                  ende = edge.getLastPoint();
              } catch (ArrayIndexOutOfBoundsException e){
                  start= edge.getSourcePortFi​g().center();
                  ende = edge.getDestPortFig().center();
              }
              
              if ((start.x == ende.x) && (start.y == ende.y)) return;
              
              d = helper.getNormOffset(anPos, start, ende);
              ratio = helper.getRatio(anPos, start, ende);
                          Point normpoint = helper.getNormPointO​nEdge(anPos, start, ende);
              // store values
              AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
              prop.setRatio(ratio,​prop.hasFixedRatio()​);
              prop.setOffset(d ,prop.hasFixedOffset());
              
              // so ungefaehr
              //((PathConvPercentP​lusConst)edge.getPat​hConvOfFig(anotation​)).setPercentOffset(​(int)ratio, d);
              System.out.println("ratio = " +ratio + " d= " +d);
              
              //
          }
          drawConnectingLine(anotation);
      }
  
      // draws a dotted line between this anotation and its owner
      public void drawConnectingLine(Fig anotation) throws NullPointerException{
          if (!(getAnotationPrope​rties(anotation).lin​eIsVisible(anotation​))) return;
          Fig owner = anotation.getAnotationOwner();
          AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
          FigLine line = prop.getConnectingLine();
          
          
          if ( ((FigEdge)owner).get​SourcePortFig().cent​er() == null || ((FigEdge)owner).get​DestPortFig().center​() == null ) return;
                  //line from anotation to center of owning edge
          //line.setShape(anot​ation.center(), owner.center());
                  //line from anotation to closest point on owning edge
                  try{
                      line.setShape(anotat​ion.center(), helper.getClosestPoi​ntOnEdge(anotation.c​enter(),((FigEdge)ow​ner).getFirstPoint()​, ((FigEdge)owner).get​LastPoint()));
                  } catch (ArrayIndexOutOfBoundsException e){
                      //line.setShape(anot​ation.center(), calculateLotpunkt(an​otation.center(), ((FigEdge)owner).get​SourcePortFig().cent​er(), ((FigEdge)owner).get​DestPortFig().center​() ));
                      line.setShape(anotat​ion.center(), helper.getClosestPoi​ntOnEdge(anotation.c​enter(), ((FigEdge)owner).get​SourcePortFig().cent​er(), ((FigEdge)owner).get​DestPortFig().center​() ));
                  }
                  //line.setShape(anot​ation.center(), getClosestPointOnEdg​e(anotation.center()​, ((FigEdge)owner).get​SourcePortFig().cent​er(), ((FigEdge)owner).get​DestPortFig().center​() ));
                  line.setLineColor(ge​tAnotationProperties​(anotation).getLineC​olor());
          line.setFillColor(ge​tAnotationProperties​(anotation).getLineC​olor());
          line.setDashed(true);
          // draw the line
          if (!(Globals.curEditor​().getLayerManager()​.getContents().conta​ins(line))) Globals.curEditor().add(line);
          Globals.curEditor().​getLayerManager().br​ingToFront(anotation​);
          //
          line.damage();
          anotation.damage();
  
          // remove line automatically
          AnotationLineRemover​.instance().removeLi​neIn( getAnotationProperti​es(anotation).getLin​eVisibilityDuration(​),anotation );
          }
  
      // move anotations
      // this method is called, when an anotationOwner is moved without its
      // anotations
      public void translateAnotations(Fig owner){
          java.util.Enumeration enum = anotations.keys();
          // owner has moved; set anotations to their new positions
          while (enum.hasMoreElements()){
              Fig anotation = (Fig)enum.nextElement();
              anotation.setLocatio​n(restoreAnotationPo​sition(anotation));
              //drawConnectingLine​(anotation);
              Globals.curEditor().​getLayerManager().br​ingToFront(anotation​);
              // call endtrans of anotation
              anotation.endTrans();
              anotation.damage();
              
          }
          owner.damage();
      }
  
  } // end of class
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/FigT​extAnotationProperti​es.java
  
  Index: FigTextAnotationProperties.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import org.tigris.gef.base.*;
  
  
  // each Anotation has one associated AnotationProperties object
  public class FigTextAnotationProperties extends AnotationProperties{
      
          public FigTextAnotationProp​erties(boolean fixedOffset, int offset, boolean fixedRatio, float ratio){
              super(fixedOffset, offset, fixedRatio, ratio);
          }
  
      public FigTextAnotationProperties(int offset, float ratio){
          super(false, offset, false, ratio);
      }
      
      // anotation is visible if it contains some text
      protected boolean anotationIsVisible(Fig anotation){
          if (!(anotation instanceof FigText)) return true;
          FigText f = (FigText)anotation;
          return !(f.getText().equals(""));
      }
              
          
  
  } // end of class
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/NoAn​otationStrategy.java​
  
  Index: NoAnotationStrategy.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.util.*;
  
  public class NoAnotationStrategy extends AnotationStrategy{
           
          // Diese Klasse ist nur ein Dummy fuer die Figs, die keine Anotations
          // haben sollen. Sie wird standardmaessig fuer jede Fig angelegt.
      public NoAnotationStrategy(){
      }
  
      public void translateAnotations(Fig owner){
          // do nothing in this case
      }
      
      /*
      protected void restoreAnotationPosition(Fig anotation){
          // do nothing in this case
      }
      */
      
      public void storeAnotationPosition(Fig anotation){
          // do nothing in this case
      }
  }
  
  
  1.1 gef/src/org/tigris/g​ef/presentation/Node​AnotationStrategy.ja​va
  
  Index: NodeAnotationStrategy.java
  ====================​====================​====================​=======
  package org.tigris.gef.presentation;
  
  import java.util.*;
  import java.awt.*;
  import org.tigris.gef.base.*;
  
  
  
  public class NodeAnotationStrategy extends AnotationStrategy{
      
      public NodeAnotationStrategy(){
      }
  
      protected Point restoreAnotationPosition(Fig anotation){
          int delta_x;
          float delta_y;
          Fig owner = anotation.getAnotationOwner();
          // in this case: owner is a node
          if (! ( (owner instanceof FigEdge) || (owner instanceof FigLine) )){
              ArrayList list = (ArrayList)anotation​s.get(anotation);
              delta_x = ((Integer)list.get(0​)).intValue();
              delta_y = ((Float)list.get(1))​.floatValue();
              int own_x = (int) owner.center().x;
              int own_y = (int) owner.center().y;
              int newX = (int) (own_x + delta_x);
              int newY = (int) (own_y + delta_y);
              // neue Position der Anotation einstellen
              return new Point( (int)newX- (anotation.getWidth()/2), (int)newY-(anotation​.getHeight()/2) );
          }
          return new Point(1,1);
      }
          
      public void storeAnotationPosition(Fig anotation){
          int delta_x; float delta_y;
          Fig owner = anotation.getAnotationOwner();
          // in this case: owner is a node
          if (! ( (owner instanceof FigEdge) || (owner instanceof FigLine) )){
              Point anPos = anotation.center();
              Point ownerPos = owner.center();
              delta_x = anPos.x-ownerPos.x;
              delta_y = anPos.y-ownerPos.y;
              // store values
              ArrayList list = (ArrayList)anotation​s.get(anotation);
              FigLine line = (FigLine)list.get(2);
              list.add(0, new Integer(delta_x));
              list.add(1, new Float(delta_y));
              list.add(2, line);
              anotations.put(anotation, list);
          }
          drawConnectingLine(anotation);
      }
  
      public void drawConnectingLine(Fig anotation){
          Fig owner = anotation.getAnotationOwner();
          AnotationProperties prop = (AnotationProperties​)anotations.get(anot​ation);
          FigLine line = prop.getConnectingLine();
          line.setShape(anotat​ion.center(), owner.center());
          line.setLineColor(Color.red);
          line.setFillColor(Color.red);
          line.setDashed(true);
          if (!(Globals.curEditor​().getLayerManager()​.getContents().conta​ins(line))) Globals.curEditor().add(line);
          Globals.curEditor().​getLayerManager().br​ingToFront(anotation​);
          line.damage();
          anotation.damage();
          }
          
      // move anotations to its new position
      public void translateAnotations(Fig owner){
          java.util.Enumeration enum = anotations.keys();
          while (enum.hasMoreElements()){
              Fig anotation = (Fig)enum.nextElement();
              anotation.setLocatio​n(restoreAnotationPo​sition(anotation));
              drawConnectingLine(anotation);
              anotation.endTrans();
              anotation.damage();
          }
      }
      
  } // end of class
  
  
  1.12 +34 -3 gef/src/org/tigris/g​ef/xml/pgml/PGMLPars​er.java
  
  Index: PGMLParser.java
  ====================​====================​====================​=======
  RCS file: /cvs/gef/src/org/tig​ris/gef/xml/pgml/PGM​LParser.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PGMLParser.java 2001/04/03 15:17:12 1.11
  +++ PGMLParser.java 2001/04/12 14:29:29 1.12
  @@ -54,6 +54,8 @@
     protected HashMap _figRegistry = null;
     protected Map _ownerRegistry = new HashMap();
   
  + protected boolean _anotationsTag = false;
  +
     ////////////////////​////////////////////​////////////////////​////
     // constructors
   
  @@ -115,7 +117,7 @@
         }
         else {
           ex.printStackTrace();
  - }
  + }
       }
       catch (Exception ex) {
         System.out.println("Exception in readDiagram");
  @@ -186,8 +188,9 @@
           else if (elementName.equals("pgml")) {
               handlePGML(attrList);
           }
  +
           else if (_nestedGroups == 0) {
  - if (elementName.equals("path")) {
  + if (elementName.equals("path")) {
               _diagram.add(handleP​olyLine(attrList));
           }
           else if (elementName.equals("ellipse")) {
  @@ -223,7 +226,7 @@
           polyStateStartElemen​t(elementName,attrLi​st);
           break;
   
  - case NODE_STATE:
  + case NODE_STATE:
               nodeStateStartElemen​t(elementName,attrLi​st);
               break;
   
  @@ -231,8 +234,23 @@
           edgeStateStartElemen​t(elementName,attrLi​st);
           break;
       }
  +
  + //sb: anotation handling
  + if (elementName.equals(​"anotations")){
  + handleStartAnotation​s(elementName,attrLi​st);
  + }
  + }
  +
  + public void handleStartAnotations(String elementName, AttributeList attrList){
  + _anotationsTag = true;
  + //System.out.println​("==========handling​ anotations START=====");
  + }
  + public void handleEndAnotations(String elementName){
  + _anotationsTag = false;
  + //System.out.println​("==========handling​ anotations END=====");
     }
   
  +
     public void endElement(String elementName) {
       switch(_elementState) {
           case 0:
  @@ -332,6 +350,10 @@
               _textBuf = null;
           break;
       }
  + //sb: anotation handling
  + if (elementName.equals(​"anotations")){
  + handleEndAnotations(​elementName);
  + }
     }
   
     public void characters(char[] ch,
  @@ -448,6 +470,15 @@
         int textsizeInt = Integer.parseInt(textsize);
         f.setFontSize(textsizeInt);
       }
  +
  + // sb: anotation related
  + /*
  + if (_anotationsTag){
  + System.out.println(" ====== Text in AnotationTag found !=============");
  + System.out.println(" ====== Text: " + attrList.getValue("name") + " AnOwner: " + _currentEdge);
  + }
  + */
  +
       return f;
     }

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

Messages

Show all messages in topic

CVS update: gef/src/org/tigris/gef/xml/pgml PGMLParser.java 1sturm Thorsten Sturm 2001-04-12 07:29:29 PDT
Messages per page: