[chore] Formatting

This commit is contained in:
Bigeon Emmanuel 2024-02-10 17:44:26 +01:00
parent 115caa0218
commit 8bcee58b98
3 changed files with 131 additions and 128 deletions

84
pom.xml
View file

@ -1,49 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.u-paris.gla</groupId> <groupId>fr.u-paris.gla</groupId>
<artifactId>project</artifactId> <artifactId>project</artifactId>
<version>2024.1.0.0-SNAPSHOT</version> <version>2024.1.0.0-SNAPSHOT</version>
<name>Project Base</name> <name>Project Base</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId> <artifactId>junit-jupiter</artifactId>
<version>5.9.1</version> <version>5.9.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version> <version>3.3.0</version>
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<addClasspath>true</addClasspath> <addClasspath>true</addClasspath>
<mainClass>fr.u_paris.gla.project.App</mainClass> <mainClass>fr.u_paris.gla.project.App</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
</plugins> <resources> </plugins>
<resource> <resources>
<directory>src/main/resources-filtered</directory> <resource>
<filtering>true</filtering> <directory>src/main/resources-filtered</directory>
</resource> <filtering>true</filtering>
</resources> </resource>
</build> </resources>
</build>
</project> </project>

View file

@ -19,95 +19,96 @@ import javax.swing.WindowConstants;
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class App { public class App {
/** /**
* *
*/ */
private static final String UNSPECIFIED = "Unspecified"; //$NON-NLS-1$ private static final String UNSPECIFIED = "Unspecified"; //$NON-NLS-1$
/** The logo image name. */ /** The logo image name. */
private static final String LOGO_NAME = "uparis_logo_rvb.png"; //$NON-NLS-1$ private static final String LOGO_NAME = "uparis_logo_rvb.png"; //$NON-NLS-1$
/** Image height. */ /** Image height. */
private static final int HEIGHT = 256; private static final int HEIGHT = 256;
/** Image width. */ /** Image width. */
private static final int WIDTH = HEIGHT; private static final int WIDTH = HEIGHT;
/** Resizes an image. /** Resizes an image.
* *
* @param src source image * @param src source image
* @param w width * @param w width
* @param h height * @param h height
* @return the resized image */ * @return the resized image */
private static Image getScaledImage(Image src, int w, int h) { private static Image getScaledImage(Image src, int w, int h) {
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = resizedImg.createGraphics(); Graphics2D g2d = resizedImg.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR); RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(src, 0, 0, w, h, null); g2d.drawImage(src, 0, 0, w, h, null);
g2d.dispose(); g2d.dispose();
return resizedImg; return resizedImg;
} }
/** Application entry point. /** Application entry point.
* *
* @param args launching arguments */ * @param args launching arguments */
public static void main(String[] args) { public static void main(String[] args) {
if (args.length > 0) { if (args.length > 0) {
for (String string : args) { for (String string : args) {
if ("--info".equals(string)) { //$NON-NLS-1$ if ("--info".equals(string)) { //$NON-NLS-1$
printAppInfos(System.out); printAppInfos(System.out);
return; return;
}
if ("--gui".equals(string)) { //$NON-NLS-1$
showLogo();
}
}
} }
if ("--gui".equals(string)) { //$NON-NLS-1$ }
showLogo();
/** @param out */
public static void printAppInfos(PrintStream out) {
Properties props = new Properties();
try (InputStream is = App.class.getResourceAsStream("application.properties")) { //$NON-NLS-1$
props.load(is);
} catch (IOException e) {
throw new RuntimeException("Unable to read application informations", e); //$NON-NLS-1$
} }
}
}
}
/** @param out */ out.println("Application: " + props.getProperty("app.name", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
public static void printAppInfos(PrintStream out) { out.println("Version: " + props.getProperty("app.version", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
Properties props = new Properties(); out.println("By: " + props.getProperty("app.team", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
try (InputStream is = App.class.getResourceAsStream("application.properties")) { //$NON-NLS-1$
props.load(is);
} catch (IOException e) {
throw new RuntimeException("Unable to read application informations", e); //$NON-NLS-1$
} }
out.println("Application: " + props.getProperty("app.name", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$ /** Shows the logo in an image. */
out.println("Version: " + props.getProperty("app.version", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$ public static void showLogo() {
out.println("By: " + props.getProperty("app.team", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$ Properties props = new Properties();
} try (InputStream is = App.class.getResourceAsStream("application.properties")) { //$NON-NLS-1$
props.load(is);
} catch (IOException e) {
throw new RuntimeException("Unable to read application informations", e); //$NON-NLS-1$
}
/** Shows the logo in an image. */ JFrame frame = new JFrame(props.getProperty("app.name")); //$NON-NLS-1$
public static void showLogo() { frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Properties props = new Properties();
try (InputStream is = App.class.getResourceAsStream("application.properties")) { //$NON-NLS-1$ JLabel container = new JLabel();
props.load(is);
} catch (IOException e) { try (InputStream is = App.class.getResourceAsStream(LOGO_NAME)) {
throw new RuntimeException("Unable to read application informations", e); //$NON-NLS-1$ if (is == null) {
container.setText("Image Not Found");
} else {
BufferedImage img = ImageIO.read(is);
ImageIcon icon = new ImageIcon(img);
ImageIcon resized = new ImageIcon(
getScaledImage(icon.getImage(), WIDTH, HEIGHT));
container.setIcon(resized);
}
} catch (IOException e) {
container.setText("Image Not Read: " + e.getLocalizedMessage());
}
frame.getContentPane().add(container);
frame.pack();
frame.setVisible(true);
} }
JFrame frame = new JFrame(props.getProperty("app.name")); //$NON-NLS-1$
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JLabel container = new JLabel();
try (InputStream is = App.class.getResourceAsStream(LOGO_NAME)) {
if (is == null) {
container.setText("Image Not Found");
} else {
BufferedImage img = ImageIO.read(is);
ImageIcon icon = new ImageIcon(img);
ImageIcon resized = new ImageIcon(getScaledImage(icon.getImage(), WIDTH, HEIGHT));
container.setIcon(resized);
}
} catch (IOException e) {
container.setText("Image Not Read: "+e.getLocalizedMessage());
}
frame.getContentPane().add(container);
frame.pack();
frame.setVisible(true);
}
} }

View file

@ -6,9 +6,9 @@ import org.junit.jupiter.api.Test;
/** Unit test for simple App. */ /** Unit test for simple App. */
public class AppTest { public class AppTest {
/** Rigorous Test :-) */ /** Rigorous Test :-) */
@Test @Test
public void shouldAnswerWithTrue() { public void shouldAnswerWithTrue() {
assertTrue(true); assertTrue(true);
} }
} }