/** * Determines if the given graphNode is expanded. * * @return True if already expanded. */ public boolean isExpanded(GraphNode graphNode) { int modelArcsSize = graphNode.getArcs().size(); int frameArcsSize = getNodeToArcCount((OWLEntity) graphNode.getUserObject()); return modelArcsSize >= frameArcsSize; } }
protected AffineTransform createTransform(GraphNode node) { Rectangle2D bounds = node.getBounds(); double oldW = bounds.getWidth(); double oldH = bounds.getHeight(); double newW = node.getWidthInLayout(); double newH = node.getHeightInLayout(); double dw = newW - oldW; double dh = newH - oldH; double dx = (node.getXInLayout() - bounds.getX()); double dy = (node.getYInLayout() - bounds.getY()); AffineTransform at = new AffineTransform(); boolean valid = false; if ((Math.abs(dx) > DELTA) || (Math.abs(dy) > DELTA)) { at.translate(dx, dy); valid = true; } if (resizeNodes && ((oldW != 0) && (oldH != 0)) && ((Math.abs(dw) > DELTA) || (Math.abs(dh) > DELTA))) { double sx = (newW / oldW); double sy = (newH / oldH); // TODO I don't know if this actually works! at.scale(sx, sy); valid = true; } if (!valid) { at = null; } return at; }
protected void addNodeInternal(GraphNode node) { if ((node != null) && !nodes.containsKey(node.getUserObject())) { // this should be the ONLY place where nodes are added to the map nodes.put(node.getUserObject(), node); if (!nodeTypes.contains(node.getType())) { nodeTypes.add(node.getType()); fireNodeTypeAddedEvent(node.getType()); } fireNodeAddedEvent(node); } }
/** * Expands the given graphNode based on a specific arcType and keeping existing nodes. * * @param graphNode */ public void expandNode(GraphNode graphNode, String arcType) { graphNode.setHighlighted(false); restrictToArcType = arcType; showNeighborhood((OWLEntity) graphNode.getUserObject(), false); restrictToArcType = ""; }
public boolean containsNode(GraphNode node) { if (node != null) { return nodes.containsKey(node.getUserObject()); } return false; }
if(!node.isFixedLocation()) { if (animate) { AffineTransform transform = createTransform(node); node.setLocation(node.getXInLayout(), node.getYInLayout());
/** * Adds a GraphArc to the model if it doesn't already exist. * * @return The created or found GraphArc. */ protected GraphArc addArc(OWLEntity srcEntity, OWLEntity destEntity, String relType, Icon icon) { if (!relType.contains(restrictToArcType)) { return null; } boolean newNode = true; if (getNode(destEntity) != null) { newNode = false; } GraphNode srcNode = addNode(srcEntity); GraphNode destNode = addNode(destEntity); if (newNode) { destNode.setLocation(srcNode.getBounds().getX(), srcNode.getBounds().getY()); } String key = srcEntity.toString() + relType + destEntity.toString(); DefaultGraphArc arc = (DefaultGraphArc) addArc(key, srcNode, destNode, relType, icon); //arc.setType(relType); // for this sample the arc types work backworks (is_a, etc) arc.setInverted(true); return arc; }
/** * @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 + " " : ""); }
/** * Expands a node if it is not already expanded, otherwise it collapses it. * * @param graphNode The node to expand or collapse. */ private void expandCollapseNode(GraphNode graphNode) { graphNode.setHighlighted(false); graphNode.moveToFront(); if (graphModel.isExpanded(graphNode)) { graphModel.collapseNode(graphNode); } else { graphModel.expandNode(graphNode); } graph.performLayout(); }
public Collection<GraphArc> getArcs(Object nodeUserObject) { if (nodes.containsKey(nodeUserObject)) { GraphNode node = nodes.get(nodeUserObject); return node.getArcs(); } // not sure if this is necessary or a good idea if (nodeUserObject instanceof GraphNode) { GraphNode node = (GraphNode) nodeUserObject; return node.getArcs(); } // return null or empty list? return Collections.emptyList(); }
public void setTransform(AffineTransform at) { //node.setTransform(at); node.setLocation(startX + at.getTranslateX(), startY + at.getTranslateY()); }
/** * Collapses the given graphNode. */ public void collapseNode(GraphNode graphNode) { Set<IRI> seen = new HashSet<IRI>(); graphNode.setHighlighted(false); collapseNode(graphNode, seen); }
public Point2D getOverlayIconPosition(GraphNode graphNode) { if (overlayIconPosition != null) { return overlayIconPosition; } // if no position is set, return a default position of top left return getTopLeft(graphNode.getBounds()); }
public void collectionChanged(GraphNodeCollectionEvent evt) { for (GraphNode node : evt.getOldNodes()) { node.setSelected(false); } for (GraphNode node : evt.getNewNodes()) { node.setSelected(true); } } };
public Collection<GraphNode> getConnectedNodes(Object nodeUserObject) { if (nodes.containsKey(nodeUserObject)) { GraphNode node = nodes.get(nodeUserObject); return node.getConnectedNodes(); } // not sure if this is necessary or a good idea? if (nodeUserObject instanceof GraphNode) { GraphNode node = (GraphNode) nodeUserObject; return node.getConnectedNodes(); } // return null or empty list? return Collections.emptyList(); }
protected void addArcInternal(DefaultGraphArc arc) { // this is the ONLY place where arcs are added arcs.put(arc.getUserObject(), arc); if (!arcTypes.contains(arc.getType())) { arcTypes.add(arc.getType()); fireArcTypeAddedEvent(arc.getType()); } // add this arc to the source and destination nodes arc.getSource().addArc(arc); arc.getDestination().addArc(arc); fireArcAddedEvent(arc); }
/** * Creates a GraphArc with the given parameters without actually adding the GraphNodes or * GraphArc to the model. * * @return A GraphArc object. */ protected GraphArc createArc(GraphNode srcNode, GraphNode destNode, String relType, Icon icon) { String key = srcNode.getUserObject().toString() + relType + destNode.getUserObject().toString(); return new DefaultGraphArc(key, srcNode, destNode, icon, relType); }
/** * Determines whether the given GraphNode is removable. It is removable if it does not have any * arcs or the only arcs it has are self loops. * * @param node * @return True if removable. */ private boolean isRemovable(GraphNode node) { for (GraphArc arc : node.getArcs()) { if (!arc.getDestination().equals(arc.getSource())) { return false; } } return true; }