Application state is now an OSGi concern and SCR has been fully integrated to simplify plugin registration

This commit is contained in:
Brendan Robert 2016-07-03 01:00:44 -05:00
parent bb0a9339fe
commit 18ed359af0
25 changed files with 447 additions and 205 deletions

View File

@ -7,10 +7,12 @@
<version>0.1</version>
<packaging>bundle</packaging>
<name>OutlawPluginExample OSGi Bundle</name>
<name>Outlaw Plugin Example</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
@ -22,24 +24,36 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>org.osgi.framework,org.badvision.outlaweditor.api,org.badvision.outlaweditor.data,org.badvision.outlaweditor.data.xml,org.badvision.outlaweditor.ui</Import-Package>
<Export-Package>org.badvision.outlaw.plugin.example.*</Export-Package>
<Export-Package>org.badvision.outlaw.plugin.example</Export-Package>
<Bundle-Activator>org.badvision.outlaw.plugin.example.Activator</Bundle-Activator>
<Export-Service>*</Export-Service>
</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>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.4.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.badvision</groupId>
<artifactId>OutlawEditor</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
@ -48,5 +62,10 @@
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.main</artifactId>
<version>5.4.0</version>
</dependency>
</dependencies>
</project>

View File

@ -1,33 +1,47 @@
package org.badvision.outlaw.plugin.example;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.badvision.outlaweditor.api.ApplicationState;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
/**
*
* This is an example activator class, provided to demonstrate basic bundle lifecycle events.
* Since we're using declarative servies (Felix SCR), all the messy bits of service registration
* and reference passing are managed for us. Otherwise we'd be doing that here. Fortunately,
* we don't have to do all that.
*
* Still, this is a useful mechanism if you have some one-time setup or shutdown concerns that apply
* to your whole bundle, such as reading configuration data from a file or whatever.
*
* @author blurry
*/
public class Activator implements BundleActivator {
@Override
public void start(BundleContext bc) throws Exception {
System.out.println("Hello, world!");
ApplicationState app = bc.getService(bc.getServiceReference(ApplicationState.class));
System.out.println("Hello, plugin!");
checkReferences();
}
@Override
public void stop(BundleContext bc) throws Exception {
System.out.println("Goodbye, plugin!");
}
private void checkReferences() {
// Note that our activator is not a component, so we can't use the @Reference
// annotation to inject app automatically. ApplicationState has a convenience
// method to get around this in just such events, but it's a hack.
// Ultimately it's not a good idea to rely on this too much as it follows
// some bad practices behind the scene that leave unclosed references, etc.
// I'll have to come up with a safer way to inject dependencies without
// causing housekeeping issues for OSGi.
ApplicationState app = ApplicationState.getInstance();
if (app == null) {
System.out.println("App is null?!?!");
} else if (app.getCurrentPlatform() == null) {
System.out.println("Current platform is null?");
} else {
if (app.getCurrentPlatform() == null) {
System.out.println("Current platform is null?");
} else {
System.out.println("Current platform is "+app.getCurrentPlatform());
}
}
System.out.println("Current platform is " + app.getCurrentPlatform());
}
}
public void stop(BundleContext bc) throws Exception {
}
}

View File

@ -0,0 +1,65 @@
package org.badvision.outlaw.plugin.example;
import javafx.event.ActionEvent;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.MenuAction;
import org.osgi.framework.BundleContext;
/**
* This
* @author blurry
*/
@Component(immediate = true)
@Service(MenuAction.class)
public class ExamplePlugin implements MenuAction {
// Note: Because ApplicationState is already a defined service, this will automatically be bound.
// Hence, it is not necessary to worry about passing it it.
@Reference
ApplicationState app;
// This is called when our plugin is starting
@Activate
public void activate() throws Exception {
System.out.println("Hello, menu!");
checkReferences();
}
// This is called when our plugin is stopping
@Deactivate
public void stop(BundleContext bc) throws Exception {
System.out.println("Goodbye, menu!");
}
// This identifies the menu item label
@Override
public String getName() {
return "Example action";
}
// This method is called when the user selects the menu item
@Override
public void handle(ActionEvent event) {
System.out.println("Clicked!");
checkReferences();
}
private void checkReferences() {
// app = ApplicationState.getInstance();
if (app == null) {
System.out.println("App is null?!?!");
} else {
if (app.getCurrentPlatform() == null) {
System.out.println("Current platform is null?");
} else {
System.out.println("Current platform is "+app.getCurrentPlatform());
}
}
}
}

View File

@ -9,6 +9,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>org.badvision.outlaweditor.Application</mainClass>
<!--<mainClass>org.apache.felix.main.Main</mainClass>-->
<netbeans.hint.license>apache20</netbeans.hint.license>
</properties>
@ -23,6 +24,19 @@
<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>org.apache.felix</groupId>
@ -158,15 +172,15 @@
<artifactId>org.apache.felix.main</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
</project>

View File

