Commit 1a6aa043 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#784 FXML defined layout to code generated layout.

parent d50a5f2a
<?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 {
......@@ -74,11 +79,7 @@ public class DesktopLauncher extends Application {
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);
}else {
launch(DesktopLauncher.class, arg);
}
launch(DesktopLauncher.class, arg);
}
public static Tablexia initTablexia(){
......@@ -143,31 +144,11 @@ 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);
Scene scene = new Scene(getLauncherLayoutPane(primaryStage), 300, 200);
primaryStage.setTitle("Tablexia");
primaryStage.setScene(scene);
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
}
});
primaryStage.setResizable(false);
primaryStage.getIcons().add(new Image("file:icon" + File.separator + "desktop_icon_32.png"));
primaryStage.show();
}
......@@ -251,4 +232,97 @@ 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){
// TODO: 12/1/17 launcher icon
// TODO: 12/1/17 change text on locale
// TODO: 12/1/17 consts
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("Resolution");
resolutionLabel.setPadding(new Insets(0, 50, 0, 0));
ChoiceBox resolutionChoiceBox = new ChoiceBox();
resolutionChoiceBox.setPrefWidth(150);
resolutionChoiceBox.getItems().addAll(WindowsResolution.getFittingResolutions());
resolutionChoiceBox.getSelectionModel().select(0);
resolutionChoiceBox.setId(RESOLUTION_CHOICE_ID);
Label fullscreenLabel = new Label("Fullscreen");
fullscreenLabel.setPadding(new Insets(0, 50, 0, 0));
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("Run");
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());
// TODO: 25.4.17 save previous settings
}
});
buttonBorderPane.setCenter(launchButton);
buttonBorderPane.setMargin(launchButton, new Insets(10));
return buttonBorderPane;
}
}
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