You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(103) |
Jun
(121) |
Jul
(16) |
Aug
(67) |
Sep
(126) |
Oct
(161) |
Nov
(164) |
Dec
(588) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(394) |
Feb
(181) |
Mar
(131) |
Apr
(180) |
May
(255) |
Jun
(11) |
Jul
(79) |
Aug
(70) |
Sep
(274) |
Oct
(138) |
Nov
(195) |
Dec
(8) |
2008 |
Jan
(3) |
Feb
(142) |
Mar
(162) |
Apr
(124) |
May
(148) |
Jun
(157) |
Jul
(425) |
Aug
(373) |
Sep
(264) |
Oct
(315) |
Nov
(225) |
Dec
(6) |
2009 |
Jan
(67) |
Feb
(78) |
Mar
(279) |
Apr
(294) |
May
(92) |
Jun
(65) |
Jul
(134) |
Aug
(41) |
Sep
(138) |
Oct
(125) |
Nov
(126) |
Dec
(122) |
2010 |
Jan
(15) |
Feb
(48) |
Mar
(9) |
Apr
(195) |
May
(373) |
Jun
(507) |
Jul
(42) |
Aug
(16) |
Sep
(38) |
Oct
(81) |
Nov
(64) |
Dec
(18) |
2011 |
Jan
(13) |
Feb
(12) |
Mar
(39) |
Apr
(1) |
May
(2) |
Jun
(27) |
Jul
(27) |
Aug
(31) |
Sep
(14) |
Oct
(102) |
Nov
(20) |
Dec
(37) |
2012 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
(18) |
Jul
(6) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
(47) |
Jun
(7) |
Jul
(107) |
Aug
|
Sep
|
Oct
(112) |
Nov
(31) |
Dec
(17) |
2014 |
Jan
(29) |
Feb
(111) |
Mar
(34) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(18) |
Dec
(10) |
From: <aki...@us...> - 2012-06-15 19:57:25
|
Revision: 9185 http://gridarta.svn.sourceforge.net/gridarta/?rev=9185&view=rev Author: akirschbaum Date: 2012-06-15 19:57:18 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Rename MapUserListenerManager to MapMouseListener. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListenerManager.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapMouseListener.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java Copied: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapMouseListener.java (from rev 9184, trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapMouseListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapMouseListener.java 2012-06-15 19:57:18 UTC (rev 9185) @@ -0,0 +1,194 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.mapuserlistener; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import net.sf.gridarta.gui.map.event.MouseOpEvent; +import net.sf.gridarta.gui.map.event.MouseOpListener; +import net.sf.gridarta.gui.map.mapview.MapView; +import net.sf.gridarta.gui.map.renderer.MapRenderer; +import net.sf.gridarta.gui.panel.tools.ToolPalette; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Tracks mouse actions and calls the appropriate {@link MouseOpListener + * MouseOpListeners}. + * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum + */ +public class MapMouseListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * The {@link ToolPalette} for mapping mouse events to {@link + * MouseOpListener actions}. + */ + @NotNull + private final ToolPalette<G, A, R> toolPalette; + + /** + * The {@link MapRenderer} being tracked for mouse actions. + */ + @NotNull + private final MapRenderer renderer; + + /** + * Temporary point. Stored in a field to avoid frequent reallocation. + */ + @NotNull + private final Point tmpPoint = new Point(); + + /** + * The parameters for the currently processed event. Stored in a field to + * avoid frequent reallocation. + */ + @NotNull + private final MouseOpEvent<G, A, R> mouseOpEvent; + + /** + * The {@link MouseListener} attached to {@link #renderer}. + */ + @NotNull + private final MouseListener mouseListener = new MouseListener() { + + @Override + public void mouseClicked(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.clicked(mouseOpEvent); + } + } + + @Override + public void mousePressed(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.pressed(mouseOpEvent); + } + } + + @Override + public void mouseReleased(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.released(mouseOpEvent); + } + } + + @Override + public void mouseEntered(@NotNull final MouseEvent e) { + // ignore + } + + @Override + public void mouseExited(@NotNull final MouseEvent e) { + // ignore + } + + }; + + /** + * The {@link MouseMotionListener} attached to {@link #renderer}. + */ + @NotNull + private final MouseMotionListener mouseMotionListener = new MouseMotionListener() { + + @Override + public void mouseDragged(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.dragged(mouseOpEvent); + } + } + + @Override + public void mouseMoved(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.moved(mouseOpEvent); + } + } + + }; + + /** + * Creates a new instance. + * @param renderer the map renderer to track for mouse actions + * @param toolPalette the tool palette for mapping mouse events to actions + * @param mapView the map view associated with the renderer + */ + public MapMouseListener(@NotNull final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { + this.toolPalette = toolPalette; + this.renderer = renderer; + renderer.addMouseListener(mouseListener); + renderer.addMouseMotionListener(mouseMotionListener); + mouseOpEvent = new MouseOpEvent<G, A, R>(mapView); + } + + /** + * Must be called when this object is freed. Unregisters all listeners. + */ + public void closeNotify() { + renderer.removeMouseListener(mouseListener); + renderer.removeMouseMotionListener(mouseMotionListener); + } + + /** + * Initializes {@link #mouseOpEvent} from a {@link MouseEvent}. + * @param event the mouse event + */ + private void initEvent(@NotNull final MouseEvent event) { + mouseOpEvent.setButton(event.getButton()); + mouseOpEvent.setId(event.getID()); + mouseOpEvent.setMapLocation(getMapLocation(event)); + mouseOpEvent.setModifiers(event.getModifiersEx()); + mouseOpEvent.setClickCount(event.getClickCount()); + event.consume(); + } + + /** + * Get the mouse operation for a MouseEvent. + * @param event the mouse event to get mouse operation for + * @return the mouse operation for <var>event</var> + */ + @Nullable + private MouseOpListener<G, A, R> getMouseOperation(@NotNull final MouseEvent event) { + initEvent(event); + return toolPalette.getTool(mouseOpEvent); + } + + /** + * Get the map location for a MouseEvent. + * @param event the mouse event to get map location for + * @return the map location for <var>event</var> or <code>null</code> if + * outside map + */ + @Nullable + private Point getMapLocation(@NotNull final MouseEvent event) { + return renderer.getSquareLocationAt(event.getPoint(), tmpPoint); + } + +} Property changes on: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapMouseListener.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:56:17 UTC (rev 9184) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:57:18 UTC (rev 9185) @@ -1,194 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2011 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gui.mapuserlistener; - -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import net.sf.gridarta.gui.map.event.MouseOpEvent; -import net.sf.gridarta.gui.map.event.MouseOpListener; -import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.renderer.MapRenderer; -import net.sf.gridarta.gui.panel.tools.ToolPalette; -import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.gameobject.GameObject; -import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Tracks mouse actions and calls the appropriate {@link MouseOpListener - * MouseOpListeners}. - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - * @author Andreas Kirschbaum - */ -public class MapUserListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - - /** - * The {@link ToolPalette} for mapping mouse events to {@link - * MouseOpListener actions}. - */ - @NotNull - private final ToolPalette<G, A, R> toolPalette; - - /** - * The {@link MapRenderer} being tracked for mouse actions. - */ - @NotNull - private final MapRenderer renderer; - - /** - * Temporary point. Stored in a field to avoid frequent reallocation. - */ - @NotNull - private final Point tmpPoint = new Point(); - - /** - * The parameters for the currently processed event. Stored in a field to - * avoid frequent reallocation. - */ - @NotNull - private final MouseOpEvent<G, A, R> mouseOpEvent; - - /** - * The {@link MouseListener} attached to {@link #renderer}. - */ - @NotNull - private final MouseListener mouseListener = new MouseListener() { - - @Override - public void mouseClicked(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.clicked(mouseOpEvent); - } - } - - @Override - public void mousePressed(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.pressed(mouseOpEvent); - } - } - - @Override - public void mouseReleased(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.released(mouseOpEvent); - } - } - - @Override - public void mouseEntered(@NotNull final MouseEvent e) { - // ignore - } - - @Override - public void mouseExited(@NotNull final MouseEvent e) { - // ignore - } - - }; - - /** - * The {@link MouseMotionListener} attached to {@link #renderer}. - */ - @NotNull - private final MouseMotionListener mouseMotionListener = new MouseMotionListener() { - - @Override - public void mouseDragged(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.dragged(mouseOpEvent); - } - } - - @Override - public void mouseMoved(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.moved(mouseOpEvent); - } - } - - }; - - /** - * Creates a new instance. - * @param renderer the map renderer to track for mouse actions - * @param toolPalette the tool palette for mapping mouse events to actions - * @param mapView the map view associated with the renderer - */ - public MapUserListener(@NotNull final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { - this.toolPalette = toolPalette; - this.renderer = renderer; - renderer.addMouseListener(mouseListener); - renderer.addMouseMotionListener(mouseMotionListener); - mouseOpEvent = new MouseOpEvent<G, A, R>(mapView); - } - - /** - * Must be called when this object is freed. Unregisters all listeners. - */ - public void closeNotify() { - renderer.removeMouseListener(mouseListener); - renderer.removeMouseMotionListener(mouseMotionListener); - } - - /** - * Initializes {@link #mouseOpEvent} from a {@link MouseEvent}. - * @param event the mouse event - */ - private void initEvent(@NotNull final MouseEvent event) { - mouseOpEvent.setButton(event.getButton()); - mouseOpEvent.setId(event.getID()); - mouseOpEvent.setMapLocation(getMapLocation(event)); - mouseOpEvent.setModifiers(event.getModifiersEx()); - mouseOpEvent.setClickCount(event.getClickCount()); - event.consume(); - } - - /** - * Get the mouse operation for a MouseEvent. - * @param event the mouse event to get mouse operation for - * @return the mouse operation for <var>event</var> - */ - @Nullable - private MouseOpListener<G, A, R> getMouseOperation(@NotNull final MouseEvent event) { - initEvent(event); - return toolPalette.getTool(mouseOpEvent); - } - - /** - * Get the map location for a MouseEvent. - * @param event the mouse event to get map location for - * @return the map location for <var>event</var> or <code>null</code> if - * outside map - */ - @Nullable - private Point getMapLocation(@NotNull final MouseEvent event) { - return renderer.getSquareLocationAt(event.getPoint(), tmpPoint); - } - -} Modified: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListenerManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListenerManager.java 2012-06-15 19:56:17 UTC (rev 9184) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListenerManager.java 2012-06-15 19:57:18 UTC (rev 9185) @@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable; /** - * Tracks map views and attaches/detaches {@link MapUserListener} instances. + * Tracks map views and attaches/detaches {@link MapMouseListener} instances. * @author Andreas Kirschbaum */ public class MapUserListenerManager<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { @@ -53,10 +53,10 @@ private final MapViewsManager<G, A, R> mapViewsManager; /** - * Maps {@link MapView} instance to attached {@link MapUserListener}. + * Maps {@link MapView} instance to attached {@link MapMouseListener}. */ @NotNull - private final Map<MapView<G, A, R>, MapUserListener<G, A, R>> mapUserListeners = new IdentityHashMap<MapView<G, A, R>, MapUserListener<G, A, R>>(); + private final Map<MapView<G, A, R>, MapMouseListener<G, A, R>> mapUserListeners = new IdentityHashMap<MapView<G, A, R>, MapMouseListener<G, A, R>>(); /** * The {@link MapManagerListener} for tracking {@link MapControl} @@ -94,15 +94,15 @@ @Override public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - final MapUserListener<G, A, R> mapUserListener = new MapUserListener<G, A, R>(mapView.getRenderer(), toolPalette, mapView); - mapUserListeners.put(mapView, mapUserListener); + final MapMouseListener<G, A, R> mapMouseListener = new MapMouseListener<G, A, R>(mapView.getRenderer(), toolPalette, mapView); + mapUserListeners.put(mapView, mapMouseListener); } @Override public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - final MapUserListener<G, A, R> mapUserListener = mapUserListeners.remove(mapView); - assert mapUserListener != null; - mapUserListener.closeNotify(); + final MapMouseListener<G, A, R> mapMouseListener = mapUserListeners.remove(mapView); + assert mapMouseListener != null; + mapMouseListener.closeNotify(); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-15 19:56:24
|
Revision: 9184 http://gridarta.svn.sourceforge.net/gridarta/?rev=9184&view=rev Author: akirschbaum Date: 2012-06-15 19:56:17 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Remove redundant assert statement. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java Modified: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:55:53 UTC (rev 9183) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:56:17 UTC (rev 9184) @@ -188,7 +188,6 @@ */ @Nullable private Point getMapLocation(@NotNull final MouseEvent event) { - assert renderer != null; return renderer.getSquareLocationAt(event.getPoint(), tmpPoint); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-15 19:56:00
|
Revision: 9183 http://gridarta.svn.sourceforge.net/gridarta/?rev=9183&view=rev Author: akirschbaum Date: 2012-06-15 19:55:53 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Add comments. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java Modified: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:48:54 UTC (rev 9182) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:55:53 UTC (rev 9183) @@ -35,22 +35,36 @@ import org.jetbrains.annotations.Nullable; /** + * Tracks mouse actions and calls the appropriate {@link MouseOpListener + * MouseOpListeners}. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum */ public class MapUserListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** - * ToolSelector of ArchPanel. + * The {@link ToolPalette} for mapping mouse events to {@link + * MouseOpListener actions}. */ @NotNull private final ToolPalette<G, A, R> toolPalette; + /** + * The {@link MapRenderer} being tracked for mouse actions. + */ @NotNull private final MapRenderer renderer; + /** + * Temporary point. Stored in a field to avoid frequent reallocation. + */ @NotNull private final Point tmpPoint = new Point(); + /** + * The parameters for the currently processed event. Stored in a field to + * avoid frequent reallocation. + */ @NotNull private final MouseOpEvent<G, A, R> mouseOpEvent; @@ -120,6 +134,12 @@ }; + /** + * Creates a new instance. + * @param renderer the map renderer to track for mouse actions + * @param toolPalette the tool palette for mapping mouse events to actions + * @param mapView the map view associated with the renderer + */ public MapUserListener(@NotNull final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { this.toolPalette = toolPalette; this.renderer = renderer; @@ -128,11 +148,18 @@ mouseOpEvent = new MouseOpEvent<G, A, R>(mapView); } + /** + * Must be called when this object is freed. Unregisters all listeners. + */ public void closeNotify() { renderer.removeMouseListener(mouseListener); renderer.removeMouseMotionListener(mouseMotionListener); } + /** + * Initializes {@link #mouseOpEvent} from a {@link MouseEvent}. + * @param event the mouse event + */ private void initEvent(@NotNull final MouseEvent event) { mouseOpEvent.setButton(event.getButton()); mouseOpEvent.setId(event.getID()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-15 19:49:01
|
Revision: 9182 http://gridarta.svn.sourceforge.net/gridarta/?rev=9182&view=rev Author: akirschbaum Date: 2012-06-15 19:48:54 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Do not export MouseListener and MouseMotionListener interfaces from MapUserListener. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java Modified: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:41:15 UTC (rev 9181) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:48:54 UTC (rev 9182) @@ -37,7 +37,7 @@ /** * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> */ -public class MapUserListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MouseListener, MouseMotionListener { +public class MapUserListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** * ToolSelector of ArchPanel. @@ -54,30 +54,85 @@ @NotNull private final MouseOpEvent<G, A, R> mouseOpEvent; + /** + * The {@link MouseListener} attached to {@link #renderer}. + */ + @NotNull + private final MouseListener mouseListener = new MouseListener() { + + @Override + public void mouseClicked(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.clicked(mouseOpEvent); + } + } + + @Override + public void mousePressed(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.pressed(mouseOpEvent); + } + } + + @Override + public void mouseReleased(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.released(mouseOpEvent); + } + } + + @Override + public void mouseEntered(@NotNull final MouseEvent e) { + // ignore + } + + @Override + public void mouseExited(@NotNull final MouseEvent e) { + // ignore + } + + }; + + /** + * The {@link MouseMotionListener} attached to {@link #renderer}. + */ + @NotNull + private final MouseMotionListener mouseMotionListener = new MouseMotionListener() { + + @Override + public void mouseDragged(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.dragged(mouseOpEvent); + } + } + + @Override + public void mouseMoved(@NotNull final MouseEvent e) { + final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); + if (mouseOpListener != null) { + mouseOpListener.moved(mouseOpEvent); + } + } + + }; + public MapUserListener(@NotNull final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { this.toolPalette = toolPalette; this.renderer = renderer; - renderer.addMouseListener(this); - renderer.addMouseMotionListener(this); + renderer.addMouseListener(mouseListener); + renderer.addMouseMotionListener(mouseMotionListener); mouseOpEvent = new MouseOpEvent<G, A, R>(mapView); } public void closeNotify() { - renderer.removeMouseListener(this); - renderer.removeMouseMotionListener(this); + renderer.removeMouseListener(mouseListener); + renderer.removeMouseMotionListener(mouseMotionListener); } - /** - * {@inheritDoc} - */ - @Override - public void mouseClicked(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.clicked(mouseOpEvent); - } - } - private void initEvent(@NotNull final MouseEvent event) { mouseOpEvent.setButton(event.getButton()); mouseOpEvent.setId(event.getID()); @@ -88,66 +143,6 @@ } /** - * {@inheritDoc} - */ - @Override - public void mouseEntered(@NotNull final MouseEvent e) { - // ignore - } - - /** - * {@inheritDoc} - */ - @Override - public void mouseExited(@NotNull final MouseEvent e) { - // ignore - } - - /** - * {@inheritDoc} - */ - @Override - public void mouseDragged(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.dragged(mouseOpEvent); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void mouseMoved(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.moved(mouseOpEvent); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void mousePressed(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.pressed(mouseOpEvent); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void mouseReleased(@NotNull final MouseEvent e) { - final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); - if (mouseOpListener != null) { - mouseOpListener.released(mouseOpEvent); - } - } - - /** * Get the mouse operation for a MouseEvent. * @param event the mouse event to get mouse operation for * @return the mouse operation for <var>event</var> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-15 19:41:22
|
Revision: 9181 http://gridarta.svn.sourceforge.net/gridarta/?rev=9181&view=rev Author: akirschbaum Date: 2012-06-15 19:41:15 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Add nullable annotations. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java Modified: trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:00:47 UTC (rev 9180) +++ trunk/src/app/net/sf/gridarta/gui/mapuserlistener/MapUserListener.java 2012-06-15 19:41:15 UTC (rev 9181) @@ -42,16 +42,19 @@ /** * ToolSelector of ArchPanel. */ + @NotNull private final ToolPalette<G, A, R> toolPalette; + @NotNull private final MapRenderer renderer; + @NotNull private final Point tmpPoint = new Point(); @NotNull private final MouseOpEvent<G, A, R> mouseOpEvent; - public MapUserListener(final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { + public MapUserListener(@NotNull final MapRenderer renderer, @NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapView<G, A, R> mapView) { this.toolPalette = toolPalette; this.renderer = renderer; renderer.addMouseListener(this); @@ -68,14 +71,14 @@ * {@inheritDoc} */ @Override - public void mouseClicked(final MouseEvent e) { + public void mouseClicked(@NotNull final MouseEvent e) { final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); if (mouseOpListener != null) { mouseOpListener.clicked(mouseOpEvent); } } - private void initEvent(final MouseEvent event) { + private void initEvent(@NotNull final MouseEvent event) { mouseOpEvent.setButton(event.getButton()); mouseOpEvent.setId(event.getID()); mouseOpEvent.setMapLocation(getMapLocation(event)); @@ -88,7 +91,7 @@ * {@inheritDoc} */ @Override - public void mouseEntered(final MouseEvent e) { + public void mouseEntered(@NotNull final MouseEvent e) { // ignore } @@ -96,7 +99,7 @@ * {@inheritDoc} */ @Override - public void mouseExited(final MouseEvent e) { + public void mouseExited(@NotNull final MouseEvent e) { // ignore } @@ -104,7 +107,7 @@ * {@inheritDoc} */ @Override - public void mouseDragged(final MouseEvent e) { + public void mouseDragged(@NotNull final MouseEvent e) { final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); if (mouseOpListener != null) { mouseOpListener.dragged(mouseOpEvent); @@ -115,7 +118,7 @@ * {@inheritDoc} */ @Override - public void mouseMoved(final MouseEvent e) { + public void mouseMoved(@NotNull final MouseEvent e) { final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); if (mouseOpListener != null) { mouseOpListener.moved(mouseOpEvent); @@ -126,7 +129,7 @@ * {@inheritDoc} */ @Override - public void mousePressed(final MouseEvent e) { + public void mousePressed(@NotNull final MouseEvent e) { final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); if (mouseOpListener != null) { mouseOpListener.pressed(mouseOpEvent); @@ -137,7 +140,7 @@ * {@inheritDoc} */ @Override - public void mouseReleased(final MouseEvent e) { + public void mouseReleased(@NotNull final MouseEvent e) { final MouseOpListener<G, A, R> mouseOpListener = getMouseOperation(e); if (mouseOpListener != null) { mouseOpListener.released(mouseOpEvent); @@ -150,7 +153,7 @@ * @return the mouse operation for <var>event</var> */ @Nullable - private MouseOpListener<G, A, R> getMouseOperation(final MouseEvent event) { + private MouseOpListener<G, A, R> getMouseOperation(@NotNull final MouseEvent event) { initEvent(event); return toolPalette.getTool(mouseOpEvent); } @@ -162,7 +165,7 @@ * outside map */ @Nullable - private Point getMapLocation(final MouseEvent event) { + private Point getMapLocation(@NotNull final MouseEvent event) { assert renderer != null; return renderer.getSquareLocationAt(event.getPoint(), tmpPoint); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-15 19:00:56
|
Revision: 9180 http://gridarta.svn.sourceforge.net/gridarta/?rev=9180&view=rev Author: akirschbaum Date: 2012-06-15 19:00:47 +0000 (Fri, 15 Jun 2012) Log Message: ----------- Implement Map|Show Light to toggle highlighting of lighted map squares. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettingsListener.java trunk/model/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java trunk/src/app/net/sf/gridarta/gui/map/viewaction/ViewActions.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/atrinik/ChangeLog 2012-06-15 19:00:47 UTC (rev 9180) @@ -1,3 +1,8 @@ +2012-06-15 Andreas Kirschbaum + + * Implement Map|Show Light to toggle highlighting of lighted map + squares. + 2012-06-14 Andreas Kirschbaum * Change colors of tiles with warnings and of lighted tiles. Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -33,7 +33,7 @@ resources.menu=collectArches collectSpells - reloadFaces - viewTreasurelists tools.menu=newScript editScript - controlServer controlClient - validateMap cleanCompletelyBlockedSquares - zoom gc analyze.menu= -view.menu=resetView - gridVisible doubleFaces - prevWindow nextWindow +view.menu=resetView - gridVisible lightVisible doubleFaces - prevWindow nextWindow plugins.menu=- editPlugins - savePlugins importPlugin window.menu=closeAllMaps help.menu=showHelp tipOfTheDay about update @@ -42,7 +42,7 @@ mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection -mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects +mapwindowMap.menu=gridVisible lightVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes ########## Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/crossfire/ChangeLog 2012-06-15 19:00:47 UTC (rev 9180) @@ -1,3 +1,8 @@ +2012-06-15 Andreas Kirschbaum + + * Implement Map|Show Light to toggle highlighting of lighted map + squares. + 2012-06-14 Andreas Kirschbaum * Change colors of tiles with warnings and of lighted tiles. Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -33,7 +33,7 @@ resources.menu=collectArches - reloadFaces - viewTreasurelists tools.menu=newScript editScript - controlServer controlClient - validateMap - zoom gc analyze.menu= -view.menu=resetView - gridVisible smoothing - prevWindow nextWindow +view.menu=resetView - gridVisible lightVisible smoothing - prevWindow nextWindow plugins.menu=- editPlugins - savePlugins importPlugin window.menu=closeAllMaps help.menu=showHelp tipOfTheDay about update @@ -42,7 +42,7 @@ mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection -mapwindowMap.menu=gridVisible smoothing - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects +mapwindowMap.menu=gridVisible lightVisible smoothing - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes ########## Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -130,6 +130,11 @@ } @Override + public void lightVisibleChanged(final boolean lightVisible) { + forceRepaint(); + } + + @Override public void smoothingChanged(final boolean smoothing) { forceRepaint(); } @@ -418,7 +423,7 @@ */ protected void paintSquareSelection(@NotNull final Graphics graphics, @NotNull final Point point) { final int gridFlags = mapGrid.getFlags(point.x, point.y); - final boolean light = mapModel.getMapSquare(point).isLight(); + final boolean light = mapViewSettings.isLightVisible() && mapModel.getMapSquare(point).isLight(); gridMapSquarePainter.paint(graphics, gridFlags, light, borderOffset.x + point.x * IGUIConstants.SQUARE_WIDTH, borderOffset.y + point.y * IGUIConstants.SQUARE_HEIGHT, this); } Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/daimonin/ChangeLog 2012-06-15 19:00:47 UTC (rev 9180) @@ -1,3 +1,8 @@ +2012-06-15 Andreas Kirschbaum + + * Implement Map|Show Light to toggle highlighting of lighted map + squares. + 2012-06-14 Andreas Kirschbaum * Change colors of tiles with warnings and of lighted tiles. Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -33,7 +33,7 @@ resources.menu=collectArches collectSpells - reloadFaces - viewTreasurelists tools.menu=newScript editScript - controlServer controlClient - validateMap cleanCompletelyBlockedSquares - zoom gc analyze.menu= -view.menu=resetView - gridVisible doubleFaces - prevWindow nextWindow +view.menu=resetView - gridVisible lightVisible doubleFaces - prevWindow nextWindow plugins.menu=- editPlugins - savePlugins importPlugin window.menu=closeAllMaps help.menu=showHelp tipOfTheDay about update @@ -42,7 +42,7 @@ mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection -mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects +mapwindowMap.menu=gridVisible lightVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes ########## Modified: trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -37,6 +37,11 @@ private boolean gridVisible = loadGridVisible(); /** + * The visibility of the light. + */ + private boolean lightVisible = loadLightVisible(); + + /** * Whether smoothing display is active. */ private boolean smoothing = loadSmoothing(); @@ -123,6 +128,28 @@ * {@inheritDoc} */ @Override + public boolean isLightVisible() { + return lightVisible; + } + + /** + * {@inheritDoc} + */ + @Override + public void setLightVisible(final boolean lightVisible) { + if (this.lightVisible == lightVisible) { + return; + } + + this.lightVisible = lightVisible; + saveLightVisible(lightVisible); + fireLightVisibleChanged(); + } + + /** + * {@inheritDoc} + */ + @Override public boolean isSmoothing() { return smoothing; } @@ -301,6 +328,15 @@ } /** + * Informs all registered listeners that the light visibility has changed. + */ + private void fireLightVisibleChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.lightVisibleChanged(lightVisible); + } + } + + /** * Informs all registered listeners that the smoothing setting has changed. */ private void fireSmoothingChanged() { @@ -359,6 +395,18 @@ protected abstract void saveGridVisible(final boolean gridVisible); /** + * Loads the default value for {@link #lightVisible}. + * @return the default value + */ + protected abstract boolean loadLightVisible(); + + /** + * Saves the {@link #lightVisible} value. + * @param lightVisible the light visible value + */ + protected abstract void saveLightVisible(final boolean lightVisible); + + /** * Loads the default value for {@link #smoothing}. * @return the default value */ Modified: trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -38,6 +38,12 @@ private static final String GRID_VISIBLE_KEY = "mapViewSettings.gridVisible"; /** + * Key for saving {@link #lightVisible} state in preferences. + */ + @NotNull + private static final String LIGHT_VISIBLE_KEY = "mapViewSettings.lightVisible"; + + /** * Key for saving {@link #smoothing} state in preferences. */ @NotNull @@ -87,6 +93,22 @@ * {@inheritDoc} */ @Override + protected boolean loadLightVisible() { + return preferences.getBoolean(LIGHT_VISIBLE_KEY, false); + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveLightVisible(final boolean lightVisible) { + preferences.putBoolean(LIGHT_VISIBLE_KEY, lightVisible); + } + + /** + * {@inheritDoc} + */ + @Override protected boolean loadSmoothing() { return preferences.getBoolean(SMOOTHING_KEY, false); } Modified: trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -56,6 +56,20 @@ void setGridVisible(boolean gridVisible); /** + * Get the visibility of the light. + * @return visibility of the light (<code>true</code> for visible, + * <code>false</code> for invisible) + */ + boolean isLightVisible(); + + /** + * Set the visibility of the light. + * @param lightVisible new visibility of the light (<code>true</code> for + * making the light visible, <code>false</code> for invisible) + */ + void setLightVisible(boolean lightVisible); + + /** * Returns the smoothing setting. * @return the smoothing setting */ Modified: trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettingsListener.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettingsListener.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/model/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettingsListener.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -37,6 +37,12 @@ void gridVisibleChanged(boolean gridVisible); /** + * This event handler is called when the .ight visibility has changed. + * @param lightVisible the new light visibility + */ + void lightVisibleChanged(boolean lightVisible); + + /** * This event handler is called when the smoothing setting has changed. * @param smoothing the new smoothing settings */ Modified: trunk/model/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/model/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -46,6 +46,22 @@ * {@inheritDoc} */ @Override + protected boolean loadLightVisible() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveLightVisible(final boolean lightVisible) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override protected boolean loadSmoothing() { return false; } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -84,6 +84,12 @@ private final ToggleAction aGridVisible = (ToggleAction) ACTION_BUILDER.createToggle(true, "gridVisible", this); /** + * Action for "light visible". + */ + @NotNull + private final ToggleAction aLightVisible = (ToggleAction) ACTION_BUILDER.createToggle(true, "lightVisible", this); + + /** * Action for "smoothing". */ @NotNull @@ -239,6 +245,11 @@ } @Override + public void lightVisibleChanged(final boolean lightVisible) { + updateActions(); + } + + @Override public void smoothingChanged(final boolean smoothing) { updateActions(); } @@ -433,6 +444,28 @@ } /** + * Action method for "light visible". + * @return <code>true</code> if the light is visible, or <code>false</code> + * if the light is invisible + */ + @ActionMethod + public boolean isLightVisible() { + return doLightVisible(false, false) && mapViewSettings.isLightVisible(); + } + + /** + * Sets whether the light of the current map should be visible. + * @param lightVisible new visibility of light in current map, + * <code>true</code> if the light should be visible, <code>false</code> if + * invisible + * @see #isLightVisible() + */ + @ActionMethod + public void setLightVisible(final boolean lightVisible) { + doLightVisible(true, lightVisible); + } + + /** * Action method for "smoothing". * @return <code>true</code> if smoothing is active, or <code>false</code> * if smoothing is disabled @@ -666,6 +699,8 @@ private void updateActions() { aGridVisible.setEnabled(doGridVisible(false, false)); aGridVisible.setSelected(isGridVisible()); + aLightVisible.setEnabled(doLightVisible(false, false)); + aLightVisible.setSelected(isLightVisible()); aSmoothing.setEnabled(doSmoothing(false, false)); aSmoothing.setSelected(isSmoothing()); aDoubleFaces.setEnabled(doDoubleFaces(false, false)); @@ -703,6 +738,22 @@ } /** + * Executes the "light visible" action. + * @param performAction whether the action should be performed + * @param lightVisible whether the light should be visible; ignored unless + * <code>performAction</code> is set + * @return whether the action was or can be performed + * @noinspection SameReturnValue + */ + private boolean doLightVisible(final boolean performAction, final boolean lightVisible) { + if (performAction) { + mapViewSettings.setLightVisible(lightVisible); + } + + return true; + } + + /** * Executes the "smoothing" action. * @param performAction whether the action should be performed * @param smoothing whether smoothing should be performed; ignored unless Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -81,6 +81,11 @@ } @Override + public void lightVisibleChanged(final boolean lightVisible) { + // ignore + } + + @Override public void smoothingChanged(final boolean smoothing) { // ignore } Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -164,6 +164,11 @@ } @Override + public void lightVisibleChanged(final boolean lightVisible) { + forceRepaint(); + } + + @Override public void smoothingChanged(final boolean smoothing) { // does not render smoothed faces } @@ -656,6 +661,7 @@ * @param g the graphics for painting */ private void paintMapSelection(@NotNull final Graphics g) { + final boolean lightVisible = mapViewSettings.isLightVisible(); final Point point = new Point(); for (int y = 0; y < mapSize.getHeight(); y++) { int xStart = origin.x - (y + 1) * isoMapSquareInfo.getXLen2(); @@ -665,7 +671,7 @@ if (g.hitClip(xStart, yStart, isoMapSquareInfo.getXLen(), isoMapSquareInfo.getYLen())) { final int gridFlags = mapGrid.getFlags(x, y); point.x = x; - final boolean light = mapModel.getMapSquare(point).isLight(); + final boolean light = lightVisible && mapModel.getMapSquare(point).isLight(); gridMapSquarePainter.paint(g, gridFlags, light, xStart, yStart, this); } else { /* DO NOTHING if outside clip region. Modified: trunk/src/app/net/sf/gridarta/gui/map/viewaction/ViewActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/viewaction/ViewActions.java 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/gui/map/viewaction/ViewActions.java 2012-06-15 19:00:47 UTC (rev 9180) @@ -106,6 +106,11 @@ } @Override + public void lightVisibleChanged(final boolean lightVisible) { + // ignore + } + + @Override public void smoothingChanged(final boolean smoothing) { // ignore } Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/messages.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -139,6 +139,11 @@ gridVisible.shortdescription=Draws a grid that shows the individual map squares. gridVisible.accel=ctrl pressed G +lightVisible.text=Show Light +lightVisible.mnemonic=L +lightVisible.shortdescription=Highlights map squares that are lighted. +lightVisible.accel=ctrl shift pressed L + smoothing.text=Show Smoothing smoothing.mnemonic=S smoothing.shortdescription=Hides square borders by smearing faces into adjacent squares. @@ -1167,6 +1172,7 @@ prefs.mapDirectory=Maps directory. prefs.MapSquareBottom=true=display Game Object Attribute Dialog at bottom, false=display at right side. prefs.mapViewSettings.gridVisible=Whether the map grid is visible. +prefs.mapViewSettings.lightVisible=Whether lighted map squares are highlighted. prefs.mapViewSettings.smoothing=Whether smoothing is active. prefs.mapViewSettings.doubleFaces=Whether double faces are shown. prefs.mapViewSettings.alphaType=The settings for alpha faces. Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -122,6 +122,10 @@ gridVisible.mnemonic=G gridVisible.shortdescription=Zeichnet ein Gitter, das die verschiedenen Kartenfelder voneinander abgrenzt. +lightVisible.text=Beleuchtung anzeigen +lightVisible.mnemonic=L +lightVisible.shortdescription=Hebt beleuchtete Kartenfelder hervor. + smoothing.text=Smoothing anzeigen smoothing.mnemonic=S smoothing.shortdescription=Verwischt die \u00dcberg\u00e4nge zwischen benachbarten Kartenfeldern. Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -126,6 +126,10 @@ gridVisible.mnemonic=G #gridVisible.shortdescription= +#lightVisible.text= +#lightVisible.mnemonic= +#lightVisible.shortdescription= + smoothing.text=Lissage smoothing.mnemonic=L smoothing.shortdescription=Active le lissage des images, permettant un rendu moins carr\u00e9. Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2012-06-14 20:47:53 UTC (rev 9179) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2012-06-15 19:00:47 UTC (rev 9180) @@ -120,6 +120,10 @@ gridVisible.mnemonic=R gridVisible.shortdescription=Rita ut rutn\u00e4t f\u00f6r att visa enstaka kartrutor +#lightVisible.text= +#lightVisible.mnemonic= +#lightVisible.shortdescription= + #smoothing.text= #smoothing.mnemonic= #smoothing.shortdescription= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-06-14 20:47:59
|
Revision: 9179 http://gridarta.svn.sourceforge.net/gridarta/?rev=9179&view=rev Author: akirschbaum Date: 2012-06-14 20:47:53 +0000 (Thu, 14 Jun 2012) Log Message: ----------- Change colors of tiles with warnings and of lighted tiles. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/resource/system/light.png trunk/atrinik/resource/system/warning.png trunk/crossfire/ChangeLog trunk/crossfire/resource/system/light.png trunk/crossfire/resource/system/warning.png trunk/daimonin/ChangeLog trunk/daimonin/resource/system/light.png trunk/daimonin/resource/system/warning.png Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) +++ trunk/atrinik/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) @@ -1,3 +1,7 @@ +2012-06-14 Andreas Kirschbaum + + * Change colors of tiles with warnings and of lighted tiles. + 2012-05-31 Andreas Kirschbaum * Implement #3527374 (Illumination coverage filter). For now this Modified: trunk/atrinik/resource/system/light.png =================================================================== (Binary files differ) Modified: trunk/atrinik/resource/system/warning.png =================================================================== (Binary files differ) Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) +++ trunk/crossfire/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) @@ -1,3 +1,7 @@ +2012-06-14 Andreas Kirschbaum + + * Change colors of tiles with warnings and of lighted tiles. + 2012-05-31 Andreas Kirschbaum * Implement #3527374 (Illumination coverage filter). For now this Modified: trunk/crossfire/resource/system/light.png =================================================================== (Binary files differ) Modified: trunk/crossfire/resource/system/warning.png =================================================================== (Binary files differ) Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) +++ trunk/daimonin/ChangeLog 2012-06-14 20:47:53 UTC (rev 9179) @@ -1,3 +1,7 @@ +2012-06-14 Andreas Kirschbaum + + * Change colors of tiles with warnings and of lighted tiles. + 2012-05-31 Andreas Kirschbaum * Implement #3527374 (Illumination coverage filter). For now this Modified: trunk/daimonin/resource/system/light.png =================================================================== (Binary files differ) Modified: trunk/daimonin/resource/system/warning.png =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-05-31 19:52:29
|
Revision: 9178 http://gridarta.svn.sourceforge.net/gridarta/?rev=9178&view=rev Author: akirschbaum Date: 2012-05-31 19:52:21 +0000 (Thu, 31 May 2012) Log Message: ----------- Implement #3527374 (Illumination coverage filter). Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/model/gameobject/GameObject.java trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/gameobject/GameObject.java trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/model/gameobject/GameObject.java trunk/model/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquare.java trunk/model/src/test/net/sf/gridarta/model/gameobject/TestGameObject.java trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java trunk/src/app/net/sf/gridarta/gui/map/renderer/GridMapSquarePainter.java trunk/utils/src/app/net/sf/gridarta/utils/SystemIcons.java Added Paths: ----------- trunk/atrinik/resource/system/light.png trunk/crossfire/resource/system/light.png trunk/daimonin/resource/system/light.png trunk/model/src/app/net/sf/gridarta/model/mapmodel/LightMapModelTracker.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/atrinik/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) @@ -1,3 +1,8 @@ +2012-05-31 Andreas Kirschbaum + + * Implement #3527374 (Illumination coverage filter). For now this + is not an option but always active. + 2012-04-29 Andreas Kirschbaum * Ensure that at least 3 map squares are visible around a moving Added: trunk/atrinik/resource/system/light.png =================================================================== (Binary files differ) Property changes on: trunk/atrinik/resource/system/light.png ___________________________________________________________________ Added: svn:mime-type + image/png Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/model/gameobject/GameObject.java =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/model/gameobject/GameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/model/gameobject/GameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -157,4 +157,12 @@ } } + /** + * {@inheritDoc} + */ + @Override + public int getLightRadius() { + return getAttributeInt(GLOW_RADIUS); + } + } Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/crossfire/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) @@ -1,3 +1,8 @@ +2012-05-31 Andreas Kirschbaum + + * Implement #3527374 (Illumination coverage filter). For now this + is not an option but always active. + 2012-04-29 Andreas Kirschbaum * Ensure that at least 3 map squares are visible around a moving Added: trunk/crossfire/resource/system/light.png =================================================================== (Binary files differ) Property changes on: trunk/crossfire/resource/system/light.png ___________________________________________________________________ Added: svn:mime-type + image/png Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/AbstractFlatMapRenderer.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -418,7 +418,8 @@ */ protected void paintSquareSelection(@NotNull final Graphics graphics, @NotNull final Point point) { final int gridFlags = mapGrid.getFlags(point.x, point.y); - gridMapSquarePainter.paint(graphics, gridFlags, borderOffset.x + point.x * IGUIConstants.SQUARE_WIDTH, borderOffset.y + point.y * IGUIConstants.SQUARE_HEIGHT, this); + final boolean light = mapModel.getMapSquare(point).isLight(); + gridMapSquarePainter.paint(graphics, gridFlags, light, borderOffset.x + point.x * IGUIConstants.SQUARE_WIDTH, borderOffset.y + point.y * IGUIConstants.SQUARE_HEIGHT, this); } /** Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/gameobject/GameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/gameobject/GameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -54,6 +54,12 @@ public static final String ELEVATION = "elevation"; /** + * The name of the "glow_radius" attribute. + */ + @NotNull + public static final String GLOW_RADIUS = "glow_radius"; + + /** * The name of the "invisible" attribute. */ @NotNull @@ -155,4 +161,12 @@ return getNormalImage(); } + /** + * {@inheritDoc} + */ + @Override + public int getLightRadius() { + return getAttributeInt(GLOW_RADIUS); + } + } Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/daimonin/ChangeLog 2012-05-31 19:52:21 UTC (rev 9178) @@ -1,3 +1,8 @@ +2012-05-31 Andreas Kirschbaum + + * Implement #3527374 (Illumination coverage filter). For now this + is not an option but always active. + 2012-04-29 Andreas Kirschbaum * Ensure that at least 3 map squares are visible around a moving Added: trunk/daimonin/resource/system/light.png =================================================================== (Binary files differ) Property changes on: trunk/daimonin/resource/system/light.png ___________________________________________________________________ Added: svn:mime-type + image/png Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/model/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/model/gameobject/GameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/model/gameobject/GameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -44,6 +44,13 @@ public class GameObject extends DefaultIsoGameObject<GameObject, MapArchObject, Archetype> { /** + * Maps values of {@link #GLOW_RADIUS} to effective glow radius in map + * squares. + */ + @NotNull + private static final int[] LIGHT_MASK_WIDTH = { 0, 1, 2, 2, 3, 3, 3, 4, 4, 4, }; + + /** * The serial version UID. */ private static final long serialVersionUID = 1L; @@ -151,4 +158,13 @@ } } + /** + * {@inheritDoc} + */ + @Override + public int getLightRadius() { + final int attributeInt = Math.abs(getAttributeInt(GLOW_RADIUS)); + return LIGHT_MASK_WIDTH[Math.min(attributeInt, LIGHT_MASK_WIDTH.length - 1)]; + } + } Modified: trunk/model/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/model/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -94,6 +94,12 @@ public static final String ROTATE = "rotate"; /** + * The name of the "glow_radius" attribute. + */ + @NotNull + public static final String GLOW_RADIUS = "glow_radius"; + + /** * The {@link FaceObjectProviders} for looking up faces. */ @NotNull Modified: trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -288,4 +288,11 @@ */ void markModified(); + /** + * Returns the effective light radius of this game object. + * @return the effective light radius or <code>0</code> if this object does + * not emit light + */ + int getLightRadius(); + } Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -195,6 +195,12 @@ private boolean modified; /** + * The {@link LightMapModelTracker} tracking this instance. + */ + @NotNull + private final LightMapModelTracker<G, A, R> lightMapModelTracker = new LightMapModelTracker<G, A, R>(this); + + /** * The {@link MapArchObjectListener} used to detect changes in {@link * #mapArchObject} and set the {@link #modified} flag accordingly. */ @@ -313,6 +319,8 @@ // no other thread may access this map model while resizing synchronized (syncLock) { + lightMapModelTracker.mapSizeChanging(newSize, mapSize); + // first delete all arches in the area that will get cut off // (this is especially important to remove all multi-part objects // reaching into that area) @@ -424,6 +432,7 @@ log.error("endSquareChange: square (" + mapSquare + ") was changed outside a transaction"); final Set<MapSquare<G, A, R>> mapSquares = new HashSet<MapSquare<G, A, R>>(1); mapSquares.add(mapSquare); + lightMapModelTracker.mapSquaresChanged(Collections.unmodifiableCollection(mapSquares)); fireMapSquaresChangedEvent(mapSquares); } else { synchronized (changedSquares) { @@ -530,6 +539,21 @@ * Deliver all pending events. */ private void fireEvents() { + // Call lightMapModelTracker first as it might change more game objects + transactionDepth++; // temporarily increase transaction depth because updating light information causes changes + try { + // Create copy to avoid ConcurrentModificationExceptions due to newly changed squares + final Collection<MapSquare<G, A, R>> mapSquares = new HashSet<MapSquare<G, A, R>>(changedSquares); + for (final G gameObject : changedGameObjects) { + final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); + if (mapSquare != null) { + mapSquares.add(mapSquare); + } + } + lightMapModelTracker.mapSquaresChanged(mapSquares); + } finally { + transactionDepth--; + } if (!changedGameObjects.isEmpty() || !transientChangedGameObjects.isEmpty()) { transientChangedGameObjects.removeAll(changedGameObjects); transactionDepth++; // temporarily increase transaction depth because updating edit types causes transient changes Added: trunk/model/src/app/net/sf/gridarta/model/mapmodel/LightMapModelTracker.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/LightMapModelTracker.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/LightMapModelTracker.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -0,0 +1,165 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.model.mapmodel; + +import java.awt.Point; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.utils.Size2D; +import org.jetbrains.annotations.NotNull; + +/** + * Tracks a {@link MapModel} for light emitting game objects. Whenever such a + * game object is added to, removed from, or modified while on the map, all + * affected map squares are updated. + * @author Andreas Kirschbaum + */ +public class LightMapModelTracker<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * The maximal supported light radius. The return values of {@link + * GameObject#getLightRadius()} is clipped to this value. + */ + private static final int MAX_LIGHT_RADIUS = 4; + + /** + * The tracked {@link MapModel}. + */ + @NotNull + private final MapModel<G, A, R> mapModel; + + /** + * A temporary point. Stored in a field to avoid reallocations. + */ + @NotNull + private final Point point = new Point(); + + /** + * A temporary point. Stored in a field to avoid reallocations. + */ + @NotNull + private final Point point2 = new Point(); + + /** + * Creates a new instance. + * @param mapModel the tracked map model + */ + public LightMapModelTracker(@NotNull final MapModel<G, A, R> mapModel) { + this.mapModel = mapModel; + } + + /** + * Called whenever the tracked map is about to change size. + * @param newSize the new map size + * @param oldSize the current map size + */ + public void mapSizeChanging(@NotNull final Size2D newSize, @NotNull final Size2D oldSize) { + final int newWidth = newSize.getWidth(); + final int oldWidth = oldSize.getWidth(); + final int newHeight = newSize.getHeight(); + final int oldHeight = oldSize.getHeight(); + for (point.x = newWidth; point.x < oldWidth; point.x++) { + for (point.y = 0; point.y < oldHeight; point.y++) { + final MapSquare<G, A, R> mapSquare = mapModel.getMapSquare(point); + setLightRadius(mapSquare, 0); + } + } + for (point.x = 0; point.x < newWidth; point.x++) { + for (point.y = newHeight; point.y < newHeight; point.y++) { + final MapSquare<G, A, R> mapSquare = mapModel.getMapSquare(point); + setLightRadius(mapSquare, 0); + } + } + } + + /** + * Called whenever some game objects have changed. + * @param mapSquares the map square that contain changed game objects + */ + public void mapSquaresChanged(@NotNull final Iterable<MapSquare<G, A, R>> mapSquares) { + for (final MapSquare<G, A, R> mapSquare : mapSquares) { + updateLightRadius(mapSquare); + } + } + + /** + * Recalculates information about light emitting game objects in a map + * square. + * @param mapSquare the map square + */ + private void updateLightRadius(@NotNull final MapSquare<G, A, R> mapSquare) { + int maxLightRadius = 0; + for (final G gameObject : mapSquare) { + final int lightRadius = gameObject.getLightRadius(); + if (maxLightRadius < lightRadius) { + maxLightRadius = lightRadius; + } + } + setLightRadius(mapSquare, Math.min(maxLightRadius, MAX_LIGHT_RADIUS)); + } + + /** + * Updates the light radius of a map square. The light radius is the maximal + * light radius of all light emitting game objects in the map square. + * @param mapSquare the map square to update + * @param lightRadius the new light radius to set + */ + private void setLightRadius(@NotNull final MapSquare<G, A, R> mapSquare, final int lightRadius) { + final int prevLightRadius = mapSquare.getLightRadius(); + if (lightRadius == prevLightRadius) { + return; + } + mapSquare.setLightRadius(lightRadius); + if (lightRadius < prevLightRadius) { + // light radius shrinked => remove light sources + for (int dx = -prevLightRadius; dx <= prevLightRadius; dx++) { + for (int dy = -prevLightRadius; dy <= prevLightRadius; dy++) { + if (dx < -lightRadius || dx > lightRadius || dy < -lightRadius || dy > lightRadius || lightRadius == 0) { + point2.x = mapSquare.getMapX() + dx; + point2.y = mapSquare.getMapY() + dy; + try { + final MapSquare<G, A, R> mapSquare2 = mapModel.getMapSquare(point2); + mapSquare2.removeLightSource(mapSquare); + } catch (final IndexOutOfBoundsException ignored) { + // skip points outside map bounds + } + } + } + } + } else { + // light increased shrinked => add light sources + for (int dx = -lightRadius; dx <= lightRadius; dx++) { + for (int dy = -lightRadius; dy <= lightRadius; dy++) { + if (dx < -prevLightRadius || dx > prevLightRadius || dy < -prevLightRadius || dy > prevLightRadius || prevLightRadius == 0) { + point2.x = mapSquare.getMapX() + dx; + point2.y = mapSquare.getMapY() + dy; + try { + mapModel.getMapSquare(point2).addLightSource(mapSquare); + } catch (final IndexOutOfBoundsException ignored) { + // skip points outside map bounds + } + } + } + } + } + } + +} Property changes on: trunk/model/src/app/net/sf/gridarta/model/mapmodel/LightMapModelTracker.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquare.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquare.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquare.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -20,6 +20,9 @@ package net.sf.gridarta.model.mapmodel; import java.awt.Point; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.GameObjectContainer; import net.sf.gridarta.model.gameobject.GameObject; @@ -61,6 +64,20 @@ private final int mapY; /** + * The maximum light radius of all objects within this map square. Set to + * <code>0</code> if no light emitting objects are present. + */ + private int lightRadius; + + /** + * The {@link MapSquare MapSquares} on the {@link #mapModel map} that + * contain light emitting game objects that affect this map square. Set to + * {@link Collections#emptyList()} when empty. + */ + @NotNull + private List<MapSquare<G, A, R>> lightSources = Collections.emptyList(); + + /** * Creates a new instance. * @param mapModel the map model this map square is part of * @param mapX the x coordinate of this map square within the model's grid @@ -316,4 +333,78 @@ return mapModel.getMapArchObject().getMapName() + ":" + mapX + "/" + mapY; } + /** + * Returns the maximum light radius of all light emitting objects within + * this map square. + * @return the light radius or <code>0</code></codE> if no light emitting + * objects are present + */ + public int getLightRadius() { + return lightRadius; + } + + /** + * Sets the maximum light radius of all light emitting objects within this + * map square. + * @param lightRadius the light radius or <code>0</code></codE> if no light + * emitting objects are present + */ + public void setLightRadius(final int lightRadius) { + if (this.lightRadius == lightRadius) { + return; + } + + notifyBeginChange(); + try { + this.lightRadius = lightRadius; + } finally { + notifyEndChange(); + } + } + + /** + * Adds a light emitting game object that affects this map square. + * @param mapSquare the map square that contains the game object + */ + public void addLightSource(@NotNull final MapSquare<G, A, R> mapSquare) { + if (lightSources.isEmpty()) { + lightSources = new ArrayList<MapSquare<G, A, R>>(); + } + + notifyBeginChange(); + try { + lightSources.add(mapSquare); + } finally { + notifyEndChange(); + } + } + + /** + * Removes a light emitting game object that affects this map square. + * @param mapSquare the map square that contains the game object + */ + public void removeLightSource(@NotNull final MapSquare<G, A, R> mapSquare) { + notifyBeginChange(); + try { + if (!lightSources.remove(mapSquare)) { + assert false; + } + if (lightSources.isEmpty()) { + lightSources = Collections.emptyList(); + } + } finally { + notifyEndChange(); + } + } + + /** + * Returns whether this map square is affected by any light emitting game + * objects. + * @return whether this map square is affected by any light emitting game + * objects + */ + public boolean isLight() { + return !lightSources.isEmpty(); + } + } Modified: trunk/model/src/test/net/sf/gridarta/model/gameobject/TestGameObject.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/gameobject/TestGameObject.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/model/src/test/net/sf/gridarta/model/gameobject/TestGameObject.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -72,6 +72,14 @@ * {@inheritDoc} */ @Override + public int getLightRadius() { + return 0; + } + + /** + * {@inheritDoc} + */ + @Override public void propagateElevation(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { // ignore } Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -656,13 +656,17 @@ * @param g the graphics for painting */ private void paintMapSelection(@NotNull final Graphics g) { + final Point point = new Point(); for (int y = 0; y < mapSize.getHeight(); y++) { int xStart = origin.x - (y + 1) * isoMapSquareInfo.getXLen2(); int yStart = origin.y + y * isoMapSquareInfo.getYLen2(); + point.y = y; for (int x = 0; x < mapSize.getWidth(); x++) { if (g.hitClip(xStart, yStart, isoMapSquareInfo.getXLen(), isoMapSquareInfo.getYLen())) { final int gridFlags = mapGrid.getFlags(x, y); - gridMapSquarePainter.paint(g, gridFlags, xStart, yStart, this); + point.x = x; + final boolean light = mapModel.getMapSquare(point).isLight(); + gridMapSquarePainter.paint(g, gridFlags, light, xStart, yStart, this); } else { /* DO NOTHING if outside clip region. * DO NOT use continue. xStart and yStart are recalculated at the end of the loop. Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/GridMapSquarePainter.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/GridMapSquarePainter.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/GridMapSquarePainter.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -74,6 +74,12 @@ private final Image warningSquareImg; /** + * The overlay {@link Image} for map squares that are affected by light + * emitting game objects. + */ + private final Image lightSquare; + + /** * Creates a new instance. * @param systemIcons the system icons for creating icons */ @@ -86,17 +92,20 @@ preSelImg = systemIcons.getMapPreSelectedIcon().getImage(); cursorImg = systemIcons.getMapCursorIcon().getImage(); warningSquareImg = systemIcons.getWarningSquareIcon().getImage(); + lightSquare = systemIcons.getLightSquareIcon().getImage(); } /** * Paints overlay images for one grid square. * @param graphics the graphics to paint into * @param gridFlags the grid flags to paint + * @param light whether this map square is affected by a light emitting game + * object * @param x the x-coordinate to paint at * @param y the y-coordinate to paint at * @param imageObserver the image observer to notify */ - public void paint(@NotNull final Graphics graphics, final int gridFlags, final int x, final int y, @NotNull final ImageObserver imageObserver) { + public void paint(@NotNull final Graphics graphics, final int gridFlags, final boolean light, final int x, final int y, @NotNull final ImageObserver imageObserver) { if ((gridFlags & MapGrid.GRID_FLAG_SELECTION) != 0) { graphics.drawImage(selImg, x, y, imageObserver); } @@ -121,6 +130,9 @@ if ((gridFlags & MapGrid.GRID_FLAG_ERROR) != 0) { graphics.drawImage(warningSquareImg, x, y, imageObserver); } + if (light) { + graphics.drawImage(lightSquare, x, y, imageObserver); + } } } Modified: trunk/utils/src/app/net/sf/gridarta/utils/SystemIcons.java =================================================================== --- trunk/utils/src/app/net/sf/gridarta/utils/SystemIcons.java 2012-05-31 19:33:36 UTC (rev 9177) +++ trunk/utils/src/app/net/sf/gridarta/utils/SystemIcons.java 2012-05-31 19:52:21 UTC (rev 9178) @@ -65,6 +65,12 @@ public static final String SQUARE_WARNING = SYSTEM_DIR + "warning.png"; + /** + * The name of the image for highlighting map squares that are affected by + * nearby light emitting game objects. + */ + public static final String SQUARE_LIGHT = SYSTEM_DIR + "light.png"; + public static final String SQUARE_NO_FACE = SYSTEM_DIR + "no_face.png"; public static final String SQUARE_NO_ARCH = SYSTEM_DIR + "no_arch.png"; @@ -137,6 +143,9 @@ private ImageIcon warningSquareIcon = null; @Nullable + private ImageIcon lightSquareIcon = null; + + @Nullable private ImageIcon noFaceSquareIcon = null; @Nullable @@ -234,8 +243,28 @@ return warningSquareIcon; } + /** + * Returns the {@link ImageIcon} for highlighting map squares that are + * affected by nearby light emitting game objects. + * @return the image icon + */ @NotNull @SuppressWarnings("NullableProblems") + public ImageIcon getLightSquareIcon() { + if (lightSquareIcon == null) { + final ImageFilter alphaFilter = AlphaImageFilterInstance.ALPHA_FILTER; + final ImageIcon sysIcon = guiUtils.getResourceIcon(SQUARE_LIGHT); + final Image image = sysIcon.getImage(); + final ImageProducer source = image.getSource(); + final ImageProducer producer = new FilteredImageSource(source, alphaFilter); + final Image image2 = Toolkit.getDefaultToolkit().createImage(producer); + lightSquareIcon = new ImageIcon(image2); + } + return lightSquareIcon; + } + + @NotNull + @SuppressWarnings("NullableProblems") public ImageIcon getNoFaceSquareIcon() { if (noFaceSquareIcon == null) { noFaceSquareIcon = guiUtils.getResourceIcon(SQUARE_NO_FACE); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-05-31 19:33:43
|
Revision: 9177 http://gridarta.svn.sourceforge.net/gridarta/?rev=9177&view=rev Author: akirschbaum Date: 2012-05-31 19:33:36 +0000 (Thu, 31 May 2012) Log Message: ----------- Whitespace change. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapgrid/MapGrid.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapgrid/MapGrid.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapgrid/MapGrid.java 2012-04-29 20:24:24 UTC (rev 9176) +++ trunk/model/src/app/net/sf/gridarta/model/mapgrid/MapGrid.java 2012-05-31 19:33:36 UTC (rev 9177) @@ -31,7 +31,7 @@ /** * 2D-Grid containing flags for selection, pre-selection, cursor, warnings and * errors. This class provides methods to modify these flags. Normally a map - * cursor is used to access them. Selection flags are not changed directly. + * cursor is used to access them. Selection flags are not changed directly. * First pre-selection flags have to be set with {@link #preSelect(Point, * Point)}, then {@link #selectArea(Point, Point, SelectionMode)} will change * the selection flags according to {@link SelectionMode}. This allows This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-04-29 20:24:31
|
Revision: 9176 http://gridarta.svn.sourceforge.net/gridarta/?rev=9176&view=rev Author: akirschbaum Date: 2012-04-29 20:24:24 +0000 (Sun, 29 Apr 2012) Log Message: ----------- Ensure that at least 3 map squares are visible around a moving map cursor. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/src/app/net/sf/gridarta/gui/map/renderer/MapRenderer.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-04-15 17:43:07 UTC (rev 9175) +++ trunk/atrinik/ChangeLog 2012-04-29 20:24:24 UTC (rev 9176) @@ -1,3 +1,8 @@ +2012-04-29 Andreas Kirschbaum + + * Ensure that at least 3 map squares are visible around a moving + map cursor. + 2012-01-08 Andreas Kirschbaum * Implement #3464771 (Browse option for plugins). Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-04-15 17:43:07 UTC (rev 9175) +++ trunk/crossfire/ChangeLog 2012-04-29 20:24:24 UTC (rev 9176) @@ -1,3 +1,8 @@ +2012-04-29 Andreas Kirschbaum + + * Ensure that at least 3 map squares are visible around a moving + map cursor. + 2012-01-08 Andreas Kirschbaum * Implement #3464771 (Browse option for plugins). Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-04-15 17:43:07 UTC (rev 9175) +++ trunk/daimonin/ChangeLog 2012-04-29 20:24:24 UTC (rev 9176) @@ -1,3 +1,8 @@ +2012-04-29 Andreas Kirschbaum + + * Ensure that at least 3 map squares are visible around a moving + map cursor. + 2012-01-08 Andreas Kirschbaum * Implement #3464771 (Browse option for plugins). Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/MapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/MapRenderer.java 2012-04-15 17:43:07 UTC (rev 9175) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/MapRenderer.java 2012-04-29 20:24:24 UTC (rev 9176) @@ -89,4 +89,10 @@ @NotNull Rectangle getSquareBounds(@NotNull Point p); + /** + * Ensures that a rectangular area is visible. + * @param aRect the area + */ + void scrollRectToVisible(@NotNull Rectangle aRect); + } Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2012-04-15 17:43:07 UTC (rev 9175) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2012-04-29 20:24:24 UTC (rev 9176) @@ -28,6 +28,7 @@ import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; +import net.sf.gridarta.gui.map.renderer.MapRenderer; import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; @@ -52,6 +53,12 @@ public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** + * The visible border around the cursor. Whenever the cursor moves, the map + * view is scrolled to make this area visible. + */ + private static final int BORDER = 3; + + /** * The object chooser. */ @NotNull @@ -442,8 +449,30 @@ * @return whether the action was or can be performed */ private boolean doMoveCursor(final boolean performAction, @NotNull final Direction direction) { - final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); - return mapCursor != null && mapCursor.goTo(performAction, direction); + final MapView<G, A, R> mapView = currentMapView; + if (mapView == null) { + return false; + } + + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(mapView); + if (mapCursor == null) { + return false; + } + + if (!mapCursor.goTo(performAction, direction)) { + return false; + } + + if (performAction) { + final MapRenderer renderer = mapView.getRenderer(); + final Point location = mapCursor.getLocation(); + if (location != null) { + location.translate(BORDER * direction.getDx(), BORDER * direction.getDy()); + renderer.scrollRectToVisible(renderer.getSquareBounds(location)); + } + } + + return true; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2012-04-15 17:43:13
|
Revision: 9175 http://gridarta.svn.sourceforge.net/gridarta/?rev=9175&view=rev Author: ryo_saeba Date: 2012-04-15 17:43:07 +0000 (Sun, 15 Apr 2012) Log Message: ----------- Update event types. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2012-03-11 10:45:25 UTC (rev 9174) +++ trunk/crossfire/resource/resource/conf/types.xml 2012-04-15 17:43:07 UTC (rev 9175) @@ -232,7 +232,7 @@ <list name="event"> <listentry value="1" name="apply"/> - <listentry value="2" name="attack"/> + <listentry value="2" name="attacked"/> <listentry value="3" name="death"/> <listentry value="4" name="drop"/> <listentry value="5" name="pickup"/> @@ -245,6 +245,7 @@ <listentry value="12" name="timer"/> <listentry value="13" name="destroy"/> <listentry value="31" name="user"/> + <listentry value="33" name="attacks"/> </list> <list name="mood"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2012-03-11 10:45:31
|
Revision: 9174 http://gridarta.svn.sourceforge.net/gridarta/?rev=9174&view=rev Author: ryo_saeba Date: 2012-03-11 10:45:25 +0000 (Sun, 11 Mar 2012) Log Message: ----------- Add attribute. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2012-02-11 16:43:20 UTC (rev 9173) +++ trunk/crossfire/resource/resource/conf/types.xml 2012-03-11 10:45:25 UTC (rev 9174) @@ -1934,6 +1934,9 @@ <attribute arch="name" editor="script options" type="string"> If set, this field contains options passed to the script. </attribute> + <attribute arch="unique" editor="only once" type="bool"> + If set, then the event happens only once. + </attribute> </type> <!--####################################################################--> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2012-02-11 16:43:26
|
Revision: 9173 http://gridarta.svn.sourceforge.net/gridarta/?rev=9173&view=rev Author: ryo_saeba Date: 2012-02-11 16:43:20 +0000 (Sat, 11 Feb 2012) Log Message: ----------- Add new property. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2012-01-28 13:29:59 UTC (rev 9172) +++ trunk/crossfire/resource/resource/conf/types.xml 2012-02-11 16:43:20 UTC (rev 9173) @@ -4949,6 +4949,10 @@ If set, will apply a compound animation to the player or monster casting this spell. </attribute> + <attribute arch="immunity_chance" editor="immunity chance" type="int" min="0" max="100"> + For mood change spells like "charm monster", the probability that a + monster resisting the attack gets immune to it. + </attribute> </type> <!--####################################################################--> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2012-01-28 13:30:05
|
Revision: 9172 http://gridarta.svn.sourceforge.net/gridarta/?rev=9172&view=rev Author: ryo_saeba Date: 2012-01-28 13:29:59 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Add some Crossfire properties. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2012-01-18 21:34:53 UTC (rev 9171) +++ trunk/crossfire/resource/resource/conf/types.xml 2012-01-28 13:29:59 UTC (rev 9172) @@ -445,6 +445,24 @@ The image-name defines what image is displayed for this object in-game. </attribute> + <attribute arch="identified_name" editor="identified_name" type="string"> + If defined, then the object will take this name when identified. + </attribute> + <attribute arch="identified_name_pl" editor="identified_name_pl" type="string"> + If defined, then the object will take this plural name when identified. + </attribute> + <attribute arch="identified_face" editor="identified image" type="facename"> + If defined, then the object will take this appareance when identified. + </attribute> + <attribute arch="identified_anim_random" editor="identified random animation?" type="bool"> + If defined, then the object's animation is in a random sequence when identified. + </attribute> + <attribute arch="identified_anim_speed" editor="identified animation speed" type="float"> + If defined, then the object will have this animation speed when identified. + </attribute> + <attribute arch="identified_animation" editor="identified animation" type="animname"> + If defined, then the object will take this animation when identified. + </attribute> <attribute arch="nrof" editor="number" type="int"> This value determines the number of objects in one stack (for example: 100 gold coins => "number = 100"). You should set this This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2012-01-18 21:35:00
|
Revision: 9171 http://gridarta.svn.sourceforge.net/gridarta/?rev=9171&view=rev Author: ryo_saeba Date: 2012-01-18 21:34:53 +0000 (Wed, 18 Jan 2012) Log Message: ----------- Add the 'artifact' (should be a list, but no support for now). Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2012-01-08 19:24:27 UTC (rev 9170) +++ trunk/crossfire/resource/resource/conf/types.xml 2012-01-18 21:34:53 UTC (rev 9171) @@ -426,6 +426,9 @@ are not inherited. --> <default_type> + <attribute arch="artifact" editor="artifact" type="string"> + If defined, refers to an artifact to get values from. + </attribute> <attribute arch="name" editor="name" type="string"> This is the name of the object, displayed to the player. </attribute> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 19:24:34
|
Revision: 9170 http://gridarta.svn.sourceforge.net/gridarta/?rev=9170&view=rev Author: akirschbaum Date: 2012-01-08 19:24:27 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Implement #3464771 (Browse option for plugins). Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/model/src/app/net/sf/gridarta/model/io/PathManager.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginView.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java trunk/src/app/net/sf/gridarta/gui/dialog/prefs/AppPreferences.java trunk/src/app/net/sf/gridarta/gui/dialog/prefs/ResPreferences.java trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java Added Paths: ----------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapPathParameter.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/atrinik/ChangeLog 2012-01-08 19:24:27 UTC (rev 9170) @@ -1,5 +1,7 @@ 2012-01-08 Andreas Kirschbaum + * Implement #3464771 (Browse option for plugins). + * Do not drop plugin script parameter with unknown type. Create String parameters instead. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/crossfire/ChangeLog 2012-01-08 19:24:27 UTC (rev 9170) @@ -1,5 +1,7 @@ 2012-01-08 Andreas Kirschbaum + * Implement #3464771 (Browse option for plugins). + * Do not drop plugin script parameter with unknown type. Create String parameters instead. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/daimonin/ChangeLog 2012-01-08 19:24:27 UTC (rev 9170) @@ -1,5 +1,7 @@ 2012-01-08 Andreas Kirschbaum + * Implement #3464771 (Browse option for plugins). + * Do not drop plugin script parameter with unknown type. Create String parameters instead. Modified: trunk/model/src/app/net/sf/gridarta/model/io/PathManager.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/io/PathManager.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/model/src/app/net/sf/gridarta/model/io/PathManager.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -85,7 +85,20 @@ */ @NotNull public String getMapPath(@NotNull final String path) { - final String mapDirName = globalSettings.getMapsDirectory().getPath(); + return getMapPath(path, globalSettings.getMapsDirectory()); + } + + /** + * Create map path. Replaces all occurrences of '\' with '/' and removes the + * path to the map directory (absolute, relative or canonical) from the + * path. + * @param mapDir the map dir + * @param path to create map path from + * @return fixed path + */ + @NotNull + public static String getMapPath(@NotNull final String path, @NotNull final File mapDir) { + @NotNull final String mapDirName = mapDir.getPath(); String mapPath = path.replace('\\', '/'); if (mapPath.startsWith(mapDirName)) { mapPath = mapPath.substring(mapDirName.length()); Added: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java (rev 0) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -0,0 +1,77 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.plugin.parameter; + +import java.io.File; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; + +/** + * Base class for {@link PluginParameter PluginParameters} that hold a {@link + * File} value. + * @author Andreas Kirschbaum + */ +public abstract class AbstractPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, String> { + + /** + * The base directory. + */ + @NotNull + private final File baseDir; + + /** + * Creates a new instance. + * @param baseDir the base directory + */ + protected AbstractPathParameter(@NotNull final File baseDir) { + this.baseDir = baseDir; + setValue(""); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean setStringValue(@NotNull final String value) { + setValue(value); + return true; + } + + /** + * Returns the base directory. + * @return the base directory + */ + @NotNull + public File getBaseDir() { + return baseDir; + } + + /** + * Sets the current {@link File}. + * @param file the file + */ + public void setFile(@NotNull final File file) { + setValue(PathManager.getMapPath(file.getAbsolutePath(), baseDir)); + } + +} // class AbstractPathParameter Property changes on: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPathParameter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapPathParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapPathParameter.java (rev 0) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapPathParameter.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -0,0 +1,66 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.plugin.parameter; + +import java.io.File; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link PluginParameter} that represents a map. + * @author Andreas Kirschbaum + */ +public class MapPathParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPathParameter<G, A, R> { + + /** + * The string representation of this parameter type. + */ + @NotNull + public static final String PARAMETER_TYPE = "MapPathParameter"; + + /** + * Creates a new instance. + * @param baseDir the base directory + */ + public MapPathParameter(@NotNull final File baseDir) { + super(baseDir); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public String getParameterType() { + return PARAMETER_TYPE; + } + +} Property changes on: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapPathParameter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -148,6 +148,17 @@ @NotNull @Override + public Element visit(@NotNull final MapPathParameter<G, A, R> parameter) { + final Element e = toXML(parameter); + final Element s = new Element("value"); + final String value = parameter.getValue(); + s.addContent(value != null ? value : ""); + e.addContent(s); + return e; + } + + @NotNull + @Override public Element visit(@NotNull final StringParameter<G, A, R> parameter) { final Element e = toXML(parameter); final Element s = new Element("value"); @@ -261,6 +272,16 @@ @NotNull @Override + public PluginParameter<G, A, R> visit(@NotNull final MapPathParameter<G, A, R> parameter) { + fromXML(parameter); + assert e != null; + final String val = e.getChildTextTrim("value"); + parameter.setValue(val); + return parameter; + } + + @NotNull + @Override public PluginParameter<G, A, R> visit(@NotNull final StringParameter<G, A, R> parameter) { fromXML(parameter); assert e != null; Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -25,6 +25,7 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapmanager.MapManager; +import net.sf.gridarta.model.settings.GlobalSettings; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -43,6 +44,9 @@ @NotNull private final NamedFilter defaultFilterList; + @NotNull + private final GlobalSettings globalSettings; + /** * The {@link PluginParameterCodec} for converting {@link PluginParameter * PluginParameters} to or from XML representation. @@ -50,10 +54,11 @@ @NotNull private final PluginParameterCodec<G, A, R> codec = new PluginParameterCodec<G, A, R>(); - public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final NamedFilter defaultFilterList) { + public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final NamedFilter defaultFilterList, @NotNull final GlobalSettings globalSettings) { this.archetypeSet = archetypeSet; this.mapManager = mapManager; this.defaultFilterList = defaultFilterList; + this.globalSettings = globalSettings; } @NotNull @@ -93,6 +98,9 @@ if (type.equals(MapParameter.PARAMETER_TYPE)) { return new MapParameter<G, A, R>(mapManager); } + if (type.equals(MapPathParameter.PARAMETER_TYPE)) { + return new MapPathParameter<G, A, R>(globalSettings.getMapsDirectory()); + } if (type.equals(FilterParameter.PARAMETER_TYPE)) { return new FilterParameter<G, A, R>(defaultFilterList); } @@ -108,7 +116,7 @@ @NotNull public String[] getTypes() { - return new String[] { StringParameter.PARAMETER_TYPE, IntegerParameter.PARAMETER_TYPE, DoubleParameter.PARAMETER_TYPE, BooleanParameter.PARAMETER_TYPE, ArchParameter.PARAMETER_TYPE, MapParameter.PARAMETER_TYPE, FilterParameter.PARAMETER_TYPE, }; + return new String[] { StringParameter.PARAMETER_TYPE, IntegerParameter.PARAMETER_TYPE, DoubleParameter.PARAMETER_TYPE, BooleanParameter.PARAMETER_TYPE, ArchParameter.PARAMETER_TYPE, MapParameter.PARAMETER_TYPE, FilterParameter.PARAMETER_TYPE, MapPathParameter.PARAMETER_TYPE, }; } } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -49,6 +49,9 @@ T visit(@NotNull MapParameter<G, A, R> parameter); @NotNull + T visit(@NotNull MapPathParameter<G, A, R> parameter); + + @NotNull T visit(@NotNull StringParameter<G, A, R> parameter); } Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginEditor.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -421,7 +421,7 @@ return existingPluginParameterView; } - final PluginParameterView<G, A, R> newPluginParameterView = pluginParameterViewFactory.getView(param); + final PluginParameterView<G, A, R> newPluginParameterView = pluginParameterViewFactory.getView(paramTable, param); newTableComponent(newPluginParameterView.getConfigComponent()); newTableComponent(newPluginParameterView.getValueComponent()); Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/PluginView.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -21,7 +21,6 @@ import java.awt.BorderLayout; import java.awt.Component; -import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -218,7 +217,7 @@ p.setMessageType(JOptionPane.QUESTION_MESSAGE); p.setMessage("Please provide runtime parameters for " + plugin.getName()); final GridBagLayout layout = new GridBagLayout(); - final Container panel = new JPanel(layout); + final JComponent panel = new JPanel(layout); final JDialog dialog = p.createDialog(parent, plugin.getName()); dialog.setModal(true); dialog.getContentPane().removeAll(); @@ -226,7 +225,7 @@ for (final PluginParameter<G, A, R> parameter : plugin) { log.debug("adding parameter"); final Component name = new JLabel(parameter.getName()); - final PluginParameterView<G, A, R> view = pluginParameterViewFactory.getView(parameter); + final PluginParameterView<G, A, R> view = pluginParameterViewFactory.getView(panel, parameter); final JComponent val = view.getValueComponent(); val.setToolTipText(parameter.getDescription()); final GridBagConstraints gn = new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 5, 5); Added: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -0,0 +1,96 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.dialog.plugin.parameter; + +import java.io.File; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JPanel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import net.sf.gridarta.gui.utils.JFileField; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.plugin.parameter.MapPathParameter; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link PluginParameterView} that displays a {@link MapPathParameter}. + * @author Andreas Kirschbaum + */ +public class MapPathParameterView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements PluginParameterView<G, A, R> { + + @NotNull + private final JComponent config = new JPanel(); + + /** + * The button that displays the map path. + */ + @NotNull + private final JFileField valueComponent; + + /** + * Creates a new instance. + * @param parent the parent component for the file chooser + * @param parameter the parameter to affect + */ + public MapPathParameterView(@NotNull final JComponent parent, @NotNull final MapPathParameter<G, A, R> parameter) { + final String value = parameter.getValue(); + valueComponent = new JFileField(parent, null, parameter.getBaseDir(), new File(value == null ? "" : value), JFileChooser.FILES_AND_DIRECTORIES); + valueComponent.addDocumentListener(new DocumentListener() { + + @Override + public void insertUpdate(final DocumentEvent e) { + parameter.setFile(valueComponent.getFile()); + } + + @Override + public void removeUpdate(final DocumentEvent e) { + parameter.setFile(valueComponent.getFile()); + } + + @Override + public void changedUpdate(final DocumentEvent e) { + parameter.setFile(valueComponent.getFile()); + } + + }); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public JComponent getValueComponent() { + return valueComponent; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public JComponent getConfigComponent() { + return config; + } + +} // class MapPathParameterView Property changes on: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/MapPathParameterView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -19,6 +19,7 @@ package net.sf.gridarta.gui.dialog.plugin.parameter; +import javax.swing.JComponent; import net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel; import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; @@ -33,10 +34,12 @@ import net.sf.gridarta.plugin.parameter.FilterParameter; import net.sf.gridarta.plugin.parameter.IntegerParameter; import net.sf.gridarta.plugin.parameter.MapParameter; +import net.sf.gridarta.plugin.parameter.MapPathParameter; import net.sf.gridarta.plugin.parameter.PluginParameter; import net.sf.gridarta.plugin.parameter.PluginParameterVisitor; import net.sf.gridarta.plugin.parameter.StringParameter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Factory for creating {@link PluginParameterView} instances. @@ -62,6 +65,12 @@ @NotNull private final FaceObjectProviders faceObjectProviders; + /** + * The parent component for showing dialogs. + */ + @Nullable + private JComponent parent; + @NotNull private final PluginParameterVisitor<G, A, R, PluginParameterView<G, A, R>> visitor = new PluginParameterVisitor<G, A, R, PluginParameterView<G, A, R>>() { @@ -103,6 +112,13 @@ @NotNull @Override + public PluginParameterView<G, A, R> visit(@NotNull final MapPathParameter<G, A, R> parameter) { + assert parent != null; + return new MapPathParameterView<G, A, R>(parent, parameter); + } + + @NotNull + @Override public PluginParameterView<G, A, R> visit(@NotNull final StringParameter<G, A, R> parameter) { return new StringParameterView<G, A, R>(parameter); } @@ -122,9 +138,17 @@ this.faceObjectProviders = faceObjectProviders; } + /** + * @param parent the parent component for showing dialogs + */ @NotNull - public PluginParameterView<G, A, R> getView(@NotNull final PluginParameter<G, A, R> parameter) { - return parameter.visit(visitor); + public PluginParameterView<G, A, R> getView(@NotNull final JComponent parent, @NotNull final PluginParameter<G, A, R> parameter) { + this.parent = parent; + try { + return parameter.visit(visitor); + } finally { + this.parent = null; + } } } Modified: trunk/src/app/net/sf/gridarta/gui/dialog/prefs/AppPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/prefs/AppPreferences.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/dialog/prefs/AppPreferences.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -144,13 +144,13 @@ final PreferencesHelper preferencesHelper = new PreferencesHelper(panel); panel.setBorder(createTitledBorder("optionsApps")); - serverField = new JFileField(this, "optionsAppServer", new File(appPreferencesModel.getServer()), JFileChooser.FILES_ONLY); + serverField = new JFileField(this, "optionsAppServer", null, new File(appPreferencesModel.getServer()), JFileChooser.FILES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsAppServer")); preferencesHelper.addComponent(serverField); - clientField = new JFileField(this, "optionsAppClient", new File(appPreferencesModel.getClient()), JFileChooser.FILES_ONLY); + clientField = new JFileField(this, "optionsAppClient", null, new File(appPreferencesModel.getClient()), JFileChooser.FILES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsAppClient")); preferencesHelper.addComponent(clientField); - editorField = new JFileField(this, "optionsAppEditor", new File(appPreferencesModel.getEditor()), JFileChooser.FILES_ONLY); + editorField = new JFileField(this, "optionsAppEditor", null, new File(appPreferencesModel.getEditor()), JFileChooser.FILES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsAppEditor")); preferencesHelper.addComponent(editorField); Modified: trunk/src/app/net/sf/gridarta/gui/dialog/prefs/ResPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/prefs/ResPreferences.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/dialog/prefs/ResPreferences.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -256,14 +256,14 @@ final JComponent panel = new JPanel(new GridBagLayout()); final PreferencesHelper preferencesHelper = new PreferencesHelper(panel); panel.setBorder(createTitledBorder("optionsResPaths")); - archField = new JFileField(this, "optionsResArch", globalSettings.getArchDirectory(), JFileChooser.DIRECTORIES_ONLY); + archField = new JFileField(this, "optionsResArch", null, globalSettings.getArchDirectory(), JFileChooser.DIRECTORIES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsResArch")); preferencesHelper.addComponent(archField); - mapField = new JFileField(this, "optionsResMaps", globalSettings.getMapsDirectory(), JFileChooser.DIRECTORIES_ONLY); + mapField = new JFileField(this, "optionsResMaps", null, globalSettings.getMapsDirectory(), JFileChooser.DIRECTORIES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsResMaps")); preferencesHelper.addComponent(mapField); if (globalSettings.hasMediaDirectory()) { - mediaField = new JFileField(this, "optionsResMedia", globalSettings.getMediaDirectory(), JFileChooser.DIRECTORIES_ONLY); + mediaField = new JFileField(this, "optionsResMedia", null, globalSettings.getMediaDirectory(), JFileChooser.DIRECTORIES_ONLY); preferencesHelper.addComponent(ActionBuilderUtils.newLabel(ACTION_BUILDER, "optionsResMedia")); assert mediaField != null; preferencesHelper.addComponent(mediaField); Modified: trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -27,7 +27,8 @@ import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JTextField; -import net.sf.gridarta.utils.FileChooserUtils; +import javax.swing.event.DocumentListener; +import net.sf.gridarta.model.io.PathManager; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; import net.sf.japi.swing.action.ActionMethod; @@ -54,6 +55,13 @@ private final JComponent parent; /** + * The base directory. When non-<code>null</code>, the contents of {@link + * #textField} are relative to this directory. + */ + @Nullable + private final File baseDir; + + /** * The text file that contains the currently selected file. */ @NotNull @@ -70,12 +78,15 @@ * @param parent the parent component * @param key the resource key for showing tooltips; <code>null</code> * disables tooltips + * @param baseDir the base directory; when non-<code>null</code> the + * contents of the text input field are relative to this directory * @param file the currently selected file * @param fileSelectionMode the file selection mode for the file chooser */ - public JFileField(@NotNull final JComponent parent, @Nullable final String key, @NotNull final File file, final int fileSelectionMode) { + public JFileField(@NotNull final JComponent parent, @Nullable final String key, @Nullable final File baseDir, @NotNull final File file, final int fileSelectionMode) { this.parent = parent; - textField = new JTextField(file.getPath(), 20); + this.baseDir = baseDir; + textField = new JTextField(getRelativeFile(file), 20); fileChooser.setFileSelectionMode(fileSelectionMode); @@ -101,7 +112,11 @@ @NotNull public File getFile() { final String text = textField.getText(); - return text.isEmpty() ? new File(System.getProperty("user.dir")) : new File(text); + if (text.isEmpty()) { + return baseDir == null ? new File(System.getProperty("user.dir")) : baseDir; + } else { + return baseDir == null ? new File(text) : new File(baseDir, text); + } } /** @@ -109,23 +124,44 @@ * @param file the currently selected file */ public void setFile(@NotNull final File file) { - textField.setText(file.getAbsolutePath()); + final String text = getRelativeFile(file); + textField.setText(text.isEmpty() ? "/" : text); } /** + * Returns the contents for the text input field for a file. + * @param file the file + * @return the contents + */ + @NotNull + private String getRelativeFile(final File file) { + return baseDir == null ? file.getPath() : PathManager.getMapPath(file.getAbsolutePath(), baseDir); + } + + /** + * Adds a {@link DocumentListener} to the text input field. + * @param documentListener the document listener to add + */ + public void addDocumentListener(@NotNull final DocumentListener documentListener) { + textField.getDocument().addDocumentListener(documentListener); + } + + /** * The action method for the button. It shows the file chooser. */ @ActionMethod public void fileChooserButton() { final File file = getFile(); fileChooser.setSelectedFile(file); - if (file.isDirectory()) { - FileChooserUtils.setCurrentDirectory(fileChooser, file); - } else { - FileChooserUtils.setCurrentDirectory(fileChooser, file.getParentFile()); - } + //if (file.isDirectory()) { + //FileChooserUtils.setCurrentDirectory(fileChooser, file); + //fileChooser.setSelectedFile(null); + //} else { + //FileChooserUtils.setCurrentDirectory(fileChooser, file.getParentFile()); + //fileChooser.setSelectedFile(file); + //} if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { - textField.setText(fileChooser.getSelectedFile().getPath()); + setFile(fileChooser.getSelectedFile()); } } Modified: trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java 2012-01-08 19:19:57 UTC (rev 9169) +++ trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java 2012-01-08 19:24:27 UTC (rev 9170) @@ -281,7 +281,7 @@ final AbstractResources<G, A, R> resources = editorFactory.newResources(gameObjectParser, archetypeSet, archetypeParser, mapViewSettings, faceObjects, animationObjects, archFaceProvider, faceObjectProviders); final Spells<NumberSpell> numberSpells = new Spells<NumberSpell>(); final Spells<GameObjectSpell<G, A, R>> gameObjectSpells = new Spells<GameObjectSpell<G, A, R>>(); - final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, defaultFilterList); + final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, defaultFilterList, globalSettings); final DefaultMainControl<G, A, R> mainControl = editorFactory.newMainControl(mode == GridartaRunMode.COLLECT_ARCHES, errorView, globalSettings, configSourceFactory, pathManager, gameObjectMatchers, gameObjectFactory, archetypeTypeSet, archetypeSet, archetypeChooserModel, autojoinLists, mapManager, pluginModel, validators, scriptedEventEditor, resources, numberSpells, gameObjectSpells, pluginParameterFactory, validatorPreferences, mapWriter); final NamedFilter defaultNamedFilterList = new NamedFilter(gameObjectMatchers.getFilters()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 19:20:03
|
Revision: 9169 http://gridarta.svn.sourceforge.net/gridarta/?rev=9169&view=rev Author: akirschbaum Date: 2012-01-08 19:19:57 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Do not drop plugin script parameter with unknown type. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2012-01-08 18:31:29 UTC (rev 9168) +++ trunk/atrinik/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) @@ -1,5 +1,8 @@ 2012-01-08 Andreas Kirschbaum + * Do not drop plugin script parameter with unknown type. Create + String parameters instead. + * Fix file chooser buttons in setup dialog. 2011-11-17 Andreas Kirschbaum Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2012-01-08 18:31:29 UTC (rev 9168) +++ trunk/crossfire/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) @@ -1,5 +1,8 @@ 2012-01-08 Andreas Kirschbaum + * Do not drop plugin script parameter with unknown type. Create + String parameters instead. + * Fix file chooser buttons in setup dialog. 2011-11-17 Andreas Kirschbaum Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2012-01-08 18:31:29 UTC (rev 9168) +++ trunk/daimonin/ChangeLog 2012-01-08 19:19:57 UTC (rev 9169) @@ -1,5 +1,8 @@ 2012-01-08 Andreas Kirschbaum + * Do not drop plugin script parameter with unknown type. Create + String parameters instead. + * Fix file chooser buttons in setup dialog. 2011-11-17 Andreas Kirschbaum Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java 2012-01-08 18:31:29 UTC (rev 9168) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java 2012-01-08 19:19:57 UTC (rev 9169) @@ -117,12 +117,12 @@ final Collection<Element> parameters = node.getChildren("parameter"); if (parameters != null && !parameters.isEmpty()) { for (final Element parameter : parameters) { - final PluginParameter<G, A, R> pluginParameter; + PluginParameter<G, A, R> pluginParameter; try { pluginParameter = pluginParameterFactory.createParameter(parameter); } catch (final NoSuchParameterException ex) { - log.warn("Cannot create parameter type " + ex.getMessage() + ", dropping parameter"); - continue; + log.warn("Parameter type " + ex.getMessage() + " in plugin " + pluginModel + " is unknown"); + pluginParameter = pluginParameterFactory.createStringParameter(parameter); } pluginModel.addParameter(pluginParameter); } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 18:31:29 UTC (rev 9168) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 19:19:57 UTC (rev 9169) @@ -61,7 +61,19 @@ return createParameter(parameterNode.getChildText("type"), parameterNode); } + /** + * Creates a new {@link StringParameter} from XML representation. + * @param parameterNode the XML representation + * @return the string parameter + */ @NotNull + public PluginParameter<G, A, R> createStringParameter(@NotNull final Element parameterNode) { + final PluginParameter<G, A, R> parameter = new StringParameter<G, A, R>(); + codec.fromXML(parameter, parameterNode); + return parameter; + } + + @NotNull public PluginParameter<G, A, R> createParameter(@NotNull final String type) throws NoSuchParameterException { if (type.equals(StringParameter.PARAMETER_TYPE)) { return new StringParameter<G, A, R>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 18:31:35
|
Revision: 9168 http://gridarta.svn.sourceforge.net/gridarta/?rev=9168&view=rev Author: akirschbaum Date: 2012-01-08 18:31:29 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Make parameter optional. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java Modified: trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 18:29:24 UTC (rev 9167) +++ trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 18:31:29 UTC (rev 9168) @@ -32,6 +32,7 @@ import net.sf.japi.swing.action.ActionBuilderFactory; import net.sf.japi.swing.action.ActionMethod; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A component for selecting files. It consists of a text field and a button @@ -67,19 +68,22 @@ /** * Creates a new instance. * @param parent the parent component - * @param key the resource key for creating components + * @param key the resource key for showing tooltips; <code>null</code> + * disables tooltips * @param file the currently selected file * @param fileSelectionMode the file selection mode for the file chooser */ - public JFileField(@NotNull final JComponent parent, @NotNull final String key, @NotNull final File file, final int fileSelectionMode) { + public JFileField(@NotNull final JComponent parent, @Nullable final String key, @NotNull final File file, final int fileSelectionMode) { this.parent = parent; textField = new JTextField(file.getPath(), 20); fileChooser.setFileSelectionMode(fileSelectionMode); - final String tooltip = ACTION_BUILDER.getString(key + ".shortdescription"); - if (tooltip != null) { - textField.setToolTipText(tooltip); + if (key != null) { + final String tooltip = ACTION_BUILDER.getString(key + ".shortdescription"); + if (tooltip != null) { + textField.setToolTipText(tooltip); + } } final AbstractButton fileChooserButton = new JButton(ACTION_BUILDER.createAction(false, "fileChooserButton", this)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 18:29:30
|
Revision: 9167 http://gridarta.svn.sourceforge.net/gridarta/?rev=9167&view=rev Author: akirschbaum Date: 2012-01-08 18:29:24 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Merge JFileChooserButton into JFileField. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/utils/JFileChooserButton.java Deleted: trunk/src/app/net/sf/gridarta/gui/utils/JFileChooserButton.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/JFileChooserButton.java 2012-01-08 17:03:53 UTC (rev 9166) +++ trunk/src/app/net/sf/gridarta/gui/utils/JFileChooserButton.java 2012-01-08 18:29:24 UTC (rev 9167) @@ -1,105 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2011 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.gui.utils; - -import java.awt.Insets; -import java.io.File; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JFileChooser; -import javax.swing.JTextField; -import net.sf.gridarta.utils.FileChooserUtils; -import net.sf.japi.swing.action.ActionBuilder; -import net.sf.japi.swing.action.ActionBuilderFactory; -import net.sf.japi.swing.action.ActionMethod; -import org.jetbrains.annotations.NotNull; - -/** - * A button for selecting a file. - * @author Andreas Kirschbaum - */ -public class JFileChooserButton extends JButton { - - /** - * The {@link ActionBuilder}. - */ - @NotNull - private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); - - /** - * The {@link JFileChooser} for selecting the file. - */ - @NotNull - private final JFileChooser fileChooser = new JFileChooser(); - - /** - * The parent component. - */ - @NotNull - private final JComponent parent; - - /** - * The currently selected file. - */ - @NotNull - private final JTextField textField; - - /** - * Creates a new instance. - * @param parent the parent component - * @param textField the text field to modify - * @param fileSelectionMode the file selection mode for the file chooser - */ - public JFileChooserButton(@NotNull final JComponent parent, @NotNull final JTextField textField, final int fileSelectionMode) { - this.parent = parent; - this.textField = textField; - setAction(ACTION_BUILDER.createAction(false, "fileChooserButton", this)); - fileChooser.setFileSelectionMode(fileSelectionMode); - setMargin(new Insets(0, 0, 0, 0)); - } - - /** - * The action method for the button. It shows the file chooser. - */ - @ActionMethod - public void fileChooserButton() { - final File file = getFile(); - fileChooser.setSelectedFile(file); - if (file.isDirectory()) { - FileChooserUtils.setCurrentDirectory(fileChooser, file); - } else { - FileChooserUtils.setCurrentDirectory(fileChooser, file.getParentFile()); - } - if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { - textField.setText(fileChooser.getSelectedFile().getPath()); - } - } - - /** - * Returns the currently selected file. - * @return the currently selected file - */ - @NotNull - public File getFile() { - final String text = textField.getText(); - return text.isEmpty() ? new File(System.getProperty("user.dir")) : new File(text); - } - -} Modified: trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 17:03:53 UTC (rev 9166) +++ trunk/src/app/net/sf/gridarta/gui/utils/JFileField.java 2012-01-08 18:29:24 UTC (rev 9167) @@ -20,11 +20,17 @@ package net.sf.gridarta.gui.utils; import java.awt.BorderLayout; +import java.awt.Insets; import java.io.File; +import javax.swing.AbstractButton; +import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JFileChooser; import javax.swing.JTextField; +import net.sf.gridarta.utils.FileChooserUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; +import net.sf.japi.swing.action.ActionMethod; import org.jetbrains.annotations.NotNull; /** @@ -41,12 +47,24 @@ private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); /** + * The parent component. + */ + @NotNull + private final JComponent parent; + + /** * The text file that contains the currently selected file. */ @NotNull private final JTextField textField; /** + * The {@link JFileChooser} for selecting the file. + */ + @NotNull + private final JFileChooser fileChooser = new JFileChooser(); + + /** * Creates a new instance. * @param parent the parent component * @param key the resource key for creating components @@ -54,16 +72,22 @@ * @param fileSelectionMode the file selection mode for the file chooser */ public JFileField(@NotNull final JComponent parent, @NotNull final String key, @NotNull final File file, final int fileSelectionMode) { + this.parent = parent; textField = new JTextField(file.getPath(), 20); + fileChooser.setFileSelectionMode(fileSelectionMode); + final String tooltip = ACTION_BUILDER.getString(key + ".shortdescription"); if (tooltip != null) { textField.setToolTipText(tooltip); } + final AbstractButton fileChooserButton = new JButton(ACTION_BUILDER.createAction(false, "fileChooserButton", this)); + fileChooserButton.setMargin(new Insets(0, 0, 0, 0)); + setLayout(new BorderLayout()); add(textField, BorderLayout.CENTER); - add(new JFileChooserButton(parent, textField, fileSelectionMode), BorderLayout.EAST); + add(fileChooserButton, BorderLayout.EAST); } /** @@ -84,4 +108,21 @@ textField.setText(file.getAbsolutePath()); } + /** + * The action method for the button. It shows the file chooser. + */ + @ActionMethod + public void fileChooserButton() { + final File file = getFile(); + fileChooser.setSelectedFile(file); + if (file.isDirectory()) { + FileChooserUtils.setCurrentDirectory(fileChooser, file); + } else { + FileChooserUtils.setCurrentDirectory(fileChooser, file.getParentFile()); + } + if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { + textField.setText(fileChooser.getSelectedFile().getPath()); + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 17:04:00
|
Revision: 9166 http://gridarta.svn.sourceforge.net/gridarta/?rev=9166&view=rev Author: akirschbaum Date: 2012-01-08 17:03:53 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Extract XML decoding of PluginParameters into PluginParameterCodec. Modified Paths: -------------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -23,7 +23,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.utils.EventListenerList2; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -104,15 +103,6 @@ * {@inheritDoc} */ @Override - public void fromXML(@NotNull final Element e) { - name = e.getChildText("name"); - description = e.getChildText("description"); - } - - /** - * {@inheritDoc} - */ - @Override public void addPluginParameterListener(@NotNull final PluginParameterListener<G, A, R> listener) { listeners.add(listener); } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -24,7 +24,6 @@ import net.sf.gridarta.model.archetypeset.ArchetypeSet; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,13 +54,6 @@ this.archetypeSet = archetypeSet; } - @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - valueString = e.getChildTextTrim("value"); - setValue(archetypeSet.getOrCreateArchetype(valueString)); - } - /** * {@inheritDoc} */ Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -22,7 +22,6 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** @@ -55,18 +54,6 @@ * {@inheritDoc} */ @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - final String val = e.getChildText("value"); - setValue(Boolean.valueOf(val)); - trueText = e.getChildText("trueText"); - falseText = e.getChildText("falseText"); - } - - /** - * {@inheritDoc} - */ - @Override public boolean setStringValue(@NotNull final String value) { if (value.equals("true")) { setValue(Boolean.TRUE); Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -22,8 +22,6 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import net.sf.gridarta.utils.NumberUtils; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** @@ -62,24 +60,6 @@ * {@inheritDoc} */ @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - final String val = e.getChildText("value"); - setValue(NumberUtils.parseDouble(val)); - try { - min = Double.parseDouble(e.getChildTextTrim("minimum")); - } catch (final NumberFormatException ignored) { - } - try { - max = Math.max(min, Double.parseDouble(e.getChildTextTrim("maximum"))); - } catch (final NumberFormatException ignored) { - } - } - - /** - * {@inheritDoc} - */ - @Override public boolean setStringValue(@NotNull final String value) { final double doubleValue; try { Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -20,12 +20,10 @@ package net.sf.gridarta.plugin.parameter; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.filter.FilterParser; import net.sf.gridarta.model.filter.NamedFilter; import net.sf.gridarta.model.filter.NamedFilterConfig; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; public class FilterParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, NamedFilterConfig> { @@ -59,13 +57,6 @@ return false; // XXX: not implemented } - @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - final NamedFilterConfig conf = getValue(); - new FilterParser().fromXML(e, conf); - } - /** * {@inheritDoc} */ Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -22,7 +22,6 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** @@ -59,29 +58,6 @@ * {@inheritDoc} */ @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - final String val = e.getChildText("value"); - try { - final Integer iVal = Integer.parseInt(val); - setValue(iVal); - } catch (final NumberFormatException ignored) { - setValue(0); - } - try { - min = Integer.parseInt(e.getChildTextTrim("minimum")); - } catch (final NumberFormatException ignored) { - } - try { - max = Math.max(Integer.parseInt(e.getChildTextTrim("maximum")), min); - } catch (final NumberFormatException ignored) { - } - } - - /** - * {@inheritDoc} - */ - @Override public boolean setStringValue(@NotNull final String value) { final int intValue; try { Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -24,7 +24,6 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcontrol.MapControl; import net.sf.gridarta.model.mapmanager.MapManager; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -73,15 +72,6 @@ /** * {@inheritDoc} */ - @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - super.setValue(e.getChildTextTrim("value")); - } - - /** - * {@inheritDoc} - */ @NotNull @Override public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { @@ -126,7 +116,7 @@ */ @Override public boolean setStringValue(@NotNull final String value) { - return false; // XXX: not yet implemented + return super.setValue(value); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -22,7 +22,6 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,8 +52,6 @@ */ boolean setStringValue(@NotNull String value); - void fromXML(@NotNull Element e); - @NotNull String getParameterType(); Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -21,8 +21,10 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.filter.FilterParser; +import net.sf.gridarta.model.filter.NamedFilterConfig; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.utils.NumberUtils; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,19 +44,17 @@ /** * Converts a generic {@link PluginParameter} to XML encoding. + * @param parameter the plugin parameter * @return the plugin parameter in XML encoding */ @NotNull - private Element toXML() { + private Element toXML(@NotNull final PluginParameter<G, A, R> parameter) { final Element e = new Element("parameter"); final Element n = new Element("name"); final Element d = new Element("description"); final Element t = new Element("type"); - assert parameter != null; n.addContent(parameter.getName()); - assert parameter != null; d.addContent(parameter.getDescription()); - assert parameter != null; t.addContent(parameter.getParameterType()); e.addContent(n); e.addContent(d); @@ -65,7 +65,7 @@ @NotNull @Override public Element visit(@NotNull final ArchParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element v = new Element("value"); final Archetype<G, A, R> archetype = parameter.getValue(); if (archetype != null) { @@ -80,7 +80,7 @@ @NotNull @Override public Element visit(@NotNull final BooleanParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element v = new Element("value"); final Boolean value = parameter.getValue(); v.addContent(value != null ? value.toString() : ""); @@ -97,7 +97,7 @@ @NotNull @Override public Element visit(@NotNull final DoubleParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element v = new Element("value"); final Double value = parameter.getValue(); v.addContent(value != null ? value.toString() : ""); @@ -114,7 +114,7 @@ @NotNull @Override public Element visit(@NotNull final FilterParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); e.addContent(new FilterParser().toXML(parameter.getValue())); return e; } @@ -122,7 +122,7 @@ @NotNull @Override public Element visit(@NotNull final IntegerParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element v = new Element("value"); final Integer value = parameter.getValue(); v.addContent(value != null ? value.toString() : ""); @@ -139,7 +139,7 @@ @NotNull @Override public Element visit(@NotNull final MapParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element v = new Element("value"); v.addContent((String) parameter.getValue()); e.addContent(v); @@ -149,7 +149,7 @@ @NotNull @Override public Element visit(@NotNull final StringParameter<G, A, R> parameter) { - final Element e = toXML(); + final Element e = toXML(parameter); final Element s = new Element("value"); final String value = parameter.getValue(); s.addContent(value != null ? value : ""); @@ -160,10 +160,122 @@ }; /** - * Holds the {@link PluginParameter} being encoded or decoded. + * A {@link PluginParameterVisitor} that restores a {@link PluginParameter} + * from XML representation. */ + @NotNull + private final PluginParameterVisitor<G, A, R, PluginParameter<G, A, R>> fromXML = new PluginParameterVisitor<G, A, R, PluginParameter<G, A, R>>() { + + /** + * Restores generic plugin parameter values. + * @param parameter the plugin parameter being restored + */ + public void fromXML(@NotNull final PluginParameter<G, A, R> parameter) { + assert e != null; + parameter.setName(e.getChildText("name")); + assert e != null; + parameter.setDescription(e.getChildText("description")); + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final ArchParameter<G, A, R> parameter) { + fromXML(parameter); + assert e != null; + parameter.setStringValue(e.getChildTextTrim("value")); + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final BooleanParameter<G, A, R> parameter) { + fromXML(parameter); + assert e != null; + final String val = e.getChildText("value"); + parameter.setValue(Boolean.valueOf(val)); + assert e != null; + parameter.setTrueText(e.getChildText("trueText")); + assert e != null; + parameter.setFalseText(e.getChildText("falseText")); + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final DoubleParameter<G, A, R> parameter) { + fromXML(parameter); + try { + parameter.setMin(Double.parseDouble(e.getChildTextTrim("minimum"))); + } catch (final NumberFormatException ignored) { + } + try { + parameter.setMax(Double.parseDouble(e.getChildTextTrim("maximum"))); + } catch (final NumberFormatException ignored) { + } + final String val = e.getChildText("value"); + parameter.setValue(NumberUtils.parseDouble(val)); + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final FilterParameter<G, A, R> parameter) { + fromXML(parameter); + final NamedFilterConfig conf = parameter.getValue(); + assert e != null; + assert e != null; + new FilterParser().fromXML(e, conf); + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final IntegerParameter<G, A, R> parameter) { + fromXML(parameter); + final String val = e.getChildText("value"); + try { + final Integer iVal = Integer.parseInt(val); + parameter.setValue(iVal); + } catch (final NumberFormatException ignored) { + parameter.setValue(0); + } + try { + parameter.setMin(Integer.parseInt(e.getChildTextTrim("minimum"))); + } catch (final NumberFormatException ignored) { + } + try { + parameter.setMax(Integer.parseInt(e.getChildTextTrim("maximum"))); + } catch (final NumberFormatException ignored) { + } + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final MapParameter<G, A, R> parameter) { + fromXML(parameter); + assert e != null; + parameter.setStringValue(e.getChildTextTrim("value")); + return parameter; + } + + @NotNull + @Override + public PluginParameter<G, A, R> visit(@NotNull final StringParameter<G, A, R> parameter) { + fromXML(parameter); + assert e != null; + final String val = e.getChildTextTrim("value"); + parameter.setValue(val); + return parameter; + } + + }; + + /** + * Holds the XML representation being decoded. + */ @Nullable - private PluginParameter<G, A, R> parameter; + private Element e; /** * Returns the XML representation of a {@link PluginParameter}. @@ -172,12 +284,18 @@ */ @NotNull public Element toXML(@NotNull final PluginParameter<G, A, R> parameter) { - this.parameter = parameter; - try { - return parameter.visit(toXML); - } finally { - this.parameter = null; - } + return parameter.visit(toXML); } + /** + * Restores a {@link PluginParameter} from XML representation. + * @param parameter the plugin parameter to restore + * @param e the XML representation + */ + public void fromXML(@NotNull final PluginParameter<G, A, R> parameter, @NotNull final Element e) { + this.e = e; + parameter.visit(fromXML); + this.e = null; + } + } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterFactory.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -43,6 +43,13 @@ @NotNull private final NamedFilter defaultFilterList; + /** + * The {@link PluginParameterCodec} for converting {@link PluginParameter + * PluginParameters} to or from XML representation. + */ + @NotNull + private final PluginParameterCodec<G, A, R> codec = new PluginParameterCodec<G, A, R>(); + public PluginParameterFactory(@NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final NamedFilter defaultFilterList) { this.archetypeSet = archetypeSet; this.mapManager = mapManager; @@ -83,7 +90,7 @@ @NotNull public PluginParameter<G, A, R> createParameter(@NotNull final String type, @NotNull final Element parameterNode) throws NoSuchParameterException { final PluginParameter<G, A, R> p = createParameter(type); - p.fromXML(parameterNode); + codec.fromXML(p, parameterNode); return p; } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 16:37:14 UTC (rev 9165) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 17:03:53 UTC (rev 9166) @@ -24,7 +24,6 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import org.apache.log4j.Category; import org.apache.log4j.Logger; -import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** @@ -65,19 +64,6 @@ /** * {@inheritDoc} */ - @Override - public void fromXML(@NotNull final Element e) { - super.fromXML(e); - final String val = e.getChildTextTrim("value"); - if (log.isDebugEnabled()) { - log.debug("value imported from xml is " + val); - } - setValue(val); - } - - /** - * {@inheritDoc} - */ @NotNull @Override public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 16:37:21
|
Revision: 9165 http://gridarta.svn.sourceforge.net/gridarta/?rev=9165&view=rev Author: akirschbaum Date: 2012-01-08 16:37:14 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Extract XML encoding of PluginParameters into PluginParameterCodec. Modified Paths: -------------- trunk/plugin/src/app/net/sf/gridarta/plugin/Plugin.java trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java Added Paths: ----------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/Plugin.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/Plugin.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/Plugin.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -36,6 +36,7 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.plugin.parameter.NoSuchParameterException; import net.sf.gridarta.plugin.parameter.PluginParameter; +import net.sf.gridarta.plugin.parameter.PluginParameterCodec; import net.sf.gridarta.plugin.parameter.PluginParameterFactory; import net.sf.gridarta.plugin.parameter.StringParameter; import org.apache.log4j.Category; @@ -82,6 +83,13 @@ private final PluginParameterFactory<G, A, R> pluginParameterFactory; /** + * The {@link PluginParameterCodec} for converting {@link PluginParameter + * PluginParameters} to or from XML representation. + */ + @NotNull + private final PluginParameterCodec<G, A, R> codec = new PluginParameterCodec<G, A, R>(); + + /** * Whether this plugin is run whenever the editor starts. */ private boolean autoBoot = false; @@ -259,7 +267,7 @@ model.script = script; model.modified = modified; for (final PluginParameter<G, A, R> param : parameters) { - final Element paramXml = param.toXML(); + final Element paramXml = codec.toXML(param); final PluginParameter<G, A, R> clonedParam; try { clonedParam = pluginParameterFactory.createParameter(paramXml); @@ -367,7 +375,7 @@ * @throws NoSuchParameterException if the index is invalid */ public void convertType(final int index, @NotNull final String newType) throws NoSuchParameterException { - parameters.set(index, pluginParameterFactory.createParameter(newType, parameters.get(index).toXML())); + parameters.set(index, pluginParameterFactory.createParameter(newType, codec.toXML(parameters.get(index)))); modified = true; notifyListeners(); } @@ -454,4 +462,14 @@ return null; } + /** + * Returns XML representation for a {@link PluginParameter}. + * @param pluginParameter the plugin parameter + * @return the plugin parameter in XML representation + */ + @NotNull + public Element toXML(@NotNull final PluginParameter<G, A, R> pluginParameter) { + return codec.toXML(pluginParameter); + } + } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/PluginModelParser.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -164,7 +164,7 @@ root.addContent(modes); for (final PluginParameter<G, A, R> pluginParameter : plugin) { - root.addContent(pluginParameter.toXML()); + root.addContent(plugin.toXML(pluginParameter)); } return root; } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -103,26 +103,7 @@ /** * {@inheritDoc} */ - @NotNull @Override - public Element toXML() { - final Element e = new Element("parameter"); - final Element n = new Element("name"); - final Element d = new Element("description"); - final Element t = new Element("type"); - n.addContent(name); - d.addContent(description); - t.addContent(getParameterType()); - e.addContent(n); - e.addContent(d); - e.addContent(t); - return e; - } - - /** - * {@inheritDoc} - */ - @Override public void fromXML(@NotNull final Element e) { name = e.getChildText("name"); description = e.getChildText("description"); Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -74,24 +74,6 @@ /** * {@inheritDoc} */ - @NotNull - @Override - public Element toXML() { - final Element e = super.toXML(); - final Element v = new Element("value"); - final Archetype<G, A, R> archetype = getValue(); - if (archetype != null) { - v.addContent(archetype.getArchetypeName()); - } else { - v.addContent(valueString); - } - e.addContent(v); - return e; - } - - /** - * {@inheritDoc} - */ @Nullable @Override public Archetype<G, A, R> getValue() { @@ -125,4 +107,9 @@ return PARAMETER_TYPE; } + @Nullable + public String getValueString() { + return valueString; + } + } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -84,25 +84,6 @@ */ @NotNull @Override - public Element toXML() { - final Element e = super.toXML(); - final Element v = new Element("value"); - v.addContent(getValue() != null ? getValue().toString() : ""); - e.addContent(v); - final Element yes = new Element("trueText"); - yes.addContent(trueText); - final Element no = new Element("falseText"); - no.addContent(falseText); - e.addContent(yes); - e.addContent(no); - return e; - } - - /** - * {@inheritDoc} - */ - @NotNull - @Override public String getParameterType() { return PARAMETER_TYPE; } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -96,25 +96,6 @@ */ @NotNull @Override - public Element toXML() { - final Element e = super.toXML(); - final Element v = new Element("value"); - v.addContent(getValue() != null ? getValue().toString() : ""); - e.addContent(v); - final Element min = new Element("minimum"); - final Element max = new Element("maximum"); - min.addContent(Double.toString(this.min)); - max.addContent(Double.toString(this.max)); - e.addContent(min); - e.addContent(max); - return e; - } - - /** - * {@inheritDoc} - */ - @NotNull - @Override public String getParameterType() { return PARAMETER_TYPE; } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -75,14 +75,6 @@ return visitor.visit(this); } - @NotNull - @Override - public Element toXML() { - final Element e = super.toXML(); - e.addContent(new FilterParser().toXML(getValue())); - return e; - } - /** * {@inheritDoc} */ Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -98,25 +98,6 @@ */ @NotNull @Override - public Element toXML() { - final Element e = super.toXML(); - final Element v = new Element("value"); - v.addContent(getValue() != null ? getValue().toString() : ""); - e.addContent(v); - final Element min = new Element("minimum"); - final Element max = new Element("maximum"); - min.addContent(Integer.toString(this.min)); - max.addContent(Integer.toString(this.max)); - e.addContent(min); - e.addContent(max); - return e; - } - - /** - * {@inheritDoc} - */ - @NotNull - @Override public String getParameterType() { return PARAMETER_TYPE; } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -91,19 +91,6 @@ /** * {@inheritDoc} */ - @NotNull - @Override - public Element toXML() { - final Element e = super.toXML(); - final Element v = new Element("value"); - v.addContent((String) super.getValue()); - e.addContent(v); - return e; - } - - /** - * {@inheritDoc} - */ @Nullable @Override public Object getValue() { Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -53,9 +53,6 @@ */ boolean setStringValue(@NotNull String value); - @NotNull - Element toXML(); - void fromXML(@NotNull Element e); @NotNull Added: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java (rev 0) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -0,0 +1,183 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.plugin.parameter; + +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.filter.FilterParser; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Converts {@link PluginParameter PluginParameters} from or to XML encoding. + * @author tchize + * @author Andreas Kirschbaum + */ +public class PluginParameterCodec<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * A {@link PluginParameterVisitor} that returns XML representation. + */ + @NotNull + private final PluginParameterVisitor<G, A, R, Element> toXML = new PluginParameterVisitor<G, A, R, Element>() { + + /** + * Converts a generic {@link PluginParameter} to XML encoding. + * @return the plugin parameter in XML encoding + */ + @NotNull + private Element toXML() { + final Element e = new Element("parameter"); + final Element n = new Element("name"); + final Element d = new Element("description"); + final Element t = new Element("type"); + assert parameter != null; + n.addContent(parameter.getName()); + assert parameter != null; + d.addContent(parameter.getDescription()); + assert parameter != null; + t.addContent(parameter.getParameterType()); + e.addContent(n); + e.addContent(d); + e.addContent(t); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final ArchParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element v = new Element("value"); + final Archetype<G, A, R> archetype = parameter.getValue(); + if (archetype != null) { + v.addContent(archetype.getArchetypeName()); + } else { + v.addContent(parameter.getValueString()); + } + e.addContent(v); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final BooleanParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element v = new Element("value"); + final Boolean value = parameter.getValue(); + v.addContent(value != null ? value.toString() : ""); + e.addContent(v); + final Element yes = new Element("trueText"); + yes.addContent(parameter.getTrueText()); + final Element no = new Element("falseText"); + no.addContent(parameter.getFalseText()); + e.addContent(yes); + e.addContent(no); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final DoubleParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element v = new Element("value"); + final Double value = parameter.getValue(); + v.addContent(value != null ? value.toString() : ""); + e.addContent(v); + final Element min = new Element("minimum"); + final Element max = new Element("maximum"); + min.addContent(Double.toString(parameter.getMin())); + max.addContent(Double.toString(parameter.getMax())); + e.addContent(min); + e.addContent(max); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final FilterParameter<G, A, R> parameter) { + final Element e = toXML(); + e.addContent(new FilterParser().toXML(parameter.getValue())); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final IntegerParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element v = new Element("value"); + final Integer value = parameter.getValue(); + v.addContent(value != null ? value.toString() : ""); + e.addContent(v); + final Element min = new Element("minimum"); + final Element max = new Element("maximum"); + min.addContent(Integer.toString(parameter.getMin())); + max.addContent(Integer.toString(parameter.getMax())); + e.addContent(min); + e.addContent(max); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final MapParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element v = new Element("value"); + v.addContent((String) parameter.getValue()); + e.addContent(v); + return e; + } + + @NotNull + @Override + public Element visit(@NotNull final StringParameter<G, A, R> parameter) { + final Element e = toXML(); + final Element s = new Element("value"); + final String value = parameter.getValue(); + s.addContent(value != null ? value : ""); + e.addContent(s); + return e; + } + + }; + + /** + * Holds the {@link PluginParameter} being encoded or decoded. + */ + @Nullable + private PluginParameter<G, A, R> parameter; + + /** + * Returns the XML representation of a {@link PluginParameter}. + * @param parameter the plugin parameter to encode + * @return the plugin parameter in XML repfresentation + */ + @NotNull + public Element toXML(@NotNull final PluginParameter<G, A, R> parameter) { + this.parameter = parameter; + try { + return parameter.visit(toXML); + } finally { + this.parameter = null; + } + } + +} Property changes on: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterCodec.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 16:21:09 UTC (rev 9164) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 16:37:14 UTC (rev 9165) @@ -93,17 +93,4 @@ return PARAMETER_TYPE; } - /** - * {@inheritDoc} - */ - @NotNull - @Override - public Element toXML() { - final Element e = super.toXML(); - final Element s = new Element("value"); - s.addContent(getValue() != null ? getValue() : ""); - e.addContent(s); - return e; - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 16:21:16
|
Revision: 9164 http://gridarta.svn.sourceforge.net/gridarta/?rev=9164&view=rev Author: akirschbaum Date: 2012-01-08 16:21:09 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Simplify PluginParameterViewFactory. Modified Paths: -------------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -65,9 +65,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -45,9 +45,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -52,9 +52,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -69,9 +69,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } @NotNull Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -49,9 +49,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -82,9 +82,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -65,6 +65,7 @@ void removePluginParameterListener(@NotNull PluginParameterListener<G, A, R> listener); - void visit(@NotNull PluginParameterVisitor<G, A, R> visitor); + @NotNull + <T> T visit(@NotNull PluginParameterVisitor<G, A, R, T> visitor); } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -28,20 +28,27 @@ * Interface for visitors of {@link PluginParameter} instances. * @author Andreas Kirschbaum */ -public interface PluginParameterVisitor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { +public interface PluginParameterVisitor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, T> { - void visit(@NotNull ArchParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull ArchParameter<G, A, R> parameter); - void visit(@NotNull BooleanParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull BooleanParameter<G, A, R> parameter); - void visit(@NotNull DoubleParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull DoubleParameter<G, A, R> parameter); - void visit(@NotNull FilterParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull FilterParameter<G, A, R> parameter); - void visit(@NotNull IntegerParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull IntegerParameter<G, A, R> parameter); - void visit(@NotNull MapParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull MapParameter<G, A, R> parameter); - void visit(@NotNull StringParameter<G, A, R> parameter); + @NotNull + T visit(@NotNull StringParameter<G, A, R> parameter); } Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -78,9 +78,10 @@ /** * {@inheritDoc} */ + @NotNull @Override - public void visit(@NotNull final PluginParameterVisitor<G, A, R> visitor) { - visitor.visit(this); + public <T> T visit(@NotNull final PluginParameterVisitor<G, A, R, T> visitor) { + return visitor.visit(this); } /** Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 16:18:57 UTC (rev 9163) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 16:21:09 UTC (rev 9164) @@ -37,7 +37,6 @@ import net.sf.gridarta.plugin.parameter.PluginParameterVisitor; import net.sf.gridarta.plugin.parameter.StringParameter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * Factory for creating {@link PluginParameterView} instances. @@ -63,45 +62,49 @@ @NotNull private final FaceObjectProviders faceObjectProviders; - @Nullable - private PluginParameterView<G, A, R> view = null; - @NotNull - private final PluginParameterVisitor<G, A, R> visitor = new PluginParameterVisitor<G, A, R>() { + private final PluginParameterVisitor<G, A, R, PluginParameterView<G, A, R>> visitor = new PluginParameterVisitor<G, A, R, PluginParameterView<G, A, R>>() { + @NotNull @Override - public void visit(@NotNull final ArchParameter<G, A, R> parameter) { - view = new ArchParameterView<G, A, R>(parameter, gameObjectAttributesModel, archetypeSet, objectChooser, faceObjectProviders); + public PluginParameterView<G, A, R> visit(@NotNull final ArchParameter<G, A, R> parameter) { + return new ArchParameterView<G, A, R>(parameter, gameObjectAttributesModel, archetypeSet, objectChooser, faceObjectProviders); } + @NotNull @Override - public void visit(@NotNull final BooleanParameter<G, A, R> parameter) { - view = new BooleanParameterView<G, A, R>(parameter); + public PluginParameterView<G, A, R> visit(@NotNull final BooleanParameter<G, A, R> parameter) { + return new BooleanParameterView<G, A, R>(parameter); } + @NotNull @Override - public void visit(@NotNull final DoubleParameter<G, A, R> parameter) { - view = new DoubleParameterView<G, A, R>(parameter); + public PluginParameterView<G, A, R> visit(@NotNull final DoubleParameter<G, A, R> parameter) { + return new DoubleParameterView<G, A, R>(parameter); } + @NotNull @Override - public void visit(@NotNull final FilterParameter<G, A, R> parameter) { - view = new FilterParameterView<G, A, R>(parameter); + public PluginParameterView<G, A, R> visit(@NotNull final FilterParameter<G, A, R> parameter) { + return new FilterParameterView<G, A, R>(parameter); } + @NotNull @Override - public void visit(@NotNull final IntegerParameter<G, A, R> parameter) { - view = new IntegerParameterView<G, A, R>(parameter); + public PluginParameterView<G, A, R> visit(@NotNull final IntegerParameter<G, A, R> parameter) { + return new IntegerParameterView<G, A, R>(parameter); } + @NotNull @Override - public void visit(@NotNull final MapParameter<G, A, R> parameter) { - view = new MapParameterView<G, A, R>(parameter, mapManager); + public PluginParameterView<G, A, R> visit(@NotNull final MapParameter<G, A, R> parameter) { + return new MapParameterView<G, A, R>(parameter, mapManager); } + @NotNull @Override - public void visit(@NotNull final StringParameter<G, A, R> parameter) { - view = new StringParameterView<G, A, R>(parameter); + public PluginParameterView<G, A, R> visit(@NotNull final StringParameter<G, A, R> parameter) { + return new StringParameterView<G, A, R>(parameter); } }; @@ -121,10 +124,7 @@ @NotNull public PluginParameterView<G, A, R> getView(@NotNull final PluginParameter<G, A, R> parameter) { - view = null; - parameter.visit(visitor); - assert view != null; - return view; + return parameter.visit(visitor); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 16:19:03
|
Revision: 9163 http://gridarta.svn.sourceforge.net/gridarta/?rev=9163&view=rev Author: akirschbaum Date: 2012-01-08 16:18:57 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Make project compilable. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/ArchParameterView.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/StringParameterView.java Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/ArchParameterView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/ArchParameterView.java 2012-01-08 16:10:30 UTC (rev 9162) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/ArchParameterView.java 2012-01-08 16:18:57 UTC (rev 9163) @@ -43,14 +43,14 @@ private final JComboBox value; @NotNull - private final AbstractPluginParameter<G, A, R, Archetype<G, A, R>, Void> parameter; + private final AbstractPluginParameter<G, A, R, Archetype<G, A, R>> parameter; /** * Creates a new instance. * @param faceObjectProviders the face object providers for looking up * faces */ - public ArchParameterView(@NotNull final AbstractPluginParameter<G, A, R, Archetype<G, A, R>, Void> param, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders) { + public ArchParameterView(@NotNull final AbstractPluginParameter<G, A, R, Archetype<G, A, R>> param, @NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders) { value = new ArchComboBox<G, A, R>(gameObjectAttributesModel, archetypeSet, objectChooser, faceObjectProviders); parameter = param; value.setSelectedItem(param.getValue()); Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/StringParameterView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/StringParameterView.java 2012-01-08 16:10:30 UTC (rev 9162) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/StringParameterView.java 2012-01-08 16:18:57 UTC (rev 9163) @@ -41,9 +41,9 @@ private final JComponent config = new JPanel(); @NotNull - private final AbstractPluginParameter<G, A, R, String, Void> linkedParameter; + private final AbstractPluginParameter<G, A, R, String> linkedParameter; - public StringParameterView(@NotNull final AbstractPluginParameter<G, A, R, String, Void> parameter) { + public StringParameterView(@NotNull final AbstractPluginParameter<G, A, R, String> parameter) { linkedParameter = parameter; final Document d = value.getDocument(); d.addDocumentListener(new DocumentListener() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 16:10:36
|
Revision: 9162 http://gridarta.svn.sourceforge.net/gridarta/?rev=9162&view=rev Author: akirschbaum Date: 2012-01-08 16:10:30 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Add @NotNull annotations. Modified Paths: -------------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 15:56:59 UTC (rev 9161) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/PluginParameterVisitor.java 2012-01-08 16:10:30 UTC (rev 9162) @@ -22,6 +22,7 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; /** * Interface for visitors of {@link PluginParameter} instances. @@ -29,18 +30,18 @@ */ public interface PluginParameterVisitor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - void visit(ArchParameter<G, A, R> parameter); + void visit(@NotNull ArchParameter<G, A, R> parameter); - void visit(BooleanParameter<G, A, R> parameter); + void visit(@NotNull BooleanParameter<G, A, R> parameter); - void visit(DoubleParameter<G, A, R> parameter); + void visit(@NotNull DoubleParameter<G, A, R> parameter); - void visit(FilterParameter<G, A, R> parameter); + void visit(@NotNull FilterParameter<G, A, R> parameter); - void visit(IntegerParameter<G, A, R> parameter); + void visit(@NotNull IntegerParameter<G, A, R> parameter); - void visit(MapParameter<G, A, R> parameter); + void visit(@NotNull MapParameter<G, A, R> parameter); - void visit(StringParameter<G, A, R> parameter); + void visit(@NotNull StringParameter<G, A, R> parameter); } Modified: trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 15:56:59 UTC (rev 9161) +++ trunk/src/app/net/sf/gridarta/gui/dialog/plugin/parameter/PluginParameterViewFactory.java 2012-01-08 16:10:30 UTC (rev 9162) @@ -66,40 +66,41 @@ @Nullable private PluginParameterView<G, A, R> view = null; + @NotNull private final PluginParameterVisitor<G, A, R> visitor = new PluginParameterVisitor<G, A, R>() { @Override - public void visit(final ArchParameter<G, A, R> parameter) { + public void visit(@NotNull final ArchParameter<G, A, R> parameter) { view = new ArchParameterView<G, A, R>(parameter, gameObjectAttributesModel, archetypeSet, objectChooser, faceObjectProviders); } @Override - public void visit(final BooleanParameter<G, A, R> parameter) { + public void visit(@NotNull final BooleanParameter<G, A, R> parameter) { view = new BooleanParameterView<G, A, R>(parameter); } @Override - public void visit(final DoubleParameter<G, A, R> parameter) { + public void visit(@NotNull final DoubleParameter<G, A, R> parameter) { view = new DoubleParameterView<G, A, R>(parameter); } @Override - public void visit(final FilterParameter<G, A, R> parameter) { + public void visit(@NotNull final FilterParameter<G, A, R> parameter) { view = new FilterParameterView<G, A, R>(parameter); } @Override - public void visit(final IntegerParameter<G, A, R> parameter) { + public void visit(@NotNull final IntegerParameter<G, A, R> parameter) { view = new IntegerParameterView<G, A, R>(parameter); } @Override - public void visit(final MapParameter<G, A, R> parameter) { + public void visit(@NotNull final MapParameter<G, A, R> parameter) { view = new MapParameterView<G, A, R>(parameter, mapManager); } @Override - public void visit(final StringParameter<G, A, R> parameter) { + public void visit(@NotNull final StringParameter<G, A, R> parameter) { view = new StringParameterView<G, A, R>(parameter); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2012-01-08 15:57:06
|
Revision: 9161 http://gridarta.svn.sourceforge.net/gridarta/?rev=9161&view=rev Author: akirschbaum Date: 2012-01-08 15:56:59 +0000 (Sun, 08 Jan 2012) Log Message: ----------- Remove unused code. Modified Paths: -------------- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/AbstractPluginParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -31,14 +31,11 @@ * Parameter for a Plugin. * @author tchize */ -public abstract class AbstractPluginParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V, C> implements PluginParameter<G, A, R> { +public abstract class AbstractPluginParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>, V> implements PluginParameter<G, A, R> { @Nullable private V value; - @Nullable - private C config; - @NotNull private String description = "[description]"; @@ -51,15 +48,6 @@ protected AbstractPluginParameter() { } - @Nullable - public C getConfig() { - return config; - } - - public void setConfig(@Nullable final C config) { - this.config = config; - } - /** * {@inheritDoc} */ Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/ArchParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -31,7 +31,7 @@ /** * A {@link PluginParameter} that holds an {@link Archetype} value. */ -public class ArchParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Archetype<G, A, R>, Void> { +public class ArchParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Archetype<G, A, R>> { /** * The string representation of this parameter type. Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/BooleanParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -28,7 +28,7 @@ /** * A {@link PluginParameter} that holds a boolean value. */ -public class BooleanParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Boolean, Void> { +public class BooleanParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Boolean> { /** * The string representation of this parameter type. Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/DoubleParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -29,7 +29,7 @@ /** * A {@link PluginParameter} that holds a double value. */ -public class DoubleParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Double, Void> { +public class DoubleParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Double> { /** * The string representation of this parameter type. Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/FilterParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -28,7 +28,7 @@ import org.jdom.Element; import org.jetbrains.annotations.NotNull; -public class FilterParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, NamedFilterConfig, Void> { +public class FilterParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, NamedFilterConfig> { @NotNull public static final String PARAMETER_TYPE = NamedFilterConfig.class.getName(); Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/IntegerParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -28,7 +28,7 @@ /** * A {@link PluginParameter} that holds an integer value. */ -public class IntegerParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Integer, Void> { +public class IntegerParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Integer> { /** * The string representation of this parameter type. Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/MapParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -31,7 +31,7 @@ /** * A {@link PluginParameter} that holds a {@link MapControl} value. */ -public class MapParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Object, Void> { // XXX: find correct parameter type: String or MapControl<GameObject, MapArchObject, Archetype> +public class MapParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, Object> { // XXX: find correct parameter type: String or MapControl<GameObject, MapArchObject, Archetype> /** * The string representation of this parameter type. Modified: trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java =================================================================== --- trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 15:54:42 UTC (rev 9160) +++ trunk/plugin/src/app/net/sf/gridarta/plugin/parameter/StringParameter.java 2012-01-08 15:56:59 UTC (rev 9161) @@ -30,7 +30,7 @@ /** * A {@link PluginParameter} that holds a string value. */ -public class StringParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, String, Void> { +public class StringParameter<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractPluginParameter<G, A, R, String> { /** * The Logger for printing log messages. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |