KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.nightlabs.editor2d.model;
2
3 import java.util.List JavaDoc;
4
5 import org.eclipse.ui.views.properties.PropertyDescriptor;
6 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
7
8 import com.nightlabs.editor2d.EditorPlugin;
9 import com.nightlabs.editor2d.TextDrawComponent;
10 import com.nightlabs.editor2d.properties.CheckboxPropertyDescriptor;
11 import com.nightlabs.editor2d.properties.FontNamePropertyDescriptor;
12 import com.nightlabs.editor2d.properties.FontSizePropertyDescriptor;
13
14 public class TextPropertySource
15 extends ShapeDrawComponentPropertySource
16 {
17     public TextPropertySource(TextDrawComponent text) {
18         super(text);
19     }
20     
21     protected TextDrawComponent getTextDrawComponent() {
22         return (TextDrawComponent) drawComponent;
23     }
24     
25     public static final String JavaDoc CATEGORY_FONT = EditorPlugin.getResourceString("property.category.text");
26         
27     protected List JavaDoc createPropertyDescriptors()
28     {
29         List JavaDoc descriptors = super.createPropertyDescriptors();
30         
31         // Font Name
32
PropertyDescriptor desc = new FontNamePropertyDescriptor(TextDrawComponent.PROP_FONT_NAME,
33                 EditorPlugin.getResourceString("property.fontname.label"));
34         desc.setCategory(CATEGORY_FONT);
35         descriptors.add(desc);
36         
37         // Font Size
38
desc = new FontSizePropertyDescriptor(TextDrawComponent.PROP_FONT_SIZE,
39                 EditorPlugin.getResourceString("property.fontsize.label"));
40         desc.setCategory(CATEGORY_FONT);
41         descriptors.add(desc);
42         
43         // Bold
44
desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_BOLD,
45                 EditorPlugin.getResourceString("property.bold.label"));
46         desc.setCategory(CATEGORY_FONT);
47         descriptors.add(desc);
48         
49         // Italic
50
desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_ITALIC,
51                 EditorPlugin.getResourceString("property.italic.label"));
52         desc.setCategory(CATEGORY_FONT);
53         descriptors.add(desc);
54         
55         // Text
56
desc = new TextPropertyDescriptor(TextDrawComponent.PROP_TEXT,
57                 EditorPlugin.getResourceString("property.text.label"));
58         desc.setCategory(CATEGORY_FONT);
59         descriptors.add(desc);
60         
61         return descriptors;
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
66      */

67     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
68     {
69         super.setPropertyValue(id, value);
70         
71         if (id.equals(TextDrawComponent.PROP_FONT_NAME)) {
72             getTextDrawComponent().setFontName((String JavaDoc)value);
73         }
74         else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) {
75             getTextDrawComponent().setFontSize(((Integer JavaDoc)value).intValue());
76         }
77         else if (id.equals(TextDrawComponent.PROP_BOLD)) {
78             getTextDrawComponent().setBold(((Boolean JavaDoc)value).booleanValue());
79         }
80         else if (id.equals(TextDrawComponent.PROP_ITALIC)) {
81             getTextDrawComponent().setItalic(((Boolean JavaDoc)value).booleanValue());
82         }
83         else if (id.equals(TextDrawComponent.PROP_TEXT)) {
84             getTextDrawComponent().setText((String JavaDoc)value);
85         }
86
87     }
88     
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
91      */

92     public Object JavaDoc getPropertyValue(Object JavaDoc id)
93     {
94         Object JavaDoc o = super.getPropertyValue(id);
95         if (o != null)
96             return o;
97         else
98         {
99             if (id.equals(TextDrawComponent.PROP_FONT_NAME)) {
100                 return getTextDrawComponent().getFontName();
101             }
102             else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) {
103                 return new Integer JavaDoc(getTextDrawComponent().getFontSize());
104             }
105             else if (id.equals(TextDrawComponent.PROP_BOLD)) {
106                 return new Boolean JavaDoc(getTextDrawComponent().isBold());
107             }
108             else if (id.equals(TextDrawComponent.PROP_ITALIC)) {
109                 return new Boolean JavaDoc(getTextDrawComponent().isItalic());
110             }
111             else if (id.equals(TextDrawComponent.PROP_TEXT)) {
112                 return getTextDrawComponent().getText();
113             }
114
115             return null;
116         }
117     }
118 }
119
Popular Tags