ajout: Lancement rapide via Launch.java

This commit is contained in:
Brendan Saint Germes 2026-04-14 16:13:04 +02:00
parent 87ae5fc037
commit 63fb8fa6af

View file

@ -4,6 +4,7 @@ import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import javax.swing.JFrame; 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.Drawing;
import org.insa.graphs.gui.drawing.components.BasicDrawing; 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.Graph;
import org.insa.graphs.model.Path; import org.insa.graphs.model.Path;
import org.insa.graphs.model.io.BinaryGraphReader; 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.GraphReader;
import org.insa.graphs.model.io.PathReader; import org.insa.graphs.model.io.PathReader;
@ -42,38 +45,58 @@ public class Launch {
return basicDrawing; 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. public static void main(String[] args) throws Exception {
final String mapName = // 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)
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; final String mapName = "C:\\Users\\Brendan\\Mon Drive\\INSA\\3MIC\\S6 - Graphes\\BE-Graphes\\Maps\\insa.mapfg";
final String pathName = final String pathName = "C:\\Users\\Brendan\\Mon Drive\\INSA\\3MIC\\S6 - Graphes\\BE-Graphes\\Paths\\path_fr31insa_rangueil_r2.path";
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
final Graph graph; final Graph graph;
final Path path; final Path path;
final Drawing drawing;
// create a graph reader // On récupère le graphe
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream( if (mapName.endsWith(".mapgr")) {
new BufferedInputStream(new FileInputStream(mapName))))) { try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))))) {
graph = reader.read();
// TODO: read the graph }
graph = null; 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 // Dessin du chemin
final Drawing drawing = createDrawing(); try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))))) {
path = pathReader.readPath(graph);
// TODO: draw the graph on the drawing
// TODO: create a path reader
try (final PathReader pathReader = null) {
// TODO: read the path
path = null;
} }
drawing.drawPath(path);
// TODO: draw the path on the drawing
} }
} }