Total completion of refactoring, got all the bugs out of the refactored classes (finally!) :-)

This commit is contained in:
Brendan Robert 2014-06-01 01:52:40 -05:00
parent a096d73ae5
commit ddf5ac1128
8 changed files with 87 additions and 64 deletions

View File

@ -0,0 +1,66 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.badvision.outlaweditor.ui;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.scene.control.ListCell;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.ComboBoxListCell;
import org.badvision.outlaweditor.data.PropertyHelper;
import org.badvision.outlaweditor.ui.impl.ApplicationUIControllerImpl;
/**
*
* @author blurry
*/
public abstract class EntitySelectorCell<T> extends ComboBoxListCell<T> {
static Map<TextField, Object> lastSelected = new HashMap<>();
TextField nameField;
public EntitySelectorCell(TextField tileNameField) {
super.setPrefWidth(125);
nameField = tileNameField;
}
@Override
public void updateSelected(boolean sel) {
if (sel) {
Object o = lastSelected.get(nameField);
if (o != null && !o.equals(getItem())) {
((ListCell) o).updateSelected(false);
}
textProperty().unbind();
textProperty().bind(nameField.textProperty());
lastSelected.put(nameField, this);
} else {
updateItem(getItem(), false);
}
}
@Override
public void updateItem(T item, boolean empty) {
textProperty().unbind();
super.updateItem(item, empty);
if (item != null && !(item instanceof String)) {
try {
textProperty().bind(PropertyHelper.stringProp(item, "name"));
} catch (NoSuchMethodException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
finishUpdate(item);
} else {
setText(null);
}
}
public void finishUpdate(T item) {
}
}

View File

@ -127,7 +127,7 @@ public abstract class MapEditorTabController {
@FXML
abstract public void scrollMapUp(ActionEvent event);
protected void initalize() {
public void initalize() {
assert mapEditorAnchorPane != null : "fx:id=\"mapEditorAnchorPane\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
assert mapHeightField != null : "fx:id=\"mapHeightField\" was not injected: check your FXML file 'mapEditorTab.fxml'.";
assert mapNameField != null : "fx:id=\"mapNameField\" was not injected: check your FXML file 'mapEditorTab.fxml'.";

View File

@ -85,4 +85,7 @@ public abstract class TileEditorTabController {
abstract public void rebuildTileSelectors();
public void initalize() {
}
}

View File

@ -1,17 +1,9 @@
package org.badvision.outlaweditor.ui.impl;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.Event;
import javafx.scene.control.ListCell;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.ComboBoxListCell;
import javafx.scene.input.DataFormat;
import org.badvision.outlaweditor.Application;
import org.badvision.outlaweditor.Editor;
import static org.badvision.outlaweditor.data.PropertyHelper.*;
import org.badvision.outlaweditor.data.TileUtils;
import org.badvision.outlaweditor.data.TilesetUtils;
import org.badvision.outlaweditor.data.xml.Tile;
@ -34,6 +26,9 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
rebuildTileSelectors();
}
});
tileController.initalize();
mapController.initalize();
imageController.initalize();
}
@Override
@ -127,51 +122,6 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
public static final DataFormat SCRIPT_DATA_FORMAT = new DataFormat("MythosScript");
abstract public static class EntitySelectorCell<T> extends ComboBoxListCell<T> {
static Map<TextField, Object> lastSelected = new HashMap<>();
TextField nameField;
public EntitySelectorCell(TextField tileNameField) {
super.setPrefWidth(125);
nameField = tileNameField;
}
@Override
public void updateSelected(boolean sel) {
if (sel) {
Object o = lastSelected.get(nameField);
if (o != null && !o.equals(getItem())) {
((ListCell) o).updateSelected(false);
}
textProperty().unbind();
textProperty().bind(nameField.textProperty());
lastSelected.put(nameField, this);
} else {
updateItem(getItem(), false);
}
}
@Override
public void updateItem(T item, boolean empty) {
textProperty().unbind();
super.updateItem(item, empty);
if (item != null && !(item instanceof String)) {
try {
textProperty().bind(stringProp(item, "name"));
} catch (NoSuchMethodException ex) {
Logger.getLogger(ApplicationUIControllerImpl.class.getName()).log(Level.SEVERE, null, ex);
}
finishUpdate(item);
} else {
setText(null);
}
}
public void finishUpdate(T item) {
}
};
@Override
public void clearData() {
tileController.setCurrentTile(null);

View File

@ -1,5 +1,6 @@
package org.badvision.outlaweditor.ui.impl;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
@ -52,7 +53,7 @@ public class ImageEditorTabControllerImpl extends ImageEditorTabController {
imageSelector.setCellFactory(new Callback<ListView<Image>, ListCell<Image>>() {
@Override
public ListCell<Image> call(ListView<Image> param) {
return new ApplicationUIControllerImpl.EntitySelectorCell<Image>(imageNameField) {
return new EntitySelectorCell<Image>(imageNameField) {
@Override
public void finishUpdate(Image item) {
}

View File

@ -1,5 +1,6 @@
package org.badvision.outlaweditor.ui.impl;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
@ -185,6 +186,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
}
}
@Override
public void completeInflightOperations() {
if (getCurrentEditor() != null) {
getCurrentEditor().getCurrentMap().updateBackingMap();
@ -248,7 +250,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
}
@Override
protected void initalize() {
public void initalize() {
super.initalize();
mapSelect.setButtonCell(new ComboBoxListCell<org.badvision.outlaweditor.data.xml.Map>() {
{
@ -256,7 +258,7 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
}
@Override
public void updateItem(org.badvision.outlaweditor.data.xml.Map item, boolean empty) {
public void updateItem(Map item, boolean empty) {
textProperty().unbind();
super.updateItem(item, empty);
if (item != null) {
@ -266,13 +268,13 @@ public class MapEditorTabControllerImpl extends MapEditorTabController {
}
}
});
mapSelect.setCellFactory(new Callback<ListView<org.badvision.outlaweditor.data.xml.Map>, ListCell<org.badvision.outlaweditor.data.xml.Map>>() {
mapSelect.setCellFactory(new Callback<ListView<Map>, ListCell<Map>>() {
@Override
public ListCell<org.badvision.outlaweditor.data.xml.Map> call(ListView<org.badvision.outlaweditor.data.xml.Map> param) {
return new ApplicationUIControllerImpl.EntitySelectorCell<org.badvision.outlaweditor.data.xml.Map>(mapNameField) {
public ListCell<org.badvision.outlaweditor.data.xml.Map> call(ListView<Map> param) {
return new EntitySelectorCell<Map>(mapNameField) {
@Override
public void finishUpdate(org.badvision.outlaweditor.data.xml.Map item) {
}
public void finishUpdate(Map item) {
}
};
}
});

View File

@ -1,5 +1,6 @@
package org.badvision.outlaweditor.ui.impl;
import org.badvision.outlaweditor.ui.EntitySelectorCell;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -156,7 +157,7 @@ public class TileEditorTabControllerImpl extends TileEditorTabController {
tileSelector.setCellFactory(new Callback<ListView<Tile>, ListCell<Tile>>() {
@Override
public ListCell<Tile> call(ListView<Tile> param) {
return new ApplicationUIControllerImpl.EntitySelectorCell<Tile>(tileNameField) {
return new EntitySelectorCell<Tile>(tileNameField) {
@Override
public void finishUpdate(Tile item) {
setGraphic(new ImageView(TileUtils.getImage(item, Application.currentPlatform)));

View File

@ -5,7 +5,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.web.*?>
<AnchorPane id="AnchorPane" prefHeight="748.0" prefWidth="1024.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="org.badvision.outlaweditor.MythosScriptEditorController">
<AnchorPane id="AnchorPane" prefHeight="748.0" prefWidth="1024.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="org.badvision.outlaweditor.ui.MythosScriptEditorController">
<!-- <stylesheets>
<URL value="@/styles/mythosscripteditor.css"/>
</stylesheets>-->