[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"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
<artifactId>project</artifactId>
<version>2024.1.0.0-SNAPSHOT</version>
<groupId>fr.u-paris.gla</groupId>
<artifactId>project</artifactId>
<version>2024.1.0.0-SNAPSHOT</version>
<name>Project Base</name>
<name>Project Base</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fr.u_paris.gla.project.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins> <resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fr.u_paris.gla.project.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

View file

@ -19,95 +19,96 @@ import javax.swing.WindowConstants;
*
* @author Emmanuel Bigeon */
public class App {
/**
*
*/
private static final String UNSPECIFIED = "Unspecified"; //$NON-NLS-1$
/** The logo image name. */
private static final String LOGO_NAME = "uparis_logo_rvb.png"; //$NON-NLS-1$
/** Image height. */
private static final int HEIGHT = 256;
/** Image width. */
private static final int WIDTH = HEIGHT;
/**
*
*/
private static final String UNSPECIFIED = "Unspecified"; //$NON-NLS-1$
/** The logo image name. */
private static final String LOGO_NAME = "uparis_logo_rvb.png"; //$NON-NLS-1$
/** Image height. */
private static final int HEIGHT = 256;
/** Image width. */
private static final int WIDTH = HEIGHT;
/** Resizes an image.
*
* @param src source image
* @param w width
* @param h height
* @return the resized image */
private static Image getScaledImage(Image src, int w, int h) {
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = resizedImg.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(src, 0, 0, w, h, null);
g2d.dispose();
return resizedImg;
}
/** Resizes an image.
*
* @param src source image
* @param w width
* @param h height
* @return the resized image */
private static Image getScaledImage(Image src, int w, int h) {
BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = resizedImg.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(src, 0, 0, w, h, null);
g2d.dispose();
return resizedImg;
}
/** Application entry point.
*
* @param args launching arguments */
public static void main(String[] args) {
if (args.length > 0) {
for (String string : args) {
if ("--info".equals(string)) { //$NON-NLS-1$
printAppInfos(System.out);
return;
/** Application entry point.
*
* @param args launching arguments */
public static void main(String[] args) {
if (args.length > 0) {
for (String string : args) {
if ("--info".equals(string)) { //$NON-NLS-1$
printAppInfos(System.out);
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 */
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$
out.println("Application: " + props.getProperty("app.name", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
out.println("Version: " + props.getProperty("app.version", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
out.println("By: " + props.getProperty("app.team", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
}
out.println("Application: " + props.getProperty("app.name", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
out.println("Version: " + props.getProperty("app.version", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
out.println("By: " + props.getProperty("app.team", UNSPECIFIED)); //$NON-NLS-1$ //$NON-NLS-2$
}
/** Shows the logo in an image. */
public static void showLogo() {
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. */
public static void showLogo() {
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$
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);
}
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. */
public class AppTest {
/** Rigorous Test :-) */
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
/** Rigorous Test :-) */
@Test
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}