mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-20 10:15:22 -04:00
Add fonts selector for #153
This commit is contained in:
parent
9d4cac26e5
commit
3909371774
21 changed files with 416 additions and 86 deletions
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package nsusbloader;
|
||||
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
|
@ -28,6 +30,7 @@ public class AppPreferences {
|
|||
private final Preferences preferences;
|
||||
private final Locale locale;
|
||||
public static final String[] goldleafSupportedVersions = {"v0.5", "v0.7.x", "v0.8-0.9", "v0.10"};
|
||||
private static final Font DEFAULT_FONT = Font.getDefault();
|
||||
|
||||
private AppPreferences(){
|
||||
this.preferences = Preferences.userRoot().node("NS-USBloader");
|
||||
|
@ -152,4 +155,17 @@ public class AppPreferences {
|
|||
public void setPatchesTabInvisible(boolean value){preferences.putBoolean("patches_tab_visible", value);}
|
||||
public String getPatchPattern(String type, int moduleNumber, int offsetId){ return preferences.get(String.format("%s_%02x_%02x", type, moduleNumber, offsetId), ""); }
|
||||
public void setPatchPattern(String fullTypeSpecifier, String offset){ preferences.put(fullTypeSpecifier, offset); }
|
||||
|
||||
public String getFontFamily(){ return preferences.get("font_family", DEFAULT_FONT.getFamily()); }
|
||||
public double getFontSize(){ return preferences.getDouble("font_size", DEFAULT_FONT.getSize()); }
|
||||
public String getFontStyle(){
|
||||
final String fontFamily = preferences.get("font_family", DEFAULT_FONT.getFamily());
|
||||
final double fontSize = preferences.getDouble("font_size", DEFAULT_FONT.getSize());
|
||||
|
||||
return String.format("-fx-font-family: \"%s\"; -fx-font-size: %.0f;", fontFamily, fontSize);
|
||||
}
|
||||
public void setFontStyle(String fontFamily, double size){
|
||||
preferences.put("font_family", fontFamily);
|
||||
preferences.putDouble("font_size", size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ public class FilesDropHandle {
|
|||
Scene mainScene = new Scene(parentVBox, 310, 185);
|
||||
|
||||
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
parentVBox.setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
stage.setOnHidden(windowEvent -> filesDropHandleTask.cancel(true ) );
|
||||
|
||||
|
|
56
src/main/java/nsusbloader/Controllers/FontSelector.java
Normal file
56
src/main/java/nsusbloader/Controllers/FontSelector.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Copyright 2019-2023 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Controllers;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.Stage;
|
||||
import nsusbloader.AppPreferences;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class FontSelector {
|
||||
public FontSelector(ResourceBundle resourceBundle) throws Exception{
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(800);
|
||||
stage.setMinHeight(800);
|
||||
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/FontSettings.fxml"));
|
||||
fxmlLoader.setResources(resourceBundle);
|
||||
|
||||
stage.setTitle(resourceBundle.getString("tab2_Btn_ApplicationFont"));
|
||||
stage.getIcons().addAll(
|
||||
new Image("/res/app_icon32x32.png"),
|
||||
new Image("/res/app_icon48x48.png"),
|
||||
new Image("/res/app_icon64x64.png"),
|
||||
new Image("/res/app_icon128x128.png"));
|
||||
|
||||
Parent parent = fxmlLoader.load();
|
||||
Scene fontScene = new Scene(parent, 550, 600);
|
||||
|
||||
fontScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
parent.setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
stage.setAlwaysOnTop(true);
|
||||
stage.setScene(fontScene);
|
||||
stage.show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
Copyright 2019-2023 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Controllers;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.stage.Stage;
|
||||
import nsusbloader.AppPreferences;
|
||||
import nsusbloader.MediatorControl;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class FontSettingsController implements Initializable {
|
||||
private final AppPreferences preferences = AppPreferences.getInstance();
|
||||
|
||||
@FXML
|
||||
private Button applyBtn, cancelBtn, resetBtn;
|
||||
|
||||
@FXML
|
||||
private ListView<String> fontsLv;
|
||||
|
||||
@FXML
|
||||
private Spinner<Double> fontSizeSpinner;
|
||||
|
||||
@FXML
|
||||
private Text exampleText;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
applyBtn.setDefaultButton(true);
|
||||
applyBtn.getStyleClass().add("buttonUp");
|
||||
applyBtn.setOnAction(e -> applyChanges());
|
||||
|
||||
cancelBtn.setCancelButton(true);
|
||||
cancelBtn.setOnAction(e -> closeWindow());
|
||||
|
||||
resetBtn.setOnAction(e -> reset());
|
||||
|
||||
fontsLv.setCellFactory(item -> getCellFactory());
|
||||
fontsLv.setItems(getFonts());
|
||||
fontsLv.getSelectionModel().select(preferences.getFontFamily());
|
||||
fontsLv.getSelectionModel().selectedIndexProperty().addListener(
|
||||
(observableValue, oldValueNumber, newValueNumber) -> setExampleTextFont());
|
||||
fontsLv.setFixedCellSize(40.0);
|
||||
|
||||
fontSizeSpinner.setEditable(false);
|
||||
fontSizeSpinner.setValueFactory(getValueFactory());
|
||||
|
||||
exampleText.setText(resourceBundle.getString("fontPreviewText"));
|
||||
|
||||
fontSizeSpinner.getValueFactory().setValue(preferences.getFontSize());
|
||||
}
|
||||
|
||||
private ListCell<String> getCellFactory(){
|
||||
return new ListCell<>(){
|
||||
@Override
|
||||
protected void updateItem(String item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (empty || item == null)
|
||||
return;
|
||||
Font font = Font.font(item);
|
||||
Text itemText = new Text(item);
|
||||
itemText.setFont(font);
|
||||
setGraphic(itemText);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ObservableList<String> getFonts(){
|
||||
ObservableList<String> fonts = FXCollections.observableArrayList();
|
||||
fonts.addAll(Font.getFamilies());
|
||||
|
||||
return fonts;
|
||||
}
|
||||
|
||||
private SpinnerValueFactory<Double> getValueFactory(){
|
||||
return new SpinnerValueFactory<>() {
|
||||
@Override
|
||||
public void decrement(int i) {
|
||||
double value = getValue() - i;
|
||||
if (value < 4)
|
||||
return;
|
||||
|
||||
setValue(value);
|
||||
setExampleTextFont(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increment(int i) {
|
||||
double value = getValue() + i;
|
||||
if (value > 100)
|
||||
return;
|
||||
|
||||
setValue(value);
|
||||
setExampleTextFont(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setExampleTextFont(){
|
||||
setExampleTextFont(fontsLv.getSelectionModel().getSelectedItem(), fontSizeSpinner.getValue());
|
||||
}
|
||||
private void setExampleTextFont(double size){
|
||||
setExampleTextFont(fontsLv.getSelectionModel().getSelectedItem(), size);
|
||||
}
|
||||
private void setExampleTextFont(String font, double size){
|
||||
exampleText.setFont(Font.font(font, size));
|
||||
}
|
||||
|
||||
private void reset(){
|
||||
final Font defaultFont = Font.getDefault();
|
||||
exampleText.setFont(defaultFont);
|
||||
|
||||
fontsLv.getSelectionModel().select(defaultFont.getFamily());
|
||||
fontSizeSpinner.getValueFactory().setValue(defaultFont.getSize());
|
||||
}
|
||||
|
||||
private void applyChanges(){
|
||||
final String fontFamily = fontsLv.getSelectionModel().getSelectedItem();
|
||||
final double fontSize = fontSizeSpinner.getValue().intValue();
|
||||
|
||||
preferences.setFontStyle(fontFamily, fontSize);
|
||||
MediatorControl.getInstance().updateApplicationFont(fontFamily, fontSize);
|
||||
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
private void closeWindow(){
|
||||
((Stage) cancelBtn.getScene().getWindow()).close();
|
||||
}
|
||||
}
|
|
@ -43,6 +43,9 @@ import java.util.ResourceBundle;
|
|||
public class SettingsBlockGenericController implements Initializable {
|
||||
@FXML
|
||||
private ChoiceBox<LocaleHolder> languagesChB;
|
||||
@FXML
|
||||
private Button fontSelectBtn;
|
||||
|
||||
@FXML
|
||||
private Button submitLanguageBtn,
|
||||
driversInstallBtn,
|
||||
|
@ -81,6 +84,14 @@ public class SettingsBlockGenericController implements Initializable {
|
|||
newVersionHyperlink.setOnAction(e-> hostServices.showDocument(newVersionHyperlink.getText()));
|
||||
checkForUpdBtn.setOnAction(e->checkForUpdatesAction());
|
||||
submitLanguageBtn.setOnAction(e->languageButtonAction());
|
||||
fontSelectBtn.setOnAction(e -> openFontSettings());
|
||||
}
|
||||
private void openFontSettings() {
|
||||
try {
|
||||
new FontSelector(resourceBundle);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void setDriversInstallFeature(){
|
||||
|
|
|
@ -60,4 +60,8 @@ public class MediatorControl {
|
|||
getPatchesController().notifyThreadStarted(isActive, appModuleType);
|
||||
}
|
||||
public synchronized boolean getTransferActive() { return this.isTransferActive.get(); }
|
||||
public void updateApplicationFont(String fontFamily, double fontSize){
|
||||
mainController.logArea.getScene().getRoot().setStyle(
|
||||
String.format("-fx-font-family: \"%s\"; -fx-font-size: %.0f;", fontFamily, fontSize));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class NSLMain extends Application {
|
|||
);
|
||||
|
||||
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
root.setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
primaryStage.setScene(mainScene);
|
||||
primaryStage.show();
|
||||
|
|
|
@ -44,7 +44,6 @@ public class ServiceWindow {
|
|||
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
|
||||
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
|
||||
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
|
||||
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
|
||||
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
|
||||
dialogStage.setAlwaysOnTop(true);
|
||||
|
@ -54,6 +53,9 @@ public class ServiceWindow {
|
|||
new Image("/res/warn_ico64x64.png"),
|
||||
new Image("/res/warn_ico128x128.png")
|
||||
);
|
||||
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
dialogStage.getScene().getRoot().setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
alertBox.show();
|
||||
dialogStage.toFront();
|
||||
}
|
||||
|
@ -68,7 +70,6 @@ public class ServiceWindow {
|
|||
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
|
||||
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
|
||||
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
|
||||
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
|
||||
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
|
||||
dialogStage.setAlwaysOnTop(true);
|
||||
|
@ -78,6 +79,10 @@ public class ServiceWindow {
|
|||
new Image("/res/ask_ico64x64.png"),
|
||||
new Image("/res/ask_ico128x128.png")
|
||||
);
|
||||
|
||||
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
dialogStage.getScene().getRoot().setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
dialogStage.toFront();
|
||||
|
||||
Optional<ButtonType> result = alertBox.showAndWait();
|
||||
|
|
|
@ -103,6 +103,7 @@ public class DriversInstall {
|
|||
Scene mainScene = new Scene(parentVBox, 405, 155);
|
||||
|
||||
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
parentVBox.setStyle(AppPreferences.getInstance().getFontStyle());
|
||||
|
||||
stage.setOnHidden(windowEvent -> {
|
||||
downloadTask.cancel(true );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue