Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /antelope/src/ise/antelope/common/dependency/

antelope
Discussion topic

Back to topic list

CVS update: /antelope/src/ise/antelope/common/dependency/

Author danson
Full name Dale Anson
Date 2004-04-14 06:18:51 PDT
Message User: danson
Date: 04/04/14 06:18:51

Added:
 /antelope/src/ise/an​telope/common/depend​ency/
  DependencyEdge.java, DependencyFigCircle.java, DependencyFigNode.java,
  DependencyNode.java, DependencyPort.java, DependencyViewer.java,
  MidLineArrowHead.java

Log:
 added to project
 

File Changes:

Directory: /antelope/src/ise/an​telope/common/depend​ency/
====================​====================​================

File [added]: DependencyEdge.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyEdge.​java?rev=1.1&con​tent-type=text/vnd.v​iewcvs-markup
Added lines: 68
---------------

package ise.antelope.common.dependency;

import java.awt.Color;
import java.util.*;
import org.tigris.gef.base.*;
import org.tigris.gef.demo.*;
import org.tigris.gef.graph​.presentation.*;
import org.tigris.gef.presentation.*;

public class DependencyEdge extends NetEdge {

   private Hashtable _attrs = null;
   private String _label = null;

   public DependencyEdge() {
      super();
   }

   public DependencyEdge( String label ) {
      super();
      _label = label;
   }

   public String getLabel() {
      return _label;
   }

   public void setLabel( String label ) {
      _label = label;
   }

   public void initialize( Hashtable args ) {
      _attrs = args;
   }

   public String getId() {
      return toString();
   }

   public Object getAttributes() {
      return _attrs;
   }

   public Object getAttribute( Object key ) {
      return _attrs.get( key );
   }

   public Object setAttribute( Object key, Object value ) {
      return _attrs.put( key, value );
   }

   public FigEdge makePresentation( Layer lay ) {
      FigEdge line = new FigEdgePoly();
      if ( _label != null ) {
         FigText label = new FigText( 10, 30, 90, 20 );
         label.setText( _label );
         label.setTextColor( Color.black );
         label.setTextFilled( false );
         label.setFilled( false );
         label.setLineWidth( 0 );
         line.addPathItem( label, new PathConvPercent( line, 50, 10 ) );
      }
      line.setDestArrowHead( new MidLineArrowHead(20) );
      return line;
   }

}

File [added]: DependencyFigCircle.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyFigCi​rcle.java?rev=1.1​&content-type=text/​vnd.viewcvs-markup
Added lines: 24
---------------
package ise.antelope.common.dependency;

import java.awt.Color;
import org.tigris.gef.presentation.*;

public class DependencyFigCircle extends FigCircle {
    public DependencyFigCircle(int x, int y, int w, int h) {
        super(x, y, w, h);
    }

    public DependencyFigCircle(int x, int y, int w, int h, Color lColor, Color fColor) {
        super(x, y, w, h, lColor, fColor);
    }

    public DependencyFigCircle(int x, int y, int w, int h, boolean resizable) {
        super(x, y, w, h);
        setResizable(resizable);
    }

    public DependencyFigCircle(int x, int y, int w, int h, boolean resizable, Color lColor, Color fColor) {
        super(x, y, w, h, lColor, fColor);
        setResizable(resizable);
    }
}

File [added]: DependencyFigNode.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyFigNo​de.java?rev=1.1&​content-type=text/vn​d.viewcvs-markup
Added lines: 125
----------------

package ise.antelope.common.dependency;

import java.awt.*;
import java.util.*;

import ise.antelope.common.*;

import org.tigris.gef.presentation.*;
import org.tigris.gef.graph​.presentation.*;

public class DependencyFigNode extends FigNode {
   Fig border, circle;
   FigText label;
   private Color GREEN = new Color( 0, 153, 51 );