@ -11,71 +11,98 @@ package org.badvision.outlaweditor;
import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.main.AutoProcessor;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.impl.Activator;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.MenuAction;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.data.xml.GameData;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.launch.Framework;
import org.osgi.util.tracker.ServiceTracker;
/**
*
* @author brobert
*/
@Component(name = "org.badvision.outlaweditor.api.ApplicationState")
public class Application extends javafx.application.Application implements ApplicationState {
@Component
@Service(org.badvision.outlaweditor.api.ApplicationState.class)
public class Application extends javafx.application.Application implements ApplicationState, BundleActivator {
public static GameData gameData = new GameData();
public static Platform currentPlatform = Platform.AppleII;
static Application instance;
public static Application getInstance() {
return instance;
}
public static Framework felix;
private GameData gameData = new GameData();
private Platform currentPlatform = Platform.AppleII;
private ApplicationUIController controller;
private Stage primaryStage;
public static void shutdown() {
try {
instance.pluginContainer.stop();
instance.pluginContainer.waitForStop(0L);
felix.stop();
felix.waitForStop(0L);
} catch (BundleException | InterruptedException ex) {
Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
}
}
private ApplicationUIController controller;
private Felix pluginContainer;
@Override
public GameData getGameData() {
return gameData;
}
@Override
public ApplicationUIController getApplicationUI() {
return controller;
}
@Override
public Platform getCurrentPlatform() {
return currentPlatform;
}
@Override
public void setGameData(GameData newData) {
gameData = newData;
}
@Override
public void setCurrentPlatform(Platform newPlatform) {
currentPlatform = newPlatform;
}
@Override
public ApplicationUIController getController() {
return controller;
}
public Stage primaryStage;
public static Stage getPrimaryStage() {
return instance.primaryStage;
@Override
public Stage getPrimaryStage() {
return primaryStage;
}
@Override
public void start(Stage primaryStage) {
instance = this;
this.primaryStage = primaryStage;
javafx.application.Platform.setImplicitExit(true);
try {
startPluginContainer();
} catch (BundleException ex) {
} catch (Exception ex) {
Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}
@ -96,7 +123,6 @@ public class Application extends javafx.application.Application implements Appli
});
primaryStage.show();
}
Canvas tilePreview;
/**
* The main() method is ignored in correctly deployed JavaFX application.
@ -110,35 +136,36 @@ public class Application extends javafx.application.Application implements Appli
launch(args);
}
private void startPluginContainer() throws BundleException {
Map<String, String> pluginConfiguration = new HashMap<>();
pluginConfiguration.put("felix.cache.locking", "false");
pluginConfiguration.put("felix.auto.deploy.action", "install,start");
pluginConfiguration.put("felix.auto.deploy.dir", "install");
pluginConfiguration.put("org.osgi.framework.system.packages.extra",
"org.badvision.outlaweditor.api,"
+ "org.badvision.outlaweditor.data,"
+ "org.badvision.outlaweditor.data.xml,"
+ "org.badvision.outlaweditor.ui,"
+ "org.osgi.framework");
pluginContainer = new Felix(pluginConfiguration);
pluginContainer.start();
pluginContainer.getBundleContext().registerService(ApplicationState.class, this, new Hashtable<>());
AutoProcessor.process(pluginConfiguration, pluginContainer.getBundleContext());
ServiceTracker tracker;
private void startPluginContainer() throws BundleException, Exception {
Map<String, String> config = new HashMap<>();
config.put(FelixConstants.ACTIVATION_LAZY, "false");
config.put("felix.cache.locking", "false");
config.put("felix.auto.deploy.dir", "install");
config.put("felix.auto.deploy.action", "install,start");
config.put("org.osgi.framework.system.packages.extra",
"javafx.event,"
+ "org.badvision.outlaweditor.api,"
+ "org.badvision.outlaweditor.data,"
+ "org.badvision.outlaweditor.data.xml,"
+ "org.badvision.outlaweditor.ui,"
+ "org.osgi.framework");
felix = new Felix(config);
felix.start();
felix.getBundleContext().registerService(ApplicationState.class, this, null);
tracker = new ServiceTracker(felix.getBundleContext(), MenuAction.class, null);
tracker.open();
Activator scrActivator = new Activator();
scrActivator.start(felix.getBundleContext());
AutoProcessor.process(config, felix.getBundleContext());
}
@Override
public void start(BundleContext bc) throws Exception {
launch();
}
@Override
public GameData getGameData() {
return gameData;
}
@Override
public ApplicationUIController getApplicationUI() {
return controller;
}
@Override
public Platform getCurrentPlatform() {
return currentPlatform;
public void stop(BundleContext bc) throws Exception {
}
}

View File

@ -24,6 +24,7 @@ import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import javafx.stage.FileChooser;
import org.badvision.outlaweditor.api.ApplicationState;
/**
*
@ -67,7 +68,7 @@ public class FileUtils {
f.getExtensionFilters().add(e.getExtensionFilter());
}
if (create) {
File file = f.showSaveDialog(Application.getPrimaryStage());
File file = f.showSaveDialog(ApplicationState.getInstance().getPrimaryStage());
if (file == null) {
return null;
}
@ -77,7 +78,7 @@ public class FileUtils {
return file;
}
} else {
return f.showOpenDialog(Application.getPrimaryStage());
return f.showOpenDialog(ApplicationState.getInstance().getPrimaryStage());
}
}

View File

@ -11,6 +11,8 @@
package org.badvision.outlaweditor;
import javafx.scene.layout.Pane;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.GameData;
import org.badvision.outlaweditor.data.xml.Global;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Scripts;
@ -19,17 +21,18 @@ public class GlobalEditor extends Editor<Global, Void>{
@Override
public void addScript(Script script) {
Scripts scripts = Application.gameData.getGlobal().getScripts();
GameData gameData = getGameData();
Scripts scripts = gameData.getGlobal().getScripts();
if (scripts == null) {
Application.gameData.getGlobal().setScripts(new Scripts());
scripts = Application.gameData.getGlobal().getScripts();
gameData.getGlobal().setScripts(new Scripts());
scripts = gameData.getGlobal().getScripts();
}
scripts.getScript().add(script);
}
public void removeScript(Script script) {
Scripts scripts = Application.gameData.getGlobal().getScripts();
Scripts scripts = getGameData().getGlobal().getScripts();
scripts.getScript().remove(script);
}
@ -82,5 +85,9 @@ public class GlobalEditor extends Editor<Global, Void>{
public void observedObjectChanged(Global object) {
throw new UnsupportedOperationException("Not supported."); //To change body of generated methods, choose Tools | Templates.
}
private GameData getGameData() {
return ApplicationState.getInstance().getGameData();
}
}

View File

@ -9,7 +9,6 @@
*/
package org.badvision.outlaweditor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -43,7 +42,7 @@ import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.xml.Map;
@ -67,8 +66,8 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
double zoom = 1.0;
DrawMode drawMode = DrawMode.Pencil1px;
TileMap currentMap;
double tileWidth = currentPlatform.tileRenderer.getWidth() * zoom;
double tileHeight = currentPlatform.tileRenderer.getHeight() * zoom;
double tileWidth = getCurrentPlatform().tileRenderer.getWidth() * zoom;
double tileHeight = getCurrentPlatform().tileRenderer.getHeight() * zoom;
@Override
protected void onEntityUpdated() {
@ -115,7 +114,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
@Override
public void buildEditorUI(Pane tileEditorAnchorPane) {
anchorPane = tileEditorAnchorPane;
Application.getPrimaryStage().getScene().addEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
ApplicationState.getInstance().getPrimaryStage().getScene().addEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
initCanvas();
redraw();
}
@ -127,7 +126,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
if (currentTile != null) {
category = currentTile.getCategory();
}
if (this.equals(Application.getInstance().getController().getVisibleEditor())) {
if (this.equals(ApplicationState.getInstance().getController().getVisibleEditor())) {
UIAction.showTileSelectModal(anchorPane, category, this::setCurrentTile);
}
}
@ -138,8 +137,8 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
anchorPane.getChildren().remove(drawCanvas);
}
drawCanvas = new Canvas();
drawCanvas.heightProperty().bind(Application.getPrimaryStage().heightProperty().subtract(120));
drawCanvas.widthProperty().bind(Application.getPrimaryStage().widthProperty().subtract(200));
drawCanvas.heightProperty().bind(ApplicationState.getInstance().getPrimaryStage().heightProperty().subtract(120));
drawCanvas.widthProperty().bind(ApplicationState.getInstance().getPrimaryStage().widthProperty().subtract(200));
// drawCanvas.widthProperty().bind(anchorPane.widthProperty());
drawCanvas.widthProperty().addListener((ObservableValue<? extends Number> ov, Number t, Number t1) -> {
redraw();
@ -226,8 +225,8 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
//
// double newLeft = (left + pointerX) * ratio - pointerX;
// double newTop = (top + pointerY) * ratio - pointerY;
tileWidth = currentPlatform.tileRenderer.getWidth() * zoom;
tileHeight = currentPlatform.tileRenderer.getHeight() * zoom;
tileWidth = getCurrentPlatform().tileRenderer.getWidth() * zoom;
tileHeight = getCurrentPlatform().tileRenderer.getHeight() * zoom;
redraw();
}
@ -300,7 +299,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
double xx = x * tileWidth;
double yy = y * tileHeight;
if (tile != null) {
drawCanvas.getGraphicsContext2D().drawImage(TileUtils.getImage(tile, currentPlatform), xx, yy, tileWidth, tileHeight);
drawCanvas.getGraphicsContext2D().drawImage(TileUtils.getImage(tile, getCurrentPlatform()), xx, yy, tileWidth, tileHeight);
}
}
@ -398,7 +397,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
drawCanvas.heightProperty().unbind();
anchorPane.getChildren().remove(drawCanvas);
currentMap.updateBackingMap();
Application.getPrimaryStage().getScene().removeEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
ApplicationState.getInstance().getPrimaryStage().getScene().removeEventHandler(KeyEvent.KEY_PRESSED, this::keyPressed);
}
/**
@ -417,14 +416,14 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
drawMode = DrawMode.Pencil1px;
}
this.currentTile = currentTile;
ImageCursor cursor = new ImageCursor(TileUtils.getImage(currentTile, currentPlatform), 2, 2);
ImageCursor cursor = new ImageCursor(TileUtils.getImage(currentTile, getCurrentPlatform()), 2, 2);
drawCanvas.setCursor(cursor);
return currentTile;
}
public void showPreview() {
byte[] data = currentPlatform.imageRenderer.renderPreview(currentMap, posX, posY, currentPlatform.maxImageWidth, currentPlatform.maxImageHeight);
WritableImage img = currentPlatform.imageRenderer.renderImage(null, data, currentPlatform.maxImageWidth, currentPlatform.maxImageHeight);
byte[] data = getCurrentPlatform().imageRenderer.renderPreview(currentMap, posX, posY, getCurrentPlatform().maxImageWidth, getCurrentPlatform().maxImageHeight);
WritableImage img = getCurrentPlatform().imageRenderer.renderImage(null, data, getCurrentPlatform().maxImageWidth, getCurrentPlatform().maxImageHeight);
Stage stage = new Stage();
stage.setTitle("Preview");
ImageView imgView = new ImageView(img);
@ -435,12 +434,12 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
@Override
public void copy() {
byte[] data = currentPlatform.imageRenderer.renderPreview(currentMap, posX, posY, currentPlatform.maxImageWidth, currentPlatform.maxImageHeight);
WritableImage img = currentPlatform.imageRenderer.renderImage(null, data, currentPlatform.maxImageWidth, currentPlatform.maxImageHeight);
byte[] data = getCurrentPlatform().imageRenderer.renderPreview(currentMap, posX, posY, getCurrentPlatform().maxImageWidth, getCurrentPlatform().maxImageHeight);
WritableImage img = getCurrentPlatform().imageRenderer.renderImage(null, data, getCurrentPlatform().maxImageWidth, getCurrentPlatform().maxImageHeight);
java.util.Map<DataFormat, Object> clip = new HashMap<>();
clip.put(DataFormat.IMAGE, img);
if (drawMode != DrawMode.Select || startX >= 0) {
clip.put(DataFormat.PLAIN_TEXT, "selection/map/" + Application.gameData.getMap().indexOf(getEntity()) + "/" + getSelectionInfo());
clip.put(DataFormat.PLAIN_TEXT, "selection/map/" + ApplicationState.getInstance().getGameData().getMap().indexOf(getEntity()) + "/" + getSelectionInfo());
}
Clipboard.getSystemClipboard().setContent(clip);
clearSelection();
@ -460,7 +459,7 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
java.util.Map<String, Integer> selection = TransferHelper.getSelectionDetails(clipboardInfo);
if (selection.containsKey("map")) {
trackState();
Map sourceMap = Application.gameData.getMap().get(selection.get("map"));
Map sourceMap = ApplicationState.getInstance().getGameData().getMap().get(selection.get("map"));
TileMap source = getCurrentMap();
if (!sourceMap.equals(getCurrentMap().getBackingMap())) {
source = new TileMap(sourceMap);
@ -507,6 +506,10 @@ public class MapEditor extends Editor<Map, MapEditor.DrawMode> implements EventH
redraw();
}
private org.badvision.outlaweditor.api.Platform getCurrentPlatform() {
return ApplicationState.getInstance().getCurrentPlatform();
}
public static enum DrawMode {
Pencil1px, Pencil3px, Pencil5px, FilledRect, Eraser(false), Select(false);

View File

@ -35,6 +35,7 @@ import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.Block;
import org.badvision.outlaweditor.data.xml.Global;
import org.badvision.outlaweditor.data.xml.Mutation;
@ -192,7 +193,7 @@ public class MythosEditor {
}
public static Scope getGlobalScope() {
return Application.gameData.getGlobal();
return ApplicationState.getInstance().getGameData().getGlobal();
}
private boolean isGlobalScope() {

View File

@ -15,16 +15,43 @@
*/
package org.badvision.outlaweditor.api;
import javafx.stage.Stage;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.data.xml.GameData;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
/**
*
*
* @author blurry
*/
public interface ApplicationState {
public GameData getGameData();
public void setGameData(GameData newData);
public ApplicationUIController getApplicationUI();
public Platform getCurrentPlatform();
public void setCurrentPlatform(Platform p);
public ApplicationUIController getController();
public Stage getPrimaryStage();
static public BundleContext getBundleContext() {
if (Application.felix != null) {
return Application.felix.getBundleContext();
} else {
return FrameworkUtil.getBundle(ApplicationState.class).getBundleContext();
}
}
public static ApplicationState getInstance() {
BundleContext bc = getBundleContext();
return bc.getService(bc.getServiceReference(ApplicationState.class));
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright 2016 org.badvision.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.badvision.outlaweditor.api;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
/**
* Any ser
* @author blurry
*/
public interface MenuAction extends EventHandler<ActionEvent> {
public String getName();
default public String getDescription() {
return getName();
}
}

View File

@ -28,11 +28,11 @@ import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.FileUtils;
import org.badvision.outlaweditor.ImageEditor;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.data.TileMap;
import org.badvision.outlaweditor.data.xml.Image;
import org.badvision.outlaweditor.data.xml.PlatformData;
@ -435,7 +435,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
public void copy() {
java.util.Map<DataFormat, Object> clip = new HashMap<>();
clip.put(DataFormat.IMAGE, currentImage);
clip.put(DataFormat.PLAIN_TEXT, "selection/image/" + Application.gameData.getImage().indexOf(getEntity()) + "/" + getSelectionInfo());
clip.put(DataFormat.PLAIN_TEXT, "selection/image/" + ApplicationState.getInstance().getGameData().getImage().indexOf(getEntity()) + "/" + getSelectionInfo());
Clipboard.getSystemClipboard().setContent(clip);
copyData = Arrays.copyOf(getImageData(), getImageData().length);
}
@ -460,7 +460,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
System.out.println("Clipboard >> " + contentPath);
Map<String, Integer> selection = TransferHelper.getSelectionDetails(contentPath);
if (selection.containsKey("map")) {
TileMap map = new TileMap(Application.gameData.getMap().get(selection.get("map")));
TileMap map = new TileMap(ApplicationState.getInstance().getGameData().getMap().get(selection.get("map")));
byte[] buf = getPlatform().imageRenderer.renderPreview(
map,
selection.get("x1"),
@ -471,7 +471,7 @@ public class AppleImageEditor extends ImageEditor implements EventHandler<MouseE
redraw();
return true;
} else if (selection.containsKey("image")) {
Image sourceImage = Application.gameData.getImage().get(selection.get("image"));
Image sourceImage = ApplicationState.getInstance().getGameData().getImage().get(selection.get("image"));
byte[] sourceData;
if (sourceImage.equals(getEntity())) {
sourceData = copyData;

View File

@ -15,7 +15,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.Field;
import org.badvision.outlaweditor.data.xml.Global;
import org.badvision.outlaweditor.data.xml.Map;
@ -28,8 +28,8 @@ public class DataUtilities {
}
public static void ensureGlobalExists() {
if (Application.gameData.getGlobal() == null) {
Application.gameData.setGlobal(new Global());
if (ApplicationState.getInstance().getGameData().getGlobal() == null) {
ApplicationState.getInstance().getGameData().setGlobal(new Global());
}
}
@ -101,8 +101,8 @@ public class DataUtilities {
}
public static void cleanupAllScriptNames() {
cleanupScriptNames(Application.gameData.getGlobal());
Application.gameData.getMap().forEach(DataUtilities::cleanupScriptNames);
cleanupScriptNames(ApplicationState.getInstance().getGameData().getGlobal());
ApplicationState.getInstance().getGameData().getMap().forEach(DataUtilities::cleanupScriptNames);
}
//------------------------------ String comparators

View File

@ -22,6 +22,7 @@ import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javax.xml.bind.JAXBElement;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.data.xml.Map;
import org.badvision.outlaweditor.data.xml.Map.Chunk;
@ -89,7 +90,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
});
}
locationScripts.remove(loc);
Application.getInstance().getController().redrawScripts();
ApplicationState.getInstance().getController().redrawScripts();
}
private void registerLocationScript(int x, int y, Script s) {
@ -104,7 +105,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
locationScripts.put(loc, list);
}
list.add(s);
Application.getInstance().getController().redrawScripts();
ApplicationState.getInstance().getController().redrawScripts();
}
private int getMortonNumber(int x, int y) {
@ -195,7 +196,7 @@ public class TileMap extends ArrayList<ArrayList<Tile>> implements Serializable
if (t == null) {
t = new Tile();
unknownTiles.add(t);
Platform p = Application.currentPlatform;
Platform p = ApplicationState.getInstance().getCurrentPlatform();
WritableImage img = UIAction.getBadImage(p.tileRenderer.getWidth(), p.tileRenderer.getHeight());
TileUtils.setImage(t, p, img);
}

View File

@ -13,7 +13,7 @@ package org.badvision.outlaweditor.data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.xml.Tile;
/**
@ -27,18 +27,18 @@ public class TilesetUtils implements Serializable {
}
public static boolean add(Tile e) {
boolean output = Application.gameData.getTile().add(e);
boolean output = ApplicationState.getInstance().getGameData().getTile().add(e);
DataProducer.notifyObservers(TilesetUtils.class);
return output;
}
public static void clear() {
Application.gameData.getTile().clear();
ApplicationState.getInstance().getGameData().getTile().clear();
DataProducer.notifyObservers(TilesetUtils.class);
}
public static void remove(Tile t) {
Application.gameData.getTile().remove(t);
ApplicationState.getInstance().getGameData().getTile().remove(t);
DataProducer.notifyObservers(TilesetUtils.class);
}
// The tileset should have been a map in retrospect but now it has to
@ -48,7 +48,7 @@ public class TilesetUtils implements Serializable {
public static Tile getTileById(String tileId) {
if (lookup == null || (lookup.get(tileId) == null && !lookup.containsKey(tileId))) {
lookup = new HashMap<>();
for (Tile t : Application.gameData.getTile()) {
for (Tile t : ApplicationState.getInstance().getGameData().getTile()) {
lookup.put(TileUtils.getId(t), t);
}
if (lookup.get(tileId) == null) {
@ -57,4 +57,7 @@ public class TilesetUtils implements Serializable {
}
return lookup.get(tileId);
}
private TilesetUtils() {
}
}

View File

@ -12,6 +12,7 @@ package org.badvision.outlaweditor.ui;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Menu;
/**
*
@ -19,6 +20,9 @@ import javafx.fxml.FXML;
*/
public abstract class ApplicationMenuController {
@FXML
protected Menu extraMenu;
@FXML
abstract public void onChangePlatformAppleDHGRSolid(ActionEvent event);
@ -60,5 +64,6 @@ public abstract class ApplicationMenuController {
@FXML
abstract public void performUndo(ActionEvent event);
abstract public void initalize();
}

View File

@ -14,13 +14,13 @@ import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.Event;
import javafx.fxml.FXML;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.Editor;
import org.badvision.outlaweditor.api.ApplicationState;
public abstract class ApplicationUIController {
public static ApplicationUIController getController() {
return Application.getInstance().getController();
return ApplicationState.getInstance().getController();
}
abstract public void rebuildTileSelectors();

View File

@ -62,10 +62,10 @@ import javafx.util.Duration;
import javafx.util.converter.DefaultStringConverter;
import javax.xml.bind.JAXB;
import org.badvision.outlaweditor.Application;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.FileUtils;
import org.badvision.outlaweditor.MythosEditor;
import org.badvision.outlaweditor.SheetEditor;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.apple.ImageDitherEngine;
import org.badvision.outlaweditor.data.DataUtilities;
import org.badvision.outlaweditor.data.TileUtils;
@ -131,7 +131,7 @@ public class UIAction {
GameData newData = JAXB.unmarshal(currentSaveFile, GameData.class);
ApplicationUIController.getController().clearData();
TilesetUtils.clear();
Application.gameData = newData;
ApplicationState.getInstance().setGameData(newData);
DataUtilities.ensureGlobalExists();
DataUtilities.cleanupAllScriptNames();
ApplicationUIController.getController().updateSelectors();
@ -151,7 +151,7 @@ public class UIAction {
}
if (currentSaveFile != null) {
currentSaveFile.delete();
JAXB.marshal(Application.gameData, currentSaveFile);
JAXB.marshal(ApplicationState.getInstance().getGameData(), currentSaveFile);
}
break;
}
@ -299,10 +299,10 @@ public class UIAction {
public static void createAndEditUserType() throws IntrospectionException {
UserType type = new UserType();
if (editAndGetUserType(type).isPresent()) {
if (Application.gameData.getGlobal().getUserTypes() == null) {
Application.gameData.getGlobal().setUserTypes(new Global.UserTypes());
if (ApplicationState.getInstance().getGameData().getGlobal().getUserTypes() == null) {
ApplicationState.getInstance().getGameData().getGlobal().setUserTypes(new Global.UserTypes());
}
Application.gameData.getGlobal().getUserTypes().getUserType().add(type);
ApplicationState.getInstance().getGameData().getGlobal().getUserTypes().getUserType().add(type);
}
}
@ -345,10 +345,10 @@ public class UIAction {
public static Sheet createAndEditSheet() throws IntrospectionException {
Sheet sheet = new Sheet();
sheet.setName("New Sheet");
if (Application.gameData.getGlobal().getSheets() == null) {
Application.gameData.getGlobal().setSheets(new Global.Sheets());
if (ApplicationState.getInstance().getGameData().getGlobal().getSheets() == null) {
ApplicationState.getInstance().getGameData().getGlobal().setSheets(new Global.Sheets());
}
Application.gameData.getGlobal().getSheets().getSheet().add(sheet);
ApplicationState.getInstance().getGameData().getGlobal().getSheets().getSheet().add(sheet);
return editSheet(sheet);
}
@ -392,10 +392,10 @@ public class UIAction {
}
currentTileSelector = new AnchorPane();
int TILE_WIDTH = Application.currentPlatform.tileRenderer.getWidth();
int TILE_HEIGHT = Application.currentPlatform.tileRenderer.getHeight();
int TILE_WIDTH = ApplicationState.getInstance().getCurrentPlatform().tileRenderer.getWidth();
int TILE_HEIGHT = ApplicationState.getInstance().getCurrentPlatform().tileRenderer.getHeight();
List<Tile> tiles = Application.gameData.getTile().stream().filter((Tile t) -> {
List<Tile> tiles = ApplicationState.getInstance().getGameData().getTile().stream().filter((Tile t) -> {
return category == null || t.getCategory().equals(category);
}).collect(Collectors.toList());
@ -406,7 +406,7 @@ public class UIAction {
currentTileSelector.setPrefHeight(Math.min(numRows * (TILE_HEIGHT + GRID_SPACING) + GRID_SPACING, prefWidth));
for (int i = 0; i < tiles.size(); i++) {
final Tile tile = tiles.get(i);
ImageView tileIcon = new ImageView(TileUtils.getImage(tile, currentPlatform));
ImageView tileIcon = new ImageView(TileUtils.getImage(tile, ApplicationState.getInstance().getCurrentPlatform()));
currentTileSelector.getChildren().add(tileIcon);
tileIcon.setOnMouseClicked((e) -> {
e.consume();
@ -442,8 +442,8 @@ public class UIAction {
null)));
currentTileSelector.setEffect(new DropShadow(5.0, 1.0, 1.0, Color.BLACK));
anchorPane.getChildren().add(currentTileSelector);
Application.getPrimaryStage().getScene().addEventHandler(KeyEvent.KEY_PRESSED, cancelTileSelectKeyHandler);
Application.getPrimaryStage().getScene().addEventFilter(MouseEvent.MOUSE_PRESSED, cancelTileSelectMouseHandler);
ApplicationState.getInstance().getPrimaryStage().getScene().addEventHandler(KeyEvent.KEY_PRESSED, cancelTileSelectKeyHandler);
ApplicationState.getInstance().getPrimaryStage().getScene().addEventFilter(MouseEvent.MOUSE_PRESSED, cancelTileSelectMouseHandler);
}
private static final EventHandler<MouseEvent> cancelTileSelectMouseHandler = (MouseEvent e) -> {
@ -460,8 +460,8 @@ public class UIAction {
};
public static void closeCurrentTileSelector() {
Application.getPrimaryStage().getScene().removeEventHandler(KeyEvent.KEY_PRESSED, cancelTileSelectKeyHandler);
Application.getPrimaryStage().getScene().removeEventFilter(MouseEvent.MOUSE_PRESSED, cancelTileSelectMouseHandler);
ApplicationState.getInstance().getPrimaryStage().getScene().removeEventHandler(KeyEvent.KEY_PRESSED, cancelTileSelectKeyHandler);
ApplicationState.getInstance().getPrimaryStage().getScene().removeEventFilter(MouseEvent.MOUSE_PRESSED, cancelTileSelectMouseHandler);
fadeOut(currentTileSelector, (ActionEvent ev) -> {
if (currentTileSelector != null) {

View File

@ -14,45 +14,54 @@ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
import javafx.scene.control.MenuItem;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.Editor;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.api.MenuAction;
import org.badvision.outlaweditor.api.Platform;
import org.badvision.outlaweditor.apple.AppleTileRenderer;
import org.badvision.outlaweditor.ui.ApplicationMenuController;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.badvision.outlaweditor.ui.UIAction;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
/**
*
* @author blurry
*/
public class ApplicationMenuControllerImpl extends ApplicationMenuController {
@Override
public void initalize() {
setupPluginMenu();
}
@Override
public void onChangePlatformAppleSolid(ActionEvent event) {
AppleTileRenderer.useSolidPalette = true;
Application.currentPlatform = Platform.AppleII;
ApplicationState.getInstance().setCurrentPlatform(Platform.AppleII);
ApplicationUIController.getController().platformChange();
}
@Override
public void onChangePlatformAppleText(ActionEvent event) {
AppleTileRenderer.useSolidPalette = false;
Application.currentPlatform = Platform.AppleII;
ApplicationState.getInstance().setCurrentPlatform(Platform.AppleII);
ApplicationUIController.getController().platformChange();
}
@Override
public void onChangePlatformAppleDHGRSolid(ActionEvent event) {
AppleTileRenderer.useSolidPalette = true;
Application.currentPlatform = Platform.AppleII_DHGR;
ApplicationState.getInstance().setCurrentPlatform(Platform.AppleII_DHGR);
ApplicationUIController.getController().platformChange();
}
@Override
public void onChangePlatformAppleDHGRText(ActionEvent event) {
AppleTileRenderer.useSolidPalette = false;
Application.currentPlatform = Platform.AppleII_DHGR;
ApplicationState.getInstance().setCurrentPlatform(Platform.AppleII_DHGR);
ApplicationUIController.getController().platformChange();
}
@ -136,4 +145,19 @@ public class ApplicationMenuControllerImpl extends ApplicationMenuController {
}
}
private void setupPluginMenu() {
System.out.println("Setting up extras menu");
BundleContext bc = ApplicationState.getBundleContext();
try {
bc.getServiceReferences(MenuAction.class, null).stream().map(bc::getService).forEach((MenuAction a) -> {
System.out.println("Adding menu item " + a.getName());
MenuItem item = new MenuItem(a.getName());
item.setOnAction(a);
extraMenu.getItems().add(item);
});
} catch (InvalidSyntaxException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@ -12,8 +12,8 @@ package org.badvision.outlaweditor.ui.impl;
import javafx.event.Event;
import javafx.scene.input.DataFormat;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.Editor;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.TilesetUtils;
import org.badvision.outlaweditor.data.xml.Tile;
@ -30,18 +30,19 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
public void initialize() {
super.initialize();
TilesetUtils.addObserver((org.badvision.outlaweditor.data.DataObserver) (Object object) -> {
TilesetUtils.addObserver((Object object) -> {
rebuildTileSelectors();
});
tileController.initalize();
mapController.initalize();
imageController.initalize();
globalController.initialize();
menuController.initalize();
}
@Override
public void platformChange() {
Application.gameData.getTile().stream().forEach((t) -> {
ApplicationState.getInstance().getGameData().getTile().stream().forEach((t) -> {
TileUtils.redrawTile(t);
});
Tile tile = tileController.getCurrentTile();

View File

@ -19,8 +19,8 @@ import javafx.scene.control.Tooltip;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.DataUtilities;
import org.badvision.outlaweditor.data.xml.Script;
import org.badvision.outlaweditor.data.xml.Sheet;
@ -52,7 +52,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void startEdit() {
UIAction.editVariable(getItem(), Application.gameData.getGlobal());
UIAction.editVariable(getItem(), ApplicationState.getInstance().getGameData().getGlobal());
cancelEdit();
updateItem(getItem(), false);
}
@ -71,7 +71,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void startEdit() {
UIAction.editScript(getItem(), Application.gameData.getGlobal());
UIAction.editScript(getItem(), ApplicationState.getInstance().getGameData().getGlobal());
cancelEdit();
updateItem(getItem(), false);
}
@ -124,7 +124,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
protected void onScriptAddPressed(ActionEvent event) {
UIAction.createAndEditScript(Application.gameData.getGlobal());
UIAction.createAndEditScript(ApplicationState.getInstance().getGameData().getGlobal());
}
@Override
@ -153,7 +153,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
Script script = TransferHelper.cloneObject(source, Script.class, "script");
script.setName(source.getName() + " CLONE");
getCurrentEditor().addScript(script);
editScript(script, Application.gameData.getGlobal());
editScript(script, ApplicationState.getInstance().getGameData().getGlobal());
} catch (JAXBException ex) {
Logger.getLogger(MapEditorTabControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
UIAction.alert("Error occured when attempting clone operation:\n" + ex.getMessage());
@ -180,7 +180,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
+ type.getName()
+ "? There is no undo for this!",
() -> {
Application.gameData.getGlobal().getUserTypes().getUserType().remove(type);
ApplicationState.getInstance().getGameData().getGlobal().getUserTypes().getUserType().remove(type);
redrawGlobalDataTypes();
}, null);
}
@ -197,7 +197,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
UserType newType = TransferHelper.cloneObject(source, UserType.class, "userType");
newType.setName(source.getName() + " CLONE");
if (UIAction.editAndGetUserType(newType) != null) {
Application.gameData.getGlobal().getUserTypes().getUserType().add(newType);
ApplicationState.getInstance().getGameData().getGlobal().getUserTypes().getUserType().add(newType);
redrawGlobalDataTypes();
}
} catch (JAXBException ex) {
@ -229,7 +229,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
+ sheet.getName()
+ "? There is no undo for this!",
() -> {
Application.gameData.getGlobal().getSheets().getSheet().remove(sheet);
ApplicationState.getInstance().getGameData().getGlobal().getSheets().getSheet().remove(sheet);
redrawGlobalSheets();
}, null);
}
@ -246,7 +246,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
Sheet sheet = TransferHelper.cloneObject(source, Sheet.class, "sheet");
sheet.setName(source.getName() + " CLONE");
Sheet newVar = UIAction.editSheet(sheet);
Application.gameData.getGlobal().getSheets().getSheet().add(newVar);
ApplicationState.getInstance().getGameData().getGlobal().getSheets().getSheet().add(newVar);
redrawGlobalSheets();
} catch (JAXBException ex) {
Logger.getLogger(GlobalEditorTabControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
@ -258,7 +258,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
protected void onVariableAddPressed(ActionEvent event) {
try {
UIAction.createAndEditVariable(Application.gameData.getGlobal());
UIAction.createAndEditVariable(ApplicationState.getInstance().getGameData().getGlobal());
redrawGlobalVariables();
} catch (IntrospectionException ex) {
Logger.getLogger(GlobalEditorTabControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
@ -274,7 +274,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
+ var.getName()
+ "? There is no undo for this!",
() -> {
Application.gameData.getGlobal().getVariables().getVariable().remove(var);
ApplicationState.getInstance().getGameData().getGlobal().getVariables().getVariable().remove(var);
redrawGlobalVariables();
}, null);
}
@ -292,7 +292,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
variable.setName(source.getName() + " CLONE");
Optional<Variable> newVar = UIAction.editAndGetVariable(variable);
if (newVar.isPresent()) {
Application.gameData.getGlobal().getVariables().getVariable().add(newVar.get());
ApplicationState.getInstance().getGameData().getGlobal().getVariables().getVariable().add(newVar.get());
redrawGlobalVariables();
}
} catch (JAXBException ex) {
@ -307,9 +307,9 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void redrawGlobalScripts() {
DataUtilities.ensureGlobalExists();
if (globalScriptList.getItems() != null && Application.gameData.getGlobal().getScripts() != null) {
DataUtilities.sortNamedEntities(Application.gameData.getGlobal().getScripts().getScript());
globalScriptList.getItems().setAll(Application.gameData.getGlobal().getScripts().getScript());
if (globalScriptList.getItems() != null && ApplicationState.getInstance().getGameData().getGlobal().getScripts() != null) {
DataUtilities.sortNamedEntities(ApplicationState.getInstance().getGameData().getGlobal().getScripts().getScript());
globalScriptList.getItems().setAll(ApplicationState.getInstance().getGameData().getGlobal().getScripts().getScript());
} else {
globalScriptList.getItems().clear();
}
@ -318,9 +318,9 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void redrawGlobalVariables() {
DataUtilities.ensureGlobalExists();
if (variableList.getItems() != null && Application.gameData.getGlobal().getVariables() != null) {
DataUtilities.sortNamedEntities(Application.gameData.getGlobal().getVariables().getVariable());
variableList.getItems().setAll(Application.gameData.getGlobal().getVariables().getVariable());
if (variableList.getItems() != null && ApplicationState.getInstance().getGameData().getGlobal().getVariables() != null) {
DataUtilities.sortNamedEntities(ApplicationState.getInstance().getGameData().getGlobal().getVariables().getVariable());
variableList.getItems().setAll(ApplicationState.getInstance().getGameData().getGlobal().getVariables().getVariable());
} else {
variableList.getItems().clear();
}
@ -329,9 +329,9 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void redrawGlobalDataTypes() {
DataUtilities.ensureGlobalExists();
if (dataTypeList.getItems() != null && Application.gameData.getGlobal().getUserTypes() != null) {
DataUtilities.sortNamedEntities(Application.gameData.getGlobal().getUserTypes().getUserType());
dataTypeList.getItems().setAll(Application.gameData.getGlobal().getUserTypes().getUserType());
if (dataTypeList.getItems() != null && ApplicationState.getInstance().getGameData().getGlobal().getUserTypes() != null) {
DataUtilities.sortNamedEntities(ApplicationState.getInstance().getGameData().getGlobal().getUserTypes().getUserType());
dataTypeList.getItems().setAll(ApplicationState.getInstance().getGameData().getGlobal().getUserTypes().getUserType());
} else {
dataTypeList.getItems().clear();
}
@ -340,9 +340,9 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
@Override
public void redrawGlobalSheets() {
DataUtilities.ensureGlobalExists();
if (sheetList.getItems() != null && Application.gameData.getGlobal().getSheets() != null) {
DataUtilities.sortNamedEntities(Application.gameData.getGlobal().getSheets().getSheet());
sheetList.getItems().setAll(Application.gameData.getGlobal().getSheets().getSheet());
if (sheetList.getItems() != null && ApplicationState.getInstance().getGameData().getGlobal().getSheets() != null) {
DataUtilities.sortNamedEntities(ApplicationState.getInstance().getGameData().getGlobal().getSheets().getSheet());
sheetList.getItems().setAll(ApplicationState.getInstance().getGameData().getGlobal().getSheets().getSheet());
} else {
sheetList.getItems().clear();
}

View File

@ -20,10 +20,10 @@ import javafx.scene.control.ListView;
import javafx.util.StringConverter;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import static org.badvision.outlaweditor.Application.currentPlatform;
import org.badvision.outlaweditor.Editor;
import org.badvision.outlaweditor.ImageEditor;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.api.ApplicationState;
import static org.badvision.outlaweditor.data.PropertyHelper.bind;
import static org.badvision.outlaweditor.data.PropertyHelper.stringProp;
import org.badvision.outlaweditor.data.xml.Image;
@ -149,7 +149,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
}
Image clone = TransferHelper.cloneObject(getCurrentImage(), Image.class, "image");
clone.setName(clone.getName()+" clone");
Application.gameData.getImage().add(clone);
ApplicationState.getInstance().getGameData().getImage().add(clone);
setCurrentImage(clone);
rebuildImageSelector();
} catch (JAXBException ex) {
@ -161,7 +161,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
public void onImageCreatePressed(ActionEvent event) {
Image i = new Image();
i.setName("Untitled");
Application.gameData.getImage().add(i);
ApplicationState.getInstance().getGameData().getImage().add(i);
setCurrentImage(i);
rebuildImageSelector();
}
@ -174,7 +174,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
confirm("Delete image '" + currentImage.getName() + "'. Are you sure?", () -> {
Image del = currentImage;
setCurrentImage(null);
Application.gameData.getImage().remove(del);
ApplicationState.getInstance().getGameData().getImage().remove(del);
rebuildImageSelector();
}, null);
}
@ -231,7 +231,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
try {
currentImageEditor = currentPlatform.imageEditor.newInstance();
currentImageEditor = ApplicationState.getInstance().getCurrentPlatform().imageEditor.newInstance();
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
@ -262,7 +262,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
public void rebuildImageSelector() {
Image i = getCurrentImage();
imageSelector.getItems().clear();
List<Image> allImages = Application.gameData.getImage();
List<Image> allImages = ApplicationState.getInstance().getGameData().getImage();
allImages.sort((Image o1, Image o2) -> {
int c1 = String.valueOf(o1.getCategory()).compareTo(String.valueOf(o2.getCategory()));
if (c1 != 0) {

View File

@ -26,10 +26,9 @@ import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javax.xml.bind.JAXBException;
import org.badvision.outlaweditor.Application;
import static org.badvision.outlaweditor.Application.currentPlatform;
import static org.badvision.outlaweditor.Application.gameData;
import org.badvision.outlaweditor.MapEditor;
import org.badvision.outlaweditor.TransferHelper;
import org.badvision.outlaweditor.api.ApplicationState;
import org.badvision.outlaweditor.data.DataUtilities;
import static org.badvision.outlaweditor.data.PropertyHelper.bind;
import static org.badvision.outlaweditor.data.PropertyHelper.stringProp;
@ -121,7 +120,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
m.setName("Untitled");
m.setWidth(512);
m.setHeight(512);
gameData.getMap().add(m);
ApplicationState.getInstance().getGameData().getMap().add(m);
rebuildMapSelectors();
setCurrentMap(m);
}
@ -135,7 +134,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
confirm("Delete map '" + currentMap.getName() + "'. Are you sure?", () -> {
org.badvision.outlaweditor.data.xml.Map del = currentMap;
setCurrentMap(null);
Application.gameData.getMap().remove(del);
ApplicationState.getInstance().getGameData().getMap().remove(del);
rebuildMapSelectors();
}, null);
}
@ -337,8 +336,8 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
public void rebuildMapSelectors() {
Map m = mapSelect.getSelectionModel().getSelectedItem();
mapSelect.getItems().clear();
DataUtilities.sortMaps(Application.gameData.getMap());
mapSelect.getItems().addAll(Application.gameData.getMap());
DataUtilities.sortMaps(ApplicationState.getInstance().getGameData().getMap());
mapSelect.getItems().addAll(ApplicationState.getInstance().getGameData().getMap());
mapSelect.getSelectionModel().select(m);
}
@ -375,8 +374,8 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
ToggleGroup tileGroup = new ToggleGroup();
HashMap<String, Menu> submenus = new HashMap<>();
Application.gameData.getTile().stream().forEach((Tile t) -> {
WritableImage img = TileUtils.getImage(t, currentPlatform);
ApplicationState.getInstance().getGameData().getTile().stream().forEach((Tile t) -> {
WritableImage img = TileUtils.getImage(t, ApplicationState.getInstance().getCurrentPlatform());
ImageView iv = new ImageView(img);
String category = String.valueOf(t.getCategory());
Menu categoryMenu = submenus.get(category);
@ -391,7 +390,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
tileGroup.selectToggle(tileSelection);
theMenu.setStyle("-fx-font-weight:bold; -fx-text-fill:blue");
}
tileSelection.setGraphic(new ImageView(TileUtils.getImage(t, currentPlatform)));
tileSelection.setGraphic(new ImageView(TileUtils.getImage(t, ApplicationState.getInstance().getCurrentPlatform())));
tileSelection.setOnAction((event) -> {
if (getCurrentEditor() != null) {
getCurrentEditor().setCurrentTile(t);

View File

@ -10,7 +10,6 @@
package org.badvision.outlaweditor.ui.impl;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
@ -23,7 +22,7 @@ import javafx.scene.image.ImageView;
import javafx.util.StringConverter;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.TileEditor;
import static org.badvision.outlaweditor.ui.UIAction.confirm;
import org.badvision.outlaweditor.api.ApplicationState;
import static org.badvision.outlaweditor.data.PropertyHelper.bind;
import static org.badvision.outlaweditor.data.PropertyHelper.boolProp;
import static org.badvision.outlaweditor.data.PropertyHelper.stringProp;
@ -32,7 +31,9 @@ import org.badvision.outlaweditor.data.TilesetUtils;
import org.badvision.outlaweditor.data.xml.PlatformData;
import org.badvision.outlaweditor.data.xml.Tile;
import org.badvision.outlaweditor.ui.ApplicationUIController;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import org.badvision.outlaweditor.ui.TileEditorTabController;
import static org.badvision.outlaweditor.ui.UIAction.confirm;
/**
* FXML Controller class for tile editor tab
@ -95,7 +96,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
confirm("Delete tile '" + getCurrentTile().getName() + "'. Are you sure?", () -> {
Tile del = getCurrentTile();
setCurrentTile(null);
Application.gameData.getTile().remove(del);
ApplicationState.getInstance().getGameData().getTile().remove(del);
mainController.rebuildTileSelectors();
}, null);
}
@ -150,7 +151,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
return new EntitySelectorCell<Tile>(tileNameField, tileCategoryField) {
@Override
public void finishUpdate(Tile item) {
setGraphic(new ImageView(TileUtils.getImage(item, Application.currentPlatform)));
setGraphic(new ImageView(TileUtils.getImage(item, ApplicationState.getInstance().getCurrentPlatform())));
}
};
});
@ -223,7 +224,7 @@ 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 = Application.currentPlatform.tileEditor.newInstance();
TileEditor editor = ApplicationState.getInstance().getCurrentPlatform().tileEditor.newInstance();
editor.setEntity(t);
setCurrentTileEditor(editor);
tileNameField.textProperty().addListener(rebuildListener);
@ -241,7 +242,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
public void rebuildTileSelectors() {
Tile t = getCurrentTile();
tileSelector.getItems().clear();
List<Tile> allTiles = Application.gameData.getTile();
List<Tile> allTiles = ApplicationState.getInstance().getGameData().getTile();
allTiles.sort((Tile o1, Tile o2) -> {
int c1 = String.valueOf(o1.getCategory()).compareTo(String.valueOf(o2.getCategory()));
if (c1 != 0) {

View File

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.input.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.input.KeyCodeCombination?>
<MenuBar styleClass="menu" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.ApplicationMenuControllerImpl">
<MenuBar styleClass="menu" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.badvision.outlaweditor.ui.impl.ApplicationMenuControllerImpl">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
@ -38,6 +36,7 @@
</Menu>
</items>
</Menu>
<Menu fx:id="extraMenu" mnemonicParsing="false" text="Extras" />
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" onAction="#onHelpAbout" text="About" />