public void clear() { clearNodeSelection(); for (int i = 0; i < getCamera().getLayerCount(); i++) { getCamera().getLayer(i).removeAllChildren(); } getCamera().removeAllChildren(); repaint(); }
public void focusLost(FocusEvent e) { getCanvas().setBorder(FOCUS_LOST_BORDER); } };
protected void addGraphArc(GraphArc arc) { // copy the default arc style into the arc if ((getGraphArcStyle() != null) && !getGraphArcStyle().equals(arc.getArcStyle())) { arc.setArcStyle(getGraphArcStyle()); } // check if this arc is filtered // add the arc to the canvas if (arc instanceof PNode) { addArc((PNode) arc); } }
protected void addGraphItems(Collection<GraphNode> nodesToAdd, Collection<GraphArc> arcsToAdd) { for (GraphNode node : nodesToAdd) { addGraphNode(node); } for (GraphArc arc : arcsToAdd) { addGraphArc(arc); } }
protected void addGraphNode(GraphNode node) { // copy the default node style into the node if ((getGraphNodeStyle() != null) && !getGraphNodeStyle().equals(node.getNodeStyle())) { node.setNodeStyle(getGraphNodeStyle()); } // add the node to the canvas if (node instanceof PNode) { addNode((PNode) node); } }
public AbstractGraph() { super(); this.model = new DefaultGraphModel(); this.graphModelListeners = new ArrayList<GraphModelListener>(); this.layouts = new ArrayList<LayoutAction>(); addDefaultLayouts(); this.graphPopupListener = new GraphPopupListener(); getCamera().addInputEventListener(graphPopupListener); this.filterManager = new FilterManager(this); this.filterManager.addFilterChangedListener(filterListener); this.selectedNodes = new NodeCollection(); selectedNodes.addCollectionListener(selectionListener); this.matchingNodes = new NodeCollection(); matchingNodes.addCollectionListener(matchingListener); this.nodeStyle = new DefaultGraphNodeStyle(); this.arcStyle = new DefaultGraphArcStyle(); addFocusListener(focusListener); // register to use our custom tooltips CustomToolTipManager.sharedInstance().registerComponent(this); initializeLayers(); // this is needed to handle keyboard events getRoot().getDefaultInputManager().setKeyboardFocus(new KeyHandlerDelegate(getCamera())); }
protected PLayer getNodeLayer() { return getCamera().getLayer(NODE_LAYER_INDEX); }
protected void initializeLayers() { // one layer is automatically created (layer 0), see the PCanvas constructor // we'll let that one be the arc layer // now create and add the node layer (layer 1) PLayer nodeLayer = new PLayer(); getRoot().addChild(nodeLayer); getCamera().addLayer(NODE_LAYER_INDEX, nodeLayer); }
/** * Moves the tooltip to the left if the owner is on the right hand side * of the screen. */ private void adjustX(AbstractGraph graph, PNode owner) { Rectangle2D rect = owner.getBounds(); if(isCameraNode) rect = graph.getCamera().viewToLocal(owner.getBounds()); double maxX = graph.getWidth() / 3; maxX *= 2; if(getX() > maxX) { this.translate(-1 * (getWidth() + rect.getWidth()), 0); } }
/** * @see javax.swing.JComponent#getToolTipText(java.awt.event.MouseEvent) */ public String getToolTipText(MouseEvent e) { String tooltipText = ""; if (e != null) { PNode pnode = getCamera().pick(e.getX(), e.getY(), 1).getPickedNode(); if (pnode.getVisible()) { if (pnode instanceof GraphNode && isShowNodeTooltips()) { GraphNode node = (GraphNode) pnode; tooltipText = node.getTooltip(); ttBackground = node.getNodeStyle().getTooltipBackgroundColor(); ttTextColor = node.getNodeStyle().getTooltipTextColor(); ttFont = node.getNodeStyle().getTooltipFont(); } else if (pnode instanceof GraphArc) { GraphArc arc = (GraphArc) pnode; tooltipText = arc.getTooltip(); if (tooltipText == null || tooltipText.equals("")) { tooltipText = arc.getSource().getText() + " ---" + arc.getType() + "---> " + arc.getDestination().getText(); } ttBackground = arc.getArcStyle().getTooltipBackgroundColor(); ttTextColor = arc.getArcStyle().getTooltipTextColor(); ttFont = arc.getArcStyle().getTooltipFont(); } } } return (tooltipText.length() > 0 ? " " + tooltipText + " " : ""); }
/** * Adds the nodes and arcs to this graph/canvas. Also sets the graph node and arc style on every * node and arc. */ protected void loadModel() { clear(); addGraphItems(model.getAllNodes(), model.getAllArcs()); }
protected void addDefaultLayouts() { int style = LayoutStyles.NO_LAYOUT_NODE_RESIZING; addLayout(new LayoutAction(LayoutConstants.LAYOUT_GRID_BY_ALPHA, ResourceHandler.getIcon("icon_grid_layout.gif"), new GridLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_RADIAL, ResourceHandler.getIcon("icon_radial_layout.gif"), new RadialLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_SPRING, ResourceHandler.getIcon("icon_spring_layout.gif"), new SpringLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_TREE_VERTICAL, ResourceHandler.getIcon("icon_tree_layout.gif"), new TreeLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_TREE_HORIZONTAL, ResourceHandler.getIcon("icon_tree_layout_horizontal.gif"), new HorizontalTreeLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_DIRECTED_VERTICAL, ResourceHandler.getIcon("icon_tree_layout.gif"), new DirectedGraphLayoutAlgorithm(style), this)); addLayout(new LayoutAction(LayoutConstants.LAYOUT_DIRECTED_HORIZONTAL, ResourceHandler.getIcon("icon_tree_layout_horizontal.gif"), new HorizontalDirectedGraphLayoutAlgorithm(style), this)); // important - set the last layout this.lastLayout = getLayout(LayoutConstants.LAYOUT_DIRECTED_VERTICAL); }
public void graphNodeAdded(GraphNode node) { addGraphNode(node); } public void graphNodeRemoved(GraphNode node) {
public void graphArcAdded(GraphArc arc) { addGraphArc(arc); } public void graphArcRemoved(GraphArc arc) {
public void addGraphInputListener(PInputEventListener listener) { getCamera().addInputEventListener(listener); }
public void focusGained(FocusEvent e) { getCanvas().setBorder(FOCUS_GAINED_BORDER); }
protected PLayer getArcLayer() { return getCamera().getLayer(ARC_LAYER_INDEX); }
/** * Sets the tooltip location relative the owner's position in the global coordinate system. */ private void initLocation(AbstractGraph graph, PNode owner) { PCamera camera = graph.getCanvas().getCamera(); Rectangle bounds = graph.getCanvas().getBounds(); Rectangle2D rect = owner.getBounds(); //camera.viewToLocal(owner.getBounds()); if(isCameraNode) rect = camera.viewToLocal(owner.getBounds()); double x = rect.getX(); double y = rect.getY(); x += rect.getWidth(); x = Math.min(x, bounds.getWidth() - this.getWidth()); y = Math.max(y, 0); this.setX(x); this.setY(y); }
public void removeGraphInputListener(PInputEventListener listener) { getCamera().removeInputEventListener(listener); }
private void hideToolTip(DefaultGraphNode node) { PCamera camera = graph.getCanvas().getCamera(); if(toolTip != null) { camera.removeChild(toolTip); camera.repaint(); toolTip = null; } }