001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.lib.client.commands;
015:
016: import org.jetbrains.annotations.NotNull;
017: import org.jetbrains.annotations.Nullable;
018:
019: import javax.swing.*;
020: import java.beans.PropertyChangeEvent;
021: import java.beans.PropertyChangeListener;
022: import java.util.ArrayList;
023: import java.util.HashMap;
024:
025: /**
026: * User: Martin
027: * Date: 19.11.2004
028: * Time: 13:56:43
029: */
030: public class Presentation {
031: @NotNull
032: private ArrayList<PropertyChangeListener> propertyChangeListeners;
033:
034: @NotNull
035: private String text;
036: @NotNull
037: private String description;
038: @NotNull
039: private HashMap<String, ImageIcon> icons;
040: private boolean enabled;
041: private boolean visible;
042:
043: @NotNull
044: private CommandApplicationRoot commandApplicationRoot;
045:
046: @NotNull
047: private Command command;
048:
049: @NotNull
050: private HashMap<String, Object> clientPropertiesMap;
051:
052: @Nullable
053: private KeyStroke accelerator;
054: private int mnemonic;
055: private int displayedMnemonicIndex;
056:
057: public Presentation(@NotNull
058: Command command, @NotNull
059: String text, @NotNull
060: String description, boolean enabled, boolean visible, @Nullable
061: KeyStroke accelerator, int mnemonic, int displayedMnemonicIndex) {
062: this .command = command;
063: this .text = text;
064: this .description = description;
065: this .enabled = enabled;
066: this .visible = visible;
067: this .accelerator = accelerator;
068: this .mnemonic = mnemonic;
069: this .displayedMnemonicIndex = displayedMnemonicIndex;
070:
071: propertyChangeListeners = new ArrayList<PropertyChangeListener>();
072: icons = new HashMap<String, ImageIcon>();
073:
074: clientPropertiesMap = new HashMap<String, Object>();
075: }
076:
077: @NotNull
078: public Command getCommand() {
079: return command;
080: }
081:
082: public void addPropertyChangeListener(@NotNull
083: PropertyChangeListener propertyChangeListener) {
084: if (!propertyChangeListeners.contains(propertyChangeListener)) {
085: propertyChangeListeners.add(propertyChangeListener);
086: }
087: }
088:
089: private void notifyPropertyChangeListeners(@NotNull
090: String propertyName, @Nullable
091: Object oldValue, @Nullable
092: Object newValue) {
093: ArrayList<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>(
094: propertyChangeListeners);
095: for (PropertyChangeListener propertyChangeListener : listeners) {
096: propertyChangeListener
097: .propertyChange(new PropertyChangeEvent(this ,
098: propertyName, oldValue, newValue));
099: }
100: }
101:
102: @NotNull
103: public CommandApplicationRoot getCommandApplicationRoot() {
104: return commandApplicationRoot;
105: }
106:
107: public void setCommandApplicationRoot(@NotNull
108: CommandApplicationRoot commandApplicationRoot) {
109: this .commandApplicationRoot = commandApplicationRoot;
110: }
111:
112: @NotNull
113: public String getText() {
114: return text;
115: }
116:
117: public void setText(@NotNull
118: String text) {
119: String oldText = this .text;
120: this .text = text;
121:
122: if (!oldText.equals(text)) {
123: notifyPropertyChangeListeners("text", oldText, text);//NON-NLS
124: }
125: }
126:
127: @NotNull
128: public String getDescription() {
129: return description;
130: }
131:
132: public void setDescription(@NotNull
133: String description) {
134: String oldDescription = this .description;
135: this .description = description;
136:
137: if (!oldDescription.equals(description)) {
138: notifyPropertyChangeListeners("description",
139: oldDescription, description);//NON-NLS
140: }
141: }
142:
143: @Nullable
144: public ImageIcon getIcon(@Nullable
145: String key) {
146: return icons.get(key);
147: }
148:
149: public void setIcon(@NotNull
150: String key, @NotNull
151: ImageIcon icon) {
152: Icon oldIcon = icons.get(key);
153: icons.put(key, icon);
154: notifyPropertyChangeListeners("icon", oldIcon, icon);//NON-NLS
155: }
156:
157: @NotNull
158: public HashMap<String, ImageIcon> getIcons() {
159: return new HashMap<String, ImageIcon>(icons);
160: }
161:
162: public void setIcons(@NotNull
163: HashMap<String, ImageIcon> newIcons) {
164: HashMap<String, ImageIcon> oldIcons = icons;
165: icons = new HashMap<String, ImageIcon>(newIcons);
166: notifyPropertyChangeListeners("icons", oldIcons, icons);//NON-NLS
167: }
168:
169: public void setClientProperty(@NotNull
170: String key, @NotNull
171: Object value) {
172: //noinspection ConstantConditions
173: if (key == null) {
174: throw new IllegalArgumentException("key must not be null");
175: }
176: //noinspection ConstantConditions
177: if (value == null) {
178: throw new IllegalArgumentException("value must not be null");
179: }
180:
181: Object oldValue = clientPropertiesMap.get(key);
182: clientPropertiesMap.put(key, value);
183:
184: if (!value.equals(oldValue)) {
185: notifyPropertyChangeListeners(key, oldValue, value);
186: }
187: }
188:
189: @NotNull
190: public Object getClientProperty(@NotNull
191: String key) {
192: //noinspection ConstantConditions
193: if (key == null) {
194: throw new IllegalArgumentException("key must not be null");
195: }
196: return clientPropertiesMap.get(key);
197: }
198:
199: public void clearClientProperty(@NotNull
200: String key) {
201: //noinspection ConstantConditions
202: if (key == null) {
203: throw new IllegalArgumentException("key must not be null");
204: }
205: Object value = clientPropertiesMap.remove(key);
206:
207: if (value != null) {
208: notifyPropertyChangeListeners(key, value, null);
209: }
210: }
211:
212: public boolean isEnabled() {
213: return enabled;
214: }
215:
216: public void setEnabled(boolean enabled) {
217: boolean oldEnabled = this .enabled;
218: this .enabled = enabled;
219:
220: if (oldEnabled != enabled) {
221: notifyPropertyChangeListeners("enabled", Boolean
222: .valueOf(oldEnabled), Boolean.valueOf(enabled));//NON-NLS
223: }
224: }
225:
226: public boolean isVisible() {
227: return visible;
228: }
229:
230: public void setVisible(boolean visible) {
231: boolean oldVisible = this .visible;
232: this .visible = visible;
233:
234: if (oldVisible != visible) {
235: notifyPropertyChangeListeners("visible", Boolean
236: .valueOf(oldVisible), Boolean.valueOf(visible));//NON-NLS
237: }
238: }
239:
240: public void fireStructureChanged() {
241: notifyPropertyChangeListeners("structure", null, null);//NON-NLS
242: }
243:
244: public void clearPropertyChangeListeners() {
245: propertyChangeListeners.clear();
246: }
247:
248: @Nullable
249: public JComponent getCustomComponent() {
250: return null;
251: }
252:
253: public void setAccelerator(@Nullable
254: KeyStroke accelerator) {
255: KeyStroke oldAccelerator = this .accelerator;
256:
257: this .accelerator = accelerator;
258:
259: notifyPropertyChangeListeners("accelerator", oldAccelerator,
260: accelerator);//NON-NLS
261: }
262:
263: public void setMnemonic(int mnemonic) {
264: int oldMnemonic = this .mnemonic;
265:
266: this .mnemonic = mnemonic;
267:
268: notifyPropertyChangeListeners("mnemonic", Integer
269: .valueOf(oldMnemonic), Integer.valueOf(mnemonic));//NON-NLS
270: }
271:
272: public void setDisplayedMnemonicIndex(int displayedMnemonicIndex) {
273: int oldDisplayedMnemonicIndex = this .displayedMnemonicIndex;
274:
275: this .displayedMnemonicIndex = displayedMnemonicIndex;
276:
277: notifyPropertyChangeListeners("displayedMnemonicIndex", Integer
278: .valueOf(oldDisplayedMnemonicIndex), Integer
279: .valueOf(displayedMnemonicIndex));//NON-NLS
280: }
281:
282: @Nullable
283: public KeyStroke getAccelerator() {
284: return accelerator;
285: }
286:
287: public int getMnemonic() {
288: return mnemonic;
289: }
290:
291: public int getDisplayedMnemonicIndex() {
292: return displayedMnemonicIndex;
293: }
294: }
|