From 44ae861fb8e73e2cafe0ae8716d850cb6925211f Mon Sep 17 00:00:00 2001 From: Mikael Capelle Date: Tue, 13 Mar 2018 17:48:54 +0100 Subject: [PATCH] Create a basic Launch class. --- src/main/org/insa/base/Launch.java | 69 ++++++++++++++++++++++ src/main/org/insa/graphics/MainWindow.java | 12 +++- 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/main/org/insa/base/Launch.java diff --git a/src/main/org/insa/base/Launch.java b/src/main/org/insa/base/Launch.java new file mode 100644 index 0000000..f98f9a8 --- /dev/null +++ b/src/main/org/insa/base/Launch.java @@ -0,0 +1,69 @@ +package org.insa.base; + +import java.awt.Dimension; +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.FileInputStream; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.insa.graph.Graph; +import org.insa.graph.Path; +import org.insa.graph.io.BinaryGraphReader; +import org.insa.graph.io.GraphReader; +import org.insa.graph.io.PathReader; +import org.insa.graphics.drawing.Drawing; +import org.insa.graphics.drawing.components.BasicDrawing; + +public class Launch { + + /** + * Create a new Drawing inside a JFrame an return it. + * + * @return The created drawing. + */ + public static Drawing createDrawing() throws Exception { + BasicDrawing basicDrawing = new BasicDrawing(); + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + JFrame frame = new JFrame("BE Graphes - Launch"); + frame.setContentPane(basicDrawing); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setVisible(true); + frame.setSize(new Dimension(800, 600)); + } + }); + return basicDrawing; + } + + public static void main(String[] args) throws Exception { + + // Visit these directory to see the list of available files on Commetud. + String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; + String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/path/path_fr31insa_rangueil_r2.path"; + + // Create a graph reader. + GraphReader reader = new BinaryGraphReader( + new DataInputStream(new BufferedInputStream(new FileInputStream(mapName)))); + + // TODO: Read the graph. + Graph graph = null; + + // Create the drawing: + Drawing drawing = createDrawing(); + + // TODO: Draw the graph on the drawing. + + // TODO: Create a PathReader. + PathReader pathReader = null; + + // TODO: Read the path. + Path path = null; + + // TODO: Draw the path. + + } + +} diff --git a/src/main/org/insa/graphics/MainWindow.java b/src/main/org/insa/graphics/MainWindow.java index 3ad12fd..844840f 100644 --- a/src/main/org/insa/graphics/MainWindow.java +++ b/src/main/org/insa/graphics/MainWindow.java @@ -37,6 +37,7 @@ import javax.swing.JSplitPane; import javax.swing.JTextArea; import javax.swing.KeyStroke; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.UIManager; import javax.swing.border.CompoundBorder; @@ -848,9 +849,14 @@ public class MainWindow extends JFrame { catch (Exception e) { } - MainWindow w = new MainWindow(); - w.setExtendedState(JFrame.MAXIMIZED_BOTH); - w.setVisible(true); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + MainWindow w = new MainWindow(); + w.setExtendedState(JFrame.MAXIMIZED_BOTH); + w.setVisible(true); + } + }); } }