KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc;
31
32 import org.eclipse.ui.views.properties.PropertyDescriptor;
33 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
34
35 import org.nightlabs.base.property.CheckboxPropertyDescriptor;
36 import org.nightlabs.base.property.IntPropertyDescriptor;
37 import org.nightlabs.editor2d.EditorPlugin;
38 import org.nightlabs.editor2d.TextDrawComponent;
39 import org.nightlabs.editor2d.properties.FontNamePropertyDescriptor;
40
41 public class TextPropertySource
42 extends ShapeDrawComponentPropertySource
43 {
44     public TextPropertySource(TextDrawComponent text) {
45         super(text);
46     }
47     
48     protected TextDrawComponent getTextDrawComponent() {
49         return (TextDrawComponent) drawComponent;
50     }
51     
52     public static final String JavaDoc CATEGORY_FONT = EditorPlugin.getResourceString("property.category.text");
53         
54     protected List JavaDoc createPropertyDescriptors()
55     {
56         List JavaDoc descriptors = super.createPropertyDescriptors();
57         
58         // Font Name
59
PropertyDescriptor desc = new FontNamePropertyDescriptor(TextDrawComponent.PROP_FONT_NAME,
60                 EditorPlugin.getResourceString("property.fontname.label"));
61         desc.setCategory(CATEGORY_FONT);
62         descriptors.add(desc);
63         
64         // Font Size
65
// desc = new FontSizePropertyDescriptor(TextDrawComponent.PROP_FONT_SIZE,
66
// EditorPlugin.getResourceString("property.fontsize.label"));
67
// desc.setCategory(CATEGORY_FONT);
68
// descriptors.add(desc);
69
desc = new IntPropertyDescriptor(TextDrawComponent.PROP_FONT_SIZE,
70                 EditorPlugin.getResourceString("property.fontsize.label"));
71         desc.setCategory(CATEGORY_FONT);
72         descriptors.add(desc);
73         
74         // Bold
75
desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_BOLD,
76                 EditorPlugin.getResourceString("property.bold.label"));
77         desc.setCategory(CATEGORY_FONT);
78         descriptors.add(desc);
79         
80         // Italic
81
desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_ITALIC,
82                 EditorPlugin.getResourceString("property.italic.label"));
83         desc.setCategory(CATEGORY_FONT);
84         descriptors.add(desc);
85         
86         // Text
87
desc = new TextPropertyDescriptor(TextDrawComponent.PROP_TEXT,
88                 EditorPlugin.getResourceString("property.text.label"));
89         desc.setCategory(CATEGORY_FONT);
90         descriptors.add(desc);
91         
92         return descriptors;
93     }
94     
95     /* (non-Javadoc)
96      * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
97      */

98     public void setPropertyValue(Object JavaDoc id, Object JavaDoc value)
99     {
100         super.setPropertyValue(id, value);
101         
102         if (id.equals(TextDrawComponent.PROP_FONT_NAME)) {
103             getTextDrawComponent().setFontName((String JavaDoc)value);
104         }
105         else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) {
106             getTextDrawComponent().setFontSize(((Integer JavaDoc)value).intValue());
107         }
108         else if (id.equals(TextDrawComponent.PROP_BOLD)) {
109             getTextDrawComponent().setBold(((Boolean JavaDoc)value).booleanValue());
110         }
111         else if (id.equals(TextDrawComponent.PROP_ITALIC)) {
112             getTextDrawComponent().setItalic(((Boolean JavaDoc)value).booleanValue());
113         }
114         else if (id.equals(TextDrawComponent.PROP_TEXT)) {
115             getTextDrawComponent().setText((String JavaDoc)value);
116         }
117
118     }
119     
120     /* (non-Javadoc)
121      * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
122      */

123     public Object JavaDoc getPropertyValue(Object JavaDoc id)
124     {
125         Object JavaDoc o = super.getPropertyValue(id);
126         if (o != null)
127             return o;
128         else
129         {
130             if (id.equals(TextDrawComponent.PROP_FONT_NAME)) {
131                 return getTextDrawComponent().getFontName();
132             }
133             else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) {
134                 return new Integer JavaDoc(getTextDrawComponent().getFontSize());
135             }
136             else if (id.equals(TextDrawComponent.PROP_BOLD)) {
137                 return new Boolean JavaDoc(getTextDrawComponent().isBold());
138             }
139             else if (id.equals(TextDrawComponent.PROP_ITALIC)) {
140                 return new Boolean JavaDoc(getTextDrawComponent().isItalic());
141             }
142             else if (id.equals(TextDrawComponent.PROP_TEXT)) {
143                 return getTextDrawComponent().getText();
144             }
145
146             return null;
147         }
148     }
149 }
150
Popular Tags