1 package com.nightlabs.editor2d.model; 2 3 import java.util.List ; 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 CATEGORY_FONT = EditorPlugin.getResourceString("property.category.text"); 26 27 protected List createPropertyDescriptors() 28 { 29 List descriptors = super.createPropertyDescriptors(); 30 31 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 desc = new FontSizePropertyDescriptor(TextDrawComponent.PROP_FONT_SIZE, 39 EditorPlugin.getResourceString("property.fontsize.label")); 40 desc.setCategory(CATEGORY_FONT); 41 descriptors.add(desc); 42 43 desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_BOLD, 45 EditorPlugin.getResourceString("property.bold.label")); 46 desc.setCategory(CATEGORY_FONT); 47 descriptors.add(desc); 48 49 desc = new CheckboxPropertyDescriptor(TextDrawComponent.PROP_ITALIC, 51 EditorPlugin.getResourceString("property.italic.label")); 52 desc.setCategory(CATEGORY_FONT); 53 descriptors.add(desc); 54 55 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 67 public void setPropertyValue(Object id, Object value) 68 { 69 super.setPropertyValue(id, value); 70 71 if (id.equals(TextDrawComponent.PROP_FONT_NAME)) { 72 getTextDrawComponent().setFontName((String )value); 73 } 74 else if (id.equals(TextDrawComponent.PROP_FONT_SIZE)) { 75 getTextDrawComponent().setFontSize(((Integer )value).intValue()); 76 } 77 else if (id.equals(TextDrawComponent.PROP_BOLD)) { 78 getTextDrawComponent().setBold(((Boolean )value).booleanValue()); 79 } 80 else if (id.equals(TextDrawComponent.PROP_ITALIC)) { 81 getTextDrawComponent().setItalic(((Boolean )value).booleanValue()); 82 } 83 else if (id.equals(TextDrawComponent.PROP_TEXT)) { 84 getTextDrawComponent().setText((String )value); 85 } 86 87 } 88 89 92 public Object getPropertyValue(Object id) 93 { 94 Object 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 (getTextDrawComponent().getFontSize()); 104 } 105 else if (id.equals(TextDrawComponent.PROP_BOLD)) { 106 return new Boolean (getTextDrawComponent().isBold()); 107 } 108 else if (id.equals(TextDrawComponent.PROP_ITALIC)) { 109 return new Boolean (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 |