Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/wt/core
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv28193/src/games/stendhal/client/gui/wt/core
Modified Files:
WtWindowManager.java
Log Message:
Support multiple listeners for a single property, and deregistering listeners
Index: WtWindowManager.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/wt/core/WtWindowManager.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** WtWindowManager.java 19 Nov 2012 16:41:45 -0000 1.49
--- WtWindowManager.java 30 Nov 2012 20:54:24 -0000 1.50
***************
*** 21,25 ****
--- 21,27 ----
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+ import java.util.ArrayList;
import java.util.HashMap;
+ import java.util.List;
import java.util.Map;
import java.util.Properties;
***************
*** 35,39 ****
* @author mtotz
*/
! public class WtWindowManager {
/** the logger instance. */
--- 37,41 ----
* @author mtotz
*/
! public final class WtWindowManager {
/** the logger instance. */
***************
*** 54,58 ****
/** Change listeners. */
! private final Map<String, SettingChangeListener> listeners = new HashMap<String, SettingChangeListener>();
/** no public constructor. */
--- 56,60 ----
/** Change listeners. */
! private final Map<String, List<SettingChangeListener>> listeners = new HashMap<String, List<SettingChangeListener>>();
/** no public constructor. */
***************
*** 74,81 ****
* properties known for this panel.
*
! * @param name
! * @param minimized
! * @param x
! * @param y
*/
public void setDefaultProperties(final String name, final boolean minimized, final int x,
--- 76,83 ----
* properties known for this panel.
*
! * @param name window identifier
! * @param minimized <code>true</code> if the window is minimized
! * @param x window x coordinate
! * @param y window y coordinate
*/
public void setDefaultProperties(final String name, final boolean minimized, final int x,
***************
*** 134,146 ****
/**
! * @param panel
! * @return the config. If it does not exist yet, a new one is created.
*/
! private WindowConfiguration getConfig(final ManagedWindow panel) {
! final String name = panel.getName();
WindowConfiguration winC = configs.get(name);
if (winC == null) {
winC = new WindowConfiguration(name);
! winC.readFromProperties(properties, panel);
configs.put(name, winC);
}
--- 136,150 ----
/**
! * Get the configuration of a window.
! *
! * @param window the window whose configuration is wanted
! * @return the configuration. If it does not exist yet, a new one is created.
*/
! private WindowConfiguration getConfig(final ManagedWindow window) {
! final String name = window.getName();
WindowConfiguration winC = configs.get(name);
if (winC == null) {
winC = new WindowConfiguration(name);
! winC.readFromProperties(properties, window);
configs.put(name, winC);
}
***************
*** 188,192 ****
*/
public void registerSettingChangeListener(String key, SettingChangeListener listener) {
! listeners.put("config." + key, listener);
}
--- 192,215 ----
*/
public void registerSettingChangeListener(String key, SettingChangeListener listener) {
! String realKey = "config." + key;
! List<SettingChangeListener> list = listeners.get(realKey);
! if (list == null) {
! list = new ArrayList<SettingChangeListener>();
! listeners.put(realKey, list);
! }
! list.add(listener);
! }
!
! /**
! * Deregister a change listener.
! *
! * @param key the key the listener was registered for
! * @param listener listener to be removed
! */
! public void deregisterSettingChangeListener(String key, SettingChangeListener listener) {
! List<SettingChangeListener> list = listeners.get("config. " + key);
! if (list != null) {
! list.remove(listener);
! }
}
***************
*** 200,232 ****
String realKey = "config." + key;
properties.setProperty(realKey, value);
! SettingChangeListener listener = listeners.get(realKey);
! if (listener != null) {
! listener.changed(value);
}
}
/**
! * Formats the window with the saved config. Nothing happens when this
! * windows config is not known.
*
! * @param panel
*/
! public void formatWindow(final ManagedWindow panel) {
! final WindowConfiguration config = getConfig(panel);
! panel.moveTo(config.x, config.y);
! panel.setMinimized(config.minimized);
! panel.setVisible(config.visible);
}
/**
! * the panel was moved, so update the internal representation.
*
! * @param panel
! * @param x
! * @param y
*/
! public void moveTo(final ManagedWindow panel, final int x, final int y) {
! final WindowConfiguration config = getConfig(panel);
config.x = x;
config.y = y;
--- 223,257 ----
String realKey = "config." + key;
properties.setProperty(realKey, value);
! List<SettingChangeListener> list = listeners.get(realKey);
! if (list != null) {
! for (SettingChangeListener listener : list) {
! listener.changed(value);
! }
}
}
/**
! * Apply a saved configuration to a window. Nothing happens when this
! * windows configuration is not known.
*
! * @param window the window
*/
! public void formatWindow(final ManagedWindow window) {
! final WindowConfiguration config = getConfig(window);
! window.moveTo(config.x, config.y);
! window.setMinimized(config.minimized);
! window.setVisible(config.visible);
}
/**
! * Notify that a window has moved.
*
! * @param window the window that moved
! * @param x new x coordinate
! * @param y new y coordinate
*/
! public void moveTo(final ManagedWindow window, final int x, final int y) {
! final WindowConfiguration config = getConfig(window);
config.x = x;
config.y = y;
***************
*** 234,250 ****
/**
! * the panels minimized state changed, update the internal representation.
*
! * @param panel
! * @param state
*/
! public void setMinimized(final ManagedWindow panel, final boolean state) {
! final WindowConfiguration config = getConfig(panel);
config.minimized = state;
}
! public void setVisible(final ManagedWindow panel, final boolean state) {
! final WindowConfiguration config = getConfig(panel);
config.visible = state;
--- 259,283 ----
/**
! * Notify a window's minimized state has changed.
*
! * @param window changed window
! * @param state new minimization state. <code>true</code> if minimized,
! * <code>false</code> otherwise
*/
! public void setMinimized(final ManagedWindow window, final boolean state) {
! final WindowConfiguration config = getConfig(window);
config.minimized = state;
}
! /**
! * Notify that a window's visibility has changed.
! *
! * @param window changed window
! * @param state the new visibility state. <code>true</code> if visible,
! * <code>false</code> otherwise
! */
! public void setVisible(final ManagedWindow window, final boolean state) {
! final WindowConfiguration config = getConfig(window);
config.visible = state;
***************
*** 252,272 ****
/** encapsulates the configuration of a window. */
! private static class WindowConfiguration {
!
/** name of the window. */
private String name;
-
/** minimized state of the window. */
private boolean minimized;
-
/** is the window visible? */
private boolean visible;
-
/** x-pos. */
private int x;
-
/** y-pos. */
private int y;
private WindowConfiguration(final String name) {
this.name = name;
--- 285,305 ----
/** encapsulates the configuration of a window. */
! private static final class WindowConfiguration {
/** name of the window. */
private String name;
/** minimized state of the window. */
private boolean minimized;
/** is the window visible? */
private boolean visible;
/** x-pos. */
private int x;
/** y-pos. */
private int y;
+ /**
+ * Create configuration for a window.
+ *
+ * @param name window identifier
+ */
private WindowConfiguration(final String name) {
this.name = name;
***************
*** 283,287 ****
}
- /** returns to config as a property string. */
@Override
public String toString() {
--- 316,319 ----
***************
*** 290,300 ****
/**
! * reads the config from the properties.
*
! * @param props
! * @param defaultMinimized
! * @param defaultX
! * @param defaultY
! * @param defaultVisible
*/
private void readFromProperties(final Properties props,
--- 322,334 ----
/**
! * Read window configuration from properties.
*
! * @param props properties
! * @param defaultMinimized default minimization state <code>true</code>
! * for minimized windows, <code>false</code> for others
! * @param defaultX default x coordinate
! * @param defaultY default y coordinate
! * @param defaultVisible default visibility state <code>true</code> for
! * visible windows, <code>false</code> for others
*/
private void readFromProperties(final Properties props,
***************
*** 312,319 ****
/**
! * reads the config from the properties.
*
! * @param props
! * @param defaults
*/
private void readFromProperties(final Properties props, final ManagedWindow defaults) {
--- 346,353 ----
/**
! * Read window configuration from properties.
*
! * @param props properties
! * @param defaults default properties
*/
private void readFromProperties(final Properties props, final ManagedWindow defaults) {
***************
*** 321,326 ****
defaults.getY(), defaults.isVisible());
}
-
}
-
}
--- 355,358 ----
|