Skip to content

Commit

Permalink
font adaptive jfx ui
Browse files Browse the repository at this point in the history
  • Loading branch information
optyfr committed Apr 6, 2024
1 parent 470bf1f commit 789baa1
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 43 deletions.
2 changes: 1 addition & 1 deletion jrmfx/src/main/java/jrm/fx/ui/BatchDirUpd8rResults.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>

<BorderPane stylesheets="@MainFrame.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.BatchDirUpd8rResultsController">
<BorderPane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.BatchDirUpd8rResultsController">
<center>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="400.0" prefWidth="600.0">
<content>
Expand Down
3 changes: 1 addition & 2 deletions jrmfx/src/main/java/jrm/fx/ui/BatchDirUpd8rResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.URISyntaxException;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
Expand Down Expand Up @@ -37,7 +36,7 @@ public BatchDirUpd8rResults(Stage parent, DirUpdaterResults results) throws URIS
controller = loader.getController();
if(results!=null && results.getResults()!=null)
controller.getResultList().getItems().setAll(results.getResults());
setScene(new Scene(root));
setScene(new JRMScene(root));
sizeToScene();
show();
}
Expand Down
2 changes: 1 addition & 1 deletion jrmfx/src/main/java/jrm/fx/ui/BatchTorrentResults.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>

<BorderPane prefHeight="500.0" prefWidth="600.0" stylesheets="@MainFrame.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.BatchTorrentResultsController">
<BorderPane prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.BatchTorrentResultsController">
<center>
<ScrollPane fitToHeight="true" fitToWidth="true" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<content>
Expand Down
3 changes: 1 addition & 2 deletions jrmfx/src/main/java/jrm/fx/ui/BatchTorrentResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.URISyntaxException;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
Expand Down Expand Up @@ -39,7 +38,7 @@ public BatchTorrentResults(Stage parent, TrntChkReport results) throws URISyntax
if (results != null)
controller.setResult(results);

setScene(new Scene(root));
setScene(new JRMScene(root));
sizeToScene();
show();
}
Expand Down
89 changes: 89 additions & 0 deletions jrmfx/src/main/java/jrm/fx/ui/JRMScene.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package jrm.fx.ui;

import javafx.beans.NamedArg;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.paint.Paint;
import lombok.Getter;
import lombok.Setter;

public class JRMScene extends Scene
{
public enum StyleSheet
{
SYSTEM(null), XS("XS.css"), S("S.css"), M("M.css"), L("L.css"), XL("XL.css");

@Getter
private String fileName;

private StyleSheet(String fileName)
{
this.fileName = fileName;
}
}

@Getter @Setter private static StyleSheet sheet = StyleSheet.XL;

private String[] orgSheets;

public JRMScene(@NamedArg("root") Parent root, @NamedArg(value="width", defaultValue="-1") double width, @NamedArg(value="height", defaultValue="-1") double height, @NamedArg("depthBuffer") boolean depthBuffer, @NamedArg(value="antiAliasing", defaultValue="DISABLED") SceneAntialiasing antiAliasing)
{
super(root, width, height, depthBuffer, antiAliasing);
initSheets();
}

public JRMScene(@NamedArg("root") Parent root, @NamedArg(value="width", defaultValue="-1") double width, @NamedArg(value="height", defaultValue="-1") double height, @NamedArg("depthBuffer") boolean depthBuffer)
{
super(root, width, height, depthBuffer);
initSheets();
}

public JRMScene(@NamedArg("root") Parent root, @NamedArg(value="width", defaultValue="-1") double width, @NamedArg(value="height", defaultValue="-1") double height, @NamedArg(value="fill", defaultValue="WHITE") Paint fill)
{
super(root, width, height, fill);
initSheets();
}

public JRMScene(@NamedArg("root") Parent root, @NamedArg(value="width", defaultValue="-1") double width, @NamedArg(value="height", defaultValue="-1") double height)
{
super(root, width, height);
initSheets();
}

public JRMScene(@NamedArg("root") Parent root, Paint fill)
{
super(root, fill);
initSheets();
}

public JRMScene(@NamedArg("root") Parent root)
{
super(root);
initSheets();
}

private void initSheets()
{
final var styleSheets = getStylesheets();
orgSheets = styleSheets.toArray(String[]::new);
applySheet(sheet);
}

public void applySheet(StyleSheet ss)
{
getStylesheets().clear();
getStylesheets().addAll(orgSheets);
setSheet(ss);
applySheet(this);
}

public static void applySheet(Scene scene)
{
if(sheet.fileName!=null)
{
final var url = Scene.class.getResource("/jrm/fx/ui/css/%s".formatted(sheet.fileName)).toExternalForm();
scene.getStylesheets().add(url);
}
}
}
8 changes: 5 additions & 3 deletions jrmfx/src/main/java/jrm/fx/ui/Loading.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jrm.fx.ui;