   public DependencyFigNode(Object owner) {
      super();
      setOwner(owner);
      //border = new FigRect( -25, -25, 50, 50, Color.black, Color.white );
      
      Color outer = Color.black;
      Color inner = Color.black;

      SAXTreeNode node = ((DependencyNode)get​Owner()).getNode();
      if (node != null) {
         if (node.isPrivate()) {
            outer = Color.gray;
            inner = Color.gray;
         }
         
         if (node.isImported())
            inner = Color.red;
         
         if (node.isDefaultTarget()) {
            outer = GREEN;
         }
         
      }
      else
         throw new RuntimeException("node is null!");
      
      
      
      
      circle = new FigCircle( -20, -20, 40, 40, outer, outer );
      FigCircle wc = new FigCircle(-15, -15, 30, 30, Color.white, Color.white);
      FigCircle rc = new FigCircle(-10, -10, 20, 20, inner, inner);
      
      label = new FigText( -20, 20, 40, 40 );
      label.setText(node.g​etAttributeValue("na​me"));
      label.setLineWidth( 0 );
      label.setFilled(false);
      label.setJustification( FigText.JUSTIFY_CENTER );
      
      //addFig(border);
      addFig(circle);
      addFig(wc);
      addFig(rc);
      addFig(label);
   }
   
   public boolean isResizable() {
      return false;
   }
   
   public Fig deepSelect(Rectangle r) {
      return this;
   }
   
   public void setOwner( Object own ) {
      super.setOwner( own );
      if ( !( own instanceof DependencyNode ) )
         return ;
   }

   public void addPort( NetPort port ) {
      Fig fig = new DependencyFigCircle( 0, 0, 10, 10, Color.red, Color.red );
      fig.setVisible(false);
      addFig( fig );
      bindPort( port, fig );
      alignPorts();
   }

   private void alignPorts() {
      ArrayList figs = ( ArrayList ) getFigs( new ArrayList() );
      ArrayList port_figs = new ArrayList();
      Iterator it = figs.iterator();
      while ( it.hasNext() ) {
         Fig fig = ( Fig ) it.next();
         if ( fig instanceof DependencyFigCircle ) {
            port_figs.add( fig );
         }
      }
      double interval = ( double ) 360 / ( double ) port_figs.size();
      if ( interval == 360 )
         interval = 0;
      double radius = 20;
      it = port_figs.iterator();
      Rectangle r = circle.getBounds();
      int cx = r.x + ( r.width / 2 );
      int cy = r.y + ( r.height / 2 );
      
      for ( int i = 0; it.hasNext(); i++ ) {
         Fig fig = ( Fig ) it.next();
         fig.setBounds(cx - 5, cy - 5, 10, 10);
      }
   }

   public String getPrivateData() {
      return "text=\"" + label.getText() + "\"";
   }
   
   public void setPrivateData( String data ) {
      StringTokenizer tokenizer = new StringTokenizer( data, "=\"' " );

      while ( tokenizer.hasMoreTokens() ) {
         String tok = tokenizer.nextToken();
         if ( tok.equals( "text" ) ) {
            String s = tokenizer.nextToken();
            label.setText( s );
         }
      }
   }
}

File [added]: DependencyNode.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyNode.​java?rev=1.1&con​tent-type=text/vnd.v​iewcvs-markup
Added lines: 64
---------------

package ise.antelope.common.dependency;

import java.awt.Color;
import java.util.*;
import org.tigris.gef.base.*;
import org.tigris.gef.demo.*;
import org.tigris.gef.graph​.presentation.*;
import org.tigris.gef.presentation.*;
import ise.antelope.common.*;

public class DependencyNode extends NetNode {

   private Hashtable _attrs = null;
   private String _id = "";
   private SAXTreeNode _node = null;
   private DependencyFigNode _fig_node = null;

   public DependencyNode(SAXTreeNode node) {
      _node = node;
      _id = node.getAttributeValue("name");
   }

   public SAXTreeNode getNode() {
      return _node;
   }
   
   public void initialize( Hashtable args ) {
      _attrs = args;
   }
   
   public void addPort(NetPort port) {
      super.addPort(port);
      activatePort(port);
   }

