From 101ca8c87c1017d172566f883821d9bf040ba30e Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Sat, 10 May 2014 00:17:29 -0500 Subject: [PATCH] Broke menu bar out into its own FXML and controller, just a trial for the next big step. --- .../ApplicationMenuController.java | 51 +++++++ .../ApplicationMenuControllerImpl.java | 134 +++++++++++++++++ .../outlaweditor/ApplicationUIController.java | 57 +++----- .../ApplicationUIControllerImpl.java | 135 +++--------------- .../src/main/resources/ApplicationUI.fxml | 36 +---- OutlawEditor/src/main/resources/Menubar.fxml | 41 ++++++ 6 files changed, 263 insertions(+), 191 deletions(-) create mode 100644 OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuController.java create mode 100644 OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuControllerImpl.java create mode 100644 OutlawEditor/src/main/resources/Menubar.fxml diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuController.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuController.java new file mode 100644 index 00000000..a9f59d45 --- /dev/null +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuController.java @@ -0,0 +1,51 @@ +package org.badvision.outlaweditor; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; + +/** + * + * @author blurry + */ +public abstract class ApplicationMenuController { + + @FXML + abstract public void onChangePlatformAppleDHGRSolid(ActionEvent event); + + @FXML + abstract public void onChangePlatformAppleDHGRText(ActionEvent event); + + @FXML + abstract public void onChangePlatformAppleSolid(ActionEvent event); + + @FXML + abstract public void onChangePlatformAppleText(ActionEvent event); + + @FXML + abstract public void onChangePlatformC64(ActionEvent event); + + @FXML + abstract public void onEditCopy(ActionEvent event); + + @FXML + abstract public void onEditPaste(ActionEvent event); + + @FXML + abstract public void onEditSelect(ActionEvent event); + + @FXML + abstract public void onFileOpen(ActionEvent event); + + @FXML + abstract public void onFileQuit(ActionEvent event); + + @FXML + abstract public void onFileSave(ActionEvent event); + + @FXML + abstract public void onFileSaveAs(ActionEvent event); + + @FXML + abstract public void onHelpAbout(ActionEvent event); + +} diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuControllerImpl.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuControllerImpl.java new file mode 100644 index 00000000..a1f32758 --- /dev/null +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationMenuControllerImpl.java @@ -0,0 +1,134 @@ +package org.badvision.outlaweditor; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javafx.event.ActionEvent; +import org.badvision.outlaweditor.apple.AppleTileRenderer; +import org.badvision.outlaweditor.data.TileUtils; +import org.badvision.outlaweditor.data.xml.Tile; + +/** + * + * @author blurry + */ +public class ApplicationMenuControllerImpl extends ApplicationMenuController { + + @Override + public void onChangePlatformAppleSolid(ActionEvent event) { + AppleTileRenderer.useSolidPalette = true; + Application.currentPlatform = Platform.AppleII; + platformChange(); + } + + @Override + public void onChangePlatformAppleText(ActionEvent event) { + AppleTileRenderer.useSolidPalette = false; + Application.currentPlatform = Platform.AppleII; + platformChange(); + } + + @Override + public void onChangePlatformAppleDHGRSolid(ActionEvent event) { + AppleTileRenderer.useSolidPalette = true; + Application.currentPlatform = Platform.AppleII_DHGR; + platformChange(); + } + + @Override + public void onChangePlatformAppleDHGRText(ActionEvent event) { + AppleTileRenderer.useSolidPalette = false; + Application.currentPlatform = Platform.AppleII_DHGR; + platformChange(); + } + + private void platformChange() { + for (Tile t : Application.gameData.getTile()) { + TileUtils.redrawTile(t); + } + ApplicationUIController mainController = ApplicationUIController.getController(); + Tile tile = mainController.getCurrentTile(); + mainController.rebuildTileSelectors(); + mainController.setCurrentTile(tile); + if (mainController.getCurrentMapEditor() != null) { + mainController.getCurrentMapEditor().redraw(); + } + mainController.rebuildImageSelector(); + } + + @Override + public void onChangePlatformC64(ActionEvent event) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public void onEditCopy(ActionEvent event) { + ApplicationUIController mainController = ApplicationUIController.getController(); + if (mainController.getVisibleEditor() != null) { + mainController.getVisibleEditor().copy(); + } + } + + @Override + public void onEditPaste(ActionEvent event) { + ApplicationUIController mainController = ApplicationUIController.getController(); + if (mainController.getVisibleEditor() != null) { + mainController.getVisibleEditor().paste(); + } + } + + @Override + public void onEditSelect(ActionEvent event) { + ApplicationUIController mainController = ApplicationUIController.getController(); + if (mainController.getVisibleEditor() != null) { + mainController.getVisibleEditor().select(); + } + } + + @Override + public void onFileOpen(ActionEvent event) { + ApplicationUIController mainController = ApplicationUIController.getController(); + try { + UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Load); + mainController.rebuildImageSelector(); + mainController.rebuildMapSelectors(); + mainController.rebuildTileSelectors(); + } catch (IOException ex) { + Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void onFileQuit(ActionEvent event) { + UIAction.quit(); + } + + @Override + public void onFileSave(ActionEvent event) { + ApplicationUIController mainController = ApplicationUIController.getController(); + if (mainController.getCurrentMapEditor() != null) { + mainController.getCurrentMapEditor().currentMap.updateBackingMap(); + } + try { + UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Save); + } catch (IOException ex) { + Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void onFileSaveAs(ActionEvent event) { + try { + UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Save_as); + } catch (IOException ex) { + Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Override + public void onHelpAbout(ActionEvent event) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + +} diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIController.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIController.java index 15830daa..a2a698bb 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIController.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIController.java @@ -18,8 +18,26 @@ import org.badvision.outlaweditor.data.xml.Script; import org.badvision.outlaweditor.data.xml.Tile; public abstract class ApplicationUIController { + public static ApplicationUIController getController() { + return Application.instance.controller; + } + + abstract public MapEditor getCurrentMapEditor(); + + abstract public void setCurrentTile(Tile tile); + + abstract public Tile getCurrentTile(); + + abstract void rebuildMapSelectors(); + abstract void rebuildTileSelectors(); + + abstract void rebuildImageSelector(); + + abstract Editor getVisibleEditor(); + @FXML // ResourceBundle that was given to the FXMLLoader protected ResourceBundle resources; + @FXML ApplicationMenuController menuController; @FXML // URL location of the FXML file that was given to the FXMLLoader protected URL location; @FXML // fx:id="imageCategoryField" @@ -132,45 +150,6 @@ public abstract class ApplicationUIController { @FXML abstract public void onCurrentTileSelected(ActionEvent event); - @FXML - abstract public void onChangePlatformAppleSolid(ActionEvent event); - - @FXML - abstract public void onChangePlatformAppleText(ActionEvent event); - - @FXML - abstract public void onChangePlatformAppleDHGRSolid(ActionEvent event); - - @FXML - abstract public void onChangePlatformAppleDHGRText(ActionEvent event); - - @FXML - abstract public void onChangePlatformC64(ActionEvent event); - - @FXML - abstract public void onEditCopy(ActionEvent event); - - @FXML - abstract public void onEditPaste(ActionEvent event); - - @FXML - abstract public void onEditSelect(ActionEvent event); - - @FXML - abstract public void onFileOpen(ActionEvent event); - - @FXML - abstract public void onFileQuit(ActionEvent event); - - @FXML - abstract public void onFileSave(ActionEvent event); - - @FXML - abstract public void onFileSaveAs(ActionEvent event); - - @FXML - abstract public void onHelpAbout(ActionEvent event); - // Handler for Button[Button[id=null, styleClass=button]] onAction @FXML abstract public void onImageClonePressed(ActionEvent event); diff --git a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java index 94dcc8ae..14291524 100644 --- a/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java +++ b/OutlawEditor/src/main/java/org/badvision/outlaweditor/ApplicationUIControllerImpl.java @@ -1,6 +1,5 @@ package org.badvision.outlaweditor; -import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -16,16 +15,11 @@ import javafx.scene.control.TextField; import javafx.scene.control.cell.ComboBoxListCell; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; -import javafx.scene.input.ClipboardContent; import javafx.scene.input.DataFormat; -import javafx.scene.input.Dragboard; -import javafx.scene.input.MouseEvent; -import javafx.scene.input.TransferMode; import javafx.util.Callback; import static org.badvision.outlaweditor.Application.currentPlatform; import static org.badvision.outlaweditor.Application.gameData; import static org.badvision.outlaweditor.UIAction.*; -import org.badvision.outlaweditor.apple.AppleTileRenderer; import static org.badvision.outlaweditor.data.PropertyHelper.*; import org.badvision.outlaweditor.data.TileUtils; import org.badvision.outlaweditor.data.TilesetUtils; @@ -258,116 +252,6 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { setCurrentTile(tileSelector.getSelectionModel().getSelectedItem()); } - @Override - public void onChangePlatformAppleSolid(ActionEvent event) { - AppleTileRenderer.useSolidPalette = true; - Application.currentPlatform = Platform.AppleII; - platformChange(); - } - - @Override - public void onChangePlatformAppleText(ActionEvent event) { - AppleTileRenderer.useSolidPalette = false; - Application.currentPlatform = Platform.AppleII; - platformChange(); - } - - @Override - public void onChangePlatformAppleDHGRSolid(ActionEvent event) { - AppleTileRenderer.useSolidPalette = true; - Application.currentPlatform = Platform.AppleII_DHGR; - platformChange(); - } - - @Override - public void onChangePlatformAppleDHGRText(ActionEvent event) { - AppleTileRenderer.useSolidPalette = false; - Application.currentPlatform = Platform.AppleII_DHGR; - platformChange(); - } - - private void platformChange() { - for (Tile t : Application.gameData.getTile()) { - TileUtils.redrawTile(t); - } - Tile tile = currentTile; - rebuildTileSelectors(); - setCurrentTile(tile); - if (currentMapEditor != null) { - currentMapEditor.redraw(); - } - rebuildImageSelector(); - } - - @Override - public void onChangePlatformC64(ActionEvent event) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void onEditCopy(ActionEvent event) { - if (getVisibleEditor() != null) { - getVisibleEditor().copy(); - } - } - - @Override - public void onEditPaste(ActionEvent event) { - if (getVisibleEditor() != null) { - getVisibleEditor().paste(); - } - } - - @Override - public void onEditSelect(ActionEvent event) { - if (getVisibleEditor() != null) { - getVisibleEditor().select(); - } - } - - @Override - public void onFileOpen(ActionEvent event) { - try { - UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Load); - rebuildImageSelector(); - rebuildMapSelectors(); - rebuildTileSelectors(); - } catch (IOException ex) { - Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @Override - public void onFileQuit(ActionEvent event) { - UIAction.quit(); - } - - @Override - public void onFileSave(ActionEvent event) { - if (currentMapEditor != null) { - currentMapEditor.currentMap.updateBackingMap(); - } - try { - UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Save); - } catch (IOException ex) { - Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @Override - public void onFileSaveAs(ActionEvent event) { - try { - UIAction.actionPerformed(UIAction.MAIN_ACTIONS.Save_as); - } catch (IOException ex) { - Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex); - } - } - - @Override - public void onHelpAbout(ActionEvent event) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - @Override public void onImageClonePressed(ActionEvent event) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. @@ -622,10 +506,12 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { currentTileEditor = editor; } + @Override public Tile getCurrentTile() { return currentTile; } + @Override public void setCurrentTile(Tile t) { tileSelector.getSelectionModel().select(t); if (t != null && t.equals(currentTile)) { @@ -669,6 +555,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { currentTile = t; } + @Override public void rebuildTileSelectors() { tileSelector.getItems().clear(); tileSelector.getItems().addAll(Application.gameData.getTile()); @@ -739,6 +626,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { redrawMapScripts(); } + @Override public void rebuildMapSelectors() { mapSelect.getItems().clear(); mapSelect.getItems().addAll(Application.gameData.getMap()); @@ -797,13 +685,19 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { return currentImage; } - private void rebuildImageSelector() { + @Override + public void rebuildImageSelector() { Image i = getCurrentImage(); imageSelector.getItems().clear(); imageSelector.getItems().addAll(Application.gameData.getImage()); imageSelector.getSelectionModel().select(i); } + @Override + public MapEditor getCurrentMapEditor() { + return currentMapEditor; + } + public static enum TABS { image, map, tile @@ -825,6 +719,7 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { currentTab = TABS.tile; } + @Override public Editor getVisibleEditor() { switch (currentTab) { case image: @@ -867,7 +762,11 @@ public class ApplicationUIControllerImpl extends ApplicationUIController { if (currentMap == null) { mapScriptsList.getItems().clear(); } else { - mapScriptsList.getItems().setAll(currentMap.getScripts().getScript()); + if (mapScriptsList.getItems() != null && currentMap.getScripts() != null) { + mapScriptsList.getItems().setAll(currentMap.getScripts().getScript()); + } else { + mapScriptsList.getItems().clear(); + } } } diff --git a/OutlawEditor/src/main/resources/ApplicationUI.fxml b/OutlawEditor/src/main/resources/ApplicationUI.fxml index 59f6d009..1e650396 100644 --- a/OutlawEditor/src/main/resources/ApplicationUI.fxml +++ b/OutlawEditor/src/main/resources/ApplicationUI.fxml @@ -6,43 +6,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/OutlawEditor/src/main/resources/Menubar.fxml b/OutlawEditor/src/main/resources/Menubar.fxml new file mode 100644 index 00000000..eb3526c5 --- /dev/null +++ b/OutlawEditor/src/main/resources/Menubar.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file