prefuselib.java
来自「用applet实现很多应用小程序」· Java 代码 · 共 457 行 · 第 1/2 页
JAVA
457 行
* @param item the VisualItem to update
* @param val the visibility value to set
*/
public static void updateVisible(VisualItem item, boolean val) {
item.setStartVisible(item.isVisible());
item.setVisible(val);
item.setEndVisible(val);
}
/**
* Update the x-coordinate of an item. The current x value will become the
* new starting x value, while the given value will become the new current
* x and ending x values. This method also supports an optional referrer
* item, whose x coordinate will become the new starting x coordinate
* of item if item's current x value is NaN.
* @param item the VisualItem to update
* @param referrer an optional referrer VisualItem
* @param x the x value to set
*/
public static void setX(VisualItem item, VisualItem referrer, double x) {
double sx = item.getX();
if ( Double.isNaN(sx) )
sx = (referrer != null ? referrer.getX() : x);
item.setStartX(sx);
item.setEndX(x);
item.setX(x);
}
/**
* Update the y-coordinate of an item. The current y value will become the
* new starting y value, while the given value will become the new current
* x and ending y values. This method also supports an optional referrer
* item, whose y coordinate will become the new starting y coordinate
* of item if item's current x value is NaN.
* @param item the VisualItem to update
* @param referrer an optional referrer VisualItem
* @param y the y value to set
*/
public static void setY(VisualItem item, VisualItem referrer, double y) {
double sy = item.getY();
if ( Double.isNaN(sy) )
sy = (referrer != null ? referrer.getY() : y);
item.setStartY(sy);
item.setEndY(y);
item.setY(y);
}
// ------------------------------------------------------------------------
// Group Name Methods
/**
* Indicates if a group is a child group, a non-top-level data group in
* a set of nested data groups (e.g., the node or edge table of a
* graph or tree).
* @return true if the group is a nested, or child, group
*/
public static boolean isChildGroup(String group) {
return group.indexOf(GROUP_DELIMITER) != -1;
}
/**
* Get the parent group string of a child group, stripping off the
* bottom-level group from the group name (e.g., graph.nodes --> graph).
* @param group the group name
* @return the stripped parent group name
*/
public static String getParentGroup(String group) {
int idx = group.lastIndexOf(GROUP_DELIMITER);
return (idx < 0 ? null : group.substring(0,idx));
}
/**
* Get the tail group name of a child group, stripping all but the
* bottom-level group from the group name (e.g., graph.nodes --> nodes).
* @param group the group name
* @return the stripped child group name
*/
public static String getChildGroup(String group) {
int idx = group.lastIndexOf(GROUP_DELIMITER);
return (idx < 0 ? null : group.substring(idx+1));
}
/**
* Get the group name for the given parent and child group, simply
* concatenating them together with a group delimiter in between.
* @param parent the parent group name
* @param child the child group name
* @return the combined group name
*/
public static String getGroupName(String parent, String child) {
return parent + GROUP_DELIMITER + child;
}
/**
* For a given interpolated field name, get the name of the start
* field.
* @param field the data field
* @return the starting field for the interpolated column
*/
public static String getStartField(String field) {
return field+":start";
}
/**
* For a given interpolated field name, get the name of the end
* field.
* @param field the data field
* @return the ending field for the interpolated column
*/
public static String getEndField(String field) {
return field+":end";
}
// ------------------------------------------------------------------------
// Schema Routines
/**
* Get an instance of the default Schema used for VisualItem instances.
* Contains all the data members commonly used to model a visual element,
* such as x,y position, stroke, fill, and text, colors, size, font,
* and validated, visibility, interactive, fixed, highlight, and mouse
* hover fields.
* @return the VisualItem data Schema
*/
public static Schema getVisualItemSchema() {
Schema s = new Schema();
// booleans
s.addColumn(VisualItem.VALIDATED, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.VISIBLE, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.STARTVISIBLE, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.ENDVISIBLE, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.INTERACTIVE, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.EXPANDED, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.FIXED, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.HIGHLIGHT, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.HOVER, boolean.class, Boolean.FALSE);
s.addInterpolatedColumn(VisualItem.X, double.class);
s.addInterpolatedColumn(VisualItem.Y, double.class);
// bounding box
s.addColumn(VisualItem.BOUNDS, Rectangle2D.class, new Rectangle2D.Double());
// color
Integer defStroke = new Integer(ColorLib.rgba(0,0,0,0));
s.addInterpolatedColumn(VisualItem.STROKECOLOR, int.class, defStroke);
Integer defFill = new Integer(ColorLib.rgba(0,0,0,0));
s.addInterpolatedColumn(VisualItem.FILLCOLOR, int.class, defFill);
Integer defTextColor = new Integer(ColorLib.rgba(0,0,0,0));
s.addInterpolatedColumn(VisualItem.TEXTCOLOR, int.class, defTextColor);
// size
s.addInterpolatedColumn(VisualItem.SIZE, double.class, new Double(1));
// shape
s.addColumn(VisualItem.SHAPE, int.class,
new Integer(Constants.SHAPE_RECTANGLE));
// stroke
s.addColumn(VisualItem.STROKE, Stroke.class, new BasicStroke());
// font
Font defFont = FontLib.getFont("SansSerif",Font.PLAIN,10);
s.addInterpolatedColumn(VisualItem.FONT, Font.class, defFont);
// degree-of-interest
s.addColumn(VisualItem.DOI, double.class, new Double(Double.MIN_VALUE));
return s;
}
/**
* Get the minimal Schema needed for a unique VisualItem. Can be useful
* for derived groups that inherit other visual properties from a
* another visual data group.
* @return the minimal VisualItem data Schema
*/
public static Schema getMinimalVisualSchema() {
Schema s = new Schema();
// booleans
s.addColumn(VisualItem.VALIDATED, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.VISIBLE, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.STARTVISIBLE, boolean.class, Boolean.FALSE);
s.addColumn(VisualItem.ENDVISIBLE, boolean.class, Boolean.TRUE);
s.addColumn(VisualItem.INTERACTIVE, boolean.class, Boolean.TRUE);
// bounding box
s.addColumn(VisualItem.BOUNDS, Rectangle2D.class, new Rectangle2D.Double());
return s;
}
/**
* Get the VisualItem Schema used for axis tick marks and labels. Extends
* the VisualItem Schema with an additional end-point coordinate, a
* String label field, and numeric value field for storing the value
* which the axis label corresponds to.
* @return the Schema for axis tick marks and labels.
*/
public static Schema getAxisLabelSchema() {
Schema s = getVisualItemSchema();
s.setDefault(VisualItem.STARTVISIBLE, Boolean.FALSE);
Integer defColor = new Integer(ColorLib.gray(230));
s.setInterpolatedDefault(VisualItem.STROKECOLOR, defColor);
defColor = new Integer(ColorLib.gray(150));
s.setInterpolatedDefault(VisualItem.TEXTCOLOR, defColor);
Double nan = new Double(Double.NaN);
s.addInterpolatedColumn(VisualItem.X2, double.class);
s.addInterpolatedColumn(VisualItem.Y2, double.class);
s.addColumn(VisualItem.LABEL, String.class);
s.addColumn(VisualItem.VALUE, double.class, nan);
return s;
}
} // end of class PrefuseLib
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?