Add Lines view in gui, try to adapt pom file for Swing UI Designer but not working

This commit is contained in:
RODRIGUEZ lucas 2024-04-29 15:44:12 +02:00
parent c33dd8c883
commit 8c8654ef79
7 changed files with 2169 additions and 21 deletions

54
pom.xml
View file

@ -62,7 +62,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>fr.u_paris.gla.project.itinerary.ItineraryCalculator</mainClass>
<mainClass>fr.u_paris.gla.project.gui.View</mainClass>
</manifest>
</archive>
</configuration>
@ -85,12 +85,64 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<dependencies>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-compiler-ant-tasks</artifactId>
<version>241.15989.121</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-gui-forms-rt</artifactId>
<version>241.15989.121</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-gui-forms-compiler</artifactId>
<version>241.15989.121</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<pluginRepositories>
<pluginRepository>
<id>intellij-repository</id>
<url>https://www.jetbrains.com/intellij-repository/releases</url>
</pluginRepository>
<pluginRepository>
<id>intellij-third-party</id>
<url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
</pluginRepository>
</pluginRepositories>
</project>

View file

@ -181,9 +181,48 @@
<border type="none"/>
<children/>
</grid>
<grid id="5ab99" binding="LinesPanel" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<card name="Card5"/>
</constraints>
<properties>
<background color="-406200"/>
</properties>
<border type="none"/>
<children>
<component id="32efa" class="javax.swing.JLabel" binding="lineLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="20" style="1"/>
<text value="Show line"/>
</properties>
</component>
<component id="4836e" class="javax.swing.JComboBox" binding="linesComboBox">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="200" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="2aedb" class="javax.swing.JButton" binding="showLineButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="1" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="78" height="30"/>
</grid>
</constraints>
<properties>
<text value="Open"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="67039" class="javax.swing.JMenuBar" layout-manager="GridLayoutManager" row-count="9" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="67039" class="javax.swing.JMenuBar" layout-manager="GridLayoutManager" row-count="11" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@ -263,6 +302,21 @@
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b44bf" class="javax.swing.JMenuItem" binding="Lines">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="102" height="20"/>
</grid>
</constraints>
<properties>
<text value="Lines"/>
</properties>
</component>
<vspacer id="1e08c">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</children>

View file