   public void activatePort(NetPort port) {
      if (_fig_node == null)
         makePresentation(null);
      _fig_node.addPort(port);
   }

   public String getId() {
      return _id;
   }

   public Object getAttributes() {
      return _attrs;
   }

   public Object getAttribute( Object key ) {
      return _attrs.get( key );
   }

   public Object setAttribute( Object key, Object value ) {
      return _attrs.put( key, value );
   }

   public FigNode makePresentation( Layer lay ) {
      if ( _fig_node == null )
         _fig_node = new DependencyFigNode(this);
      return _fig_node;
   }
}

File [added]: DependencyPort.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyPort.​java?rev=1.1&con​tent-type=text/vnd.v​iewcvs-markup
Added lines: 28
---------------
package ise.antelope.common.dependency;

import org.tigris.gef.base.*;
import org.tigris.gef.demo.*;
import org.tigris.gef.graph.*;
import org.tigris.gef.graph​.presentation.*;
import org.tigris.gef.presentation.*;


public class DependencyPort extends NetPort {

   public DependencyPort( NetNode parent ) {
      super( parent );
   }

   protected Class defaultEdgeClass( NetPort otherPort ) {
      try {
         return Class.forName( "ise.antelope.common​.DependencyEdge" );
      }
      catch ( java.lang.ClassNotFo​undException ignore ) {
         return null;
      }
   }
   public boolean canConnectTo( GraphModel gm, Object anotherPort ) {
      return true;
   }

}

File [added]: DependencyViewer.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/DependencyViewe​r.java?rev=1.1&c​ontent-type=text/vnd​.viewcvs-markup
Added lines: 115
----------------

package ise.antelope.common.dependency;

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import org.xml.sax.*;
import org.tigris.gef.base.*;
import org.tigris.gef.demo.*;
import org.tigris.gef.graph.*;
import org.tigris.gef.graph​.presentation.*;
import org.tigris.gef.presentation.*;

import ise.antelope.common.*;

public class DependencyViewer {

   private File _build_file = null;

   public DependencyViewer( File build_file ) {
      _build_file = build_file;

      // load the build file and get all target nodes
      SAXTreeModel model = new SAXTreeModel( _build_file );
      HashMap target_nodes = model.getTargets();

      // make corresponding graph nodes
      HashMap graph_nodes = new HashMap();
      Iterator it = target_nodes.keySet(​).iterator();
      while ( it.hasNext() ) {
         String name = ( String ) it.next();
         SAXTreeNode child = ( SAXTreeNode ) target_nodes.get( name );
         DependencyNode graph_node = new DependencyNode( child );
         String child_name = child.getAttributeValue( "name" );
         if ( child.isImported() )
            child_name = ( ( SAXTreeNode ) child.getParent() ).getAttributeValue( "name" ) + "." + child_name;
         graph_nodes.put( child_name, graph_node );
      }

      DefaultGraphModel graph_model = new DefaultGraphModel();

      JGraph graph = new JGraph( graph_model );
      graph.setForeground( java.awt.Color.white );

      //JFrame.setDefaultL​ookAndFeelDecorated(​ true );
      JFrame frame = new JFrame();
      frame.setTitle(build​_file.getAbsolutePat​h());
      frame.setContentPane( graph );
      frame.setSize( 600, 600 );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      frame.setVisible( true );

      LayerManager lm = graph.getEditor().ge​tLayerManager();
      lm.replaceLayer( lm.findLayerNamed( "Grid" ), new LayerGrid( new Color( 180, 180, 180 ), Color.white, 16, false ) );
      LayerPerspective active_layer = ( LayerPerspective ) lm.getActiveLayer();
      active_layer.addNodeTypeRegion( DependencyNode.class, new java.awt.Rectangle( 100, 100, 800, 600 ) );

      // build the graph edges
      it = graph_nodes.keySet()​.iterator();
      ArrayList edges = new ArrayList();
      while ( it.hasNext() ) {
         String target_name = ( String ) it.next();
         DependencyNode target_node = ( DependencyNode ) graph_nodes.get( target_name );
         Attributes attrs = ( Attributes ) target_node.getNode(​).getAttributes();
         if ( attrs != null ) {
            int index = attrs.getIndex( "depends" );
            String value = attrs.getValue( index );
            if ( value != null ) {
               StringTokenizer st = new StringTokenizer( value, "," );
               for ( int i = 0; i < st.countTokens(); i++ ) {
                  String dname = st.nextToken();
                  DependencyNode dnode = ( DependencyNode ) graph_nodes.get( dname );
                  if ( dnode == null )
                     continue;

                  DependencyPort dp1 = new DependencyPort( target_node );
                  target_node.addPort( dp1 );
                  DependencyPort dp2 = new DependencyPort( dnode );
                  dnode.addPort( dp2 );

                  DependencyEdge dedge2 = new DependencyEdge( String.valueOf( i + 1 ) );
                  dedge2.connect( graph_model, dp1, dp2 );
                  edges.add( dedge2 );
               }
            }
         }
      }
      
      // populate the graph
      Iterator itr = graph_nodes.values()​.iterator();
      while ( itr.hasNext() )
         graph_model.addNode( ( NetNode ) itr.next() );
      itr = edges.iterator();
      while ( itr.hasNext() ) {
         NetEdge edge = ( NetEdge ) itr.next();
         graph_model.addEdge( edge );
         lm.sendToBack( edge.presentationFor( active_layer ) );
      }
      graph.layoutGraph();

   }

