📄 shapeseditorpalettefactory.java
字号:
/******************************************************************************* * Copyright (c) 2004, 2005 Elias Volanakis and others.�* All rights reserved. This program and the accompanying materials�* are made available under the terms of the Eclipse Public License v1.0�* which accompanies this distribution, and is available at�* http://www.eclipse.org/legal/epl-v10.html�*�* Contributors:�*����Elias Volanakis - initial API and implementation�*******************************************************************************/package net.sf.freenote;import net.sf.freenote.mindmap.model.BranchShape;import net.sf.freenote.mindmap.model.RootShape;import net.sf.freenote.model.CircleShape;import net.sf.freenote.model.EllipticalShape;import net.sf.freenote.model.ImageFileShape;import net.sf.freenote.model.LinkFileShape;import net.sf.freenote.model.RectangularShape;import net.sf.freenote.model.TextShape;import net.sf.freenote.uml.model.ClassShape;import net.sf.freenote.uml.model.SystemShape;import net.sf.freenote.uml.model.UseCaseShape;import net.sf.freenote.uml.model.UserRoleShape;import org.eclipse.gef.palette.CombinedTemplateCreationEntry;import org.eclipse.gef.palette.ConnectionCreationToolEntry;import org.eclipse.gef.palette.PaletteContainer;import org.eclipse.gef.palette.PaletteDrawer;import org.eclipse.gef.palette.PaletteEntry;import org.eclipse.gef.palette.PaletteGroup;import org.eclipse.gef.palette.PaletteRoot;import org.eclipse.gef.palette.PanningSelectionToolEntry;import org.eclipse.gef.palette.ToolEntry;import org.eclipse.gef.requests.CreationFactory;import org.eclipse.gef.requests.SimpleFactory;/** * Utility class that can create a GEF Palette. * @see #createPalette() * @author Elias Volanakis */final class ShapesEditorPaletteFactory {/** * Creates the PaletteRoot and adds all palette elements. * Use this factory method to create a new palette for your graphical editor. * @return a new PaletteRoot */static PaletteRoot createPalette() { PaletteRoot palette = new PaletteRoot(); palette.add(createToolsGroup(palette)); palette.add(createShapesDrawer()); palette.add(createUmlShapesDrawer()); palette.add(createMindMapShapesDrawer()); palette.add(createGalleryDrawer()); return palette;}/** Create the "Shapes" drawer. */private static PaletteContainer createShapesDrawer() { PaletteDrawer componentsDrawer = new PaletteDrawer("常用工具"); CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry( "椭圆", "Create an elliptical shape", EllipticalShape.class, new SimpleFactory(EllipticalShape.class), ShapesPlugin.getImageDescriptor("icons/ellipse.gif"), ShapesPlugin.getImageDescriptor("icons/ellipse.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "矩形", "Create a rectangular shape", RectangularShape.class, new SimpleFactory(RectangularShape.class), ShapesPlugin.getImageDescriptor("icons/rectangle.gif"), ShapesPlugin.getImageDescriptor("icons/rectangle.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "圆形", "Create a circle shape", CircleShape.class, new SimpleFactory(CircleShape.class), ShapesPlugin.getImageDescriptor("icons/circle.gif"), ShapesPlugin.getImageDescriptor("icons/circle.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "文字", "Create a text shape", TextShape.class, new SimpleFactory(TextShape.class), ShapesPlugin.getImageDescriptor("icons/text.gif"), ShapesPlugin.getImageDescriptor("icons/text.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "图片", "Create a image shape from file", ImageFileShape.class, new SimpleFactory(ImageFileShape.class), ShapesPlugin.getImageDescriptor("icons/imagefile.gif"), ShapesPlugin.getImageDescriptor("icons/imagefile.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "文件", "Create a link shape from file", LinkFileShape.class, new SimpleFactory(LinkFileShape.class), ShapesPlugin.getImageDescriptor("icons/linkfile.gif"), ShapesPlugin.getImageDescriptor("icons/linkfile.gif")); componentsDrawer.add(component); return componentsDrawer;} private static PaletteEntry createUmlShapesDrawer() { PaletteDrawer componentsDrawer = new PaletteDrawer("UML工具"); CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry( "用例", "创建一个用例", UseCaseShape.class, new SimpleFactory(UseCaseShape.class), ShapesPlugin.getImageDescriptor("icons/usecase.gif"), ShapesPlugin.getImageDescriptor("icons/usecase.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "角色", "创建一个用角", UserRoleShape.class, new SimpleFactory(UserRoleShape.class), ShapesPlugin.getImageDescriptor("icons/userrole.gif"), ShapesPlugin.getImageDescriptor("icons/userrole.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "系统", "创建一个系统", SystemShape.class, new SimpleFactory(SystemShape.class), ShapesPlugin.getImageDescriptor("icons/system.gif"), ShapesPlugin.getImageDescriptor("icons/system.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "类图", "创建一个类", ClassShape.class, new SimpleFactory(ClassShape.class), ShapesPlugin.getImageDescriptor("icons/class.gif"), ShapesPlugin.getImageDescriptor("icons/class.gif")); componentsDrawer.add(component); return componentsDrawer;}private static PaletteEntry createMindMapShapesDrawer() { PaletteDrawer componentsDrawer = new PaletteDrawer("MindMap"); CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry( "中心主题", "创建一个中心主题", RootShape.class, new SimpleFactory(RootShape.class), ShapesPlugin.getImageDescriptor("icons/root.gif"), ShapesPlugin.getImageDescriptor("icons/root.gif")); componentsDrawer.add(component); component = new CombinedTemplateCreationEntry( "分支主题", "创建一个分支主题", BranchShape.class, new SimpleFactory(BranchShape.class), ShapesPlugin.getImageDescriptor("icons/branch.gif"), ShapesPlugin.getImageDescriptor("icons/branch.gif")); componentsDrawer.add(component); return componentsDrawer;}private static PaletteEntry createGalleryDrawer() { PaletteDrawer componentsDrawer = new PaletteDrawer("图集"); componentsDrawer.setId("ICON_ONLY"); for(final String path:GalleryHelper.getRegistry()){ CombinedTemplateCreationEntry component = new CombinedTemplateCreationEntry( "", "", ImageFileShape.class, new CreationFactory(){ public Object getNewObject() { return GalleryHelper.createImageFileShape(path); } public Object getObjectType() { return ImageFileShape.class; } }, ShapesPlugin.getImageDescriptor(path), ShapesPlugin.getImageDescriptor(path)); component.setId("ICON_ONLY"); componentsDrawer.add(component); } return componentsDrawer;}/** Create the "Tools" group. */private static PaletteContainer createToolsGroup(PaletteRoot palette) { PaletteGroup toolGroup = new PaletteGroup("通用工具"); // Add a selection tool to the group ToolEntry tool = new PanningSelectionToolEntry(); tool.setLabel("选择"); toolGroup.add(tool); palette.setDefaultEntry(tool); // Add a marquee tool to the group// MarqueeToolEntry marqueeTool = new MarqueeToolEntry();// marqueeTool.setLabel("框选");// toolGroup.add(marqueeTool); // Add a (unnamed) separator to the group// toolGroup.add(new PaletteSeparator()); // Add (solid-line) connection tool tool = new ConnectionCreationToolEntry( "连接", "创建一个连接", new CreationFactory() { public Object getNewObject() { return null; } // see ShapeEditPart#createEditPolicies() // this is abused to transmit the desired line style public Object getObjectType() { return new Integer(1); } }, ShapesPlugin.getImageDescriptor("icons/connection_s.gif"), ShapesPlugin.getImageDescriptor("icons/connection_s.gif")); toolGroup.add(tool); // Add (dashed-line) connection tool// tool = new ConnectionCreationToolEntry(// "虚线连接",// "Create a dashed-line connection",// new CreationFactory() {// public Object getNewObject() { return null; }// // see ShapeEditPart#createEditPolicies()// // this is abused to transmit the desired line style // public Object getObjectType() { return Connection.DASHED_CONNECTION; }// },// ShapesPlugin.getImageDescriptor("icons/connection_d.gif"),// ShapesPlugin.getImageDescriptor("icons/connection_d.gif"));// toolGroup.add(tool); return toolGroup;}/** Utility class. */private ShapesEditorPaletteFactory() { // Utility class}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -