Add squelette

This commit is contained in:
FyloZ 2022-05-30 10:23:53 -04:00
parent a2ed695a4a
commit b5d3a3cad7
Signed by: william
GPG Key ID: 835378AE9AF4AE97
12 changed files with 416 additions and 23 deletions

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

15
src/Simulation.java Normal file
View File

@ -0,0 +1,15 @@
import view.Environment;
import view.MainWindow;
public class Simulation {
/**
* Cette classe représente l'application dans son ensemble.
*/
public static void main(String[] args) {
Environment environment = new Environment();
MainWindow window = new MainWindow();
environment.addPropertyChangeListener(window);
environment.execute();
}
}

View File

@ -1,12 +0,0 @@
import configuration.ConfigurationParser;
import configuration.ConfigurationParsingException;
import configuration.XmlConfigurationParser;
public class TestMain {
public static void main(String[] args) throws ConfigurationParsingException {
String configurationFilePath = "/home/william/Dev/Projects/Uni/Log121/TP01/squelette/src/ressources/configuration.xml";
ConfigurationParser parser = new XmlConfigurationParser();
parser.parseConfiguration(configurationFilePath);
}
}

View File

@ -6,11 +6,11 @@ import org.w3c.dom.NodeList;
import java.util.Iterator;
public class NodeListElementIterator implements Iterator<Element> {
public class ElementListIterator implements Iterator<Element> {
private final NodeList nodes;
private int position = 0;
public NodeListElementIterator(NodeList nodes) {
public ElementListIterator(NodeList nodes) {
this.nodes = nodes;
}

View File

@ -7,16 +7,16 @@ import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
public class IterableNodeList implements Iterable<Element> {
public class IterableElementList implements Iterable<Element> {
private final NodeList nodes;
public IterableNodeList(NodeList nodes) {
public IterableElementList(NodeList nodes) {
this.nodes = nodes;
}
@Override
public Iterator<Element> iterator() {
return new NodeListElementIterator(nodes);
return new ElementListIterator(nodes);
}
@Override

View File

@ -63,7 +63,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
Node metadataNode = document.getElementsByTagName(TAG_METADATA).item(0);
Map<String, BuildingMetadata> metadata = new HashMap<>();
for (Element elem : new IterableNodeList(metadataNode.getChildNodes())) {
for (Element elem : new IterableElementList(metadataNode.getChildNodes())) {
String buildingType = elem.getAttribute(ATTRIBUTE_TYPE);
metadata.put(buildingType, parseBuildingMetadata(elem));
@ -86,7 +86,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
FactoryOutput output = null;
int productionInterval = -1;
for (Element elem : new IterableNodeList(factoryElement.getChildNodes())) {
for (Element elem : new IterableElementList(factoryElement.getChildNodes())) {
switch (elem.getNodeName()) {
case TAG_ICONS -> iconsPaths = parseBuildingIcons(elem);
case TAG_INPUT -> {
@ -105,7 +105,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
Map<BuildingState, String> iconsPaths = null;
WarehouseInput input = null;
for (Element elem : new IterableNodeList(warehouseElement.getChildNodes())) {
for (Element elem : new IterableElementList(warehouseElement.getChildNodes())) {
switch (elem.getNodeName()) {
case TAG_ICONS -> iconsPaths = parseBuildingIcons(elem);
case TAG_INPUT -> input = parseWarehouseInput(elem);
@ -118,7 +118,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
private Map<BuildingState, String> parseBuildingIcons(Element iconsElement) {
Map<BuildingState, String> iconsPaths = new HashMap<>();
for (Element elem : new IterableNodeList(iconsElement.getChildNodes())) {
for (Element elem : new IterableElementList(iconsElement.getChildNodes())) {
BuildingState state = BuildingState.getFromTypeName(elem.getAttribute(ATTRIBUTE_TYPE));
String path = elem.getAttribute(ATTRIBUTE_PATH);
@ -154,7 +154,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
Collection<Building> buildings = new ArrayList<>();
Collection<Route> routes = null;
for (Element elem : new IterableNodeList(dataNode.getChildNodes())) {
for (Element elem : new IterableElementList(dataNode.getChildNodes())) {
switch (elem.getNodeName()) {
case TAG_BUILDING -> buildings.add(parseBuilding(elem));
case TAG_ROUTES -> routes = parseRoutes(elem);
@ -178,7 +178,7 @@ public class XmlConfigurationParser implements ConfigurationParser {
private Collection<Route> parseRoutes(Element routesElement) {
Collection<Route> routes = new ArrayList<>();
for (Element elem : new IterableNodeList(routesElement.getChildNodes())) {
for (Element elem : new IterableElementList(routesElement.getChildNodes())) {
int from = Integer.parseInt(elem.getAttribute(ATTRIBUTE_TO));
int to = Integer.parseInt(elem.getAttribute(ATTRIBUTE_FROM));

19
src/view/Environment.java Normal file
View File

@ -0,0 +1,19 @@
package view;
import javax.swing.*;
public class Environment extends SwingWorker<Object, String> {
private static final int DELAY = 100;
private boolean active = true;
@Override
protected Object doInBackground() throws Exception {
while (active) {
Thread.sleep(DELAY);
firePropertyChange("TEST", null, "Ceci est un test");
}
return null;
}
}

23
src/view/MainPanel.java Normal file
View File

@ -0,0 +1,23 @@
package view;
import javax.swing.*;
import java.awt.*;
import java.io.Serial;
public class MainPanel extends JPanel {
@Serial
private static final long serialVersionUID = 1L;
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);
}
}

44
src/view/MainWindow.java Normal file
View File

@ -0,0 +1,44 @@
package view;
import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.Serial;
public class MainWindow extends JFrame implements PropertyChangeListener {
@Serial
private static final long serialVersionUID = 1L;
private static final String WINDOW_TITLE = "Laboratoire 1 : LOG121 - Simulation";
private static final Dimension DIMENSION = new Dimension(700, 700);
public MainWindow() {
MainPanel mainPanel = new MainPanel();
WindowMenu menu = new WindowMenu();
add(mainPanel);
add(menu, BorderLayout.NORTH);
// Faire en sorte que le X de la fenêtre ferme la fenêtre
setDefaultCloseOperation(EXIT_ON_CLOSE);
setTitle(WINDOW_TITLE);
setSize(DIMENSION);
// Rendre la fenêtre visible
setVisible(true);
// Mettre la fenêtre au centre de l'écran
setLocationRelativeTo(null);
// Empêcher la redimension de la fenêtre
setResizable(false);
}
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equals("TEST")) {
repaint();
System.out.println(event.getNewValue());
}
}
}

View File

@ -0,0 +1,57 @@
package view;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.Serial;
import java.util.Enumeration;
public class StrategyPanel extends JPanel {
@Serial
private static final long serialVersionUID = 1L;
public StrategyPanel() {
JRadioButton strategy1 = new JRadioButton("Stratégie 1");
JRadioButton strategy2 = new JRadioButton("Stratégie 2");
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(strategy1);
buttonGroup.add(strategy2);
JButton confirmButton = new JButton("Confirmer");
confirmButton.addActionListener((ActionEvent e) -> {
// TODO - Appeler la bonne stratégie
System.out.println(getSelectedButtonText(buttonGroup));
// Fermer la fenêtre du component
SwingUtilities.getWindowAncestor((Component) e.getSource()).dispose();
});
JButton cancelButton = new JButton("Annuler");
cancelButton.addActionListener((ActionEvent e) -> {
// Fermer la fenêtre du component
SwingUtilities.getWindowAncestor((Component) e.getSource()).dispose();
});
add(strategy1);
add(strategy2);
add(confirmButton);
add(cancelButton);
}
/**
* Retourne le bouton sélectionné dans un groupe de boutons.
*
* @param buttonGroup
* @return
*/
public String getSelectedButtonText(ButtonGroup buttonGroup) {
for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements(); ) {
AbstractButton button = buttons.nextElement();
if (button.isSelected()) {
return button.getText();
}
}
return null;
}
}

View File

@ -0,0 +1,24 @@
package view;
import javax.swing.*;
import java.awt.*;
import java.io.Serial;
public class StrategyWindow extends JFrame {
@Serial
private static final long serialVersionUID = 1L;
private static final String WINDOW_TITLE = "Sélectionnez votre stratégie de vente";
private static final Dimension DIMENSION = new Dimension(250, 100);
private final StrategyPanel strategyPanel = new StrategyPanel();
public StrategyWindow() {
add(strategyPanel);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle(WINDOW_TITLE);
setSize(DIMENSION);
setVisible(true);
setLocationRelativeTo(null);
setResizable(false);
}
}

99
src/view/WindowMenu.java Normal file
View File

@ -0,0 +1,99 @@
package view;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.Serial;
public class WindowMenu extends JMenuBar {
@Serial
private static final long serialVersionUID = 1L;
private static final String MENU_FILE_TITLE = "Fichier";
private static final String MENU_FILE_LOAD = "Charger";
private static final String MENU_FILE_EXIT = "Quitter";
private static final String MENU_SIMULATION_TITLE = "Simulation";
private static final String MENU_SIMULATION_CHOOSE = "Choisir";
private static final String MENU_HELP_TITLE = "Aide";
private static final String MENU_HELP_ABOUT = "À propos de...";
public WindowMenu() {
addFileMenu();
addSimulationMenu();
addHelpMenu();
}
/**
* Créer le menu de fichier.
*/
private void addFileMenu() {
JMenu fileMenu = new JMenu(MENU_FILE_TITLE);
JMenuItem loadMenu = new JMenuItem(MENU_FILE_LOAD);
JMenuItem exitMenu = new JMenuItem(MENU_FILE_EXIT);
loadMenu.addActionListener((ActionEvent e) -> {
JFileChooser fileChooser = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
fileChooser.setDialogTitle("Sélectionnez un fichier de configuration");
fileChooser.setAcceptAllFileFilterUsed(false);
// Créer un filtre
FileNameExtensionFilter filter = new FileNameExtensionFilter(".xml", "xml");
fileChooser.addChoosableFileFilter(filter);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
// TODO - Parser le fichier XML sélectionné
File selectedFile = fileChooser.getSelectedFile();
System.out.println(selectedFile.getAbsoluteFile());
}
});
exitMenu.addActionListener((ActionEvent e) -> {
System.exit(0);
});
fileMenu.add(loadMenu);
fileMenu.add(exitMenu);
add(fileMenu);
}
/**
* Créer le menu de simulation.
*/
private void addSimulationMenu() {
JMenu simulationMenu = new JMenu(MENU_SIMULATION_TITLE);
JMenuItem chooseMenu = new JMenuItem(MENU_SIMULATION_CHOOSE);
chooseMenu.addActionListener((ActionEvent e) -> {
// Ouvrir la fenêtre de sélection
// TODO - Récupérer la bonne stratégie de vente
new StrategyWindow();
});
simulationMenu.add(chooseMenu);
add(simulationMenu);
}
/**
* Créer le menu aide.
*/
private void addHelpMenu() {
JMenu helpMenu = new JMenu(MENU_HELP_TITLE);
JMenuItem aboutMenu = new JMenuItem(MENU_HELP_ABOUT);
aboutMenu.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(null,
"<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>" +
"<p>&Eacute;cole de technologie sup&eacute;rieure</p></html>");
});
helpMenu.add(aboutMenu);
add(helpMenu);
}
}