下面列出了javax.swing.undo.AbstractUndoableEdit#org.jgraph.graph.GraphConstants 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
*
* @param vertex
*
* @return
*/
private static AttributeMap commonVertexAttributes(OverviewVertex vertex) {
AttributeMap map = new AttributeMap();
GraphConstants.setAutoSize(map, true);
GraphConstants.setInset(map, 5);
GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
GraphConstants.setOpaque(map, true);
ImageIcon icon = vertex.getThumbnail();
if (icon != null) {
GraphConstants.setIcon(map, vertex.getThumbnail());
} else {
GraphConstants.setIcon(map, new ImageIcon());
}
GraphConstants.setVerticalTextPosition(map, SwingConstants.TOP);
return map;
}
/**
* Returns an attribute map for Overview view edges
*
*
* @param edge
* @return a map of attributes to be used for a sketchnode
*/
public static AttributeMap viewEdgeAttributes(ViewDefinitionEdge edge) {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
Color color = getColor("edge_overview_view");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth("edge_overview_view", 1.5));
return map;
}
/**
* Checks to see if any of the query nodes have moved and, if so, updates them
* and sets the view to dirty. If the view is already dirty, we don't have to do
* anything at all.
*/
public void checkDirty() {
if (_dirty) {
return;
}
for (QueryNode n : _nodes.values()) {
if (n == null) {
// not sure why this would ever be null
} else {
Rectangle2D newBounds = GraphConstants.getBounds(n.getAttributes());
if ((int) newBounds.getX() != n.getLastKnownX()) {
setDirty(true);
return;
}
}
}
}
/**
* Returns an attribute map for normal (non-injective, non-partial) edges.
*
* @return a map of attributes to be used for new normal edges
*/
private AttributeMap normalEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
Color color = getColor(_mode + "edge_normal");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_normal", 1.5));
return map;
}
/**
* Returns the attribute map for injective edges.
*
* @return a map of attributes to be used for new injective edges
*/
private AttributeMap injectiveEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_DIAMOND);
GraphConstants.setBeginFill(map, false);
GraphConstants.setBeginSize(map, 15);
Color color = getColor(_mode + "edge_injective");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_injective", 1.5));
return map;
}
/**
* Returns the attribute map for partial edges.
*
* @return a map of attributes to be used for partial edges
*/
private AttributeMap partialEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_LINE);
GraphConstants.setBeginFill(map, true);
GraphConstants.setBeginSize(map, 15);
Color color = getColor(_mode + "edge_partial");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_partial", 1.5));
return map;
}
/**
* Returns the attribute map for virtual edges.
*
* @return a map of attributes to be used for new virtual edges
*/
private AttributeMap virtualEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_NONE);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_NONE);
GraphConstants.setDashPattern(map, new float[] { 5.0f, 3.0f });
Color color = getColor(_mode + "edge_virtual");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_virtual", 1.5));
return map;
}
/**
* Returns an attribute map for normal (non-injective, non-partial) edges.
*
* @return a map of attributes to be used for new normal edges
*/
private AttributeMap normalEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
Color color = getColor(_mode + "edge_normal");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_normal", 1.5));
return map;
}
/**
* Returns the attribute map for injective edges.
*
* @return a map of attributes to be used for new injective edges
*/
private AttributeMap injectiveEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_DIAMOND);
GraphConstants.setBeginFill(map, false);
GraphConstants.setBeginSize(map, 15);
Color color = getColor(_mode + "edge_injective");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_injective", 1.5));
return map;
}
/**
* Returns the attribute map for partial edges.
*
* @return a map of attributes to be used for partial edges
*/
private AttributeMap partialEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_TECHNICAL);
GraphConstants.setEndFill(map, true);
GraphConstants.setEndSize(map, 10);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_LINE);
GraphConstants.setBeginFill(map, true);
GraphConstants.setBeginSize(map, 15);
Color color = getColor(_mode + "edge_partial");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_partial", 1.5));
return map;
}
/**
* Returns the attribute map for virtual edges.
*
* @return a map of attributes to be used for new virtual edges
*/
private AttributeMap virtualEdgeAttributes() {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, GraphConstants.ARROW_NONE);
GraphConstants.setLineBegin(map, GraphConstants.ARROW_NONE);
GraphConstants.setDashPattern(map, new float[] { 5.0f, 3.0f });
Color color = getColor(_mode + "edge_virtual");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_virtual", 1.5));
return map;
}
/**
* Removes the visuals from the sketch (when hiding)
*/
private void removeVisualsFromModel() {
// Push loading state
_theModel.getStateManager().pushState(new LoadingState<>(_theModel));
_theModel.getGraphModel().beginInsignificantUpdate();
GraphLayoutCache glc = _theModel.getGraphLayoutCache();
glc.remove(_visuals.toArray(new GuideEdge[0]));
_visuals.clear();
_edgesVisualized = false;
GraphConstants.setSelectable(getAttributes(), false);
_theModel.refresh();
_theModel.getGraphModel().cancelInsignificantUpdate();
// Pop state
_theModel.getStateManager().popState();
}
/**
* When pushed on, the first thing done is clearing the selection and then
* disabling selection for all items except for edges.
*/
@Override
@SuppressWarnings("rawtypes")
public void pushedOn() {
setNextButton(false);
setCancelButton(true);
setFinishButton(false);
_selectable = new Hashtable();
_unselectable = new Hashtable();
GraphConstants.setSelectable(_selectable, true);
GraphConstants.setSelectable(_unselectable, false);
// Initially, we allow all edges and entities to be selected
_ourModel.clearSelection();
_ourModel.refresh();
// Gets pushed on by all "add constraint" states. We don't want to be
// able to imbed adding constraints
_ourModel.getFrame().enableAddConstraintItems(false);
}
/**
* When pushed on, the first thing done is clearing the selection and then
* disabling selection for all items except for edges.
*/
@Override
@SuppressWarnings("rawtypes")
public void pushedOn() {
setNextButton(false);
setCancelButton(true);
setFinishButton(false);
_selectable = new Hashtable();
_unselectable = new Hashtable();
GraphConstants.setSelectable(_selectable, true);
GraphConstants.setSelectable(_unselectable, false);
// Initially, we allow all edges and entities to be selected
_ourModel.clearSelection();
_ourModel.refresh();
// Gets pushed on by all "add constraint" states. We don't want to be
// able to imbed adding constraints
_ourModel.getFrame().enableAddConstraintItems(false);
}
/**
* Returns the common attribute mapping for edges. Used by
* normalEdgeAttributes() et al. to establish the common attributes for an edge.
*
* @return The attribute mapping
*/
@SuppressWarnings("static-access")
public static AttributeMap commonEdgeAttributes() {
AttributeMap map = new AttributeMap();
GraphConstants.setLabelAlongEdge(map, true);
GraphConstants.setBendable(map, false);
GraphConstants.setMoveable(map, false);
GraphConstants.setConnectable(map, false);
GraphConstants.setDisconnectable(map, false);
EdgeRouter er = EdgeRouter.getSharedInstance();
er.setEdgeSeparation(20.0);
er.setEdgeDeparture(50.0);
GraphConstants.setRouting(map, er);
GraphConstants.setLineStyle(map, GraphConstants.STYLE_SPLINE);
return map;
}
public RelationEdge(Relation aRelation, TableCell aImporting, TableCell aExporting) {
super(aRelation);
GraphConstants.setLineStyle(getAttributes(), GraphConstants.STYLE_ORTHOGONAL);
GraphConstants.setConnectable(getAttributes(), false);
GraphConstants.setDisconnectable(getAttributes(), false);
GraphConstants.setBendable(getAttributes(), true);
GraphConstants.setLineWidth(getAttributes(), 1);
GraphConstants.setLineBegin(getAttributes(), LINE_BEGIN);
GraphConstants.setLineEnd(getAttributes(), LINE_END);
setSource(aImporting.getChildAt(0));
setTarget(aExporting.getChildAt(0));
}
public DefaultGraphCell createVertex(String name, double x, double y, Color bg, boolean raised) {
// Create vertex with the given name
DefaultGraphCell cell = new DefaultGraphCell(name);
GraphConstants.setBorder(cell.getAttributes(), BorderFactory.createEtchedBorder());
GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(x, y, 10, 10));
GraphConstants.setResize(cell.getAttributes(), true);
GraphConstants.setAutoSize(cell.getAttributes(), true);
// Set fill color
if (bg != null) {
GraphConstants.setOpaque(cell.getAttributes(), true);
GraphConstants.setGradientColor(cell.getAttributes(), bg);
}
// Set raised border
if (raised)
GraphConstants.setBorder(cell.getAttributes(), BorderFactory.createRaisedBevelBorder());
else
// Set black border
GraphConstants.setBorderColor(cell.getAttributes(), Color.black);
return cell;
}
/**
* Returns an attribute map for SketchNodes
*
* @param node
* @return The attribute mapping
*/
private static AttributeMap sketchAttributes(SketchNode node) {
AttributeMap map = commonVertexAttributes(node);
GraphConstants.setBorder(map, BorderFactory.createLineBorder(getColor("overview_sketch_border"),
getIntWidth("overview_sketch_border", 2)));
GraphConstants.setBackground(map, getColor("overview_sketch_bg"));
GraphConstants.setForeground(map, getColor("overview_sketch_fg"));
return map;
}
/**
* Returns an attribute map for Overview views
*
* @param node
* @return The attribute mapping
*/
private static AttributeMap viewAttributes(ViewNode node) {
AttributeMap map = commonVertexAttributes(node);
GraphConstants.setBorder(map, BorderFactory.createLineBorder(getColor("overview_view_border"),
getIntWidth("overview_view_border", 2)));
GraphConstants.setBackground(map, getColor("overview_view_bg"));
GraphConstants.setForeground(map, getColor("overview_view_fg"));
return map;
}
/**
* Accessor for the X coordinate
*
* @return The x coordinate
*/
public int getX() {
Rectangle2D bounds = GraphConstants.getBounds(getAttributes());
if (bounds != null) {
return (int) bounds.getX();
}
return _initX;
}
/**
* Accessor for the Y Coordinate
*
* @return The Y Coordinate
*/
public int getY() {
Rectangle2D bounds = GraphConstants.getBounds(getAttributes());
if (bounds != null) {
return (int) bounds.getY();
}
return _initY;
}
/**
* Add one one of our verticies to the overview
*
* @param theNode The node to be added
*/
public void addVertex(OverviewVertex theNode) {
// The next call will fire a rendering. At this point, the model adapter
// does not know
// where it should place the node, and picks a default value. This will
// cause an update
// in our Node's x and y coordinates, making it forget where it was
// initialized.
// We store it's initializeded position so as not to lose them in the
// first rendering.
int initX = theNode.getX();
int initY = theNode.getY();
// Make sure the name is unique; increment it if not.
if (isNameUsed(theNode.getName())) {
theNode.setName(getNewName(theNode.getName()));
}
// Add our sketch to the graph
getGraphLayoutCache().insert(theNode);
// Add our vertex to the appropriate map
if (theNode instanceof SketchNode) {
_sketchNodes.put(theNode.toString(), (SketchNode) theNode);
_appFrame.getInfoTreeUI().addSketch((SketchNode) theNode);
} else if (theNode instanceof ViewNode) {
_viewNodes.put(theNode.toString(), (ViewNode) theNode);
_appFrame.getInfoTreeUI().addView((ViewNode) theNode);
}
// Set the on-screen position of our sketch to the attributes of the
// sketch
AttributeMap nAttribs = theNode.getAttributes();
GraphConstants.setAutoSize(nAttribs, true);
GraphConstants.setBounds(nAttribs, new Rectangle2D.Double(initX, initY, 0, 0));
// Reload the graph to reflect the new changes
refresh(theNode);
}
/**
* TRIANGLES CF2012 Set the attributes for display of a triangle edge.
*
* @param edge the edge to read attributes from
* @return a map of attributes to be used for new triangle edges
*/
private static AttributeMap triangleEdgeAttributes(
TriangleEdge<ViewFrame, ViewGraphModel, View, QueryNode, View_Edge> edge) {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, edge.getLineEnd());
GraphConstants.setLineBegin(map, edge.getLineBegin());
GraphConstants.setLineWidth(map, edge.getWidth());
GraphConstants.setLineColor(map, edge.getColor());
GraphConstants.setForeground(map, edge.getColor());
GraphConstants.setDashPattern(map, new float[] { edge.getWidth(), 3 });
return map;
}
/**
* Returns the attribute map for highlighted virtual edges.
*
* @return a map of attributes to be used for highlighted virtual edges
*/
private AttributeMap virtualHighlightedEdgeAttributes() {
AttributeMap map = virtualEdgeAttributes();
Color color = getColor(_mode + "edge_virtual_highlighted");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_virtual_highlighted", 1.5));
return map;
}
/**
* Returns the attribute map for vertices (i.e. EntityNodes).
*
* @return a map of attributes to be used for new vertices
*/
private AttributeMap vertexAttributes() {
AttributeMap map = new AttributeMap();
GraphConstants.setAutoSize(map, true);
GraphConstants.setInset(map, 5);
GraphConstants.setBorder(map, BorderFactory.createLineBorder(getColor(_mode + "entity_border"),
getIntWidth(_mode + "entity_border", 1)));
GraphConstants.setBackground(map, getColor(_mode + "entity_bg"));
GraphConstants.setForeground(map, getColor(_mode + "entity_fg"));
GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
GraphConstants.setOpaque(map, true);
return map;
}
/**
* Returns the attribute map for virtual vertices (i.e. constaint nodes).
*
* @return a map of attributes to be used for new virtual vertices
*/
private AttributeMap virtualVertexAttributes() {
AttributeMap map = new AttributeMap();
GraphConstants.setAutoSize(map, true);
GraphConstants.setInset(map, 5);
GraphConstants.setBorder(map, BorderFactory.createLineBorder(getColor(_mode + "constraint_border"),
getIntWidth(_mode + "constraint_border", 1)));
GraphConstants.setBackground(map, getColor(_mode + "constraint_bg"));
GraphConstants.setForeground(map, getColor(_mode + "constraint_fg"));
GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
GraphConstants.setOpaque(map, true);
return map;
}
/**
* Override the super getAttributes() to reflect whether or not this edge is
* selectable.
*
* @return
*/
@Override
public AttributeMap getAttributes() {
final AttributeMap attrs = super.getAttributes();
// A SketchEdge is selectable unless we're in manipulation mode
final Sketch sketch = _sourceObj.getMModel();
GraphConstants.setSelectable(attrs, sketch.getFrame().getMode() != SketchFrame.Mode.MANIPULATE);
return attrs;
}
/**
* TRIANGLES CF2012 Set the attributes for display of a triangle edge.
*
* @param edge the edge to read attributes from
* @return a map of attributes to be used for new triangle edges
*/
private static AttributeMap triangleEdgeAttributes(
TriangleEdge<SketchFrame, SketchGraphModel, Sketch, EntityNode, SketchEdge> edge) {
AttributeMap map = commonEdgeAttributes();
GraphConstants.setLineEnd(map, edge.getLineEnd());
GraphConstants.setLineBegin(map, edge.getLineBegin());
GraphConstants.setLineWidth(map, edge.getWidth());
GraphConstants.setLineColor(map, edge.getColor());
GraphConstants.setForeground(map, edge.getColor());
GraphConstants.setDashPattern(map, new float[] { edge.getWidth(), 3 });
return map;
}
/**
* Returns the attribute map for highlighted virtual edges.
*
* @return a map of attributes to be used for highlighted virtual edges
*/
private AttributeMap virtualHighlightedEdgeAttributes() {
AttributeMap map = virtualEdgeAttributes();
Color color = getColor(_mode + "edge_virtual_highlighted");
GraphConstants.setLineColor(map, color);
GraphConstants.setForeground(map, color);
GraphConstants.setLineWidth(map, getWidth(_mode + "edge_virtual_highlighted", 1.5));
return map;
}
/**
* Returns the attribute map for vertices (i.e. EntityNodes).
*
* @return a map of attributes to be used for new vertices
*/
private AttributeMap vertexAttributes() {
AttributeMap map = new AttributeMap();
GraphConstants.setAutoSize(map, true);
GraphConstants.setInset(map, 5);
GraphConstants.setBorder(map, BorderFactory.createLineBorder(getColor(_mode + "entity_border"),
getIntWidth(_mode + "entity_border", 1)));
GraphConstants.setBackground(map, getColor(_mode + "entity_bg"));
GraphConstants.setForeground(map, getColor(_mode + "entity_fg"));
GraphConstants.setFont(map, GraphConstants.DEFAULTFONT.deriveFont(Font.BOLD, 12));
GraphConstants.setOpaque(map, true);
return map;
}