⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stub.java

📁 ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c
💻 JAVA
字号:
package edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph;import java.awt.Color;import java.awt.Dimension;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Point;import java.util.Enumeration;import java.util.Random;import edu.odu.cs.zeil.AlgAE.Debug;import edu.odu.cs.zeil.AlgAE.Direction;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.Edge;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.Edgeable;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.EdgeList;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.IDTree;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.Node;import edu.odu.cs.zeil.AlgAE.Client.DataViewer.DataGraph.PartialSum;import edu.odu.cs.zeil.AlgAE.Client.GraphicsInfo;/** * A stub is a special node that only appears as a component of a larger * object.  A stub is created when a node that is already a component of * some compound object is added again to that same object or some other. * The stub therefore draws its text and out edges from the node that * it "duplicates". */public class Stub extends Node{  /**   * The node that this stub duplicates.   */  private Node duplicateOf;  /**   * last ID issued to a stub   */  static private int lastID = 0;    /**   * Create a new Stub.   *   * @param duplicates The node that this stub stands for.   * @param theNormalColor  Color in which to draw this node (when not   *              highlighted).   * @param isVertical True if any nested nodes contained within this one   *              should be arranged vertically. False if they should be   *              arranged horizontally. If there are no nested nodes, this   *              has no effect.   */  public Stub(Node duplicates, Color theNormalColor, boolean isVertical)  {    super ("stub" + (lastID-1), theNormalColor, isVertical);    --lastID;    duplicateOf = duplicates;    --timeStamp;  }  /**   *  Update timestamp to indicate that node has been changed.   *  (Overridden to do nothing for stubs, whose timeStamp is only set   *  when info from the duplicated node is copied.)   */  void changed()  {  }  private void copyDuplicatedNode()  {    if ((duplicateOf != null) &&  (timeStamp != duplicateOf.timeStamp))      {	color = duplicateOf.color;		setText (duplicateOf.text);		clearOutEdges();	for (Enumeration edgeEnum = duplicateOf.outEdges.edges();	     edgeEnum.hasMoreElements(); )	  {	    Edge e = (Edge)(edgeEnum.nextElement());	    if (e.destination != duplicateOf)	      addEdge ((Node)e.destination, e.dir, e.color, e.label);	    else	      addEdge (this, e.dir, e.color, e.label);	  }		clearComponents();	for (Enumeration compEnum = duplicateOf.children();	     compEnum.hasMoreElements(); )	  {	    Node n = (Node)(compEnum.nextElement());	    if (n != null)	      addComponent (new Stub(n, n.color, n.vertical));	  }		timeStamp = duplicateOf.timeStamp;      }  }  	  /**   * Draw the node (but not its edges).   *  @param gi Graphics context information   */  void draw (GraphicsInfo gi)  {    copyDuplicatedNode();    super.draw (gi);  }    /**   * Draw the edges emanating from this node.   *  @param gi Graphics context information   */  void drawEdges(GraphicsInfo gi)  {    copyDuplicatedNode();    super.drawEdges (gi);  }    /**   * Compute the size of this node, given its current label and nested   * components.  The result is stored in the node's <code>nodeSize</code> data   * member.   *  @param gi Graphics context information   */  void computeSize(GraphicsInfo gi)  {    copyDuplicatedNode();    super.computeSize (gi);  }  /**   *  If this node has no position yet, choose one.   *  The same chosen position will be assigned as the old, new, and current   *  position.   *   *   @param gi Graphics context information   *   @param graph  The data graph within which this node occurs.   */  void chooseInitialPosition (GraphicsInfo gi, IDTree graph)  {    copyDuplicatedNode();    super.chooseInitialPosition (gi, graph);  }    /**   *  Try to find a more visibly pleasing position for this node.   *  The chosen position will be assigned as the new position.   *   *   @param gi Graphics context information   *   @param graph  The data graph within which this node occurs.   *   @param targetLength  Desired average length for all edges.   */  void reposition (GraphicsInfo gi, IDTree graph, double targetLength)  {    copyDuplicatedNode();    super.reposition (gi, graph, targetLength);  }  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -