added image support for designer
This commit is contained in:
parent
58acfb9337
commit
55739cdb98
5 changed files with 88 additions and 12 deletions
|
@ -15,6 +15,7 @@ import techreborn.manual.designer.fileUtils.SaveSystem;
|
|||
import techreborn.manual.designer.windows.MainWindowController;
|
||||
import techreborn.manual.saveFormat.Entry;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
|
@ -73,10 +74,30 @@ public class ManualDesigner extends Application {
|
|||
if(entry.data.data.containsKey("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
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -96,6 +117,14 @@ public class ManualDesigner extends Application {
|
|||
controller.image.fitWidthProperty().bind(controller.renderPane.widthProperty());
|
||||
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();
|
||||
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package techreborn.manual.designer.fileUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import techreborn.manual.designer.ManualCatergories;
|
||||
import techreborn.manual.designer.ManualDesigner;
|
||||
|
@ -19,20 +21,28 @@ import java.io.FileReader;
|
|||
public class LoadSystem {
|
||||
|
||||
public static void load() throws FileNotFoundException {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Open master.json");
|
||||
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Jason File (*.json)", "*.json"));
|
||||
fileChooser.setInitialFileName("master.json");
|
||||
DirectoryChooser fileChooser = new DirectoryChooser();
|
||||
fileChooser.setTitle("Open Folder");
|
||||
fileChooser.setInitialDirectory(new File("."));
|
||||
File file = fileChooser.showOpenDialog(ManualDesigner.stage);
|
||||
if(file != null){
|
||||
if(file.getName().endsWith(".json")){
|
||||
File folder = fileChooser.showDialog(ManualDesigner.stage);
|
||||
if(folder != null){
|
||||
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
|
||||
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();
|
||||
ManualFormat format;
|
||||
format = gson.fromJson(reader, ManualFormat.class);
|
||||
System.out.println(format.entries);
|
||||
for(Entry entry : format.entries){
|
||||
System.out.println(entry.type);
|
||||
TreeItem parentTree = null;
|
||||
|
@ -49,6 +59,7 @@ public class LoadSystem {
|
|||
parentTree.setExpanded(true);
|
||||
SaveSystem.entries.put(newItem, entry);
|
||||
}
|
||||
SaveSystem.lastSave = folder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SaveSystem {
|
|||
|
||||
public static ManualFormat master;
|
||||
|
||||
static File lastSave = null;
|
||||
public static File lastSave = null;
|
||||
|
||||
public static void export(){
|
||||
List<Entry> entryList = new ArrayList<>(entries.values());
|
||||
|
@ -40,6 +40,10 @@ public class SaveSystem {
|
|||
chooser.setInitialDirectory(openLocation);
|
||||
File selectedDirectory = chooser.showDialog(ManualDesigner.stage);
|
||||
lastSave = selectedDirectory;
|
||||
File imageDir = new File(selectedDirectory, "images");
|
||||
if(!imageDir.exists()){
|
||||
imageDir.mkdir();
|
||||
}
|
||||
File masterJson = new File(selectedDirectory, "master.json");
|
||||
if(masterJson.exists()){
|
||||
masterJson.delete();
|
||||
|
|
|
@ -4,6 +4,7 @@ import javafx.event.ActionEvent;
|
|||
import javafx.event.Event;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.MenuBar;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
|
@ -34,6 +35,9 @@ public class MainWindowController {
|
|||
public TextArea textInput;
|
||||
public Button buttonDelete;
|
||||
public TextField nameTextArea;
|
||||
public TextField imageTextArea;
|
||||
public ImageView pageimage;
|
||||
public Label infoLabel;
|
||||
|
||||
public void newItem(Event event) {
|
||||
if(treeList.getSelectionModel().getSelectedItem() instanceof TreeItem){
|
||||
|
@ -114,6 +118,9 @@ public class MainWindowController {
|
|||
nameTextArea.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
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() {
|
||||
if(!treeList.getSelectionModel().isEmpty()){
|
||||
if(SaveSystem.entries.containsKey(treeList.getSelectionModel().getSelectedItem())){
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?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>
|
||||
<MenuBar fx:id="menuBar">
|
||||
<menus>
|
||||
|
@ -52,12 +52,15 @@
|
|||
<AnchorPane fx:id="renderPane" minHeight="0.0" minWidth="0.0" prefHeight="358.0" prefWidth="417.0">
|
||||
<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="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">
|
||||
<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" />
|
||||
<TextField fx:id="nameTextArea" layoutX="88.0" layoutY="25.0" />
|
||||
<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>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
|
|
Loading…
Reference in a new issue