001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.beaninfo;
043:
044: import java.awt.Image;
045: import java.beans.*;
046:
047: import org.openide.loaders.DataLoader;
048: import org.openide.loaders.UniFileLoader;
049: import org.openide.loaders.MultiFileLoader;
050: import org.openide.util.Exceptions;
051: import org.openide.util.Utilities;
052: import org.openide.util.NbBundle;
053:
054: public class DataLoaderPool {
055:
056: /** Create read-only 'extensions' property. Method used in [Folder|Instance]LoaderBeanInfo.
057: */
058: private static PropertyDescriptor[] createExtensionsPropertyDescriptor() {
059: try {
060: PropertyDescriptor extensions = new PropertyDescriptor(
061: "extensions", UniFileLoader.class); // NOI18N
062: extensions.setDisplayName(NbBundle.getBundle(
063: DataLoaderPool.class).getString(
064: "PROP_UniFileLoader_extensions"));
065: extensions.setShortDescription(NbBundle.getBundle(
066: DataLoaderPool.class).getString(
067: "HINT_UniFileLoader_extensions"));
068: extensions.setWriteMethod(null);
069: return new PropertyDescriptor[] { extensions };
070: } catch (IntrospectionException ie) {
071: Exceptions.printStackTrace(ie);
072: return null;
073: }
074: }
075:
076: public static class FolderLoaderBeanInfo extends SimpleBeanInfo {
077:
078: public BeanInfo[] getAdditionalBeanInfo() {
079: try {
080: // FolderLoader bean info uses MultiFileLoader's bean info instead of
081: // UniFileLoader's one. That is why it is necessary to remove 'extensions'
082: // property (declared in UniFileLoaderBeanInfo).
083: // Currently this property is only addition to MultiFileLoader bean info
084: // provided by UniFileLoaderBeanInfo.
085: return new BeanInfo[] { Introspector
086: .getBeanInfo(MultiFileLoader.class) };
087: } catch (IntrospectionException ie) {
088: Exceptions.printStackTrace(ie);
089: return null;
090: }
091: }
092:
093: public PropertyDescriptor[] getPropertyDescriptors() {
094: return createExtensionsPropertyDescriptor();
095: }
096:
097: public Image getIcon(int type) {
098: if ((type == BeanInfo.ICON_COLOR_16x16)
099: || (type == BeanInfo.ICON_MONO_16x16)) {
100: return Utilities
101: .loadImage("org/openide/loaders/defaultFolder.gif"); // NOI18N
102: } else {
103: return Utilities
104: .loadImage("org/openide/loaders/defaultFolder32.gif"); // NOI18N
105: }
106: }
107: }
108:
109: public static class InstanceLoaderBeanInfo extends SimpleBeanInfo {
110:
111: public BeanInfo[] getAdditionalBeanInfo() {
112: try {
113: // InstanceLoader bean info uses MultiFileLoader's bean info instead of
114: // UniFileLoader's one. That is why it is necessary to change 'extensions'
115: // property from r/w (declared in UniFileLoaderBeanInfo) to r/o property.
116: // Currently this property is only addition to MultiFileLoader bean info
117: // provided by UniFileLoaderBeanInfo.
118: return new BeanInfo[] { Introspector
119: .getBeanInfo(MultiFileLoader.class) };
120: } catch (IntrospectionException ie) {
121: Exceptions.printStackTrace(ie);
122: return null;
123: }
124: }
125:
126: public PropertyDescriptor[] getPropertyDescriptors() {
127: return createExtensionsPropertyDescriptor();
128: }
129:
130: public Image getIcon(int type) {
131: if ((type == BeanInfo.ICON_COLOR_16x16)
132: || (type == BeanInfo.ICON_MONO_16x16)) {
133: return Utilities
134: .loadImage("org/netbeans/core/resources/action.gif"); // NOI18N
135: } else {
136: return Utilities
137: .loadImage("org/netbeans/core/resources/action32.gif"); // NOI18N
138: }
139: }
140:
141: }
142:
143: public static class DefaultLoaderBeanInfo extends SimpleBeanInfo {
144:
145: public BeanInfo[] getAdditionalBeanInfo() {
146: try {
147: return new BeanInfo[] { Introspector
148: .getBeanInfo(DataLoader.class) };
149: } catch (IntrospectionException ie) {
150: Exceptions.printStackTrace(ie);
151: return null;
152: }
153: }
154:
155: public Image getIcon(int type) {
156: if ((type == BeanInfo.ICON_COLOR_16x16)
157: || (type == BeanInfo.ICON_MONO_16x16)) {
158: return Utilities
159: .loadImage("org/openide/resources/pending.gif"); // NOI18N
160: } else {
161: return Utilities
162: .loadImage("org/openide/resources/pending32.gif"); // NOI18N
163: }
164: }
165:
166: }
167:
168: public static class ShadowLoaderBeanInfo extends SimpleBeanInfo {
169: public BeanInfo[] getAdditionalBeanInfo() {
170: try {
171: return new BeanInfo[] { Introspector
172: .getBeanInfo(DataLoader.class) };
173: } catch (IntrospectionException ie) {
174: Exceptions.printStackTrace(ie);
175: return null;
176: }
177: }
178:
179: public PropertyDescriptor[] getPropertyDescriptors() {
180: try {
181: // Hide the actions property from users, since shadows inherit actions anyway:
182: Class c = Class
183: .forName("org.openide.loaders.DataLoaderPool$ShadowLoader"); // NOI18N
184: PropertyDescriptor actions = new PropertyDescriptor(
185: "actions", c); // NOI18N
186: actions.setHidden(true);
187: return new PropertyDescriptor[] { actions };
188: } catch (ClassNotFoundException ie) {
189: Exceptions.printStackTrace(ie);
190: return null;
191: } catch (IntrospectionException ie) {
192: Exceptions.printStackTrace(ie);
193: return null;
194: }
195: }
196:
197: public Image getIcon(int type) {
198: if ((type == BeanInfo.ICON_COLOR_16x16)
199: || (type == BeanInfo.ICON_MONO_16x16)) {
200: return Utilities
201: .loadImage("org/openide/resources/actions/copy.gif"); // NOI18N
202: } else {
203: // [PENDING]
204: //return Utilities.loadImage ("org/openide/resources/actions/copy32.gif"); // NOI18N
205: return null;
206: }
207: }
208:
209: }
210:
211: }
|