public GraphNode getSourceNode(Object arcUserObject) { if (arcs.containsKey(arcUserObject)) { GraphArc arc = arcs.get(arcUserObject); return arc.getSource(); } // not sure if this is necessary or a good idea if (arcUserObject instanceof GraphArc) { GraphArc arc = (GraphArc) arcUserObject; return arc.getSource(); } return null; }
public Collection<GraphNode> getConnectedNodes() { ArrayList<GraphNode> connectedNodes = new ArrayList<GraphNode>(); for (GraphArc arc : getArcs()) { GraphNode src = arc.getSource(); GraphNode dest = arc.getDestination(); GraphNode nodeToAdd = null; if (this == src) { nodeToAdd = dest; } else if (this == dest) { nodeToAdd = src; } if ((nodeToAdd != null) && !connectedNodes.contains(nodeToAdd)) { connectedNodes.add(nodeToAdd); } } return connectedNodes; }
/** * 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; }
public Collection<GraphArc> getArcs(boolean incoming, boolean outgoing) { Collection<GraphArc> graphArcs; if (incoming && outgoing) { graphArcs = getArcs(); } else if (!incoming && !outgoing) { graphArcs = Collections.emptyList(); } else { graphArcs = new ArrayList<GraphArc>(); for (GraphArc arc : getArcs()) { if (incoming && (arc.getDestination() == this)) { graphArcs.add(arc); } else if (outgoing && (arc.getSource() == this)) { graphArcs.add(arc); } } } return graphArcs; }
protected void removeArcInternal(GraphArc arc) { if ((arc != null) && arcs.containsKey(arc.getUserObject())) { // remove this arc from the source and destination nodes arc.getSource().removeArc(arc); arc.getDestination().removeArc(arc); // now remove the arc from the model and fire the event arcs.remove(arc.getUserObject()); fireArcRemovedEvent(arc); } }
/** * Adds the list of arcs to the graph model. All nodes included in the arc relationships are * also added to the model if necessary. * * @param arcs */ private void addArcsToModel(Collection<GraphArc> arcs, boolean removeOldNodes) { Set<GraphNode> newGraphNodes = new HashSet<GraphNode>(); for (GraphArc arc : arcs) { GraphArc createdArc = addArc((OWLEntity) arc.getSource().getUserObject(), (OWLEntity) arc.getDestination().getUserObject(), arc.getType().toString(), arc.getIcon()); if (createdArc != null) { newGraphNodes.add(createdArc.getSource()); newGraphNodes.add(createdArc.getDestination()); createdArc.setInverted(arc.isInverted()); //PNode n = (PNode)createdArc.getDestination(); //System.out.println(n.getRoot().getClass()); } } if (removeOldNodes) { // remove all old nodes GraphNode[] allNodes = getAllNodes().toArray(new GraphNode[getAllNodes().size()]); for (GraphNode node : allNodes) { if (!newGraphNodes.contains(node)) { removeNode(node.getUserObject()); } } } }
/** * Finds relationships between an artifact as a item in the domain, and the ranges of its * properties */ private Set<GraphArc> loadDomainRangeRels(OWLEntity entityOfInterest, boolean outgoing, boolean mustBeVisible) { Set<GraphArc> domainRangeArcs = new HashSet<GraphArc>(); getDomainRangeRelationships(); // ensures that domain range rels are created for (GraphArc relationship : domainRangeRelsBuffer) { if(!filterManager.isArcTypeVisible(relationship.getType())) continue; OWLEntity sourceObject = (OWLEntity) relationship.getSource().getUserObject(); OWLEntity destObject = (OWLEntity) relationship.getDestination().getUserObject(); if (!isDisplayableNode(sourceObject, mustBeVisible) || !isDisplayableNode(destObject, mustBeVisible)) { continue; } if ((outgoing && sourceObject.equals(entityOfInterest)) || destObject.equals(entityOfInterest)) { if(outgoing) relationship.setInverted(false); domainRangeArcs.add(relationship); } } return domainRangeArcs; }
/** * Hides all incoming arcs and attempts to hide any nodes and their arcs. * * @param graphNode * @param seen The list of recursively visited items, need this to avoid cycles */ private void hideAscendants(GraphNode graphNode, Set<IRI> seen) { GraphArc[] arcs = graphNode.getArcs().toArray(new GraphArc[graphNode.getArcs().size()]); seen.add(((OWLEntity) graphNode.getUserObject()).getIRI()); for (GraphArc arc : arcs) { Object userObject = arc.getSource().getUserObject(); GraphNode node = getNode(userObject); // recursively collapse the child node, check our seen object in order to avoid cycles if (node != null && !node.equals(graphNode)) { removeArc(arc.getUserObject()); if (!seen.contains(((OWLEntity) userObject).getIRI())) { hideAll(node, seen); } if (isRemovable(node)) { removeNode(userObject); } } else { userObject = arc.getDestination().getUserObject(); seen.add(((OWLEntity) userObject).getIRI()); } } }
private void updateArcs() { for (GraphArc arc : arcs) { if (isSelected()) { arc.setSelected(true); } else { GraphNode src = arc.getSource(); GraphNode dest = arc.getDestination(); if (src == dest) { arc.setSelected(false); } else if (this == src) { arc.setSelected(dest.isSelected()); } else if (this == dest) { arc.setSelected(src.isSelected()); } } } }
/** * @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 + " " : ""); }