📄 node.java~
字号:
/*
* TouchGraph LLC. Apache-Style Software License
*
*
* Copyright (c) 2001-2002 Alexander Shapiro. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* TouchGraph LLC (http://www.touchgraph.com/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "TouchGraph" or "TouchGraph LLC" must not be used to endorse
* or promote products derived from this software without prior written
* permission. For written permission, please contact
* alex@touchgraph.com
*
* 5. Products derived from this software may not be called "TouchGraph",
* nor may "TouchGraph" appear in their name, without prior written
* permission of alex@touchgraph.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TOUCHGRAPH OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
*/
package com.touchgraph.graphlayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.Date;
import java.util.Vector;
import java.util.Iterator;
/** Node.
*
* @author Alexander Shapiro
* @author Murray Altheim (2001-11-06; added support for round rects and alternate Node colors)
* @version 1.21 $Id: Node.java,v 1.29 2002/04/01 05:52:15 x_ander Exp $
*/
public class Node {
/** This Node's type is a Rectangle. */
public final static int TYPE_RECTANGLE = 1;
/** This Node's type is a Round Rectangle. */
public final static int TYPE_ROUNDRECT = 2;
/** This Node's type is an Ellipse. */
public final static int TYPE_ELLIPSE = 3;
/** This Node's type is a Circle. */
public final static int TYPE_CIRCLE = 4;
public static final Font SMALL_TAG_FONT = new Font("Courier",Font.PLAIN,9);
// Variables that store default values for colors + fonts + node type
public static Color BACK_FIXED_COLOR = new Color(0,150,0);//Color.green;
public static Color BACK_SELECT_COLOR = Color.red;//new Color(255, 224, 0);
public static Color BACK_DEFAULT_COLOR = new Color(0,150,0);//new Color(208, 96, 0);
public static Color BACK_HILIGHT_COLOR = Color.decode("#ffb200"); // altheim: new
public static Color BORDER_DRAG_COLOR = Color.black;
public static Color BORDER_MOUSE_OVER_COLOR = new Color(160,160,160);
public static Color BORDER_INACTIVE_COLOR = Color.white;
public static Color TEXT_COLOR = Color.white;
public static Font TEXT_FONT = new Font("Arial",Font.BOLD,10);//new Font("Courier",Font.PLAIN,12);
public static int DEFAULT_TYPE = 1;
/** an int indicating the Node type.
* @see TYPE_RECTANGLE
* @see TYPE_ROUNDRECT
* @see TYPE_ELLIPSE
*/
protected int typ = TYPE_RECTANGLE;
private String id;
public double drawx;
public double drawy;
protected FontMetrics fontMetrics;
protected Font font;
protected String lbl;
protected Color backColor = BACK_DEFAULT_COLOR;
protected Color textColor = TEXT_COLOR;
public double x;
public double y;
protected double dx; //Used by layout
protected double dy; //Used by layout
protected boolean fixed;
protected int repulsion; //Used by layout
public boolean justMadeLocal = false;
public boolean markedForRemoval = false;
public int visibleEdgeCnt; //Should only be modified by graphelements.VisibleLocality
protected boolean visible;
private Vector edges;
// ............
/** Minimal constructor which will generate an ID value from Java's Date class.
* Defaults will be used for type and color. The label will be taken from the ID value.
*/
public Node()
{
initialize(null);
lbl = id;
}
/** Constructor with the required ID <tt>id</tt>, using defaults
* for type (rectangle), color (a static variable from TGPanel).
* The Node's label will be taken from the ID value.
*/
public Node( String id )
{
initialize(id);
lbl = id;
}
public Node( String id, Color col )
{
initialize(id);
lbl = id;
backColor = col;
}
public Node( String id, String label, Color col )
{
initialize(id);
if ( label == null ) lbl = id;
else lbl = label;
backColor = col;
}
/** Constructor with Strings for ID <tt>id</tt> and <tt>label</tt>, using defaults
* for type (rectangle) and color (a static variable from TGPanel).
* If the label is null, it will be taken from the ID value.
*/
public Node( String id, String label )
{
initialize(id);
if ( label == null ) lbl = id;
else lbl = label;
}
/** Constructor with a String ID <tt>id</tt>, an int <tt>type</tt>, Background Color <tt>bgColor</tt>,
* and a String <tt>label</tt>. If the label is null, it will be taken from the ID value.
* @see TYPE_RECTANGLE
* @see TYPE_ROUNDRECT
*/
public Node( String id, int type, Color color, String label )
{
initialize(id);
typ = type;
backColor = color;
if ( label == null ) lbl = id;
else lbl = label;
}
private void initialize( String identifier ) {
this.id = identifier;
edges = new Vector();
x = Math.random()*2-1; // If multiple nodes are added without repositioning,
y = Math.random()*2-1; // randomizing starting location causes them to spread out nicely.
repulsion = 100;
font = TEXT_FONT;
fixed = false;
typ = DEFAULT_TYPE;
visibleEdgeCnt=0;
visible = false;
}
// setters and getters ...............
public static void setNodeBackFixedColor( Color color ) { BACK_FIXED_COLOR = color; }
public static void setNodeBackSelectColor( Color color ) { BACK_SELECT_COLOR = color; }
public static void setNodeBackDefaultColor( Color color ) { BACK_DEFAULT_COLOR = color; }
public static void setNodeBackHilightColor( Color color ) { BACK_HILIGHT_COLOR = color; }
public static void setNodeBorderDragColor( Color color ) { BORDER_DRAG_COLOR = color; }
public static void setNodeBorderMouseOverColor( Color color ) { BORDER_MOUSE_OVER_COLOR = color; }
public static void setNodeBorderInactiveColor( Color color ) { BORDER_INACTIVE_COLOR = color; }
public static void setNodeTextColor( Color color ) { TEXT_COLOR = color; }
public static void setNodeTextFont( Font font ) { TEXT_FONT = font; }
public static void setNodeType( int type ) { DEFAULT_TYPE = type; }
/** Set the ID of this Node to the String <tt>id</tt>.
*/
public void setID( String id ) {
this.id = id;
}
/** Return the ID of this Node as a String.
*/
public String getID() {
return id;
}
/** Set the location of this Node provided the Point <tt>p</tt>.
*/
public void setLocation( Point p ) {
this.x = p.x;
this.y = p.y;
}
/** Return the location of this Node as a Point.
*/
public Point getLocation() {
return new Point((int)x,(int)y);
}
/** Set the visibility of this Node to the boolean <tt>v</tt>.
*/
public void setVisible( boolean v) {
visible = v;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -