KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > model > DrawComponentPropertySource


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.model;
29
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34
35 import org.eclipse.ui.views.properties.IPropertyDescriptor;
36 import org.eclipse.ui.views.properties.IPropertySource;
37 import org.eclipse.ui.views.properties.PropertyDescriptor;
38 import org.nightlabs.base.language.LanguageManager;
39 import org.nightlabs.base.property.IntPropertyDescriptor;
40 import org.nightlabs.editor2d.DrawComponent;
41 import org.nightlabs.editor2d.EditorPlugin;
42 import org.nightlabs.editor2d.properties.NamePropertyDescriptor;
43 import org.nightlabs.editor2d.properties.RotationPropertyDescriptor;
44 import org.nightlabs.language.LanguageCf;
45
46 public class DrawComponentPropertySource
47 implements IPropertySource
48 {
49     protected DrawComponent drawComponent;
50 // protected NameLanguageManager nameLangMan;
51
// public DrawComponentPropertySource(DrawComponent element) {
52
// this.drawComponent = element;
53
// descriptors = createPropertyDescriptors();
54
// nameLangMan = NameLanguageManager.sharedInstance();
55
// nameLangMan.addLanguageChangeListener(langListener);
56
// }
57

58 // protected LanguageChangeListener langListener = new LanguageChangeListener(){
59
// public void languageChanged(LanguageChangeEvent event) {
60
// String newLanguageID = event.getNewLanguage().getLanguageID();
61
// drawComponent.setLanguageId(newLanguageID);
62
// }
63
// };
64

65     protected LanguageManager nameLangMan;
66     public DrawComponentPropertySource(DrawComponent element) {
67         this.drawComponent = element;
68         descriptors = createPropertyDescriptors();
69         nameLangMan = LanguageManager.sharedInstance();
70         nameLangMan.addPropertyChangeListener(langListener);
71     }
72     
73     protected PropertyChangeListener JavaDoc langListener = new PropertyChangeListener JavaDoc()
74     {
75         public void propertyChange(PropertyChangeEvent JavaDoc evt)
76         {
77             if (evt.getPropertyName().equals(LanguageManager.LANGUAGE_CHANGED))
78             {
79                 LanguageCf langCf = (LanguageCf) evt.getNewValue();
80                 drawComponent.setLanguageId(langCf.getLanguageID());
81             }
82         }
83     };
84     
85     /* (non-Javadoc)
86      * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
87      */

88     public Object JavaDoc getEditableValue() {
89         return drawComponent;
90     }
91
92     public static final String JavaDoc CATEGORY_NAME = EditorPlugin.getResourceString("property.category.name");
93     public static final String JavaDoc CATEGORY_GEOM = EditorPlugin.getResourceString("property.category.geom");
94     public static final String JavaDoc CATEGORY_ROTATION = EditorPlugin.getResourceString("property.category.rotation");
95     
96     protected List JavaDoc descriptors = null;
97     protected List JavaDoc getDescriptors() {
98         if (descriptors == null)
99             descriptors = new ArrayList JavaDoc();
100         return descriptors;
101     }
102         
103     protected List JavaDoc createPropertyDescriptors()
104     {
105         List JavaDoc descriptors = getDescriptors();
106         
107 // // Name
108
// PropertyDescriptor desc = new TextPropertyDescriptor(DrawComponent.PROP_NAME,
109
// EditorPlugin.getResourceString("property.name.label"));
110
// desc.setCategory(CATEGORY_NAME);
111
// descriptors.add(desc);
112
// // Name
113
// PropertyDescriptor desc = new LanguagePropertyDescriptor(
114
// drawComponent.getI18nText(),
115
// DrawComponent.PROP_NAME,
116
// EditorPlugin.getResourceString("property.name.label"));
117
// Name
118
PropertyDescriptor desc = new NamePropertyDescriptor(drawComponent,
119                 DrawComponent.PROP_NAME,
120                 EditorPlugin.getResourceString("property.name.label"));
121         desc.setCategory(CATEGORY_NAME);
122         descriptors.add(desc);
123         
124         // X
125
desc = new IntPropertyDescriptor(DrawComponent.PROP_X,
126                 EditorPlugin.getResourceString("property.x.label"));
127         desc.setCategory(CATEGORY_GEOM);
128         descriptors.add(desc);
129         
130         // Y
131
desc = new IntPropertyDescriptor(DrawComponent.PROP_Y,
132                 EditorPlugin.getResourceString("property.y.label"));
133         desc.setCategory(CATEGORY_GEOM);
134         descriptors.add(desc);
135         
136         // Width
137
desc = new IntPropertyDescriptor(DrawComponent.PROP_WIDTH,
138                 EditorPlugin.getResourceString("property.width.label"));
139         desc.setCategory(CATEGORY_GEOM);
140         descriptors.add(desc);
141         
142         // Height
143
desc = new IntPropertyDescriptor(DrawComponent.PROP_HEIGHT,
144                 EditorPlugin.getResourceString("property.height.label"));
145         desc.setCategory(CATEGORY_GEOM);
146         descriptors.add(desc);
147         
148         // Rotation
149
desc = new RotationPropertyDescriptor(DrawComponent.PROP_ROTATION,
150                 EditorPlugin.getResourceString("property.rotation.label"));
151         desc.setCategory(CATEGORY_ROTATION);
152         descriptors.add(desc);
153         
154         // RotationX
155
desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_X,
156                 EditorPlugin.getResourceString("property.rotationx.label"));
157         desc.setCategory(CATEGORY_ROTATION);
158         descriptors.add(desc);
159         
160         // RotationY
161
desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_Y,
162                 EditorPlugin.getResourceString("property.rotationy.label"));
163         desc.setCategory(CATEGORY_ROTATION);
164         descriptors.add(desc);
165         
166         return descriptors;
167     }
168     
169     public IPropertyDescriptor[] getPropertyDescriptors()
170     {
171         if (drawComponent == null)
172             return new IPropertyDescriptor[0];
173         
174         List JavaDoc descriptors = getDescriptors();
175         return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} );
176     }
177     
178     /* (non-Javadoc)
179      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
180      */

