1 8 package com.nightlabs.editor2d.model; 9 10 import java.util.ArrayList ; 11 import java.util.List ; 12 13 import org.eclipse.ui.views.properties.IPropertyDescriptor; 14 import org.eclipse.ui.views.properties.IPropertySource; 15 import org.eclipse.ui.views.properties.PropertyDescriptor; 16 17 import com.nightlabs.editor2d.DrawComponent; 18 import com.nightlabs.editor2d.EditorPlugin; 19 import com.nightlabs.editor2d.properties.IntPropertyDescriptor; 20 import com.nightlabs.editor2d.properties.NameLanguageManager; 21 import com.nightlabs.editor2d.properties.NamePropertyDescriptor; 22 import com.nightlabs.editor2d.properties.RotationPropertyDescriptor; 23 import com.nightlabs.rcp.language.LanguageChangeEvent; 24 import com.nightlabs.rcp.language.LanguageChangeListener; 25 26 public class DrawComponentPropertySource 27 implements IPropertySource 28 { 29 protected DrawComponent drawComponent; 30 protected NameLanguageManager nameLangMan; 31 public DrawComponentPropertySource(DrawComponent element) { 32 this.drawComponent = element; 33 descriptors = createPropertyDescriptors(); 34 nameLangMan = NameLanguageManager.sharedInstance(); 35 nameLangMan.addLanguageChangeListener(langListener); 36 } 37 38 protected LanguageChangeListener langListener = new LanguageChangeListener(){ 39 public void languageChanged(LanguageChangeEvent event) { 40 String newLanguageID = event.getNewLanguage().getLanguageID(); 41 drawComponent.setLanguageId(newLanguageID); 42 } 43 }; 44 45 48 public Object getEditableValue() { 49 return drawComponent; 50 } 51 52 56 113 public static final String CATEGORY_NAME = EditorPlugin.getResourceString("property.category.name"); 114 public static final String CATEGORY_GEOM = EditorPlugin.getResourceString("property.category.geom"); 115 public static final String CATEGORY_ROTATION = EditorPlugin.getResourceString("property.category.rotation"); 116 117 protected List descriptors = null; 118 protected List getDescriptors() { 119 if (descriptors == null) 120 descriptors = new ArrayList (); 121 return descriptors; 122 } 123 124 protected List createPropertyDescriptors() 125 { 126 List descriptors = getDescriptors(); 127 128 PropertyDescriptor desc = new NamePropertyDescriptor(drawComponent, 140 DrawComponent.PROP_NAME, 141 EditorPlugin.getResourceString("property.name.label")); 142 desc.setCategory(CATEGORY_NAME); 143 descriptors.add(desc); 144 145 desc = new IntPropertyDescriptor(DrawComponent.PROP_X, 147 EditorPlugin.getResourceString("property.x.label")); 148 desc.setCategory(CATEGORY_GEOM); 149 descriptors.add(desc); 150 151 desc = new IntPropertyDescriptor(DrawComponent.PROP_Y, 153 EditorPlugin.getResourceString("property.y.label")); 154 desc.setCategory(CATEGORY_GEOM); 155 descriptors.add(desc); 156 157 desc = new IntPropertyDescriptor(DrawComponent.PROP_WIDTH, 159 EditorPlugin.getResourceString("property.width.label")); 160 desc.setCategory(CATEGORY_GEOM); 161 descriptors.add(desc); 162 163 desc = new IntPropertyDescriptor(DrawComponent.PROP_HEIGHT, 165 EditorPlugin.getResourceString("property.height.label")); 166 desc.setCategory(CATEGORY_GEOM); 167 descriptors.add(desc); 168 169 desc = new RotationPropertyDescriptor(DrawComponent.PROP_ROTATION, 171 EditorPlugin.getResourceString("property.rotation.label")); 172 desc.setCategory(CATEGORY_ROTATION); 173 descriptors.add(desc); 174 175 desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_X, 177 EditorPlugin.getResourceString("property.rotationx.label")); 178 desc.setCategory(CATEGORY_ROTATION); 179 descriptors.add(desc); 180 181 desc = new IntPropertyDescriptor(DrawComponent.PROP_ROTATION_Y, 183 EditorPlugin.getResourceString("property.rotationy.label")); 184 desc.setCategory(CATEGORY_ROTATION); 185 descriptors.add(desc); 186 187 return descriptors; 188 } 189 190 public IPropertyDescriptor[] getPropertyDescriptors() 191 { 192 if (drawComponent == null) 193 return new IPropertyDescriptor[0]; 194 195 List descriptors = getDescriptors(); 196 return (IPropertyDescriptor[])descriptors.toArray( new IPropertyDescriptor[] {} ); 197 } 198 199 202 public Object getPropertyValue(Object id) 203 { 204 if (id.equals(DrawComponent.PROP_X)) { 205 return new Integer (drawComponent.getX()); 206 } 207 else if (id.equals(DrawComponent.PROP_Y)) { 208 return new Integer (drawComponent.getY()); 209 } 210 else if (id.equals(DrawComponent.PROP_WIDTH)) { 211 return new Integer (drawComponent.getWidth()); 212 } 213 else if (id.equals(DrawComponent.PROP_HEIGHT)) { 214 return new Integer (drawComponent.getHeight()); 215 } 216 else if (id.equals(DrawComponent.PROP_ROTATION)) { 217 return new Double (drawComponent.getRotation()); 218 } 219 else if (id.equals(DrawComponent.PROP_ROTATION_X)) { 220 return new Integer (drawComponent.getRotationX()); 221 } 222 else if (id.equals(DrawComponent.PROP_ROTATION_Y)) { 223 return new Integer (drawComponent.getRotationY()); 224 } 225 else if (id.equals(DrawComponent.PROP_NAME)) { 232 return drawComponent.getI18nText().getText(nameLangMan.getCurrentLanguageID()); 233 } 234 235 return null; 236 } 237 238 246 249 public boolean isPropertySet(Object id) { 250 return false; 252 } 253 254 257 public void resetPropertyValue(Object id) { 258 } 260 261 264 public void setPropertyValue(Object id, Object value) 265 { 266 if (id.equals(DrawComponent.PROP_X)) { 267 drawComponent.setX(((Integer )value).intValue()); 268 } 269 else if (id.equals(DrawComponent.PROP_Y)) { 270 drawComponent.setY(((Integer )value).intValue()); 271 } 272 else if (id.equals(DrawComponent.PROP_WIDTH)) { 273 drawComponent.setWidth(((Integer )value).intValue()); 274 } 275 else if (id.equals(DrawComponent.PROP_HEIGHT)) { 276 drawComponent.setHeight(((Integer )value).intValue()); 277 } 278 else if (id.equals(DrawComponent.PROP_ROTATION)) { 279 drawComponent.setRotation(((Double )value).doubleValue()); 280 } 281 else if (id.equals(DrawComponent.PROP_ROTATION_X)) { 282 drawComponent.setRotationX(((Integer )value).intValue()); 283 } 284 else if (id.equals(DrawComponent.PROP_ROTATION_Y)) { 285 drawComponent.setRotationY(((Integer )value).intValue()); 286 } 287 else if (id.equals(DrawComponent.PROP_NAME)) { 291 drawComponent.setName((String )value); 292 } 293 294 } 295 296 302 } 303 304
| Popular Tags
|