@Override public Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel, Graph graph) { Edge newEdge = buildEdge(graph, id, source, target, directed, typeLabel); try { if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist. return newEdge; } } catch (Exception e) { Logger.getLogger("").log( Level.SEVERE, "Error when adding edge [id = {0}, source = {1}, target = {2}, directed = {3}, typeLabel = {4}] to the graph. Exception message: {5}", new Object[]{id, source.getId(), target.getId(), directed, typeLabel, e.getMessage()} ); } return null; }
private void loadSelectedRow(JPanel settingsPanel) { JLabel selectedRowLabel = new JLabel(); selectedRowLabel.setText(getMessage("MergeNodesUI.selectedRowText")); settingsPanel.add(selectedRowLabel, "wrap"); nodesComboBox = new JComboBox(); //Prepare selected node combo box with nodes data: nodes = manipulator.getNodes(); Node selectedNode = manipulator.getSelectedNode(); for (int i = 0; i < nodes.length; i++) { nodesComboBox.addItem(nodes[i].getId() + " - " + nodes[i].getLabel()); if (nodes[i] == selectedNode) { nodesComboBox.setSelectedIndex(i); } } settingsPanel.add(nodesComboBox, "growx, wrap 25px"); }
@Override public void setup(Manipulator m, DialogControls dialogControls) { manipulator = (LinkNodes) m; nodes = manipulator.getNodes(); if(manipulator.isDirected()){ directedEdge.setSelected(true); }else{ undirectedEdge.setSelected(true); } Node sourceNode = manipulator.getSourceNode(); //Prepare combo box with nodes data: for (int i = 0; i < nodes.length; i++) { sourceNodeComboBox.addItem(nodes[i].getId() + " - " + nodes[i].getLabel()); if (nodes[i] == sourceNode) { sourceNodeComboBox.setSelectedIndex(i); } } }
@Override public void select() { //Get current visible graph GraphController graphController = Lookup.getDefault().lookup(GraphController.class); Graph graph = graphController.getGraphModel().getGraphVisible(); //Build the autocomplete data. A simple map from node's label graph.readLock(); data = new HashMap<String, Node>(); for (Node n : graph.getNodes()) { String label = n.getLabel(); String id = n.getId().toString(); if (label != null) { if (!label.isEmpty()) { data.put(label, n); } } else if (id != null && !id.isEmpty()) { data.put(id, n); } } graph.readUnlock(); }
if (n.getId().toString().toLowerCase().equals(str)) { nodes.add(n); } else if ((n.getLabel() != null) && n.getLabel().toLowerCase().equals(str)) {
private EdgeImpl verifyEdge(Edge edge) { EdgeImpl edgeImpl = (EdgeImpl) edge; verifyElement(edgeImpl); EdgeImpl existingEdge = store.getEdge(edge.getId()); if (existingEdge != null && (!existingEdge.getSource().getId().equals(edge.getSource().getId()) || !existingEdge .getTarget().getId().equals(edge.getTarget().getId()))) { throw new RuntimeException("An edge with a similar id '" + edge.getId() + "' already exists"); } return edgeImpl; }
private EdgeImpl verifyEdge(Edge edge) { EdgeImpl edgeImpl = (EdgeImpl) edge; verifyElement(edgeImpl); EdgeImpl existingEdge = store.getEdge(edge.getId()); if (existingEdge != null && (!existingEdge.getSource().getId().equals(edge.getSource().getId()) || !existingEdge .getTarget().getId().equals(edge.getTarget().getId()))) { throw new RuntimeException("An edge with a similar id '" + edge.getId() + "' already exists"); } return edgeImpl; }
private void refreshRows() { rows = columnsAndRowChooser.getRows(); Object sourceRow = columnsAndRowChooser.getRow(); Node node; Edge edge; //Prepare combo box with nodes/edges data: for (int i = 0; i < rows.length; i++) { if (rows[i] instanceof Node) { node = (Node) rows[i]; rowComboBox.addItem(node.getId() + " - " + node.getLabel()); } else { edge = (Edge) rows[i]; rowComboBox.addItem(edge.getId() + " - " + edge.getLabel()); } if (rows[i] == sourceRow) { rowComboBox.setSelectedIndex(i); } } }
Text labelTextOutline = target.createTextNode(label); Element outlineElem = target.createElement("text"); outlineElem.setAttribute("class", SVGUtils.idAsClassAttribute(node.getId())); outlineElem.setAttribute("x", String.valueOf(x)); outlineElem.setAttribute("y", String.valueOf(y)); labelElem.setAttribute("class", SVGUtils.idAsClassAttribute(node.getId())); labelElem.setAttribute("x", String.valueOf(x)); labelElem.setAttribute("y", String.valueOf(y));
@Override public void setup(Manipulator m, DialogControls dialogControls) { this.manipulator = (AddEdgeToGraph) m; if (manipulator.isDirected()) { directedRadioButton.setSelected(true); } else { undirectedRadioButton.setSelected(true); } graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph(); nodes = graph.getNodes().toArray(); workspace = Lookup.getDefault().lookup(ProjectController.class).getCurrentWorkspace(); for (Node n : nodes) { sourceNodesComboBox.addItem(n.getId() + " - " + n.getLabel()); targetNodesComboBox.addItem(n.getId() + " - " + n.getLabel()); } SelectedOptions selectedOptions = workspace.getLookup().lookup(SelectedOptions.class); if (selectedOptions != null) { setNodeComboBoxSelection(sourceNodesComboBox, selectedOptions.source); setNodeComboBoxSelection(targetNodesComboBox, selectedOptions.target); edgeTypeComboBox.setSelectedItem(selectedOptions.edgeType); } else { workspace.add(new SelectedOptions()); } refreshAvailableEdgeTypes(); dialogControls.setOkButtonEnabled(nodes.length > 0); }
@Override public void mouseClicked(PreviewMouseEvent event, PreviewProperties properties, Workspace workspace) { for (Node node : Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace).getGraph().getNodes()) { if (clickingInNode(node, event)) { properties.putValue("display-label.node.id", node.getId()); System.err.println("Node " + node.getLabel() + " clicked!");//System.out is ignored in Netbeans platform applications!! JOptionPane.showMessageDialog(null, "Node " + node.getLabel() + " clicked!"); event.setConsumed(true);//So the renderer is executed and the graph repainted return; } } properties.removeSimpleValue("display-label.node.id"); event.setConsumed(true);//So the renderer is executed and the graph repainted }
nodeElem.setAttribute("class", SVGUtils.idAsClassAttribute(node.getId())); nodeElem.setAttribute("cx", x.toString()); nodeElem.setAttribute("cy", y.toString());
"M %f,%f C %f,%f %f,%f %f,%f", h.x, h.y, h.v1.x, h.v1.y, h.v2.x, h.v2.y, h.x, h.y)); selfLoopElem.setAttribute("class", SVGUtils.idAsClassAttribute(h.node.getId())); selfLoopElem.setAttribute( "stroke",
checkIdDoesntExist(n.getId());
checkIdDoesntExist(n.getId());