默认情况下,GEF中要创建一个新的结点都是通点在Palette上选择一个结点,然后在Editor区域单击实现的。
也有一些是通过拖放Palette中的一个对象到Editor区域来实现的。
要实现一个拖放支持也是很容易的。GEF中默认实现了一组drag-drop listener用来支持拖放实现:
1。TemplateTransferDropTargetListener
因为是要从palette上拖到Editor中,所以此监听事件显示是应该安放在Editor上,在GEF中就是GraphicalViewer,可以在initializeGraphicalViewer()方法中加上:
getGraphicalViewer().addDropTargetListener(new TemplateTransferDropTargetListener(
getGraphicalViewer()));
2。TemplateTransferDragSourceListener
显示此事件需要加在palette上,也就是PaletteViewer上,可以在initializePaletteViewer()方法中加上:
getPaletteViewer().addDragSourceListener(new TemplateTransferDragSourceListener(getPaletteViewer()));
回头再看一下我们对Palette上的Item的声明:
CombinedTemplateCreationEntry(String label, String shortDesc,
CreationFactory factory, ImageDescriptor iconSmall, ImageDescriptor iconLarge)
需要注意CombinedTemplateCreationEntry构造方法的选用。认为上述构造方法为默认选择,而CreationFactory类为SimpleFactory。
如果选择另一个构造方法:
CombinedTemplateCreationEntry(String label, String shortDesc, Object template,
CreationFactory factory, ImageDescriptor iconSmall, ImageDescriptor iconLarge)
则我们需要注意:如果template和factory都是SimpleFactory则没有问题,因为默认的template就是SimpleFactory。否则我们需要根据自己的template值来得到对应的model,也就是要实现自己的CreationFactory。例如:
CombinedTemplateCreationEntry elementCreationEntry = new CombinedTemplateCreationEntry(
"Element", "Element type",ModelCreationFactory.ELEMENT_TYPE,new ModelCreationFactory(ModelCreationFactory.ELEMENT_TYPE), Activator
.getImageDescriptor("icons/element.png"), Activator
.getImageDescriptor("icons/element.png"));
CombinedTemplateCreationEntry attributeCreationEntry = new CombinedTemplateCreationEntry(
"Attribute", "Attribute type",ModelCreationFactory.ATTRIBUTE_TYPE, new ModelCreationFactory(ModelCreationFactory.ATTRIBUTE_TYPE), Activator
.getImageDescriptor("icons/attribute.png"), Activator
.getImageDescriptor("icons/attribute.png"));
getGraphicalViewer().addDropTargetListener(new CustomTemplateTransferDropTargetListener(
getGraphicalViewer()));
public class ModelCreationFactory implements CreationFactory {
private int objectType;
public static final int ELEMENT_TYPE = 0x01;
public static final int ATTRIBUTE_TYPE = 0x02;
public static final int ROOT_TYPE = 0x04;
public ModelCreationFactory(int objectType) {
super();
this.objectType = objectType;
}
public Object getNewObject() {
switch (objectType) {
case ELEMENT_TYPE:
return new ElementType();
case ATTRIBUTE_TYPE:
return new AttributeType();
case ROOT_TYPE:
return new RootType();
default:
break;
}
return null;
}
public Object getObjectType() {
return objectType;
}
}
public class CustomTemplateTransferDropTargetListener extends
TemplateTransferDropTargetListener {
public CustomTemplateTransferDropTargetListener(EditPartViewer viewer) {
super(viewer);
}
@Override
protected CreationFactory getFactory(Object template) {
return new ModelCreationFactory(((Integer)template).intValue());
}
}
分享到:
相关推荐
明基Palette Master支持硬件自动校准,简化校正并确实地产生正确的色彩结果。 Palette Master 可以用来校正显示器的色彩引擎,并完全支支持 X-Rite 色度计/分光仪。 除了可在短时间内提供可靠的校正外,Palette ...
"Android颜色拾取Palette"是一个强大的工具,它允许开发者从图像中提取主要和次要的颜色,并将这些颜色应用到应用程序的不同元素上,如状态栏、标题栏、ToolBar等,以实现更加美观且一致的视觉效果。这个功能尤其...
《Android 5.x—Palette 深度解析与实践》 在Android开发中,我们经常需要处理图片资源,而Android 5.x引入了一个强大的新工具——Palette,它可以帮助开发者从图像中提取关键颜色,用于界面主题的动态设定,提供更...
在Android开发中,`Palette`是Google在API Level 21(Android 5.0 Lollipop)引入的一个重要工具类,用于从Bitmap图像中提取出关键颜色,以便于实现与图片色调相协调的UI设计。`Palette`可以快速地分析图片,并从中...
【标题】"PaletteDemo"揭示了Android开发中的一个重要概念,即Palette库的使用。Palette是Android SDK中的一个工具,主要用于从图像中提取出主要的颜色,帮助开发者创建与图像色彩协调的UI界面。这个Demo旨在展示...
在Android开发中,`Palette`和`RoundedBitmapDrawable`是两个非常实用的工具,尤其在处理图像资源和用户界面的视觉效果时。`Palette`主要用于从图片中提取颜色,以便自定义UI组件的颜色风格,而`...
palette的jar包,放在libs目录里面,build path就可以使用了
Android Studio是Google官方推荐的集成开发环境(IDE),对于实现Material Design提供了强大的支持。本文将深入探讨如何在Android应用中实现Material Design中的两个关键组件:Toolbar和Palette,并结合...
一个集成RecyclerView+CardView+Palette的Demo
【标题】:Palette实现原理与ViewPager应用详解 在Android开发中,我们常常需要从图片中提取出主要的颜色,以适应界面的主题或者作为界面的色彩基础。这就是Android提供的Palette库的作用,它可以从Bitmap中提取出...
此外,Palette还支持回调机制,可以注册一个回调监听器,当生成过程完成时会得到通知: ```java palette.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { ...
`swift-iOS图片精确提取主色调算法iOS-Palette`项目提供了一种高效的方法来实现这一功能,尤其适用于Swift开发者。这个项目的核心是通过算法分析图像像素,找出最能代表图片整体色彩的主色调。 iOS-Palette库使用了...
此外,`Palette`库也支持自定义颜色采样和调整。例如,你可以通过设置`Swatch`的数量和色调范围来定制颜色提取过程: ```java Palette.Builder builder = Palette.from(bitmap); buildermaximumColorCount(6); // ...
**阴影(Shadows)**是Material Design中的核心元素之一,它为UI组件增加了深度感。Android 5.X引入了`CardView`和`RecyclerView`等组件,它们自然地支持阴影效果。`CardView`通过设置`cardElevation`属性,可以为...
`Palette`库是Android SDK提供的一种工具,用于从图像中提取关键颜色并将其应用于UI元素,从而实现与图像色彩协调一致的界面设计。本文将深入探讨如何使用`Palette`进行图片渲染,以及在实际应用中的技巧。 ### `...
这个"Android 5.0 新组件Demo"是针对这些改进的一个实践示例,让我们来深入探讨其中的核心组件:RecyclerView、CardView和Palette。 1. **RecyclerView**:RecyclerView是Android 5.0引入的替代ListView的视图组件...
palette.js 是一个能够识别图像、图表、制图中色彩颜色元素的插件,还能输出颜色的 RGB 值。 标签:palette 分享 window._bd_share_config = ...
android-support-v7-palette 工具库
android-support-v7-palette.jar