   public static void main ( String[] args ) {
      try {
         File f = new File( "c:/apache-ant-1.6.0​/src/apache-ant-1.6.​0/build.xml" );
         if ( !f.exists() )
            throw new FileNotFoundException( f.getAbsolutePath() );
         new DependencyViewer( f );
      }
      catch ( Exception e ) {
         e.printStackTrace();
      }
   }
}

File [added]: MidLineArrowHead.java
Url: http://antelope.tigr​is.org/source/browse​/antelope/src/ise/an​telope/common/depend​ency/MidLineArrowHea​d.java?rev=1.1&c​ontent-type=text/vnd​.viewcvs-markup
Added lines: 47
---------------
package ise.antelope.common.dependency;

import java.awt.*;
import org.tigris.gef.base.*;
import org.tigris.gef.presentation.*;

/**
 * An arrow head that can be placed in the middle of a line rather than at the
 * ends. Of course, setting offset to 0 will put the arrow head at the end anyway.
 * @author Dale Anson, April 2004
 */
public class MidLineArrowHead extends ArrowHeadTriangle {

   private int _offset = 0;

   /**
    * @param offset the offset from the end of the line in pixels to place the
    * arrowhead.
    */
   public MidLineArrowHead( int offset ) {
      _offset = offset;
   }

   /**
    * Overridden to position the arrow head at the specified offset.
    */
   public void paintAtHead( Graphics g, Fig path ) {
      Graphics2D g2 = ( Graphics2D ) g;
      Stroke oldStroke = g2.getStroke();
      g2.setStroke( new BasicStroke( path.getLineWidth() ) );
      paint( g2, path.pointAlongPerimeter( _offset + 5 ), path.pointAlongPerimeter( _offset ) );
      g2.setStroke( oldStroke );
   }

   /**
    * Overridden to position the arrow head at the specified offset.
    */
   public void paintAtTail( Graphics g, Fig path ) {
      Graphics2D g2 = ( Graphics2D ) g;
      Stroke oldStroke = g2.getStroke();
      g2.setStroke( new BasicStroke( path.getLineWidth() ) );
      int len = path.getPerimeterLength();
      paint( g2, path.pointAlongPerimeter( len - ( _offset + 5 ) ), path.pointAlongPerimeter( len - _offset ) );
      g2.setStroke( oldStroke );
   }

}




--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@ante​lope.tigris.org
For additional commands, e-mail: cvs-help at antelope dot tigris dot org

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

Messages

Show all messages in topic

CVS update: /antelope/src/ise/antelope/common/dependency/ danson Dale Anson 2004-04-14 06:18:51 PDT
Messages per page: