added image support for designer

This commit is contained in:
modmuss50 2016-04-16 13:41:52 +01:00
parent 58acfb9337
commit 55739cdb98
No known key found for this signature in database
GPG key ID: 1838986A0F12E8EE
5 changed files with 88 additions and 12 deletions

View file

@ -15,6 +15,7 @@ import techreborn.manual.designer.fileUtils.SaveSystem;
import techreborn.manual.designer.windows.MainWindowController; import techreborn.manual.designer.windows.MainWindowController;
import techreborn.manual.saveFormat.Entry; import techreborn.manual.saveFormat.Entry;
import java.io.File;
import java.net.URL; import java.net.URL;
/** /**
@ -73,10 +74,30 @@ public class ManualDesigner extends Application {
if(entry.data.data.containsKey("text")){ if(entry.data.data.containsKey("text")){
controller.textInput.setText(entry.data.data.get("text")); controller.textInput.setText(entry.data.data.get("text"));
} }
if(entry.data.data.containsKey("image")){
controller.imageTextArea.setText(entry.data.data.get("image"));
if(SaveSystem.lastSave != null){
File imagesDir = new File(SaveSystem.lastSave, "images");
if(imagesDir.exists()){
File image = new File(imagesDir, entry.data.data.get("image") + ".png");
if(image.exists()){
controller.pageimage.setImage(new Image(image.toURI().toString()));
}
}
}
} else {
controller.imageTextArea.setText("");
}
//TODO Improve this //TODO Improve this
} else { } else {
controller.textInput.setText(""); controller.textInput.setText("");
} }
if(entry.type.equalsIgnoreCase("image")){
controller.imageTextArea.setDisable(false);
} else {
controller.imageTextArea.setDisable(true);
}
controller.infoLabel.setText("Settings: " + entry.type);
controller.nameTextArea.setText(entry.registryName); controller.nameTextArea.setText(entry.registryName);
} }
} }
@ -96,6 +117,14 @@ public class ManualDesigner extends Application {
controller.image.fitWidthProperty().bind(controller.renderPane.widthProperty()); controller.image.fitWidthProperty().bind(controller.renderPane.widthProperty());
controller.image.fitHeightProperty().bind(controller.renderPane.heightProperty()); controller.image.fitHeightProperty().bind(controller.renderPane.heightProperty());
controller.pageimage.setPreserveRatio(true);
controller.pageimage.setSmooth(true);
controller.pageimage.setCache(true);
controller.pageimage.setFitHeight(1000);
controller.pageimage.setFitWidth(1000);
controller.pageimage.fitWidthProperty().bind(controller.renderPane.widthProperty());
controller.pageimage.fitHeightProperty().bind(controller.renderPane.heightProperty());
controller.load(); controller.load();
Alert alert = new Alert(Alert.AlertType.INFORMATION); Alert alert = new Alert(Alert.AlertType.INFORMATION);

View file

@ -1,7 +1,9 @@
package techreborn.manual.designer.fileUtils; package techreborn.manual.designer.fileUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import javafx.scene.control.Alert;
import javafx.scene.control.TreeItem; import javafx.scene.control.TreeItem;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import techreborn.manual.designer.ManualCatergories; import techreborn.manual.designer.ManualCatergories;
import techreborn.manual.designer.ManualDesigner; import techreborn.manual.designer.ManualDesigner;
@ -19,20 +21,28 @@ import java.io.FileReader;
public class LoadSystem { public class LoadSystem {
public static void load() throws FileNotFoundException { public static void load() throws FileNotFoundException {
FileChooser fileChooser = new FileChooser(); DirectoryChooser fileChooser = new DirectoryChooser();
fileChooser.setTitle("Open master.json"); fileChooser.setTitle("Open Folder");
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Jason File (*.json)", "*.json"));
fileChooser.setInitialFileName("master.json");
fileChooser.setInitialDirectory(new File(".")); fileChooser.setInitialDirectory(new File("."));
File file = fileChooser.showOpenDialog(ManualDesigner.stage); File folder = fileChooser.showDialog(ManualDesigner.stage);
if(file != null){ if(folder != null){
if(file.getName().endsWith(".json")){ File masterJson = new File(folder, "master.json");
if(!masterJson.exists()){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Could not find project");
alert.setHeaderText("Could not find project!");
alert.setContentText("Could not find the project in this directory!");
alert.show();
} else if(masterJson.getName().endsWith(".json")){
//Things //Things
BufferedReader reader = new BufferedReader(new FileReader(file)); File imageDir = new File(folder, "images");
if(!imageDir.exists()){
imageDir.mkdir();
}
BufferedReader reader = new BufferedReader(new FileReader(masterJson));
Gson gson = new Gson(); Gson gson = new Gson();
ManualFormat format; ManualFormat format;
format = gson.fromJson(reader, ManualFormat.class); format = gson.fromJson(reader, ManualFormat.class);
System.out.println(format.entries);
for(Entry entry : format.entries){ for(Entry entry : format.entries){
System.out.println(entry.type); System.out.println(entry.type);
TreeItem parentTree = null; TreeItem parentTree = null;
@ -49,6 +59,7 @@ public class LoadSystem {
parentTree.setExpanded(true); parentTree.setExpanded(true);
SaveSystem.entries.put(newItem, entry); SaveSystem.entries.put(newItem, entry);
} }
SaveSystem.lastSave = folder;
} }
} }
} }

View file

@ -24,7 +24,7 @@ public class SaveSystem {
public static ManualFormat master; public static ManualFormat master;
static File lastSave = null; public static File lastSave = null;
public static void export(){ public static void export(){
List<Entry> entryList = new ArrayList<>(entries.values()); List<Entry> entryList = new ArrayList<>(entries.values());
@ -40,6 +40,10 @@ public class SaveSystem {
chooser.setInitialDirectory(openLocation); chooser.setInitialDirectory(openLocation);
File selectedDirectory = chooser.showDialog(ManualDesigner.stage); File selectedDirectory = chooser.showDialog(ManualDesigner.stage);
lastSave = selectedDirectory; lastSave = selectedDirectory;
File imageDir = new File(selectedDirectory, "images");
if(!imageDir.exists()){
imageDir.mkdir();
}
File masterJson = new File(selectedDirectory, "master.json"); File masterJson = new File(selectedDirectory, "master.json");
if(masterJson.exists()){ if(masterJson.exists()){
masterJson.delete(); masterJson.delete();

View file

@ -4,6 +4,7 @@ import javafx.event.ActionEvent;
import javafx.event.Event; import javafx.event.Event;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.MenuBar; import javafx.scene.control.MenuBar;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
@ -34,6 +35,9 @@ public class MainWindowController {
public TextArea textInput; public TextArea textInput;
public Button buttonDelete; public Button buttonDelete;
public TextField nameTextArea; public TextField nameTextArea;
public TextField imageTextArea;
public ImageView pageimage;
public Label infoLabel;
public void newItem(Event event) { public void newItem(Event event) {
if(treeList.getSelectionModel().getSelectedItem() instanceof TreeItem){ if(treeList.getSelectionModel().getSelectedItem() instanceof TreeItem){
@ -114,6 +118,9 @@ public class MainWindowController {
nameTextArea.textProperty().addListener((observable, oldValue, newValue) -> { nameTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
nameChange(); nameChange();
}); });
imageTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
imageAreaChanged();
});
} }
@ -140,6 +147,28 @@ public class MainWindowController {
} }
} }
public void imageAreaChanged() {
if(!treeList.getSelectionModel().isEmpty()){
if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){
Entry entry = SaveSystem.entries.get(treeList.getSelectionModel().getSelectedItem());
if(entry != null){
if(entry.data == null){
entry.data = new EntryData();
}
if(entry.data.data == null){
entry.data.data = new HashMap<>();
}
if(entry.data.data.containsKey("image")){
entry.data.data.replace("image", imageTextArea.getText());
} else {
entry.data.data.put("image", imageTextArea.getText());
}
}
SaveSystem.entries.replace((TreeItem) treeList.getSelectionModel().getSelectedItem(), entry);
}
}
}
public void nameChange() { public void nameChange() {
if(!treeList.getSelectionModel().isEmpty()){ if(!treeList.getSelectionModel().isEmpty()){
if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){ if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){

View file

@ -13,7 +13,7 @@
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="550.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="techreborn.manual.designer.windows.MainWindowController"> <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="550.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.72" xmlns:fx="http://javafx.com/fxml/1" fx:controller="techreborn.manual.designer.windows.MainWindowController">
<children> <children>
<MenuBar fx:id="menuBar"> <MenuBar fx:id="menuBar">
<menus> <menus>
@ -52,12 +52,15 @@
<AnchorPane fx:id="renderPane" minHeight="0.0" minWidth="0.0" prefHeight="358.0" prefWidth="417.0"> <AnchorPane fx:id="renderPane" minHeight="0.0" minWidth="0.0" prefHeight="358.0" prefWidth="417.0">
<children> <children>
<ImageView fx:id="image" fitHeight="298.0" fitWidth="417.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="75.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <ImageView fx:id="image" fitHeight="298.0" fitWidth="417.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="75.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<ImageView fx:id="pageimage" fitHeight="234.0" fitWidth="359.0" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true" />
<AnchorPane prefHeight="98.0" prefWidth="627.0" style="-fx-background-color: lightgrey;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"> <AnchorPane prefHeight="98.0" prefWidth="627.0" style="-fx-background-color: lightgrey;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children> <children>
<Label layoutY="6.0" text="Settings" /> <Label fx:id="infoLabel" layoutY="6.0" text="Settings" />
<TextArea fx:id="textInput" layoutX="43.0" layoutY="8.0" maxWidth="250.0" prefHeight="59.0" prefWidth="250.0" AnchorPane.bottomAnchor="8.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="8.0" /> <TextArea fx:id="textInput" layoutX="43.0" layoutY="8.0" maxWidth="250.0" prefHeight="59.0" prefWidth="250.0" AnchorPane.bottomAnchor="8.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="8.0" />
<TextField fx:id="nameTextArea" layoutX="88.0" layoutY="25.0" /> <TextField fx:id="nameTextArea" layoutX="88.0" layoutY="25.0" />
<Label layoutX="6.0" layoutY="29.0" text="Registry Name" /> <Label layoutX="6.0" layoutY="29.0" text="Registry Name" />
<Label layoutX="11.0" layoutY="59.0" text="Image Name" />
<TextField fx:id="imageTextArea" layoutX="88.0" layoutY="55.0" />
</children> </children>
</AnchorPane> </AnchorPane>
</children> </children>