Skip to content
Snippets Groups Projects
Commit 3cf18be7 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Version javaFX 2023

parent 13eb50ed
Branches
No related tags found
No related merge requests found
Pipeline #19249 passed
......@@ -4,12 +4,19 @@ plugins {
id 'checkstyle'
id 'jacoco'
id 'pmd'
id "com.github.spotbugs" version "5.0.12"
id "com.github.spotbugs" version "5.0.13"
id 'org.openjfx.javafxplugin' version '0.1.0'
id 'org.beryx.jlink' version '2.26.0'
}
group 'fr.univ_amu'
version '1.0-SNAPSHOT'
javafx {
version = "21"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
checkstyle {
toolVersion = '10.3.4'
}
......@@ -19,12 +26,12 @@ repositories {
}
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter-api:5.9.0',
'org.assertj:assertj-core:3.23.1')
testImplementation('org.junit.jupiter:junit-jupiter-api:5.10.0',
'org.assertj:assertj-core:3.24.2')
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
implementation 'org.apache.logging.log4j:log4j-api:2.20.0'
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
}
test {
......@@ -39,7 +46,7 @@ test {
}
application {
mainClass = 'sample.MyJavaFrame'
mainClass = 'sample.App'
}
tasks.named('jar') {
......@@ -60,7 +67,8 @@ spotbugsMain {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
Provider<Directory> output = layout.buildDirectory.dir("reports/spotbugs/main/spotbugs.html")
outputLocation = output.get().asFile
stylesheet = 'fancy-hist.xsl'
}
}
......@@ -70,7 +78,8 @@ spotbugsTest {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/test/spotbugs.html")
Provider<Directory> output = layout.buildDirectory.dir("reports/spotbugs/test/spotbugs.html")
outputLocation = output.get().asFile
stylesheet = 'fancy-hist.xsl'
}
}
......
org.gradle.warning.mode=none
\ No newline at end of file
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
package sample;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) {
Scene scene = createScene();
stage.setTitle("Loading an image");
stage.setScene(scene);
stage.show();
}
private static Scene createScene() {
Image image = new Image("sample/image.png");
//Setting the image view
ImageView imageView = new ImageView(image);
//Setting the position of the image
imageView.setX(100);
imageView.setY(100);
//setting the fit height and width of the image view
imageView.setFitHeight(216);
imageView.setFitWidth(256);
//Setting the preserve ratio of the image view
imageView.setPreserveRatio(true);
//Creating a Group object
Group root = new Group(imageView);
//Creating and returning a scene object
return new Scene(root, 600, 600);
}
public static void main(String[] args) {
launch();
}
}
package sample;
import java.io.Serial;
import javax.swing.JFrame;
/**
* An extended version of javax.swing.JFrame containing a panel to draw images.
*/
public class MyJavaFrame extends JFrame {
@Serial
private static final long serialVersionUID = 42L;
/**
* Constructs a new visible frame.
*/
public MyJavaFrame() {
setTitle("Main window");
setSize(400, 400);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new MyJavaPanel());
setVisible(true);
}
public static void main(String[] args) {
new MyJavaFrame();
}
}
package sample;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.Serial;
import java.text.MessageFormat;
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* An extension of javax.swing.JFrame that can draw images.
*/
public class MyJavaPanel extends JPanel {
@Serial
private static final long serialVersionUID = 4242L;
private transient BufferedImage image;
/**
* Constructs a new panel that draw an image.
*/
public MyJavaPanel() {
Logger logger = LogManager.getLogger(this.getClass());
logger.debug("Construct a MyJavaPanel");
String path = "image.png";
if (logger.isDebugEnabled()) {
String message = MessageFormat.format("Loading image at path {0}", path);
logger.debug(message);
}
try {
image = ImageIO.read(Objects.requireNonNull(getClass().getResource(path)));
} catch (Exception ex) {
String message = MessageFormat.format("Error: Cannot load image at path: {0}", path);
logger.error(message, ex);
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 50, 50, null);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment