BaNg@taobao

          Just Do It!

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            20 Posts :: -1 Stories :: 202 Comments :: 0 Trackbacks

          公告



          常用鏈接

          留言簿(33)

          我參與的團(tuán)隊(duì)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          最近發(fā)現(xiàn)一個(gè)很怪的問題,GEF的PaletteGroup在3.3及以下都有border,而在3.4卻消失了,我覺得好像是GEF 3.4 PaletteViewer的開發(fā)者Hudson和Shah認(rèn)為不可見的邊框更“友好”,可是好多人都不習(xí)慣了,覺得是bug了,在給gef newsgroup上一個(gè)人回答問題的時(shí)候順便把這個(gè)hack了一下,效果還不錯(cuò),哈哈!下面是步驟:

          1 定義一個(gè)HackedGroupEditPart:

          import org.eclipse.draw2d.ColorConstants;
          import org.eclipse.draw2d.Graphics;
          import org.eclipse.draw2d.IFigure;
          import org.eclipse.draw2d.MarginBorder;
          import org.eclipse.draw2d.geometry.Insets;
          import org.eclipse.draw2d.geometry.Rectangle;
          import org.eclipse.gef.internal.ui.palette.editparts.GroupEditPart;
          import org.eclipse.gef.palette.PaletteContainer;
          import org.eclipse.jface.action.Separator;

          public class HackedGroupEditPart extends GroupEditPart {

              
          public HackedGroupEditPart(PaletteContainer group) {
                  
          super(group);
              }
              @Override
              
          protected void refreshVisuals() {
                  
          super.refreshVisuals();
                  Insets insets 
          = getContentPane().getBorder().getInsets(getContentPane());
                  getContentPane().setBorder(
          new MarginBorder(insets){
                      @Override
                      
          public void paint(IFigure figure, Graphics graphics, Insets insets) {
                          Rectangle r 
          = getPaintRectangle(figure, insets);
                          r.height
          --;
                          graphics.setForegroundColor(ColorConstants.buttonDarker);
                          graphics.drawLine(r.x, r.bottom(), r.right(), r.bottom());
                      }
                  });
              }
              
          }

          2 使用這個(gè)加了邊框的GroupEditPart,在編輯器定義里面重寫 createPaletteViewerProvider 方法,如下:

          public class LivingEditor extends GraphicalEditorWithFlyoutPalette {
          .
          .
          @Override
          protected PaletteViewerProvider createPaletteViewerProvider() {
                  
          return new PaletteViewerProvider(getEditDomain())
                  {
                      @Override
                      
          public PaletteViewer createPaletteViewer(Composite parent) {
                          
                          
          //add border for GroupEditPart
                          final PaletteEditPartFactory pepf = new PaletteEditPartFactory()
                          {
                              @Override
                              
          protected EditPart createGroupEditPart(
                                      EditPart parentEditPart, Object model) {
                                  
          return new HackedGroupEditPart((PaletteContainer)model);
                              }
                          };
                          PaletteViewer pViewer 
          = new PaletteViewer(){
                              {
                                  setEditPartFactory(pepf);
                              }
                          };
                          pViewer.createControl(parent);
                          configurePaletteViewer(pViewer);
                          hookPaletteViewer(pViewer);
                          
          return pViewer;
                      }
                  };
              }


          }

          我的Palette定義,使用了三個(gè)PaletteGroup,但不改一下根本看不出來group之間的分隔

          public class PaletteProvider {

              
          public static PaletteRoot provide(LivingEditor livingEditor) {
                  PaletteRoot root 
          = new PaletteRoot();
                  createStandardTool(root);
                  createConnectionTool(root);
                  createModelTool(root);
                  
          return root;
              }

              
          private static void createModelTool(PaletteRoot root) {
                  PaletteGroup model_group 
          = new PaletteGroup("model");
                  CombinedTemplateCreationEntry person_entry 
          = new CombinedTemplateCreationEntry("Person",
                          
          "Create a person",
                          
          new SimpleFactory(Person.class),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/person16.png"),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/person24.png")
                          );
                  model_group.add(person_entry);
                  CombinedTemplateCreationEntry dog_entry 
          = new CombinedTemplateCreationEntry("Dog",
                          
          "Create a dog",
                          
          new SimpleFactory(Dog.class),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/dog16.gif"),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/dog24.gif"));
                  model_group.add(dog_entry);
                  root.add(model_group);
              }

              
          private static void createConnectionTool(PaletteRoot root) {
                  ConnectionCreationToolEntry relation 
          = new ConnectionCreationToolEntry("relation",
                          
          "relation between person and dog",
                          
          new SimpleFactory(Relation.class),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/connection16.gif"),
                          Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, 
          "icon/connection24.gif")
                          );
                  PaletteGroup conn_group 
          = new PaletteGroup("relations");
                  conn_group.add(relation);
                  root.add(conn_group);
                  
              }

              
          private static void createStandardTool(PaletteRoot root) {
                  PaletteGroup std 
          = new PaletteGroup("Standard");
                  SelectionToolEntry selection 
          = new SelectionToolEntry();
                  std.add(selection);
                  
                  root.add(std);
              }

          可以看一下修改后的對(duì)比:



          不過這種方法使用了internal API,不適應(yīng)版本更新,只適合救急。我已經(jīng)報(bào)告了這個(gè)誤會(huì),3.5應(yīng)該不會(huì)有了。

          如果你也有這個(gè)困擾,就試試吧。



          posted on 2008-08-17 22:40 Always BaNg. 閱讀(1872) 評(píng)論(0)  編輯  收藏 所屬分類: JavaEclipse源代碼分析
          主站蜘蛛池模板: 多伦县| 临颍县| 东乡族自治县| 康乐县| 璧山县| 茶陵县| 南涧| 清水河县| 陆川县| 华坪县| 扎鲁特旗| 隆尧县| 安徽省| 武平县| 尉氏县| 宣城市| 上犹县| 海城市| 平谷区| 云龙县| 博客| 中西区| 宝鸡市| 凭祥市| 怀宁县| 南皮县| 喜德县| 辽阳市| 沈阳市| 大埔区| 儋州市| 阿拉善盟| 博白县| 大宁县| 桂东县| 曲阳县| 南通市| 汉川市| 兴安县| 军事| 鹿泉市|