From: <aki...@us...> - 2006-12-17 00:09:43
|
Revision: 1121 http://svn.sourceforge.net/gridarta/?rev=1121&view=rev Author: akirschbaum Date: 2006-12-16 16:09:44 -0800 (Sat, 16 Dec 2006) Log Message: ----------- Unify comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 00:06:13 UTC (rev 1120) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 00:09:44 UTC (rev 1121) @@ -330,11 +330,11 @@ * Add an archetype to the destination map. Inserts a new object instance * for default archetypes, and a clone for non-default archetypes. * If <var>allowDouble</var> is <code>false</code> and <var>gameObject</var> is an {@link net.sf.gridarta.gameobject.Archetype}, the object will only be inserted if there wasn't already an object with the same Archetype. - * @param mapControl MapControl of the destination map. - * @param gameObject GameObject to add. - * @param pos Position of MapSquare to add GameObject to. - * @param allowDouble <code>true</code> if insertion of multiple instances of the same Archetype should be allowed, otherwise <code>false</code> - * @param fillBelow <code>true</code> if insertion should happen below other objects on the same MapSquare, <code>false</code> to insert above other objects. + * @param mapControl MapControl of the map the object should be added to. + * @param gameObject GameObject to add. + * @param pos position to add GameObject at + * @param allowDouble <code>true</code> for allowing similar GameObjects on the same square, <code>false</code> to disallow + * @param fillBelow <code>true</code> if the GameObject should be added below all others, <code>false</code> for above */ private void addArchToMap(final MapControl mapControl, final GameObject gameObject, final Point pos, final boolean allowDouble, final boolean fillBelow) { if (gameObject.isArchetype()) { Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 00:06:13 UTC (rev 1120) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 00:09:44 UTC (rev 1121) @@ -458,11 +458,12 @@ /** * Add an archetype to the destination map. Inserts a new object instance * for default archetypes, and a clone for non-default archetypes. - * @param mapControl MapControl of the map the object should be added to. - * @param gameObject GameObject to add. - * @param pos Position to add GameObject at. - * @param allowDouble <code>true</code> for allowing similar GameObjects on the same square, <code>false</code> to disallow. - * @param fillBelow <code>true</code> if the GameObject should be added below all others, <code>false</code> for above. + * If <var>allowDouble</var> is <code>false</code> and <var>gameObject</var> is an {@link net.sf.gridarta.gameobject.Archetype}, the object will only be inserted if there wasn't already an object with the same Archetype. + * @param mapControl MapControl of the map the object should be added to. + * @param gameObject GameObject to add. + * @param pos position to add GameObject at + * @param allowDouble <code>true</code> for allowing similar GameObjects on the same square, <code>false</code> to disallow + * @param fillBelow <code>true</code> if the GameObject should be added below all others, <code>false</code> for above */ private void addArchToMap(final MapControl mapControl, final GameObject gameObject, final Point pos, final boolean allowDouble, final boolean fillBelow) { if (gameObject.isArchetype()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 00:38:22
|
Revision: 1122 http://svn.sourceforge.net/gridarta/?rev=1122&view=rev Author: akirschbaum Date: 2006-12-16 16:38:22 -0800 (Sat, 16 Dec 2006) Log Message: ----------- Unify CopyBuffer implementation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 00:09:44 UTC (rev 1121) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 00:38:22 UTC (rev 1122) @@ -34,6 +34,7 @@ import java.util.HashSet; import net.sf.gridarta.Size2D; import net.sf.gridarta.MainControl; +import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -75,10 +76,6 @@ /** The dummy MapArchObject of {@link #copyMap}. */ private final MapArchObject mapArch; - private int bufWidth; // buffer's width (counted in tiles) - - private int bufHeight; // buffer's height (counted in tiles) - /** * Create the copy buffer. * @param mainControl main control @@ -87,9 +84,6 @@ this.mainControl = mainControl; // link main control in mapArch = new MapArchObject(); - bufWidth = 1; - bufHeight = 1; - mapArch.setMapSize(new Size2D(bufWidth, bufHeight)); mapArch.setFileName("cb"); mapArch.setMapName("cb"); } @@ -140,16 +134,17 @@ // Prepare the buffer (if it's a cut or copy) if (mode == Mode.DO_CUT || mode == Mode.DO_COPY) { final boolean wasEmpty = copyMap == null; + if (!wasEmpty) { + // recycle and resize buffer + copyMap.clearMap(); // free old map (/buffer) object + } - // recycle and resize buffer - bufWidth = Math.abs(selRec.width) + 1; // new width - bufHeight = Math.abs(selRec.height) + 1; // new height - mapArch.setMapSize(new Size2D(bufWidth, bufHeight)); - copyMap = new DefaultMapModel(mainControl, copyMapCtrl, null, mapArch); // new MapModel + mapArch.setMapSize(new Size2D(selRec.width + 1, selRec.height + 1)); copyMapCtrl = new MapControl(mainControl, null, mapArch, false, null); // new MapControl + copyMap = copyMapCtrl.getMapModel(); if (wasEmpty) { - mainControl.getMainView().refreshMenus(); // "Paste" enabled + mainControl.getMainView().refreshMenus(); // "Paste" enabled // XXX: sucks - no MVC } } @@ -209,35 +204,29 @@ // cycle through all tile coordinates which are highlighted: mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); - final Point sourcePos = new Point(); - for (pos.x = startp.x; Math.abs(pos.x - startp.x) < bufWidth; pos.x++) { - for (pos.y = startp.y; Math.abs(pos.y - startp.y) < bufHeight; pos.y++) { - // paste the archs if on the map: - if (mapControl.isPointValid(pos)) { - sourcePos.x = pos.x - startp.x; - sourcePos.y = pos.y - startp.y; - for (final GameObject gameObject : copyMapCtrl.getMapModel().getMapSquare(sourcePos)) { - if (!gameObject.isMulti()) { - // read arch from buffer and stick in on the map - final GameObject clone = gameObject.createClone(pos.x, pos.y); - mapControl.addArchObjectToMap(clone); - } + assert copyMap != null; + for (final MapSquare<GameObject> square : copyMap) { + pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); + // paste the archs if on the map: + if (mapControl.isPointValid(pos)) { + for (final GameObject gameObject : square) { + if (!gameObject.isMulti()) { + // read gameObject from buffer and stick in on the map + final GameObject clone = gameObject.createClone(pos.x, pos.y); + mapControl.addArchObjectToMap(clone); } } } } - // now we loop through the tiles again and paste all multis found - for (pos.x = startp.x; Math.abs(pos.x - startp.x) < bufWidth; pos.x++) { - for (pos.y = startp.y; Math.abs(pos.y - startp.y) < bufHeight; pos.y++) { - // paste the archs if on the map: - if (mapControl.isPointValid(pos)) { - sourcePos.x = pos.x - startp.x; - sourcePos.y = pos.y - startp.y; - for (final GameObject gameObject : copyMapCtrl.getMapModel().getMapSquare(sourcePos)) { - if (gameObject.isMulti()) { - addArchToMap(mapControl, gameObject, pos, true, false); - } + assert copyMapCtrl != null; + for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { + pos.setLocation(startp); + pos.translate(square.getMapX(), square.getMapY()); + if (mapControl.isPointValid(pos)) { // paste the archs if on the map: + for (final GameObject gameObject : square) { + if (gameObject.isMulti()) { + addArchToMap(mapControl, gameObject, pos, true, false); } } } Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 00:09:44 UTC (rev 1121) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 00:38:22 UTC (rev 1122) @@ -134,18 +134,16 @@ // Prepare the buffer (if it's a cut or copy) if (mode == Mode.DO_CUT || mode == Mode.DO_COPY) { - final boolean wasEmpty; - if (copyMap != null) { + final boolean wasEmpty = copyMap == null; + if (!wasEmpty) { // recycle and resize buffer copyMap.clearMap(); // free old map (/buffer) object - wasEmpty = false; - } else { - wasEmpty = true; } mapArch.setMapSize(new Size2D(selRec.width + 1, selRec.height + 1)); copyMapCtrl = new MapControl(mainControl, null, mapArch, false, false); // new MapControl copyMap = copyMapCtrl.getMapModel(); + if (wasEmpty) { mainControl.getMainView().refreshMenus(); // "Paste" enabled // XXX: sucks - no MVC } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 12:24:20
|
Revision: 1128 http://svn.sourceforge.net/gridarta/?rev=1128&view=rev Author: akirschbaum Date: 2006-12-17 04:24:20 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapTileList.java trunk/daimonin/src/daieditor/CMapTileList.java Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-17 12:16:48 UTC (rev 1127) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-17 12:24:20 UTC (rev 1128) @@ -95,8 +95,8 @@ /** * Create a CMapTileList. - * @param mainControl MainControl, used for some icons. - * @param mainView View to attach to. + * @param mainControl MainControl, used for icons + * @param mainView MainView, used for updating UI */ public CMapTileList(final CMainControl mainControl, final CMainView mainView) { this.mainControl = mainControl; @@ -112,11 +112,11 @@ scrollPane.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); add(scrollPane, BorderLayout.CENTER); - final JPanel dummy = new JPanel(); + final JPanel arrows = new JPanel(); if (mainView.isMapTileListBottom()) { - dummy.setLayout(new GridLayout(2, 1)); + arrows.setLayout(new GridLayout(2, 1)); } - final JScrollPane scrollPane2 = new JScrollPane(dummy); + final JScrollPane scrollPane2 = new JScrollPane(arrows); scrollPane2.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_NEVER); scrollPane2.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); scrollPane2.getViewport().setScrollMode(SIMPLE_SCROLL_MODE); @@ -141,7 +141,7 @@ buttonDown.setVerticalTextPosition(SwingConstants.BOTTOM); buttonDown.setHorizontalTextPosition(SwingConstants.CENTER); if (!mainView.isMapTileListBottom()) { - dummy.add(buttonDown, BorderLayout.EAST); + arrows.add(buttonDown, BorderLayout.EAST); } final CFancyButton buttonUp = new CFancyButton(null, "Move Tile Position Up", @@ -158,10 +158,10 @@ buttonUp.setVerticalTextPosition(SwingConstants.BOTTOM); buttonUp.setHorizontalTextPosition(SwingConstants.CENTER); if (!mainView.isMapTileListBottom()) { - dummy.add(buttonUp, BorderLayout.WEST); + arrows.add(buttonUp, BorderLayout.WEST); } else { - dummy.add(buttonUp); - dummy.add(buttonDown); + arrows.add(buttonUp); + arrows.add(buttonDown); } list.addListSelectionListener(new ListSelectionListener() { @@ -375,14 +375,14 @@ */ private int addInvObjects(final GameObject node, final GameObject gameObject) { int selListCounter = -1; - for (final GameObject invItem : node.getHead()) { - if (invItem == gameObject) { + for (final GameObject invObject : node.getHead()) { + if (invObject == gameObject) { selListCounter = listCounter; } listCounter++; - model.addElement(invItem); + model.addElement(invObject); - final int tmpListCounter = addInvObjects(invItem, gameObject); + final int tmpListCounter = addInvObjects(invObject, gameObject); if (tmpListCounter != -1) { selListCounter = tmpListCounter; } Modified: trunk/daimonin/src/daieditor/CMapTileList.java =================================================================== --- trunk/daimonin/src/daieditor/CMapTileList.java 2006-12-17 12:16:48 UTC (rev 1127) +++ trunk/daimonin/src/daieditor/CMapTileList.java 2006-12-17 12:24:20 UTC (rev 1128) @@ -58,6 +58,7 @@ import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * The panel that displays the arches of the currently selected map square. @@ -90,11 +91,10 @@ private transient MapSquare<GameObject> currentSquare; /** - * Creates a CMapTileList. - * @param mainControl MainControl, used for icons. - * @param mainView MainView, used for updating UI. + * Create a CMapTileList. + * @param mainControl MainControl, used for icons + * @param mainView MainView, used for updating UI */ - /** Build Panel. */ public CMapTileList(final CMainControl mainControl, final CMainView mainView) { this.mainControl = mainControl; this.mainView = mainView; @@ -283,7 +283,7 @@ * Return the currently selected GameObject within this list (currently selected MapSquare). * @return the currently selected GameObject */ - public GameObject getMapTileSelection() { + @Nullable public GameObject getMapTileSelection() { return (GameObject) list.getSelectedValue(); } @@ -393,14 +393,14 @@ */ private int addInvObjects(final GameObject node, final GameObject gameObject) { int selListCounter = -1; - for (GameObject arch : node.reverse()) { - if (arch == gameObject) { + for (final GameObject invObject : node.reverse()) { + if (invObject == gameObject) { selListCounter = listCounter; } listCounter++; - model.addElement(arch); + model.addElement(invObject); - final int tmpListCounter = addInvObjects(arch, gameObject); + final int tmpListCounter = addInvObjects(invObject, gameObject); if (tmpListCounter != -1) { selListCounter = tmpListCounter; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 12:33:53
|
Revision: 1131 http://svn.sourceforge.net/gridarta/?rev=1131&view=rev Author: akirschbaum Date: 2006-12-17 04:33:53 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 12:26:53 UTC (rev 1130) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 12:33:53 UTC (rev 1131) @@ -148,7 +148,6 @@ } } - final Point offset = selRec.getLocation(); mapControl.getMapModel().beginTransaction("Cut / Clear"); // TODO: I18N/L10N final HashSet<GameObject> gameObjectsToDelete = new HashSet<GameObject>(); for (final MapSquare<GameObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 12:26:53 UTC (rev 1130) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 12:33:53 UTC (rev 1131) @@ -149,7 +149,6 @@ } } - final Point offset = selRec.getLocation(); mapControl.getMapModel().beginTransaction("Cut / Clear"); // TODO: I18N/L10N final HashSet<GameObject> gameObjectsToDelete = new HashSet<GameObject>(); for (final MapSquare<GameObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { @@ -161,7 +160,7 @@ // arches that don't match the view settings are ignored! if ((mode == Mode.DO_CUT || mode == Mode.DO_COPY) && gameObject.isHead() && !gameObject.isInContainer() && mainControl.isTileEdit(gameObject)) { // copy this gameObject - final GameObject clone = gameObject.createClone(posx - offset.x, posy - offset.y); + final GameObject clone = gameObject.createClone(posx - selRec.x, posy - selRec.y); assert copyMapCtrl != null; copyMapCtrl.getMapModel().addGameObjectToMap(clone, false); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 12:44:17
|
Revision: 1133 http://svn.sourceforge.net/gridarta/?rev=1133&view=rev Author: akirschbaum Date: 2006-12-17 04:44:17 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 12:36:33 UTC (rev 1132) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 12:44:17 UTC (rev 1133) @@ -239,14 +239,14 @@ * @todo the fill density is ignored for floodfill */ public void fill(final MapControl mapControl, final boolean fillBelow, final int density) { + if (!mapControl.getMapViewFrame().isHighlight()) { + return; // should actually never happen + } + final Rectangle selRec = mapControl.getMapGrid().getSelectedRec();; final Point cursor = mapControl.getMapViewFrame().getView().getCursorPosition(); final Point pos = new Point(); - if (!mapControl.getMapViewFrame().isHighlight()) { - return; // should actually never happen - } - if (mainControl.getArchPanelHighlight() == null) { // no selected arch to fill with return; } Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 12:36:33 UTC (rev 1132) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 12:44:17 UTC (rev 1133) @@ -237,7 +237,6 @@ * @param rand Percentage of filling (e.g. 100 for 100%, 10 for 10%). */ public void fill(final MapControl mapControl, final boolean fillBelow, final MapControl seed, final int rand) { - if (!mapControl.getMapViewFrame().isHighlight()) { return; // should actually never happen } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 14:20:06
|
Revision: 1137 http://svn.sourceforge.net/gridarta/?rev=1137&view=rev Author: akirschbaum Date: 2006-12-17 06:20:04 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Split fill and floodfill into separate functions in user interface. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/action.properties trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/action.properties trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/ChangeLog 2006-12-17 14:20:04 UTC (rev 1137) @@ -1,5 +1,8 @@ 2006-12-17 Andreas Kirschbaum + * Split fill and floodfill into separate functions in user + interface. + * Add replace of non-rectangular selections; make replacement of large areas much faster. Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -1577,6 +1577,17 @@ } } + /** + * "Floodfill" was selected from the Edit menu. + */ + public void floodfill() { + if (currentMap == null || currentMap.getMapViewFrame() == null) { + return; // this should never be possible, but I just wanna make sure... + } + + copybuffer.floodfill(currentMap); + } + /** "Replace" was selected from the Edit menu. */ public void replace() { if (currentMap == null || currentMap.getMapViewFrame() == null) { Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -863,6 +863,8 @@ private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", mainControl); + private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", mainControl); + private final Action aEnterExit = ACTION_FACTORY.createAction(true, "enterExit", mainControl); private final Action aTileShow = ACTION_FACTORY.createToggle(true, "tileShow", mainControl); @@ -945,6 +947,7 @@ aFillBelow.setEnabled(selState); aRandFillAbove.setEnabled(selState); aRandFillBelow.setEnabled(selState); + aFloodfill.setEnabled(selState); aEnterExit.setEnabled(selState); aRevert.setEnabled(mapState && fLevelEdited && mainControl.isPlainSaveEnabled()); aPaste.setEnabled(selState && !mainControl.isCopyBufferEmpty()); Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -2,6 +2,7 @@ * Crossfire Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 Andreas Kirschbaum * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -36,12 +37,14 @@ import net.sf.gridarta.MainControl; import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * This class manages the cut/copy/paste actions in maps. The data is stored in * an ordinary but invisible map-object. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum */ public final class CopyBuffer { @@ -236,7 +239,6 @@ * @param fillBelow if true, the filling content is placed *below* the * existing map * @param density the fill density in percent; -1 to disable - * @todo the fill density is ignored for floodfill */ public void fill(final MapControl mapControl, final boolean fillBelow, final int density) { if (!mapControl.getMapViewFrame().isHighlight()) { @@ -250,32 +252,46 @@ return; } - // If selection is empty and map-spot empty, a floodfill is done - final GameObject arch; - if ((selRec == null || (selRec.x == 0 && selRec.height == 0)) && !mapControl.containsArchObject(cursor)) { - arch = mainControl.getArchPanelHighlight(); - if (arch != null) { - floodfill(mapControl, cursor.x, cursor.y, arch); + mapControl.getMapModel().beginTransaction("Fill"); // TODO; I18N/L10N + for (final Point p : mapControl.getMapViewFrame().getView().getSelection()) { + if (density != -1 && density != 100 && density < MainControl.rnd.nextInt(100) + 1) { + continue; } - } else { - mapControl.getMapModel().beginTransaction("Fill"); // TODO; I18N/L10N - for (final Point p : mapControl.getMapViewFrame().getView().getSelection()) { - if (density != -1 && density != 100 && density < MainControl.rnd.nextInt(100) + 1) { - continue; - } - final GameObject gameObject = mainControl.getArchPanelHighlight(); - addArchToMap(mapControl, gameObject, p, false, fillBelow); - } - mapControl.getMapModel().endTransaction(); + final GameObject gameObject = mainControl.getArchPanelHighlight(); + addArchToMap(mapControl, gameObject, p, false, fillBelow); } + mapControl.getMapModel().endTransaction(); + mainControl.getMainView().refreshMapTileList(); + } - // now the map and toolbars must be redrawn - mapControl.repaint(); + /** + * Floodfill the the map, starting at the cursor position. + * + * @param mapControl the map to fill + */ + public void floodfill(@NotNull final MapControl mapControl) { + final Point cursor = mapControl.getMapViewFrame().getView().getCursorPosition(); + if (cursor == null) { + return; + } + + if (mapControl.containsArchObject(cursor)) { + return; + } + + final GameObject arch = mainControl.getArchPanelHighlight(); + if (arch == null) { + return; + } + + mapControl.getMapModel().beginTransaction("Floodfill"); // TODO: I18N/L10N + floodfill(mapControl, cursor.x, cursor.y, arch); + mapControl.getMapModel().endTransaction(); mainControl.getMainView().refreshMapTileList(); } /** - * Floodfill the map, starting at the highlighted square. + * Floodfill the map. * <p/> * Okay, yes, this algorithm is as inefficient as it could be. But it is * short and easy. And CF maps are so small anyways. Modified: trunk/crossfire/src/cfeditor/action.properties =================================================================== --- trunk/crossfire/src/cfeditor/action.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/action.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -10,7 +10,7 @@ main.menubar=file edit map cursor pickmaps resources tools analyze view plugins window help file.menu=createNew open close - save saveAs revert createImg - options - exit -edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow +edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow floodfill map.menu=autoJoin - gridVisible enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterUpperMap enterLowerMap tileShow - mapProperties cursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes pickmaps.menu=lockAllPickmaps - addNewPickmap closePickmap - openPickmapMap - savePickmap revertPickmap @@ -25,7 +25,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor mapwindowView mapwindowFile.menu=save saveAs createImg - revert - close -mapwindowEdit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow +mapwindowEdit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow floodfill mapwindowMap.menu=autoJoin - gridVisible enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterUpperMap enterLowerMap tileShow - mapProperties mapwindowCursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes mapwindowView.menu=showMonster showExit showBackground showDoor showWall showEquipment showTreasure showConnected resetView @@ -71,7 +71,9 @@ randFillBelow.icon=EmptySmallIcon +floodfill.icon=EmptySmallIcon + mapProperties.icon=general/Properties16 Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -169,7 +169,9 @@ randFillBelow.text=Random Fill Below randFillBelow.accel=ctrl shift pressed D +floodfill.text=Flood Fill + ####### # Map Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -394,7 +394,9 @@ randFillBelow.text=Zuf\xE4llig unten f\xFCllen randFillBelow.accel=ctrl shift pressed D +floodfill.text=Freien Bereich f\xFCllen + ####### # Map Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -1848,6 +1848,17 @@ } } + /** + * "Floodfill" was selected from the Edit menu. + */ + public void floodfill() { + if (currentMap == null || currentMap.getMapViewFrame() == null) { + return; // this should never be possible, but I just wanna make sure... + } + + copybuffer.floodfill(currentMap); + } + /** "Replace" was selected from the Edit menu. */ public void replace() { if (currentMap == null || currentMap.getMapViewFrame() == null) { Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -766,6 +766,8 @@ private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", mainControl); + private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", mainControl); + private final Action aSelectAll = ACTION_FACTORY.createAction(true, "selectAll", mainControl); private final Action aEnterExit = ACTION_FACTORY.createAction(true, "enterExit", mainControl); @@ -839,6 +841,7 @@ aFillBelow.setEnabled(selState); aRandFillAbove.setEnabled(selState); aRandFillBelow.setEnabled(selState); + aFloodfill.setEnabled(selState); aEnterExit.setEnabled(selState); //aRevert.setEnabled(mapState && mainControl.getCurrentMap().isLevelChanged()); aPaste.setEnabled(selState && !mainControl.isCopyBufferEmpty()); Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-17 14:20:04 UTC (rev 1137) @@ -2,6 +2,7 @@ * Daimonin Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 Andreas Kirschbaum * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -37,12 +38,14 @@ import net.sf.gridarta.Size2D; import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * This class manages the cut/copy/paste actions in maps. The data is stored in * an ordinary but invisible map-object. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum */ public final class CopyBuffer { @@ -258,25 +261,15 @@ return; } - // If offset is zero and map-spot empty, a floodfill at the cursor is done - if (!mapControl.getMapViewFrame().getView().hasSelection() && mapControl.getMapViewFrame().getView().getCursorSquare().isEmpty()) { - final Point p = mapControl.getMapViewFrame().getView().getCursorPosition(); - assert p != null; - floodfill(mapControl, p.x, p.y, archList); // floodfill - } else { - mapControl.getMapModel().beginTransaction("Fill"); // TODO; I18N/L10N - for (final Point p : mapControl.getMapViewFrame().getView().getSelection()) { - if (density != -1 && density != 100 && density < rnd.nextInt(100) + 1) { - continue; - } - final GameObject gameObject = archList.get(rnd.nextInt(archList.size())); - addArchToMap(mapControl, gameObject, p, false, fillBelow); + mapControl.getMapModel().beginTransaction("Fill"); // TODO; I18N/L10N + for (final Point p : mapControl.getMapViewFrame().getView().getSelection()) { + if (density != -1 && density != 100 && density < rnd.nextInt(100) + 1) { + continue; } - mapControl.getMapModel().endTransaction(); + final GameObject gameObject = archList.get(rnd.nextInt(archList.size())); + addArchToMap(mapControl, gameObject, p, false, fillBelow); } - - // now the map and toolbars must be redrawn - mapControl.repaint(); + mapControl.getMapModel().endTransaction(); mainControl.getMainView().refreshMapTileList(); } @@ -359,6 +352,32 @@ return objects.size() == 0 ? null : objects; } + /** + * Floodfill the the map, starting at the cursor position. + * + * @param mapControl the map to fill + */ + public void floodfill(@NotNull final MapControl mapControl) { + final Point cursor = mapControl.getMapViewFrame().getView().getCursorPosition(); + if (cursor == null) { + return; + } + + if (!mapControl.getMapViewFrame().getView().getCursorSquare().isEmpty()) { + return; + } + + final List<GameObject> archList = mainControl.getArchPanelSelection(); + if (archList == null || archList.size() == 0) { + return; + } + + mapControl.getMapModel().beginTransaction("Floodfill"); // TODO: I18N/L10N + floodfill(mapControl, cursor.x, cursor.y, archList); + mapControl.getMapModel().endTransaction(); + mainControl.getMainView().refreshMapTileList(); + } + /** Constants for lookArea. */ private static final byte NOT_LOOKED_AT = (byte) 0; @@ -369,7 +388,7 @@ private static final byte BLOCKED = (byte) 3; /** - * Floodfill the map, starting at the highlighted square. + * Floodfill the map. * @param mapControl MapControl of the active map we paste on * @param startX starting x-coord for floodfill * @param startY starting y-coord for floodfill Modified: trunk/daimonin/src/daieditor/action.properties =================================================================== --- trunk/daimonin/src/daieditor/action.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/action.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -9,7 +9,7 @@ # Menus main.menubar=file edit map cursor pickmaps resources tools view window help file.menu=createNew open recent close closeAll - save saveAs revert createImg - options - exit -edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow - selectAll +edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow floodfill - selectAll map.menu=enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties cursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes @@ -94,6 +94,8 @@ randFillBelow.icon=EmptySmallIcon +floodfill.icon=EmptySmallIcon + selectAll.icon=EmptySmallIcon Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/messages.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -330,6 +330,8 @@ randFillBelow.text=Random Fill Below randFillBelow.accel=ctrl shift pressed D +floodfill.text=Flood Fill + selectAll.text=Select All selectAll.mnemonic=S selectAll.accel=ctrl pressed A Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2006-12-17 13:22:22 UTC (rev 1136) +++ trunk/daimonin/src/daieditor/messages_de.properties 2006-12-17 14:20:04 UTC (rev 1137) @@ -299,6 +299,8 @@ randFillBelow.text=Zuf\xE4llig unten f\xFCllen randFillBelow.accel=ctrl shift pressed D +floodfill.text=Freien Bereich f\xFCllen + selectAll.text=Alles ausw\xE4hlen selectAll.accel=ctrl pressed A This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-17 15:22:54
|
Revision: 1143 http://svn.sourceforge.net/gridarta/?rev=1143&view=rev Author: christianhujer Date: 2006-12-17 07:22:49 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Some unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CAttribDialog.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-17 15:16:42 UTC (rev 1142) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-17 15:22:49 UTC (rev 1143) @@ -201,12 +201,10 @@ archetype = this.gameObject.getArchetype(); // check if the type of the object is present in the definitions - CFArchType tmp = archTypeList.getHead().getNext(); //typeNr = 0; // for invalid types, we take "type 0" - type = tmp; boolean typeFound = false; int i = 0; - for (; tmp != null; tmp = tmp.getNext()) { + for (final CFArchType tmp : archTypeList) { if (tmp.getTypeNr() == this.gameObject.getArchTypNr()) { if (tmp.getTypeAttr() == null) { // no type-attributes, so we only compared type-numbers @@ -254,6 +252,9 @@ } i++; } + if (!typeFound) { + type = archTypeList.getArchType(0); + } // get the type data //type = archTypeList.getType(typeNr); @@ -309,9 +310,9 @@ final String[] namelist = new String[archTypeList.getLength()]; // list of typenames // read all type names - CFArchType tmp = archTypeList.getHead().getNext(); - for (int i = 0; tmp != null; tmp = tmp.getNext(), i++) { - namelist[i] = " " + tmp.getTypeName(); + int i = 0; + for (final CFArchType tmp : archTypeList) { + namelist[i++] = " " + tmp.getTypeName(); } // the active type appears selected in the box Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 15:16:42 UTC (rev 1142) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 15:22:49 UTC (rev 1143) @@ -341,6 +341,10 @@ return archTypeList.iterator(); } + public CFArchType getArchType(final int n) { + return archTypeList.get(n); + } + /** * Lookup the name of an archtype. * @param typeNr type number Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-17 15:16:42 UTC (rev 1142) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-17 15:22:49 UTC (rev 1143) @@ -83,9 +83,9 @@ /* Build Panel */ CArchPanelPan(final CArchPanel controlPanel, final CMainControl mainControl) { + super(new BorderLayout()); this.mainControl = mainControl; archPanel = controlPanel; - setLayout(new BorderLayout()); panelDesktop = new JPanel(); panelDesktop.setLayout(new BorderLayout()); Modified: trunk/daimonin/src/daieditor/CAttribDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribDialog.java 2006-12-17 15:16:42 UTC (rev 1142) +++ trunk/daimonin/src/daieditor/CAttribDialog.java 2006-12-17 15:22:49 UTC (rev 1143) @@ -605,7 +605,7 @@ final String trueVal = attrib.getMisc()[0]; if (trueVal.equals("0")) { final String attrString = gameObject.getAttributeString(nameOld); - input = new JCheckBox(attrib.getNameNew(), attrString.length() == 0 || "0".equals(attrString)); + input = new JCheckBox(attrib.getNameNew(), attrString.length() == 0 || attrString.equals("0")); } else { input = new JCheckBox(attrib.getNameNew(), gameObject.getAttributeString(nameOld).equals(trueVal)); } @@ -672,7 +672,7 @@ case FACENAME: case ANIMNAME: { final String dtxt; - if ("name".equalsIgnoreCase(nameOld)) { + if (nameOld.equalsIgnoreCase("name")) { if (gameObject.getObjName() != null && gameObject.getObjName().length() > 0) { dtxt = gameObject.getObjName(); } else if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { @@ -680,7 +680,7 @@ } else { dtxt = archetype.getArchetypeName(); } - } else if ("face".equalsIgnoreCase(nameOld)) { + } else if (nameOld.equalsIgnoreCase("face")) { if (gameObject.getFaceRealName() != null && gameObject.getFaceRealName().length() > 0) { dtxt = gameObject.getFaceRealName(); } else { @@ -810,7 +810,7 @@ newAttr = new DialogAttrib<JTextField>(attrib); // textfield (no direct input, text is set by the treasurelist dialog) String treasureName = gameObject.getAttributeString(nameOld); - if (treasureName.trim().length() == 0 || "none".equalsIgnoreCase(treasureName.trim())) { + if (treasureName.trim().length() == 0 || treasureName.trim().equalsIgnoreCase("none")) { treasureName = CFTreasureListTree.NONE_SYM; } final JTextField input = new JTextField(" " + treasureName, TEXTFIELD_COLUMNS); @@ -1138,7 +1138,7 @@ final String inline = ((DialogAttrib<JTextField>) attr).input.getText().trim(); if (inline != null) { - if ("name".equalsIgnoreCase(attr.ref.getNameOld())) { + if (attr.ref.getNameOld().equalsIgnoreCase("name")) { // special case #1: "name"-textfield if (archetype.getObjName() != null && archetype.getObjName().length() > 0) { if (!inline.equals(archetype.getObjName())) { @@ -1177,7 +1177,7 @@ break; case TEXT: { // a String attribute - if ("msg".equalsIgnoreCase(attr.ref.getNameOld()) && ((DialogAttrib<JTextArea>) attr).input.getText().trim().length() > 0) { + if (attr.ref.getNameOld().equalsIgnoreCase("msg") && ((DialogAttrib<JTextArea>) attr).input.getText().trim().length() > 0) { newMsg = ((DialogAttrib<JTextArea>) attr).input.getText().trim(); } } @@ -1248,7 +1248,7 @@ if (!isNone && !CFTreasureListTree.containsTreasureList(inline) && !inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld()))) { // The user has specified a WRONG treasurelist name, and it does not come // from the default gameObject. -> Error and out. - showMessageDialog(this, "In attribute '" + attr.ref.getNameNew() + "':\n" + "\'" + inline + "' is not a known treasurelist name!", "Input Error", ERROR_MESSAGE); + showMessageDialog(this, "In attribute '" + attr.ref.getNameNew() + "':\n" + "'" + inline + "' is not a known treasurelist name!", "Input Error", ERROR_MESSAGE); return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 15:48:18
|
Revision: 1147 http://svn.sourceforge.net/gridarta/?rev=1147&view=rev Author: akirschbaum Date: 2006-12-17 07:48:18 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Move text message into message file. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/messages.properties trunk/daimonin/src/daieditor/messages_de.properties Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 15:48:18 UTC (rev 1147) @@ -57,6 +57,7 @@ import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; import net.sf.gridarta.io.IOUtils; +import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -69,6 +70,9 @@ private static final Logger log = Logger.getLogger(CFTreasureListTree.class); + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -638,7 +642,7 @@ // is selected, also return null because those must not be used on maps. final TreasureTreeNode trNode = (TreasureTreeNode) node; if (trNode.getTreasureObj().getType() == TreasureObj.FOLDER) { - JOptionPane.showMessageDialog(this, "The " + trNode.getTreasureObj().getName() + " treasurelists must not be used in maps.\nThese lists are reserved for internal use in the Crossfire server.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); + ACTION_FACTORY.showMessageDialog(this, "treasurelistForbidden", trNode.getTreasureObj().getName()); return null; } Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-12-17 15:48:18 UTC (rev 1147) @@ -36,6 +36,10 @@ openScriptNotFound.title=Script file not found openScriptNotFound.message=The file ''{0}'' does not exist.\nPlease correct the path. +# Treasure lists +treasurelistForbidden.title=Invalid Selection +treasurelistForbidden.message=The {0} treasurelists must not be used in maps.\nThese lists are reserved for internal use in the Crossfire server. + # Map Properties mapParametersTabTitle=Parameters mapShopTabTitle=Shop Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-17 15:48:18 UTC (rev 1147) @@ -53,6 +53,9 @@ createImgIOException.title=Kann Bild nicht erzeugen createImgIOException.message=Das Bild kann nicht erzeugt werden, da ein Ein-/Ausgabefehler\nbeim Schreiben von {0} aufgetreten ist:\n{1} +treasurelistForbidden.title=Ung\xFCltige Auswahl +treasurelistForbidden.message=Die Schatzliste {0} darf in Karten nicht verwendet werden.\nSie wird vom Crossfire-Server intern verwendet. + enterExitNoExit.title=Ausgang nicht gefunden enterExitNoExit.message=Die Auswahl enth\xE4lt keinen Ausgang. enterExitNowhere.title=Ziel ung\xFCltig Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 15:48:18 UTC (rev 1147) @@ -62,6 +62,7 @@ import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; import net.sf.gridarta.io.IOUtils; +import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.EnumerationIterator; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -75,6 +76,9 @@ private static final Logger log = Logger.getLogger(CFTreasureListTree.class); + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -661,7 +665,7 @@ // is selected, also return null because those must not be used on maps. final TreasureTreeNode trNode = (TreasureTreeNode) node; if (trNode.getTreasureObj().getType() == TreasureObj.FOLDER) { - JOptionPane.showMessageDialog(this, "The " + trNode.getTreasureObj().getName() + " treasurelists must not be used in maps.\nThese lists are reserved for internal use in the Daimonin server.", "Invalid Selection", JOptionPane.WARNING_MESSAGE); + ACTION_FACTORY.showMessageDialog(this, "treasurelistForbidden", trNode.getTreasureObj().getName()); return null; } Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/daimonin/src/daieditor/messages.properties 2006-12-17 15:48:18 UTC (rev 1147) @@ -96,6 +96,10 @@ loadDuplicateArch.title=Error: Duplicate arch loadDuplicateArch.message=Warning!\n\nDuplicate arch: ''{0}''\nFile: ''{1}''\nI will ignore this duplicate. +# Treasure lists +treasurelistForbidden.title=Invalid Selection +treasurelistForbidden.message=The {0} treasurelists must not be used in maps.\nThese lists are reserved for internal use in the Daimonin server. + # Map Properties mapMap=Map mapSound=Background sound Modified: trunk/daimonin/src/daieditor/messages_de.properties =================================================================== --- trunk/daimonin/src/daieditor/messages_de.properties 2006-12-17 15:30:30 UTC (rev 1146) +++ trunk/daimonin/src/daieditor/messages_de.properties 2006-12-17 15:48:18 UTC (rev 1147) @@ -35,6 +35,9 @@ overwriteOtherFile.title=Datei \xFCberschreiben? overwriteOtherFile.message=Eine Datei mit Namen "{0}" existiert bereits.\n\nWirklich \xFCberschreiben? +treasurelistForbidden.title=Ung\xFCltige Auswahl +treasurelistForbidden.message=Die Schatzliste {0} darf in Karten nicht verwendet werden.\nSie wird vom Crossfire-Server intern verwendet. + # New Map newMap.title=Neue Karte erstellen newPickmap.title=Neue Pickmap erstellen This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 15:50:48
|
Revision: 1148 http://svn.sourceforge.net/gridarta/?rev=1148&view=rev Author: akirschbaum Date: 2006-12-17 07:50:49 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Center error message on dialog box. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CFTreasureListTree.java Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 15:48:18 UTC (rev 1147) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 15:50:49 UTC (rev 1148) @@ -642,7 +642,7 @@ // is selected, also return null because those must not be used on maps. final TreasureTreeNode trNode = (TreasureTreeNode) node; if (trNode.getTreasureObj().getType() == TreasureObj.FOLDER) { - ACTION_FACTORY.showMessageDialog(this, "treasurelistForbidden", trNode.getTreasureObj().getName()); + ACTION_FACTORY.showMessageDialog(frame, "treasurelistForbidden", trNode.getTreasureObj().getName()); return null; } Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 15:48:18 UTC (rev 1147) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 15:50:49 UTC (rev 1148) @@ -665,7 +665,7 @@ // is selected, also return null because those must not be used on maps. final TreasureTreeNode trNode = (TreasureTreeNode) node; if (trNode.getTreasureObj().getType() == TreasureObj.FOLDER) { - ACTION_FACTORY.showMessageDialog(this, "treasurelistForbidden", trNode.getTreasureObj().getName()); + ACTION_FACTORY.showMessageDialog(frame, "treasurelistForbidden", trNode.getTreasureObj().getName()); return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-17 16:27:08
|
Revision: 1153 http://svn.sourceforge.net/gridarta/?rev=1153&view=rev Author: akirschbaum Date: 2006-12-17 08:27:08 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Unify comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-17 16:21:56 UTC (rev 1152) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-17 16:27:08 UTC (rev 1153) @@ -107,11 +107,11 @@ /** * Creates a DefaultLevelRenderer. - * @param mapViewBasic MapView to render. - * @param mainControl MainControl, used for getting icons and similar. - * @param mapControl MapControl of the map to render. + * @param mapViewBasic MapView to render + * @param mainControl MainControl, used for getting icons and similar + * @param mapControl MapControl of the map to render * @param pickmap <code>true</code> if the rendered map is a pickmap, otherwise <code>false</code> - * @param mapGrid Grid to render. + * @param mapGrid Grid to render */ public DefaultLevelRenderer(final CMapViewBasic mapViewBasic, final CMainControl mainControl, final MapControl mapControl, final boolean pickmap, final MapGrid mapGrid) { this.mapViewBasic = mapViewBasic; @@ -162,7 +162,7 @@ /** * Returns whether the rendered map is a pickmap. - * @return <code>true</code> if the rendered map is a pickmap, otherwise <code>false</code>. + * @return <code>true</code> if the rendered map is a pickmap, otherwise <code>false</code> */ public boolean isPickmap() { return isPickmap; @@ -228,7 +228,7 @@ /** * Paints this component. - * @param grfx The graphics context to paint to. + * @param grfx The graphics context to paint to * @param isSnapshot true when this drawing is for a * "screenshot"-image, false for normal drawing */ @@ -315,7 +315,7 @@ * Important: This method currently works only for standard * (rectangular) view. Iso has overlapping tiles which makes this a lot * more difficult. :( - * @param point Map coordinates for the tile to draw. + * @param point Map coordinates for the tile to draw */ @Override public void paintTile(final Point point) { final Graphics grfx; Modified: trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2006-12-17 16:21:56 UTC (rev 1152) +++ trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2006-12-17 16:27:08 UTC (rev 1153) @@ -98,10 +98,10 @@ /** * Creates a DefaultLevelRenderer. - * @param mainControl MainControl, used for getting icons and similar. - * @param mapControl MapControl of the map to render. + * @param mainControl MainControl, used for getting icons and similar + * @param mapControl MapControl of the map to render * @param pickmap <code>true</code> if the rendered map is a pickmap, otherwise <code>false</code> - * @param mapGrid Grid to render. + * @param mapGrid Grid to render */ public DefaultLevelRenderer(final CMainControl mainControl, final MapControl mapControl, final boolean pickmap, final MapGrid mapGrid) { this.mainControl = mainControl; @@ -178,8 +178,8 @@ } /** - * Returns whether the associated map is a pickmap. - * @return <code>true</code> if the associated map is a pickmap, otherwise <code>false</code>. + * Returns whether the rendered map is a pickmap. + * @return <code>true</code> if the rendered map is a pickmap, otherwise <code>false</code> */ public boolean isPickmap() { return isPickmap; @@ -236,7 +236,7 @@ /** * Paints this component. - * @param grfx The graphics context to paint to. + * @param grfx The graphics context to paint to */ private void paintComponent2(final Graphics2D grfx) { final long start = System.currentTimeMillis(); @@ -285,7 +285,7 @@ /** * Get smallest Rectangle on map that needs to be repaint. - * @param visRec visible Rectangle. + * @param visRec visible Rectangle * @return rectangle on the map. */ private Rectangle getRepaintRec(final Rectangle visRec) { @@ -470,7 +470,7 @@ /** * Sets the ArchObjects that are known to contain errors. - * @param erraneousArchObjects the ArchObjects that are known to contain errors. + * @param erraneousArchObjects the ArchObjects that are known to contain errors */ public void setErraneousArchObjects(final Map<net.sf.gridarta.gameobject.GameObject, ValidationError> erraneousArchObjects) { final Map<net.sf.gridarta.gameobject.GameObject, ValidationError> erraneousArchObjects1 = erraneousArchObjects; @@ -478,7 +478,7 @@ /** * Sets the MapSquares that are known to contain errors. - * @param erraneousMapSquares the MapSquares that are known to contain errors. + * @param erraneousMapSquares the MapSquares that are known to contain errors */ public void setErraneousMapSquares(final Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject>, ValidationError> erraneousMapSquares) { this.erraneousMapSquares = erraneousMapSquares; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-17 18:07:21
|
Revision: 1161 http://svn.sourceforge.net/gridarta/?rev=1161&view=rev Author: christianhujer Date: 2006-12-17 10:07:13 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Some unification of startup code (unfinnished). Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFJavaEditor.java trunk/daimonin/src/daieditor/CFJavaEditor.java Modified: trunk/crossfire/src/cfeditor/CFJavaEditor.java =================================================================== --- trunk/crossfire/src/cfeditor/CFJavaEditor.java 2006-12-17 17:22:53 UTC (rev 1160) +++ trunk/crossfire/src/cfeditor/CFJavaEditor.java 2006-12-17 18:07:13 UTC (rev 1161) @@ -52,7 +52,7 @@ * The main method that is invoked by the Java Runtime. * @param args The command line parameters given to the level editor. */ - public static void main(final String[] args) { + public static void main(final String... args) { // Make sure the locale is set before any ActionFactory is used. final String locName = CSettings.getInstance(IGUIConstants.APP_NAME).getProperty(PREFS_LANGUAGE, null); if (locName != null) { @@ -65,39 +65,49 @@ String outfile = null; // if specified in the parameters, create image of map and exit String inlist = null; boolean doShow = true; - boolean err = false; - - for (int i = 0; i < args.length; i++) { - // get command line parameters for "infile" (map to open initially) - // and "outfile" (image created from infile map) - if (args[i].compareTo("-infile") == 0 && i < args.length - 1) { - infiles.add(args[++i]); - } else if (args[i].compareTo("-outfile") == 0 && i < args.length - 1) { - outfile = args[++i]; - } else if (args[i].compareTo("-filelist") == 0 && i < args.length - 1) { - inlist = args[++i]; - } else if (args[i].compareTo("-nogui") == 0) { - doShow = false; - } else if (args[i].compareTo("--help") == 0 - || args[i].compareTo("-help") == 0 - || args[i].compareTo("-h") == 0) { - usage(); - System.exit(0); - } else if (args[i].compareTo("--") == 0) { - i++; - while (i < args.length) { - infiles.add(args[i++]); + boolean err = false; // whether a fatal error (exit required) occurred. + boolean exit = false; // whether to quit using System.exit(); + String op = null; // option, stored for error messages + try { // parse command line arguments + for (int i = 0; i < args.length; i++) { + final String arg = args[i]; + // get command line parameters for "infile" (map to open initially) + // and "outfile" (image created from infile map) + if (arg.equals("--help") || arg.equals("-h")) { + usage(); + return; + } else if (arg.equals(op = "--exit")) { + exit = true; + } else if (arg.equals(op = "--outfile") || arg.equals(op = "-o")) { + if (outfile != null) { + System.err.println("Warning: Option -outfile specified more than once. Overriding previous argument."); + } + outfile = args[++i]; + } else if (arg.equals(op = "--filelist")) { + inlist = args[++i]; + } else if (arg.equals(op = "--nogui")) { + doShow = false; + } else if (arg.equals("--")) { + while (++i < args.length) { + infiles.add(args[i]); + } + } else if (arg.startsWith("-")) { + System.err.println("Got unknown option: " + arg); + err = true; + } else { + infiles.add(arg); } - break; - } else if (!args[i].startsWith("-")) { - infiles.add(args[i]); - } else { - System.err.println("Got unknown option: " + args[i]); - err = true; } + } catch (final ArrayIndexOutOfBoundsException e) { + System.err.println("Missing argument for option " + op + '.'); + err = true; } if (err) { - System.exit(1); + if (exit) { + System.exit(1); + } else { + return; + } } if (inlist != null && infiles.size() > 0) { System.err.println("-filelist option and loading maps are mutually exclusive"); Modified: trunk/daimonin/src/daieditor/CFJavaEditor.java =================================================================== --- trunk/daimonin/src/daieditor/CFJavaEditor.java 2006-12-17 17:22:53 UTC (rev 1160) +++ trunk/daimonin/src/daieditor/CFJavaEditor.java 2006-12-17 18:07:13 UTC (rev 1161) @@ -26,6 +26,10 @@ import static daieditor.CMainControl.PREFS_LANGUAGE; import java.io.File; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -75,31 +79,46 @@ splashScreen.show(); final List<String> infiles = new ArrayList<String>(); // map file names to open initially String outfile = null; // if specified in the parameters, create image of map and exit + boolean err = false; // whether a fatal error (exit required) occurred. + boolean exit = false; // whether to quit using System.exit(); String op = null; // option, stored for error messages try { // parse command line arguments for (int i = 0; i < args.length; i++) { final String arg = args[i]; // get command line parameters for "infile" (map to open initially) // and "outfile" (image created from infile map) - if ("-help".equals(arg) || "--help".equals(arg) || "-h".equals(arg)) { - System.err.println("Usage: java -jar DaimoninEditor.jar [--outfile pngfile] [map file...]"); + if (arg.equals("--help") || arg.equals("-h")) { + usage(); return; - } else if (arg.equals(op = "-outfile") || arg.equals(op = "--outfile") || arg.equals(op = "-o")) { + } else if (arg.equals(op = "--exit")) { + exit = true; + } else if (arg.equals(op = "--outfile") || arg.equals(op = "-o")) { if (outfile != null) { System.err.println("Warning: Option -outfile specified more than once. Overriding previous argument."); } outfile = args[++i]; + } else if (arg.equals("--")) { + while (++i < args.length) { + infiles.add(args[i]); + } } else if (arg.startsWith("-")) { System.err.println("Got unknown option: " + arg); - return; + err = true; } else { infiles.add(arg); } } } catch (final ArrayIndexOutOfBoundsException e) { System.err.println("Missing argument for option " + op + '.'); - return; + err = true; } + if (err) { + if (exit) { + System.exit(1); + } else { + return; + } + } // print jre version, for easier recognition of jre-specific problems System.err.println("Running java version " + System.getProperty("java.version")); @@ -121,4 +140,53 @@ splashScreen.hide(); } + private static void makeImage(final CMainControl mainControl, final File in, final File out) { + if (log.isInfoEnabled()) { + log.info("converting " + in + " to " + out); + } + + if (in.canRead()) { + mainControl.openFile(in); + mainControl.createImageWanted(out); + mainControl.close(); + } + } + + private static void processFile(final CMainControl mainControl, final String filelist) { + try { + final BufferedReader reader = new BufferedReader(new FileReader(filelist)); + try { + while (true) { + final String in = reader.readLine(); + final String out = reader.readLine(); + if (in == null || out == null) { + log.info("done."); + System.exit(0); + } + makeImage(mainControl, new File(in), new File(out)); + } + } catch (final IOException e) { + log.info("done."); + System.exit(0); + } + } catch (final FileNotFoundException e) { + log.warn("Read error: ", e); + System.exit(-1); + } + System.exit(0); + } + + private static void usage() { + System.out.println("usage: java -jar DaimoninEditor.jar [option...] [mapfile...]"); + System.out.println(""); + System.out.println(" -filelist file convert images from file: first line is a mapfile, second"); + System.out.println(" line if a pngfile; file can contain any number of pairs to"); + System.out.println(" convert"); + System.out.println(" -help print this help"); + System.out.println(" -infile mapfile map name to load initially"); + System.out.println(" -nogui do not show gui window; only useful for converting maps"); + System.out.println(" -outfile pngfile png file name to convert map to; needs exactly one -infile"); + System.out.println(" or mapfile"); + } + } // class CFJavaEditor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-17 18:07:43
|
Revision: 1162 http://svn.sourceforge.net/gridarta/?rev=1162&view=rev Author: christianhujer Date: 2006-12-17 10:07:43 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Fix for bug introduced with commit #1143. Some unification of CFArchTypeList. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchTypeList.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-17 18:07:13 UTC (rev 1161) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-17 18:07:43 UTC (rev 1162) @@ -204,7 +204,11 @@ //typeNr = 0; // for invalid types, we take "type 0" boolean typeFound = false; int i = 0; + type = null; for (final CFArchType tmp : archTypeList) { + if (type == null) { + type = tmp; + } if (tmp.getTypeNr() == this.gameObject.getArchTypNr()) { if (tmp.getTypeAttr() == null) { // no type-attributes, so we only compared type-numbers @@ -252,9 +256,6 @@ } i++; } - if (!typeFound) { - type = archTypeList.getArchType(0); - } // get the type data //type = archTypeList.getType(typeNr); @@ -1348,7 +1349,7 @@ // deal with syntax errors now if (errors != null) { - if (typeStruct == archTypeList.getHead().getNext()) { + if (typeStruct == archTypeList.getArchType(1)) { // for generic (misc) type, all errors are automatically kept. // "misc" is no real type - it is more a default mask for unknown types gameObject.addObjectText(errors.trim()); Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2006-12-17 18:07:13 UTC (rev 1161) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2006-12-17 18:07:43 UTC (rev 1162) @@ -83,8 +83,6 @@ private final CFArchType defaultArchType; // contains default attributes - private CFArchType next = null; // next CFArchType in the list - private String desc = null; // descrption of this type private String use = null; // notes on usage of this type @@ -293,17 +291,19 @@ int importNum = 0; if (importName != null) { - CFArchType impType = tlist.getHead(); - boolean foundType = false; // search through all known types, looking for import type - for (; !foundType && impType != null && impType != this; - impType = foundType ? impType : impType.getNext()) { - if (impType.getTypeName().equalsIgnoreCase(importName)) { - foundType = true; + CFArchType impType = null; + for (final CFArchType archType : tlist) { + if (archType == this) { + continue; } + if (archType.typeName.equalsIgnoreCase(importName)) { + impType = archType; + break; + } } - if (foundType) { + if (impType != null) { // initialize array to store imported attribs importList = new CFArchAttrib[impType.attr.length]; @@ -412,21 +412,11 @@ /** * Create the documentation to this GameObject-type. * @return the full html-text to be (parsed and) displayed - * @fixme my HTML is broken */ public String createHtmlDocu() { return ACTION_FACTORY.format("arcDoc.htmlText", typeName, desc != null ? desc.trim() : "", use != null ? use.trim() : ""); } - // convenience functions: - public CFArchType getNext() { - return next; - } - - public void setNext(final CFArchType cfType) { - next = cfType; - } - public CFArchAttrib[] getAttr() { return attr; } Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 18:07:13 UTC (rev 1161) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 18:07:43 UTC (rev 1162) @@ -84,8 +84,6 @@ */ private Map<String, List<String>> ignoreListTable; - private int length = 0; // Number of types in the list - /** List of exit object types. (Integer values) */ private static final HashSet<Integer> EXIT_TYPES = new HashSet<Integer>(); @@ -180,7 +178,6 @@ // if we manage to parse it properly from the file if (head.load(elem, this)) { cfType = head; - //length++; // our list is now one element longer } } @@ -223,15 +220,14 @@ // attach the new CFArchType element to the list // if we manage to parse it properly from the file if (newType.load(elem, this)) { - cfType.setNext(newType); - cfType = cfType.getNext(); - length++; // our list is now one element longer + archTypeList.add(newType); + cfType = newType; } } } if (log.isInfoEnabled()) { - log.info("Loaded " + length + " types from '" + IGUIConstants.TYPEDEF_FILE + "'"); + log.info("Loaded " + archTypeList.size() + " types from '" + IGUIConstants.TYPEDEF_FILE + "'"); } } } finally { @@ -275,18 +271,6 @@ return list; } - /** - * Returns the number of CFArchTypes in this list (excluding the default type). - * @return The number of CFArchTypes in this list. - */ - public int getLength() { - return length; - } - - public CFArchType getHead() { - return head; - } - private void parseTypes(final Element root) { // parse all type elements final List entries = root.getChildren("type"); @@ -320,6 +304,10 @@ return bitmaskTable; } + public CFArchType getDefaultArchType() { + return defaultArchType; + } + /** * Return the ignore list table which contains all definitions of ignore lists for arch attributes. * @return ignore list table @@ -355,6 +343,15 @@ } /** + * Returns the number of CFArchTypes in the list. + * The default type is not counted. + * @return Number of CFArchTypes in the list. + */ + public int getLength() { + return archTypeList.size(); + } + + /** * Find and return the type-structure (<code>CFArchType</code>) that * matches for the given arch. This is not only a comparison between * type numbers - special type-attributes must also be dealt with. @@ -368,16 +365,11 @@ */ public CFArchType getTypeOfArch(final GameObject arch) { // check if the type of the object is present in the definitions - CFArchType tmp = head.getNext(); // tmp cycles through all types - CFArchType type = tmp; // return value: the type of the arch, first one (misc) if no other found - - boolean typeFound = false; - - for (int i = 0; tmp != null && !typeFound; tmp = tmp.getNext(), i++) { + for (final CFArchType tmp : archTypeList) { if (tmp.getTypeNr() == arch.getArchTypNr()) { if (tmp.getTypeAttr() == null) { // no type-attributes, so we only compared type-numbers - typeFound = true; + return tmp; } else { // check if all the type-attributes match @@ -396,18 +388,13 @@ // we've got a match after all if (match) { - typeFound = true; + return tmp; } } - - // we found our type - if (typeFound) { - type = tmp; // this is the type we are looking for - } } } - - return type; + // type of archobject not found - return first one (misc) + return archTypeList.get(0); } /** @@ -415,7 +402,7 @@ * @return <code>true</code> if this typelist contains no data, otherwise <code>false</code>. */ public boolean isEmpty() { - return head == null || head.getNext() == null; + return archTypeList.size() == 0; } /** @@ -429,18 +416,8 @@ */ public CFArchType getTypeByName(final String typeName) { // return: matching type or first type (misc) if no other found - CFArchType type = head.getNext(); - boolean typeFound = false; // true when type is found - - for (CFArchType tmp = type; tmp != null && !typeFound; tmp = tmp.getNext()) { - if (tmp.getTypeName().equals(typeName.trim())) { - // we found our type - type = tmp; - typeFound = true; - } - } - - return type; + final CFArchType type = archTypeNames.get(typeName.trim()); + return type == null ? archTypeList.get(0) : type; } } // class CFArchTypeList Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2006-12-17 18:07:13 UTC (rev 1161) +++ trunk/daimonin/src/daieditor/CFArchType.java 2006-12-17 18:07:43 UTC (rev 1162) @@ -277,14 +277,12 @@ // search through all known types, looking for import type CFArchType impType = null; for (final CFArchType archType : tlist) { - if (impType != null) { - break; - } if (archType == this) { continue; } if (archType.typeName.equalsIgnoreCase(importName)) { impType = archType; + break; } } Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-17 18:07:13 UTC (rev 1161) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2006-12-17 18:07:43 UTC (rev 1162) @@ -391,7 +391,7 @@ boolean match = true; for (int t = 0, l = numArgs * 2; t < l && match; t += 2) { final String archvalue = arch.getAttributeString(tmp.getTypeAttr()[t]); - if (!archvalue.equals(tmp.getTypeAttr()[t + 1]) && !("0".equals(tmp.getTypeAttr()[t + 1]) && archvalue.length() == 0)) { + if (!archvalue.equals(tmp.getTypeAttr()[t + 1]) && !(tmp.getTypeAttr()[t + 1].equals("0") && archvalue.length() == 0)) { match = false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-17 22:40:38
|
Revision: 1177 http://svn.sourceforge.net/gridarta/?rev=1177&view=rev Author: christianhujer Date: 2006-12-17 14:40:38 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Fixed imports and some javadoc issues. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchPanel.java trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainStatusbar.java trunk/crossfire/src/cfeditor/CMainToolbar.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapTileList.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CNewMapDialog.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/Spells.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/anim/AnimationObject.java trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java trunk/daimonin/src/daieditor/CFJavaEditor.java trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainStatusbar.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/ReplaceDialog.java trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java trunk/daimonin/src/daieditor/gui/map/MapUserListener.java trunk/daimonin/src/daieditor/gui/map/tools/ToolSelectorPane.java Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -26,11 +26,8 @@ import cfeditor.gameobject.GameObject; import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Dimension; import java.awt.Toolkit; -import java.util.ArrayList; -import java.util.List; import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.JSplitPane; Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -30,8 +30,6 @@ import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -43,7 +41,6 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JViewport; -import javax.swing.ListModel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -30,9 +30,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Iterator; import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.jdom.Attribute; Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -43,7 +43,6 @@ import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; Modified: trunk/crossfire/src/cfeditor/CMainStatusbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CMainStatusbar.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -40,8 +40,8 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * <code>CMainStatusbar</code> implements the main statusbar of the Modified: trunk/crossfire/src/cfeditor/CMainToolbar.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CMainToolbar.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -28,9 +28,9 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.InputEvent; import java.util.Enumeration; import java.util.Vector; import javax.swing.ButtonGroup; Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -31,8 +31,8 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; -import java.awt.Rectangle; import java.awt.Point; +import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; @@ -52,8 +52,8 @@ import javax.swing.JOptionPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; -import javax.swing.UIManager; import javax.swing.SwingConstants; +import javax.swing.UIManager; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; import net.sf.gridarta.gui.GSplitPane; @@ -162,7 +162,6 @@ /** * Constructs the main view and registers the given main controller. - * @param mainControl the controller of this view */ CMainView() { super(IGUIConstants.APP_NAME + " - " + IGUIConstants.APP_WINDOW_TITLE); Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -35,9 +35,9 @@ import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.InputEvent; import java.util.Date; import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; @@ -45,15 +45,14 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.SwingConstants; -import javax.swing.ScrollPaneConstants; import static javax.swing.JViewport.SIMPLE_SCROLL_MODE; +import javax.swing.ScrollPaneConstants; import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER; import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER; +import javax.swing.SwingConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gameobject.GameObjectContainer; -import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -31,10 +31,10 @@ import cfeditor.map.MapModel; import java.awt.Point; import java.awt.Rectangle; +import java.awt.event.InputEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; -import java.awt.event.InputEvent; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -581,7 +581,6 @@ * This method is only called for pickmaps. Take the currently * highlighted arch on the map (if any) and insert it on this pickmap. * @param pos tile-coordinates in pickmap - * @return array of coordinates for tiles that need to be redrawn */ private void insertMapArchToPickmap(final Point pos) { final MapControl currentMap = mainControl.getCurrentMap(); Modified: trunk/crossfire/src/cfeditor/CNewMapDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CNewMapDialog.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -28,10 +28,10 @@ import cfeditor.map.MapArchObject; import java.awt.Component; import java.awt.FlowLayout; -import java.util.Calendar; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.Calendar; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -26,15 +26,14 @@ package cfeditor; import cfeditor.gameobject.GameObject; -import cfeditor.map.DefaultMapModel; import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; import java.awt.Point; import java.awt.Rectangle; import java.util.HashSet; -import net.sf.gridarta.Size2D; import net.sf.gridarta.MainControl; +import net.sf.gridarta.Size2D; import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -24,7 +24,6 @@ package cfeditor; -import cfeditor.gameobject.GameObject; import cfeditor.gui.MapView; import cfeditor.map.MapControl; import java.awt.BorderLayout; Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -28,7 +28,6 @@ import cfeditor.map.MapControl; import java.awt.FlowLayout; import java.awt.Point; -import java.awt.Rectangle; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.ArrayList; @@ -45,7 +44,6 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; -import net.sf.gridarta.Size2D; import net.sf.gridarta.map.MapSquare; import net.sf.japi.swing.ActionFactory; Modified: trunk/crossfire/src/cfeditor/Spells.java =================================================================== --- trunk/crossfire/src/cfeditor/Spells.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/Spells.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -27,7 +27,6 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -52,8 +52,8 @@ import net.sf.gridarta.io.IOUtils; import net.sf.japi.swing.Progress; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * The <code>ArchetypeSet</code> contains all the Archetypes. Modified: trunk/crossfire/src/cfeditor/gameobject/anim/AnimationObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/anim/AnimationObject.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/gameobject/anim/AnimationObject.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -27,8 +27,8 @@ import java.io.Serializable; import javax.swing.ImageIcon; +import net.sf.gridarta.gameobject.NamedObject; import net.sf.gridarta.gameobject.anim.AbstractAnimationObject; -import net.sf.gridarta.gameobject.NamedObject; /** * A single animation object. Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -38,14 +38,8 @@ import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.MouseMotionListener; -import java.awt.geom.NoninvertibleTransformException; import java.awt.image.BufferedImage; -import java.util.Vector; import javax.swing.ImageIcon; -import javax.swing.JComponent; import net.sf.gridarta.Size2D; import net.sf.gridarta.gui.map.MapGrid; import net.sf.gridarta.gui.map.MapGridEvent; @@ -407,6 +401,8 @@ /** * Resize the backing buffer to the new grid size. + * It will only be resized if the map is not a pickmap. + * @return <code>true</code> if the back buffer was resized, otherwise <code>false</code>. */ private boolean resizeBackBuffer() { if (isPickmap) { Modified: trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/crossfire/src/cfeditor/gui/map/MapCursorControl.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -266,8 +266,8 @@ final boolean hasCursor = mapCursor != null && mapCursor.isActive(); - for (int direction = 0; direction < directionsGo.length; direction++) { - ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(hasCursor); + for (final String aDirectionsGo : directionsGo) { + ACTION_FACTORY.getAction(aDirectionsGo).setEnabled(hasCursor); } aSelectTile.setEnabled(hasCursor); aStartStopDrag.setEnabled(hasCursor); Modified: trunk/daimonin/src/daieditor/CFJavaEditor.java =================================================================== --- trunk/daimonin/src/daieditor/CFJavaEditor.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/CFJavaEditor.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -25,11 +25,11 @@ package daieditor; import static daieditor.CMainControl.PREFS_LANGUAGE; +import java.io.BufferedReader; import java.io.File; -import java.io.BufferedReader; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; -import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Locale; Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -48,7 +48,6 @@ import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; Modified: trunk/daimonin/src/daieditor/CMainStatusbar.java =================================================================== --- trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/CMainStatusbar.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -40,8 +40,8 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.japi.swing.ActionFactory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * <code>CMainStatusbar</code> implements the main statusbar of the Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -56,8 +56,8 @@ import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * <code>CMapViewBasic</code> is the true mapview object. However, it is not Modified: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -44,8 +44,8 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.WindowConstants; +import net.sf.gridarta.MainControl; import net.sf.gridarta.map.MapSquare; -import net.sf.gridarta.MainControl; import net.sf.japi.swing.ActionFactory; /** Modified: trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -36,9 +36,9 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; -import java.io.InputStream; import net.sf.gridarta.gameobject.face.AbstractFaceObjects; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.Progress; Modified: trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/gui/map/MapCursorControl.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -265,8 +265,8 @@ final boolean hasCursor = mapCursor != null && mapCursor.isActive(); - for (int direction = 0; direction < directionsGo.length; direction++) { - ACTION_FACTORY.getAction(directionsGo[direction]).setEnabled(hasCursor); + for (final String aDirectionsGo : directionsGo) { + ACTION_FACTORY.getAction(aDirectionsGo).setEnabled(hasCursor); } aSelectTile.setEnabled(hasCursor); aStartStopDrag.setEnabled(hasCursor); Modified: trunk/daimonin/src/daieditor/gui/map/MapUserListener.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapUserListener.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/gui/map/MapUserListener.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -28,10 +28,10 @@ import daieditor.gui.map.tools.ToolSelectorPane; import daieditor.map.MapControl; import java.awt.Point; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.awt.event.InputEvent; import net.sf.gridarta.gui.map.MapCursor; import org.jetbrains.annotations.Nullable; Modified: trunk/daimonin/src/daieditor/gui/map/tools/ToolSelectorPane.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/tools/ToolSelectorPane.java 2006-12-17 21:30:18 UTC (rev 1176) +++ trunk/daimonin/src/daieditor/gui/map/tools/ToolSelectorPane.java 2006-12-17 22:40:38 UTC (rev 1177) @@ -2,8 +2,8 @@ import daieditor.gui.map.event.MouseOpEvent; import java.awt.BorderLayout; +import java.awt.event.InputEvent; import java.awt.event.MouseEvent; -import java.awt.event.InputEvent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-18 21:24:13
|
Revision: 1186 http://svn.sourceforge.net/gridarta/?rev=1186&view=rev Author: akirschbaum Date: 2006-12-18 13:24:05 -0800 (Mon, 18 Dec 2006) Log Message: ----------- Remove useless comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-18 20:54:56 UTC (rev 1185) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-18 21:24:05 UTC (rev 1186) @@ -195,17 +195,14 @@ final Point startp = mapControl.getMapCursor().getLocation(); assert startp != null; - // cycle through all tile coordinates which are highlighted: mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); assert copyMap != null; for (final MapSquare<GameObject> square : copyMap) { pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); - // paste the archs if on the map: if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { if (!gameObject.isMulti()) { - // read gameObject from buffer and stick in on the map final GameObject clone = gameObject.createClone(pos.x, pos.y); mapControl.addArchObjectToMap(clone); } @@ -217,7 +214,7 @@ for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { pos.setLocation(startp); pos.translate(square.getMapX(), square.getMapY()); - if (mapControl.isPointValid(pos)) { // paste the archs if on the map: + if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { if (gameObject.isMulti()) { addArchToMap(mapControl, gameObject, pos, true, false); Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-18 20:54:56 UTC (rev 1185) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-18 21:24:05 UTC (rev 1186) @@ -195,17 +195,14 @@ final Point startp = mapControl.getMapCursor().getLocation(); assert startp != null; - // cycle through all tile coordinates which are highlighted: mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); assert copyMap != null; for (final MapSquare<GameObject> square : copyMap) { pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); - // paste the archs if on the map: if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { if (!gameObject.isMulti()) { - // read gameObject from buffer and stick in on the map addArchToMap(mapControl, gameObject, pos, true, false); // XXX Oh oh this looks BOGUS - shouldn't the object be cloned?! } } @@ -216,7 +213,7 @@ for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { pos.setLocation(startp); pos.translate(square.getMapX(), square.getMapY()); - if (mapControl.isPointValid(pos)) { // paste the archs if on the map: + if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { if (gameObject.isMulti()) { addArchToMap(mapControl, gameObject, pos, true, false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-18 21:29:14
|
Revision: 1187 http://svn.sourceforge.net/gridarta/?rev=1187&view=rev Author: akirschbaum Date: 2006-12-18 13:29:13 -0800 (Mon, 18 Dec 2006) Log Message: ----------- Fix mismatched x-/y-coordinates. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-18 21:24:05 UTC (rev 1186) +++ trunk/crossfire/ChangeLog 2006-12-18 21:29:13 UTC (rev 1187) @@ -1,5 +1,7 @@ 2006-12-18 Andreas Kirschbaum + * Fix crash when pasting multipart objects. + * Accelerate map drawing speed. 2006-12-17 Andreas Kirschbaum Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-18 21:24:05 UTC (rev 1186) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2006-12-18 21:29:13 UTC (rev 1187) @@ -304,11 +304,11 @@ private boolean isRectangular() { final int width = mapSize.getWidth(); final int height = mapSize.getHeight(); - if (mapGrid.length != height) { + if (mapGrid.length != width) { return false; } - for (int y = 0; y < height; y++) { - if (mapGrid[y].length != width) { + for (int x = 0; x < width; x++) { + if (mapGrid[x].length != height) { return false; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-19 00:13:57
|
Revision: 1188 http://svn.sourceforge.net/gridarta/?rev=1188&view=rev Author: akirschbaum Date: 2006-12-18 16:13:57 -0800 (Mon, 18 Dec 2006) Log Message: ----------- Properly enable/disable edit 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/MapViewIFrame.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/MapViewIFrame.java trunk/daimonin/src/daieditor/map/MapControl.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/ChangeLog 2006-12-19 00:13:57 UTC (rev 1188) @@ -1,3 +1,7 @@ +2006-12-19 Andreas Kirschbaum + + * Properly enable/disable edit menu entries. + 2006-12-18 Andreas Kirschbaum * Fix crash when pasting multipart objects. Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -2,6 +2,7 @@ * Crossfire Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -44,6 +45,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import javax.swing.Action; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JOptionPane; @@ -56,6 +58,10 @@ import net.sf.gridarta.gameobject.Collectable; import net.sf.gridarta.gameobject.Collector; import net.sf.gridarta.gui.HideFileFilterProxy; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.gui.map.MapGridEvent; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.gridarta.map.MapType; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; @@ -72,6 +78,7 @@ * The main controller of the level editor. Basically the main application. * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum */ public final class CMainControl implements ThrowableHandler, MainControl { @@ -181,6 +188,9 @@ private final MapCursorControl mapCursorControl; + /** Actions used by this instance. */ + private final MainActions mainActions = new MainActions(this); + /** Constructs the main controller and its model and view. */ public CMainControl() { instance = this; @@ -461,6 +471,10 @@ mainView.openHelpWindow(); } + /** + * Return the CopyBuffer instance. + * @return the CopyBuffer instance + */ public CopyBuffer getCopyBuffer() { return copybuffer; } @@ -706,6 +720,8 @@ final MapControl map = new MapControl(this, objects, maparch, false, initial); if (view) { + map.addMapGridListener(mainActions); + map.addMapCursorListener(mainActions); setStatusText("Creating new map " + maparch.getMapDisplayName()); mainView.addLevelView(map.getMapViewFrame()); // one view... map.getMapViewFrame().setAutoscrolls(true); @@ -1448,6 +1464,8 @@ mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); + + mainActions.currentMapChanged(); } /** Invoked when user wants to revert the current map to previously saved state. */ @@ -1495,126 +1513,7 @@ } } - /** "Clear" was selected from the Edit menu. */ - public void clear() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.clear(currentMap); - } - - /** "Cut" was selected from the Edit menu. */ - public void cut() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.cut(currentMap); - } - - /** "Copy" was selected from the Edit menu. */ - public void copy() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.copy(currentMap); - } - - /** "Paste" was selected from the Edit menu. */ - public void paste() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.paste(currentMap); - } - - /** "Fill above" was selected from the Edit menu. */ - public void fillAbove() { - fillWanted(false); - } - - /** "Fill below" was selected from the Edit menu. */ - public void fillBelow() { - fillWanted(true); - } - /** - * "Fill" was selected from the Edit menu. - * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" - */ - private void fillWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.fill(currentMap, fillBelow, -1); - } - - /** "Random fill above" was selected from the Edit menu. */ - public void randFillAbove() { - fillRandomWanted(false); - } - - /** "Random fill below" was selected from the Edit menu. */ - public void randFillBelow() { - fillRandomWanted(true); - } - - /** - * "RandomFill" was selected from the Edit menu. - * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" - */ - private void fillRandomWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - String input = "100"; - for (;;) { - input = (String) JOptionPane.showInputDialog(mainView, "Enter a fill density between 1-100", fillBelow ? "Random fill below" : "Random fill above", JOptionPane.QUESTION_MESSAGE, null, null, input); - if (input == null) { - break; - } - - int rand; - try { - rand = Integer.parseInt(input); - } catch (final NumberFormatException e) { - rand = -1; - } - if (rand < 1 || rand > 100) { - JOptionPane.showMessageDialog(mainView, "The fill density must be between 1-100.", "Illegal Value.", JOptionPane.ERROR_MESSAGE); - } else { - copybuffer.fill(currentMap, fillBelow, rand); - break; - } - } - } - - /** - * "Floodfill" was selected from the Edit menu. - */ - public void floodfill() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.floodfill(currentMap); - } - - /** "Replace" was selected from the Edit menu. */ - public void replace() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - ReplaceDialog.getInstance().display(currentMap); - } - - /** * Returns whether the CopyBuffer is empty. * @return <code>true</code> if the CopyBuffer is empty, otherwise <code>false</code>. */ @@ -1651,10 +1550,6 @@ CSettings.getInstance(IGUIConstants.APP_NAME).saveSettings(); } - public void refreshMenus() { - mainView.refreshMenus(); - } - /** Refreshes the state of menu items and toolbar buttons. */ public void refreshMenusAndToolbars() { mainView.refreshMenusAndToolbars(); @@ -1850,4 +1745,315 @@ refreshMenusAndToolbars(); } + /** + * Encapsulates actions and related functions. + */ + public static final class MainActions implements MapCursorListener, MapGridListener { + + /** The MainControl. */ + private final CMainControl mainControl; + + /** Action called for "clear". */ + private final Action aClear = ACTION_FACTORY.createAction(true, "clear", this); + + /** Action called for "cut". */ + private final Action aCut = ACTION_FACTORY.createAction(true, "cut", this); + + /** Action called for "copy". */ + private final Action aCopy = ACTION_FACTORY.createAction(true, "copy", this); + + /** Action called for "paste". */ + private final Action aPaste = ACTION_FACTORY.createAction(true, "paste", this); + + /** Action called for "replace". */ + private final Action aReplace = ACTION_FACTORY.createAction(true, "replace", this); + + /** Action called for "fill above". */ + private final Action aFillAbove = ACTION_FACTORY.createAction(true, "fillAbove", this); + + /** Action called for "fill below". */ + private final Action aFillBelow = ACTION_FACTORY.createAction(true, "fillBelow", this); + + /** Action called for "random fill above". */ + private final Action aRandFillAbove = ACTION_FACTORY.createAction(true, "randFillAbove", this); + + /** Action called for "random fill below". */ + private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", this); + + /** Action called for "floodfill". */ + private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", this); + + /** + * Create a new instance. + * + * @param mainControl the MainControl + */ + public MainActions(@NotNull final CMainControl mainControl) { + this.mainControl = mainControl; + } + + /** + * Enable/disable menu entries based on the current state. + */ + private void refreshMenus() { + aClear.setEnabled(isClearEnabled()); + aCut.setEnabled(isCutEnabled()); + aCopy.setEnabled(isCopyEnabled()); + aPaste.setEnabled(isPasteEnabled()); + aReplace.setEnabled(isReplaceEnabled()); + aFillAbove.setEnabled(isFillAboveEnabled()); + aFillBelow.setEnabled(isFillBelowEnabled()); + aRandFillAbove.setEnabled(isRandFillAboveEnabled()); + aRandFillBelow.setEnabled(isRandFillBelowEnabled()); + aFloodfill.setEnabled(isFloodfillEnabled()); + } + + /** + * Called when the current map of the attached MainControl has changed. + */ + public void currentMapChanged() { + refreshMenus(); + } + + /** {@inheritDoc} */ + public void mapGridChanged(@NotNull final MapGridEvent e) { + refreshMenus(); // selection state may have changed + } + + /** {@inheritDoc} */ + public void mapGridResized(@NotNull final MapGridEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + refreshMenus(); // cursor may have been activated or deactivated + } + + /** "Clear" was selected from the Edit menu. */ + public void clear() { + if (isClearEnabled()) { + mainControl.getCopyBuffer().clear(mainControl.getCurrentMap()); + } + } + + /** "Cut" was selected from the Edit menu. */ + public void cut() { + if (isCutEnabled()) { + mainControl.getCopyBuffer().cut(mainControl.getCurrentMap()); + } + } + + /** "Copy" was selected from the Edit menu. */ + public void copy() { + if (isCopyEnabled()) { + mainControl.getCopyBuffer().copy(mainControl.getCurrentMap()); + } + } + + /** "Paste" was selected from the Edit menu. */ + public void paste() { + if (isPasteEnabled()) { + mainControl.getCopyBuffer().paste(mainControl.getCurrentMap()); + } + } + + /** "Replace" was selected from the Edit menu. */ + public void replace() { + if (isReplaceEnabled()) { + ReplaceDialog.getInstance().display(mainControl.getCurrentMap()); + } + } + + /** "Fill above" was selected from the Edit menu. */ + public void fillAbove() { + if (isFillAboveEnabled()) { + fillWanted(false); + } + } + + /** "Fill below" was selected from the Edit menu. */ + public void fillBelow() { + if (isFillBelowEnabled()) { + fillWanted(true); + } + } + + /** + * "Fill" was selected from the Edit menu. + * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" + */ + private void fillWanted(final boolean fillBelow) { + mainControl.getCopyBuffer().fill(mainControl.getCurrentMap(), fillBelow, -1); + } + + /** "Random fill above" was selected from the Edit menu. */ + public void randFillAbove() { + if (isRandFillAboveEnabled()) { + fillRandomWanted(false); + } + } + + /** "Random fill below" was selected from the Edit menu. */ + public void randFillBelow() { + if (isRandFillBelowEnabled()) { + fillRandomWanted(true); + } + } + + /** + * "RandomFill" was selected from the Edit menu. + * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" + */ + private void fillRandomWanted(final boolean fillBelow) { + final MapControl currentMap = mainControl.getCurrentMap(); + + String input = "100"; + for (;;) { + input = (String) JOptionPane.showInputDialog(mainControl.getMainView(), "Enter a fill density between 1-100", fillBelow ? "Random fill below" : "Random fill above", JOptionPane.QUESTION_MESSAGE, null, null, input); + if (input == null) { + break; + } + + int rand; + try { + rand = Integer.parseInt(input); + } catch (final NumberFormatException e) { + rand = -1; + } + if (rand < 1 || rand > 100) { + JOptionPane.showMessageDialog(mainControl.getMainView(), "The fill density must be between 1-100.", "Illegal Value.", JOptionPane.ERROR_MESSAGE); + } else { + mainControl.getCopyBuffer().fill(currentMap, fillBelow, rand); + break; + } + } + } + + /** + * "Floodfill" was selected from the Edit menu. + */ + public void floodfill() { + if (isFloodfillEnabled()) { + mainControl.getCopyBuffer().floodfill(mainControl.getCurrentMap()); + } + } + + /** + * Determine if "clear" is enabled. + * @return <code>true</code> if "clear" is enabled, <code>false</code> + * otherwise + */ + private boolean isClearEnabled() { + return hasSelection(); + } + + /** + * Determine if "cut" is enabled. + * @return <code>true</code> if "cut" is enabled, <code>false</code> + * otherwise + */ + private boolean isCutEnabled() { + return hasSelection(); + } + + /** + * Determine if "copy" is enabled. + * @return <code>true</code> if "copy" is enabled, <code>false</code> + * otherwise + */ + private boolean isCopyEnabled() { + return hasSelection(); + } + + /** + * Determine if "paste" is enabled. + * @return <code>true</code> if "paste" is enabled, <code>false</code> + * otherwise + */ + private boolean isPasteEnabled() { + return hasCursor() && !mainControl.isCopyBufferEmpty(); + } + + /** + * Determine if "replace" is enabled. + * @return <code>true</code> if "replace" is enabled, + * <code>false</code> otherwise + */ + private boolean isReplaceEnabled() { + return mainControl.getCurrentMap() != null; + } + + /** + * Determine if "fill above" is enabled. + * @return <code>true</code> if "fill above" is enabled, + * <code>false</code> otherwise + */ + private boolean isFillAboveEnabled() { + return hasSelection(); + } + + /** + * Determine if "fill below" is enabled. + * @return <code>true</code> if "fill below" is enabled, + * <code>false</code> otherwise + */ + private boolean isFillBelowEnabled() { + return hasSelection(); + } + + /** + * Determine if "random fill above" is enabled. + * @return <code>true</code> if "random fill above" is enabled, + * <code>false</code> otherwise + */ + private boolean isRandFillAboveEnabled() { + return hasSelection(); + } + + /** + * Determine if "random fill below" is enabled. + * @return <code>true</code> if "random fill below" is enabled, + * <code>false</code> otherwise + */ + private boolean isRandFillBelowEnabled() { + return hasSelection(); + } + + /** + * Determine if "floodfill" is enabled. + * @return <code>true</code> if "floodfill" is enabled, + * <code>false</code> otherwise + */ + private boolean isFloodfillEnabled() { + return hasCursor(); + } + + /** + * Determine if the current map has a selection. + * @return <code>true</code> a selection exists, <code>false</code> + * otherwise + */ + private boolean hasSelection() { + final MapControl currentMap = mainControl.getCurrentMap(); + return currentMap != null && currentMap.hasSelection(); + } + + /** + * Determine if the current map has an active cursor. + * @return <code>true</code> a cursor exists, <code>false</code> + * otherwise + */ + private boolean hasCursor() { + final MapControl currentMap = mainControl.getCurrentMap(); + return currentMap != null && currentMap.hasCursor(); + } + + } // class MainActions + } // class CMainControl Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -843,26 +843,6 @@ private final Action aCreateImg = ACTION_FACTORY.createAction(true, "createImg", mainControl); - private final Action aClear = ACTION_FACTORY.createAction(true, "clear", mainControl); - - private final Action aCut = ACTION_FACTORY.createAction(true, "cut", mainControl); - - private final Action aCopy = ACTION_FACTORY.createAction(true, "copy", mainControl); - - private final Action aPaste = ACTION_FACTORY.createAction(true, "paste", mainControl); - - private final Action aReplace = ACTION_FACTORY.createAction(true, "replace", mainControl); - - private final Action aFillAbove = ACTION_FACTORY.createAction(true, "fillAbove", mainControl); - - private final Action aFillBelow = ACTION_FACTORY.createAction(true, "fillBelow", mainControl); - - private final Action aRandFillAbove = ACTION_FACTORY.createAction(true, "randFillAbove", mainControl); - - private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", mainControl); - - private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", mainControl); - private final Action aEnterExit = ACTION_FACTORY.createAction(true, "enterExit", mainControl); private final Action aTileShow = ACTION_FACTORY.createToggle(true, "tileShow", mainControl); @@ -933,22 +913,12 @@ aSaveAs.setEnabled(mapState); //aTileShow.setEnabled(mapState); aMapProperties.setEnabled(mapState); - aReplace.setEnabled(mapState); for (int direction = 0; direction < directionsMap.length; direction++) { final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } - aClear.setEnabled(selState); - aCut.setEnabled(selState); - aCopy.setEnabled(selState); - aFillAbove.setEnabled(selState); - aFillBelow.setEnabled(selState); - aRandFillAbove.setEnabled(selState); - aRandFillBelow.setEnabled(selState); - aFloodfill.setEnabled(selState); aEnterExit.setEnabled(selState); aRevert.setEnabled(mapState && fLevelEdited && mainControl.isPlainSaveEnabled()); - aPaste.setEnabled(selState && !mainControl.isCopyBufferEmpty()); aGridVisible.setEnabled(mapState); ((ToggleAction) aGridVisible).setSelected(mainControl.isGridVisible()); rebuildWindowMenu(); Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -50,6 +50,7 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -297,6 +298,14 @@ frame.updateTitle(); } + /** + * Get whether a selection exists. + * @return <code>true</code> if a selection exists, otherwise <code>false</code> + */ + public boolean hasSelection() { + return mapGrid.getSelectedRec() != null; + } + public Point[] getSelection() { final List<Point> selection = new ArrayList<Point>(); final Size2D mapSize = mapModel.getMapSize(); @@ -714,4 +723,30 @@ // Ignore mode change events } + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + mapGrid.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return mapCursor.isActive(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + mapCursor.addMapCursorListener(listener); + } + } // class CMapViewBasic Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -36,6 +36,8 @@ import javax.swing.JInternalFrame; import javax.swing.JViewport; import static javax.swing.KeyStroke.getKeyStroke; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.japi.swing.ActionFactory; /** @@ -201,6 +203,42 @@ return view; } + /** + * Determines if this map has an active selection. + * + * @return <code>true</code> if this map has an active selection, + * <code>false</code> otherwise + */ + public boolean hasSelection() { + return view.hasSelection(); + } + + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + view.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return view.hasCursor(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + view.addMapCursorListener(listener); + } + /** Action class for selecting this window. */ public final class WindowAction extends AbstractAction { Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -34,7 +34,9 @@ import java.util.List; import net.sf.gridarta.Size2D; import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.gui.map.MapGridListener; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -589,4 +591,40 @@ return mapModel.getMapArchObject(); } + /** + * Determines if this map has an active selection. + * + * @return <code>true</code> if this map has an active selection, + * <code>false</code> otherwise + */ + public boolean hasSelection() { + return mapViewFrame.hasSelection(); + } + + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + mapViewFrame.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return mapViewFrame.hasCursor(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + mapViewFrame.addMapCursorListener(listener); + } + } // class MapControl Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -3,6 +3,7 @@ * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl * Copyright (C) 2005 Christian Hujer + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -89,6 +90,7 @@ import java.util.prefs.Preferences; import static java.util.prefs.Preferences.userNodeForPackage; import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JOptionPane; @@ -98,6 +100,10 @@ import net.sf.gridarta.gameobject.Collectable; import net.sf.gridarta.gameobject.Collector; import net.sf.gridarta.gui.HideFileFilterProxy; +import net.sf.gridarta.gui.map.MapCursorEvent; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.gui.map.MapGridEvent; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -121,6 +127,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian.Hujer</a> + * @author Andreas Kirschbaum * @fixme I'm 2200 lines long, therefor I suck. */ public final class CMainControl implements ThrowableHandler, MapModelListener, MainControl { @@ -289,6 +296,9 @@ private final MapCursorControl mapCursorControl; + /** Actions used by this instance. */ + private final MainActions mainActions = new MainActions(this); + /** Constructs the main controller and its model and view. */ public CMainControl() { instance = this; @@ -656,6 +666,14 @@ mainView.openHelpWindow(); } + /** + * Return the CopyBuffer instance. + * @return the CopyBuffer instance + */ + public CopyBuffer getCopyBuffer() { + return copybuffer; + } + /** Set all global settings from the preferences. */ private void readGlobalSettings() { initDirs(); @@ -865,6 +883,8 @@ final MapControl map = new MapControl(this, objects, maparch, false, view); levels.add(map); if (view) { + map.addMapGridListener(mainActions); + map.addMapCursorListener(mainActions); setCurrentLevel(map); refreshMenusAndToolbars(); } @@ -1443,14 +1463,6 @@ showMapProperties(currentMap); } - /** Invoked when the user wants to select all squares from a map. */ - public void selectAll() { - if (currentMap == null) { - throw new IllegalStateException("BUG: selectAll was enabled without a current map. Please report this."); - } - currentMap.selectAll(); - } - /** * Shows the given levels properties. * @param level The level whose properties we want. @@ -1679,6 +1691,8 @@ mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); + + mainActions.currentMapChanged(); } /** Invoked when user wants to revert the current map to previously saved state. */ @@ -1728,147 +1742,7 @@ } } - /** "Clear" was selected from the Edit menu. */ - public void clear() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.clear(currentMap); - } - - /** "Cut" was selected from the Edit menu. */ - public void cut() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.cut(currentMap); - } - - /** "Copy" was selected from the Edit menu. */ - public void copy() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.copy(currentMap); - } - - /** "Paste" was selected from the Edit menu. */ - public void paste() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.paste(currentMap); - } - - /** "Fill above" was selected from the Edit menu. */ - public void fillAbove() { - fillWanted(false); - } - - /** "Fill below" was selected from the Edit menu. */ - public void fillBelow() { - fillWanted(true); - } - /** - * "Fill" was selected from the Edit menu. - * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" - */ - private void fillWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.fill(currentMap, fillBelow, null, -1); - } - - /** "Random fill above" was selected from the Edit menu. */ - public void randFillAbove() { - fillRandomWanted(false); - } - - /** "Random fill below" was selected from the Edit menu. */ - public void randFillBelow() { - fillRandomWanted(true); - } - - /** - * "RandomFill" was selected from the Edit menu. - * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" - */ - private void fillRandomWanted(final boolean fillBelow) { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - final StringBuilder title = new StringBuilder("Random fill "); - final GameObject arch = instance.getArchPanelHighlight(); - MapControl pmap = null; - - /* if we have a single arch, use it as random seed. - * We can throw the arch with % chance over the selected area. - * If the arch is null, we look we have a selected pickmap. - * if so, use the pickmap as random arch seed for the filler. - */ - if (arch != null) { - title.append("with arch ").append(arch.getArchetypeName()); - } else { - pmap = CPickmapPanel.getInstance().getCurrentPickmap(); - if (pmap != null) { - title.append("with pickmap ").append(pmap.getMapArch().getMapName()); - } else { // ok ,we have a problem here: arch == null, pmap == null... - // XXX but shouldn't be something told to the user? - // Not even a logging? - return; - } - } - final String input = JOptionPane.showInputDialog(mainView, "Enter a fill seed value between 1-100\n(default is 100%)", title.toString(), JOptionPane.QUESTION_MESSAGE); - if (input != null) { - int rand = 100; - if (input.trim().length() == 0) { - rand = 100; - } else { - try { - rand = Integer.parseInt(input); - if (rand < 0) { - rand = 1; - } - if (rand > 100) { - rand = 100; - } - } catch (final NumberFormatException e) { - JOptionPane.showMessageDialog(mainView, "You entered an illegal value", "Illegal Value.", JOptionPane.ERROR_MESSAGE); - } - } - copybuffer.fill(currentMap, fillBelow, pmap, rand); - } - } - - /** - * "Floodfill" was selected from the Edit menu. - */ - public void floodfill() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - copybuffer.floodfill(currentMap); - } - - /** "Replace" was selected from the Edit menu. */ - public void replace() { - if (currentMap == null || currentMap.getMapViewFrame() == null) { - return; // this should never be possible, but I just wanna make sure... - } - - ReplaceDialog.getInstance().display(currentMap); - } - - /** * Returns whether the CopyBuffer is empty. * @return <code>true</code> if the CopyBuffer is empty, otherwise <code>false</code>. */ @@ -2214,4 +2088,355 @@ } // class Recent + /** + * Encapsulates actions and related functions. + */ + public static final class MainActions implements MapCursorListener, MapGridListener { + + /** The MainControl. */ + private final CMainControl mainControl; + + /** Action called for "clear". */ + private final Action aClear = ACTION_FACTORY.createAction(true, "clear", this); + + /** Action called for "cut". */ + private final Action aCut = ACTION_FACTORY.createAction(true, "cut", this); + + /** Action called for "copy". */ + private final Action aCopy = ACTION_FACTORY.createAction(true, "copy", this); + + /** Action called for "paste". */ + private final Action aPaste = ACTION_FACTORY.createAction(true, "paste", this); + + /** Action called for "replace". */ + private final Action aReplace = ACTION_FACTORY.createAction(true, "replace", this); + + /** Action called for "fill above". */ + private final Action aFillAbove = ACTION_FACTORY.createAction(true, "fillAbove", this); + + /** Action called for "fill below". */ + private final Action aFillBelow = ACTION_FACTORY.createAction(true, "fillBelow", this); + + /** Action called for "random fill above". */ + private final Action aRandFillAbove = ACTION_FACTORY.createAction(true, "randFillAbove", this); + + /** Action called for "random fill below". */ + private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", this); + + /** Action called for "floodfill". */ + private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", this); + + /** Action called for "select all". */ + private final Action aSelectAll = ACTION_FACTORY.createAction(true, "selectAll", this); + + /** + * Create a new instance. + * + * @param mainControl the MainControl + */ + public MainActions(@NotNull final CMainControl mainControl) { + this.mainControl = mainControl; + } + + /** + * Enable/disable menu entries based on the current state. + */ + private void refreshMenus() { + aClear.setEnabled(isClearEnabled()); + aCut.setEnabled(isCutEnabled()); + aCopy.setEnabled(isCopyEnabled()); + aPaste.setEnabled(isPasteEnabled()); + aReplace.setEnabled(isReplaceEnabled()); + aFillAbove.setEnabled(isFillAboveEnabled()); + aFillBelow.setEnabled(isFillBelowEnabled()); + aRandFillAbove.setEnabled(isRandFillAboveEnabled()); + aRandFillBelow.setEnabled(isRandFillBelowEnabled()); + aFloodfill.setEnabled(isFloodfillEnabled()); + aSelectAll.setEnabled(isSelectAllEnabled()); + } + + /** + * Called when the current map of the attached MainControl has changed. + */ + public void currentMapChanged() { + refreshMenus(); + } + + /** {@inheritDoc} */ + public void mapGridChanged(@NotNull final MapGridEvent e) { + refreshMenus(); // selection state may have changed + } + + /** {@inheritDoc} */ + public void mapGridResized(@NotNull final MapGridEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + refreshMenus(); // cursor may have been activated or deactivated + } + + /** "Clear" was selected from the Edit menu. */ + public void clear() { + if (isClearEnabled()) { + mainControl.getCopyBuffer().clear(mainControl.getCurrentMap()); + } + } + + /** "Cut" was selected from the Edit menu. */ + public void cut() { + if (isCutEnabled()) { + mainControl.getCopyBuffer().cut(mainControl.getCurrentMap()); + } + } + + /** "Copy" was selected from the Edit menu. */ + public void copy() { + if (isCopyEnabled()) { + mainControl.getCopyBuffer().copy(mainControl.getCurrentMap()); + } + } + + /** "Paste" was selected from the Edit menu. */ + public void paste() { + if (isPasteEnabled()) { + mainControl.getCopyBuffer().paste(mainControl.getCurrentMap()); + } + } + + /** "Replace" was selected from the Edit menu. */ + public void replace() { + if (isReplaceEnabled()) { + ReplaceDialog.getInstance().display(mainControl.getCurrentMap()); + } + } + + /** "Fill above" was selected from the Edit menu. */ + public void fillAbove() { + if (isFillAboveEnabled()) { + fillWanted(false); + } + } + + /** "Fill below" was selected from the Edit menu. */ + public void fillBelow() { + if (isFillBelowEnabled()) { + fillWanted(true); + } + } + + /** + * "Fill" was selected from the Edit menu. + * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" + */ + private void fillWanted(final boolean fillBelow) { + mainControl.getCopyBuffer().fill(mainControl.getCurrentMap(), fillBelow, null, -1); + } + + /** "Random fill above" was selected from the Edit menu. */ + public void randFillAbove() { + if (isRandFillAboveEnabled()) { + fillRandomWanted(false); + } + } + + /** "Random fill below" was selected from the Edit menu. */ + public void randFillBelow() { + if (isRandFillBelowEnabled()) { + fillRandomWanted(true); + } + } + + /** + * "RandomFill" was selected from the Edit menu. + * @param fillBelow true if "Fill Below" was activated, false if "Fill Above" + */ + private void fillRandomWanted(final boolean fillBelow) { + final MapControl currentMap = mainControl.getCurrentMap(); + final StringBuilder title = new StringBuilder("Random fill "); + final GameObject arch = instance.getArchPanelHighlight(); + MapControl pmap = null; + + /* if we have a single arch, use it as random seed. + * We can throw the arch with % chance over the selected area. + * If the arch is null, we look we have a selected pickmap. + * if so, use the pickmap as random arch seed for the filler. + */ + if (arch != null) { + title.append("with arch ").append(arch.getArchetypeName()); + } else { + pmap = CPickmapPanel.getInstance().getCurrentPickmap(); + if (pmap != null) { + title.append("with pickmap ").append(pmap.getMapArch().getMapName()); + } else { // ok ,we have a problem here: arch == null, pmap == null... + // XXX but shouldn't be something told to the user? + // Not even a logging? + return; + } + } + final String input = JOptionPane.showInputDialog(mainControl.getMainView(), "Enter a fill seed value between 1-100\n(default is 100%)", title.toString(), JOptionPane.QUESTION_MESSAGE); + if (input != null) { + int rand = 100; + if (input.trim().length() == 0) { + rand = 100; + } else { + try { + rand = Integer.parseInt(input); + if (rand < 0) { + rand = 1; + } + if (rand > 100) { + rand = 100; + } + } catch (final NumberFormatException e) { + JOptionPane.showMessageDialog(mainControl.getMainView(), "You entered an illegal value", "Illegal Value.", JOptionPane.ERROR_MESSAGE); + } + } + mainControl.getCopyBuffer().fill(currentMap, fillBelow, pmap, rand); + } + } + + /** + * "Floodfill" was selected from the Edit menu. + */ + public void floodfill() { + if (isFloodfillEnabled()) { + mainControl.getCopyBuffer().floodfill(mainControl.getCurrentMap()); + } + } + + /** Invoked when the user wants to select all squares from a map. */ + public void selectAll() { + if (isSelectAllEnabled()) { + mainControl.getCurrentMap().selectAll(); + } + } + + /** + * Determine if "clear" is enabled. + * @return <code>true</code> if "clear" is enabled, <code>false</code> + * otherwise + */ + private boolean isClearEnabled() { + return hasSelection(); + } + + /** + * Determine if "cut" is enabled. + * @return <code>true</code> if "cut" is enabled, <code>false</code> + * otherwise + */ + private boolean isCutEnabled() { + return hasSelection(); + } + + /** + * Determine if "copy" is enabled. + * @return <code>true</code> if "copy" is enabled, <code>false</code> + * otherwise + */ + private boolean isCopyEnabled() { + return hasSelection(); + } + + /** + * Determine if "paste" is enabled. + * @return <code>true</code> if "paste" is enabled, <code>false</code> + * otherwise + */ + private boolean isPasteEnabled() { + return hasCursor() && !mainControl.isCopyBufferEmpty(); + } + + /** + * Determine if "replace" is enabled. + * @return <code>true</code> if "replace" is enabled, + * <code>false</code> otherwise + */ + private boolean isReplaceEnabled() { + return mainControl.getCurrentMap() != null; + } + + /** + * Determine if "fill above" is enabled. + * @return <code>true</code> if "fill above" is enabled, + * <code>false</code> otherwise + */ + private boolean isFillAboveEnabled() { + return hasSelection(); + } + + /** + * Determine if "fill below" is enabled. + * @return <code>true</code> if "fill below" is enabled, + * <code>false</code> otherwise + */ + private boolean isFillBelowEnabled() { + return hasSelection(); + } + + /** + * Determine if "random fill above" is enabled. + * @return <code>true</code> if "random fill above" is enabled, + * <code>false</code> otherwise + */ + private boolean isRandFillAboveEnabled() { + return hasSelection(); + } + + /** + * Determine if "random fill below" is enabled. + * @return <code>true</code> if "random fill below" is enabled, + * <code>false</code> otherwise + */ + private boolean isRandFillBelowEnabled() { + return hasSelection(); + } + + /** + * Determine if "floodfill" is enabled. + * @return <code>true</code> if "floodfill" is enabled, + * <code>false</code> otherwise + */ + private boolean isFloodfillEnabled() { + return hasCursor(); + } + + /** + * Determine if "select all" is enabled. + * @return <code>true</code> if "select all" is enabled, + * <code>false</code> otherwise + */ + private boolean isSelectAllEnabled() { + return mainControl.getCurrentMap() != null; + } + + /** + * Determine if the current map has a selection. + * @return <code>true</code> a selection exists, <code>false</code> + * otherwise + */ + private boolean hasSelection() { + final MapControl currentMap = mainControl.getCurrentMap(); + return currentMap != null && currentMap.hasSelection(); + } + + /** + * Determine if the current map has an active cursor. + * @return <code>true</code> a cursor exists, <code>false</code> + * otherwise + */ + private boolean hasCursor() { + final MapControl currentMap = mainControl.getCurrentMap(); + return currentMap != null && currentMap.hasCursor(); + } + + } // class MainActions + } // class CMainControl Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -748,28 +748,6 @@ private final Action aRedo = ACTION_FACTORY.createAction(true, "redo", mainControl); - private final Action aClear = ACTION_FACTORY.createAction(true, "clear", mainControl); - - private final Action aCut = ACTION_FACTORY.createAction(true, "cut", mainControl); - - private final Action aCopy = ACTION_FACTORY.createAction(true, "copy", mainControl); - - private final Action aPaste = ACTION_FACTORY.createAction(true, "paste", mainControl); - - private final Action aReplace = ACTION_FACTORY.createAction(true, "replace", mainControl); - - private final Action aFillAbove = ACTION_FACTORY.createAction(true, "fillAbove", mainControl); - - private final Action aFillBelow = ACTION_FACTORY.createAction(true, "fillBelow", mainControl); - - private final Action aRandFillAbove = ACTION_FACTORY.createAction(true, "randFillAbove", mainControl); - - private final Action aRandFillBelow = ACTION_FACTORY.createAction(true, "randFillBelow", mainControl); - - private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", mainControl); - - private final Action aSelectAll = ACTION_FACTORY.createAction(true, "selectAll", mainControl); - private final Action aEnterExit = ACTION_FACTORY.createAction(true, "enterExit", mainControl); private final Action aMapCreateView = ACTION_FACTORY.createAction(true, "mapCreateView", mainControl); @@ -828,23 +806,12 @@ //aSaveAs.setEnabled(fLevelEdited); aMapCreateView.setEnabled(mapState); aMapProperties.setEnabled(mapState); - aReplace.setEnabled(mapState); - aSelectAll.setEnabled(mapState); 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); } - aClear.setEnabled(selState); - aCut.setEnabled(selState); - aCopy.setEnabled(selState); - aFillAbove.setEnabled(selState); - aFillBelow.setEnabled(selState); - aRandFillAbove.setEnabled(selState); - aRandFillBelow.setEnabled(selState); - aFloodfill.setEnabled(selState); aEnterExit.setEnabled(selState); //aRevert.setEnabled(mapState && mainControl.getCurrentMap().isLevelChanged()); - aPaste.setEnabled(selState && !mainControl.isCopyBufferEmpty()); //aGridToggle.setEnabled(mapState); //((ToggleAction) aGridToggle).setSelected(mapState && mainControl.isGridVisible()); // FIXME IMPORTANT!!! rebuildWindowMenu(); Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -52,6 +52,7 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -455,4 +456,30 @@ // Ignore mode change events } + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + mapGrid.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return mapCursor.isActive(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + mapCursor.addMapCursorListener(listener); + } + } // class CMapViewBasic Modified: trunk/daimonin/src/daieditor/MapViewIFrame.java =================================================================== --- trunk/daimonin/src/daieditor/MapViewIFrame.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/daimonin/src/daieditor/MapViewIFrame.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -37,6 +37,8 @@ import javax.swing.ImageIcon; import javax.swing.JInternalFrame; import static javax.swing.KeyStroke.getKeyStroke; +import net.sf.gridarta.gui.map.MapCursorListener; +import net.sf.gridarta.gui.map.MapGridListener; /** * The <code>MapViewIFrame</code> is mainly a wrapper class which creates a @@ -152,6 +154,42 @@ return view; } + /** + * Determines if this map has an active selection. + * + * @return <code>true</code> if this map has an active selection, + * <code>false</code> otherwise + */ + public boolean hasSelection() { + return view.hasSelection(); + } + + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + view.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return view.hasCursor(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + view.addMapCursorListener(listener); + } + /** Action class for selecting this window. */ public final class WindowAction extends AbstractAction { Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-18 21:29:13 UTC (rev 1187) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-19 00:13:57 UTC (rev 1188) @@ -47,7 +47,9 @@ import javax.swing.ImageIcon; import net.sf.gridarta.Size2D; import net.sf.gridarta.gui.map.MapCursor; +import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.gui.map.MapGridListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -683,4 +685,40 @@ changed = true; } + /** + * Determines if this map has an active selection. + * + * @return <code>true</code> if this map has an active selection, + * <code>false</code> otherwise + */ + public boolean hasSelection() { + return mapViewFrame.hasSelection(); + } + + /** + * Register a MapGridListener. + * @param listener MapGridListener to register + */ + public void addMapGridListener(final MapGridListener listener) { + mapViewFrame.addMapGridListener(listener); + } + + /** + * Determines if this map has an active cursor. + * + * @return <code>true</code> if this map has an active cursor, + * <code>false</code> otherwise + */ + public boolean hasCursor() { + return mapViewFrame.hasCursor(); + } + + /** + * Register a MapCursorListener. + * @param listener MapCursorListener to register + */ + public void addMapCursorListener(final MapCursorListener listener) { + mapViewFrame.addMapCursorListener(listener); + } + } // class MapControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-19 00:27:26
|
Revision: 1189 http://svn.sourceforge.net/gridarta/?rev=1189&view=rev Author: akirschbaum Date: 2006-12-18 16:27:26 -0800 (Mon, 18 Dec 2006) Log Message: ----------- Add "select all" to edit menu. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/action.properties trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/messages.properties trunk/crossfire/src/cfeditor/messages_de.properties trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/ChangeLog 2006-12-19 00:27:26 UTC (rev 1189) @@ -1,5 +1,7 @@ 2006-12-19 Andreas Kirschbaum + * Add "select all" to edit menu. + * Properly enable/disable edit menu entries. 2006-12-18 Andreas Kirschbaum Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-19 00:27:26 UTC (rev 1189) @@ -1783,6 +1783,9 @@ /** Action called for "floodfill". */ private final Action aFloodfill = ACTION_FACTORY.createAction(true, "floodfill", this); + /** Action called for "select all". */ + private final Action aSelectAll = ACTION_FACTORY.createAction(true, "selectAll", this); + /** * Create a new instance. * @@ -1806,6 +1809,7 @@ aRandFillAbove.setEnabled(isRandFillAboveEnabled()); aRandFillBelow.setEnabled(isRandFillBelowEnabled()); aFloodfill.setEnabled(isFloodfillEnabled()); + aSelectAll.setEnabled(isSelectAllEnabled()); } /** @@ -1944,6 +1948,13 @@ } } + /** Invoked when the user wants to select all squares from a map. */ + public void selectAll() { + if (isSelectAllEnabled()) { + mainControl.getCurrentMap().selectAll(); + } + } + /** * Determine if "clear" is enabled. * @return <code>true</code> if "clear" is enabled, <code>false</code> @@ -2035,6 +2046,15 @@ } /** + * Determine if "select all" is enabled. + * @return <code>true</code> if "select all" is enabled, + * <code>false</code> otherwise + */ + private boolean isSelectAllEnabled() { + return mainControl.getCurrentMap() != null; + } + + /** * Determine if the current map has a selection. * @return <code>true</code> a selection exists, <code>false</code> * otherwise Modified: trunk/crossfire/src/cfeditor/action.properties =================================================================== --- trunk/crossfire/src/cfeditor/action.properties 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/src/cfeditor/action.properties 2006-12-19 00:27:26 UTC (rev 1189) @@ -10,7 +10,7 @@ main.menubar=file edit map cursor pickmaps resources tools analyze view plugins window help file.menu=createNew open close - save saveAs revert createImg - options - exit -edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow floodfill +edit.menu=clear cut copy paste - replace fillAbove fillBelow randFillAbove randFillBelow floodfill - selectAll map.menu=autoJoin - gridVisible enterExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterUpperMap enterLowerMap tileShow - mapProperties cursor.menu=moveCursor - selectTile startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes pickmaps.menu=lockAllPickmaps - addNewPickmap closePickmap - openPickmapMap - savePickmap revertPickmap @@ -73,7 +73,9 @@ floodfill.icon=EmptySmallIcon +selectAll.icon=EmptySmallIcon + mapProperties.icon=general/Properties16 Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-12-19 00:27:26 UTC (rev 1189) @@ -229,6 +229,13 @@ mapModel.deleteMapArch(gameObject, pos, join); } + /** + * Selects all. + */ + public void selectAll() { + getMapGrid().selectAll(); + } + public GameObject getMapArch(final GameObject gameObject, final Point pos) { return mapModel.getMapArch(gameObject, pos); } Modified: trunk/crossfire/src/cfeditor/messages.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages.properties 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/src/cfeditor/messages.properties 2006-12-19 00:27:26 UTC (rev 1189) @@ -175,7 +175,11 @@ floodfill.text=Flood Fill +selectAll.text=Select All +selectAll.mnemonic=S +selectAll.accel=ctrl pressed A + ####### # Map Modified: trunk/crossfire/src/cfeditor/messages_de.properties =================================================================== --- trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/crossfire/src/cfeditor/messages_de.properties 2006-12-19 00:27:26 UTC (rev 1189) @@ -399,7 +399,11 @@ floodfill.text=Freien Bereich f\xFCllen +selectAll.text=Alles ausw\xE4hlen +selectAll.mnemonic=W +selectAll.accel=ctrl pressed A + ####### # Map Modified: trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-19 00:13:57 UTC (rev 1188) +++ trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-12-19 00:27:26 UTC (rev 1189) @@ -487,12 +487,7 @@ /** Mark all tiles as selected. */ public void selectAll() { - for (int x = 0; x < gridSize.getWidth(); x++) { - for (int y = 0; y < gridSize.getHeight(); y++) { - gridFlags[x][y] |= GRID_FLAG_SELECTION; - } - } - fireMapGridChangedEvent(); + setFlags(0, 0, gridSize.getWidth() - 1, gridSize.getHeight() - 1, GRID_FLAG_SELECTION); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-19 23:47:59
|
Revision: 1191 http://svn.sourceforge.net/gridarta/?rev=1191&view=rev Author: christianhujer Date: 2006-12-19 15:47:59 -0800 (Tue, 19 Dec 2006) Log Message: ----------- Fix for Mantis #0000541: Pickmaps on windows are not selectable Modified Paths: -------------- trunk/daimonin/src/daieditor/CPickmapPanel.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java trunk/src/app/net/sf/gridarta/map/MapArchObject.java Modified: trunk/daimonin/src/daieditor/CPickmapPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CPickmapPanel.java 2006-12-19 00:41:14 UTC (rev 1190) +++ trunk/daimonin/src/daieditor/CPickmapPanel.java 2006-12-19 23:47:59 UTC (rev 1191) @@ -313,7 +313,9 @@ boolean foundMap = false; - final String newName = File.separator + tabpane.getTitleAt(tabpane.getSelectedIndex()); + // Fix for Mantis #0000541: pickmap selection doesn't work on windows + // This has to be a '/' always, even on Windows, because the pickmap filename is a URI. + final String newName = '/' + tabpane.getTitleAt(tabpane.getSelectedIndex()); for (MapControl tmp : pickmaps) { if (tmp != null && tmp.getMapFileName().endsWith(newName)) { Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-19 00:41:14 UTC (rev 1190) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-12-19 23:47:59 UTC (rev 1191) @@ -283,6 +283,7 @@ return mapModel.isCutoffSafe(size); } + // TODO: Rename because the filename is a URI now. public String getMapFileName() { return mapArch.getFileName(); } Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-12-19 00:41:14 UTC (rev 1190) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-12-19 23:47:59 UTC (rev 1191) @@ -16,6 +16,7 @@ @NotNull private String mapName = "<unnamed>"; /** The filename of this map. */ + // TODO: Rename because the filename is a URI now. @NotNull private String fileName = "<new map>"; /** The x coordinate for entering the map. */ @@ -76,6 +77,7 @@ } /** {@inheritDoc} */ + // TODO: Rename because the filename is a URI now. @NotNull public final String getFileName() { return fileName; } Modified: trunk/src/app/net/sf/gridarta/map/MapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2006-12-19 00:41:14 UTC (rev 1190) +++ trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2006-12-19 23:47:59 UTC (rev 1191) @@ -58,6 +58,7 @@ * @deprecated the filename isn't really an attribute of the MapArchObject. Only use MapControl for this. * @todo if this remains here, think whether the fileName is really not null or whether a nullable filename makes more sense. */ + // TODO: Rename because the filename is a URI now. @Deprecated @NotNull String getFileName(); /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-20 21:04:25
|
Revision: 1194 http://svn.sourceforge.net/gridarta/?rev=1194&view=rev Author: akirschbaum Date: 2006-12-20 13:04:22 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Add @Nullable annotation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CArchQuickView.java trunk/daimonin/src/daieditor/CArchQuickView.java Modified: trunk/crossfire/src/cfeditor/CArchQuickView.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-12-20 00:32:40 UTC (rev 1193) +++ trunk/crossfire/src/cfeditor/CArchQuickView.java 2006-12-20 21:04:22 UTC (rev 1194) @@ -31,6 +31,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; /** * The <code>CArchQuickView</code> holds the tile palette. @@ -92,9 +93,9 @@ * Show quick info for an object. * * @param gameObject the object to show; this may be any part of a multi-part - * object + * object, or <code>null</code> to clear the attributes */ - void showArchPanelQuickObject(final GameObject gameObject) { + void showArchPanelQuickObject(@Nullable final GameObject gameObject) { if (gameObject == null) { archObjNameText.setText(null); archArchNameText.setText(null); Modified: trunk/daimonin/src/daieditor/CArchQuickView.java =================================================================== --- trunk/daimonin/src/daieditor/CArchQuickView.java 2006-12-20 00:32:40 UTC (rev 1193) +++ trunk/daimonin/src/daieditor/CArchQuickView.java 2006-12-20 21:04:22 UTC (rev 1194) @@ -31,6 +31,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import net.sf.gridarta.gameobject.Archetype; +import org.jetbrains.annotations.Nullable; /** * The <code>CArchQuickView</code> holds the tile palette. @@ -92,9 +93,9 @@ * Show quick info for an object. * * @param gameObject the object to show; this may be any part of a multi-part - * object + * object, or <code>null</code> to clear the attributes */ - void showArchPanelQuickObject(final GameObject gameObject) { + void showArchPanelQuickObject(@Nullable final GameObject gameObject) { if (gameObject == null) { if (mainControl.getMainView().isPickmapActive()) { archObjNameText.setText(" -random pick- "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-20 21:06:51
|
Revision: 1195 http://svn.sourceforge.net/gridarta/?rev=1195&view=rev Author: akirschbaum Date: 2006-12-20 13:06:50 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Sort archetypes in archetype panel by name. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CArchPanel.java trunk/crossfire/src/cfeditor/CArchPanelPan.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/CArchPanel.java trunk/daimonin/src/daieditor/CArchPanelPan.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/ChangeLog 2006-12-20 21:06:50 UTC (rev 1195) @@ -1,3 +1,7 @@ +2006-12-20 Andreas Kirschbaum + + * Sort archetypes in archetype panel by name. + 2006-12-19 Andreas Kirschbaum * Add "select all" to edit menu. Modified: trunk/crossfire/src/cfeditor/CArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/CArchPanel.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -2,6 +2,7 @@ * Crossfire Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -36,12 +37,14 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.gridarta.gui.GSplitPane; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * The <code>CArchPanel</code> holds the tile palette. * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum */ public final class CArchPanel extends JPanel { @@ -57,16 +60,16 @@ * Name of the selected archetype. * @serial include */ - private String selectedArch; + private GameObject selectedArch = null; /** Panel holding both archlist and pickmaps. */ - private final JTabbedPane archAndPickPane; + private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); /** Our split pane. */ private final GSplitPane splitPane; /** The Tab panel with arch lists. */ - private final JTabbedPane tabDesktop; + private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); /** The data/view of selected objects in tab panel. */ private final CArchQuickView archQuickPanel; @@ -81,14 +84,11 @@ public CArchPanel(final CMainControl mainControl) { super(new BorderLayout()); this.mainControl = mainControl; - selectedArch = null; - tabDesktop = new JTabbedPane(SwingConstants.TOP); tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); archQuickPanel = new CArchQuickView(mainControl); // archAndPickPane is the panel containing both archpanel and pickmaps - archAndPickPane = new JTabbedPane(SwingConstants.TOP); archAndPickPane.addTab("Arch List", tabDesktop); archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); // this listener informs the mainview which panel is active: archlist or pickmaps? @@ -107,27 +107,42 @@ /** Move the pickmap panel in front of the default-archpanel. */ public void movePickmapPanelToFront() { - if (archAndPickPane != null && archAndPickPane.getTabCount() > 1) { - archAndPickPane.setSelectedIndex(1); - } + archAndPickPane.setSelectedIndex(1); } + /** + * Get the currently selected archetype. + * + * @return the selected archetype, or <code>null</code> if none is selected + */ @Nullable public GameObject getArchPanelSelection() { return selectedPanel != null ? selectedPanel.getArchListObject() : null; } - public void showArchPanelQuickObject(final GameObject gameObject) { + /** + * Show the given game object's attributes in the quick panel. + * + * @param gameObject the game object to show, or <code>null</code> to clear + * the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { archQuickPanel.showArchPanelQuickObject(gameObject); } - public int addArchPanelCombo(final String name) { - return selectedPanel.addArchPanelCombo(name); + /** + * Add a new archetype. Create the panel and/or folder if necessary. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + final CArchPanelPan panel = findOrCreatePanel(panelName); + panel.addArchetype(folderName, arch); } - public void addArchPanelArch(final String archetypeName, final int index) { - selectedPanel.addArchPanelArch(archetypeName, index); - } - /** * Sets the enabled state of the tab pane for Archetypes. * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. @@ -139,19 +154,30 @@ } } - public void addPanel(final String name) { - final CArchPanelPan newnode = new CArchPanelPan(this, mainControl); + /** + * Return a panel by name. If this panel does not exist, create a new one. + * + * @param panelName the panel name + * + * @return the panel + */ + @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + if (panelName.equals(tabDesktop.getTitleAt(i))) { + return (CArchPanelPan) tabDesktop.getComponentAt(i); + } + } - // insert new panels in alphabetical order + final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + + // insert new panel in alphabetical order int i; - for (i = 0; i < tabDesktop.getTabCount() && name.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { + for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { ; } - tabDesktop.insertTab(name, null, newnode, null, i); + tabDesktop.insertTab(panelName, null, newPanel, null, i); - // careful: during the build process we are setting 'selectedPanel' - // in spite of the fact that this panel might *not* actually be selected - selectedPanel = newnode; + return newPanel; } /** @@ -160,6 +186,10 @@ * setting and make sure the arch list is properly drawn. */ public void finishBuildProcess() { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + } + selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); if (selectedPanel != null) { selectedPanel.showArchList(); @@ -169,17 +199,6 @@ tabDesktop.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); - selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - } - }); - - // we must set the list of the selected list depend on combo selection - tabDesktop.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); setSelectedArch(null); selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); if (selectedPanel != null) { @@ -198,15 +217,15 @@ * Get name of selected Arch. * @return Name of selected arch in arch panel */ - public String getSelectedArch() { - return selectedArch; + @Nullable public String getSelectedArch() { + return selectedArch == null ? null : selectedArch.getArchetypeName(); } /** * Set selected Arch. * @param selectedArch name of selected arch in arch panel */ - public void setSelectedArch(final String selectedArch) { + public void setSelectedArch(@Nullable final GameObject selectedArch) { this.selectedArch = selectedArch; } Modified: trunk/crossfire/src/cfeditor/CArchPanelPan.java =================================================================== --- trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/CArchPanelPan.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -2,6 +2,7 @@ * Crossfire Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -31,9 +32,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.Comparator; +import java.util.TreeSet; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.JComboBox; @@ -45,8 +45,13 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * @author unknown + * @author Andreas Kirschbaum + */ public final class CArchPanelPan extends JPanel { private static final Logger log = Logger.getLogger(CArchPanelPan.class); @@ -57,10 +62,18 @@ /** Controller of this subview. */ private final CMainControl mainControl; - /** Maps index to list of archetype names. */ - private Map<Integer, ArrayList<String>> archLists = new HashMap<Integer, ArrayList<String>>(); + /** + * List of archetypes for each folder. The folders correspond to the + * entries in {@link #comboBox}. + * @note The first entry is always <code>null</code>. + */ + private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); - private final JList theList; + /** + * The list of currently shown archetypes; it is updated from {@link + * #folders} each time a new folder is selected. + */ + private final JList archList; private final DefaultListModel model; @@ -68,6 +81,22 @@ private final CArchPanel archPanel; + /** + * Comparator used to sort entries shown in {@link archList}. + */ + private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() + { + public int compare(final GameObject o1, final GameObject o2) { + return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); + } + }; + + /** + * Temporary variable used to collect and sort the archeteypes to be + * inserted into {@link #archList}. + */ + private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); + /* Build Panel */ CArchPanelPan(final CArchPanel controlPanel, final CMainControl mainControl) { super(new BorderLayout()); @@ -77,27 +106,29 @@ comboBox = new JComboBox(); model = new DefaultListModel(); - theList = new JList(model); - theList.setCellRenderer(new MyCellRenderer()); - theList.setBackground(IGUIConstants.BG_COLOR); - theList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - final JScrollPane scrollPane = new JScrollPane(theList); + archList = new JList(model); + archList.setCellRenderer(new MyCellRenderer()); + archList.setBackground(IGUIConstants.BG_COLOR); + archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final JScrollPane scrollPane = new JScrollPane(archList); add(scrollPane, BorderLayout.CENTER); add(comboBox, BorderLayout.NORTH); scrollPane.setAutoscrolls(true); scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); comboBox.setAutoscrolls(true); + } + public void finishBuildProcess() { comboBox.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { showArchList(); } }); - theList.addListSelectionListener(new ListSelectionListener() { + archList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { - showArchListObject(e.getFirstIndex()); + updateSelectedArchListObject(); } }); } @@ -107,84 +138,90 @@ * @return GameObject or <code>null</code> if no selection */ public GameObject getArchListObject() { - return getArchListObject(theList.getSelectedIndex()); + return (GameObject) archList.getSelectedValue(); } /** - * Get the GameObject from the list. - * @param index Index of selected list element or <code>-1</code> for no selection. - * @return GameObject or <code>null</code> if <var>index</var> was <code>-1</code> + * Show the selected archetype. */ - @Nullable private GameObject getArchListObject(final int index) { - GameObject archetype = null; - if (index != -1) { - archetype = mainControl.getArchetypeSet().getArchetype((String) theList.getSelectedValue()); - } - return archetype; + private void updateSelectedArchListObject() { + final GameObject archetype = (GameObject) archList.getSelectedValue(); + mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); + archPanel.setSelectedArch(archetype); + mainControl.showArchPanelQuickObject(archetype); } - private void showArchListObject(int index) { - GameObject archetype = null; - String archetypeName = null; - if (0 <= index && index < model.getSize()) { - archetypeName = (String) theList.getSelectedValue(); - if (archetypeName != null) { - archetype = mainControl.getArchetypeSet().getArchetype(archetypeName); - archPanel.setSelectedArch(archetypeName); - } - } - mainControl.setStatusText(archetypeName == null ? "" : archetypeName); - mainControl.showArchPanelQuickObject(archetype); // send it to quick view + /** + * Add an archetype to this panel. + * + * @param folderName the folder to add it to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { + final ArrayList<GameObject> folder = findOrCreateFolder(folderName); + folder.add(arch); } /** - * Add this arch to list of (this) Jlist list. - * @param archetypeName name of the archetype to add - * @param index index of subdir where to add + * Return a folder by name. If this folder does not exist, create a new one. + * + * @param folderName the folder name + * + * @return the folder */ - public void addArchPanelArch(final String archetypeName, final int index) { - final ArrayList<String> tmp = archLists.get(index); - final ArrayList<String> archList; - if (tmp == null) { - archList = new ArrayList<String>(); - archLists.put(index, archList); - } else { - archList = tmp; + @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { + assert folders.size() == comboBox.getItemCount(); + for (int i = 1; i < folders.size(); i++) { + if (folderName.equals(comboBox.getItemAt(i))) { + return folders.get(i); + } } - archList.add(archetypeName); + if (folders.size() <= 0) { + comboBox.addItem("show all"); + folders.add(null); // first entry is always empty + } + + // insert new folder in alphabetical order + int i; + for (i = 1; i < folders.size(); i++) { + if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { + break; + } + } + + final ArrayList<GameObject> folder = new ArrayList<GameObject>(); + comboBox.insertItemAt(folderName, i); + folders.add(i, folder); + + return folder; } /** - * Add a new category to the combo box. - * - * @param name the name of the combo box to create - * - * @return the combo box index + * Update {@link #archList} to contain the currently selected folder. */ - public int addArchPanelCombo(final String name) { - comboBox.addItem(name); - return comboBox.getItemCount() - 1; - } - public void showArchList() { final int index = comboBox.getSelectedIndex(); - model.removeAllElements(); + sortedArchetypes.clear(); if (index == 0) { - for (final List<String> archList : archLists.values()) { - for (final String archName : archList) { - model.addElement(archName); - } + for (int i = 1; i < folders.size(); i++) { + sortedArchetypes.addAll(folders.get(i)); } } else if (index > 0) { - final List<String> archList = archLists.get(index); + final ArrayList<GameObject> archList = folders.get(index); if (archList != null) { - for (final String archName : archList) { - model.addElement(archName); - } + sortedArchetypes.addAll(archList); } } + + archList.setVisible(false); + model.removeAllElements(); + for (final GameObject arch : sortedArchetypes) { + model.addElement(arch); + } + archList.setVisible(true); } /** Cell Renderer for rendering cells in the ArchPanelPan. */ @@ -198,11 +235,8 @@ public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - final ArchetypeSet archetypeSet = mainControl.getArchetypeSet(); - final String archetypeName = (String) value; - final GameObject archetype = archetypeSet.getArchetype(archetypeName); - assert archetype != null : "Archetype not found: " + archetypeName; - setText(archetypeName); + final GameObject archetype = (GameObject) value; + setText(archetype.getArchetypeName()); if (archetype.getFaceFlag()) { setIcon(CMainControl.getNofaceTileIcon()); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -611,20 +611,21 @@ mainView.setTabPaneEnabled(tabPaneEnabled); } - /** {@inheritDoc} */ - public void addArchPanel(@NotNull final String name) { - mainView.addArchPanel(name); + /** + * Add an archetype to the archetype panel. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + * + * @deprecated this has nothing to do with MainControl and should be refactored + */ + public void addArchPanelArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + mainView.addArchPanelArchetype(panelName, folderName, arch); } - /** {@inheritDoc} */ - public int addArchPanelCombo(@NotNull final String name) { - return mainView.addArchPanelCombo(name); - } - - public void addArchPanelArch(final String archname, final int index) { - mainView.addArchPanelArch(archname, index); - } - /** * Return name of the selected arch in arch panel. * @return name of selected arch in arch panel Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -61,6 +61,7 @@ import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ToggleAction; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -390,10 +391,6 @@ return mapTileList.getMapTileSelection(); } - public void addArchPanel(final String name) { - archPanel.addPanel(name); - } - /** * Sets the enabled state of the tab pane for Archetypes. * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it @@ -402,14 +399,19 @@ archPanel.setTabPaneEnabled(tabPaneEnabled); } - public int addArchPanelCombo(final String name) { - return archPanel.addArchPanelCombo(name); + /** + * Add an archetype to the archetype panel. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + */ + public void addArchPanelArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + archPanel.addArchetype(panelName, folderName, arch); } - public void addArchPanelArch(final String archname, final int index) { - archPanel.addArchPanelArch(archname, index); - } - /** * Return the name of the selected arch in arch panel. * @return name of selected arch in arch panel Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -42,6 +42,7 @@ import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -150,12 +151,12 @@ } /** {@inheritDoc} */ - public void parseArchetype(final String fname, final int index) { + public void parseArchetype(final String fname, @NotNull final String panelName, @NotNull final String folderName) { //Open the file for reading try { final BufferedReader in = new BufferedReader(new FileReader(fname)); try { - parseArchetypeFromStream(in, index, fname); + parseArchetypeFromStream(in, panelName, folderName, fname); } finally { in.close(); } @@ -168,7 +169,7 @@ /** {@inheritDoc} */ @Nullable - public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject prototype, @Nullable final String line, @Nullable final String archName, int index, final String fname) throws IOException { + public GameObject parseArchetypeFromStream(final BufferedReader in, @Nullable final GameObject prototype, @Nullable final String line, @Nullable final String archName, @NotNull final String panelName, @NotNull final String folderName, final String fname) throws IOException { // start with new clean GameObject instance GameObject archetype; GameObject archlast = null; @@ -186,15 +187,13 @@ thisLine2 = line; // pre read "Object" from artifacts file loader } - boolean isNewCategory = true; - String oldCat = "<xxx>"; GameObject firstArch = null; boolean archmore = false; boolean parsearch = false; boolean animflag = false; boolean msgflag = false; boolean loreflag = false; - String newCat = "no category info"; + String editorFolder = null; while (thisLine2 != null) { final String thisLine = thisLine2.trim(); @@ -271,48 +270,25 @@ } else { // add arch to the archpanel - only if it is not the map arch if (!archetype.getArchetypeName().equals(STARTARCH_NAME)) { + final String panel; + final String folder; if (!mainControl.getArchetypeSet().isLoadedFromArchive() || archName != null) { - // loading from individual files, so we simply add it to list - // ArchetypeSet.loadArchFromFiles() takes care of the panels - mainControl.addArchPanelArch(archetype.getArchetypeName(), index); + panel = panelName; + folder = folderName; } else { - // loading from collected files, so we need process panels here - if (isNewCategory) { - String folder = newCat; // main folder of new category - if (newCat.indexOf("/") > 0) { - folder = newCat.substring(0, newCat.indexOf("/")); - } - - if (!oldCat.startsWith(folder)) { - // an entire new panel must be opened - mainControl.addArchPanel(folder); - mainControl.addArchPanelCombo("show all"); - mainControl.addArchPanelCombo(folder); - index = 1; - } - - if (newCat.indexOf("/") > 0) { - folder = newCat.substring(newCat.indexOf("/") + 1); - if (newCat.startsWith(folder)) { - index = 1; // add to the base folder - } else if (!oldCat.endsWith(folder)) { - // a new JComboBox must be added - index = mainControl.addArchPanelCombo(folder); - } - } else { - index = 1; // add to the base folder - } - - isNewCategory = false; - oldCat = newCat; + if (editorFolder == null) { + editorFolder = "default"; } - mainControl.addArchPanelArch(archetype.getArchetypeName(), index); + final String[] names = editorFolder.split("/", 3); + panel = names[0]; + folder = names.length >= 2 ? names[1] : names[0]; } + mainControl.addArchPanelArchetype(panel, folder, archetype); } } postParseArchetype(archetype); archetype.setIsArchetype(); - archetype.setEditorFolder(newCat); + archetype.setEditorFolder(editorFolder); mainControl.getArchetypeSet().addArchetype(archetype); archmore = false; // we assume this is last... but perhaps.. @@ -388,11 +364,7 @@ archetype.setFaceFlag(false); // we HAVE a face archetype.setFaceName(thisLine.substring(x, thisLine.length())); } else if (thisLine.startsWith("editor_folder ")) { - // the display category (= "folder" the arch belongs to) - newCat = thisLine.substring(14).trim(); - if (!newCat.equals(oldCat)) { - isNewCategory = true; // this arch has a new category - } + editorFolder = thisLine.substring(14).trim(); } archetype.addObjectText(thisLine); if (log.isDebugEnabled()) { Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -76,8 +76,6 @@ private final CMainControl mainControl; - private int folderLevel; - /** * Create the ArchetypeSet. * @param mainControl reference to CMainControl @@ -132,14 +130,13 @@ // browse arch archive // load object from a arch file you found final File f = new File(mainControl.getArchDefaultFolder()); - folderLevel = 0; mainControl.setTabPaneEnabled(false); // here we go... if (mainControl.isArchLoadedFromCollection()) { loadArchFromCollected(); // collect arches & images from collection } else { - loadArchetypesFromFiles(f, 0); // collect arches & images from individual files + loadArchetypesFromFiles(f, 0, "default", "default"); // collect arches & images from individual files } mainControl.setStatusText("Sorting..."); @@ -187,7 +184,7 @@ final BufferedReader stream = IOUtils.createReader(IGUIConstants.CONFIG_DIR, IGUIConstants.ARCH_FILE); try { // load all arches - mainControl.getArchetypeParser().parseArchetypeFromStream(stream, 0, null); + mainControl.getArchetypeParser().parseArchetypeFromStream(stream, "default", "default", null); } finally { // close filestream stream.close(); @@ -202,34 +199,25 @@ * This method loads the arches & faces recursively by looping through * the arch folder, collecting all the trash. * @param f file path where we currently are - * @param index counter for arches + * @param panelName the panel to add archetypes to + * @param folderName the folder to add archetypes to */ - private void loadArchetypesFromFiles(final File f, int index) { + private void loadArchetypesFromFiles(final File f, final int folderLevel, @NotNull final String panelName, @NotNull final String folderName) { final String name = f.getName(); setLoadedFromArchive(false); // don't load from the collected files if (f.isDirectory()) { // now, setup the arch panels if (!"cvs".equalsIgnoreCase(name) && !"dev".equalsIgnoreCase(name) && !name.startsWith(".")) { - if (folderLevel > 0 && folderLevel < 2) { // add first folders as panels - mainControl.addArchPanel(name); - mainControl.addArchPanelCombo("show all"); - } - - if (folderLevel > 0 && folderLevel < 3) { // add first folders as panels - index = mainControl.addArchPanelCombo(name); - // mainControl.showMessage("LOAD FILE", "name: "+name+" index: "+index); - } - - folderLevel++; + final String thisPanelName = folderLevel == 1 ? name : panelName; + final String thisFolderName = folderLevel == 1 || folderLevel == 2 ? name : folderName; final String[] children = f.list(); if (children != null) { Arrays.sort(children); for (final String child : children) { - loadArchetypesFromFiles(new File(f, child), index); + loadArchetypesFromFiles(new File(f, child), folderLevel + 1, thisPanelName, thisFolderName); } } - folderLevel--; } } else { if (!"cvs".equalsIgnoreCase(name) && !"dev".equalsIgnoreCase(name)) { @@ -243,7 +231,7 @@ if ((len = name.length()) >= 4) { if (name.regionMatches(len - 4, ".arc", 0, 4)) { //mainControl.setStatusText("Loading Arch: "+name); - mainControl.getArchetypeParser().parseArchetype(f.getAbsolutePath(), index); + mainControl.getArchetypeParser().parseArchetype(f.getAbsolutePath(), panelName, folderName); } else if (name.regionMatches(len - 4, ".png", 0, 4)) { //mainControl.setStatusText("Loading PNG: "+name); if (mainControl.getImageSet() == null || name.contains("." + mainControl.getImageSet() + ".")) { Modified: trunk/daimonin/src/daieditor/CArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/daimonin/src/daieditor/CArchPanel.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -2,6 +2,7 @@ * Daimonin Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -27,8 +28,6 @@ import daieditor.gameobject.GameObject; import daieditor.gui.map.tools.ToolSelectorPane; import java.awt.BorderLayout; -import java.util.ArrayList; -import java.util.List; import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.JSplitPane; @@ -37,6 +36,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.gridarta.gui.GSplitPane; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -44,6 +44,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum */ public final class CArchPanel extends JPanel { @@ -60,20 +61,17 @@ * Name of the selected archetype. * @serial include */ - private String selectedArch; + private GameObject selectedArch = null; /** Panel holding both archlist and pickmaps. */ - private final JTabbedPane archAndPickPane; + private final JTabbedPane archAndPickPane = new JTabbedPane(SwingConstants.TOP); /** The Tab panel with arch lists. */ - private final JTabbedPane tabDesktop; + private final JTabbedPane tabDesktop = new JTabbedPane(SwingConstants.TOP); /** The data/view of selected objects in tab panel. */ private final CArchQuickView archQuickPanel; - /** List of arch panels. */ - private static List<PanelNode> panelNodeList = new ArrayList<PanelNode>(); - /** The active panel. */ private CArchPanelPan selectedPanel; @@ -84,14 +82,11 @@ public CArchPanel(final CMainControl mainControl) { super(new BorderLayout()); this.mainControl = mainControl; - selectedArch = null; - tabDesktop = new JTabbedPane(SwingConstants.TOP); tabDesktop.setBorder(BorderFactory.createEmptyBorder(IGUIConstants.SPACE_PICKARCH_TOP, 0, 0, 0)); archQuickPanel = new CArchQuickView(mainControl); // archAndPickPane is the panel containing both archpanel and pickmaps - archAndPickPane = new JTabbedPane(SwingConstants.TOP); archAndPickPane.addTab("Arch List", tabDesktop); archAndPickPane.addTab("Pickmaps", mainControl.getMainView().getPickmapPanel()); // this listener informs the mainview which panel is active: archlist or pickmaps? @@ -103,45 +98,46 @@ // TODO: introduce a tool registry add(new GSplitPane(JSplitPane.VERTICAL_SPLIT, toolSelectorPane, archAndPickPane), BorderLayout.CENTER); add(archQuickPanel, BorderLayout.SOUTH); - - // we must set the list of the selected list depend on combo selection - tabDesktop.addChangeListener(new ChangeListener() { - public void stateChanged(final ChangeEvent e) { - final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); - - setSelectedArch(null); - final PanelNode node = panelNodeList.get(tabbedPane.getSelectedIndex()); - selectedPanel = node.getData(); - if (selectedPanel != null) { - selectedPanel.showArchList(); - } - } - }); } /** Move the pickmap panel in front of the default-archpanel. */ public void movePickmapPanelToFront() { - if (archAndPickPane != null && archAndPickPane.getTabCount() > 1) { - archAndPickPane.setSelectedIndex(1); - } + archAndPickPane.setSelectedIndex(1); } + /** + * Get the currently selected archetype. + * + * @return the selected archetype, or <code>null</code> if none is selected + */ @Nullable public GameObject getArchPanelSelection() { return selectedPanel != null ? selectedPanel.getArchListObject() : null; } - public void showArchPanelQuickObject(final GameObject gameObject) { + /** + * Show the given game object's attributes in the quick panel. + * + * @param gameObject the game object to show, or <code>null</code> to clear + * the attributes + */ + public void showArchPanelQuickObject(@Nullable final GameObject gameObject) { archQuickPanel.showArchPanelQuickObject(gameObject); } - public int addArchPanelCombo(final String name) { - return selectedPanel.addArchPanelCombo(name); + /** + * Add a new archetype. Create the panel and/or folder if necessary. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + */ + public void addArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + final CArchPanelPan panel = findOrCreatePanel(panelName); + panel.addArchetype(folderName, arch); } - public void addArchPanelArch(final String archetypeName, final int index) { - selectedPanel.addArchPanelArch(archetypeName, index); - } - /** * Sets the enabled state of the tab pane for Archetypes. * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable it. @@ -153,29 +149,73 @@ } } - public void addPanel(final String name) { - final PanelNode newnode = new PanelNode(new CArchPanelPan(this, mainControl), name); + /** + * Return a panel by name. If this panel does not exist, create a new one. + * + * @param panelName the panel name + * + * @return the panel + */ + @NotNull private CArchPanelPan findOrCreatePanel(@NotNull final String panelName) { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + if (panelName.equals(tabDesktop.getTitleAt(i))) { + return (CArchPanelPan) tabDesktop.getComponentAt(i); + } + } - panelNodeList.add(newnode); - this.tabDesktop.add(newnode.getData().getPanel(), name); - // make it aktive - this.tabDesktop.setSelectedIndex(tabDesktop.getTabCount() - 1); - selectedPanel = newnode.getData(); + final CArchPanelPan newPanel = new CArchPanelPan(this, mainControl); + + // insert new panel in alphabetical order + int i; + for (i = 0; i < tabDesktop.getTabCount() && panelName.compareToIgnoreCase(tabDesktop.getTitleAt(i)) > 0; i++) { + ; + } + tabDesktop.insertTab(panelName, null, newPanel, null, i); + + return newPanel; } /** + * After the build process is completed and the panels have + * been fully constructed, we must correct the 'selectedPanel' + * setting and make sure the arch list is properly drawn. + */ + public void finishBuildProcess() { + for (int i = 0; i < tabDesktop.getTabCount(); i++) { + ((CArchPanelPan) tabDesktop.getComponentAt(i)).finishBuildProcess(); + } + + selectedPanel = (CArchPanelPan) tabDesktop.getSelectedComponent(); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + + // we must set the list of the selected list depend on combo selection + tabDesktop.addChangeListener(new ChangeListener() { + public void stateChanged(final ChangeEvent e) { + final JTabbedPane tabbedPane = (JTabbedPane) e.getSource(); + setSelectedArch(null); + selectedPanel = (CArchPanelPan) tabDesktop.getComponentAt(tabbedPane.getSelectedIndex()); + if (selectedPanel != null) { + selectedPanel.showArchList(); + } + } + }); + } + + /** * Get name of selected Arch. * @return Name of selected arch in arch panel */ - public String getSelectedArch() { - return selectedArch; + @Nullable public String getSelectedArch() { + return selectedArch == null ? null : selectedArch.getArchetypeName(); } /** * Set selected Arch. * @param selectedArch name of selected arch in arch panel */ - public void setSelectedArch(final String selectedArch) { + public void setSelectedArch(@Nullable final GameObject selectedArch) { this.selectedArch = selectedArch; } @@ -192,28 +232,4 @@ return toolSelectorPane; } - public static final class PanelNode { - - private final CArchPanelPan data; - - /** - * Title of this node. - */ - private final String title; - - public PanelNode(final CArchPanelPan data, final String title) { - this.data = data; - this.title = title; - } - - public String getTitle() { - return title; - } - - public CArchPanelPan getData() { - return data; - } - - } // class PanelNode - } // class CArchPanel Modified: trunk/daimonin/src/daieditor/CArchPanelPan.java =================================================================== --- trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/daimonin/src/daieditor/CArchPanelPan.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -2,6 +2,7 @@ * Daimonin Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2006 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -33,9 +34,8 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.Comparator; +import java.util.TreeSet; import javax.swing.DefaultListCellRenderer; import javax.swing.DefaultListModel; import javax.swing.ImageIcon; @@ -45,12 +45,18 @@ import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JViewport; +import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +/** + * @author unknown + * @author Andreas Kirschbaum + */ public final class CArchPanelPan extends JPanel { private static final Logger log = Logger.getLogger(CArchPanelPan.class); @@ -64,15 +70,21 @@ /** Controller of this subview. */ private final CMainControl mainControl; - /** Maps index to list of archetype names. */ - private Map<Integer, ArrayList<String>> archLists = new HashMap<Integer, ArrayList<String>>(); + /** + * List of archetypes for each folder. The folders correspond to the + * entries in {@link #comboBox}. + * @note The first entry is always <code>null</code>. + */ + private final ArrayList<ArrayList<GameObject>> folders = new ArrayList<ArrayList<GameObject>>(); - private final JList theList; + /** + * The list of currently shown archetypes; it is updated from {@link + * #folders} each time a new folder is selected. + */ + private final JList archList; private final DefaultListModel model; - private final JPanel panelDesktop; - private final JComboBox comboBox; /** The popup menu for the arch lists to bring up the editor. */ @@ -81,59 +93,69 @@ private final CArchPanel archPanel; + /** + * Comparator used to sort entries shown in {@link archList}. + */ + private static final Comparator<GameObject> archComparator = new Comparator<GameObject>() + { + public int compare(final GameObject o1, final GameObject o2) { + return o1.getArchetypeName().compareToIgnoreCase(o2.getArchetypeName()); + } + }; + + /** + * Temporary variable used to collect and sort the archeteypes to be + * inserted into {@link #archList}. + */ + private static final TreeSet<GameObject> sortedArchetypes = new TreeSet<GameObject>(archComparator); + /* Build Panel */ CArchPanelPan(final CArchPanel controlPanel, final CMainControl mainControl) { super(new BorderLayout()); this.mainControl = mainControl; archPanel = controlPanel; - panelDesktop = new JPanel(); - panelDesktop.setLayout(new BorderLayout()); - comboBox = new JComboBox(); model = new DefaultListModel(); - theList = new JList(model); - theList.setCellRenderer(new MyCellRenderer()); - theList.setBackground(IGUIConstants.BG_COLOR); - final JScrollPane scrollPane = new JScrollPane(theList); - panelDesktop.add(scrollPane, BorderLayout.CENTER); - panelDesktop.add(comboBox, BorderLayout.NORTH); + archList = new JList(model); + archList.setCellRenderer(new MyCellRenderer()); + archList.setBackground(IGUIConstants.BG_COLOR); + archList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + final JScrollPane scrollPane = new JScrollPane(archList); + add(scrollPane, BorderLayout.CENTER); + add(comboBox, BorderLayout.NORTH); scrollPane.setAutoscrolls(true); scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); comboBox.setAutoscrolls(true); + } + public void finishBuildProcess() { + // listening for mouse-click events in the ArchPanel list + archList.addMouseListener(new MouseAdapter() { + @Override public void mousePressed(final MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3) { + //this will display the future arch editor. + //Because editing default arches is not yet possible, this line is commented in production. + //menu.show((Component) e.getSource(), e.getX(), e.getY()); + } + } + }); + comboBox.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { showArchList(); } }); - theList.addListSelectionListener(new ListSelectionListener() { + archList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(final ListSelectionEvent e) { - mainControl.showArchPanelQuickObject(getArchListObject(e.getFirstIndex())); + updateSelectedArchListObject(); } }); - // listening for mouse-click events in the ArchPanel list - theList.addMouseListener(new MouseAdapter() { - @Override public void mousePressed(final MouseEvent e) { - theList.setSelectedIndex(theList.locationToIndex(e.getPoint())); - if (e.getButton() == MouseEvent.BUTTON3) { - //this will display the future arch editor. - //Because editing default arches is not yet possible, this line is commented in production. - //menu.show((Component) e.getSource(), e.getX(), e.getY()); - } - // In JDK 1.4 it is required to transfer focus back to mapview after - // every click in the panel, otherwise the menu-shortcuts stop working - if (mainControl.getCurrentMap() != null && mainControl.getCurrentMap().getMapViewFrame() != null) { - mainControl.getCurrentMap().getMapViewFrame().requestFocus(); // focus to mapview - } - } - }); - - //theList.setComponentPopupMenu(menu); + //archList.setComponentPopupMenu(menu); } private JPopupMenu createListPopupMenu() { @@ -155,76 +177,90 @@ * @return GameObject or <code>null</code> if no selection */ public GameObject getArchListObject() { - return getArchListObject(theList.getSelectedIndex()); + return (GameObject) archList.getSelectedValue(); } /** - * Get the GameObject from the list. - * @param index Index of selected list element or <code>-1</code> for no selection. - * @return GameObject or <code>null</code> if <var>index</var> was <code>-1</code> + * Show the selected archetype. */ - @Nullable private GameObject getArchListObject(final int index) { - GameObject archetype = null; - if (index != -1) { - archetype = mainControl.getArchetypeSet().getArchetype((String) theList.getSelectedValue()); - } - return archetype; + private void updateSelectedArchListObject() { + final GameObject archetype = (GameObject) archList.getSelectedValue(); + mainControl.setStatusText(archetype != null ? archetype.getArchetypeName() : ""); + archPanel.setSelectedArch(archetype); + mainControl.showArchPanelQuickObject(archetype); } /** - * Add this arch to list of (this) Jlist list. - * @param archetypeName name of the archetype to add - * @param index index of subdir where to add + * Add an archetype to this panel. + * + * @param folderName the folder to add it to + * + * @param arch the archetype to add */ - public void addArchPanelArch(final String archetypeName, final int index) { - final ArrayList<String> tmp = archLists.get(index); - final ArrayList<String> archList; - if (tmp == null) { - archList = new ArrayList<String>(); - archLists.put(index, archList); - } else { - archList = tmp; - } - - archList.add(archetypeName); + public void addArchetype(@NotNull final String folderName, @NotNull final GameObject arch) { + final ArrayList<GameObject> folder = findOrCreateFolder(folderName); + folder.add(arch); } /** - * Add a new category to the combo box. + * Return a folder by name. If this folder does not exist, create a new one. * - * @param name the name of the combo box to create + * @param folderName the folder name * - * @return the combo box index + * @return the folder */ - public int addArchPanelCombo(final String name) { - setEnabled(false); - comboBox.addItem(name); - setEnabled(true); - return comboBox.getItemCount() - 1; - } + @NotNull private ArrayList<GameObject> findOrCreateFolder(@NotNull final String folderName) { + assert folders.size() == comboBox.getItemCount(); + for (int i = 1; i < folders.size(); i++) { + if (folderName.equals(comboBox.getItemAt(i))) { + return folders.get(i); + } + } - JPanel getPanel() { - return panelDesktop; + if (folders.size() <= 0) { + comboBox.addItem("show all"); + folders.add(null); // first entry is always empty + } + + // insert new folder in alphabetical order + int i; + for (i = 1; i < folders.size(); i++) { + if (folderName.compareToIgnoreCase((String) comboBox.getItemAt(i)) <= 0) { + break; + } + } + + final ArrayList<GameObject> folder = new ArrayList<GameObject>(); + comboBox.insertItemAt(folderName, i); + folders.add(i, folder); + + return folder; } - void showArchList() { + /** + * Update {@link #archList} to contain the currently selected folder. + */ + public void showArchList() { final int index = comboBox.getSelectedIndex(); - model.removeAllElements(); + sortedArchetypes.clear(); if (index == 0) { - for (final List<String> archList : archLists.values()) { - for (final String archName : archList) { - model.addElement(archName); - } + for (int i = 1; i < folders.size(); i++) { + sortedArchetypes.addAll(folders.get(i)); } } else if (index > 0) { - final List<String> archList = archLists.get(index); + final ArrayList<GameObject> archList = folders.get(index); if (archList != null) { - for (final String archName : archList) { - model.addElement(archName); - } + sortedArchetypes.addAll(archList); } } + + archList.setVisible(false); + model.removeAllElements(); + for (final GameObject arch : sortedArchetypes) { + model.addElement(arch); + } + archList.setVisible(true); } /** Cell Renderer for rendering cells in the ArchPanelPan. */ @@ -238,19 +274,13 @@ public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - final ArchetypeSet archetypeSet = mainControl.getArchetypeSet(); - final String archetypeName = (String) value; - final GameObject archetype = archetypeSet.getArchetype(archetypeName); - if (isSelected) { // XXX it is not a good idea to query the selection information at this place. - archPanel.setSelectedArch(archetypeName); - mainControl.setStatusText(archetypeName); - } - setText(archetypeName); + final GameObject archetype = (GameObject) value; + setText(archetype.getArchetypeName()); if (archetype.hasFaceObject()) { setIcon(CMainControl.getNofaceTileIcon()); } else { - final ImageIcon icon = archetypeSet.getFace(archetype.getFaceRealName()); + final ImageIcon icon = mainControl.getArchetypeSet().getFace(archetype.getFaceRealName()); if (icon == null) { //setIcon(mainControl.nofaceTileIcon); } else { Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -798,20 +798,21 @@ mainView.setTabPaneEnabled(tabPaneEnabled); } - /** {@inheritDoc} */ - public void addArchPanel(@NotNull final String name) { - mainView.addArchPanel(name); + /** + * Add an archetype to the archetype panel. + * + * @param panelName the panel name to add the archetype to + * + * @param folderName the folder name to add the archetype to + * + * @param arch the archetype to add + * + * @deprecated this has nothing to do with MainControl and should be refactored + */ + public void addArchPanelArchetype(@NotNull final String panelName, @NotNull final String folderName, @NotNull final GameObject arch) { + mainView.addArchPanelArchetype(panelName, folderName, arch); } - /** {@inheritDoc} */ - public int addArchPanelCombo(@NotNull final String name) { - return mainView.addArchPanelCombo(name); - } - - public void addArchPanelArch(final String archname, final int index) { - mainView.addArchPanelArch(archname, index); - } - /** * Return name of the selected arch in arch panel. * @return name of selected arch in arch panel Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2006-12-20 21:04:22 UTC (rev 1194) +++ trunk/daimonin/src/daieditor/CMainView.java 2006-12-20 21:06:50 UTC (rev 1195) @@ -61,6 +61,7 @@ import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.ThrowableHandler; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** @@ -268,6 +269,10 @@ archPanel.movePickmapPanelToFront(); } + public void finishArchPanelBuildProcess() { + archPanel.finishBuildProcess(); + } + /** * Returns the active arch in the left-side panel. * This can either be a default arch from the archlist, or @@ -363,10 +368,6 @@ return mapTileList.getMapTileSelection(); } - public void addArchPanel(final String name) { - archPanel.addPanel(name); - } - /** * Sets the enabled state of the tab pane for Archetypes. * @param tabPaneEnabled <code>true</code> to enable tab pane, <code>false</code> to disable i... [truncated message content] |
From: <aki...@us...> - 2006-12-21 06:36:42
|
Revision: 1196 http://svn.sourceforge.net/gridarta/?rev=1196&view=rev Author: akirschbaum Date: 2006-12-20 22:36:43 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Add connection view. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/daimonin/src/daieditor/CMapArchPanel.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/ConnectionView.java Removed Paths: ------------- trunk/daimonin/src/daieditor/gui/ConnectionView.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/crossfire/ChangeLog 2006-12-21 06:36:43 UTC (rev 1196) @@ -1,3 +1,7 @@ +2006-12-21 Andreas Kirschbaum + + * Add connection view. + 2006-12-20 Andreas Kirschbaum * Sort archetypes in archetype panel by name. Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -730,6 +730,7 @@ setCurrentLevel(map); refreshMenusAndToolbars(); } + map.getMapModel().addMapModelListener(mainView.getMapArchPanel().getConnectionView()); return map; } Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/crossfire/src/cfeditor/CMainView.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -796,6 +796,10 @@ mainControl.showMessage("About " + IGUIConstants.APP_NAME, " Version " + IGUIConstants.VERSION + "\n (c) 2001 Michael Toennies\n" + " Andreas Vogl\n"); } + public CMapArchPanel getMapArchPanel() { + return mapArchPanel; + } + public boolean isLockAllPickmaps() { return mainControl.isLockAllPickmaps(); } Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -56,6 +56,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.gui.ConnectionView; import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; @@ -125,6 +126,9 @@ private final JPanel animationPanel; + /** The JPanel holding the connection information. */ + private final ConnectionView connectionView = new ConnectionView(); + /** Arch text field. */ private final JTextArea archTextArea = new JTextArea(4, 25); @@ -215,6 +219,7 @@ panelDesktop.add(createScriptPanel(), "Scripts"); panelDesktop.add(animationPanel, "Animation"); + panelDesktop.add(connectionView, "Connection"); // calculate default value in case there is no settings file final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); @@ -909,4 +914,12 @@ aRemove.setEnabled(removeButton); } + /** + * Get the ConnectionView. + * @return ConnectionView + */ + public ConnectionView getConnectionView() { + return connectionView; + } + } // class CMapArchPanel Modified: trunk/daimonin/src/daieditor/CMapArchPanel.java =================================================================== --- trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/daimonin/src/daieditor/CMapArchPanel.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -25,7 +25,6 @@ package daieditor; import daieditor.gameobject.GameObject; -import daieditor.gui.ConnectionView; import daieditor.gui.ErrorListView; import daieditor.map.validation.ErrorCollector; import daieditor.map.validation.ErrorHandler; @@ -62,6 +61,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.gui.ConnectionView; import net.sf.gridarta.gui.GSplitPane; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.ActionMethod; Deleted: trunk/daimonin/src/daieditor/gui/ConnectionView.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ConnectionView.java 2006-12-20 21:06:50 UTC (rev 1195) +++ trunk/daimonin/src/daieditor/gui/ConnectionView.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -1,101 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2005 Christian Hujer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package daieditor.gui; - -import java.awt.BorderLayout; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.gridarta.map.MapArchObject; -import net.sf.gridarta.map.MapModel; -import net.sf.gridarta.map.MapModelEvent; -import net.sf.gridarta.map.MapModelListener; -import net.sf.gridarta.map.MapSquare; - -/** - * A Panel that holds information about the connections of the selected arch on the selected map. - * It is unfinished. - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo more user interface features - * @todo make this a MapHighlightModel - * @todo better react on changes, don't always scan the whole map - * @todo attach - * @serial exclude - */ -public final class ConnectionView extends JPanel implements MapModelListener { - - /** The conections. */ - private final Map<Integer, List<GameObject>> connections = new HashMap<Integer, List<GameObject>>(); - - /** The List with the connections. */ - private JList connectionList = new JList(); - - /** Create a ConnectionPanel. */ - public ConnectionView() { - setLayout(new BorderLayout()); - add(new JScrollPane(connectionList)); - } - - /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent e) { - scanMapForConnections(e.getMapModel()); - } - - /** - * Scans a map for the contained connections. - * @param model Model of map to scan - */ - public void scanMapForConnections(final MapModel model) { - connections.clear(); - for (final MapSquare<? extends GameObject> mapSquare : (MapModel<? extends GameObject, MapArchObject>) model) { - for (final GameObject archObject : mapSquare) { - final String connectionSpec = archObject.getAttributeString("connected", false); - if (connectionSpec != null && connectionSpec.matches("\\d+(, *\\d+)*")) { - for (String s : connectionSpec.trim().split(",\\s*")) { - final Integer connection = Integer.valueOf(s); - if (!connections.containsKey(connection)) { - connections.put(connection, new ArrayList<GameObject>()); - } - connections.get(connection).add(archObject); - } - } - } - } - connectionList.setListData(connections.keySet().toArray()); - } - -} // class ConnectionPanel Copied: trunk/src/app/net/sf/gridarta/gui/ConnectionView.java (from rev 1195, trunk/daimonin/src/daieditor/gui/ConnectionView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/ConnectionView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/ConnectionView.java 2006-12-21 06:36:43 UTC (rev 1196) @@ -0,0 +1,101 @@ +/* + * Gridarta Java Editor. + * Copyright (C) 2005 Christian Hujer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package net.sf.gridarta.gui; + +import java.awt.BorderLayout; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapModel; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; +import net.sf.gridarta.map.MapSquare; + +/** + * A Panel that holds information about the connections of the selected arch on the selected map. + * It is unfinished. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo more user interface features + * @todo make this a MapHighlightModel + * @todo better react on changes, don't always scan the whole map + * @todo attach + * @serial exclude + */ +public final class ConnectionView extends JPanel implements MapModelListener { + + /** The conections. */ + private final Map<Integer, List<GameObject>> connections = new HashMap<Integer, List<GameObject>>(); + + /** The List with the connections. */ + private JList connectionList = new JList(); + + /** Create a ConnectionPanel. */ + public ConnectionView() { + setLayout(new BorderLayout()); + add(new JScrollPane(connectionList)); + } + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent e) { + scanMapForConnections(e.getMapModel()); + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent e) { + scanMapForConnections(e.getMapModel()); + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent e) { + scanMapForConnections(e.getMapModel()); + } + + /** + * Scans a map for the contained connections. + * @param model Model of map to scan + */ + public void scanMapForConnections(final MapModel model) { + connections.clear(); + for (final MapSquare<? extends GameObject> mapSquare : (MapModel<? extends GameObject, MapArchObject>) model) { + for (final GameObject archObject : mapSquare) { + final String connectionSpec = archObject.getAttributeString("connected", false); + if (connectionSpec != null && connectionSpec.matches("\\d+(, *\\d+)*")) { + for (String s : connectionSpec.trim().split(",\\s*")) { + final Integer connection = Integer.valueOf(s); + if (!connections.containsKey(connection)) { + connections.put(connection, new ArrayList<GameObject>()); + } + connections.get(connection).add(archObject); + } + } + } + } + connectionList.setListData(connections.keySet().toArray()); + } + +} // class ConnectionPanel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-21 21:55:00
|
Revision: 1197 http://svn.sourceforge.net/gridarta/?rev=1197&view=rev Author: akirschbaum Date: 2006-12-21 13:54:59 -0800 (Thu, 21 Dec 2006) Log Message: ----------- Sort connection numbers in connection view. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/src/app/net/sf/gridarta/gui/ConnectionView.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-21 06:36:43 UTC (rev 1196) +++ trunk/crossfire/ChangeLog 2006-12-21 21:54:59 UTC (rev 1197) @@ -1,5 +1,7 @@ 2006-12-21 Andreas Kirschbaum + * Sort connection numbers in connection view. + * Add connection view. 2006-12-20 Andreas Kirschbaum Modified: trunk/src/app/net/sf/gridarta/gui/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/ConnectionView.java 2006-12-21 06:36:43 UTC (rev 1196) +++ trunk/src/app/net/sf/gridarta/gui/ConnectionView.java 2006-12-21 21:54:59 UTC (rev 1197) @@ -23,7 +23,7 @@ import java.awt.BorderLayout; import java.util.ArrayList; -import java.util.HashMap; +import java.util.TreeMap; import java.util.List; import java.util.Map; import javax.swing.JList; @@ -49,7 +49,7 @@ public final class ConnectionView extends JPanel implements MapModelListener { /** The conections. */ - private final Map<Integer, List<GameObject>> connections = new HashMap<Integer, List<GameObject>>(); + private final Map<Integer, List<GameObject>> connections = new TreeMap<Integer, List<GameObject>>(); /** The List with the connections. */ private JList connectionList = new JList(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-21 21:56:41
|
Revision: 1198 http://svn.sourceforge.net/gridarta/?rev=1198&view=rev Author: akirschbaum Date: 2006-12-21 13:56:42 -0800 (Thu, 21 Dec 2006) Log Message: ----------- Reduce the number of change events generated when creating a new map model. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-12-21 21:54:59 UTC (rev 1197) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-12-21 21:56:42 UTC (rev 1198) @@ -78,7 +78,9 @@ this.mainControl = mainControl; this.mapControl = mapControl; + beginTransaction("Insert initial objects"); addObjectListToMap(objects); // init mapArchObject and (when not new map) the arch list + endTransaction(); } /** Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-12-21 21:54:59 UTC (rev 1197) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-12-21 21:56:42 UTC (rev 1198) @@ -85,7 +85,9 @@ this.mainControl = mainControl; this.mapControl = mapControl; + beginTransaction("Insert initial objects"); addObjectListToMap(objects); // init mapArchObject and (when not new map) the arch list + endTransaction(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-21 22:09:55
|
Revision: 1199 http://svn.sourceforge.net/gridarta/?rev=1199&view=rev Author: akirschbaum Date: 2006-12-21 14:09:55 -0800 (Thu, 21 Dec 2006) Log Message: ----------- Properly update connection view when the map changes. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/CAttribDialog.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/crossfire/ChangeLog 2006-12-21 22:09:55 UTC (rev 1199) @@ -1,5 +1,7 @@ 2006-12-21 Andreas Kirschbaum + * Properly update connection view when the map changes. + * Sort connection numbers in connection view. * Add connection view. Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-12-21 22:09:55 UTC (rev 1199) @@ -89,6 +89,7 @@ import net.sf.gridarta.gameobject.NamedObject; import net.sf.gridarta.gameobject.NamedObjects; import net.sf.gridarta.help.Help; +import net.sf.gridarta.map.MapModel; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; @@ -1058,6 +1059,22 @@ * @return true if the settings were applied, false if error occurred */ private boolean applySettings() { + final MapModel mapModel = mainControl.getCurrentMap().getMapModel(); + mapModel.beginTransaction("Change object attributes"); + try { + return applySettings2(); + } finally { + mapModel.endTransaction(); + } + } + + /** + * This method is called when the "apply"-button has been + * pressed. All the settings from the dialog get + * written into the GameObject. + * @return true if the settings were applied, false if error occurred + */ + private boolean applySettings2() { final String oldArchText = gameObject.getObjectText(); // the old ArchText final String oldMsg = gameObject.getMsgText(); // old gameObject msg final CFArchType typeStruct = archTypeList.getTypeOfArch(gameObject); // the type structure for this gameObject @@ -1326,7 +1343,6 @@ final int index = ArchetypeSet.getFaceIndex(archetype.getFaceName()); gameObject.setFaceNr(index); } - mainControl.getCurrentMap().repaint(); // repaint map } } imagePanel.setIcon(mainControl.getArchetypeSet().getFace(gameObject.getFaceNr())); Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2006-12-21 22:09:55 UTC (rev 1199) @@ -421,12 +421,22 @@ } public void setArchTypNr(final int typNr) { + if (archType == typNr) { + return; + } + archType = typNr; + squareChanged(); } /* Set the default face. Number is index of face list */ public void setFaceNr(final int nr) { + if (facenr == nr) { + return; + } + facenr = nr; + squareChanged(); } /* Get the default face. Number is index of face list */ @@ -439,12 +449,23 @@ } public void setFaceFlag(final boolean flag) { + if (noface == flag) { + return; + } + noface = flag; + squareChanged(); } // face name public void setFaceName(final String name) { - faceName = name != null ? name.intern() : null; + final String newFaceName = name != null ? name.intern() : null; + if (faceName == newFaceName) { + return; + } + + faceName = newFaceName; + squareChanged(); } public String getFaceName() { Modified: trunk/daimonin/src/daieditor/CAttribDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribDialog.java 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/daimonin/src/daieditor/CAttribDialog.java 2006-12-21 22:09:55 UTC (rev 1199) @@ -88,6 +88,7 @@ import net.sf.gridarta.gameobject.NamedObject; import net.sf.gridarta.gameobject.NamedObjects; import net.sf.gridarta.help.Help; +import net.sf.gridarta.map.MapModel; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.util.Arrays2.linearSearch; import org.apache.log4j.Logger; @@ -1052,6 +1053,23 @@ * @return true if the settings were applied, false if error occurred */ private boolean applySettings() { + final MapModel mapModel = mainControl.getCurrentMap().getMapModel(); + mapModel.beginTransaction("Change object attributes"); + try { + return applySettings2(); + } finally { + mapModel.endTransaction(); + } + } + + + /** + * This method is called when the "apply"-button has been + * pressed. All the settings from the dialog get + * written into the GameObject. + * @return true if the settings were applied, false if error occurred + */ + private boolean applySettings2() { final CFArchType typeStruct = archTypeList.getTypeOfArch(gameObject); // the type structure for this gameObject String newArchText = ""; @@ -1347,7 +1365,6 @@ // It is just a hack to fix #0000306: When changing the face (image) of an item by hitting the image button, the image in the selected tile window does not change // In fact, this hack always refreshes the whole map tile list, no matter whether it is still showing the currently selected gameObject. mainControl.getMainView().refreshMapTileList(); - mainControl.getCurrentMap().repaint(); return true; // apply succeeded } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2006-12-21 22:09:55 UTC (rev 1199) @@ -375,7 +375,12 @@ } public void setArchTypNr(final int typNr) { + if (archType == typNr) { + return; + } + archType = typNr; + squareChanged(); } /** {@inheritDoc} */ @@ -401,7 +406,12 @@ } public void setDirection(final int direction) { + if (this.direction == direction) { + return; + } + this.direction = direction; + squareChanged(); } public boolean hasFaceObject() { @@ -414,11 +424,13 @@ // face name private void setFaceObjName(final String faceObjName) { - if (faceObjName != null) { - this.faceObjName = faceObjName.intern(); - } else { - this.faceObjName = null; + final String newFaceObjName = faceObjName != null ? faceObjName.intern() : null; + if (this.faceObjName == newFaceObjName) { + return; } + + this.faceObjName = newFaceObjName; + squareChanged(); } public String getFaceObjName() { @@ -427,7 +439,13 @@ // face name public void setFaceRealName(final String faceRealName) { - this.faceRealName = faceRealName != null ? faceRealName.intern() : null; + final String newFaceRealName = faceRealName != null ? faceRealName.intern() : null; + if (this.faceRealName == newFaceRealName) { + return; + } + + this.faceRealName = newFaceRealName; + squareChanged(); } public String getFaceRealName() { @@ -606,7 +624,13 @@ * <var>animName</var></code> */ public void setAnimName(final String animName) { - this.animName = animName != null ? animName.intern() : null; + final String newAnimName = animName != null ? animName.intern() : null; + if (this.animName == newAnimName) { + return; + } + + this.animName = newAnimName; + squareChanged(); } /** Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-12-21 21:56:42 UTC (rev 1198) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2006-12-21 22:09:55 UTC (rev 1199) @@ -577,7 +577,12 @@ * @see #getEditType() */ public void setEditType(final int editType) { + if (this.editType == editType) { + return; + } + this.editType = editType; + squareChanged(); } /** Delete message text by nullification. */ @@ -735,7 +740,13 @@ * @param objName the name of this object. */ public void setObjName(@Nullable final String objName) { - this.objName = objName != null ? objName.intern() : null; + final String newObjName = objName != null ? objName.intern() : null; + if (this.objName == newObjName) { + return; + } + + this.objName = newObjName; + squareChanged(); } /** @@ -787,7 +798,12 @@ /** Clears the object text of this GameObject. */ public void resetObjectText() { + if (objectText.length() == 0) { + return; + } + objectText.delete(0, objectText.length()); + squareChanged(); } /** @@ -795,9 +811,14 @@ * @param objectText text to set as object text */ public void setObjectText(final String objectText) { + if (this.objectText.toString().equals(objectText)) { + return; + } + resetObjectText(); this.objectText.append(objectText); clearAttributeCache(); + squareChanged(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-12-22 19:43:29
|
Revision: 1203 http://svn.sourceforge.net/gridarta/?rev=1203&view=rev Author: akirschbaum Date: 2006-12-22 11:43:29 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Introduce MainControlListener interface to listen for changes in MainControl. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/MainControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/MainControlListener.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-22 19:26:11 UTC (rev 1202) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-12-22 19:43:29 UTC (rev 1203) @@ -53,8 +53,10 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.event.EventListenerList; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; +import net.sf.gridarta.MainControlListener; import net.sf.gridarta.gameobject.Collectable; import net.sf.gridarta.gameobject.Collector; import net.sf.gridarta.gui.HideFileFilterProxy; @@ -188,6 +190,9 @@ private final MapCursorControl mapCursorControl; + /** The MainControlListeners to inform of changes. */ + private EventListenerList listenerList = new EventListenerList(); + /** Actions used by this instance. */ private final MainActions mainActions = new MainActions(this); @@ -1461,15 +1466,42 @@ */ public void setCurrentLevel(final MapControl map) { + if (currentMap == map) { + return; + } + currentMap = map; refreshMenusAndToolbars(); mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); - mainActions.currentMapChanged(); + fireCurrentMapChangedEvent(); } + /** + * Notify all listeners about a changed current map. + */ + private void fireCurrentMapChangedEvent() { + final Object[] listeners = listenerList.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + //noinspection ObjectEquality + if (listeners[i] == MainControlListener.class) { + ((MainControlListener) listeners[i + 1]).currentMapChanged(currentMap); + } + } + } + + /** {@inheritDoc} */ + public void addMainControlListener(@NotNull final MainControlListener listener) { + listenerList.add(MainControlListener.class, listener); + } + + /** {@inheritDoc} */ + public void removeMainControlListener(final MainControlListener listener) { + listenerList.remove(MainControlListener.class, listener); + } + /** Invoked when user wants to revert the current map to previously saved state. */ public void revert() { final MapControl modmap = currentMap; // "modified map" to be reverted @@ -1750,7 +1782,7 @@ /** * Encapsulates actions and related functions. */ - public static final class MainActions implements MapCursorListener, MapGridListener { + public static final class MainActions implements MainControlListener, MapCursorListener, MapGridListener { /** The MainControl. */ private final CMainControl mainControl; @@ -1795,6 +1827,8 @@ */ public MainActions(@NotNull final CMainControl mainControl) { this.mainControl = mainControl; + + mainControl.addMainControlListener(this); } /** @@ -1814,10 +1848,8 @@ aSelectAll.setEnabled(isSelectAllEnabled()); } - /** - * Called when the current map of the attached MainControl has changed. - */ - public void currentMapChanged() { + /* {@inheritDoc} */ + public void currentMapChanged(@Nullable final net.sf.gridarta.map.MapControl mapControl) { refreshMenus(); } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-12-22 19:26:11 UTC (rev 1202) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-12-22 19:43:29 UTC (rev 1203) @@ -95,8 +95,10 @@ import javax.swing.JFileChooser; import javax.swing.JOptionPane; import static javax.swing.KeyStroke.getKeyStroke; +import javax.swing.event.EventListenerList; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; +import net.sf.gridarta.MainControlListener; import net.sf.gridarta.gameobject.Collectable; import net.sf.gridarta.gameobject.Collector; import net.sf.gridarta.gui.HideFileFilterProxy; @@ -296,6 +298,9 @@ private final MapCursorControl mapCursorControl; + /** The MainControlListeners to inform of changes. */ + private EventListenerList listenerList = new EventListenerList(); + /** Actions used by this instance. */ private final MainActions mainActions = new MainActions(this); @@ -1688,15 +1693,42 @@ */ public void setCurrentLevel(final MapControl map) { + if (currentMap == map) { + return; + } + currentMap = map; refreshMenusAndToolbars(); mapCursorControl.refreshMenus(); //CMainStatusbar.getInstance().setLevelInfo(level); - mainActions.currentMapChanged(); + fireCurrentMapChangedEvent(); } + /** + * Notify all listeners about a changed current map. + */ + private void fireCurrentMapChangedEvent() { + final Object[] listeners = listenerList.getListenerList(); + for (int i = listeners.length - 2; i >= 0; i -= 2) { + //noinspection ObjectEquality + if (listeners[i] == MainControlListener.class) { + ((MainControlListener) listeners[i + 1]).currentMapChanged(currentMap); + } + } + } + + /** {@inheritDoc} */ + public void addMainControlListener(@NotNull final MainControlListener listener) { + listenerList.add(MainControlListener.class, listener); + } + + /** {@inheritDoc} */ + public void removeMainControlListener(final MainControlListener listener) { + listenerList.remove(MainControlListener.class, listener); + } + /** Invoked when user wants to revert the current map to previously saved state. */ public void revert() { final MapControl modmap = currentMap; // "modified map" to be reverted @@ -2093,7 +2125,7 @@ /** * Encapsulates actions and related functions. */ - public static final class MainActions implements MapCursorListener, MapGridListener { + public static final class MainActions implements MainControlListener, MapCursorListener, MapGridListener { /** The MainControl. */ private final CMainControl mainControl; @@ -2138,6 +2170,8 @@ */ public MainActions(@NotNull final CMainControl mainControl) { this.mainControl = mainControl; + + mainControl.addMainControlListener(this); } /** @@ -2157,10 +2191,8 @@ aSelectAll.setEnabled(isSelectAllEnabled()); } - /** - * Called when the current map of the attached MainControl has changed. - */ - public void currentMapChanged() { + /* {@inheritDoc} */ + public void currentMapChanged(@Nullable final net.sf.gridarta.map.MapControl mapControl) { refreshMenus(); } Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2006-12-22 19:26:11 UTC (rev 1202) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2006-12-22 19:43:29 UTC (rev 1203) @@ -70,4 +70,16 @@ */ @Deprecated void setTabPaneEnabled(boolean tabPaneEnabled); + /** + * Register a MainControlListener. + * @param listener MainControlListener to register + */ + void addMainControlListener(@NotNull final MainControlListener listener); + + /** + * Remove a MainControlListener. + * @param listener MainControlListener to remove + */ + void removeMainControlListener(@NotNull final MainControlListener listener); + } // interface MainControl Added: trunk/src/app/net/sf/gridarta/MainControlListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControlListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/MainControlListener.java 2006-12-22 19:43:29 UTC (rev 1203) @@ -0,0 +1,42 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2006 The Gridarta Developers + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta; + +import java.util.EventListener; +import net.sf.gridarta.map.MapControl; +import org.jetbrains.annotations.Nullable; + +/** + * Interface for listeners listening to CMainControl changes. + * + * @author Andreas Kirschbaum + */ +public interface MainControlListener extends EventListener { + + /** + * This event handler is called when the current map has changed. + * + * @param mapControl the new map control, or <code>null</code> if no opened + * map exists + */ + void currentMapChanged(@Nullable MapControl mapControl); + +} Property changes on: trunk/src/app/net/sf/gridarta/MainControlListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |