GEF理解系列四(2)

二、添加调色板

到现在为止,我们完成的都是静态创建模型。还没动态创建过。要动态创建就要用到调色板了。所以现在是时候添加调色板元素了。

要添加调色板,我们就要回到Editor类里,看Editor中默认要实现的另一个方法:getPaletteRoot()。

这个方法就是用来完成调色板内容的。这个没什么可以多讲的。这里直接给出例子:

      @Override

      protected PaletteRoot getPaletteRoot() {

            PaletteRoot root = new PaletteRoot();

            PaletteGroup selectionGroup = new PaletteGroup("Selections");

            selectionGroup.add(new SelectionToolEntry());

            selectionGroup.add(new MarqueeToolEntry());

 

            ConnectionCreationToolEntry plainConnection = new ConnectionCreationToolEntry(

                        "plain", "this is plain connection", new SimpleFactory(

                                    PlainConnectionModel.class), Activator

                                    .getImageDescriptor("icons/plaintline.gif"), Activator

                                    .getImageDescriptor("icons/plaintline.gif"));

 

            selectionGroup.add(plainConnection);

 

            root.add(selectionGroup);

 

            PaletteDrawer drawer = new PaletteDrawer("Elements");

            CreationToolEntry helloWorld = new CreationToolEntry("HelloWorld",

                        "This is hello world creation tool", new SimpleFactory(

                                    HelloWorldModel.class), Activator

                                    .getImageDescriptor("icons/alt_window_16.gif"),

                        Activator.getImageDescriptor("icons/alt_window_16.gif"));

            drawer.add(helloWorld);

           

            root.add(drawer);

            return root;

      }

我们添加了两个选择工具,一个连接工具,和一个HelloWorld元素创建工具。如下:

palette1

图二

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值