работающий gui
This commit is contained in:
@@ -19,13 +19,15 @@ public class Main extends Application {
|
|||||||
primaryStage.setTitle("1С корректор (v1.0)");
|
primaryStage.setTitle("1С корректор (v1.0)");
|
||||||
primaryStage.setResizable(false);
|
primaryStage.setResizable(false);
|
||||||
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("excel.png")));
|
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("excel.png")));
|
||||||
primaryStage.setScene(loadScene());
|
primaryStage.setScene(loadScene(primaryStage));
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Scene loadScene() throws IOException {
|
private Scene loadScene(Stage stage) throws IOException {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("single_layout.fxml"));
|
||||||
loader.setLocation(getClass().getResource("single_layout.fxml"));
|
Scene scene = new Scene(loader.load(), 350-10, 174-10);
|
||||||
return new Scene(loader.load(), 350-10, 174-10);
|
MainController controller = loader.getController();
|
||||||
|
controller.setStage(stage);
|
||||||
|
return scene;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
106
src/main/java/ru/dmitriymx/corrector1s/gui/MainController.java
Normal file
106
src/main/java/ru/dmitriymx/corrector1s/gui/MainController.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package ru.dmitriymx.corrector1s.gui;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.ProgressIndicator;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.FileChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Timer;
|
||||||
|
|
||||||
|
public class MainController {
|
||||||
|
private Stage stage;
|
||||||
|
@FXML
|
||||||
|
private TextField sourceFilePath;
|
||||||
|
@FXML
|
||||||
|
private TextField saveAsFilePath;
|
||||||
|
@FXML
|
||||||
|
private CheckBox saveAsCheckBox;
|
||||||
|
@FXML
|
||||||
|
private Button btnSourceFilePath;
|
||||||
|
@FXML
|
||||||
|
private Button btnSaveAsFilePath;
|
||||||
|
@FXML
|
||||||
|
private Pane mainPane;
|
||||||
|
@FXML
|
||||||
|
private Pane waitPane;
|
||||||
|
@FXML
|
||||||
|
private ProgressIndicator progressBar;
|
||||||
|
@FXML
|
||||||
|
private Button btnStartCorrect;
|
||||||
|
|
||||||
|
private FileChooser buildFileChooser(TextField textField) {
|
||||||
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
|
||||||
|
if (!textField.getText().isEmpty() && Files.exists(Paths.get(textField.getText()))) {
|
||||||
|
File file = new File(textField.getText());
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
fileChooser.setInitialDirectory(file);
|
||||||
|
} else {
|
||||||
|
fileChooser.setInitialDirectory(file.getParentFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(
|
||||||
|
"Таблицы Excel (*.xls, *.xlsx)",
|
||||||
|
"*.xls", "*.xlsx"));
|
||||||
|
|
||||||
|
return fileChooser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
saveAsCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
saveAsFilePath.setDisable(!newValue);
|
||||||
|
btnSaveAsFilePath.setDisable(!newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
btnSourceFilePath.addEventHandler(ActionEvent.ACTION, event -> {
|
||||||
|
File file = buildFileChooser(sourceFilePath).showOpenDialog(stage);
|
||||||
|
if (file != null) {
|
||||||
|
sourceFilePath.setText(file.getAbsolutePath());
|
||||||
|
if (!saveAsCheckBox.selectedProperty().get()) {
|
||||||
|
saveAsFilePath.setText(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnSaveAsFilePath.addEventHandler(ActionEvent.ACTION,
|
||||||
|
event -> buildFileChooser(saveAsFilePath).showSaveDialog(stage));
|
||||||
|
|
||||||
|
btnStartCorrect.addEventHandler(ActionEvent.ACTION, event -> {
|
||||||
|
mainPane.setDisable(true);
|
||||||
|
mainPane.setOpacity(0.3d);
|
||||||
|
waitPane.setVisible(true);
|
||||||
|
progressBar.setProgress(0d);
|
||||||
|
|
||||||
|
Runnable runnable = () -> {
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
progressBar.setProgress(progressBar.getProgress() + 0.1d);
|
||||||
|
} while (progressBar.getProgress() <= 1.0d);
|
||||||
|
|
||||||
|
waitPane.setVisible(false);
|
||||||
|
mainPane.setOpacity(1.0d);
|
||||||
|
mainPane.setDisable(false);
|
||||||
|
};
|
||||||
|
Thread thread = new Thread(runnable);
|
||||||
|
thread.start();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStage(Stage stage) {
|
||||||
|
this.stage = stage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,31 +4,34 @@
|
|||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.CheckBox?>
|
<?import javafx.scene.control.CheckBox?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ProgressIndicator?>
|
||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
<?import javafx.scene.image.Image?>
|
<?import javafx.scene.image.Image?>
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
|
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="174.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ru.dmitriymx.corrector1s.gui.MainController">
|
||||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="174.0"
|
<Pane fx:id="mainPane" prefHeight="174.0" prefWidth="350.0">
|
||||||
prefWidth="350.0" xmlns="http://javafx.com/javafx/8.0.111">
|
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<ImageView fitHeight="103.0" fitWidth="108.0" pickOnBounds="true" preserveRatio="true" x="10.0" y="10.0">
|
<ImageView fitHeight="103.0" fitWidth="108.0" pickOnBounds="true" preserveRatio="true" x="10.0" y="10.0">
|
||||||
<Image url="@excel.png"/>
|
<Image url="@excel.png" />
|
||||||
</ImageView>
|
</ImageView>
|
||||||
<Label layoutX="132.0" layoutY="10.0" text="Исходный файл"/>
|
<Label layoutX="132.0" layoutY="10.0" text="Исходный файл" />
|
||||||
<TextField layoutX="132.0" layoutY="32.0" prefHeight="25.0" prefWidth="178.0"/>
|
<TextField fx:id="sourceFilePath" layoutX="132.0" layoutY="32.0" prefHeight="25.0" prefWidth="178.0" />
|
||||||
<Button layoutX="313.0" layoutY="32.0" mnemonicParsing="false" text="..."/>
|
<Button fx:id="btnSourceFilePath" layoutX="313.0" layoutY="32.0" mnemonicParsing="false" text="..." />
|
||||||
<CheckBox layoutX="133.0" layoutY="67.0" mnemonicParsing="false" text="Сохранить как..."/>
|
<CheckBox fx:id="saveAsCheckBox" layoutX="133.0" layoutY="67.0" mnemonicParsing="false" text="Сохранить как..." />
|
||||||
<TextField disable="true" layoutX="132.0" layoutY="89.0" prefHeight="25.0" prefWidth="178.0"/>
|
<TextField fx:id="saveAsFilePath" disable="true" layoutX="132.0" layoutY="89.0" prefHeight="25.0" prefWidth="178.0" />
|
||||||
<Button disable="true" layoutX="313.0" layoutY="89.0" mnemonicParsing="false" text="..."/>
|
<Button fx:id="btnSaveAsFilePath" disable="true" layoutX="313.0" layoutY="89.0" mnemonicParsing="false" text="..." />
|
||||||
<Button layoutX="14.0" layoutY="134.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="324.0"
|
<Button fx:id="btnStartCorrect" layoutX="14.0" layoutY="134.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="324.0" text="Преобразовать">
|
||||||
text="Преобразовать">
|
|
||||||
<font>
|
<font>
|
||||||
<Font name="System Bold" size="12.0"/>
|
<Font name="System Bold" size="12.0" />
|
||||||
</font>
|
</font>
|
||||||
</Button>
|
</Button>
|
||||||
|
</Pane>
|
||||||
|
<Pane fx:id="waitPane" prefHeight="174.0" prefWidth="350.0" visible="false">
|
||||||
|
<ProgressIndicator fx:id="progressBar" layoutX="157.0" layoutY="62.0" prefHeight="50.0" prefWidth="36.0" progress="1.0" />
|
||||||
|
</Pane>
|
||||||
</Pane>
|
</Pane>
|
||||||
|
|||||||
Reference in New Issue
Block a user