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.components;
015:
016: import org.jetbrains.annotations.NonNls;
017: import org.jetbrains.annotations.NotNull;
018: import org.jetbrains.annotations.Nullable;
019: import org.pentaho.reportdesigner.lib.client.commands.CommandToolBar;
020:
021: import javax.swing.*;
022: import java.beans.PropertyChangeListener;
023: import java.beans.PropertyChangeSupport;
024:
025: /**
026: * User: Martin
027: * Date: 11.03.2005
028: * Time: 10:11:41
029: */
030: public class Category<T extends JComponent> {
031: @NotNull
032: private Object key;
033: @Nullable
034: private ImageIcon iconBig;
035: @Nullable
036: private ImageIcon iconSmall;
037: @NotNull
038: private String title;
039: @NotNull
040: private JComponent[] actionComponents;
041: @Nullable
042: private T mainComponent;
043:
044: private long lastAccessedMillis;
045:
046: @NotNull
047: private PropertyChangeSupport propertyChangeSupport;
048:
049: @Nullable
050: private JToolBar jToolBar;
051:
052: @Nullable
053: @SuppressWarnings({"UnusedDeclaration"})
054: private CommandToolBar commandToolBar;
055: @NotNull
056: private static final JComponent[] EMPTY_JCOMPONENT_ARRAY = new JComponent[0];
057:
058: public Category(@NotNull
059: @NonNls
060: Object key, @Nullable
061: ImageIcon iconBig, @Nullable
062: ImageIcon iconSmall, @NotNull
063: String title, @Nullable
064: T mainComponent) {
065: //noinspection ConstantConditions
066: if (key == null) {
067: throw new IllegalArgumentException("key must not be null");
068: }
069:
070: this .key = key;
071: this .iconBig = iconBig;
072: this .iconSmall = iconSmall;
073: this .title = title;
074: this .actionComponents = EMPTY_JCOMPONENT_ARRAY;
075: this .mainComponent = mainComponent;
076:
077: propertyChangeSupport = new PropertyChangeSupport(this );
078: }
079:
080: @NotNull
081: public Object getKey() {
082: return key;
083: }
084:
085: @Nullable
086: public ImageIcon getIconBig() {
087: return iconBig;
088: }
089:
090: public void setIconBig(@Nullable
091: ImageIcon iconBig) {
092: ImageIcon oldIconBig = this .iconBig;
093: this .iconBig = iconBig;
094:
095: propertyChangeSupport.firePropertyChange("iconBig", oldIconBig,
096: iconBig);//NON-NLS
097: }
098:
099: @Nullable
100: public ImageIcon getIconSmall() {
101: return iconSmall;
102: }
103:
104: public void setIconSmall(@Nullable
105: ImageIcon iconSmall) {
106: ImageIcon oldIconSmall = this .iconSmall;
107: this .iconSmall = iconSmall;
108:
109: propertyChangeSupport.firePropertyChange("iconSmall",
110: oldIconSmall, iconSmall);//NON-NLS
111: }
112:
113: @NotNull
114: public String getTitle() {
115: return title;
116: }
117:
118: public void setTitle(@NotNull
119: String title) {
120: String oldTitle = this .title;
121: this .title = title;
122:
123: propertyChangeSupport.firePropertyChange("title", oldTitle,
124: title);//NON-NLS
125: }
126:
127: @NotNull
128: public JComponent[] getActionComponents() {
129: return actionComponents;
130: }
131:
132: public void setActionComponents(@NotNull
133: JComponent[] actionComponents) {
134: JComponent[] oldActionComponents = this .actionComponents;
135: this .actionComponents = actionComponents;
136:
137: propertyChangeSupport.firePropertyChange("actionComponents",
138: oldActionComponents, actionComponents);//NON-NLS
139: }
140:
141: @Nullable
142: public JToolBar getToolBar() {
143: return jToolBar;
144: }
145:
146: public void setToolBar(@NotNull
147: JToolBar jToolBar) {
148: JToolBar oldToolBar = this .jToolBar;
149: this .jToolBar = jToolBar;
150:
151: propertyChangeSupport.firePropertyChange("toolBar", oldToolBar,
152: jToolBar);//NON-NLS
153: }
154:
155: public void setToolBar(@NotNull
156: CommandToolBar commandToolBar) {
157: this .commandToolBar = commandToolBar;
158: JToolBar oldToolBar = this .jToolBar;
159: this .jToolBar = commandToolBar.getToolBar();
160:
161: propertyChangeSupport.firePropertyChange("toolBar", oldToolBar,
162: jToolBar);//NON-NLS
163: }
164:
165: @Nullable
166: public T getMainComponent() {
167: return mainComponent;
168: }
169:
170: public void setMainComponent(@Nullable
171: T mainComponent) {
172: JComponent oldMainComponent = this .mainComponent;
173: this .mainComponent = mainComponent;
174:
175: propertyChangeSupport.firePropertyChange("mainComponent",
176: oldMainComponent, mainComponent);//NON-NLS
177: }
178:
179: public long getLastAccessedMillis() {
180: return lastAccessedMillis;
181: }
182:
183: public void setLastAccessedMillis(long lastAccessedMillis) {
184: long oldLastAccessedMillis = this .lastAccessedMillis;
185: this .lastAccessedMillis = lastAccessedMillis;
186:
187: propertyChangeSupport.firePropertyChange("lastAccessedMillis",
188: Long.valueOf(oldLastAccessedMillis), Long
189: .valueOf(lastAccessedMillis));//NON-NLS
190: }
191:
192: public void addPropertyChangeListener(@NotNull
193: PropertyChangeListener listener) {
194: propertyChangeSupport.addPropertyChangeListener(listener);
195: }
196:
197: public void removePropertyChangeListener(@NotNull
198: PropertyChangeListener listener) {
199: propertyChangeSupport.removePropertyChangeListener(listener);
200: }
201:
202: @NotNull
203: public PropertyChangeListener[] getPropertyChangeListeners() {
204: return propertyChangeSupport.getPropertyChangeListeners();
205: }
206:
207: public void addPropertyChangeListener(@NotNull
208: String propertyName, @NotNull
209: PropertyChangeListener listener) {
210: propertyChangeSupport.addPropertyChangeListener(propertyName,
211: listener);
212: }
213:
214: public void removePropertyChangeListener(@NotNull
215: String propertyName, @NotNull
216: PropertyChangeListener listener) {
217: propertyChangeSupport.removePropertyChangeListener(
218: propertyName, listener);
219: }
220:
221: @NotNull
222: public PropertyChangeListener[] getPropertyChangeListeners(@NotNull
223: String propertyName) {
224: return propertyChangeSupport
225: .getPropertyChangeListeners(propertyName);
226: }
227:
228: public boolean equals(@Nullable
229: Object o) {
230: if (this == o)
231: return true;
232: if (!(o instanceof Category))
233: return false;
234:
235: final Category<?> category = (Category<?>) o;
236:
237: return key.equals(category.key);
238: }
239:
240: public int hashCode() {
241: return (key.hashCode());
242: }
243:
244: @NotNull
245: public String toString() {
246: return "Category{" + "key=" + key + ", title='" + title + "'"
247: + ", mainComponent=" + mainComponent + "}";
248: }
249: }
|