📄 graphconstants.java
字号:
/*
* @(#)GraphConstants.java 1.0 1/1/02
*
* Copyright (c) 2001-2004, Gaudenz Alder
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - 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.
* - Neither the name of JGraph nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS 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 THE COPYRIGHT OWNER OR 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 org.jgraph.graph;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.border.Border;
/**
* A collection of well known or common attribute keys and methods to apply
* to an Map to get/set the properties in a typesafe manner. The following
* attributes and methods need special attention: removeAttributes,
* removeAll and value. RemoveAttributes and RemoveAll are not stored
* in a map, but remove the specified entries. The value entry of a
* propertyMap is always in sync with the userObject of a GraphCell.
* The isMoveable, isAutoSize and isSizeable are used indepedently
* (see http://sourceforge.net/forum/forum.php?thread_id=770111&forum_id=140880)
*
* @version 1.0 1/1/02
* @author Gaudenz Alder
*/
public class GraphConstants {
/* Indicates if negative coordinates are allowed. */
public static boolean NEGATIVE_ALLOWED = false;
// Should not be necessary. See cloneMap()
public static final Point dummyPoint = new Point();
public static final Font defaultFont = UIManager.getFont("Tree.font");
public static String[] availableKeys =
new String[] {
GraphConstants.ABSOLUTE,
GraphConstants.AUTOSIZE,
GraphConstants.BACKGROUND,
GraphConstants.BEGINFILL,
GraphConstants.BEGINSIZE,
GraphConstants.BENDABLE,
GraphConstants.BORDER,
GraphConstants.BORDERCOLOR,
GraphConstants.BOUNDS,
GraphConstants.CONNECTABLE,
GraphConstants.DASHPATTERN,
GraphConstants.DISCONNECTABLE,
GraphConstants.EDITABLE,
GraphConstants.ENDFILL,
GraphConstants.ENDSIZE,
GraphConstants.FONT,
GraphConstants.FOREGROUND,
GraphConstants.HORIZONTAL_ALIGNMENT,
GraphConstants.VERTICAL_ALIGNMENT,
GraphConstants.ICON,
GraphConstants.LABELPOSITION,
GraphConstants.LINEBEGIN,
GraphConstants.LINECOLOR,
GraphConstants.LINEEND,
GraphConstants.LINESTYLE,
GraphConstants.LINEWIDTH,
GraphConstants.MOVEABLE,
GraphConstants.OFFSET,
GraphConstants.OPAQUE,
GraphConstants.POINTS,
GraphConstants.ROUTING,
GraphConstants.SIZE,
GraphConstants.SIZEABLE,
GraphConstants.VALUE };
/** Default Font size. */
public static final float DEFAULTFONTSIZE = 12;
/** Default Font style. */
public static final int DEFAULTFONTSTYLE = Font.PLAIN;
/** Default decoration size. */
public static final int DEFAULTDECORATIONSIZE = 10;
/** 100 percent unit for relative positioning. Current value is 1000. */
public static final int PERMILLE = 1000;
/** Global Stroke To Highlight Selection */
static protected float[] dash = { 5f, 5f };
static public Stroke SELECTION_STROKE =
new BasicStroke(
1,
BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER,
10.0f,
dash,
0.0f);
/** Represents no decoration */
public static final int ARROW_NONE = 0;
/** Represents a classic arrow decoration */
public static final int ARROW_CLASSIC = 1;
/** Represents a technical arrow decoration */
public static final int ARROW_TECHNICAL = 2;
/** Represents a simple arrow decoration */
public static final int ARROW_SIMPLE = 4;
/** Represents a circle decoration */
public static final int ARROW_CIRCLE = 5;
/** Represents a line decoration */
public static final int ARROW_LINE = 7;
/** Represents a double line decoration */
public static final int ARROW_DOUBLELINE = 8;
/** Represents a diamond decoration */
public static final int ARROW_DIAMOND = 9;
/** Represents an orthogonal line style */
public static final int STYLE_ORTHOGONAL = 11;
/** Represents an quadratic line style */
public static final int STYLE_QUADRATIC = 12;
/** Represents an bezier line style */
public static final int STYLE_BEZIER = 13;
/**
* A simple default Routing.
*/
public static final Edge.Routing ROUTING_SIMPLE =
new DefaultEdge.DefaultRouting();
/**
* Key for the <code>replaceAttributes</code> attribute. This special
* attribute contains a Boolean instance indicating whether a map of
* attributes should replace the attributes of the receiving view.
*/
public final static String REPLACEATTRIBUTES = "replaceAttributes";
/**
* Key for the <code>removeAttributes</code> attribute. This special
* attribute contains a list of attribute-keys which should be removed
* at the receiving views.
*/
public final static String REMOVEATTRIBUTES = "removeAttributes";
/**
* Key for the <code>removeAll</code> attribute. This causes the
* receivers attributes to be replaced by the the map that contains
* this attribute.
*/
public final static String REMOVEALL = "removeAll";
/**
* Key for the <code>icon</code> attribute. Use instances of
* Icon as values for this key.
*/
public final static String ICON = "icon";
/**
* Key for the <code>font</code> attribute. Use instances of
* Font as values for this key.
*/
public final static String FONT = "font";
/**
* Key for the <code>opaque</code> attribute. Use instances of
* Boolean as values for this key.
*/
public final static String OPAQUE = "opaque";
/**
* Key for the <code>border</code> attribute. Use instances of
* Border as values for this key. Optionally, you can set the global
* instance of LineBorder.
*/
public final static String BORDER = "border";
/**
* Key for the <code>linecolor</code> attribute. Use instances of
* Color as values for this key.
*/
public final static String LINECOLOR = "linecolor";
/**
* Key for the <code>bordercolor</code> attribute. Use instances of
* Color as values for this key.
*/
public final static String BORDERCOLOR = "bordercolor";
/**
* Key for the <code>linewidth</code> attribute. Use instances of
* Float as values for this key.
*/
public final static String LINEWIDTH = "linewidth";
/**
* Key for the <code>foreground</code> attribute. Use instances of
* Color as values for this key.
*/
public final static String FOREGROUND = "foregroundColor";
/**
* Key for the <code>background</code> attribute. Use instances of
* Color as values for this key.
*/
public final static String BACKGROUND = "backgroundColor";
/**
* Key for the <code>verticalAlignment</code> attribute. Use instances of
* Integer as values for this key. Constants defined in JLabel class.
*/
public final static String VERTICAL_ALIGNMENT = "verticalAlignment";
/**
* Key for the <code>horizontalAlignment</code> attribute. Use instances of
* Integer as values for this key. Constants defined in JLabel class.
*/
public final static String HORIZONTAL_ALIGNMENT = "horizontalAlignment";
/**
* Key for the <code>verticalTextPosition</code> attribute. Use instances of
* Integer as values for this key. Constants defined in JLabel class.
*/
public final static String VERTICAL_TEXT_POSITION = "verticalTextPosition";
/**
* Key for the <code>horizontalTextPosition</code> attribute. Use instances of
* Integer as values for this key. Constants defined in JLabel class.
*/
public final static String HORIZONTAL_TEXT_POSITION =
"horizontalTextPosition";
/**
* Key for the <code>dashPattern</code> attribute. Use instances of
* float[] as values for this key.
*/
public final static String DASHPATTERN = "dashPattern";
/**
* Key for the <code>lineStyle</code> attribute. Use instances of
* Integer as values for this key. Constants defined in this class.
*/
public final static String LINESTYLE = "lineStyle";
/**
* Key for the <code>start</code> attribute. Use instances of
* Integer as values for this key. Constants defined in this class.
*/
public final static String LINEBEGIN = "lineBegin";
/**
* Key for the <code>start</code> attribute. Use instances of
* Integer as values for this key. Constants defined in this class.
*/
public final static String LINEEND = "lineEnd";
/**
* Key for the <code>startsize</code> attribute. Use instances of
* Integer as values for this key.
*/
public final static String BEGINSIZE = "beginSize";
/**
* Key for the <code>endsize</code> attribute. Use instances of
* Integer as values for this key.
*/
public final static String ENDSIZE = "endsize";
/**
* Key for the <code>startsize</code> attribute. Use instances of
* Integer as values for this key.
*/
public final static String BEGINFILL = "beginFill";
/**
* Key for the <code>endsize</code> attribute. Use instances of
* Integer as values for this key.
*/
public final static String ENDFILL = "endFill";
/**
* Key for the <code>value</code> attribute. You can use any Object
* as a value for this key.
*/
public static final String VALUE = "value";
/**
* Key for the <code>editable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String EDITABLE = "editable";
/**
* Key for the <code>moveable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String MOVEABLE = "moveable";
/**
* Key for the <code>sizeable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String SIZEABLE = "sizeable";
/**
* Key for the <code>sizeable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String AUTOSIZE = "autosize";
/**
* Key for the <code>sizeable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String BENDABLE = "bendable";
/**
* Key for the <code>moveable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String CONNECTABLE = "connectable";
/**
* Key for the <code>moveable</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String DISCONNECTABLE = "disconnectable";
/**
* Key for the <code>bounds</code> attribute. Use instances of
* Rectangle as values for this key.
*/
public static final String BOUNDS = "bounds";
/**
* Key for the <code>points</code> attribute. Use instances of List
* as values for this key. The list should contain Point instances.
*/
public static final String POINTS = "points";
/**
* Key for the <code>routing</code> attribute. Use instances of EdgeView.EdgeRouter
* as values for this key. The list should contain Point instances.
*/
public static final String ROUTING = "routing";
/**
* Key for the <code>labelposition</code> attribute. Use instances of
* Point as values for this key.
*/
public static final String LABELPOSITION = "labelposition";
/**
* Key for the <code>absolute</code> attribute. Use instances of
* Boolean as values for this key.
*/
public static final String ABSOLUTE = "absolute";
/**
* Key for the <code>translate</code> attribute. Use instances of
* Point as values for this key.
*/
public static final String OFFSET = "offset";
/**
* Key for the <code>resize</code> attribute. Use instances of
* Dimension as values for this key.
*/
public static final String SIZE = "size";
//
// Attributes
//
public static Map createAttributes(Object cell, Object key, Object value) {
return createAttributes(
new Object[] { cell },
new Object[] { key },
new Object[] { value });
}
public static Map createAttributes(
Object[] cells,
Object key,
Object value) {
return createAttributes(
cells,
new Object[] { key },
new Object[] { value });
}
/**
* Returns a new (nested) map, from cells to attribute maps. The attributes are
* populated with the (key, value)-pairs specified by the two given arrays. The
* <code>keys</code> and <code>values</code> parameters must match in size.
*/
public static Map createAttributes(
Object[] cells,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -