KickJava   Java API By Example, From Geeks To Geeks.

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


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.awt.Color JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.eclipse.ui.views.properties.PropertyDescriptor;
34
35 import org.nightlabs.base.property.AWTColorPropertyDescriptor;
36 import org.nightlabs.base.property.CheckboxPropertyDescriptor;
37 import org.nightlabs.base.property.IntPropertyDescriptor;
38 import org.nightlabs.editor2d.EditorPlugin;
39 import org.nightlabs.editor2d.ShapeDrawComponent;
40
41
42 public class ShapeDrawComponentPropertySource
43 extends DrawComponentPropertySource
44 {
45     public static final String JavaDoc CATEGORY_COLORS = EditorPlugin.getResourceString("property.category.color");
46     public static final String JavaDoc CATEGORY_LINE = EditorPlugin.getResourceString("property.category.line");
47     
48   /**
49    * @param element
50    */

51   public ShapeDrawComponentPropertySource(ShapeDrawComponent element)
52   {
53     super(element);
54   }
55     
56     protected List JavaDoc createPropertyDescriptors()
57     {
58         List JavaDoc descriptors = super.createPropertyDescriptors();
59         
60         // Line Color
61
PropertyDescriptor desc = new AWTColorPropertyDescriptor(ShapeDrawComponent.PROP_LINE_COLOR,
62                 EditorPlugin.getResourceString("property.linecolor.label"));
63         desc.setCategory(CATEGORY_COLORS);
64         descriptors.add(desc);
65         
66         // Fill Color
67
desc = new AWTColorPropertyDescriptor(ShapeDrawComponent.PROP_FILL_COLOR,
68                 EditorPlugin.getResourceString("property.fillcolor.label"));
69         desc.setCategory(CATEGORY_COLORS);
70         descriptors.add(desc);
71         
72         // Line Width
73
desc = new IntPropertyDescriptor(ShapeDrawComponent.PROP_LINE_WIDTH,
74                 EditorPlugin.getResourceString("property.linewidth.label"));
75         desc.setCategory(CATEGORY_LINE);
76         descriptors.add(desc);
77         
78         // Line Style
79
desc = new IntPropertyDescriptor(ShapeDrawComponent.PROP_LINE_STYLE,
80                 EditorPlugin.getResourceString("property.linestyle.label"));
81         desc.setCategory(CATEGORY_LINE);
82         descriptors.add(desc);
83         
84         // Fill
85
desc = new CheckboxPropertyDescriptor(ShapeDrawComponent.PROP_FILL,
86                 EditorPlugin.getResourceString("property.fill.label"));
87         descriptors.add(desc);
88         
89         return descriptors;
90     }
91         
92     /* (non-Javadoc)
93      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
94      */

95     public Object JavaDoc getPropertyValue(Object JavaDoc id)
96     {
97         Object JavaDoc o = super.getPropertyValue(id);
98         if (o != null)
99             return o;
100         else
101         {
102             if (id.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
103                 return getShapeDrawComponent().getFillColor();
104             }
105             else if (id.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
106                 return getShapeDrawComponent().getLineColor();
107             }
108             else if (id.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
109                 return new Integer JavaDoc(getShapeDrawComponent().getLineWidth());
110             }
111             else if (id.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
112                 return new Integer JavaDoc(getShapeDrawComponent().getLineStyle());
113             }
114             else if (id.equals(ShapeDrawComponent.PROP_FILL)) {
115                 return new Boolean JavaDoc(getShapeDrawComponent().isFill());
116             }
117             
118             return null;
119         }
120     }
121     
122     /* (non-Javadoc)
123      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
124      */

125     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
126     {
127         super.setPropertyValue(id, value);
128         
129         if (id.equals(ShapeDrawComponent.PROP_FILL_COLOR)) {
130             getShapeDrawComponent().setFillColor((Color JavaDoc)value);
131         }
132         else if (id.equals(ShapeDrawComponent.PROP_LINE_COLOR)) {
133             getShapeDrawComponent().setLineColor((Color JavaDoc)value);
134         }
135         else if (id.equals(ShapeDrawComponent.PROP_LINE_WIDTH)) {
136             getShapeDrawComponent().setLineWidth(((Integer JavaDoc)value).intValue());
137         }
138         else if (id.equals(ShapeDrawComponent.PROP_LINE_STYLE)) {
139             getShapeDrawComponent().setLineStyle(((Integer JavaDoc)value).intValue());
140         }
141         else if (id.equals(ShapeDrawComponent.PROP_FILL)) {
142             getShapeDrawComponent().setFill(((Boolean JavaDoc)value).booleanValue());
143         }
144     }
145     
146     protected ShapeDrawComponent getShapeDrawComponent() {
147         return (ShapeDrawComponent) drawComponent;
148     }
149 }
150
Popular Tags