diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java index 78387b80..ba447588 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/Application.java @@ -48,16 +48,6 @@ public class Application extends javafx.application.Application { @Override public void handle(final WindowEvent t) { t.consume(); - if (quit()) { - javafx.application.Platform.exit(); -// System.exit(0); - } - javafx.application.Platform.runLater(new Runnable() { - @Override - public void run() { - getPrimaryStage().show(); - } - }); } }); primaryStage.show(); diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java index ab393834..0e924d1f 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java @@ -162,7 +162,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { currentImageEditor.setDrawMode(ImageEditor.DrawMode.Pencil5px); } } - + @Override public void imageDrawFilledRectMode(ActionEvent event) { if (currentImageEditor != null) { @@ -279,7 +279,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { Application.currentPlatform = Platform.AppleII_DHGR; platformChange(); } - + private void platformChange() { for (Tile t : Application.gameData.getTile()) { TileUtils.redrawTile(t); @@ -292,7 +292,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { } rebuildImageSelector(); } - + @Override public void onChangePlatformC64(ActionEvent event) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -378,13 +378,18 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { @Override public void onImageDeletePressed(ActionEvent event) { - if (currentImage == null) return; - if (confirm("Delete image '"+currentImage.getName()+"'. Are you sure?")) { - Image del = currentImage; - setCurrentImage(null); - Application.gameData.getImage().remove(del); - rebuildImageSelector(); + if (currentImage == null) { + return; } + confirm("Delete image '" + currentImage.getName() + "'. Are you sure?", new Runnable() { + @Override + public void run() { + Image del = currentImage; + setCurrentImage(null); + Application.gameData.getImage().remove(del); + rebuildImageSelector(); + } + }, null); } @Override @@ -415,13 +420,18 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { @Override public void onMapDeletePressed(ActionEvent event) { - if (currentMap == null) return; - if (confirm("Delete map '"+currentMap.getName()+"'. Are you sure?")) { - org.badvision.outlaweditor.data.xml.Map del = currentMap; - setCurrentMap(null); - Application.gameData.getMap().remove(del); - rebuildMapSelectors(); + if (currentMap == null) { + return; } + confirm("Delete map '" + currentMap.getName() + "'. Are you sure?", new Runnable() { + @Override + public void run() { + org.badvision.outlaweditor.data.xml.Map del = currentMap; + setCurrentMap(null); + Application.gameData.getMap().remove(del); + rebuildMapSelectors(); + } + }, null); } @Override @@ -491,13 +501,20 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { @Override public void onTileDeletePressed(ActionEvent event) { - if (currentTile == null) return; - if (confirm("Delete tile '"+currentTile.getName()+"'. Are you sure?")) { - Tile del = currentTile; - setCurrentTile(null); - Application.gameData.getTile().remove(del); - rebuildTileSelectors(); + if (currentTile == null) { + return; } + confirm("Delete tile '" + currentTile.getName() + "'. Are you sure?", new Runnable() { + + @Override + public void run() { + Tile del = currentTile; + setCurrentTile(null); + Application.gameData.getTile().remove(del); + rebuildTileSelectors(); + } + + }, null); } @Override @@ -778,8 +795,12 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { imageSelector.getSelectionModel().select(i); } - public static enum TABS{image,map,tile}; + public static enum TABS { + + image, map, tile + }; TABS currentTab; + @Override public void imageTabActivated(Event event) { currentTab = TABS.image; @@ -794,7 +815,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { public void tileTabActivated(Event event) { currentTab = TABS.tile; } - + public Editor getVisibleEditor() { switch (currentTab) { case image: @@ -851,4 +872,4 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { public void finishUpdate(T item) { } }; -} \ No newline at end of file +} diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/UIAction.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/UIAction.java index 5e8f166e..814a0c9d 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/UIAction.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/UIAction.java @@ -6,16 +6,27 @@ package org.badvision.outlaweditor; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Button; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.image.Image; import javafx.scene.image.WritableImage; +import javafx.scene.layout.HBoxBuilder; +import javafx.scene.layout.VBoxBuilder; +import javafx.scene.text.Text; +import javafx.stage.Modality; +import javafx.stage.Stage; import javax.swing.JOptionPane; import javax.xml.bind.JAXB; import org.badvision.outlaweditor.data.TilesetUtils; @@ -87,8 +98,8 @@ public class UIAction { currentSaveFile = f; case Save: if (currentSaveFile == null) { - currentSaveFile = FileUtils.getFile(currentSaveFile, "Save game data", Boolean.TRUE, FileUtils.Extension.XML, FileUtils.Extension.ALL); - } + currentSaveFile = FileUtils.getFile(currentSaveFile, "Save game data", Boolean.TRUE, FileUtils.Extension.XML, FileUtils.Extension.ALL); + } if (currentSaveFile != null) { currentSaveFile.delete(); JAXB.marshal(Application.gameData, currentSaveFile); @@ -126,12 +137,13 @@ public class UIAction { return menu; } - public static boolean quit() { - if (JOptionPane.showConfirmDialog(null, "Quit? Are you sure?") == JOptionPane.OK_OPTION) { - Platform.exit(); - return true; - } - return false; + public static void quit() { + confirm("Quit? Are you sure?", new Runnable() { + @Override + public void run() { + Platform.exit(); + } + }, null); } static Image badImage; @@ -145,8 +157,43 @@ public class UIAction { return img; } + + public static class Choice { + String text; + Runnable handler; + public Choice(String text, Runnable handler) { + this.text = text; + this.handler = handler; + } + } + + public static void confirm(String message, Runnable yes, Runnable no) { + choose(message, new Choice("Yes", yes), new Choice("No", no)); + } - public static boolean confirm(String string) { - return JOptionPane.showConfirmDialog(null, string) == JOptionPane.YES_OPTION; - } -} \ No newline at end of file + public static void choose(String message, Choice... choices) { + final Stage dialogStage = new Stage(); + + HBoxBuilder options = HBoxBuilder.create().alignment(Pos.CENTER).spacing(10.0).padding(new Insets(5)); + List