Browse Source

Create a basic Launch class.

Mikael Capelle 6 years ago
parent
commit
44ae861fb8
2 changed files with 78 additions and 3 deletions
  1. 69
    0
      src/main/org/insa/base/Launch.java
  2. 9
    3
      src/main/org/insa/graphics/MainWindow.java

+ 69
- 0
src/main/org/insa/base/Launch.java View File

@@ -0,0 +1,69 @@
1
+package org.insa.base;
2
+
3
+import java.awt.Dimension;
4
+import java.io.BufferedInputStream;
5
+import java.io.DataInputStream;
6
+import java.io.FileInputStream;
7
+
8
+import javax.swing.JFrame;
9
+import javax.swing.SwingUtilities;
10
+
11
+import org.insa.graph.Graph;
12
+import org.insa.graph.Path;
13
+import org.insa.graph.io.BinaryGraphReader;
14
+import org.insa.graph.io.GraphReader;
15
+import org.insa.graph.io.PathReader;
16
+import org.insa.graphics.drawing.Drawing;
17
+import org.insa.graphics.drawing.components.BasicDrawing;
18
+
19
+public class Launch {
20
+
21
+    /**
22
+     * Create a new Drawing inside a JFrame an return it.
23
+     * 
24
+     * @return The created drawing.
25
+     */
26
+    public static Drawing createDrawing() throws Exception {
27
+        BasicDrawing basicDrawing = new BasicDrawing();
28
+        SwingUtilities.invokeAndWait(new Runnable() {
29
+            @Override
30
+            public void run() {
31
+                JFrame frame = new JFrame("BE Graphes - Launch");
32
+                frame.setContentPane(basicDrawing);
33
+                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
34
+                frame.setVisible(true);
35
+                frame.setSize(new Dimension(800, 600));
36
+            }
37
+        });
38
+        return basicDrawing;
39
+    }
40
+
41
+    public static void main(String[] args) throws Exception {
42
+
43
+        // Visit these directory to see the list of available files on Commetud.
44
+        String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
45
+        String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/path/path_fr31insa_rangueil_r2.path";
46
+
47
+        // Create a graph reader.
48
+        GraphReader reader = new BinaryGraphReader(
49
+                new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
50
+
51
+        // TODO: Read the graph.
52
+        Graph graph = null;
53
+
54
+        // Create the drawing:
55
+        Drawing drawing = createDrawing();
56
+
57
+        // TODO: Draw the graph on the drawing.
58
+
59
+        // TODO: Create a PathReader.
60
+        PathReader pathReader = null;
61
+
62
+        // TODO: Read the path.
63
+        Path path = null;
64
+
65
+        // TODO: Draw the path.
66
+
67
+    }
68
+
69
+}

+ 9
- 3
src/main/org/insa/graphics/MainWindow.java View File

@@ -37,6 +37,7 @@ import javax.swing.JSplitPane;
37 37
 import javax.swing.JTextArea;
38 38
 import javax.swing.KeyStroke;
39 39
 import javax.swing.SwingConstants;
40
+import javax.swing.SwingUtilities;
40 41
 import javax.swing.Timer;
41 42
 import javax.swing.UIManager;
42 43
 import javax.swing.border.CompoundBorder;
@@ -848,9 +849,14 @@ public class MainWindow extends JFrame {
848 849
         catch (Exception e) {
849 850
         }
850 851
 
851
-        MainWindow w = new MainWindow();
852
-        w.setExtendedState(JFrame.MAXIMIZED_BOTH);
853
-        w.setVisible(true);
852
+        SwingUtilities.invokeLater(new Runnable() {
853
+            @Override
854
+            public void run() {
855
+                MainWindow w = new MainWindow();
856
+                w.setExtendedState(JFrame.MAXIMIZED_BOTH);
857
+                w.setVisible(true);
858
+            }
859
+        });
854 860
     }
855 861
 
856 862
 }

Loading…
Cancel
Save