KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > model > ShapeDrawComponentPropertySource


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 24.01.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.model;
9
10 import java.awt.Color JavaDoc;
11 import java.util.List JavaDoc;
12
13 import org.eclipse.ui.views.properties.PropertyDescriptor;
14
15 import com.nightlabs.editor2d.EditorPlugin;
16 import com.nightlabs.editor2d.ShapeDrawComponent;
17 import com.nightlabs.editor2d.properties.AWTColorPropertyDescriptor;
18 import com.nightlabs.editor2d.properties.CheckboxPropertyDescriptor;
19 import com.nightlabs.editor2d.properties.IntPropertyDescriptor;
20
21
22 public class ShapeDrawComponentPropertySource
23 extends DrawComponentPropertySource
24 {
25     public static final String JavaDoc CATEGORY_COLORS = EditorPlugin.getResourceString("property.category.color");
26     public static final String JavaDoc CATEGORY_LINE = EditorPlugin.getResourceString("property.category.line");
27     
28   /**
29    * @param element
30    */

31   public ShapeDrawComponentPropertySource(ShapeDrawComponent element)
32   {
33     super(element);
34   }
35     
36     protected List JavaDoc createPropertyDescriptors()
37     {
38         List JavaDoc descriptors = super.createPropertyDescriptors();
39         
40         // Line Color
41
PropertyDescriptor desc = new AWTColorPropertyDescriptor(ShapeDrawComponent.PROP_LINE_COLOR,
42                 EditorPlugin.getResourceString("property.linecolor.label"));
43         desc.setCategory(CATEGORY_COLORS);
44         descriptors.add(desc);
45         
46         // Fill Color
47
desc = new AWTColorPropertyDescriptor(ShapeDrawComponent.PROP_FILL_COLOR,
48                 EditorPlugin.getResourceString("property.fillcolor.label"));
49         desc.setCategory(CATEGORY_COLORS);
50         descriptors.add(desc);
51         
52         // Line Width
53
desc = new IntPropertyDescriptor(ShapeDrawComponent.PROP_LINE_WIDTH,
54                 EditorPlugin.getResourceString("property.linewidth.label"));
55         desc.setCategory(CATEGORY_LINE);
56         descriptors.add(desc);
57         
58         // Line Style
59
desc = new IntPropertyDescriptor(ShapeDrawComponent.PROP_LINE_STYLE,
60                 EditorPlugin.getResourceString("property.linestyle.label"));
61         desc.setCategory(CATEGORY_LINE);
62         descriptors.add(desc);
63         
64         // Fill
65
desc = new CheckboxPropertyDescriptor(ShapeDrawComponent.PROP_FILL,
66                 EditorPlugin.getResourceString("property.fill.label"));
67         descriptors.add(desc);
68         
69         return descriptors;
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
74      */

75 // public IPropertyDescriptor[] getPropertyDescriptors()
76
// {
77
// Iterator it;
78
// EClass cls = element.eClass();
79
// Collection descriptors = new ArrayList();
80
//
81
// it = cls.getEAllAttributes().iterator();
82
// while( it.hasNext() )
83
// {
84
// EAttribute attr = (EAttribute)it.next();
85
// EDataType type = attr.getEAttributeType();
86
//
87
// if( attr.isID() ) {
88
// // TODO: ID shouldn't be editable
89
// }
90
// else if( type.getInstanceClass() == String.class ) {
91
// descriptors.add( new TextPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
92
// attr.getName() ) );
93
// }
94
// else if( type.getInstanceClass() == boolean.class )
95
// {
96
// descriptors.add( new CheckboxPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
97
// attr.getName() ) );
98
// }
99
// else if( type.getInstanceClass() == int.class )
100
// {
101
// descriptors.add( new IntPropertyDescriptor( Integer.toString( attr.getFeatureID() ),
102
// attr.getName() ) );
103
// }
104
// else if (type.getInstanceClass() == Color.class )
105
// {
106
// descriptors.add(new AWTColorPropertyDescriptor(Integer.toString(attr.getFeatureID()),
107
// attr.getName()));
108
// }
109
// }
110
//
111
// return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} );
112
// }
113

114     /* (non-Javadoc)
115      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
116      */

117     public Object JavaDoc getPropertyValue(Object JavaDoc id)
118     {
119         Object JavaDoc o = super.getPropertyValue(id);
120         if (o != null)
121             return o;
122         else
123         {
124             if (id.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
125                 return getShapeDrawComponent().getFillColor();
126             }
127             else if (id.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
128                 return getShapeDrawComponent().getLineColor();
129             }
130             else if (id.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
131                 return new Integer JavaDoc(getShapeDrawComponent().getLineWidth());
132             }
133             else if (id.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
134                 return new Integer JavaDoc(getShapeDrawComponent().getLineStyle());
135             }
136             else if (id.equals(ShapeDrawComponent.PROP_FILL)) {
137                 return new Boolean JavaDoc(getShapeDrawComponent().isFill());
138             }
139             
140             return null;
141         }
142     }
143     
144     /* (non-Javadoc)
145      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
146      */

147     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
148     {
149         super.setPropertyValue(id, value);
150         
151         if (id.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
152             getShapeDrawComponent().setFillColor((Color JavaDoc)value);
153         }
154         else if (id.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
155             getShapeDrawComponent().setLineColor((Color JavaDoc)value);
156         }
157         else if (id.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
158             getShapeDrawComponent().setLineWidth(((Integer JavaDoc)value).intValue());
159         }
160         else if (id.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
161             getShapeDrawComponent().setLineStyle(((Integer JavaDoc)value).intValue());
162         }
163         else if (id.equals(ShapeDrawComponent.PROP_FILL)) {
164             getShapeDrawComponent().setFill(((Boolean JavaDoc)value).booleanValue());
165         }
166     }
167     
168     protected ShapeDrawComponent getShapeDrawComponent() {
169         return (ShapeDrawComponent) drawComponent;
170     }
171 }
172
Free Books   Free Magazines  
Popular Tags