Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / vividsolutions / jump / util / Blackboard.java @ 312

History | View | Annotate | Download (3.35 KB)

1
/*
2
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
3
 * for visualizing and manipulating spatial features with geometry and attributes.
4
 *
5
 * Copyright (C) 2003 Vivid Solutions
6
 * 
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * 
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 * 
21
 * For more information, contact:
22
 *
23
 * Vivid Solutions
24
 * Suite #1A
25
 * 2328 Government Street
26
 * Victoria BC  V8T 5G5
27
 * Canada
28
 *
29
 * (250)385-6040
30
 * www.vividsolutions.com
31
 */
32

    
33
package com.vividsolutions.jump.util;
34

    
35
import java.util.HashMap;
36
import java.util.Map;
37
/**
38
* String-to-Object map that anyone can use.
39
* For example, the Options dialog has a single instance, and
40
* it's stored on the Workbench Blackboard.
41
*/
42
public class Blackboard implements Cloneable {
43
    private HashMap properties = new HashMap();
44

    
45
    /**
46
     * Used by Java2XML
47
     */
48
    public HashMap getProperties() {
49
        return properties;
50
    }
51

    
52
    /**
53
     * Used by Java2XML
54
     */
55
    public void setProperties(HashMap properties) {
56
        this.properties = properties;
57
    }
58

    
59
    public Blackboard put(String key, Object value) {
60
        properties.put(key, value);
61
        return this;
62
    }
63

    
64
    public Object get(String key) {
65
        return properties.get(key);
66
    }
67

    
68
    public Blackboard put(String key, boolean value) {
69
        put(key, new Boolean(value));
70
        return this;
71
    }
72
    public Blackboard putAll(Map properties) {
73
        this.properties.putAll(properties);
74
        return this;
75
    }
76

    
77
    public boolean get(String key, boolean defaultValue) {
78
        if (get(key) == null) {
79
            put(key, defaultValue);
80
        }
81

    
82
        return getBoolean(key);
83
    }
84

    
85
    public boolean getBoolean(String key) {
86
        return ((Boolean) get(key)).booleanValue();
87
    }
88

    
89
    public Blackboard put(String key, int value) {
90
        put(key, new Integer(value));
91
        return this;
92
    }
93

    
94
    public Blackboard put(String key, double value) {
95
        put(key, new Double(value));
96
        return this;
97
    }
98

    
99
    public double get(String key, double defaultValue) {
100
        if (get(key) == null) {
101
            put(key, defaultValue);
102
        }
103

    
104
        return getDouble(key);
105
    }
106

    
107
    public int get(String key, int defaultValue) {
108
        if (get(key) == null) {
109
            put(key, defaultValue);
110
        }
111

    
112
        return getInt(key);
113
    }
114

    
115
    public int getInt(String key) {
116
        return ((Integer) get(key)).intValue();
117
    }
118

    
119
    public double getDouble(String key) {
120
        return ((Double) get(key)).doubleValue();
121
    }
122

    
123
    public Object get(String key, Object defaultValue) {
124
        if (get(key) == null) {
125
            put(key, defaultValue);
126
        }
127

    
128
        return get(key);
129
    }
130
    
131
    public Object clone() {
132
        return new Blackboard().putAll(properties);
133
    }
134
}