1 27 28 package org.nightlabs.editor2d.model; 29 30 import java.util.List ; 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 CATEGORY_FONT = EditorPlugin.getResourceString("property.category.text"); 53 54 protected List createPropertyDescriptors() 55 { 56 List descriptors = super.createPropertyDescriptors(); 57 58 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 desc = new IntPropertyDescriptor(TextDrawComponent.PROP_FONT_SIZE, 70 EditorPlugin.getResourceString("property.fontsize.label")); 71 desc.setCategory(CATEGORY_FONT); 72 descriptors.add(desc); 73 74 desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_BOLD, 76 EditorPlugin.getResourceString("property.bold.label")); 77 desc.setCategory(CATEGORY_FONT); 78 descriptors.add(desc); 79 80 desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_ITALIC, 82 EditorPlugin.getResourceString("property.italic.label")); 83 desc.setCategory(CATEGORY_FONT); 84 descriptors.add(desc); 85 86 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 98 public void setPropertyValue(Object id, Object value) 99 { 100 super.setPropertyValue(id, value); 101 102 if (id.equals(TextDrawComponent.PROP_FONT_NAME)) { 103 getTextDrawComponent().setFontName((String )value); 104 } 105 else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) { 106 getTextDrawComponent().setFontSize(((Integer )value).intValue()); 107 } 108 else if (id.equals(TextDrawComponent.PROP_BOLD)) { 109 getTextDrawComponent().setBold(((Boolean )value).booleanValue()); 110 } 111 else if (id.equals(TextDrawComponent.PROP_ITALIC)) { 112 getTextDrawComponent().setItalic(((Boolean )value).booleanValue()); 113 } 114 else if (id.equals(TextDrawComponent.PROP_TEXT)) { 115 getTextDrawComponent().setText((String )value); 116 } 117 118 } 119 120 123 public Object getPropertyValue(Object id) 124 { 125 Object 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 (getTextDrawComponent().getFontSize()); 135 } 136 else if (id.equals(TextDrawComponent.PROP_BOLD)) { 137 return new Boolean (getTextDrawComponent().isBold()); 138 } 139 else if (id.equals(TextDrawComponent.PROP_ITALIC)) { 140 return new Boolean (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 |