1 8 package com.nightlabs.editor2d; 9 10 import org.eclipse.gef.palette.MarqueeToolEntry; 11 import org.eclipse.gef.palette.PaletteContainer; 12 import org.eclipse.gef.palette.PaletteDrawer; 13 import org.eclipse.gef.palette.PaletteGroup; 14 import org.eclipse.gef.palette.PaletteRoot; 15 import org.eclipse.gef.palette.PaletteSeparator; 16 import org.eclipse.gef.palette.ToolEntry; 17 import org.eclipse.gef.requests.CreationFactory; 18 import org.eclipse.gef.ui.palette.FlyoutPaletteComposite.FlyoutPreferences; 19 import org.eclipse.jface.preference.IPreferenceStore; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 22 import com.nightlabs.editor2d.EllipseDrawComponent; 23 import com.nightlabs.editor2d.ImageDrawComponent; 24 import com.nightlabs.editor2d.LineDrawComponent; 25 import com.nightlabs.editor2d.RectangleDrawComponent; 26 import com.nightlabs.editor2d.TextDrawComponent; 27 import com.nightlabs.editor2d.model.ModelCreationFactory; 28 import com.nightlabs.editor2d.tools.EditorSelectionToolEntry; 29 import com.nightlabs.editor2d.tools.EllipseToolEntry; 30 import com.nightlabs.editor2d.tools.ImageToolEntry; 31 import com.nightlabs.editor2d.tools.LineToolEntry; 32 import com.nightlabs.editor2d.tools.RectangleToolEntry; 33 import com.nightlabs.editor2d.tools.TextToolEntry; 34 import com.nightlabs.editor2d.tools.ZoomToolEntry; 35 36 public abstract class AbstractPaletteFactory 37 { 38 public AbstractPaletteFactory() { 39 super(); 40 } 41 42 43 protected static final int DEFAULT_PALETTE_SIZE = 125; 44 45 protected static final String PALETTE_DOCK_LOCATION = "PaletteFactory.Location"; 46 47 protected static final String PALETTE_SIZE = "PaletteFactory.Size"; 48 49 protected static final String PALETTE_STATE = "PaletteFactory.State"; 50 51 public abstract CreationFactory getCreationFactory(Class targetClass); 52 53 56 public static FlyoutPreferences createPalettePreferences() 57 { 58 getPreferenceStore().setDefault(PALETTE_DOCK_LOCATION, -1); 61 getPreferenceStore().setDefault(PALETTE_STATE, -1); 62 getPreferenceStore().setDefault(PALETTE_SIZE, DEFAULT_PALETTE_SIZE); 63 64 return new FlyoutPreferences() { 65 public int getDockLocation() { 66 return getPreferenceStore().getInt(PALETTE_DOCK_LOCATION); 67 } 68 public int getPaletteState() { 69 return getPreferenceStore().getInt(PALETTE_STATE); 70 } 71 public int getPaletteWidth() { 72 return getPreferenceStore().getInt(PALETTE_SIZE); 73 } 74 public void setDockLocation(int location) { 75 getPreferenceStore().setValue(PALETTE_DOCK_LOCATION, location); 76 } 77 public void setPaletteState(int state) { 78 getPreferenceStore().setValue(PALETTE_STATE, state); 79 } 80 public void setPaletteWidth(int width) { 81 getPreferenceStore().setValue(PALETTE_SIZE, width); 82 } 83 }; 84 } 85 86 90 protected static IPreferenceStore getPreferenceStore() 91 { 92 return EditorPlugin.getDefault().getPreferenceStore(); 93 } 94 95 96 protected static PaletteContainer createShapesDrawer() 97 { 98 PaletteDrawer componentsDrawer = new PaletteDrawer(EditorPlugin.getResourceString("palette_group_shapes")); 99 100 ToolEntry component = new RectangleToolEntry 103 ( 104 EditorPlugin.getResourceString("palette_rectangle_label"), 105 EditorPlugin.getResourceString("palette_rectangle_shortdesc"), 106 RectangleDrawComponent.class, 107 new ModelCreationFactory(RectangleDrawComponent.class), 108 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/rectangle16.gif"), 109 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/rectangle24.gif") 110 ); 111 componentsDrawer.add(component); 112 113 component = new EllipseToolEntry 116 ( 117 EditorPlugin.getResourceString("palette_ellipse_label"), 118 EditorPlugin.getResourceString("palette_ellipse_shortdesc"), 119 EllipseDrawComponent.class, 120 new ModelCreationFactory(EllipseDrawComponent.class), 121 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/ellipse16.gif"), 122 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/ellipse24.gif") 123 ); 124 componentsDrawer.add(component); 125 126 component = new LineToolEntry 128 ( 129 EditorPlugin.getResourceString("palette_line_label"), 130 EditorPlugin.getResourceString("palette_line_shortdesc"), 131 LineDrawComponent.class, 132 new ModelCreationFactory(LineDrawComponent.class), 133 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/line16.gif"), 134 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/line24.gif") 135 ); 136 componentsDrawer.add(component); 137 138 component = new TextToolEntry 140 ( 141 EditorPlugin.getResourceString("palette.text.label"), 142 EditorPlugin.getResourceString("palette.text.shortdesc"), 143 TextDrawComponent.class, 144 new ModelCreationFactory(TextDrawComponent.class), 145 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/text16.gif"), 146 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/text24.gif") 147 ); 148 componentsDrawer.add(component); 149 150 component = new ImageToolEntry 152 ( 153 EditorPlugin.getResourceString("palette.image.label"), 154 EditorPlugin.getResourceString("palette.image.shortdesc"), 155 ImageDrawComponent.class, 156 new ModelCreationFactory(ImageDrawComponent.class), 157 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/image16.gif"), 158 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/image24.gif") 159 ); 160 componentsDrawer.add(component); 161 162 return componentsDrawer; 163 } 164 165 170 protected static PaletteRoot createPalette() 171 { 172 PaletteRoot palette = new PaletteRoot(); 173 palette.add(createToolsGroup(palette)); 174 palette.add(createShapesDrawer()); 175 return palette; 176 } 177 178 179 protected static PaletteContainer createToolsGroup(PaletteRoot palette) 180 { 181 PaletteGroup toolGroup = new PaletteGroup(EditorPlugin.getResourceString("palette_group_tools")); 182 183 ToolEntry tool = new EditorSelectionToolEntry(); 188 toolGroup.add(tool); 189 palette.setDefaultEntry(tool); 190 191 toolGroup.add(new MarqueeToolEntry()); 193 194 toolGroup.add(new ZoomToolEntry(EditorPlugin.getResourceString("palette.zoom.label"), 196 EditorPlugin.getResourceString("palette.zoom.shortdesc"), 197 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/zoom16.gif"), 198 ImageDescriptor.createFromFile(EditorPlugin.class, "icons/zoom24.gif") 199 )); 200 201 toolGroup.add(new PaletteSeparator()); 203 204 return toolGroup; 205 } 206 207 } 208
| Popular Tags
|