181     public Object JavaDoc getPropertyValue(Object JavaDoc id)
182     {
183         if (id.equals(DrawComponent.PROP_X)) {
184             return new Integer JavaDoc(drawComponent.getX());
185         }
186         else if (id.equals(DrawComponent.PROP_Y)) {
187             return new Integer JavaDoc(drawComponent.getY());
188         }
189         else if (id.equals(DrawComponent.PROP_WIDTH)) {
190             return new Integer JavaDoc(drawComponent.getWidth());
191         }
192         else if (id.equals(DrawComponent.PROP_HEIGHT)) {
193             return new Integer JavaDoc(drawComponent.getHeight());
194         }
195         else if (id.equals(DrawComponent.PROP_ROTATION)) {
196             return new Double JavaDoc(drawComponent.getRotation());
197         }
198         else if (id.equals(DrawComponent.PROP_ROTATION_X)) {
199             return new Integer JavaDoc(drawComponent.getRotationX());
200         }
201         else if (id.equals(DrawComponent.PROP_ROTATION_Y)) {
202             return new Integer JavaDoc(drawComponent.getRotationY());
203         }
204         else if (id.equals(DrawComponent.PROP_NAME)) {
205             return drawComponent.getI18nText().getText(nameLangMan.getCurrentLanguageID());
206         }
207                         
208         return null;
209     }
210     
211     /* (non-Javadoc)
212      * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
213      */

214     public boolean isPropertySet(Object JavaDoc id) {
215         // TODO Auto-generated method stub
216
return false;
217     }
218
219     /*
220      * @see org.eclipse.ui.views.properties.IPropertySouce#resetPropertyValue(java.lang.Object)
221      */

222     public void resetPropertyValue(Object JavaDoc id) {
223         // TODO Auto-generated method stub
224
}
225
226     /* (non-Javadoc)
227      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
228      */

229     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
230     {
231         if (id.equals(DrawComponent.PROP_X)) {
232             drawComponent.setX(((Integer JavaDoc)value).intValue());
233         }
234         else if (id.equals(DrawComponent.PROP_Y)) {
235             drawComponent.setY(((Integer JavaDoc)value).intValue());
236         }
237         else if (id.equals(DrawComponent.PROP_WIDTH)) {
238             drawComponent.setWidth(((Integer JavaDoc)value).intValue());
239         }
240         else if (id.equals(DrawComponent.PROP_HEIGHT)) {
241             drawComponent.setHeight(((Integer JavaDoc)value).intValue());
242         }
243         else if (id.equals(DrawComponent.PROP_ROTATION)) {
244             drawComponent.setRotation(((Double JavaDoc)value).doubleValue());
245         }
246         else if (id.equals(DrawComponent.PROP_ROTATION_X)) {
247             drawComponent.setRotationX(((Integer JavaDoc)value).intValue());
248         }
249         else if (id.equals(DrawComponent.PROP_ROTATION_Y)) {
250             drawComponent.setRotationY(((Integer JavaDoc)value).intValue());
251         }
252         else if (id.equals(DrawComponent.PROP_NAME)) {
253             drawComponent.setName((String JavaDoc)value);
254         }
255     }
256             
257 }
258
259
Popular Tags