{
@Override
// simple visitor that prints current vertex
public boolean visit(Object vertex, Object edge)
{
mxCell v = (mxCell) vertex;
mxCell e = (mxCell) edge;
if (e != null)
{
System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
}
else
{
System.out.println("Vertex: " + v.getValue() + " edge: N/A");
}
return false;
}
});
mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
}
else if (graphType2 == GraphType.DFS_DIR)
{
boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
mxGraphProperties.setDirected(aGraph.getProperties(), true);
System.out.println("DFS test");
mxTraversal.dfs(aGraph, startVertex, new mxICellVisitor()
{
@Override
// simple visitor that prints current vertex
public boolean visit(Object vertex, Object edge)
{
mxCell v = (mxCell) vertex;
mxCell e = (mxCell) edge;
if (e != null)
{
System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
}
else
{
System.out.println("Vertex: " + v.getValue() + " edge: N/A");
}
return false;
}
});
mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
}
else if (graphType2 == GraphType.BFS_UNDIR)
{
boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
mxGraphProperties.setDirected(aGraph.getProperties(), false);
System.out.println("BFS test");
mxTraversal.bfs(aGraph, startVertex, new mxICellVisitor()
{
@Override
// simple visitor that prints current vertex
public boolean visit(Object vertex, Object edge)
{
mxCell v = (mxCell) vertex;
mxCell e = (mxCell) edge;
if (e != null)
{
System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
}
else
{
System.out.println("Vertex: " + v.getValue() + " edge: N/A");
}
return false;
}
});
mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
}
else if (graphType2 == GraphType.DFS_UNDIR)
{
boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
mxGraphProperties.setDirected(aGraph.getProperties(), false);
System.out.println("DFS test");
mxTraversal.dfs(aGraph, startVertex, new mxICellVisitor()
{
@Override
// simple visitor that prints current vertex
public boolean visit(Object vertex, Object edge)
{
mxCell v = (mxCell) vertex;
mxCell e = (mxCell) edge;
if (e != null)
{
System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
}
else
{
System.out.println("Vertex: " + v.getValue() + " edge: N/A");
}
return false;
}
});
mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
}
else if (graphType2 == GraphType.MAKE_TREE_DIRECTED)
{
try
{
graph.getModel().beginUpdate();
mxGraphStructure.makeTreeDirected(aGraph, startVertex);
graph.getModel().endUpdate();
graph.getModel().beginUpdate();
mxCompactTreeLayout layout = new mxCompactTreeLayout(graph);
layout.setHorizontal(false);
layout.execute(graph.getDefaultParent());
graph.getModel().endUpdate();
}
catch (StructuralException e1)
{
System.out.println(e1);
}
}
else if (graphType2 == GraphType.INDEGREE)
{
int indegree = mxGraphStructure.indegree(aGraph, startVertex);
System.out.println("Indegree of " + aGraph.getGraph().getModel().getValue(startVertex) + " is " + indegree);
}
else if (graphType2 == GraphType.OUTDEGREE)
{
int outdegree = mxGraphStructure.outdegree(aGraph, startVertex);
System.out.println("Outdegree of " + aGraph.getGraph().getModel().getValue(startVertex) + " is " + outdegree);
}
else if (graphType2 == GraphType.IS_CUT_VERTEX)
{
boolean isCutVertex = mxGraphStructure.isCutVertex(aGraph, startVertex);
if (isCutVertex)
{
System.out.println("Vertex " + aGraph.getGraph().getModel().getValue(startVertex) + " is a cut vertex.");
}
else
{
System.out.println("Vertex " + aGraph.getGraph().getModel().getValue(startVertex) + " is not a cut vertex.");
}
}
setVisible(false);
}
});
closeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
insertGraph = false;
setVisible(false);
}
});
getContentPane().add(panelBorder, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
pack();
setResizable(false);
// setLocationRelativeTo(parent);
}
else if ((graphType2 == GraphType.DIJKSTRA) || (graphType2 == GraphType.BELLMAN_FORD))
{
JPanel panel = new JPanel(new GridLayout(2, 2, 4, 4));
panel.add(new JLabel("Starting vertex"));
panel.add(startVertexValueField);
panel.add(new JLabel("End vertex"));
panel.add(endVertexValueField);
JPanel panelBorder = new JPanel();
panelBorder.setBorder(new EmptyBorder(10, 10, 10, 10));
panelBorder.add(panel);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
BorderFactory.createEmptyBorder(16, 8, 8, 8)));
JButton applyButton = new JButton("Start");
JButton closeButton = new JButton("Cancel");
buttonPanel.add(closeButton);
buttonPanel.add(applyButton);
getRootPane().setDefaultButton(applyButton);
applyButton.addActionListener(new ActionListener()
{
double distance = 0;
public void actionPerformed(ActionEvent e)
{
applyValues();
int startValue = Integer.parseInt(startVertexValueField.getText());
int endValue = Integer.parseInt(endVertexValueField.getText());
Object startVertex = mxGraphStructure.getVertexWithValue(aGraph, startValue);
Object endVertex = mxGraphStructure.getVertexWithValue(aGraph, endValue);
if (graphType2 == GraphType.DIJKSTRA)
{
System.out.println("Dijkstra test");
try
{
mxTraversal.dijkstra(aGraph, startVertex, endVertex, new mxICellVisitor()
{
@Override
// simple visitor that prints current vertex
public boolean visit(Object vertex, Object edge)
{
mxCell v = (mxCell) vertex;
mxCell e = (mxCell) edge;
String eVal = "N/A";
if (e != null)
{
if (e.getValue() == null)
{
eVal = "1.0";
}
else
{
eVal = e.getValue().toString();
}
}
if (!eVal.equals("N/A"))
{