Broke menu bar out into its own FXML and controller, just a trial for the next big step.

This commit is contained in:
Brendan Robert 2014-05-10 00:17:29 -05:00
parent e145308853
commit 101ca8c87c
6 changed files with 263 additions and 191 deletions

View File

@ -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);
}

View File

@ -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.
}
}

View File

@ -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);

View File

@ -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();
}
}
}

View File

@ -6,43 +6,11 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="575.0" prefWidth="1000.0" styleClass="mainFxmlClass" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ApplicationUIControllerImpl">
<AnchorPane id="AnchorPane" prefHeight="575.0" prefWidth="1000.0" styleClass="outlawApp" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ApplicationUIControllerImpl">
<children>
<VBox prefHeight="500.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#onFileOpen" text="Open" />
<MenuItem mnemonicParsing="false" onAction="#onFileSave" text="Save" />
<MenuItem mnemonicParsing="false" onAction="#onFileSaveAs" text="Save As..." />
<MenuItem mnemonicParsing="false" onAction="#onFileQuit" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" onAction="#onEditSelect" text="Select" />
<MenuItem mnemonicParsing="false" onAction="#onEditCopy" text="Copy" />
<MenuItem mnemonicParsing="false" onAction="#onEditPaste" text="Paste" />
<Menu mnemonicParsing="false" text="Change Platform">
<items>
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleSolid" text="Apple (solid)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleText" text="Apple (text-friendly)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleDHGRSolid" text="Apple (DHGR solid)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleDHGRText" text="Apple (DHGR text)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformC64" text="C64" />
</items>
</Menu>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#onHelpAbout" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<fx:include source="Menubar.fxml"/>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="455.0" prefWidth="676.9998779296875" tabClosingPolicy="UNAVAILABLE" VBox.vgrow="ALWAYS">
<tabs>
<Tab onSelectionChanged="#tileTabActivated" text="Tiles">

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<MenuBar styleClass="menu" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ApplicationMenuControllerImpl">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" onAction="#onFileOpen" text="Open" />
<MenuItem mnemonicParsing="false" onAction="#onFileSave" text="Save" />
<MenuItem mnemonicParsing="false" onAction="#onFileSaveAs" text="Save As..." />
<MenuItem mnemonicParsing="false" onAction="#onFileQuit" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" onAction="#onEditSelect" text="Select" />
<MenuItem mnemonicParsing="false" onAction="#onEditCopy" text="Copy" />
<MenuItem mnemonicParsing="false" onAction="#onEditPaste" text="Paste" />
<Menu mnemonicParsing="false" text="Change Platform">
<items>
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleSolid" text="Apple (solid)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleText" text="Apple (text-friendly)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleDHGRSolid" text="Apple (DHGR solid)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformAppleDHGRText" text="Apple (DHGR text)" />
<MenuItem mnemonicParsing="false" onAction="#onChangePlatformC64" text="C64" />
</items>
</Menu>
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#onHelpAbout" text="About" />
</items>
</Menu>
</menus>
</MenuBar>