Settings window added; tray usage option added.

This commit is contained in:
Dmitry Isaenko 2019-10-20 00:07:01 +03:00
parent df6207614a
commit 9ae020f9b1
13 changed files with 238 additions and 34 deletions

21
Jenkinsfile vendored Normal file
View file

@ -0,0 +1,21 @@
pipeline {
agent {
docker {
image 'maven:3-jdk-11'
args '-v /home/docker/jenkins/files/m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
}
post {
always {
archiveArtifacts artifacts: 'target/*.jar, target/*.exe', onlyIfSuccessful: true
}
}
}

View file

@ -58,8 +58,8 @@ Want to support development? Make a donation* (see below):
* [x] Tray support
* [ ] tray icon size checks
* [x] Configuration files support
* [ ] Settings
* [ ] Tray icon settings
* [x] Settings
* [x] Tray icon settings
* [ ] Autoload
* [ ] Headless mode (CLI)
* [x] Fix UI

View file

@ -6,7 +6,7 @@
<groupId>loper</groupId>
<artifactId>LogiLed</artifactId>
<version>0.4-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<!-- <url></url> -->
<description>
@ -164,6 +164,7 @@
<version>2.10.0</version>
<scope>compile</scope>
</dependency>
<!--
<dependency>
<groupId>net.java.dev.jna</groupId>

View file

@ -0,0 +1,25 @@
package logiled;
import java.util.prefs.Preferences;
// Rule application settings
public class AppPreferences {
private Preferences preferences;
public AppPreferences(){
preferences = Preferences.userRoot().node("LogiLed");
}
public void setUseTray(boolean value){ preferences.putBoolean("USE_TRAY", value); }
public boolean getUseTray(){ return preferences.getBoolean("USE_TRAY", true); }
/*
public void setPath(String path){
preferences.put("PATH", path);
}
public String getPath(){
return preferences.get("PATH", "/");
}
*/
}

View file

@ -12,6 +12,7 @@ import logiled.About.AboutWindow;
import logiled.MessagesConsumer;
import logiled.Config.SettingsFileFormat;
import logiled.ServiceWindow;
import logiled.Settings.SettingsWindow;
import logiled.USB.EffectsThread;
import logiled.USB.GameModeThread;
import logiled.USB.KeyLedThread;
@ -39,7 +40,7 @@ public class MainController implements Initializable {
private Tab KeyLedTab, EffectsTab;
*/
@FXML
private Button applyBtn, openBtn, saveBtn, saveAsBtn, aboutBtn;
private Button applyBtn, openBtn, saveBtn, saveAsBtn, settingsBtn, aboutBtn;
@FXML
private Label infoLbl;
@ -54,6 +55,7 @@ public class MainController implements Initializable {
this.rb = resourceBundle;
aboutBtn.setOnAction(actionEvent -> new AboutWindow());
settingsBtn.setOnAction(actionEvent -> new SettingsWindow());
MessagesConsumer.getInstance().setInstance(infoLbl);
MessagesConsumer.getInstance().start();

View file

@ -16,15 +16,21 @@ import java.util.Locale;
import java.util.ResourceBundle;
public class MainFx extends Application {
public static final String appVersion = "v0.4";
public static final String appVersion = "v1.0";
private static boolean traySupport = true;
private Stage stage;
private SystemTray tray;
private TrayIcon trayIcon;
private ResourceBundle rb;
@Override
public void start(Stage primaryStage) throws Exception{
AppPreferences appPreferences = new AppPreferences();
if (traySupport) // By default it's enabled, but in case it disabled from CLI, don't touch.
traySupport = appPreferences.getUseTray(); // Otherwise, check against preferences
//-----------------------Tray support---------------------
this.stage = primaryStage;
if (traySupport){
@ -32,7 +38,8 @@ public class MainFx extends Application {
SwingUtilities.invokeLater(this::addAppToTray);
}
//--------------------------------------------------------
Mediator.getInstance().setInstance(getHostServices());
Mediator.getInstance().setHostServices(getHostServices());
Mediator.getInstance().setPreferences(appPreferences);
FXMLLoader loader = new FXMLLoader(getClass().getResource("/Main.fxml"));
@ -52,8 +59,20 @@ public class MainFx extends Application {
new Image(getClass().getResourceAsStream("/ico/appIcon_128.png"))
);
// NOTE: tray leftovers
if (traySupport)
primaryStage.setOnCloseRequest(windowEvent -> primaryStage.hide());
if (traySupport) {
stage.setOnCloseRequest(windowEvent -> {
Platform.exit();
tray.remove(trayIcon);
});
stage.iconifiedProperty().addListener((observableValue, oldVal, iconified) -> {
if (iconified)
Platform.runLater(this::hideStage);
else
Platform.runLater(this::showStage);
});
//primaryStage.setOnCloseRequest(windowEvent -> primaryStage.hide());
}
primaryStage.setTitle("LogiLed "+appVersion);
primaryStage.setMinWidth(1215);
@ -75,9 +94,9 @@ public class MainFx extends Application {
Platform.exit();
}
SystemTray tray = SystemTray.getSystemTray();
tray = SystemTray.getSystemTray();
TrayIcon trayIcon = new TrayIcon(ImageIO.read(getClass().getResourceAsStream("/ico/appIcon_24.png")));
trayIcon = new TrayIcon(ImageIO.read(getClass().getResourceAsStream("/ico/appIcon_24.png")));
trayIcon.addActionListener(ActionEvent -> Platform.runLater(this::showStage));
@ -89,9 +108,16 @@ public class MainFx extends Application {
java.awt.Font defaultFont = java.awt.Font.decode(null);
java.awt.Font boldFont = defaultFont.deriveFont(java.awt.Font.BOLD);
MenuItem openItem = new MenuItem(rb.getString("open"));
openItem.addActionListener(actionEvent -> Platform.runLater(this::showStage));
openItem.setFont(boldFont);
closeItem.setFont(boldFont);
final PopupMenu popupMenu = new PopupMenu();
popupMenu.add(openItem);
popupMenu.addSeparator();
popupMenu.add(closeItem);
trayIcon.setPopupMenu(popupMenu);
tray.add(trayIcon);
@ -103,10 +129,16 @@ public class MainFx extends Application {
}
private void showStage() {
if (stage != null) {
if (stage == null)
return;
stage.show();
stage.toFront();
}
private void hideStage(){
if (stage == null)
return;
stage.hide();
}
public static void main(String[] args) {

View file

@ -5,14 +5,17 @@ import javafx.application.HostServices;
public class Mediator{
private HostServices hostServices;
private AppPreferences preferences;
public static Mediator getInstance(){ return MediatorHolder.INSTANCE; }
public void setInstance(HostServices hostServices){ this.hostServices = hostServices; }
public void setHostServices(HostServices hostServices){ this.hostServices = hostServices; }
public void setPreferences(AppPreferences preferences){ this.preferences = preferences; }
private static class MediatorHolder{
private static final Mediator INSTANCE = new Mediator();
}
public HostServices getHostServices() { return hostServices; }
public AppPreferences getPreferences() { return preferences; }
}

View file

@ -0,0 +1,34 @@
package logiled.Settings;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.stage.Stage;
import logiled.Mediator;
import java.net.URL;
import java.util.ResourceBundle;
public class SettingsController implements Initializable {
@FXML
private Button cancelBtn, okBtn;
@FXML
private CheckBox trayCB;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
trayCB.setSelected(Mediator.getInstance().getPreferences().getUseTray());
cancelBtn.setOnAction(actionEvent -> ((Stage) cancelBtn.getScene().getWindow()).close());
okBtn.setOnAction(actionEvent -> {
Mediator.getInstance().getPreferences().setUseTray(trayCB.isSelected());
((Stage) cancelBtn.getScene().getWindow()).close();
});
//trayCB.setSelected();
}
}

View file

@ -0,0 +1,44 @@
package logiled.Settings;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;
public class SettingsWindow {
public SettingsWindow(){
Stage stageAbout = new Stage();
stageAbout.setMinWidth(500);
stageAbout.setMinHeight(500);
FXMLLoader loaderAbout = new FXMLLoader(getClass().getResource("/SettingsLayout.fxml"));
ResourceBundle resourceBundle;
Locale userLocale = new Locale(Locale.getDefault().getISO3Language()); // NOTE: user locale based on ISO3 Language codes
resourceBundle = ResourceBundle.getBundle("locale", userLocale);
loaderAbout.setResources(resourceBundle);
try {
Parent parentAbout = loaderAbout.load();
stageAbout.setTitle(resourceBundle.getString("btn_settings"));
stageAbout.getIcons().addAll(
new Image(getClass().getResourceAsStream("/ico/appIcon_32.png")),
new Image(getClass().getResourceAsStream("/ico/appIcon_48.png")),
new Image(getClass().getResourceAsStream("/ico/appIcon_64.png")),
new Image(getClass().getResourceAsStream("/ico/appIcon_128.png"))
);
stageAbout.setScene(new Scene(parentAbout, 500, 500));
stageAbout.show();
} catch (IOException ignored){}
}
}

View file

@ -71,7 +71,7 @@
<top>
<ToolBar styleClass="header" BorderPane.alignment="CENTER">
<items>
<Button fx:id="applyBtn" minHeight="36.0" mnemonicParsing="false">
<Button fx:id="applyBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<tooltip>
<Tooltip text="%btn_apply" />
</tooltip>
@ -80,7 +80,7 @@
</graphic>
</Button>
<Pane prefWidth="10.0" />
<Button fx:id="openBtn" minHeight="36.0" mnemonicParsing="false">
<Button fx:id="openBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<graphic>
<SVGPath content="M19,20H4C2.89,20 2,19.1 2,18V6C2,4.89 2.89,4 4,4H10L12,6H19A2,2 0 0,1 21,8H21L4,8V18L6.14,10H23.21L20.93,18.5C20.7,19.37 19.92,20 19,20Z" />
</graphic>
@ -88,7 +88,7 @@
<Tooltip text="%btn_open" />
</tooltip>
</Button>
<Button fx:id="saveBtn" minHeight="36.0" mnemonicParsing="false">
<Button fx:id="saveBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<graphic>
<SVGPath content="M17 3H5C3.89 3 3 3.9 3 5V19C3 20.1 3.89 21 5 21H19C20.1 21 21 20.1 21 19V7L17 3M19 19H5V5H16.17L19 7.83V19M12 12C10.34 12 9 13.34 9 15S10.34 18 12 18 15 16.66 15 15 13.66 12 12 12M6 6H15V10H6V6Z" />
</graphic>
@ -96,7 +96,7 @@
<Tooltip text="%btn_save" />
</tooltip>
</Button>
<Button fx:id="saveAsBtn" minHeight="36.0" mnemonicParsing="false">
<Button fx:id="saveAsBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<graphic>
<SVGPath content="M7 22H9V24H7V22M11 22H13V24H11V22M15 22H17V24H15V22M17 2H5C3.89 2 3 2.9 3 4V18C3 19.1 3.89 20 5 20H19C20.1 20 21 19.1 21 18V6L17 2M19 18H5V4H16.17L19 6.83V18M12 11C10.34 11 9 12.34 9 14S10.34 17 12 17 15 15.66 15 14 13.66 11 12 11M6 5H15V9H6V5Z" />
</graphic>
@ -105,9 +105,18 @@
</tooltip>
</Button>
<Pane prefWidth="10.0" />
<Button fx:id="aboutBtn" minHeight="36.0" mnemonicParsing="false">
<Button fx:id="settingsBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<graphic>
<SVGPath content="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z" />
<SVGPath content="M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z" />
</graphic>
<tooltip>
<Tooltip text="%btn_settings" />
</tooltip>
</Button>
<Pane prefWidth="10.0" />
<Button fx:id="aboutBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="36.0" prefWidth="42.0">
<graphic>
<SVGPath content="M13.5,4A1.5,1.5 0 0,0 12,5.5A1.5,1.5 0 0,0 13.5,7A1.5,1.5 0 0,0 15,5.5A1.5,1.5 0 0,0 13.5,4M13.14,8.77C11.95,8.87 8.7,11.46 8.7,11.46C8.5,11.61 8.56,11.6 8.72,11.88C8.88,12.15 8.86,12.17 9.05,12.04C9.25,11.91 9.58,11.7 10.13,11.36C12.25,10 10.47,13.14 9.56,18.43C9.2,21.05 11.56,19.7 12.17,19.3C12.77,18.91 14.38,17.8 14.54,17.69C14.76,17.54 14.6,17.42 14.43,17.17C14.31,17 14.19,17.12 14.19,17.12C13.54,17.55 12.35,18.45 12.19,17.88C12,17.31 13.22,13.4 13.89,10.71C14,10.07 14.3,8.67 13.14,8.77Z" />
</graphic>
<tooltip>
<Tooltip text="%menu_item_about" />

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<BorderPane prefHeight="200.0" prefWidth="200.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="logiled.Settings.SettingsController">
<bottom>
<ButtonBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<buttons>
<Button fx:id="cancelBtn" cancelButton="true" mnemonicParsing="false" text="%setting_cancel" />
<Button fx:id="okBtn" defaultButton="true" mnemonicParsing="false" text="%setting_save_and_close" />
</buttons>
</ButtonBar>
</bottom>
<center>
<VBox BorderPane.alignment="CENTER">
<children>
<CheckBox fx:id="trayCB" mnemonicParsing="false" text="%setting_tray_support" />
</children>
</VBox>
</center>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</BorderPane>

View file

@ -1,6 +1,3 @@
menu_File=File
menu_Help=Help
menu_Edit=Edit
btn_apply=Apply
btn_addRule=Add rule
btn_removeRule=Remove rule
@ -703,3 +700,8 @@ error_any_title=Ouch! Something bad happened.
btn_open=Open configuration
info_file_saved=File saved
info_file_not_saved=File not saved
btn_settings=Settings
setting_tray_support=Minimize to tray
setting_save_and_close=Save and close
setting_cancel=Cancel
open=Open

View file

@ -1,6 +1,3 @@
menu_File=Файл
menu_Edit=Правка
menu_Help=Справка
btn_apply=Применить
btn_addRule=Добавить правило
btn_removeRule=Удалить правило
@ -29,3 +26,8 @@ error_any_body=Это определённо похоже на ошибку. Н
btn_open=Открыть файл конфигурации
info_file_saved=Файл сохранён
info_file_not_saved=Файл не сохранён
btn_settings=Настройки
setting_tray_support=Сворачивать приложение в трей
setting_cancel=Отменить
setting_save_and_close=Сохранить и закрыть
open=Открыть