[vassalengine-svn] SF.net SVN: vassalengine: [2471] VASSAL-src/branches/ uckelman-scaling-tiling/VA
Brought to you by:
rodneykinney,
uckelman
From: <uck...@us...> - 2007-09-30 22:29:26
|
Revision: 2471 http://vassalengine.svn.sourceforge.net/vassalengine/?rev=2471&view=rev Author: uckelman Date: 2007-09-30 15:29:29 -0700 (Sun, 30 Sep 2007) Log Message: ----------- Marked calls to Map.repaint(). Other minor changes. Modified Paths: -------------- VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/GameModule.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/Map.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/KeyBufferer.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/LOS_Thread.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/LayerControl.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/MapShader.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/MenuDisplayer.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/PieceMover.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/PieceRecenterer.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/Zoomer.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/map/boardPicker/board/mapgrid/Zone.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/counters/Deck.java VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/counters/KeyBuffer.java Modified: VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/GameModule.java =================================================================== --- VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/GameModule.java 2007-09-30 22:04:00 UTC (rev 2470) +++ VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/GameModule.java 2007-09-30 22:29:29 UTC (rev 2471) @@ -118,7 +118,8 @@ public void propertyChange(PropertyChangeEvent evt) { for (Iterator maps = Map.getAllMaps(); maps.hasNext(); ) { Map map = (Map) maps.next(); - map.repaint(); + map.repaint(); // FIXME: is this ok? + System.out.println("GameModule:121"); } } }; Modified: VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/Map.java =================================================================== --- VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/Map.java 2007-09-30 22:04:00 UTC (rev 2470) +++ VASSAL-src/branches/uckelman-scaling-tiling/VASSAL/build/module/Map.java 2007-09-30 22:29:29 UTC (rev 2471) @@ -156,49 +156,64 @@ import VASSAL.tools.UniqueIdManager; /** - * The Map is the main component for displaying and containing {@link GamePiece}s during play. Pieces are displayed on - * a Map and moved by clicking and dragging. Keyboard events are forwarded to selected pieces. Multiple map windows are - * supported in a single game, with dragging between windows allowed. + * The Map is the main component for displaying and containing + * {@link GamePiece}s during play. + * + * Pieces are displayed on a Map and moved by clicking and dragging. + * Keyboard events are forwarded to selected pieces. Multiple map windows + * are supported in a single game, with dragging between windows allowed. * - * A Map may contain many different {@link Buildable} subcomponents. Components which are added directly to a Map are - * contained in the <code>VASSAL.build.module.map</code> package + * A Map may contain many different {@link Buildable} subcomponents. + * Components which are added directly to a Map are contained in the + * <code>VASSAL.build.module.map</code> package. */ -public class Map extends AbstractConfigurable implements GameComponent, MouseListener, MouseMotionListener, DropTargetListener, Configurable, - UniqueIdManager.Identifyable, ToolBarComponent, MutablePropertiesContainer, PropertySource, PlayerRoster.SideChangeListener, Runnable { +public class Map + extends AbstractConfigurable + implements GameComponent, + MouseListener, + MouseMotionListener, + DropTargetListener, + Configurable, + UniqueIdManager.Identifyable, + ToolBarComponent, + MutablePropertiesContainer, + PropertySource, + PlayerRoster.SideChangeListener, + Runnable { protected String mapID = ""; //$NON-NLS-1$ protected String mapName = ""; //$NON-NLS-1$ protected static final String MAIN_WINDOW_HEIGHT = "mainWindowHeight"; //$NON-NLS-1$ protected static UniqueIdManager idMgr = new UniqueIdManager("Map"); //$NON-NLS-1$ - protected JPanel theMap; + protected JPanel theMap; protected ArrayList<Drawable> drawComponents = new ArrayList<Drawable>(); protected JLayeredPane layeredPane; - protected JScrollPane scroll; - protected ComponentSplitter.SplitPane mainWindowDock; - protected BoardPicker picker; - protected JToolBar toolBar = new JToolBar(); - protected Zoomer zoom; - protected StackMetrics metrics; - protected Dimension edgeBuffer = new Dimension(0, 0); - protected LaunchButton launchButton; - protected boolean useLaunchButton = false; - protected String markMovedOption = GlobalOptions.ALWAYS; - protected String markUnmovedIcon = "/images/unmoved.gif"; //$NON-NLS-1$ + protected JScrollPane scroll; + protected ComponentSplitter.SplitPane mainWindowDock; + protected BoardPicker picker; + protected JToolBar toolBar = new JToolBar(); + protected Zoomer zoom; + protected StackMetrics metrics; + protected Dimension edgeBuffer = new Dimension(0, 0); + protected LaunchButton launchButton; + protected boolean useLaunchButton = false; + protected String markMovedOption = GlobalOptions.ALWAYS; + protected String markUnmovedIcon = "/images/unmoved.gif"; //$NON-NLS-1$ protected String markUnmovedText = ""; //$NON-NLS-1$ protected String markUnmovedTooltip = Resources.getString("Map.mark_unmoved"); //$NON-NLS-1$ - protected MouseListener multicaster = null; - protected ArrayList<MouseListener> mouseListenerStack = + protected MouseListener multicaster = null; + protected ArrayList<MouseListener> mouseListenerStack = new ArrayList<MouseListener>(); - protected ArrayList<Board> boards = new ArrayList<Board>(); - protected int[][] boardWidths; // Cache of board widths by row/column + protected ArrayList<Board> boards = new ArrayList<Board>(); + protected int[][] boardWidths; // Cache of board widths by row/column protected int[][] boardHeights; // Cache of board heights by row/column - protected PieceCollection pieces = new DefaultPieceCollection(); - protected Highlighter highlighter = new ColoredBorder(); + protected PieceCollection pieces = new DefaultPieceCollection(); + protected Highlighter highlighter = new ColoredBorder(); protected ArrayList<Highlighter> highlighters = new ArrayList<Highlighter>(); protected boolean clearFirst = false; // Whether to clear the display before - // drawing the map + // drawing the map protected boolean hideCounters = false; // Option to hide counters to see - // map - protected float pieceOpacity = 1.0f; + // map + protected float pieceOpacity = 1.0f; protected boolean allowMultiple = false; protected VisibilityCondition visibilityCondition; protected DragGestureListener dragGestureListener; @@ -206,59 +221,60 @@ protected String moveToFormat; protected String createFormat; protected String changeFormat = "$" + MESSAGE + "$"; //$NON-NLS-1$ //$NON-NLS-2$ - protected KeyStroke moveKey; - protected PropertyChangeListener globalPropertyListener; + protected KeyStroke moveKey; + protected PropertyChangeListener globalPropertyListener; protected String tooltip = ""; //$NON-NLS-1$ protected MutablePropertiesContainer propsContainer = new MutablePropertiesContainer.Impl(); protected PropertyChangeListener repaintOnPropertyChange = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { - repaint(); + repaint(); // FIXME + System.out.println("Map:231"); } }; protected PieceMover pieceMover; - public Map() { - getView(); - theMap.addMouseListener(this); + public Map() { + getView(); + theMap.addMouseListener(this); toolBar.setLayout(new VASSAL.tools.WrapLayout(FlowLayout.LEFT, 0, 0)); toolBar.setAlignmentX(0.0F); - toolBar.setFloatable(false); - } + toolBar.setFloatable(false); + } - public static final String NAME = "mapName"; //$NON-NLS-1$ - public static final String MARK_MOVED = "markMoved"; //$NON-NLS-1$ - public static final String MARK_UNMOVED_ICON = "markUnmovedIcon"; //$NON-NLS-1$ + public static final String NAME = "mapName"; //$NON-NLS-1$ + public static final String MARK_MOVED = "markMoved"; //$NON-NLS-1$ + public static final String MARK_UNMOVED_ICON = "markUnmovedIcon"; //$NON-NLS-1$ public static final String MARK_UNMOVED_TEXT = "markUnmovedText"; //$NON-NLS-1$ public static final String MARK_UNMOVED_TOOLTIP = "markUnmovedTooltip"; //$NON-NLS-1$ - public static final String EDGE_WIDTH = "edgeWidth"; //$NON-NLS-1$ - public static final String EDGE_HEIGHT = "edgeHeight"; //$NON-NLS-1$ - public static final String HIGHLIGHT_COLOR = "color"; //$NON-NLS-1$ - public static final String HIGHLIGHT_THICKNESS = "thickness"; //$NON-NLS-1$ - public static final String ALLOW_MULTIPLE = "allowMultiple"; //$NON-NLS-1$ - public static final String USE_LAUNCH_BUTTON = "launch"; //$NON-NLS-1$ - public static final String BUTTON_NAME = "buttonName"; //$NON-NLS-1$ + public static final String EDGE_WIDTH = "edgeWidth"; //$NON-NLS-1$ + public static final String EDGE_HEIGHT = "edgeHeight"; //$NON-NLS-1$ + public static final String HIGHLIGHT_COLOR = "color"; //$NON-NLS-1$ + public static final String HIGHLIGHT_THICKNESS = "thickness"; //$NON-NLS-1$ + public static final String ALLOW_MULTIPLE = "allowMultiple"; //$NON-NLS-1$ + public static final String USE_LAUNCH_BUTTON = "launch"; //$NON-NLS-1$ + public static final String BUTTON_NAME = "buttonName"; //$NON-NLS-1$ public static final String TOOLTIP = "tooltip"; //$NON-NLS-1$ - public static final String ICON = "icon"; //$NON-NLS-1$ - public static final String HOTKEY = "hotkey"; //$NON-NLS-1$ - public static final String SUPPRESS_AUTO = "suppressAuto"; //$NON-NLS-1$ - public static final String MOVE_WITHIN_FORMAT = "moveWithinFormat"; //$NON-NLS-1$ - public static final String MOVE_TO_FORMAT = "moveToFormat"; //$NON-NLS-1$ - public static final String CREATE_FORMAT = "createFormat"; //$NON-NLS-1$ - public static final String CHANGE_FORMAT = "changeFormat"; //$NON-NLS-1$ - public static final String MOVE_KEY = "moveKey"; //$NON-NLS-1$ + public static final String ICON = "icon"; //$NON-NLS-1$ + public static final String HOTKEY = "hotkey"; //$NON-NLS-1$ + public static final String SUPPRESS_AUTO = "suppressAuto"; //$NON-NLS-1$ + public static final String MOVE_WITHIN_FORMAT = "moveWithinFormat"; //$NON-NLS-1$ + public static final String MOVE_TO_FORMAT = "moveToFormat"; //$NON-NLS-1$ + public static final String CREATE_FORMAT = "createFormat"; //$NON-NLS-1$ + public static final String CHANGE_FORMAT = "changeFormat"; //$NON-NLS-1$ + public static final String MOVE_KEY = "moveKey"; //$NON-NLS-1$ public static final String MOVING_STACKS_PICKUP_UNITS = "movingStacksPickupUnits"; //$NON-NLS-1$ - public void setAttribute(String key, Object value) { - if (NAME.equals(key)) { - setMapName((String) value); - } - else if (MARK_MOVED.equals(key)) { - markMovedOption = (String) value; - } - else if (MARK_UNMOVED_ICON.equals(key)) { - markUnmovedIcon = (String) value; - } + public void setAttribute(String key, Object value) { + if (NAME.equals(key)) { + setMapName((String) value); + } + else if (MARK_MOVED.equals(key)) { + markMovedOption = (String) value; + } + else if (MARK_UNMOVED_ICON.equals(key)) { + markUnmovedIcon = (String) value; + } else if (MARK_UNMOVED_TEXT.equals(key)) { markUnmovedText = (String) value; if (pieceMover != null) { @@ -268,297 +284,297 @@ else if (MARK_UNMOVED_TOOLTIP.equals(key)) { markUnmovedTooltip = (String) value; } - else if ("edge".equals(key)) { // Backward-compatible //$NON-NLS-1$ - String s = (String) value; - int i = s.indexOf(","); //$NON-NLS-1$ - if (i > 0) { - edgeBuffer = new Dimension(Integer.parseInt(s.substring(0, i)), Integer.parseInt(s.substring(i + 1))); - } - } - else if (EDGE_WIDTH.equals(key)) { - if (value instanceof String) { - value = new Integer((String) value); - } - try { - edgeBuffer = new Dimension(((Integer) value).intValue(), edgeBuffer.height); - } - catch (NumberFormatException ex) { - } - } - else if (EDGE_HEIGHT.equals(key)) { - if (value instanceof String) { - value = new Integer((String) value); - } - try { - edgeBuffer = new Dimension(edgeBuffer.width, ((Integer) value).intValue()); - } - catch (NumberFormatException ex) { - } - } - else if (ALLOW_MULTIPLE.equals(key)) { - if (value instanceof String) { - value = new Boolean((String) value); - } - allowMultiple = ((Boolean) value).booleanValue(); - if (picker != null) { - picker.setAllowMultiple(allowMultiple); - } - } - else if (HIGHLIGHT_COLOR.equals(key)) { - if (value instanceof String) { - value = ColorConfigurer.stringToColor((String) value); - } - if (value != null) { - ((ColoredBorder) highlighter).setColor((Color) value); - } - } - else if (HIGHLIGHT_THICKNESS.equals(key)) { - if (value instanceof String) { - value = new Integer((String) value); - } - if (highlighter instanceof ColoredBorder) { - ((ColoredBorder) highlighter).setThickness(((Integer) value).intValue()); - } - } - else if (USE_LAUNCH_BUTTON.equals(key)) { - if (value instanceof String) { - value = new Boolean((String) value); - } - useLaunchButton = ((Boolean) value).booleanValue(); - launchButton.setVisible(useLaunchButton); - } - else if (SUPPRESS_AUTO.equals(key)) { - if (value instanceof String) { - value = new Boolean((String) value); - } - if (Boolean.TRUE.equals(value)) { - moveWithinFormat = ""; //$NON-NLS-1$ - } - } - else if (MOVE_WITHIN_FORMAT.equals(key)) { - moveWithinFormat = (String) value; - } - else if (MOVE_TO_FORMAT.equals(key)) { - moveToFormat = (String) value; - } - else if (CREATE_FORMAT.equals(key)) { - createFormat = (String) value; - } - else if (CHANGE_FORMAT.equals(key)) { - changeFormat = (String) value; - } - else if (MOVE_KEY.equals(key)) { - if (value instanceof String) { - value = HotKeyConfigurer.decode((String) value); - } - moveKey = (KeyStroke) value; - } + else if ("edge".equals(key)) { // Backward-compatible //$NON-NLS-1$ + String s = (String) value; + int i = s.indexOf(","); //$NON-NLS-1$ + if (i > 0) { + edgeBuffer = new Dimension(Integer.parseInt(s.substring(0, i)), Integer.parseInt(s.substring(i + 1))); + } + } + else if (EDGE_WIDTH.equals(key)) { + if (value instanceof String) { + value = new Integer((String) value); + } + try { + edgeBuffer = new Dimension(((Integer) value).intValue(), edgeBuffer.height); + } + catch (NumberFormatException ex) { + } + } + else if (EDGE_HEIGHT.equals(key)) { + if (value instanceof String) { + value = new Integer((String) value); + } + try { + edgeBuffer = new Dimension(edgeBuffer.width, ((Integer) value).intValue()); + } + catch (NumberFormatException ex) { + } + } + else if (ALLOW_MULTIPLE.equals(key)) { + if (value instanceof String) { + value = new Boolean((String) value); + } + allowMultiple = ((Boolean) value).booleanValue(); + if (picker != null) { + picker.setAllowMultiple(allowMultiple); + } + } + else if (HIGHLIGHT_COLOR.equals(key)) { + if (value instanceof String) { + value = ColorConfigurer.stringToColor((String) value); + } + if (value != null) { + ((ColoredBorder) highlighter).setColor((Color) value); + } + } + else if (HIGHLIGHT_THICKNESS.equals(key)) { + if (value instanceof String) { + value = new Integer((String) value); + } + if (highlighter instanceof ColoredBorder) { + ((ColoredBorder) highlighter).setThickness(((Integer) value).intValue()); + } + } + else if (USE_LAUNCH_BUTTON.equals(key)) { + if (value instanceof String) { + value = new Boolean((String) value); + } + useLaunchButton = ((Boolean) value).booleanValue(); + launchButton.setVisible(useLaunchButton); + } + else if (SUPPRESS_AUTO.equals(key)) { + if (value instanceof String) { + value = new Boolean((String) value); + } + if (Boolean.TRUE.equals(value)) { + moveWithinFormat = ""; //$NON-NLS-1$ + } + } + else if (MOVE_WITHIN_FORMAT.equals(key)) { + moveWithinFormat = (String) value; + } + else if (MOVE_TO_FORMAT.equals(key)) { + moveToFormat = (String) value; + } + else if (CREATE_FORMAT.equals(key)) { + createFormat = (String) value; + } + else if (CHANGE_FORMAT.equals(key)) { + changeFormat = (String) value; + } + else if (MOVE_KEY.equals(key)) { + if (value instanceof String) { + value = HotKeyConfigurer.decode((String) value); + } + moveKey = (KeyStroke) value; + } else if (TOOLTIP.equals(key)) { tooltip = (String) value; launchButton.setAttribute(key, value); } - else { - launchButton.setAttribute(key, value); - } - } + else { + launchButton.setAttribute(key, value); + } + } - public String getAttributeValueString(String key) { - if (NAME.equals(key)) { - return getMapName(); - } - else if (MARK_MOVED.equals(key)) { - return markMovedOption; - } - else if (MARK_UNMOVED_ICON.equals(key)) { - return markUnmovedIcon; - } + public String getAttributeValueString(String key) { + if (NAME.equals(key)) { + return getMapName(); + } + else if (MARK_MOVED.equals(key)) { + return markMovedOption; + } + else if (MARK_UNMOVED_ICON.equals(key)) { + return markUnmovedIcon; + } else if (MARK_UNMOVED_TEXT.equals(key)) { return markUnmovedText; } else if (MARK_UNMOVED_TOOLTIP.equals(key)) { return markUnmovedTooltip; } - else if (EDGE_WIDTH.equals(key)) { - return "" + edgeBuffer.width; //$NON-NLS-1$ - } - else if (EDGE_HEIGHT.equals(key)) { - return "" + edgeBuffer.height; //$NON-NLS-1$ - } - else if (ALLOW_MULTIPLE.equals(key)) { - return "" + picker.isAllowMultiple(); //$NON-NLS-1$ - } - else if (HIGHLIGHT_COLOR.equals(key)) { - if (highlighter instanceof ColoredBorder) { - return ColorConfigurer.colorToString(((ColoredBorder) highlighter).getColor()); - } - else { - return null; - } - } - else if (HIGHLIGHT_THICKNESS.equals(key)) { - if (highlighter instanceof ColoredBorder) { - return "" + ((ColoredBorder) highlighter).getThickness(); //$NON-NLS-1$ - } - else { - return null; - } - } - else if (USE_LAUNCH_BUTTON.equals(key)) { - return String.valueOf(useLaunchButton); - } - else if (MOVE_WITHIN_FORMAT.equals(key)) { - return getMoveWithinFormat(); - } - else if (MOVE_TO_FORMAT.equals(key)) { - return getMoveToFormat(); - } - else if (CREATE_FORMAT.equals(key)) { - return getCreateFormat(); - } - else if (CHANGE_FORMAT.equals(key)) { - return getChangeFormat(); - } - else if (MOVE_KEY.equals(key)) { - return HotKeyConfigurer.encode(moveKey); - } + else if (EDGE_WIDTH.equals(key)) { + return "" + edgeBuffer.width; //$NON-NLS-1$ + } + else if (EDGE_HEIGHT.equals(key)) { + return "" + edgeBuffer.height; //$NON-NLS-1$ + } + else if (ALLOW_MULTIPLE.equals(key)) { + return "" + picker.isAllowMultiple(); //$NON-NLS-1$ + } + else if (HIGHLIGHT_COLOR.equals(key)) { + if (highlighter instanceof ColoredBorder) { + return ColorConfigurer.colorToString(((ColoredBorder) highlighter).getColor()); + } + else { + return null; + } + } + else if (HIGHLIGHT_THICKNESS.equals(key)) { + if (highlighter instanceof ColoredBorder) { + return "" + ((ColoredBorder) highlighter).getThickness(); //$NON-NLS-1$ + } + else { + return null; + } + } + else if (USE_LAUNCH_BUTTON.equals(key)) { + return String.valueOf(useLaunchButton); + } + else if (MOVE_WITHIN_FORMAT.equals(key)) { + return getMoveWithinFormat(); + } + else if (MOVE_TO_FORMAT.equals(key)) { + return getMoveToFormat(); + } + else if (CREATE_FORMAT.equals(key)) { + return getCreateFormat(); + } + else if (CHANGE_FORMAT.equals(key)) { + return getChangeFormat(); + } + else if (MOVE_KEY.equals(key)) { + return HotKeyConfigurer.encode(moveKey); + } else if (TOOLTIP.equals(key)) { return (tooltip == null || tooltip.length() == 0) ? launchButton.getAttributeValueString(name) : tooltip; } - else { - return launchButton.getAttributeValueString(key); - } - } + else { + return launchButton.getAttributeValueString(key); + } + } - public void build(Element e) { - ActionListener al = new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (mainWindowDock == null && launchButton.isEnabled() && theMap.getTopLevelAncestor() != null) { - theMap.getTopLevelAncestor().setVisible(!theMap.getTopLevelAncestor().isVisible()); - } - } - }; - launchButton = new LaunchButton("Map", TOOLTIP, BUTTON_NAME, HOTKEY, ICON, al); - launchButton.setEnabled(false); - launchButton.setVisible(false); - if (e != null) { - super.build(e); - } - else { - getBoardPicker(); - getStackMetrics(); - addChild(new ForwardToKeyBuffer()); - addChild(new Scroller()); - addChild(new ForwardToChatter()); - addChild(new MenuDisplayer()); - addChild(new MapCenterer()); - addChild(new StackExpander()); - addChild(new PieceMover()); - addChild(new KeyBufferer()); - addChild(new ImageSaver()); - addChild(new CounterDetailViewer()); - setMapName("Main Map"); - } - if (getComponentsOf(GlobalProperties.class).isEmpty()) { - addChild(new GlobalProperties()); - } + public void build(Element e) { + ActionListener al = new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (mainWindowDock == null && launchButton.isEnabled() && theMap.getTopLevelAncestor() != null) { + theMap.getTopLevelAncestor().setVisible(!theMap.getTopLevelAncestor().isVisible()); + } + } + }; + launchButton = new LaunchButton("Map", TOOLTIP, BUTTON_NAME, HOTKEY, ICON, al); + launchButton.setEnabled(false); + launchButton.setVisible(false); + if (e != null) { + super.build(e); + } + else { + getBoardPicker(); + getStackMetrics(); + addChild(new ForwardToKeyBuffer()); + addChild(new Scroller()); + addChild(new ForwardToChatter()); + addChild(new MenuDisplayer()); + addChild(new MapCenterer()); + addChild(new StackExpander()); + addChild(new PieceMover()); + addChild(new KeyBufferer()); + addChild(new ImageSaver()); + addChild(new CounterDetailViewer()); + setMapName("Main Map"); + } + if (getComponentsOf(GlobalProperties.class).isEmpty()) { + addChild(new GlobalProperties()); + } if (getComponentsOf(SelectionHighlighters.class).isEmpty()) { addChild(new SelectionHighlighters()); } if (getComponentsOf(HighlightLastMoved.class).isEmpty()) { addChild(new HighlightLastMoved()); } - setup(false); - } + setup(false); + } - private void addChild(Buildable b) { - add(b); - b.addTo(this); - } + private void addChild(Buildable b) { + add(b); + b.addTo(this); + } - /** + /** * Every map must include a {@link BoardPicker} as one of its build components */ - public void setBoardPicker(BoardPicker picker) { - if (this.picker != null) { - GameModule.getGameModule().removeCommandEncoder(picker); - GameModule.getGameModule().getGameState().addGameComponent(picker); - } - this.picker = picker; - if (picker != null) { - picker.setAllowMultiple(allowMultiple); - GameModule.getGameModule().addCommandEncoder(picker); - GameModule.getGameModule().getGameState().addGameComponent(picker); - } - } + public void setBoardPicker(BoardPicker picker) { + if (this.picker != null) { + GameModule.getGameModule().removeCommandEncoder(picker); + GameModule.getGameModule().getGameState().addGameComponent(picker); + } + this.picker = picker; + if (picker != null) { + picker.setAllowMultiple(allowMultiple); + GameModule.getGameModule().addCommandEncoder(picker); + GameModule.getGameModule().getGameState().addGameComponent(picker); + } + } - /** + /** * Every map must include a {@link BoardPicker} as one of its build components * * @return the BoardPicker for this map */ - public BoardPicker getBoardPicker() { - if (picker == null) { - picker = new BoardPicker(); - picker.build(null); - add(picker); - picker.addTo(this); - } - return picker; - } + public BoardPicker getBoardPicker() { + if (picker == null) { + picker = new BoardPicker(); + picker.build(null); + add(picker); + picker.addTo(this); + } + return picker; + } - /** + /** * A map may include a {@link Zoomer} as one of its build components */ - public void setZoomer(Zoomer z) { - zoom = z; - } + public void setZoomer(Zoomer z) { + zoom = z; + } - /** + /** * A map may include a {@link Zoomer} as one of its build components * * @return the Zoomer for this map */ - public Zoomer getZoomer() { - return zoom; - } + public Zoomer getZoomer() { + return zoom; + } - /** + /** * Every map must include a {@link StackMetrics} as one of its build components, which governs the stacking behavior * of GamePieces on the map */ - public void setStackMetrics(StackMetrics sm) { - metrics = sm; - } + public void setStackMetrics(StackMetrics sm) { + metrics = sm; + } - /** + /** * Every map must include a {@link StackMetrics} as one of its build * components, which governs the stacking behavior of GamePieces on the map * * @return the StackMetrics for this map */ - public StackMetrics getStackMetrics() { - if (metrics == null) { - metrics = new StackMetrics(); - metrics.build(null); - add(metrics); - metrics.addTo(this); - } - return metrics; - } + public StackMetrics getStackMetrics() { + if (metrics == null) { + metrics = new StackMetrics(); + metrics.build(null); + add(metrics); + metrics.addTo(this); + } + return metrics; + } - /** + /** * @return the current zoom factor for the map */ - public double getZoom() { - return zoom == null ? 1.0 : zoom.getZoomFactor(); - } + public double getZoom() { + return zoom == null ? 1.0 : zoom.getZoomFactor(); + } - /** + /** * @return the toolbar for this map's window */ - public JToolBar getToolBar() { - return toolBar; - } + public JToolBar getToolBar() { + return toolBar; + } /** @@ -566,20 +582,20 @@ * * @see #paint */ - public void addDrawComponent(Drawable theComponent) { - drawComponents.add(theComponent); - } + public void addDrawComponent(Drawable theComponent) { + drawComponents.add(theComponent); + } - /** + /** * Remove a {@link Drawable} component from this map * * @see #paint */ - public void removeDrawComponent(Drawable theComponent) { - drawComponents.remove(theComponent); - } + public void removeDrawComponent(Drawable theComponent) { + drawComponents.remove(theComponent); + } - /** + /** * Expects to be added to a {@link GameModule}. Determines a unique id for * this Map. Registers itself as {@link KeyStrokeSource}. Registers itself * as a {@link GameComponent}. Registers itself as a drop target and drag @@ -588,61 +604,62 @@ * @see #getId * @see DragBuffer */ - public void addTo(Buildable b) { - idMgr.add(this); + public void addTo(Buildable b) { + idMgr.add(this); GameModule.getGameModule().addCommandEncoder(new ChangePropertyCommandEncoder(this)); - validator = new CompoundValidityChecker(new MandatoryComponent(this, BoardPicker.class), new MandatoryComponent(this, StackMetrics.class)).append(idMgr); - DragGestureListener dgl = new DragGestureListener() { - public void dragGestureRecognized(DragGestureEvent dge) { - if (mouseListenerStack.isEmpty() && dragGestureListener != null) { - dragGestureListener.dragGestureRecognized(dge); - } - } - }; - DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(theMap, DnDConstants.ACTION_MOVE, dgl); - theMap.setDropTarget(PieceMover.DragHandler.makeDropTarget(theMap, DnDConstants.ACTION_MOVE, this)); - GameModule.getGameModule().getGameState().addGameComponent(this); - GameModule.getGameModule().getToolBar().add(launchButton); - if (shouldDockIntoMainWindow()) { - IntConfigurer config = new IntConfigurer(MAIN_WINDOW_HEIGHT, null, new Integer(-1)); - Prefs.getGlobalPrefs().addOption(null, config); - ComponentSplitter splitter = new ComponentSplitter(); - mainWindowDock = splitter.splitBottom(splitter.getSplitAncestor(GameModule.getGameModule().getControlPanel(), -1), layeredPane, true); - GameModule.getGameModule().addKeyStrokeSource(new KeyStrokeSource(theMap, JComponent.WHEN_FOCUSED)); - } - else { - } - PlayerRoster.addSideChangeListener(this); + validator = new CompoundValidityChecker(new MandatoryComponent(this, BoardPicker.class), new MandatoryComponent(this, StackMetrics.class)).append(idMgr); + DragGestureListener dgl = new DragGestureListener() { + public void dragGestureRecognized(DragGestureEvent dge) { + if (mouseListenerStack.isEmpty() && dragGestureListener != null) { + dragGestureListener.dragGestureRecognized(dge); + } + } + }; + DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(theMap, DnDConstants.ACTION_MOVE, dgl); + theMap.setDropTarget(PieceMover.DragHandler.makeDropTarget(theMap, DnDConstants.ACTION_MOVE, this)); + GameModule.getGameModule().getGameState().addGameComponent(this); + GameModule.getGameModule().getToolBar().add(launchButton); + if (shouldDockIntoMainWindow()) { + IntConfigurer config = new IntConfigurer(MAIN_WINDOW_HEIGHT, null, new Integer(-1)); + Prefs.getGlobalPrefs().addOption(null, config); + ComponentSplitter splitter = new ComponentSplitter(); + mainWindowDock = splitter.splitBottom(splitter.getSplitAncestor(GameModule.getGameModule().getControlPanel(), -1), layeredPane, true); + GameModule.getGameModule().addKeyStrokeSource(new KeyStrokeSource(theMap, JComponent.WHEN_FOCUSED)); + } + else { + } + PlayerRoster.addSideChangeListener(this); GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"), //$NON-NLS-1$ new IntConfigurer(PREFERRED_EDGE_DELAY, Resources.getString("Map.scroll_delay_preference"), new Integer(PREFERRED_EDGE_SCROLL_DELAY))); //$NON-NLS-1$ GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"), //$NON-NLS-1$ new BooleanConfigurer(MOVING_STACKS_PICKUP_UNITS, Resources.getString("Map.moving_stacks_preference"), Boolean.FALSE)); //$NON-NLS-1$ - } + } public void setPieceMover(PieceMover mover) { pieceMover = mover; } - public void removeFrom(Buildable b) { - GameModule.getGameModule().getGameState().removeGameComponent(this); - Window w = SwingUtilities.getWindowAncestor(theMap); - if (w != null) { - w.dispose(); - } - GameModule.getGameModule().getToolBar().remove(launchButton); - idMgr.remove(this); - if (picker != null) { - GameModule.getGameModule().removeCommandEncoder(picker); - GameModule.getGameModule().getGameState().addGameComponent(picker); - } - PlayerRoster.removeSideChangeListener(this); - } + public void removeFrom(Buildable b) { + GameModule.getGameModule().getGameState().removeGameComponent(this); + Window w = SwingUtilities.getWindowAncestor(theMap); + if (w != null) { + w.dispose(); + } + GameModule.getGameModule().getToolBar().remove(launchButton); + idMgr.remove(this); + if (picker != null) { + GameModule.getGameModule().removeCommandEncoder(picker); + GameModule.getGameModule().getGameState().addGameComponent(picker); + } + PlayerRoster.removeSideChangeListener(this); + } - public void sideChanged(String oldSide, String newSide) { - repaint(); - } + public void sideChanged(String oldSide, String newSide) { + repaint(); // FIXME: minimal repaint? + System.out.println("Map:659"); + } - /** + /** * Set the boards for this map. Each map may contain more than one * {@link Board}. */ @@ -656,48 +673,48 @@ setBoardBoundaries(); } - /** + /** * Set the boards for this map. Each map may contain more than one * {@link Board}. * @deprecated Use {@link #setBoards(Collection<Board>)} instead. */ @Deprecated @SuppressWarnings("unchecked") - public synchronized void setBoards(Enumeration boardList) { + public synchronized void setBoards(Enumeration boardList) { setBoards(Collections.list(boardList)); - } + } - public Command getRestoreCommand() { - return null; - } + public Command getRestoreCommand() { + return null; + } - /** + /** * @return the {@link Board} on this map containing the argument point */ - public Board findBoard(Point p) { + public Board findBoard(Point p) { for (Board b : boards) { - if (b.bounds().contains(p)) - return b; - } - return null; - } + if (b.bounds().contains(p)) + return b; + } + return null; + } - /** + /** * * @return the {@link Zone} on this map containing the argument point */ - public Zone findZone(Point p) { - Board b = findBoard(p); - if (b != null) { - MapGrid grid = b.getGrid(); - if (grid != null && grid instanceof ZonedGrid) { + public Zone findZone(Point p) { + Board b = findBoard(p); + if (b != null) { + MapGrid grid = b.getGrid(); + if (grid != null && grid instanceof ZonedGrid) { Rectangle r = b.bounds(); p.translate(-r.x, -r.y); // Translate to Board co-ords - return ((ZonedGrid) grid).findZone(p); - } - } - return null; - } + return ((ZonedGrid) grid).findZone(p); + } + } + return null; + } /** * Search on all boards for a Zone with the given name @@ -733,13 +750,13 @@ return null; } - /** + /** * Return the board with the given name * * @param name * @return null if no such board found */ - public Board getBoardByName(String name) { + public Board getBoardByName(String name) { if (name != null) { for (Board b : boards) { if (name.equals(b.getName())) { @@ -748,152 +765,152 @@ } } return null; - } + } - public Dimension getPreferredSize() { - return new Dimension((int) (getZoom() * mapSize().width), + public Dimension getPreferredSize() { + return new Dimension((int) (getZoom() * mapSize().width), (int) (getZoom() * mapSize().height)); - } + } - /** + /** * @return the size of the map in pixels at 100% zoom, * including the edge buffer */ - public synchronized Dimension mapSize() { - Rectangle r = new Rectangle(0, 0); + public synchronized Dimension mapSize() { + Rectangle r = new Rectangle(0, 0); for (Board b : boards) { r = r.union(b.bounds()); } - r.width += edgeBuffer.width; - r.height += edgeBuffer.height; - return r.getSize(); - } + r.width += edgeBuffer.width; + r.height += edgeBuffer.height; + return r.getSize(); + } - /** + /** * @return true if the given point may not be a local location. I.e., if this grid will attempt to snap it to the * nearest grid location */ - public boolean isLocationRestricted(Point p) { - Board b = findBoard(p); - if (b != null) { - Rectangle r = b.bounds(); - Point snap = new Point(p); - snap.translate(-r.x, -r.y); - return b.isLocationRestricted(snap); - } - else { - return false; - } - } + public boolean isLocationRestricted(Point p) { + Board b = findBoard(p); + if (b != null) { + Rectangle r = b.bounds(); + Point snap = new Point(p); + snap.translate(-r.x, -r.y); + return b.isLocationRestricted(snap); + } + else { + return false; + } + } - /** + /** * @return the nearest allowable point according to the {@link VASSAL.build.module.map.boardPicker.board.MapGrid} on * the {@link Board} at this point * * @see Board#snapTo * @see VASSAL.build.module.map.boardPicker.board.MapGrid#snapTo */ - public Point snapTo(Point p) { - Point snap = new Point(p); - Board b = findBoard(p); - if (b == null) - return snap; - Rectangle r = b.bounds(); - snap.translate(-r.x, -r.y); - snap = b.snapTo(snap); - snap.translate(r.x, r.y); - // RFE 882378 - // If we have snapped to a point 1 pixel off the edge of the map, move - // back - // onto the map. - if (findBoard(snap) == null) { - snap.translate(-r.x, -r.y); - if (snap.x == r.width) { - snap.x = r.width - 1; - } - else if (snap.x == -1) { - snap.x = 0; - } - if (snap.y == r.height) { - snap.y = r.height - 1; - } - else if (snap.y == -1) { - snap.y = 0; - } - snap.translate(r.x, r.y); - } - return snap; - } + public Point snapTo(Point p) { + Point snap = new Point(p); + Board b = findBoard(p); + if (b == null) + return snap; + Rectangle r = b.bounds(); + snap.translate(-r.x, -r.y); + snap = b.snapTo(snap); + snap.translate(r.x, r.y); + // RFE 882378 + // If we have snapped to a point 1 pixel off the edge of the map, move + // back + // onto the map. + if (findBoard(snap) == null) { + snap.translate(-r.x, -r.y); + if (snap.x == r.width) { + snap.x = r.width - 1; + } + else if (snap.x == -1) { + snap.x = 0; + } + if (snap.y == r.height) { + snap.y = r.height - 1; + } + else if (snap.y == -1) { + snap.y = 0; + } + snap.translate(r.x, r.y); + } + return snap; + } - /** + /** * The buffer of empty space around the boards in the Map window, * in component coordinates at 100% zoom */ - public Dimension getEdgeBuffer() { - return new Dimension(edgeBuffer); - } + public Dimension getEdgeBuffer() { + return new Dimension(edgeBuffer); + } - /** + /** * Translate a point from component coordinates (i.e. x,y position on the JPanel) to map coordinates, i.e. accounting * for zoom factor * * @see #componentCoordinates */ - public Point mapCoordinates(Point p1) { - Point p = new Point(p1.x, p1.y); - p.x /= getZoom(); - p.y /= getZoom(); - return p; - } + public Point mapCoordinates(Point p1) { + Point p = new Point(p1.x, p1.y); + p.x /= getZoom(); // FIXME: is this ok w/o rounding? + p.y /= getZoom(); + return p; + } - public Rectangle mapRectangle(Rectangle r) { - r = new Rectangle(r); - r.x /= getZoom(); - r.y /= getZoom(); - r.width /= getZoom(); - r.height /= getZoom(); - return r; - } + public Rectangle mapRectangle(Rectangle r) { + r = new Rectangle(r); + r.x /= getZoom(); + r.y /= getZoom(); + r.width /= getZoom(); + r.height /= getZoom(); + return r; + } - /** + /** * Translate a point from map coordinates to component coordinates * * @see #mapCoordinates */ - public Point componentCoordinates(Point p1) { - Point p = new Point(p1.x, p1.y); - p.x *= getZoom(); - p.y *= getZoom(); - return p; - } + public Point componentCoordinates(Point p1) { + Point p = new Point(p1.x, p1.y); + p.x *= getZoom(); + p.y *= getZoom(); + return p; + } - public Rectangle componentRectangle(Rectangle r) { - r = new Rectangle(r); - r.x *= getZoom(); - r.y *= getZoom(); - r.width *= getZoom(); - r.height *= getZoom(); - return r; - } + public Rectangle componentRectangle(Rectangle r) { + r = new Rectangle(r); + r.x *= getZoom(); + r.y *= getZoom(); + r.width *= getZoom(); + r.height *= getZoom(); + return r; + } - /** + /** * @return a String name for the given location on the map * * @see Board#locationName */ - public String locationName(Point p) { - String loc = getDeckNameAt(p); - if (loc == null) { - Board b = findBoard(p); - if (b != null) { - loc = b.locationName(new Point(p.x - b.bounds().x, p.y - b.bounds().y)); - } - } - if (loc == null) { - loc = Resources.getString("Map.offboard"); //$NON-NLS-1$ - } - return loc; - } + public String locationName(Point p) { + String loc = getDeckNameAt(p); + if (loc == null) { + Board b = findBoard(p); + if (b != null) { + loc = b.locationName(new Point(p.x - b.bounds().x, p.y - b.bounds().y)); + } + } + if (loc == null) { + loc = Resources.getString("Map.offboard"); //$NON-NLS-1$ + } + return loc; + } public String localizedLocationName(Point p) { String loc = getLocalizedDeckNameAt(p); @@ -909,77 +926,77 @@ return loc; } - /** + /** * @return a String name for the given location on the map. Include Map name if requested. Report deck name instead of * location if point is inside the bounds of a deck. Do not include location if this map is not visible to all * players. */ -// public String getFullLocationName(Point p, boolean includeMap) { -// String loc = ""; //$NON-NLS-1$ -// if (includeMap && getMapName() != null && getMapName().length() > 0) { -// loc = "[" + getMapName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ -// } -// if (isVisibleToAll() && p != null) { -// String pos = getDeckNameContaining(p); -// if (pos == null) { -// if (locationName(p) != null) { -// loc = locationName(p) + loc; -// } -// } -// else { -// loc = pos; -// } -// } -// return loc; -// } +// public String getFullLocationName(Point p, boolean includeMap) { +// String loc = ""; //$NON-NLS-1$ +// if (includeMap && getMapName() != null && getMapName().length() > 0) { +// loc = "[" + getMapName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ +// } +// if (isVisibleToAll() && p != null) { +// String pos = getDeckNameContaining(p); +// if (pos == null) { +// if (locationName(p) != null) { +// loc = locationName(p) + loc; +// } +// } +// else { +// loc = pos; +// } +// } +// return loc; +// } - /** + /** * Is this map visible to all players */ - public boolean isVisibleToAll() { - if (this instanceof PrivateMap) { - if (!getAttributeValueString(PrivateMap.VISIBLE).equals("true")) { //$NON-NLS-1$ - return false; - } - } - return true; - } + public boolean isVisibleToAll() { + if (this instanceof PrivateMap) { + if (!getAttributeValueString(PrivateMap.VISIBLE).equals("true")) { //$NON-NLS-1$ + return false; + } + } + return true; + } - /** + /** * Return the name of the deck whose bounding box contains p */ - public String getDeckNameContaining(Point p) { - String deck = null; - if (p != null) { + public String getDeckNameContaining(Point p) { + String deck = null; + if (p != null) { for (DrawPile d : getComponentsOf(DrawPile.class)) { - Rectangle box = d.boundingBox(); - if (box != null && box.contains(p)) { - deck = d.getConfigureName(); - break; - } - } - } - return deck; - } + Rectangle box = d.boundingBox(); + if (box != null && box.contains(p)) { + deck = d.getConfigureName(); + break; + } + } + } + return deck; + } - /** + /** * Return the name of the deck whose position is p * * @param p * @return */ - public String getDeckNameAt(Point p) { - String deck = null; - if (p != null) { + public String getDeckNameAt(Point p) { + String deck = null; + if (p != null) { for (DrawPile d : getComponentsOf(DrawPile.class)) { - if (d.getPosition().equals(p)) { - deck = d.getConfigureName(); - break; - } - } - } - return deck; - } + if (d.getPosition().equals(p)) { + deck = d.getConfigureName(); + break; + } + } + } + return deck; + } public String getLocalizedDeckNameAt(Point p) { String deck = null; @@ -994,90 +1011,92 @@ return deck; } - /** + /** * Because MouseEvents are received in component coordinates, it is inconvenient for MouseListeners on the map to have * to translate to map coordinates. MouseListeners added with this method will receive mouse events with points * already translated into map coordinates. * addLocalMouseListenerFirst inserts the new listener at the start of the chain. */ - public void addLocalMouseListener(MouseListener l) { - multicaster = AWTEventMulticaster.add(multicaster, l); - } + public void addLocalMouseListener(MouseListener l) { + multicaster = AWTEventMulticaster.add(multicaster, l); + } public void addLocalMouseListenerFirst(MouseListener l) { multicaster = AWTEventMulticaster.add(l, multicaster); } - public void removeLocalMouseListener(MouseListener l) { - multicaster = AWTEventMulticaster.remove(multicaster, l); - } + public void removeLocalMouseListener(MouseListener l) { + multicaster = AWTEventMulticaster.remove(multicaster, l); + } - /** + /** * MouseListeners on a map may be pushed and popped onto a stack. * Only the top listener on the stack receives mouse events. */ - public void pushMouseListener(MouseListener l) { - mouseListenerStack.add(l); - } + public void pushMouseListener(MouseListener l) { + mouseListenerStack.add(l); + } - /** - * MouseListeners on a map may be pushed and popped onto a stack. Only the top listener on the stack receives mouse - * events + /** + * MouseListeners on a map may be pushed and popped onto a stack. + * Only the top listener on the stack receives mouse events. */ - public void popMouseListener() { - mouseListenerStack.remove(mouseListenerStack.size()-1); - } + public void popMouseListener() { + mouseListenerStack.remove(mouseListenerStack.size()-1); + } - public void mouseEntered(MouseEvent e) { - } + public void mouseEntered(MouseEvent e) { + } - public void mouseExited(MouseEvent e) { - } + public void mouseExited(MouseEvent e) { + } - /** - * Mouse events are first translated into map coordinates. Then the event is forwarded to the top MouseListener in the + /** + * Mouse events are first translated into map coordinates. + * Then the event is forwarded to the top MouseListener in the * stack, if any, otherwise forwarded to all LocalMouseListeners * * @see #pushMouseListener * @see #popMouseListener * @see #addLocalMouseListener */ - public void mouseClicked(MouseEvent e) { - if (!mouseListenerStack.isEmpty()) { - Point p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - mouseListenerStack.get(mouseListenerStack.size()-1).mouseClicked(e); - } - else if (multicaster != null) { - Point p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - multicaster.mouseClicked(e); - } - } + public void mouseClicked(MouseEvent e) { + if (!mouseListenerStack.isEmpty()) { + Point p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + mouseListenerStack.get(mouseListenerStack.size()-1).mouseClicked(e); + } + else if (multicaster != null) { + Point p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + multicaster.mouseClicked(e); + } + } - /** - * Mouse events are first translated into map coordinates. Then the event is forwarded to the top MouseListener in the + /** + * Mouse events are first translated into map coordinates. + * Then the event is forwarded to the top MouseListener in the * stack, if any, otherwise forwarded to all LocalMouseListeners * * @see #pushMouseListener * @see #popMouseListener * @see #addLocalMouseListener */ - - public static Map activeMap = null; public static void clearActiveMap() { if (activeMap != null) { - activeMap.repaint(); + activeMap.repaint(); // FIXME: repaint selection only + System.out.println("Map:1088"); activeMap = null; } } - public void mousePressed(MouseEvent e) { - + public static Map activeMap = null; + + public void mousePressed(MouseEvent e) { // Deselect any counters on the last Map with focus if (!this.equals(activeMap)) { boolean dirty = false; - ArrayList<GamePiece> l = + final ArrayList<GamePiece> l = Collections.list(KeyBuffer.getBuffer().getPieces()); for (GamePiece p : l) { if (p.getMap() == activeMap) { @@ -1086,25 +1105,28 @@ } } +/* if (dirty && activeMap != null) { - activeMap.repaint(); - } + activeMap.repaint(); // FIXME! + System.out.println("Map:1109"); + } +*/ } activeMap = this; - if (!mouseListenerStack.isEmpty()) { - Point p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - mouseListenerStack.get(mouseListenerStack.size()-1).mousePressed(e); - } - else if (multicaster != null) { - Point p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - multicaster.mousePressed(e); - } - } + if (!mouseListenerStack.isEmpty()) { + Point p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + mouseListenerStack.get(mouseListenerStack.size()-1).mousePressed(e); + } + else if (multicaster != null) { + Point p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + multicaster.mousePressed(e); + } + } - /** + /** * Mouse events are first translated into map coordinates. * Then the event is forwarded to the top MouseListener in the * stack, if any, otherwise forwarded to all LocalMouseListeners. @@ -1113,253 +1135,370 @@ * @see #popMouseListener * @see #addLocalMouseListener */ - public void mouseReleased(MouseEvent e) { - Point p = e.getPoint(); - p.translate(theMap.getLocation().x, theMap.getLocation().y); - if (theMap.getBounds().contains(p)) { - if (!mouseListenerStack.isEmpty()) { - p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - mouseListenerStack.get(mouseListenerStack.size()-1).mouseReleased(e); - } - else if (multicaster != null) { - p = mapCoordinates(e.getPoint()); - e.translatePoint(p.x - e.getX(), p.y - e.getY()); - multicaster.mouseReleased(e); - } - // Request Focus so that keyboard input will be recognized - theMap.requestFocus(); - } - // Clicking with mouse always repaints the map - clearFirst = true; - theMap.repaint(); + public void mouseReleased(MouseEvent e) { + Point p = e.getPoint(); + p.translate(theMap.getLocation().x, theMap.getLocation().y); + if (theMap.getBounds().contains(p)) { + if (!mouseListenerStack.isEmpty()) { + p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + mouseListenerStack.get(mouseListenerStack.size()-1).mouseReleased(e); + } + else if (multicaster != null) { + p = mapCoordinates(e.getPoint()); + e.translatePoint(p.x - e.getX(), p.y - e.getY()); + multicaster.mouseReleased(e); + } + // Request Focus so that keyboard input will be recognized + theMap.requestFocus(); + } + // Clicking with mouse always repaints the map +// clearFirst = true; +// theMap.repaint(); // FIXME: what is this intended to repaint? +// System.out.println("Map:1155"); activeMap = this; - } + } - /** + /** * This listener will be notified when a drag event is initiated, assuming that no MouseListeners are on the stack. * * @see #pushMouseListener * @param dragGestureListener */ - public void setDragGestureListener(DragGestureListener dragGestureListener) { - this.dragGestureListener = dragGestureListener; - } + public void setDragGestureListener(DragGestureListener dragGestureListener) { + this.dragGestureListener = dragGestureListener; + } - public DragGestureListener getDragGestureListener() { - return dragGestureListener; - } + public DragGestureListener getDragGestureListener() { + return dragGestureListener; + } - /* + /* * Restart scroll delay timer when re-entering map */ - public void dragEnter(DropTargetDragEvent dtde) { - restartDelay(); - } + public void dragEnter(DropTargetDragEvent dtde) { + restartDelay(); + } - public void dragOver(DropTargetDragEvent dtde) { - scrollAtEdge(dtde.getLocation(), 15); - } + public void dragOver(DropTargetDragEvent dtde) { + scrollAtEdge(dtde.getLocation(), 15); + } - public void dropActionChanged(DropTargetDragEvent dtde) { - } + public void dropActionChanged(DropTargetDragEvent dtde) { + } - /* + /* * Cancel final scroll and repaint map */ - public void dragExit(DropTargetEvent dte) { - scroll_dx = 0; - scroll_dy = 0; - repaint(); - } + public void dragExit(DropTargetEvent dte) { + scroll_dx = 0; + scroll_dy = 0; +// repaint(); // FIXME: appears to be unnecessary + System.out.println("Map:1193"); + } - public void drop(DropTargetDropEvent dtde) { - if (dtde.getDropTargetContext().getComponent() == theMap) { - MouseEvent evt = new MouseEvent(theMap, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, dtde.getLocation().x, dtde.getLocation().y, 1, false); - theMap.dispatchEvent(evt); - dtde.dropComplete(true); - } - } + public void drop(DropTargetDropEvent dtde) { + if (dtde.getDropTargetContext().getComponent() == theMap) { + MouseEvent evt = new MouseEvent(theMap, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), 0, dtde.getLocation().x, dtde.getLocation().y, 1, false); + theMap.dispatchEvent(evt); + dtde.dropComplete(true); + } + } - /** - * Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stack + /** + * Mouse motion events are not forwarded to LocalMouseListeners or to + * listeners on the stack */ - public void mouseMoved(MouseEvent e) { - } + public void mouseMoved(MouseEvent e) { + } - /** - * Mouse motion events are not forwarded to LocalMouseListeners or to listeners on the stack + /** + * Mouse motion events are not forwarded to LocalMouseListeners or to + * listeners on the stack * * The map scrolls when dragging the mouse near the edge */ - public void mouseDragged(MouseEvent e) { - if (!e.isMetaDown()) { - scrollAtEdge(e.getPoint(), 15); - } - else { - restartDelay(); - } - } - /* + public void mouseDragged(MouseEvent e) { + if (!e.isMetaDown()) { + scrollAtEdge(e.getPoint(), 15); + } + else { + restartDelay(); + } + } + /* * Delay before starting scroll at edge */ public static final int PREFERRED_EDGE_SCROLL_DELAY = 200; public static final String PREFERRED_EDGE_DELAY = "PreferredEdgeDelay"; //$NON-NLS-1$ - protected Thread scrollDelayThread; - protected long scrollExpirationTime; - protected int scroll_dist; - protected int scroll_dx; - protected int scroll_dy; + protected Thread scrollDelayThread; + protected long scrollExpirationTime; + protected int scroll_dist; + protected int scroll_dx; + protected int scroll_dy; - /** + /** * Scoll map so that the argument point is at least a certain distance from the visible edte * * @param evtPt */ - public void scrollAtEdge(Point evtPt, int dist) { - Point p = new Point(evtPt.x - scroll.getViewport().getViewPosition().x, evtPt.y - scroll.getViewport().getViewPosition().y); - int dx = 0, dy = 0; - if (p.x < dist && p.x >= 0) - dx = -1; - if (p.x >= scroll.getViewport().getWidth() - dist && p.x < scroll.getViewport().getWidth()) - dx = 1; - if (p.y < dist && p.y >= 0) - dy = -1; - if (p.y >= scroll.getViewport().getHeight() - dist && p.y < scroll.getViewport().getHeight()) - dy = 1; - scroll_dx = dx; - scroll_dy = dy; - scroll_dist = dist; - if (dx != 0 || dy != 0) { - if (scrollDelayThread == null || !scrollDelayThread.isAlive()) { - scrollDelayThread = new Thread(this); - scrollDelayThread.start(); - } - } - else { - restartDelay(); - } - } + public void scrollAtEdge(Point evtPt, int dist) { + Point p = new Point(evtPt.x - scroll.getViewport().getViewPosition().x, evtPt.y - scroll.getViewport().getViewPosition().y); + int dx = 0, dy = 0; + if (p.x < dist && p.x >= 0) + dx = -1; + if (p.x >= scroll.getViewport().getWidth() - dist && p.x < scroll.getViewport().getWidth()) + dx = 1; + if (p.y < dist && p.y >= 0) + dy = -1; + if (p.y >= scroll.getViewport().getHeight() - dist && p.y < scroll.getViewport().getHeight()) + dy = 1; + scroll_dx = dx; + scroll_dy = dy; + scroll_dist = dist; + if (dx != 0 || dy != 0) { + if (scrollDelayThread == null || !scrollDelayThread.isAlive()) { + scrollDelayThread = new Thread(this); + scrollDelayThread.start(); + } + } + else { + restartDelay(); + } + } - protected void restartDelay() { - scrollExpirationTime = System.currentTimeMillis() + + protected void restartDelay() { + scrollExpirationTime = System.currentTimeMillis() + ((Integer) GameModule.getGameModule().getPrefs().getValue(PREFERRED_EDGE_DELAY)).intValue(); - } + } - public void run() { - while (System.currentTimeMillis() < scrollExpirationTime) { - try { - Thread.sleep(Math.max(0, scrollExpirationTime - System.currentTimeMillis())); - } - catch (InterruptedException e) { - } - } - if (scroll_dx != 0 || scroll_dy != 0) { - scroll(2 * scroll_dist * scroll_dx, 2 * scroll_dist * scroll_dy); - } - } + public void run() { + while (System.currentTimeMillis() < scrollExpirationTime) { + try { + Thread.sleep(Math.max(0, scrollExpirationTime - System.currentTimeMillis())); + } + catch (InterruptedException e) { + } + } + if (scroll_dx != 0 || scroll_dy != 0) { + scroll(2 * scroll_dist * scroll_dx, 2 * scroll_dist * scroll_dy); + } + } - public void repaint(boolean cf) { - clearFirst = cf; - theMap.repaint(); - } - - /** - * Painting the map is done in three steps: 1) draw each of the {@link Board}s on the map. 2) draw all of the - * counters on the map. 3) draw all of the {@link Drawable} components on the map + /** + * Painting the map is done in three steps: + * 1) draw each of the {@link Board}s on the map. + * 2) draw all of the counters on the map. + * 3) draw all of the {@link Drawable} components on the map. * * @see #addDrawComponent * @see #setBoards * @see #addPiece + * @deprecated FIXME */ - public void paint(Graphics g) { - paint(g, 0, 0); - } + @Deprecated + public void paint(Graphics g) { + paint(g, 0, 0); + } - public void paintRegion(Graphics g, Rectangle visibleRect) { - clearMapBorder(g); // To avoid ghost pieces around the edge - drawBoardsInRegion(g, visibleRect); - drawDrawable(g, false); - drawPiecesInRegion(g, visibleRect); - drawDrawable(g, true); - } + /** + * Paint the map at the given offset, i.e. such that (xOffset, yOffset) + * is in the upper left corner. + * @deprecated + */ + @Deprecated + public void paint(Graphics g, int xOffset, int yOffset) { + drawBoards(g, xOffset, yOffset, getZoom(), theMap); + drawDrawable(g, false); + drawPieces(g, xOffset, yOffset); + drawDrawable(g, true); + } - public void drawBoardsInRegion(Graphics g, Rectangle visibleRect) { + /** @deprecated FIXME */ + @Deprecated + publi... [truncated message content] |