From: <der...@us...> - 2006-06-13 22:43:17
|
Revision: 151 Author: derdanny Date: 2006-06-13 15:43:08 -0700 (Tue, 13 Jun 2006) ViewCVS: http://svn.sourceforge.net/gridarta/?rev=151&view=rev Log Message: ----------- Fixed Mantis #419: Using the Replace feature throws NPE. Modified Paths: -------------- trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/ReplaceDialog.java trunk/daimonin/src/daieditor/map/MapControl.java Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-06-13 14:16:33 UTC (rev 150) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-06-13 22:43:08 UTC (rev 151) @@ -317,22 +317,6 @@ } /** - * Get Iterable of all MapSquares - * @return Iterable of all MapSquares - */ - public Iterable<MapSquare> getAllSquares() { - final Dimension mapSize = mapModel.getMapSize(); - final List<MapSquare> selection = new ArrayList<MapSquare>(mapSize.width * mapSize.height); - final Point pos = new Point(); - for (pos.x = 0; pos.x < mapSize.width; pos.x++) { - for (pos.y = 0; pos.y < mapSize.height; pos.y++) { - selection.add(mapModel.getMapSquare(pos)); - } - } - return selection; - } - - /** * Highlight the tile at given coordinates (just as if it had been selected with leftclick). * Besides, the mapview is always centered on the coordinates as far as possible. * @param pos coordinate Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-06-13 14:16:33 UTC (rev 150) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-06-13 22:43:08 UTC (rev 151) @@ -362,12 +362,17 @@ if (mapControl == null) { return null; } - final List<MapSquare> selectedMapSquares = mapControl.getMapViewFrame().view.getSelectedSquares(); + final CMapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); final Iterable<MapSquare> mapSquares; - if (selectedMapSquares.size() == 0) { - mapSquares = mapControl.getMapViewFrame().view.getAllSquares(); + if (mapViewIFrame == null) { + mapSquares = mapControl.getAllSquares(); } else { - mapSquares = selectedMapSquares; + final List<MapSquare> selectedMapSquares = mapViewIFrame.view.getSelectedSquares(); + if (selectedMapSquares.size() == 0) { + mapSquares = mapControl.getAllSquares(); + } else { + mapSquares = selectedMapSquares; + } } final List<ArchObject> objects = new ArrayList<ArchObject>(max); for (final MapSquare mapSquare : mapSquares) { @@ -473,7 +478,7 @@ * Returns mapControl for{@link #copyMap}. * @return mapControl for */ - public MapControl getCopyMapCtrl() { + @Nullable public MapControl getCopyMapCtrl() { return copyMapCtrl; } Modified: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-06-13 14:16:33 UTC (rev 150) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2006-06-13 22:43:08 UTC (rev 151) @@ -25,7 +25,6 @@ package daieditor; -import static net.sf.japi.swing.ActionFactory.getFactory; import daieditor.arch.ArchObject; import daieditor.map.MapControl; import daieditor.map.MapSquare; @@ -47,6 +46,7 @@ import javax.swing.JTextField; import static javax.swing.WindowConstants.HIDE_ON_CLOSE; import net.sf.japi.swing.ActionFactory; +import static net.sf.japi.swing.ActionFactory.getFactory; /** * This dialog manages the replace action. @@ -137,7 +137,7 @@ replaceCopyBuffer = CopyBuffer.getMapArchList(mainControl.getCopyMapCtrl(), 100); if (!isBuilt) { - this.mc = mapControl; + mc = mapControl; final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); @@ -148,7 +148,8 @@ line1.add(labelon); line1.add(Box.createVerticalStrut(3)); replaceEntireBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceOnMap"), ACTION_FACTORY.getString("replaceOnSelection")}); - if (mapControl.getMapViewFrame().isHighlight()) { + final CMapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { replaceEntireBox.setSelectedIndex(1); } else { replaceEntireBox.setSelectedIndex(0); @@ -222,7 +223,7 @@ rfHeading.setText('\"' + mapControl.getMapFileName() + "\":"); replaceInput1.setText(""); - this.mc = mapControl; + mc = mapControl; if (replaceArch == null) { replaceWithBox.setSelectedIndex(1); iconLabel.setIcon(null); @@ -234,7 +235,8 @@ rfArchName.setText(' ' + replaceArch.getBestName()); colonLabel.setText(":"); } - if (mapControl.getMapViewFrame().isHighlight()) { + final CMapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { replaceEntireBox.setSelectedIndex(1); // selected squares } else { replaceEntireBox.setSelectedIndex(0); // entire map Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-06-13 14:16:33 UTC (rev 150) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-06-13 22:43:08 UTC (rev 151) @@ -660,11 +660,11 @@ mapViewFrame = new CMapViewIFrame(mainControl, this, ++viewCounter); mapViewIFrames.add(mapViewFrame); if (!isPickmap) { - assert mapViewFrame != null; mainControl.getMainView().addLevelView(mapViewFrame); assert mapViewFrame != null; mapViewFrame.setAutoscrolls(true); } + assert mapViewFrame != null; return mapViewFrame; } @@ -718,4 +718,12 @@ public void setFocus(final CMapViewIFrame view) { mapViewFrame = view; } + + /** + * Get Iterable of all MapSquares. + * @return Iterable of all MapSquares + */ + public Iterable<MapSquare> getAllSquares() { + return mapModel; + } } // class MapControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |