Compare commits

..

No commits in common. "704b40ecc9b331a68ae7ed7982591f798bdf54fd" and "b5d3a3cad7c51d83b3c49a718482abbdddf612f5" have entirely different histories.

50 changed files with 63 additions and 296 deletions

View File

@ -1,13 +1,11 @@
package configuration;
import java.io.File;
public interface ConfigurationParser {
/**
* Analyse et lit une configuration de simulation depuis un fichier.
* Analyse et lit une configuration de simulation depuis un fichier au chemin donné.
*
* @param file Le fichier de configuration.
* @param path Le chemin vers le fichier de configuration.
* @return La configuration de simulation correspondant au contenu du fichier.
*/
SimulationConfiguration parseConfiguration(File file) throws ConfigurationParsingException;
SimulationConfiguration parseConfiguration(String path) throws ConfigurationParsingException;
}

View File

@ -1,6 +1,6 @@
package configuration;
import metadata.BuildingMetadata;
import model.metadata.BuildingMetadata;
import java.util.Map;

View File

@ -1,26 +0,0 @@
package configuration;
public class SimulationConfigurationSingleton {
private static SimulationConfigurationSingleton instance;
public static SimulationConfigurationSingleton getInstance() {
if (instance == null) {
instance = new SimulationConfigurationSingleton();
}
return instance;
}
private SimulationConfiguration configuration;
private SimulationConfigurationSingleton() {
}
public void setConfiguration(SimulationConfiguration config) {
this.configuration = config;
}
public SimulationConfiguration getConfiguration() {
return configuration;
}
}

View File

@ -1,7 +1,7 @@
package configuration;
import simulation.Building;
import simulation.Route;
import model.Building;
import model.Route;
import java.util.Collection;

View File

@ -1,16 +1,15 @@
package configuration;
import metadata.*;
import model.*;
import model.metadata.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import simulation.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@ -37,8 +36,8 @@ public class XmlConfigurationParser implements ConfigurationParser {
public static final String ATTRIBUTE_TO = "vers";
@Override
public SimulationConfiguration parseConfiguration(File file) throws ConfigurationParsingException {
Document document = parseDocument(file);
public SimulationConfiguration parseConfiguration(String path) throws ConfigurationParsingException {
Document document = parseDocument(path);
Map<String, BuildingMetadata> buildingsMetadata = parseBuildingsMetadata(document);
SimulationData simulationData = parseSimulationData(document);
@ -46,12 +45,12 @@ public class XmlConfigurationParser implements ConfigurationParser {
return new SimulationConfiguration(buildingsMetadata, simulationData);
}
private Document parseDocument(File file) throws ConfigurationParsingException {
private Document parseDocument(String path) throws ConfigurationParsingException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);
Document document = builder.parse(path);
document.getDocumentElement().normalize();
return document;

View File

@ -1,11 +1,11 @@
package simulation;
package model;
public abstract class Building {
protected final int id;
protected final String type;
protected final int x;
protected final int y;
protected BuildingState state = BuildingState.EMPTY;
private final int id;
private final String type;
private final int x;
private final int y;
private BuildingState state = BuildingState.EMPTY;
protected Building(int id, String type, int x, int y) {
this.id = id;

View File

@ -1,4 +1,4 @@
package simulation;
package model;
import java.util.Arrays;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package simulation;
package model;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package simulation;
package model;
public class ComponentRoute {
private final Building outputBuilding;

View File

@ -1,4 +1,4 @@
package simulation;
package model;
import java.util.Arrays;
import java.util.Objects;

View File

@ -1,4 +1,4 @@
package simulation;
package model;
public class Factory extends Building {
public Factory(int id, String type, int x, int y) {

View File

@ -1,4 +1,4 @@
package simulation;
package model;
import java.util.Objects;

14
src/model/Warehouse.java Normal file
View File

@ -0,0 +1,14 @@
package model;
public class Warehouse extends Building {
public Warehouse(int id, String type, int x, int y) {
super(id, type, x, y);
}
@Override
public void processInput(Component input) {
}
private void sellComponent() {
}
}

View File

@ -1,13 +1,13 @@
package metadata;
package model.metadata;
import simulation.BuildingState;
import model.BuildingState;
import java.util.Map;
import java.util.Objects;
public abstract class BuildingMetadata {
protected final String type;
protected final Map<BuildingState, String> iconsPaths;
private final String type;
private final Map<BuildingState, String> iconsPaths;
public BuildingMetadata(String type, Map<BuildingState, String> iconsPaths) {
this.type = type;

View File

@ -1,6 +1,6 @@
package metadata;
package model.metadata;
import simulation.ComponentType;
import model.ComponentType;
import java.util.Objects;

View File

@ -1,6 +1,6 @@
package metadata;
package model.metadata;
import simulation.BuildingState;
import model.BuildingState;
import java.util.Collection;
import java.util.Map;

View File

@ -1,6 +1,6 @@
package metadata;
package model.metadata;
import simulation.ComponentType;
import model.ComponentType;
import java.util.Objects;

View File

@ -1,6 +1,6 @@
package metadata;
package model.metadata;
import simulation.ComponentType;
import model.ComponentType;
import java.util.Objects;

View File

@ -1,6 +1,6 @@
package metadata;
package model.metadata;
import simulation.BuildingState;
import model.BuildingState;
import java.util.Map;
import java.util.Objects;
@ -13,10 +13,6 @@ public class WarehouseMetadata extends BuildingMetadata {
this.input = input;
}
public WarehouseInput getInput() {
return input;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 861 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 852 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 913 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 765 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 768 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 859 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -1,77 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<metadonnees>
<usine type="usine-matiere">
<icones>
<icone type="vide" path="src/ressources/UMP0%.png"/>
<icone type="un-tiers" path="src/ressources/UMP33%.png"/>
<icone type="deux-tiers" path="src/ressources/UMP66%.png"/>
<icone type="plein" path="src/ressources/UMP100%.png"/>
</icones>
<sortie type = "metal"/>
<interval-production>100</interval-production>
</usine>
<usine type="usine-aile">
<icones>
<icone type="vide" path="src/ressources/UT0%.png"/>
<icone type="un-tiers" path="src/ressources/UT33%.png"/>
<icone type="deux-tiers" path="src/ressources/UT66%.png"/>
<icone type="plein" path="src/ressources/UT100%.png"/>
</icones>
<entree type="metal" quantite="2"/>
<sortie type="aile"/>
<interval-production>50</interval-production>
</usine>
<usine type="usine-moteur">
<icones>
<icone type="vide" path="src/ressources/UM0%.png"/>
<icone type="un-tiers" path="src/ressources/UM33%.png"/>
<icone type="deux-tiers" path="src/ressources/UM66%.png"/>
<icone type="plein" path="src/ressources/UM100%.png"/>
</icones>
<entree type="metal" quantite="4"/>
<sortie type="moteur"/>
<interval-production>75</interval-production>
</usine>
<usine type="usine-assemblage">
<icones>
<icone type="vide" path="src/ressources/UA0%.png"/>
<icone type="un-tiers" path="src/ressources/UA33%.png"/>
<icone type="deux-tiers" path="src/ressources/UA66%.png"/>
<icone type="plein" path="src/ressources/UA100%.png"/>
</icones>
<entree type="aile" quantite="2"/>
<entree type="moteur" quantite="4"/>
<sortie type="avion"/>
<interval-production>110</interval-production>
</usine>
<usine type="entrepot">
<icones>
<icone type="vide" path="src/ressources/E0%.png"/>
<icone type="un-tiers" path="src/ressources/E33%.png"/>
<icone type="deux-tiers" path="src/ressources/E66%.png"/>
<icone type="plein" path="src/ressources/E100%.png"/>
</icones>
<entree type="avion" capacite="5"/>
</usine>
</metadonnees>
<simulation>
<usine type="usine-matiere" id="11" x="32" y="32"/>
<usine type="usine-aile" id="21" x="320" y="32"/>
<usine type="usine-assemblage" id="41" x="160" y="192"/>
<usine type="entrepot" id="51" x="640" y="192"/>
<usine type="usine-matiere" id="13" x="544" y="576"/>
<usine type="usine-matiere" id="12" x="96" y="352"/>
<usine type="usine-moteur" id="31" x="320" y="352"/>
<chemins>
<chemin de="11" vers="21" />
<chemin de="21" vers="41" />
<chemin de="41" vers="51" />
<chemin de="12" vers="31" />
<chemin de="13" vers="31" />
<chemin de="31" vers="41" />
</chemins>
</simulation>
</configuration>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -1,40 +0,0 @@
package simulation;
import configuration.SimulationConfigurationSingleton;
import metadata.WarehouseMetadata;
import java.util.ArrayList;
import java.util.Collection;
public class Warehouse extends Building implements WarehouseSubject {
private final Collection<Component> planes = new ArrayList<>();
private final Collection<WarehouseObserver> observers = new ArrayList<>();
private final int capacity = ((WarehouseMetadata) SimulationConfigurationSingleton.getInstance()
.getConfiguration().getMetadata().get(getType()))
.getInput().getCapacity();
public Warehouse(int id, String type, int x, int y) {
super(id, type, x, y);
}
@Override
public void processInput(Component input) {
planes.add(input);
}
private void sellComponent() {
}
public void attach(WarehouseObserver observer) {
observers.add(observer);
}
public void dettach(WarehouseObserver observer) {
observers.remove(observer);
}
public void notifyObservers() {
boolean isFull = planes.size() >= capacity;
observers.forEach(o -> o.update(isFull));
}
}

View File

@ -1,10 +0,0 @@
package simulation;
public interface WarehouseObserver {
/**
* Méthode appelée lorsque l'état d'un entrepot change.
*
* @param full Si l'entrepot est plein ou non
*/
void update(boolean full);
}

View File

@ -1,7 +0,0 @@
package simulation;
public interface WarehouseSubject {
void attach(WarehouseObserver observer);
void dettach(WarehouseObserver observer);
void notifyObservers();
}

View File

@ -1,88 +1,23 @@
package view;
import configuration.SimulationConfiguration;
import configuration.SimulationConfigurationSingleton;
import configuration.SimulationData;
import metadata.BuildingMetadata;
import simulation.Building;
import simulation.BuildingState;
import simulation.Route;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serial;
import java.util.HashMap;
import java.util.Map;
public class MainPanel extends JPanel {
@Serial
private static final long serialVersionUID = 1L;
private final Map<String, Image> icons = new HashMap<>();
private final Map<Integer, Building> buildingsById = new HashMap<>();
private SimulationConfiguration configuration;
private SimulationData simulationData;
public void reloadSimulation() {
configuration = SimulationConfigurationSingleton.getInstance().getConfiguration();
simulationData = configuration.getSimulationData();
buildingsById.clear();
simulationData.getBuildings().forEach(b -> buildingsById.put(b.getId(), b));
icons.clear();
configuration.getMetadata().values().forEach(m -> {
try {
loadImage(m);
} catch (IOException e) {
System.err.println("Could not load simulation icons");
}
});
}
private Point position = new Point(0, 0);
private Point speed = new Point(1, 1);
private int size = 32;
@Override
public void paint(Graphics g) {
super.paint(g);
// On ajoute à la position le delta x et y de la vitesse
// position.translate(speed.x, speed.y);
// g.fillRect(position.x, position.y, size, size);
if (configuration == null) return;
simulationData.getRoutes().forEach(r -> paintRoute(r, g));
simulationData.getBuildings().forEach(b -> paintBuilding(b, g));
}
private void paintBuilding(Building building, Graphics g) {
Image icon = icons.get(building.getType());
g.drawImage(icon, building.getX(), building.getY(), null);
}
private void paintRoute(Route route, Graphics g) {
Building fromBuilding = buildingsById.get(route.getFrom());
Image fromIcon = icons.get(fromBuilding.getType());
Building toBuilding = buildingsById.get(route.getTo());
Image toIcon = icons.get(toBuilding.getType());
g.drawLine(
fromBuilding.getX() + fromIcon.getWidth(null) / 2,
fromBuilding.getY() + fromIcon.getHeight(null) / 2,
toBuilding.getX() + toIcon.getWidth(null) / 2,
toBuilding.getY() + toIcon.getHeight(null) / 2
);
}
private void loadImage(BuildingMetadata metadata) throws IOException {
String iconPath = metadata.getIconsPaths().get(BuildingState.EMPTY);
BufferedImage image = ImageIO.read(new File(iconPath));
icons.put(metadata.getType(), image);
position.translate(speed.x, speed.y);
g.fillRect(position.x, position.y, size, size);
}
}

View File

@ -14,7 +14,7 @@ public class MainWindow extends JFrame implements PropertyChangeListener {
public MainWindow() {
MainPanel mainPanel = new MainPanel();
WindowMenu menu = new WindowMenu(mainPanel);
WindowMenu menu = new WindowMenu();
add(mainPanel);
add(menu, BorderLayout.NORTH);
@ -38,7 +38,7 @@ public class MainWindow extends JFrame implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals("TEST")) {
repaint();
// System.out.println(event.getNewValue());
System.out.println(event.getNewValue());
}
}
}

View File

@ -1,7 +1,5 @@
package view;
import configuration.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
@ -20,12 +18,7 @@ public class WindowMenu extends JMenuBar {
private static final String MENU_HELP_TITLE = "Aide";
private static final String MENU_HELP_ABOUT = "À propos de...";
private final ConfigurationParser configParser = new XmlConfigurationParser();
private final MainPanel mainPanel;
public WindowMenu(MainPanel mainPanel) {
this.mainPanel = mainPanel;
public WindowMenu() {
addFileMenu();
addSimulationMenu();
addHelpMenu();
@ -49,17 +42,9 @@ public class WindowMenu extends JMenuBar {
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
// TODO - Parser le fichier XML sélectionné
File selectedFile = fileChooser.getSelectedFile();
try {
SimulationConfiguration configuration = configParser.parseConfiguration(selectedFile);
SimulationConfigurationSingleton.getInstance().setConfiguration(configuration);
mainPanel.reloadSimulation();
} catch (ConfigurationParsingException ex) {
// TODO WN: Handle exception
throw new RuntimeException("Failed to parse config file", ex);
}
System.out.println(selectedFile.getAbsoluteFile());
}
});
@ -100,7 +85,7 @@ public class WindowMenu extends JMenuBar {
aboutMenu.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(null,
"<html><p>Application de simulation une chaine de production d'avions.</p><br>" +
"<html><p>Application simulation une chaine de production d'avions.</p><br>" +
"<p>&copy; &nbsp; 2017 &nbsp; Ghizlane El Boussaidi</p>" +
"<p>&copy; &nbsp; 2017 &nbsp; Dany Boisvert</p>" +
"<p>&copy; &nbsp; 2017 &nbsp; Vincent Mattard</p><br>" +