import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Border;
Expand All @@ -24,8 +24,10 @@ public Loading()
final var root = new HBox();
root.setBorder(new Border(new BorderStroke(Color.GRAY, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
root.setPadding(new Insets(5));
root.getChildren().addAll(new ImageView(MainFrame.getIcon("/jrm/resicons/waiting.gif")), new Label("Loading..."));
setScene(new Scene(root));
final var iv = new ImageView(MainFrame.getIcon("/jrm/resicons/waiting.gif"));
root.getChildren().addAll(iv, new Label("Loading..."));
root.setAlignment(Pos.CENTER);
setScene(new JRMScene(root));
show();
}

Expand Down
2 changes: 1 addition & 1 deletion jrmfx/src/main/java/jrm/fx/ui/MainFrame.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>

<TabPane fx:id="tabPane" prefHeight="400.0" prefWidth="800.0" stylesheets="@MainFrame.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.MainFrameController">
<TabPane fx:id="tabPane" prefHeight="400.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.MainFrameController">
<tabs>
<Tab fx:id="profilePanelTab" closable="false" text="%MainFrame.Profiles">
<content>
Expand Down
4 changes: 1 addition & 3 deletions jrmfx/src/main/java/jrm/fx/ui/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.stage.Stage;
Expand Down Expand Up @@ -54,7 +53,7 @@ public void start(Stage primaryStage)
});
primaryStage.getIcons().add(getIcon("/jrm/resicons/rom.png"));
primaryStage.setTitle(Messages.getString("MainFrame.Title") + " " + getVersion());
primaryStage.setScene(new Scene(loadMain()));
primaryStage.setScene(new JRMScene(loadMain()));
setReportFrame(new ReportFrame(primaryStage));
Settings.fromJson(session.getUser().getSettings().getProperty("MainFrame.Bounds", null), primaryStage);
primaryStage.show();
Expand All @@ -78,7 +77,6 @@ private static synchronized TabPane loadMain() throws URISyntaxException, IOExce
final var loader = new FXMLLoader(MainFrame.class.getResource("MainFrame.fxml").toURI().toURL(), Messages.getBundle());
final var root = loader.<TabPane>load();
controller = loader.getController();
root.getStylesheets().add(MainFrame.class.getResource("MainFrame.css").toExternalForm());
return root;
}

Expand Down
1 change: 0 additions & 1 deletion jrmfx/src/main/java/jrm/fx/ui/ProfilePanelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.commons.lang3.SystemUtils;

import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValueBase;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
Expand Down
6 changes: 1 addition & 5 deletions jrmfx/src/main/java/jrm/fx/ui/ScannerPanelController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
import java.util.Collection;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -856,6 +851,7 @@ private void saveSrcList()
}
catch (IOException | URISyntaxException e)
{
e.printStackTrace();
Log.err(e.getMessage(), e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions jrmfx/src/main/java/jrm/fx/ui/SettingsPanel.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>

<ScrollPane fitToWidth="true" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.SettingsPanelController">
<ScrollPane fitToWidth="true" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.SettingsPanelController">
<content>
<GridPane>
<columnConstraints>
Expand Down Expand Up @@ -96,8 +96,8 @@
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="NEVER" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="30.0" prefWidth="60.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="100.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="30.0" prefWidth="60.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="100.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
Expand Down
9 changes: 5 additions & 4 deletions jrmfx/src/main/java/jrm/fx/ui/controls/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import jrm.fx.ui.JRMScene;
import jrm.fx.ui.MainFrame;
import lombok.experimental.UtilityClass;

Expand All @@ -22,8 +23,8 @@
public static void showError(Throwable e)
{
final var alert = new Alert(AlertType.ERROR);
alert.getDialogPane().getScene().getStylesheets().add(alert.getClass().getResource("/jrm/fx/ui/MainFrame.css").toExternalForm());
((Stage)alert.getDialogPane().getScene().getWindow()).getIcons().add(MainFrame.getIcon(ICO));
JRMScene.applySheet(alert.getDialogPane().getScene());
alert.setTitle("Error");
alert.setHeaderText(e.getMessage());

Expand All @@ -44,8 +45,8 @@ public static void showError(Throwable e)
public static void showAlert(String message)
{
Alert alert = new Alert(AlertType.WARNING);
alert.getDialogPane().getScene().getStylesheets().add(alert.getClass().getResource("/jrm/fx/ui/MainFrame.css").toExternalForm());
((Stage)alert.getDialogPane().getScene().getWindow()).getIcons().add(MainFrame.getIcon(ICO));
JRMScene.applySheet(alert.getDialogPane().getScene());
alert.setTitle("Warning");

// Header Text: null
Expand All @@ -58,8 +59,8 @@ public static void showAlert(String message)
public static Optional<ButtonType> showConfirmation(String title, String message, ButtonType... buttons)
{
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.getDialogPane().getScene().getStylesheets().add(alert.getClass().getResource("/jrm/fx/ui/MainFrame.css").toExternalForm());
((Stage)alert.getDialogPane().getScene().getWindow()).getIcons().add(MainFrame.getIcon(ICO));
JRMScene.applySheet(alert.getDialogPane().getScene());
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
Expand All @@ -74,8 +75,8 @@ public static Optional<ButtonType> showConfirmation(String title, String message
public static Optional<ButtonType> showConfirmation(String title, Node message, ButtonType... buttons)
{
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.getDialogPane().getScene().getStylesheets().add(alert.getClass().getResource("/jrm/fx/ui/MainFrame.css").toExternalForm());
((Stage)alert.getDialogPane().getScene().getWindow()).getIcons().add(MainFrame.getIcon(ICO));
JRMScene.applySheet(alert.getDialogPane().getScene());
alert.setTitle(title);
alert.setHeaderText(null);
alert.getDialogPane().setContent(message);
Expand Down
7 changes: 7 additions & 0 deletions jrmfx/src/main/java/jrm/fx/ui/css/L.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.root { -fx-font-size: 17pt; }
.table-view { -fx-font-size: 0.8em; }
.tree-view { -fx-font-size: 0.8em; }
.list-view { -fx-font-size: 0.8em; }
.choice-box { -fx-font-size: 0.8em; }
.context-menu { -fx-font-size: 14pt; }
.titled-pane { -fx-font-size: 0.8em; }
7 changes: 7 additions & 0 deletions jrmfx/src/main/java/jrm/fx/ui/css/M.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.root { -fx-font-size: 14pt; }
.table-view { -fx-font-size: 0.8em; }
.tree-view { -fx-font-size: 0.8em; }
.list-view { -fx-font-size: 0.8em; }
.choice-box { -fx-font-size: 0.8em; }
.context-menu { -fx-font-size: 12pt; }
.titled-pane { -fx-font-size: 0.8em; }
7 changes: 7 additions & 0 deletions jrmfx/src/main/java/jrm/fx/ui/css/S.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.root { -fx-font-size: 11pt; }
.table-view { -fx-font-size: 0.8em; }
.tree-view { -fx-font-size: 0.8em; }
.list-view { -fx-font-size: 0.8em; }
.choice-box { -fx-font-size: 0.8em; }
.context-menu { -fx-font-size: 10pt; }
.titled-pane { -fx-font-size: 0.8em; }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.table-view { -fx-font-size: 0.8em; }
.tree-view { -fx-font-size: 0.8em; }
.list-view { -fx-font-size: 0.8em; }
.choice-box { -fx-font-size: 0.8em; }
.context-menu { -fx-font-size: 16pt; }
.titled-pane { -fx-font-size: 0.8em; }
7 changes: 7 additions & 0 deletions jrmfx/src/main/java/jrm/fx/ui/css/XS.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.root { -fx-font-size: 8pt; }
.table-view { -fx-font-size: 0.8em; }
.tree-view { -fx-font-size: 0.8em; }
.list-view { -fx-font-size: 0.8em; }
.choice-box { -fx-font-size: 0.8em; }
.context-menu { -fx-font-size: 7pt; }
.titled-pane { -fx-font-size: 0.8em; }
6 changes: 3 additions & 3 deletions jrmfx/src/main/java/jrm/fx/ui/profile/ProfileViewer.fxml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.Scene?>
<?import jrm.fx.ui.JRMScene?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuItem?>
Expand All @@ -14,7 +14,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>

<Scene stylesheets="@../MainFrame.css" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.profile.ProfileViewerController">
<JRMScene xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="jrm.fx.ui.profile.ProfileViewerController">
<root>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="600.0" prefWidth="800.0">
<items>
Expand Down Expand Up @@ -154,4 +154,4 @@
</items>
</SplitPane>
</root>
</Scene>
</JRMScene>
3 changes: 2 additions & 1 deletion jrmfx/src/main/java/jrm/fx/ui/profile/ProfileViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
import jrm.fx.ui.JRMScene;
import jrm.fx.ui.MainFrame;
import jrm.fx.ui.misc.Settings;
import jrm.locale.Messages;
Expand Down Expand Up @@ -44,7 +45,7 @@ public ProfileViewer(Stage parent) throws IOException, URISyntaxException
hide();
});
final var loader = new FXMLLoader(getClass().getResource("ProfileViewer.fxml").toURI().toURL(), Messages.getBundle());
final var root = loader.<Scene>load();
final var root = loader.<JRMScene>load();
controller = loader.getController();
setScene(root);
resetCounter.incrementAndGet();
Expand Down
Loading

0 comments on commit 789baa1

Please sign in to comment.