Skip to content

Commit 2a7ae27

Browse files
committed
Merge pull request #6 from ProgrammingLife3/Sprint1Demo
Working version for sprint 1
2 parents 8fd1d56 + 40601fb commit 2a7ae27

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

SE deliverables/DemoSprint1.jar

830 KB
Binary file not shown.

src/main/java/tudelft/ti2806/pl3/data/graph/GraphData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ private static Genome[] parseGenomeIdentifiers(String[] identifiers,
153153
* @throws FileNotFoundException
154154
* if the file is not found
155155
*/
156-
protected static List<Edge> parseEdges(File edgesFile,
157-
Map<Integer, Node> nodes) throws FileNotFoundException {
156+
public static List<Edge> parseEdges(File edgesFile, Map<Integer, Node> nodes)
157+
throws FileNotFoundException {
158158
Scanner scanner = new Scanner(edgesFile);
159159
List<Edge> list = new ArrayList<Edge>();
160160
while (scanner.hasNext()) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package tudelft.ti2806.pl3.demo;
2+
3+
import org.graphstream.graph.Graph;
4+
5+
import tudelft.ti2806.pl3.data.graph.GraphData;
6+
import tudelft.ti2806.pl3.visualization.DisplayView;
7+
8+
import java.io.File;
9+
import java.io.FileNotFoundException;
10+
11+
import javax.swing.JFileChooser;
12+
import javax.swing.JFrame;
13+
import javax.swing.filechooser.FileFilter;
14+
15+
public class Demo {
16+
/**
17+
* Demo for sprint 1, week 2. Demonstrating the parsing of the edge and node
18+
* files and displaying them with the GraphStream library.
19+
*
20+
* @param par
21+
* should be empty
22+
*/
23+
public static void main(String[] par) {
24+
JFrame frame = new JFrame();
25+
File nodeFile = selectFile("Select node file", frame, ".node.graph");
26+
File edgeFile = selectFile("Select edge file", frame, ".edge.graph");
27+
28+
GraphData graph = null;
29+
try {
30+
graph = GraphData.parseGraph(nodeFile, edgeFile);
31+
} catch (FileNotFoundException e) {
32+
e.printStackTrace();
33+
}
34+
Graph displayGraph = DisplayView.getGraph("", graph.getNodes(),
35+
graph.getEdges());
36+
displayGraph.display();
37+
}
38+
39+
private static File selectFile(String title, JFrame frame, String filter) {
40+
JFileChooser chooser = new JFileChooser();
41+
chooser.setMultiSelectionEnabled(true);
42+
chooser.setDialogTitle(title);
43+
chooser.setFileFilter(new FileFilter() {
44+
@Override
45+
public boolean accept(File file) {
46+
if (file.isDirectory()) {
47+
return true;
48+
} else {
49+
String path = file.getAbsolutePath().toLowerCase();
50+
if (path.endsWith(filter)) {
51+
return true;
52+
}
53+
}
54+
return false;
55+
}
56+
57+
@Override
58+
public String getDescription() {
59+
return filter;
60+
}
61+
});
62+
int option = chooser.showOpenDialog(frame);
63+
if (option == JFileChooser.APPROVE_OPTION) {
64+
File[] sf = chooser.getSelectedFiles();
65+
if (sf.length == 1) {
66+
return sf[0];
67+
}
68+
}
69+
return null;
70+
}
71+
}

0 commit comments

Comments
 (0)