@ -1,5 +1,8 @@
package fr.u_paris.gla.project.gui;
import fr.u_paris.gla.project.idfm.CSVImageProvider;
import fr.u_paris.gla.project.idfm.IDFMNetworkExtractor;
import fr.u_paris.gla.project.idfm.ImagePair;
import fr.u_paris.gla.project.itinerary.Stop;
import javax.swing.*;
@ -7,10 +10,17 @@ import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.logging.Logger;
public class View extends JFrame {
private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName());
private JPanel Cardpanel;
private JMenuItem Home;
private JMenuItem Network;
@ -31,6 +41,11 @@ public class View extends JFrame {
private JPanel stationsPanel;
private JLabel departText;
private JLabel arrText;
private JMenuItem Lines;
private JPanel LinesPanel;
private JLabel lineLabel;
private JComboBox linesComboBox;
private JButton showLineButton;
private ArrayList<Stop> StopList;
@ -46,18 +61,17 @@ public class View extends JFrame {
public View(ArrayList<Stop> s) throws HeadlessException {
table = new JTable();
model = (DefaultTableModel) table.getModel();
model.setColumnCount(2);
model.setColumnIdentifiers(new Object[]{"Line", "Stop"});
this.StopList = s;
setContentPane(MainPanel);
setTitle("app");
setExtendedState(JFrame.MAXIMIZED_BOTH);
//setUndecorated(true);
setVisible(true);
;
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Home.addActionListener(new ActionListener() {
@ -92,6 +106,18 @@ public class View extends JFrame {
}
});
Lines.addActionListener(e -> {
Cardpanel.removeAll();
Cardpanel.add(LinesPanel);
Cardpanel.repaint();
Cardpanel.revalidate();
});
CSVImageProvider.getLineImageMap().forEach(p -> linesComboBox.addItem(p));
showLineButton.addActionListener(f -> {
ImagePair item = (ImagePair) linesComboBox.getSelectedItem();
openWebpage(item.getValue());
});
textField1.addKeyListener(new KeyAdapter() {
@Override
@ -175,8 +201,6 @@ public class View extends JFrame {
s.add(new Stop("M8", "Balard", 1.0315897, 3.0265513));
s.add(new Stop("M14", "Gare de Lyon", 2.4658452681, 3.0265513));
View v = new View(s);
}
@ -236,4 +260,22 @@ public class View extends JFrame {
}
private void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
LOGGER.severe("Error opening browser");
}
}
}
private void openWebpage(String url) {
try {
openWebpage(new URL(url).toURI());
} catch (URISyntaxException|MalformedURLException e) {
LOGGER.severe("Default desktop browser not set");
}
}
}

View file

@ -3,24 +3,23 @@
*/
package fr.u_paris.gla.project.idfm;
import fr.u_paris.gla.project.io.ScheduleFormat;
import java.text.MessageFormat;
import java.io.IOException;
import java.io.InputStream;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Logger;
import fr.u_paris.gla.project.io.ImageFormat;
import fr.u_paris.gla.project.utils.GPS;
import fr.u_paris.gla.project.utils.CSVTools;
public final class CSVImageProvider {
/**
* The logger for information on the process
*/
private static final Logger LOGGER = Logger
.getLogger(IDFMNetworkExtractor.class.getName());
private static final NumberFormat MINUTES_SECOND_FORMATTER = NumberFormat
.getInstance(Locale.ENGLISH);
static {
@ -28,8 +27,14 @@ public final class CSVImageProvider {
}
private final String[] line = new String[ImageFormat.NUMBER_COLUMNS];
private final Iterator<Transport> current;
private static ArrayList<ImagePair> lineImageMap;
public static final String FILE_NAME = "image.csv";
/** Create the stream provider */
public CSVImageProvider(Iterator<Transport> traces) {
this.current = traces;
@ -52,4 +57,23 @@ public final class CSVImageProvider {
return Arrays.copyOf(this.line, this.line.length);
}
public static ArrayList<ImagePair> getLineImageMap() {
if (lineImageMap != null)
return lineImageMap;
lineImageMap = new ArrayList<>();
InputStream is = CSVImageProvider.class.getResourceAsStream(FILE_NAME);
System.out.println(is.toString());
try {
CSVTools.readCSVFromInputStream(is,
(String[] line) -> lineImageMap.add(new ImagePair(
line[ImageFormat.LINE_INDEX],
line[ImageFormat.IMAGE_URL_INDEX]
)));
} catch(IOException e){
LOGGER.severe("File is not generated yet");
}
lineImageMap.sort(Comparator.comparing(ImagePair::getLabel));
return lineImageMap;
}
}

View file

@ -0,0 +1,28 @@
package fr.u_paris.gla.project.idfm;
/**
* This class is made specific to store a Pair of Name/Link to be used in a Swing ComboBox
* These getters ables a ComboBox to show the label returned by toString, and get a specific value when the object is returned
*/
public class ImagePair {
private final String label;
private final String value;
public ImagePair(String label, String value){
this.label = label;
this.value = value;
}
public String getLabel(){
return this.label;
}
public String getValue(){
return this.value;
}
@Override
public String toString(){
return label;
}
}

View file

@ -33,7 +33,7 @@ public final class CSVTools {
* @param contentLineConsumer the variable used to store the data
* @throws IOException if it's impossible to download the file
*/
private static void readCSVFromInputStream(InputStream is, Consumer<String[]> contentLineConsumer)
public static void readCSVFromInputStream(InputStream is, Consumer<String[]> contentLineConsumer)
throws IOException {
ICSVParser parser = new CSVParserBuilder().withSeparator(';').build();
try (Reader reader = new BufferedReader(

File diff suppressed because it is too large Load diff