Re-implemented undo functionality

This commit is contained in:
Brendan Robert 2023-10-09 19:06:23 -05:00
parent 37a9d805fd
commit 885dc982b4
17 changed files with 101 additions and 109 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

View File

@ -5,7 +5,7 @@
<artifactId>OutlawEditor</artifactId>
<name>OutlawEditor</name>
<packaging>jar</packaging>
<version>3.0-SNAPSHOT</version>
<version>3.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>org.badvision.outlaweditor.Application</mainClass>
@ -75,6 +75,27 @@
<packageName>org.badvision.outlaweditor.data.xml</packageName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
@ -88,23 +109,12 @@
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>

View File

@ -1,8 +1,6 @@
module outlaweditor {
requires org.controlsfx.controls;
requires javafx.controls;
requires javafx.graphics;
requires jdk.jsobject;
requires javafx.web;
requires javafx.media;
requires javafx.fxml;
@ -10,8 +8,12 @@ module outlaweditor {
requires java.desktop;
requires java.scripting;
requires java.xml;
requires jdk.jsobject;
requires jakarta.xml.bind;
requires org.apache.poi.ooxml;
requires org.glassfish.jaxb.runtime;
requires org.controlsfx.controls;
// requires org.apache.poi.ooxml;
opens org.badvision.outlaweditor to javafx.graphics, javafx.fxml, javafx.web, org.apache.poi.ooxml;
opens org.badvision.outlaweditor.ui to javafx.fxml;

View File

@ -109,12 +109,14 @@ public abstract class Editor<T, D> implements DataObserver<T> {
public void undo() {
if (!undoStates.isEmpty()) {
T undoState = undoStates.removeFirst();
setEntity(undoState);
copyEntityFrom(undoState);
onEntityUpdated();
redraw();
}
}
public abstract void copyEntityFrom(T copyFrom);
protected void onEntityUpdated() {
}

View File

@ -99,5 +99,9 @@ public class GlobalEditor extends Editor<Global, Void>{
public void copyData() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void copyEntityFrom(Global src) {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
}

View File

@ -79,4 +79,14 @@ public abstract class ImageEditor extends Editor<Image, ImageEditor.DrawMode> {
public void showSelectorModal() {
patternSelectModal.showPatternSelectModal(targetPane);
}
@Override
public void copyEntityFrom(Image src) {
Image dest = getEntity();
dest.setCategory(src.getCategory());
dest.setComment(src.getComment());
dest.setName(src.getName());
dest.getDisplayData().clear();
dest.getDisplayData().addAll(src.getDisplayData());
}
}

View File

@ -817,4 +817,21 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
}
}
@Override
public void copyEntityFrom(Map src) {
Map dest = getEntity();
dest.setCategory(src.getCategory());
dest.setDisplay3D(src.isDisplay3D());
dest.setHeight(src.getHeight());
dest.setName(src.getName());
dest.setOrder(src.getOrder());
dest.setScripts(src.getScripts());
dest.setStartX(src.getStartX());
dest.setStartY(src.getStartY());
dest.setVariables(src.getVariables());
dest.setWidth(src.getWidth());
dest.getChunk().clear();
dest.getChunk().addAll(src.getChunk());
}
}

View File

@ -14,13 +14,14 @@
package org.badvision.outlaweditor;
import java.io.IOException;
import org.badvision.outlaweditor.data.xml.Sheet;
import org.badvision.outlaweditor.ui.impl.SheetEditorControllerImpl;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.badvision.outlaweditor.data.xml.Sheet;
import org.badvision.outlaweditor.ui.impl.SheetEditorControllerImpl;
/**
* Edit a spreadsheet of information

View File

@ -10,20 +10,11 @@
package org.badvision.outlaweditor;
/**
*
* @author brobert
*/
import javafx.event.EventHandler;
import javafx.scene.control.Menu;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.PatternSelectModal;
import org.badvision.outlaweditor.ui.TileSelectModal;
import javafx.scene.control.Menu;
import javafx.scene.layout.Pane;
public abstract class TileEditor extends Editor<Tile, TileEditor.DrawMode> {
abstract public void buildPatternSelector(Menu tilePatternMenu);
@ -45,4 +36,19 @@ public abstract class TileEditor extends Editor<Tile, TileEditor.DrawMode> {
public void showSelectorModal() {
patternSelectModal.showPatternSelectModal(targetPane);
}
@Override
public void copyEntityFrom(Tile src) {
Tile dest = getEntity();
dest.setBlocker(src.isBlocker());
dest.setCategory(src.getCategory());
dest.setComment(src.getComment());
dest.setId(src.getId());
dest.setName(src.getName());
dest.setObstruction(src.isObstruction());
dest.setSprite(src.isSprite());
dest.getDisplayData().clear();
dest.getDisplayData().addAll(src.getDisplayData());
}
}

View File

@ -43,7 +43,7 @@ public enum Platform {
public int maxImageWidth;
public int maxImageHeight;
Platform(Class ed, Class imged, TileRenderer ren, ImageRenderer img, int w, int h, int maxW, int maxH) {
Platform(Class<? extends TileEditor> ed, Class<? extends ImageEditor> imged, TileRenderer ren, ImageRenderer img, int w, int h, int maxW, int maxH) {
tileEditor = ed;
imageEditor = imged;
tileRenderer = ren;

View File

@ -34,12 +34,6 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.namespace.QName;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.Block;
import org.badvision.outlaweditor.data.xml.Field;
@ -266,12 +260,8 @@ public class DataUtilities {
if (file.getName().toLowerCase().endsWith("txt")
|| file.getName().toLowerCase().endsWith("tsv")) {
return readTextFile(file);
} else if (file.getName().toLowerCase().endsWith("xls")) {
return readLegacyExcel(file);
} else if (file.getName().toLowerCase().endsWith("xlsx")) {
return readExcel(file);
}
} catch (IOException | InvalidFormatException ex) {
}
} catch (IOException ex) {
Logger.getLogger(DataUtilities.class.getName()).log(Level.SEVERE, null, ex);
}
UIAction.alert("Couldn't figure out how to import file " + file.getName());
@ -283,42 +273,6 @@ public class DataUtilities {
return reader.lines().map(line -> Arrays.asList(line.split("\\t"))).collect(Collectors.toList());
}
public static List<List<String>> readLegacyExcel(File file) throws FileNotFoundException, IOException {
return readSheet(new HSSFWorkbook(new FileInputStream(file)));
}
public static List<List<String>> readExcel(File file) throws FileNotFoundException, IOException, InvalidFormatException {
return readSheet(new XSSFWorkbook(file));
}
public static List<List<String>> readSheet(Workbook workbook) {
Sheet sheet = workbook.getSheetAt(0);
List<List<String>> data = new ArrayList<>();
sheet.forEach(row -> {
List<String> rowData = new ArrayList<>();
row.forEach(cell -> {
String col = getStringValueFromCell(cell);
rowData.add(col);
});
data.add(rowData);
});
return data;
}
public static String getStringValueFromCell(Cell cell) {
switch (cell.getCellType()) {
case BOOLEAN:
return Boolean.toString(cell.getBooleanCellValue());
case BLANK:
return null;
case NUMERIC:
return Double.toString(cell.getNumericCellValue());
case STRING:
return cell.getStringCellValue();
default:
return "???";
}
}
public static String hexDump(byte[] data) {
StringBuilder dump = new StringBuilder();

View File

@ -10,8 +10,6 @@
package org.badvision.outlaweditor.ui;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Group;

View File

@ -144,6 +144,8 @@ public class UIAction {
JAXB.marshal(ApplicationState.getInstance().getGameData(), currentSaveFile);
}
break;
default:
break;
}
}

View File

@ -266,7 +266,7 @@ public class SheetEditorControllerImpl extends SheetEditorController {
rebuildColumnHeaders();
tableData = FXCollections.observableList(new ArrayList(numRows));
tableData = FXCollections.observableList(new ArrayList<>(numRows));
if (editor.getSheet().getRows() != null) {
int rowNum = 0;
for (Row row : editor.getSheet().getRows().getRow()) {

View File

@ -10,6 +10,7 @@
package org.badvision.outlaweditor.ui.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@ -46,7 +47,7 @@ import javafx.util.StringConverter;
*/
public class TileEditorTabControllerImpl extends TileEditorTabController {
FlowPane quickMenu = new FlowPane();
ChangeListener rebuildListener = (ObservableValue value, Object oldValue, Object newValue) -> rebuildTileSelectors();
ChangeListener<String> rebuildListener = (ObservableValue<? extends String> value, String oldValue, String newValue) -> rebuildTileSelectors();
@Override
public void onCurrentTileSelected(ActionEvent event) {
@ -235,12 +236,12 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
bind(tileSpriteField.selectedProperty(), boolProp(t, "sprite"));
bind(tileBlockerField.selectedProperty(), boolProp(t, "blocker"));
bind(tileNameField.textProperty(), stringProp(t, "name"));
TileEditor editor = ApplicationState.getInstance().getCurrentPlatform().tileEditor.newInstance();
TileEditor editor = ApplicationState.getInstance().getCurrentPlatform().tileEditor.getDeclaredConstructor().newInstance();
editor.setEntity(t);
setCurrentTileEditor(editor);
tileNameField.textProperty().addListener(rebuildListener);
tileCategoryField.textProperty().addListener(rebuildListener);
} catch (NoSuchMethodException ex) {
} catch (IllegalArgumentException | InvocationTargetException | SecurityException | NoSuchMethodException ex) {
Logger.getLogger(ApplicationUIController.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);

View File

@ -16,7 +16,7 @@
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" styleClass="sheetEditor" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.SheetEditorControllerImpl">
<stylesheets>
<URL value="@/styles/styles.css" />
<URL value="@styles/styles.css" />
</stylesheets>
<children>
<VBox layoutX="167.0" layoutY="63.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">

View File

@ -30,24 +30,6 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.22.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
<configuration>
<properties>
<service.vendor>8-Bit Bunch</service.vendor>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>