From: <aki...@us...> - 2006-12-17 00:01:21
|
Revision: 1118 http://svn.sourceforge.net/gridarta/?rev=1118&view=rev Author: akirschbaum Date: 2006-12-16 16:01:21 -0800 (Sat, 16 Dec 2006) Log Message: ----------- Properly enable/disable cursor menu entries. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/crossfire/ChangeLog 2006-12-17 00:01:21 UTC (rev 1118) @@ -1,3 +1,7 @@ +2006-12-17 Andreas Kirschbaum + + * Properly enable/disable cursor menu entries. + 2006-12-16 Andreas Kirschbaum * Implement non-rectangular selections. For now, it does not take Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -785,11 +785,12 @@ level.levelCloseNotify(); mainView.removeLevelView(level.getMapViewFrame()); levels.remove(level); - currentMap = null; if (levels.size() > 0) { // get next open map we can find and set it to currentMap - currentMap = levels.get(levels.size() - 1); + setCurrentLevel(levels.get(levels.size() - 1)); + } else { + setCurrentLevel(null); } } refreshMenusAndToolbars(); @@ -1427,6 +1428,7 @@ public void setCurrentLevel(final MapControl map) { currentMap = map; refreshMenusAndToolbars(); + mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); } Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -824,19 +824,12 @@ private final String[] directionsMap = {"enterNorthMap", "enterEastMap", "enterSouthMap", "enterWestMap", "enterUpperMap", "enterLowerMap"}; - private final String[] directionsGo = {"goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest"}; - private void initActions() { ACTION_FACTORY.createActions(true, mainControl, "createNew", "open", "options", "exit", "gc", "onlineHelp", "about"); ACTION_FACTORY.createActions(true, mainControl.getScriptController().getView(), "editPlugins", "savePlugins", "exportPluginAs", "importPlugin"); ACTION_FACTORY.createActions(true, mainControl, directionsMap); ACTION_FACTORY.createActions(true, this, "resetView"); ACTION_FACTORY.createToggles(true, mainControl, "autoJoin"); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), directionsGo); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectTile", "startStopDrag", "addToSelection", "subFromSelection", "releaseDrag"); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "insertArch", "deleteArch"); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectArchAbove", "selectArchBelow"); - ACTION_FACTORY.createAction(true, "archAttributes", mainControl.getMapCursorControl()); ACTION_FACTORY.createToggles(true, this, "lockAllPickmaps"); aTileShow.setEnabled(false); // not yet implemented @@ -945,9 +938,6 @@ final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } - for (int direction = 0; direction < directionsGo.length; direction++) { - ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(selState); - } aClear.setEnabled(selState); aCut.setEnabled(selState); aCopy.setEnabled(selState); Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -128,6 +128,7 @@ if (!mapControl.isPickmap()) { mapCursor.addMapCursorListener(mainControl.getMainView().getMapTileList()); mapCursor.addMapCursorListener(mainControl.getMainView().getStatusBar()); + mapCursor.addMapCursorListener(mainControl.getMapCursorControl()); } this.mainControl = mainControl; frame = fi; Modified: trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -28,25 +28,61 @@ import cfeditor.gameobject.GameObject; import cfeditor.map.MapControl; import java.awt.Point; +import javax.swing.Action; import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; /** * This class processes events from the cursor menu. * Moving the cursor, selecting map tiles/arches, inserting/deleting arches and open arch property dialog is supported. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum */ -public class MapCursorControl { +public class MapCursorControl implements MapCursorListener { + /** Action Factory to create Actions. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + /** The MainControl. */ private final CMainControl mainControl; + /** Directions for cursor movement. */ + private final String[] directionsGo = {"goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest"}; + + private final Action aSelectTile = ACTION_FACTORY.createAction(true, "selectTile", this); + + private final Action aStartStopDrag = ACTION_FACTORY.createAction(true, "startStopDrag", this); + + private final Action aAddToSelection = ACTION_FACTORY.createAction(true, "addToSelection", this); + + private final Action aSubFromSelection = ACTION_FACTORY.createAction(true, "subFromSelection", this); + + private final Action aReleaseDrag = ACTION_FACTORY.createAction(true, "releaseDrag", this); + + private final Action aInsertArch = ACTION_FACTORY.createAction(true, "insertArch", this); + + private final Action aDeleteArch = ACTION_FACTORY.createAction(true, "deleteArch", this); + + private final Action aSelectArchAbove = ACTION_FACTORY.createAction(true, "selectArchAbove", this); + + private final Action aSelectArchBelow = ACTION_FACTORY.createAction(true, "selectArchBelow", this); + + private final Action aArchAttributes = ACTION_FACTORY.createAction(true, "archAttributes", this); + /** * Create a MapCursorControl. * @param mainControl MainControl to use (used for getting the current map etc.) */ public MapCursorControl(final CMainControl mainControl) { this.mainControl = mainControl; + + ACTION_FACTORY.createActions(true, this, directionsGo); + + refreshMenus(); } /** @@ -210,4 +246,39 @@ assert mapCursor != null; return mapCursor; } + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull MapCursorEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull MapCursorEvent e) { + refreshMenus(); + } + + /** + * Enable/disable menu entries based on the current cursor state. + */ + public void refreshMenus() { + final MapControl mapControl = mainControl.getCurrentMap(); + final MapCursor mapCursor = mapControl != null ? mapControl.getMapCursor() : null; + + final boolean hasCursor = mapCursor != null && mapCursor.isActive(); + + for (int direction = 0; direction < directionsGo.length; direction++) { + ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(hasCursor); + } + aSelectTile.setEnabled(hasCursor); + aStartStopDrag.setEnabled(hasCursor); + aAddToSelection.setEnabled(hasCursor); + aSubFromSelection.setEnabled(hasCursor); + aReleaseDrag.setEnabled(hasCursor); + aInsertArch.setEnabled(hasCursor); + aDeleteArch.setEnabled(hasCursor); + aSelectArchAbove.setEnabled(hasCursor); + aSelectArchBelow.setEnabled(hasCursor); + aArchAttributes.setEnabled(hasCursor); + } + } // class MapCursorControl Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -997,9 +997,9 @@ if (levels.size() > 0) { // get next open map we can find and set it to currentMap - currentMap = levels.get(levels.size() - 1); + setCurrentLevel(levels.get(levels.size() - 1)); } else { - currentMap = null; + setCurrentLevel(null); } } refreshMenusAndToolbars(); @@ -1676,6 +1676,7 @@ public void setCurrentLevel(final MapControl map) { currentMap = map; refreshMenusAndToolbars(); + mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); } Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -727,16 +727,9 @@ private final String[] directionsMap = {"enterNorthMap", "enterEastMap", "enterSouthMap", "enterWestMap", "enterNorthEastMap", "enterSouthEastMap", "enterSouthWestMap", "enterNorthWestMap"}; - private final String[] directionsGo = {"goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest"}; - private void initActions() { ACTION_FACTORY.createActions(true, mainControl, "createNew", "open", "options", "exit", "newScript", "editScript", "controlServer", "controlClient", "validateMap", "cleanCompletelyBlockedSquares", "zoom", "gc", "prevWindow", "nextWindow", "onlineHelp", "tod", "about", "update"); ACTION_FACTORY.createActions(true, mainControl, directionsMap); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), directionsGo); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectTile", "startStopDrag", "addToSelection", "subFromSelection", "releaseDrag"); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "insertArch", "deleteArch"); - ACTION_FACTORY.createActions(true, mainControl.getMapCursorControl(), "selectArchAbove", "selectArchBelow"); - ACTION_FACTORY.createAction(true, "archAttributes", mainControl.getMapCursorControl()); ACTION_FACTORY.createToggles(true, mainControl, "drawDouble", "gridVisible"); ACTION_FACTORY.createToggles(true, this, "lockAllPickmaps"); } @@ -838,7 +831,6 @@ for (int direction = 0; direction < 8; direction++) { final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); - ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(selState); } aClear.setEnabled(selState); aCut.setEnabled(selState); Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -125,6 +125,7 @@ if (!mapControl.isPickmap()) { mapCursor.addMapCursorListener(mainControl.getMainView().getMapTileList()); mapCursor.addMapCursorListener(mainControl.getMainView().getStatusBar()); + mapCursor.addMapCursorListener(mainControl.getMapCursorControl()); } this.mainControl = mainControl; Modified: trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java 2006-12-16 22:46:32 UTC (rev 1117) +++ trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java 2006-12-17 00:01:21 UTC (rev 1118) @@ -28,25 +28,61 @@ import daieditor.gameobject.GameObject; import daieditor.map.MapControl; import java.awt.Point; +import javax.swing.Action; import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; /** * This class processes events from the cursor menu. * Moving the cursor, selecting map tiles/arches, inserting/deleting arches and open arch property dialog is supported. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum */ -public class MapCursorControl { +public class MapCursorControl implements MapCursorListener { + /** Action Factory to create Actions. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + /** The MainControl. */ private final CMainControl mainControl; + /** Directions for cursor movement. */ + private final String[] directionsGo = {"goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest"}; + + private final Action aSelectTile = ACTION_FACTORY.createAction(true, "selectTile", this); + + private final Action aStartStopDrag = ACTION_FACTORY.createAction(true, "startStopDrag", this); + + private final Action aAddToSelection = ACTION_FACTORY.createAction(true, "addToSelection", this); + + private final Action aSubFromSelection = ACTION_FACTORY.createAction(true, "subFromSelection", this); + + private final Action aReleaseDrag = ACTION_FACTORY.createAction(true, "releaseDrag", this); + + private final Action aInsertArch = ACTION_FACTORY.createAction(true, "insertArch", this); + + private final Action aDeleteArch = ACTION_FACTORY.createAction(true, "deleteArch", this); + + private final Action aSelectArchAbove = ACTION_FACTORY.createAction(true, "selectArchAbove", this); + + private final Action aSelectArchBelow = ACTION_FACTORY.createAction(true, "selectArchBelow", this); + + private final Action aArchAttributes = ACTION_FACTORY.createAction(true, "archAttributes", this); + /** * Create a MapCursorControl. * @param mainControl MainControl to use (used for getting the current map etc.) */ public MapCursorControl(final CMainControl mainControl) { this.mainControl = mainControl; + + ACTION_FACTORY.createActions(true, this, directionsGo); + + refreshMenus(); } /** @@ -209,4 +245,39 @@ assert mapCursor != null; return mapCursor; } + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull MapCursorEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull MapCursorEvent e) { + refreshMenus(); + } + + /** + * Enable/disable menu entries based on the current cursor state. + */ + public void refreshMenus() { + final MapControl mapControl = mainControl.getCurrentMap(); + final MapCursor mapCursor = mapControl != null ? mapControl.getMapCursor() : null; + + final boolean hasCursor = mapCursor != null && mapCursor.isActive(); + + for (int direction = 0; direction < directionsGo.length; direction++) { + ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(hasCursor); + } + aSelectTile.setEnabled(hasCursor); + aStartStopDrag.setEnabled(hasCursor); + aAddToSelection.setEnabled(hasCursor); + aSubFromSelection.setEnabled(hasCursor); + aReleaseDrag.setEnabled(hasCursor); + aInsertArch.setEnabled(hasCursor); + aDeleteArch.setEnabled(hasCursor); + aSelectArchAbove.setEnabled(hasCursor); + aSelectArchBelow.setEnabled(hasCursor); + aArchAttributes.setEnabled(hasCursor); + } + } // class MapCursorControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |