ajout: Lancement rapide via Launch.java
This commit is contained in:
parent
87ae5fc037
commit
63fb8fa6af
1 changed files with 47 additions and 24 deletions
|
|
@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
|||
import java.awt.Dimension;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
|
@ -11,9 +12,11 @@ import javax.swing.SwingUtilities;
|
|||
|
||||
import org.insa.graphs.gui.drawing.Drawing;
|
||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
||||
import org.insa.graphs.gui.drawing.components.MapViewDrawing;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||
import org.insa.graphs.model.io.BinaryPathReader;
|
||||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.io.PathReader;
|
||||
|
||||
|
|
@ -42,38 +45,58 @@ public class Launch {
|
|||
return basicDrawing;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public static MapViewDrawing createMapViewDrawing() throws Exception {
|
||||
MapViewDrawing mapViewDrawing = new MapViewDrawing();
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JFrame frame = new JFrame("BE Graphes - Launch");
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
frame.setSize(new Dimension(800, 600));
|
||||
frame.setContentPane(mapViewDrawing);
|
||||
frame.validate();
|
||||
}
|
||||
});
|
||||
return mapViewDrawing;
|
||||
}
|
||||
|
||||
// visit these directory to see the list of available files on commetud.
|
||||
final String mapName =
|
||||
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||
final String pathName =
|
||||
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Pour mapName: un fichier .mapgr pour un graphe simple, un fichier .mapfg pour une carte (le .mapgr associé doit être présent dans le même dossier)
|
||||
final String mapName = "C:\\Users\\Brendan\\Mon Drive\\INSA\\3MIC\\S6 - Graphes\\BE-Graphes\\Maps\\insa.mapfg";
|
||||
final String pathName = "C:\\Users\\Brendan\\Mon Drive\\INSA\\3MIC\\S6 - Graphes\\BE-Graphes\\Paths\\path_fr31insa_rangueil_r2.path";
|
||||
|
||||
final Graph graph;
|
||||
final Path path;
|
||||
final Drawing drawing;
|
||||
|
||||
// create a graph reader
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(mapName))))) {
|
||||
|
||||
// TODO: read the graph
|
||||
graph = null;
|
||||
// On récupère le graphe
|
||||
if (mapName.endsWith(".mapgr")) {
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))))) {
|
||||
graph = reader.read();
|
||||
}
|
||||
drawing = createDrawing();
|
||||
drawing.drawGraph(graph);
|
||||
} else if (mapName.endsWith(".mapfg")) {
|
||||
// Le GraphReader prend uniquement un fichier .mapgr
|
||||
final String mapgrFilename = mapName.substring(0, mapName.lastIndexOf(".mapfg")) + ".mapgr";
|
||||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapgrFilename))))) {
|
||||
graph = reader.read();
|
||||
}
|
||||
drawing = createMapViewDrawing();
|
||||
final String mapFilename = mapName.substring(0, mapName.lastIndexOf(".map")) + ".mapfg";
|
||||
final File file = new File(mapFilename);
|
||||
((MapViewDrawing) drawing).drawGraph(file);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Format de map non supporté: " + mapName);
|
||||
}
|
||||
|
||||
// create the drawing
|
||||
final Drawing drawing = createDrawing();
|
||||
|
||||
// TODO: draw the graph on the drawing
|
||||
|
||||
// TODO: create a path reader
|
||||
try (final PathReader pathReader = null) {
|
||||
|
||||
// TODO: read the path
|
||||
path = null;
|
||||
// Dessin du chemin
|
||||
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))))) {
|
||||
path = pathReader.readPath(graph);
|
||||
}
|
||||
|
||||
// TODO: draw the path on the drawing
|
||||
drawing.drawPath(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue