From: <aki...@us...> - 2007-01-09 08:04:17
|
Revision: 1521 http://svn.sourceforge.net/gridarta/?rev=1521&view=rev Author: akirschbaum Date: 2007-01-09 00:04:17 -0800 (Tue, 09 Jan 2007) Log Message: ----------- Make pickmap panel work for pickmaps with spaces in the name work. Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserView.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2007-01-08 23:14:47 UTC (rev 1520) +++ trunk/crossfire/ChangeLog 2007-01-09 08:04:17 UTC (rev 1521) @@ -1,3 +1,8 @@ +2007-01-09 Andreas Kirschbaum + + * Make pickmap panel work for pickmaps with spaces in the name + work. + 2007-01-07 Andreas Kirschbaum * Implement undo/redo. Modified: trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java 2007-01-08 23:14:47 UTC (rev 1520) +++ trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserControl.java 2007-01-09 08:04:17 UTC (rev 1521) @@ -36,11 +36,9 @@ import java.awt.Component; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; -import java.util.Map; import javax.swing.JTabbedPane; import net.sf.gridarta.map.MapType; import net.sf.japi.swing.ActionFactory; @@ -63,8 +61,11 @@ private final CMainControl mainControl; // main control reference - /** All open pickmaps (the map controllers get stored in the vector). */ - private final Map<String, MapControl> pickmaps = new HashMap<String, MapControl>(); + /** + * All open pickmaps. The sort order matches {@link + * PickmapChooserView#pickmapPanel}. + */ + private final List<MapControl> pickmaps = new ArrayList<MapControl>(); /** The view for this control. */ private final PickmapChooserView view; @@ -145,19 +146,15 @@ if (objects == null) { // The map is totally empty - bmapview = newPickmap(null, maparch, mapFile); // init the map + newPickmap(null, maparch, mapFile); // init the map } else { // go to ArchetypeParser and add the default arch list information to them if (!mainControl.collectTempList(objects, mapFile)) { // get face names, face id, etc. return false; } mainControl.getArchetypeParser().sortTempList(objects); // sort the list (put multiparts at the end) - bmapview = newPickmap(objects, maparch, mapFile); // init the map + newPickmap(objects, maparch, mapFile); // init the map } - if (bmapview == null) { - return false; - } - view.addPanel(mapFile.getName(), bmapview, getIndex(mapFile)); } catch (final IOException e) { // loading failed - could be a system file in that directory, // or something else. Doesn't deserve more attention than a printout. @@ -186,12 +183,7 @@ mapFile.getParentFile().mkdirs(); } - final CMapViewBasic bmapview = newPickmap(null, maparch, mapFile); - if (bmapview == null) { - return false; - } - view.addPanel(mapFile.getName(), bmapview, getIndex(mapFile)); - setActivePickmap(mapFile.getName()); + newPickmap(null, maparch, mapFile); actions.setLoadComplete(true); return true; } @@ -201,20 +193,19 @@ * @param objects list of objects or <code>null</code> for empty * @param maparch the maparch of the pickmap * @param mapFile The map file that's stored in the MapControl. - * @return basic mapview */ - private CMapViewBasic newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile) { + private void newPickmap(final List<GameObject> objects, final MapArchObject maparch, final File mapFile) { final MapControl mapControl = new MapControl(mainControl, objects, maparch, true, null); mapControl.getMapViewFrame().setAutoscrolls(true); mapControl.setMapFile(mapFile); + mapControl.resetModified(); - // add pickmap to hashtable - pickmaps.put(mapFile.getName(), mapControl); + final int index = getIndex(mapFile); + pickmaps.add(index, mapControl); + view.addPanel(mapFile.getName(), mapControl.getMapViewFrame().getBasicView(), index); - mapControl.resetModified(); + setActivePickmap(index); actions.setCurrentPickmap(mapControl); - - return mapControl.getMapViewFrame().getBasicView(); } /** @@ -223,35 +214,23 @@ * @return true when closing successful */ public boolean closePickmap(final MapControl mapControl) { - boolean mapClosed = false; - - final Iterator<String> keyit = pickmaps.keySet().iterator(); - while (!mapClosed && keyit.hasNext()) { - final String tmpKey = keyit.next(); - final MapControl tmpMap = pickmaps.get(tmpKey); - if (tmpMap == mapControl) { - pickmaps.remove(tmpKey); - view.removePanel(tmpMap.getMapViewFrame().getBasicView()); - mapClosed = true; - } + final int index = pickmaps.indexOf(mapControl); + if (index == -1) { + return false; } - if (mapClosed) { - updateActivePickmap(); - } - - return mapClosed; + pickmaps.remove(index); + view.removePanel(index); + updateActivePickmap(); + return true; } /** - * Set pickmap with given name to be the active one (ontop). - * @param name map name (which is also the tab title) + * Set pickmap with given tab index to be the active one (ontop). + * @param index the index into <code>pickmaps</code> */ - public void setActivePickmap(final String name) { - final MapControl tmpMap = pickmaps.get(name); - if (tmpMap != null) { - view.selectPanel(tmpMap.getMapViewFrame().getBasicView()); - } + public void setActivePickmap(final int index) { + view.selectPanel(index); } /** Update info which pickmap is currently on top. */ @@ -261,27 +240,13 @@ return; } - final String newName = view.getSelectedPanelTitle(); - if (newName == null) { + final int index = view.getSelectedPanel(); + if (index == -1) { actions.setCurrentPickmap(null); return; } - final MapControl tmp = pickmaps.get(newName); - boolean foundMap = false; - if (tmp != null && tmp.getMapFileName().endsWith("/"+newName)) { - // this is the new active pickmap - actions.setCurrentPickmap(tmp); // <- new pickmap - foundMap = true; - if (log.isDebugEnabled()) { - log.debug("new pickmap: " + newName); - } - } - - if (!foundMap && isPickmapActive() && isLoadComplete()) { - // error: the new selected pickmap couldn't be found - log.error("Bad Error in PickmapChooserControl.updateActivePickmap: Selected pickmap couldn't be found!"); - } + actions.setCurrentPickmap(pickmaps.get(index)); } /** @@ -390,7 +355,6 @@ mainControl.closeLevel(pickmap, true); // close the old map openPickmap(mfile); // open the new map - setActivePickmap(mfile.getName()); // Update the main view so the new map instantly pops up. mainControl.getMainView().update(mainControl.getMainView().getGraphics()); @@ -404,12 +368,19 @@ return view.getPickmapPanel(); } + /** + * Determine where to insert a new pickmap into {@link #pickmaps}. + * + * @param file the file of the pickmap to insert + * + * @return the insertion index + */ private int getIndex(final File file) { - int i; - for (i = 0; i < view.getPickmapPanel().getTabCount() && file.getName().compareToIgnoreCase(view.getPickmapPanel().getTitleAt(i)) < 0; i++) { - ; - } - return i; + int i; + for (i = 0; i < view.getPickmapPanel().getTabCount() && file.getName().compareToIgnoreCase(view.getPickmapPanel().getTitleAt(i)) > 0; i++) { + ; + } + return i; } } // class PickmapChooserControl Modified: trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserView.java 2007-01-08 23:14:47 UTC (rev 1520) +++ trunk/crossfire/src/cfeditor/gui/pickmapchooser/PickmapChooserView.java 2007-01-09 08:04:17 UTC (rev 1521) @@ -58,16 +58,16 @@ pickmapPanel.insertTab(name, null, mapView, null, index); } - void removePanel(final Component mapView) { - pickmapPanel.remove(mapView); + void removePanel(final int index) { + pickmapPanel.remove(index); } - void selectPanel(final Component mapView) { - pickmapPanel.setSelectedComponent(mapView); + void selectPanel(final int index) { + pickmapPanel.setSelectedIndex(index); } - String getSelectedPanelTitle() { - return pickmapPanel.getTitleAt(pickmapPanel.getSelectedIndex()); + int getSelectedPanel() { + return pickmapPanel.getSelectedIndex(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |