Skip to content

Commit

Permalink
feat: Additional fonts.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Dec 5, 2023
1 parent 6d6640a commit 699ed4f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 41 deletions.
120 changes: 79 additions & 41 deletions src/main/java/viewtify/Viewtify.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.sun.javafx.application.PlatformImpl;

import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.DoubleExpression;
Expand Down Expand Up @@ -65,9 +67,6 @@
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.stage.WindowEvent;

import com.sun.javafx.application.PlatformImpl;

import kiss.Decoder;
import kiss.Disposable;
import kiss.Encoder;
Expand Down Expand Up @@ -151,8 +150,13 @@ public Thread newThread(Runnable runnable) {
.get();

// load additional fonts
Font.loadFont(ClassLoader.getSystemResourceAsStream("viewtify/font/LeagueGothic.ttf"), 14);
Font.loadFont(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/LeagueGothic.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-Bold.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-SemiBold.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-Medium.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-Regular.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-Light.ttf"), 14);
Font.loadFonts(ClassLoader.getSystemResourceAsStream("viewtify/font/Oswald-ExtraLight.ttf"), 14);

CSS.enhance();

Expand Down Expand Up @@ -204,6 +208,9 @@ public Thread newThread(Runnable runnable) {
/** The configurable setting. */
private Class<? extends DesignScheme> scheme;

/** The configurable setting. */
private Class<? extends View> opener;

/** The configurable setting. */
private BooleanSupplier closer;

Expand Down Expand Up @@ -286,6 +293,17 @@ public static synchronized Viewtify application() {
return viewtify;
}

/**
* Configure the closing request.
*
* @param opener
* @return
*/
public Viewtify onOpening(Class<? extends View> opener) {
this.opener = opener;
return this;
}

/**
* Configure the closing request.
*
Expand Down Expand Up @@ -497,54 +515,74 @@ public void activate(View application) {
// the entire life cycle of the application. If you run it more than once, nothing happens.
initializeOnlyOnce(application.getClass());

boolean canUpdate = I.env("UpdateOnStartup", updateArchive != null);
boolean needUpdate = canUpdate && Update.isValid(updateArchive);

// launch application
PlatformImpl.startup(() -> {
toolkitInitialized = true;

View actual = needUpdate ? new Empty() : application;
mainStage = new Stage(stageStyle);
mainStage.setWidth(width != 0 ? width : Screen.getPrimary().getBounds().getWidth() / 2);
mainStage.setHeight(height != 0 ? height : Screen.getPrimary().getBounds().getHeight() / 2);
if (needUpdate) mainStage.setOpacity(0);

Scene scene = new Scene((Parent) actual.ui());
manage(actual.getClass().getName(), scene, mainStage, false);
if (opener == null) {
activateApplication(application);
} else {
View o = I.make(opener);
Stage stage = new Stage();
stage.initStyle(StageStyle.TRANSPARENT);
Scene scene = new Scene((Parent) o.ui());
stage.setScene(scene);

// root stage management
views.add(application);
mainStage.showingProperty().addListener((observable, oldValue, newValue) -> {
if (oldValue == true && newValue == false) {
views.remove(application);
manage("opener", scene, stage, false);

// If the last window has been closed, deactivate this application.
if (views.isEmpty()) deactivate();
}
});

if (closer != null) {
mainStage.setOnCloseRequest(e -> {
if (!closer.getAsBoolean()) {
e.consume();
}
inUI(() -> {
stage.setOnHidden(e -> activateApplication(application));
stage.show();
});
}

mainStage.setScene(scene);
mainStage.show();
}, false);
}

private void activateApplication(View application) {
boolean canUpdate = I.env("UpdateOnStartup", updateArchive != null);
boolean needUpdate = canUpdate && Update.isValid(updateArchive);

View actual = needUpdate ? new Empty() : application;
mainStage = new Stage(stageStyle);
mainStage.setWidth(width != 0 ? width : Screen.getPrimary().getBounds().getWidth() / 2);
mainStage.setHeight(height != 0 ? height : Screen.getPrimary().getBounds().getHeight() / 2);
if (needUpdate) mainStage.setOpacity(0);

// process the unexecuted UI action
waitingActions.forEach(Runnable::run);
waitingActions = null;
Scene scene = new Scene((Parent) actual.ui());
manage(actual.getClass().getName(), scene, mainStage, false);

if (!isHeadless()) {
// release resources for splash screen
SplashScreen screen = SplashScreen.getSplashScreen();
if (screen != null) screen.close();
// root stage management
views.add(application);
mainStage.showingProperty().addListener((observable, oldValue, newValue) -> {
if (oldValue == true && newValue == false) {
views.remove(application);

// If the last window has been closed, deactivate this application.
if (views.isEmpty()) deactivate();
}
}, false);
});

if (closer != null) {
mainStage.setOnCloseRequest(e -> {
if (!closer.getAsBoolean()) {
e.consume();
}
});
}

mainStage.setScene(scene);
mainStage.show();

// process the unexecuted UI action
waitingActions.forEach(Runnable::run);
waitingActions = null;

if (!isHeadless()) {
// release resources for splash screen
SplashScreen screen = SplashScreen.getSplashScreen();
if (screen != null) screen.close();
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/viewtify/ui/helper/LabelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ default Self icon(String iconPath) {
return icon(iconPath, 0, 0);
}

/**
* Set icon.
*
* @param iconPath
* @return
*/
default Self icon(String iconPath, int size) {
return icon(iconPath, size, size);
}

/**
* Set icon.
*
Expand Down
Binary file added src/main/resources/viewtify/font/Oswald-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file added src/main/resources/viewtify/font/Oswald-Light.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed src/main/resources/viewtify/font/Oswald.ttf
Binary file not shown.

0 comments on commit 699ed4f

Please sign in to comment.