diff --git a/src/de/deadlocker8/budgetmaster/logic/chartGenerators/CategoriesChartGenerator.java b/src/de/deadlocker8/budgetmaster/logic/chartGenerators/CategoriesChartGenerator.java index 3949d23ecec76dccf24e5ec2804e1a1bf4314a2e..b1879b2005d0ebfe6308e51df53278b6e5fa0738 100644 --- a/src/de/deadlocker8/budgetmaster/logic/chartGenerators/CategoriesChartGenerator.java +++ b/src/de/deadlocker8/budgetmaster/logic/chartGenerators/CategoriesChartGenerator.java @@ -10,6 +10,7 @@ import javafx.scene.control.Label; import javafx.scene.control.Tooltip; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import tools.ConvertTo; @@ -125,6 +126,77 @@ public class CategoriesChartGenerator return legend; } + + public VBox generateFullLegend() + { + VBox legend = new VBox(); + legend.setPadding(new Insets(10)); + legend.setSpacing(10); + legend.setStyle("-fx-background-color: #EEEEEE; -fx-border-color: #212121; -fx-border-width: 1; -fx-border-radius: 5;"); + + if(categoryInOutSums.size() == 0) + { + return legend; + } + + double totalIn = getTotal(categoryInOutSums, true); + double totalOut = getTotal(categoryInOutSums, false); + + HBox hboxLegend = new HBox(); + hboxLegend.setSpacing(10); + + VBox vboxCircles = new VBox(); + vboxCircles.setSpacing(10); + VBox vboxNames = new VBox(); + vboxNames.setSpacing(10); + VBox vboxIn = new VBox(); + vboxIn.setSpacing(10); + VBox vboxOut = new VBox(); + vboxOut.setSpacing(10); + + for(CategoryInOutSum currentItem : categoryInOutSums) + { + String name = currentItem.getName(); + if(name.equals("NONE")) + { + name = "Keine Kategorie"; + } + + Label labelCircle = new Label(); + labelCircle.setMinWidth(20); + labelCircle.setMinHeight(20); + labelCircle.setStyle("-fx-background-color: " + ConvertTo.toRGBHexWithoutOpacity(currentItem.getColor()) + "; -fx-background-radius: 50%; -fx-border-width: 1; -fx-border-color: black - fx-border-radius: 50%"); + vboxCircles.getChildren().add(labelCircle); + + Label labelName = new Label(name); + labelName.setStyle("-fx-font-weight: bold;"); + labelName.setMinHeight(20); + vboxNames.getChildren().add(labelName); + + String percentageIn = Helpers.NUMBER_FORMAT.format((currentItem.getBudgetIN() / totalIn)); + Label labelInSum = new Label("+" + Helpers.getCurrencyString(currentItem.getBudgetIN(), currency) + " (" + percentageIn + "%)"); + labelInSum.setStyle("-fx-font-weight: bold;"); + labelInSum.setMinHeight(20); + vboxIn.getChildren().add(labelInSum); + + String percentageOut = Helpers.NUMBER_FORMAT.format((currentItem.getBudgetOUT() / totalOut)); + Label labelOutSum = new Label(Helpers.getCurrencyString(currentItem.getBudgetOUT(), currency) + " (" + percentageOut + "%)"); + labelOutSum.setStyle("-fx-font-weight: bold;"); + labelOutSum.setMinHeight(20); + vboxOut.getChildren().add(labelOutSum); + } + + hboxLegend.getChildren().add(vboxCircles); + hboxLegend.getChildren().add(vboxNames); + HBox.setHgrow(vboxNames, Priority.ALWAYS); + hboxLegend.getChildren().add(vboxIn); + HBox.setHgrow(vboxIn, Priority.ALWAYS); + hboxLegend.getChildren().add(vboxOut); + HBox.setHgrow(vboxOut, Priority.ALWAYS); + legend.getChildren().add(hboxLegend); + + return legend; + } private HBox getLegendItem(String name, Color color) { diff --git a/src/de/deadlocker8/budgetmaster/ui/ChartController.java b/src/de/deadlocker8/budgetmaster/ui/ChartController.java index 0a7b9546166a78b32d58e7a178c3108733318881..6cb72445fdab551db675f9aaf36970c3ea4cdd6b 100644 --- a/src/de/deadlocker8/budgetmaster/ui/ChartController.java +++ b/src/de/deadlocker8/budgetmaster/ui/ChartController.java @@ -1,5 +1,7 @@ package de.deadlocker8.budgetmaster.ui; +import java.io.File; +import java.io.IOException; import java.time.LocalDate; import java.util.ArrayList; @@ -19,7 +21,10 @@ import fontAwesome.FontIconType; import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.chart.LineChart; import javafx.scene.control.Accordion; import javafx.scene.control.Alert.AlertType; @@ -37,6 +42,7 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.Region; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; +import javafx.stage.Modality; import javafx.stage.Stage; import javafx.util.Callback; import logger.Logger; @@ -52,6 +58,7 @@ public class ChartController implements Refreshable @FXML private DatePicker datePickerEnd; @FXML private VBox vboxChartMonth; @FXML private Button buttonChartCategoriesShow; + @FXML private Button buttonChartCategoriesExport; @FXML private ComboBox<String> comboBoxStartMonth; @FXML private ComboBox<String> comboBoxStartYear; @FXML private ComboBox<String> comboBoxEndMonth; @@ -59,8 +66,11 @@ public class ChartController implements Refreshable @FXML private Button buttonChartMonthShow; @FXML private RadioButton radioButtonBars; @FXML private RadioButton radioButtonLines; + @FXML private HBox hboxChartMonthButtons; private Controller controller; + private Button buttonChartMonthExport; + private File lastExportPath; public void init(Controller controller) { @@ -76,11 +86,28 @@ public class ChartController implements Refreshable buttonChartCategoriesShow.setStyle("-fx-background-color: #2E79B9;"); buttonChartCategoriesShow.setGraphic(iconShow); - FontIcon iconShow2 = new FontIcon(FontIconType.CHECK); + FontIcon iconShow2 = new FontIcon(FontIconType.SAVE); iconShow2.setSize(16); iconShow2.setColor(Color.WHITE); + buttonChartCategoriesExport.setStyle("-fx-background-color: #2E79B9;"); + buttonChartCategoriesExport.setGraphic(iconShow2); + + FontIcon iconShow3 = new FontIcon(FontIconType.CHECK); + iconShow3.setSize(16); + iconShow3.setColor(Color.WHITE); buttonChartMonthShow.setStyle("-fx-background-color: #2E79B9;"); - buttonChartMonthShow.setGraphic(iconShow2); + buttonChartMonthShow.setGraphic(iconShow3); + + buttonChartMonthExport = new Button(); + buttonChartMonthExport.setOnAction((event)->{ + export(vboxChartMonth); + }); + + FontIcon iconShow4 = new FontIcon(FontIconType.SAVE); + iconShow4.setSize(16); + iconShow4.setColor(Color.WHITE); + buttonChartMonthExport.setStyle("-fx-background-color: #2E79B9;"); + buttonChartMonthExport.setGraphic(iconShow4); datePickerEnd.setDayCellFactory(new Callback<DatePicker, DateCell>() { @@ -106,18 +133,23 @@ public class ChartController implements Refreshable comboBoxStartMonth.setItems(FXCollections.observableArrayList(Helpers.getMonthList())); comboBoxStartYear.setItems(FXCollections.observableArrayList(Helpers.getYearList())); comboBoxEndMonth.setItems(FXCollections.observableArrayList(Helpers.getMonthList())); - comboBoxEndYear.setItems(FXCollections.observableArrayList(Helpers.getYearList())); + comboBoxEndYear.setItems(FXCollections.observableArrayList(Helpers.getYearList())); final ToggleGroup toggleGroup = new ToggleGroup(); radioButtonBars.setToggleGroup(toggleGroup); radioButtonBars.setSelected(true); - radioButtonLines.setToggleGroup(toggleGroup); - + radioButtonLines.setToggleGroup(toggleGroup); + accordion.setExpandedPane(accordion.getPanes().get(0)); vboxChartMonth.setSpacing(15); } + + public void buttonChartCategoriesShow() + { + chartCategoriesShow(false); + } - public void chartCategoriesShow() + public void chartCategoriesShow(boolean fullLegend) { DateTime startDate = DateTime.parse(datePickerStart.getValue().toString()); DateTime endDate = DateTime.parse(datePickerEnd.getValue().toString()); @@ -127,84 +159,139 @@ public class ChartController implements Refreshable ServerConnection connection = new ServerConnection(controller.getSettings()); ArrayList<CategoryInOutSum> sums = connection.getCategoryInOutSumForMonth(startDate, endDate); - Platform.runLater(()->{ + Platform.runLater(() -> { vboxChartCategories.getChildren().clear(); - - CategoriesChartGenerator generator = new CategoriesChartGenerator("Einnahmen nach Kategorien", sums, true, controller.getSettings().getCurrency()); + + CategoriesChartGenerator generator = new CategoriesChartGenerator("Einnahmen nach Kategorien", sums, true, controller.getSettings().getCurrency()); vboxChartCategories.getChildren().add(generator.generate()); generator = new CategoriesChartGenerator("Ausgaben nach Kategorien", sums, false, controller.getSettings().getCurrency()); vboxChartCategories.getChildren().add(generator.generate()); - + Region spacer = new Region(); vboxChartCategories.getChildren().add(spacer); VBox.setVgrow(spacer, Priority.ALWAYS); - - vboxChartCategories.getChildren().add(generator.generateLegend()); + + if(fullLegend) + { + vboxChartCategories.getChildren().add(generator.generateFullLegend()); + } + else + { + vboxChartCategories.getChildren().add(generator.generateLegend()); + } }); } catch(Exception e) { Logger.error(e); - Platform.runLater(()->{ + Platform.runLater(() -> { controller.showConnectionErrorAlert(ExceptionHandler.getMessageForException(e)); }); } } + + public void chartCategoriesExport() + { + export(vboxChartCategories); + } + + public void export(VBox chart) + { + Worker.runLater(()->{ + chartCategoriesShow(true); + Platform.runLater(()->{ + try + { + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/de/deadlocker8/budgetmaster/ui/ExportChartGUI.fxml")); + Parent root = (Parent)fxmlLoader.load(); + Stage newStage = new Stage(); + newStage.initOwner(controller.getStage()); + newStage.initModality(Modality.APPLICATION_MODAL); + newStage.setTitle("Diagramm exportieren"); + newStage.setScene(new Scene(root)); + newStage.getIcons().add(controller.getIcon()); + newStage.setResizable(false); + ExportChartController newController = fxmlLoader.getController(); + newController.init(newStage, this, chart); + newStage.show(); + } + catch(IOException e) + { + Logger.error(e); + } + }); + }); + } public void chartMonthShow() { - Platform.runLater(()->{ + if(radioButtonLines.isSelected()) + { + if(!hboxChartMonthButtons.getChildren().contains(buttonChartMonthExport)) + { + hboxChartMonthButtons.getChildren().add(buttonChartMonthExport); + } + } + else + { + if(hboxChartMonthButtons.getChildren().contains(buttonChartMonthExport)) + { + hboxChartMonthButtons.getChildren().remove(buttonChartMonthExport); + } + } + + Platform.runLater(() -> { vboxChartMonth.getChildren().clear(); }); - + String startMonth = comboBoxStartMonth.getValue(); String startYear = comboBoxStartYear.getValue(); String endMonth = comboBoxEndMonth.getValue(); - String endYear = comboBoxEndYear.getValue(); - - String startDateString = "01-" + startMonth + "-" + startYear; + String endYear = comboBoxEndYear.getValue(); + + String startDateString = "01-" + startMonth + "-" + startYear; DateTime startDate = DateTime.parse(startDateString, DateTimeFormat.forPattern("dd-MMMM-YYYY")); - - String endDateString = "01-" + endMonth + "-" + endYear; - DateTime endDate = DateTime.parse(endDateString, DateTimeFormat.forPattern("dd-MMMM-YYYY")); - + + String endDateString = "01-" + endMonth + "-" + endYear; + DateTime endDate = DateTime.parse(endDateString, DateTimeFormat.forPattern("dd-MMMM-YYYY")); + if(endDate.isBefore(startDate)) - { - Platform.runLater(()->{ + { + Platform.runLater(() -> { AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Das Enddatum darf nicht vor dem Startdatum liegen.", controller.getIcon(), controller.getStage(), null, false); }); return; - } - + } + try - { + { ServerConnection connection = new ServerConnection(controller.getSettings()); ArrayList<MonthInOutSum> sums = connection.getMonthInOutSum(startDate, endDate); - - Platform.runLater(()->{ + + Platform.runLater(() -> { vboxChartMonth.getChildren().clear(); - + if(radioButtonBars.isSelected()) { - ScrollPane scrollPane = new ScrollPane(); + ScrollPane scrollPane = new ScrollPane(); scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER); scrollPane.setFocusTraversable(false); scrollPane.setStyle("-fx-background-color: transparent; -fx-background-insets: 0; -fx-border-color: transparent; -fx-border-width: 0; -fx-border-insets: 0;"); scrollPane.setPadding(new Insets(0, 0, 10, 0)); - + MonthChartGenerator generator = new MonthChartGenerator(sums, controller.getSettings().getCurrency()); HBox generatedChart = generator.generate(); - scrollPane.setContent(generatedChart); + scrollPane.setContent(generatedChart); generatedChart.prefHeightProperty().bind(scrollPane.heightProperty().subtract(30)); vboxChartMonth.getChildren().add(scrollPane); VBox.setVgrow(scrollPane, Priority.ALWAYS); vboxChartMonth.getChildren().add(generator.generateLegend()); } else - { + { LineChartGenerator generator = new LineChartGenerator(sums, controller.getSettings().getCurrency()); LineChart<String, Number> chartMonth = generator.generate(); - vboxChartMonth.getChildren().add(chartMonth); + vboxChartMonth.getChildren().add(chartMonth); VBox.setVgrow(chartMonth, Priority.ALWAYS); } }); @@ -212,40 +299,55 @@ public class ChartController implements Refreshable catch(Exception e) { Logger.error(e); - Platform.runLater(()->{ + Platform.runLater(() -> { controller.showConnectionErrorAlert(ExceptionHandler.getMessageForException(e)); }); } } + + public Controller getControlle() + { + return controller; + } + + public void setLastExportPath(File lastExportPath) + { + this.lastExportPath = lastExportPath; + } + + public File getLastExportPath() + { + return lastExportPath; + } @Override public void refresh() - { + { Stage modalStage = Helpers.showModal("Vorgang läuft", "Lade Diagramme...", controller.getStage(), controller.getIcon()); - + // prepare chart categories LocalDate startDate = LocalDate.parse(controller.getCurrentDate().withDayOfMonth(1).toString("yyyy-MM-dd")); LocalDate endDate = LocalDate.parse(controller.getCurrentDate().dayOfMonth().withMaximumValue().toString("yyy-MM-dd")); - + datePickerStart.setValue(startDate); - datePickerEnd.setValue(endDate); - + datePickerEnd.setValue(endDate); + // chart month comboBoxStartMonth.setValue(controller.getCurrentDate().minusMonths(5).toString("MMMM")); comboBoxStartYear.setValue(String.valueOf(controller.getCurrentDate().minusMonths(5).getYear())); - + comboBoxEndMonth.setValue(controller.getCurrentDate().plusMonths(6).toString("MMMM")); comboBoxEndYear.setValue(String.valueOf(controller.getCurrentDate().plusMonths(6).getYear())); - Worker.runLater(() -> { - chartCategoriesShow(); - chartMonthShow(); + Worker.runLater(() -> { + chartCategoriesShow(false); + chartMonthShow(); Platform.runLater(() -> { if(modalStage != null) { modalStage.close(); - } + } }); }); } diff --git a/src/de/deadlocker8/budgetmaster/ui/ChartTab.fxml b/src/de/deadlocker8/budgetmaster/ui/ChartTab.fxml index 7ffa60128c56a3f29617e506560b0eef6f6963ad..fbe8fad75a86df369f04c247ba95447fe4d39ab1 100644 --- a/src/de/deadlocker8/budgetmaster/ui/ChartTab.fxml +++ b/src/de/deadlocker8/budgetmaster/ui/ChartTab.fxml @@ -13,7 +13,7 @@ <?import javafx.scene.layout.VBox?> <?import javafx.scene.text.Font?> -<AnchorPane fx:id="anchorPaneMain" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.budgetmaster.ui.ChartController"> +<AnchorPane fx:id="anchorPaneMain" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.budgetmaster.ui.ChartController"> <children> <Accordion fx:id="accordion" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="25.0"> <panes> @@ -44,7 +44,7 @@ </font> </Label> <DatePicker fx:id="datePickerEnd" /> - <Button fx:id="buttonChartCategoriesShow" mnemonicParsing="false" onAction="#chartCategoriesShow"> + <Button fx:id="buttonChartCategoriesShow" mnemonicParsing="false" onAction="#buttonChartCategoriesShow"> <font> <Font name="System Bold" size="12.0" /> </font> @@ -52,6 +52,11 @@ <Insets left="15.0" /> </HBox.margin> </Button> + <Button fx:id="buttonChartCategoriesExport" mnemonicParsing="false" onAction="#chartCategoriesExport"> + <font> + <Font name="System Bold" size="12.0" /> + </font> + </Button> </children> <HBox.margin> <Insets left="15.0" /> @@ -108,7 +113,7 @@ </HBox> </children> </VBox> - <HBox alignment="CENTER_LEFT" spacing="15.0" HBox.hgrow="ALWAYS"> + <HBox fx:id="hboxChartMonthButtons" alignment="CENTER_LEFT" spacing="15.0" HBox.hgrow="ALWAYS"> <children> <RadioButton fx:id="radioButtonBars" mnemonicParsing="false" text="Balken"> <font> diff --git a/src/de/deadlocker8/budgetmaster/ui/ExportChartController.java b/src/de/deadlocker8/budgetmaster/ui/ExportChartController.java new file mode 100644 index 0000000000000000000000000000000000000000..2815dc0a7ef22b47f1c289f1229c30ba16edfbc7 --- /dev/null +++ b/src/de/deadlocker8/budgetmaster/ui/ExportChartController.java @@ -0,0 +1,242 @@ +package de.deadlocker8.budgetmaster.ui; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import java.util.Optional; + +import javax.imageio.ImageIO; + +import fontAwesome.FontIcon; +import fontAwesome.FontIconType; +import javafx.embed.swing.SwingFXUtils; +import javafx.fxml.FXML; +import javafx.scene.SnapshotParameters; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.control.TextFormatter; +import javafx.scene.image.WritableImage; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.transform.Transform; +import javafx.stage.FileChooser; +import javafx.stage.Stage; +import logger.Logger; +import tools.AlertGenerator; + +public class ExportChartController +{ + @FXML private AnchorPane anchorPaneMain; + @FXML private TextField textFieldWidth; + @FXML private TextField textFieldHeight; + @FXML private Label labelSavePath; + @FXML private Button buttonChooseFile; + @FXML private Button buttonExport; + @FXML private Button buttonCancel; + + private ChartController controller; + private Stage stage; + private VBox chart; + private File savePath; + + public void init(Stage stage, ChartController controller, VBox chart) + { + this.controller = controller; + this.stage = stage; + this.chart = chart; + + this.savePath = controller.getLastExportPath(); + if(savePath != null) + { + labelSavePath.setText(savePath.getAbsolutePath()); + } + + anchorPaneMain.setStyle("-fx-background-color: #F4F4F4;"); + + FontIcon iconShow = new FontIcon(FontIconType.FOLDER_OPEN); + iconShow.setSize(14); + iconShow.setColor(Color.WHITE); + buttonChooseFile.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 14;"); + buttonChooseFile.setGraphic(iconShow); + + FontIcon iconShow2 = new FontIcon(FontIconType.SAVE); + iconShow2.setSize(14); + iconShow2.setColor(Color.WHITE); + buttonExport.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 14;"); + buttonExport.setGraphic(iconShow2); + + FontIcon iconShow3 = new FontIcon(FontIconType.TIMES); + iconShow3.setSize(14); + iconShow3.setColor(Color.WHITE); + buttonCancel.setStyle("-fx-background-color: #2E79B9; -fx-text-fill: white; -fx-font-weight: bold; -fx-font-size: 14;"); + buttonCancel.setGraphic(iconShow3); + + textFieldWidth.setTextFormatter(new TextFormatter<>(c -> { + if(c.getControlNewText().isEmpty()) + { + return c; + } + + if(c.getControlNewText().matches("[0-9]*")) + { + return c; + } + else + { + return null; + } + })); + + textFieldHeight.setTextFormatter(new TextFormatter<>(c -> { + if(c.getControlNewText().isEmpty()) + { + return c; + } + + if(c.getControlNewText().matches("[0-9]*")) + { + return c; + } + else + { + return null; + } + })); + } + + public void chooseFile() + { + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Diagramm exportieren"); + FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("PNG (*.png)", "*.png"); + if(savePath != null) + { + fileChooser.setInitialDirectory(savePath.getParentFile()); + fileChooser.setInitialFileName(savePath.getName()); + } + fileChooser.getExtensionFilters().add(extFilter); + File file = fileChooser.showSaveDialog(stage); + if(file != null) + { + savePath = file; + labelSavePath.setText(file.getAbsolutePath()); + } + } + + public void export() + { + String widthText = textFieldWidth.getText(); + if(widthText == null || widthText.equals("")) + { + AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Bitte gib eine Breite in Pixeln an.", controller.getControlle().getIcon(), stage, null, false); + return; + } + + int width = 0; + try + { + width = Integer.parseInt(widthText); + } + catch(Exception e) + { + AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Nur ganzahlige Werte sind für das Feld Breite erlaubt.", controller.getControlle().getIcon(), stage, null, false); + return; + } + + String heightText = textFieldHeight.getText(); + if(heightText == null || heightText.equals("")) + { + AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Bitte gib eine Höhe in Pixeln an.", controller.getControlle().getIcon(), stage, null, false); + return; + } + + int height = 0; + try + { + height = Integer.parseInt(heightText); + } + catch(Exception e) + { + AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Nur ganzahlige Werte sind für das Feld Höhe erlaubt.", controller.getControlle().getIcon(), stage, null, false); + return; + } + + if(savePath == null) + { + AlertGenerator.showAlert(AlertType.WARNING, "Warnung", "", "Wähle einen Speicherort für das Diagramm aus.", controller.getControlle().getIcon(), stage, null, false); + return; + } + + SnapshotParameters sp = new SnapshotParameters(); + sp.setTransform(Transform.scale(width / chart.getWidth(), height / chart.getHeight())); + WritableImage image = chart.snapshot(sp, null); + try + { + ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", savePath); + controller.getControlle().showNotification("Diagramm erfolgreich exportiert"); + + stage.close(); + + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Erfolgreich erstellt"); + alert.setHeaderText(""); + alert.setContentText("Das Diagramm wurde erfolgreich exportiert"); + Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow(); + dialogStage.getIcons().add(controller.getControlle().getIcon()); + + ButtonType buttonTypeOne = new ButtonType("Ordner öffnen"); + ButtonType buttonTypeTwo = new ButtonType("Diagramm öffnen"); + ButtonType buttonTypeThree = new ButtonType("OK"); + alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo, buttonTypeThree); + + Optional<ButtonType> result = alert.showAndWait(); + if (result.get() == buttonTypeOne) + { + try + { + Desktop.getDesktop().open(new File(savePath.getParent().replace("\\", "/"))); + } + catch(IOException e1) + { + Logger.error(e1); + AlertGenerator.showAlert(AlertType.ERROR, "Fehler", "", "Der Ordner konnte nicht geöffnet werden\n\n" + e1.getMessage(), controller.getControlle().getIcon(), stage, null, false); + } + } + else if (result.get() == buttonTypeTwo) + { + try + { + Desktop.getDesktop().open(new File(savePath.getAbsolutePath().replace("\\", "/"))); + } + catch(IOException e1) + { + Logger.error(e1); + AlertGenerator.showAlert(AlertType.ERROR, "Fehler", "", "Das Diagramm konnte nicht geöffnet werden\n\n" + e1.getMessage(), controller.getControlle().getIcon(), stage, null, false); + } + } + else + { + alert.close(); + } + } + catch(IOException e) + { + Logger.error(e); + AlertGenerator.showAlert(AlertType.ERROR, "Fehler", "", "Beim Exportieren des Diagramms ist ein Fehler aufgetreten:\n\n" + e.getMessage(), controller.getControlle().getIcon(), stage, null, false); + } + + stage.close(); + controller.chartCategoriesShow(false); + controller.setLastExportPath(savePath); + } + + public void cancel() + { + stage.close(); + } +} \ No newline at end of file diff --git a/src/de/deadlocker8/budgetmaster/ui/ExportChartGUI.fxml b/src/de/deadlocker8/budgetmaster/ui/ExportChartGUI.fxml new file mode 100644 index 0000000000000000000000000000000000000000..f65888dba78eb7068225922fb11ba1ce345fecf6 --- /dev/null +++ b/src/de/deadlocker8/budgetmaster/ui/ExportChartGUI.fxml @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.Label?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.text.Font?> + +<AnchorPane fx:id="anchorPaneMain" prefHeight="200.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.budgetmaster.ui.ExportChartController"> + <children> + <VBox AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> + <children> + <HBox prefHeight="125.0" prefWidth="372.0" spacing="15.0"> + <children> + <VBox alignment="TOP_RIGHT" prefHeight="125.0" prefWidth="99.0" spacing="15.0"> + <children> + <Label text="Breite:"> + <font> + <Font name="System Bold" size="16.0" /> + </font> + </Label> + <Label text="Höhe:"> + <font> + <Font name="System Bold" size="16.0" /> + </font> + </Label> + <Label prefHeight="30.0" prefWidth="92.0" text="Speicherort:"> + <font> + <Font name="System Bold" size="16.0" /> + </font> + </Label> + </children> + <HBox.margin> + <Insets /> + </HBox.margin> + </VBox> + <VBox prefHeight="4.0" prefWidth="100.0" spacing="15.0" HBox.hgrow="ALWAYS"> + <children> + <TextField fx:id="textFieldWidth" /> + <TextField fx:id="textFieldHeight" /> + <HBox alignment="CENTER_LEFT" spacing="15.0"> + <children> + <Label fx:id="labelSavePath" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" /> + <Button fx:id="buttonChooseFile" mnemonicParsing="false" onAction="#chooseFile" text="Ändern" /> + </children> + </HBox> + </children> + </VBox> + </children> + </HBox> + <HBox alignment="CENTER" spacing="25.0" VBox.vgrow="ALWAYS"> + <children> + <Button fx:id="buttonCancel" mnemonicParsing="false" onAction="#cancel" text="Abbrechen" /> + <Button fx:id="buttonExport" mnemonicParsing="false" onAction="#export" text="Exportieren" /> + </children> + </HBox> + </children> + </VBox> + </children> +</AnchorPane>