001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.util;
034:
035: import java.io.Serializable;
036: import java.util.HashMap;
037: import java.util.Map;
038:
039: /**
040: * String-to-Object map that anyone can use.
041: * For example, the Options dialog has a single instance, and
042: * it's stored on the Workbench Blackboard.
043: */
044: public class Blackboard implements Cloneable, Serializable {
045: private static final long serialVersionUID = 6504993615735124204L;
046: private HashMap properties = new HashMap();
047:
048: /**
049: * Used by Java2XML
050: */
051: public HashMap getProperties() {
052: return properties;
053: }
054:
055: /**
056: * Used by Java2XML
057: */
058: public void setProperties(HashMap properties) {
059: this .properties = properties;
060: }
061:
062: public Blackboard put(String key, Object value) {
063: properties.put(key, value);
064: return this ;
065: }
066:
067: public Object get(String key) {
068: return properties.get(key);
069: }
070:
071: public Blackboard put(String key, boolean value) {
072: put(key, new Boolean(value));
073: return this ;
074: }
075:
076: public Blackboard putAll(Map properties) {
077: this .properties.putAll(properties);
078: return this ;
079: }
080:
081: public boolean get(String key, boolean defaultValue) {
082: if (get(key) == null) {
083: put(key, defaultValue);
084: }
085:
086: return getBoolean(key);
087: }
088:
089: public boolean getBoolean(String key) {
090: return ((Boolean) get(key)).booleanValue();
091: }
092:
093: public Blackboard put(String key, int value) {
094: put(key, new Integer(value));
095: return this ;
096: }
097:
098: public Blackboard put(String key, double value) {
099: put(key, new Double(value));
100: return this ;
101: }
102:
103: public double get(String key, double defaultValue) {
104: if (get(key) == null) {
105: put(key, defaultValue);
106: }
107:
108: return getDouble(key);
109: }
110:
111: public int get(String key, int defaultValue) {
112: if (get(key) == null) {
113: put(key, defaultValue);
114: }
115:
116: return getInt(key);
117: }
118:
119: public int getInt(String key) {
120: return ((Integer) get(key)).intValue();
121: }
122:
123: public double getDouble(String key) {
124: return ((Double) get(key)).doubleValue();
125: }
126:
127: public Object get(String key, Object defaultValue) {
128: if (get(key) == null) {
129: put(key, defaultValue);
130: }
131:
132: return get(key);
133: }
134:
135: public Object clone() {
136: return new Blackboard().putAll(properties);
137: }
138: }
|