KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > dd > impl > common > ComponentBeanSingle


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * Superclass that implements DisplayNameInterface and IconInterface for Servlet2.3 beans.
22  *
23  * @author Milan Kuchtiak
24  */

25 package org.netbeans.modules.web.dd.impl.common;
26
27 import org.netbeans.modules.schema2beans.BaseBean;
28 import org.netbeans.modules.schema2beans.Version;
29 import org.netbeans.api.web.dd.common.*;
30 import org.netbeans.api.web.dd.WebApp;
31
32 public abstract class ComponentBeanSingle extends DescriptionBeanSingle implements DisplayNameInterface, IconInterface {
33
34     public ComponentBeanSingle(java.util.Vector JavaDoc comps, Version version) {
35     super(comps, version);
36     }
37     
38     // methods implemented in specific BaseBeans e.g. Servlet
39
public org.netbeans.api.web.dd.Icon getIcon(){return null;}
40     public void setIcon(org.netbeans.api.web.dd.Icon icon){}
41     public abstract String JavaDoc getDisplayName();
42     public abstract void setDisplayName(String JavaDoc displayName);
43     
44     
45     public void setDisplayName(String JavaDoc locale, String JavaDoc displayName) throws VersionNotSupportedException {
46         if (locale==null) setDisplayName(displayName);
47         else throw new VersionNotSupportedException("2.3"); // NOI18N
48
}
49     
50     public void setAllDisplayNames(java.util.Map JavaDoc displayNames) throws VersionNotSupportedException {
51         throw new VersionNotSupportedException("2.3"); // NOI18N
52
}
53     
54     public String JavaDoc getDisplayName(String JavaDoc locale) throws VersionNotSupportedException {
55         if (locale==null) return getDisplayName();
56         else throw new VersionNotSupportedException("2.3"); // NOI18N
57
}
58     public String JavaDoc getDefaultDisplayName() {
59         return getDisplayName();
60     }
61     public java.util.Map JavaDoc getAllDisplayNames() {
62         java.util.Map JavaDoc map = new java.util.HashMap JavaDoc();
63         map.put(null, getDisplayName());
64         return map;
65     }
66     
67     public void removeDisplayNameForLocale(String JavaDoc locale) throws VersionNotSupportedException {
68         if (locale==null) setDisplayName(null);
69         else throw new VersionNotSupportedException("2.3"); // NOI18N
70
}
71     public void removeDisplayName() {
72         setDisplayName(null);
73     }
74     public void removeAllDisplayNames() {
75         setDisplayName(null);
76     }
77
78     // setters
79
public void setSmallIcon(String JavaDoc locale, String JavaDoc icon) throws VersionNotSupportedException {
80         if (locale==null) setSmallIcon(icon);
81         else throw new VersionNotSupportedException("2.3"); // NOI18N
82
}
83     public void setSmallIcon(String JavaDoc icon) {
84         setIcon(icon, true);
85     }
86     public void setLargeIcon(String JavaDoc locale, String JavaDoc icon) throws VersionNotSupportedException {
87         if (locale==null) setLargeIcon(icon);
88         else throw new VersionNotSupportedException("2.3"); // NOI18N
89
}
90     public void setLargeIcon(String JavaDoc icon) {
91         setIcon(icon, false);
92     }
93     public void setAllIcons(String JavaDoc[] locales, String JavaDoc[] smallIcons, String JavaDoc[] largeIcons) throws VersionNotSupportedException {
94         throw new VersionNotSupportedException("2.3"); // NOI18N
95
}
96     // getters
97
public String JavaDoc getSmallIcon(String JavaDoc locale) throws VersionNotSupportedException {
98         if (locale==null) return getSmallIcon();
99         else throw new VersionNotSupportedException("2.3"); // NOI18N
100
}
101     public String JavaDoc getSmallIcon() {
102         org.netbeans.api.web.dd.Icon icon = getIcon();
103         if (icon==null) return null;
104         else return icon.getSmallIcon();
105     }
106     public String JavaDoc getLargeIcon(String JavaDoc locale) throws VersionNotSupportedException {
107         if (locale==null) return getLargeIcon();
108         else throw new VersionNotSupportedException("2.3"); // NOI18N
109
}
110     public String JavaDoc getLargeIcon() {
111         org.netbeans.api.web.dd.Icon icon = getIcon();
112         if (icon==null) return null;
113         else return icon.getLargeIcon();
114     }
115     public org.netbeans.api.web.dd.Icon getDefaultIcon() {
116         return getIcon();
117     }
118     public java.util.Map JavaDoc getAllIcons() {
119         java.util.Map JavaDoc map = new java.util.HashMap JavaDoc();
120         org.netbeans.api.web.dd.Icon icon = getIcon();
121         if (icon!=null) {
122             String JavaDoc[] icons = new String JavaDoc[]{icon.getSmallIcon(),icon.getLargeIcon()};
123             map.put(null, icons);
124         }
125         return map;
126     }
127     // removers
128
public void removeSmallIcon(String JavaDoc locale) throws VersionNotSupportedException {
129         if (locale==null) removeSmallIcon();
130         else throw new VersionNotSupportedException("2.3"); // NOI18N
131
}
132     public void removeLargeIcon(String JavaDoc locale) throws VersionNotSupportedException {
133         if (locale==null) removeLargeIcon();
134         else throw new VersionNotSupportedException("2.3"); // NOI18N
135
}
136     public void removeIcon(String JavaDoc locale) throws VersionNotSupportedException {
137         if (locale==null) removeIcon();
138         else throw new VersionNotSupportedException("2.3"); // NOI18N
139
}
140     public void removeSmallIcon() {
141         org.netbeans.api.web.dd.Icon icon = getIcon();
142         if (icon!=null) {
143             icon.setSmallIcon(null);
144             if (icon.getLargeIcon()==null) setIcon(null);
145         }
146     }
147     public void removeLargeIcon() {
148         org.netbeans.api.web.dd.Icon icon = getIcon();
149         if (icon!=null) {
150             icon.setLargeIcon(null);
151             if (icon.getSmallIcon()==null) setIcon(null);
152         }
153     }
154     public void removeIcon() {
155         setIcon(null);
156     }
157     public void removeAllIcons() {
158         setIcon(null);
159     }
160     // universal method for setting icon
161
private void setIcon(String JavaDoc icon, boolean isSmall) {
162         org.netbeans.api.web.dd.Icon oldIcon = getIcon();
163         if (oldIcon==null) {
164             if (icon!=null) {
165                 try {
166                     org.netbeans.api.web.dd.Icon newIcon = (org.netbeans.api.web.dd.Icon) createBean("Icon");
167                     if (isSmall) newIcon.setSmallIcon(icon);
168                     else newIcon.setLargeIcon(icon);
169                     setIcon(newIcon);
170                 } catch(ClassNotFoundException JavaDoc ex){}
171             }
172         } else {
173             if (icon==null) {
174                 if (isSmall) {
175                     oldIcon.setSmallIcon(null);
176                     if (oldIcon.getLargeIcon()==null) setIcon(null);
177                 } else {
178                     oldIcon.setLargeIcon(null);
179                     if (oldIcon.getSmallIcon()==null) setIcon(null);
180                 }
181             } else {
182                 if (isSmall) oldIcon.setSmallIcon(icon);
183                 else oldIcon.setLargeIcon(icon);
184             }
185         }
186     }
187 }
188
Popular Tags