Commit 5fa0d53a authored by Drahomír Karchňák's avatar Drahomír Karchňák

Merge branch '784-prepsat-fxml-layout-soubor-do-kodu' into 'V3.5.1'

#784 Resolve "Prepsat fxml layout soubor do kodu."

See merge request !599
parents b3610986 7957398f
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<!--
~ Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.cz/)
~
~ This program 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.
~
~ This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<Pane prefHeight="200.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="300.0">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" BorderPane.alignment="CENTER">
<image>
<Image url="@tablexia.png" />
</image>
</ImageView>
</center>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</BorderPane>
<FlowPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label prefHeight="53.0" prefWidth="119.0" text="Resolution">
<padding>
<Insets right="50.0" />
</padding>
</Label>
<ChoiceBox fx:id="resolutionChoiceBox" prefWidth="150.0" />
<Label prefHeight="15.0" prefWidth="119.0" text="Fullscreen">
<padding>
<Insets right="30.0" />
</padding>
</Label>
<CheckBox fx:id="fullscreenCheckBox" mnemonicParsing="false" />
</children>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</FlowPane>
<Button fx:id="launchButton" mnemonicParsing="false" prefHeight="45.0" prefWidth="50.0" text="Run">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
</Button>
</children>
</VBox>
</children>
</Pane>
......@@ -25,10 +25,7 @@ import com.jcabi.manifests.Manifests;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Locale;
import cz.nic.tablexia.Tablexia;
......@@ -40,13 +37,21 @@ import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DesktopLauncher extends Application {
......@@ -70,12 +75,14 @@ public class DesktopLauncher extends Application {
private static final String DESKTOP_ICON_ITEST_32 = DESKTOP_ICON_PATH + "desktop_icon_itest_32.png";
private static final String DESKTOP_ICON_ITEST_128 = DESKTOP_ICON_PATH + "desktop_icon_itest_128.png";
private static final int MULTI_SAMPLING_2X = 2;
private static final String TABLEXIA_LAUNCHER_TITLE = "Tablexia Launcher";
private static final Tablexia.SQLConnectionType SQL_CONNECTION_TYPE = new Tablexia.SQLConnectionType("org.sqlite.JDBC", "jdbc:sqlite:");
public static void main(String[] arg) {
if (arg.length > 0 && arg[0] != null && arg[0].equals("nolaunch")){
initTablexia(WindowsResolution.WXGA, false);
initTablexia();
}else {
launch(DesktopLauncher.class, arg);
}
......@@ -143,31 +150,14 @@ public class DesktopLauncher extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("launcher/launcher_layout.fxml"));
Scene scene = new Scene(root, 300, 200);
primaryStage.setTitle("Tablexia");
Scene scene = new Scene(getLauncherLayoutPane(primaryStage), 300, 200);
primaryStage.setTitle(TABLEXIA_LAUNCHER_TITLE);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
ChoiceBox resolutionChoiceBox = (ChoiceBox) scene.lookup("#resolutionChoiceBox");
resolutionChoiceBox.getItems().addAll(WindowsResolution.getFittingResolutions());
resolutionChoiceBox.getSelectionModel().select(0);
CheckBox fullscreenCheckBox = (CheckBox) scene.lookup("#fullscreenCheckBox");
Button launchButton = (Button) scene.lookup("#launchButton");
launchButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
primaryStage.hide();
initTablexia(WindowsResolution.values()[resolutionChoiceBox.getSelectionModel().getSelectedIndex()], fullscreenCheckBox.isSelected());
// TODO: 25.4.17 save previous settings
}
});
String buildType = loadAttributeFromManifest(BUILD_VARIANT_MANIFEST_ATTRIBUTE, TablexiaSettings.BuildType.DEVEL.getKey());
primaryStage.getIcons().add(new Image("file:icon" + File.separator + "desktop_icon_" + buildType + "_32.png"));
primaryStage.show();
}
......@@ -251,4 +241,117 @@ public class DesktopLauncher extends Application {
return observableList;
}
}
private static final String LOGO_PATH = "file:" + "launcher" + File.separator + "tablexia.png";
private static final String RESOLUTION_CHOICE_ID = "resolutionChoiceBox";
private static final String FULLSCREEN_CHECKBOX_ID = "fullscreenCheckBox";
private Parent getLauncherLayoutPane(Stage primaryStage){
Pane pane = new Pane();
VBox mainVBox = new VBox();
pane.getChildren().add(mainVBox);
mainVBox.setPrefWidth(300);
mainVBox.setPrefHeight(200);
mainVBox.getChildren().addAll(createLogoBorderPane(), createSettingsFlowPane(), createLaunchButtonBorderPane(primaryStage, pane));
return pane;
}
private BorderPane createLogoBorderPane(){
BorderPane borderPane = new BorderPane();
borderPane.setPrefWidth(200);
borderPane.setPrefHeight(200);
ImageView logoView = new ImageView(new Image(LOGO_PATH));
logoView.setFitHeight(150);
logoView.setFitWidth(200);
logoView.setPickOnBounds(true);
logoView.setPreserveRatio(true);
borderPane.setCenter(logoView);
borderPane.setMargin(logoView, new Insets(5));
return borderPane;
}
private FlowPane createSettingsFlowPane(){
FlowPane flowPane = new FlowPane();
flowPane.setPrefWidth(200);
flowPane.setPrefHeight(200);
VBox verticalBox = new VBox();
HBox resolutionHBox = new HBox();
HBox fullscreenHBox = new HBox();
verticalBox.setSpacing(20);
Label resolutionLabel = new Label(LauncherLocalizedTextDefinition.getLocalizedText(LauncherLocalizedTextDefinition.RESOLUTION));
resolutionLabel.setPrefWidth(150);
ChoiceBox resolutionChoiceBox = new ChoiceBox();
resolutionChoiceBox.getItems().addAll(WindowsResolution.getFittingResolutions());
resolutionChoiceBox.getSelectionModel().select(0);
resolutionChoiceBox.setId(RESOLUTION_CHOICE_ID);
Label fullscreenLabel = new Label(LauncherLocalizedTextDefinition.getLocalizedText(LauncherLocalizedTextDefinition.FULLSCREEN));
fullscreenLabel.setPrefWidth(150);
CheckBox fullscreenCheckBox = new CheckBox();
fullscreenCheckBox.setMnemonicParsing(false);
fullscreenCheckBox.setId(FULLSCREEN_CHECKBOX_ID);
resolutionHBox.getChildren().addAll(resolutionLabel, resolutionChoiceBox);
fullscreenHBox.getChildren().addAll(fullscreenLabel, fullscreenCheckBox);
verticalBox.getChildren().addAll(resolutionHBox, fullscreenHBox);
flowPane.getChildren().add(verticalBox);
flowPane.setPadding(new Insets(10));
return flowPane;
}
private BorderPane createLaunchButtonBorderPane(Stage primaryStage, Parent pane){
BorderPane buttonBorderPane = new BorderPane();
Button launchButton = new Button(LauncherLocalizedTextDefinition.getLocalizedText(LauncherLocalizedTextDefinition.LAUNCH));
launchButton.setMnemonicParsing(false);
launchButton.prefWidth(50);
launchButton.prefHeight(45);
launchButton.setPadding(new Insets(10));
launchButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
primaryStage.hide();
ChoiceBox resolutionChoiceBox = (ChoiceBox) pane.lookup("#" + RESOLUTION_CHOICE_ID);
CheckBox fullscreenCheckBox = (CheckBox) pane.lookup("#" + FULLSCREEN_CHECKBOX_ID);
initTablexia(WindowsResolution.values()[resolutionChoiceBox.getSelectionModel().getSelectedIndex()], fullscreenCheckBox.isSelected());
}
});
buttonBorderPane.setCenter(launchButton);
buttonBorderPane.setMargin(launchButton, new Insets(10));
return buttonBorderPane;
}
enum LauncherLocalizedTextDefinition {
FULLSCREEN("Celá obrazovka", "Vollbild", "Celá obrazovka"),
RESOLUTION("Rozlišení", "Auflösung", "Rozlíšenie"),
LAUNCH("Spustit", "Starten", "Začať");
private String cs, de, sk;
LauncherLocalizedTextDefinition(String cs, String de, String sk) {
this.cs = cs;
this.de = de;
this.sk = sk;
}
public static String getLocalizedText(LauncherLocalizedTextDefinition localizedTextDefinition) {
switch (Locale.getDefault().getLanguage()) {
case "sk":
return localizedTextDefinition.sk;
case "de":
return localizedTextDefinition.de;
default:
return localizedTextDefinition.cs;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment