如何自定义RCP外观

博客介绍了改变Eclipse RCP皮肤及自定义外观的方法。改变皮肤可参照IBM上的Eclipse程序界面美化技术;自定义外观需用到presentationFactories,文中给出了Presentation类等代码示例,还提供了在plugin.xml和ini文件中调用的两种方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自:http://www.fengfly.com/plus/view-168171-1.html

 

如果说只需要改变RCP的皮肤可以参照IBM上的Eclipse程序界面美化技术
http://www.fengfly.com/plus/view-168476-1.html
如 果想自定义RCP的外观就得用到presentationFactories,presentationFactories是eclipse为 editor以及view提供的一个外观工厂,在eclipse官网上推荐的书中就提到过这么个工厂,今天再看MP3MANAGER源代码的时候发现实现 起来也挺简单的,不过我还是习惯eclipse风格,所以没将应用的外观改变,之前也一直在寻找改变RCP外观的方法,昨天网友告诉我IBM上有我就去看 了下,就是简单的变换了图片和背景颜色,也就是个SWT的皮肤而已,下面我就直接贴代码演示presentationFactories的实现方法
首 先就是Presentation 类:

Java代码
  1. /*******************************************************************************  
  2.  * Copyright (c) 2009 Siemens AG  
  3.  *   
  4.  * All rights reserved. This program and the accompanying materials  
  5.  * are made available under the terms of the Eclipse Public License v1.0  
  6.  * which accompanies this distribution, and is available at  
  7.  * http://www.eclipse.org/legal/epl-v10.html  
  8.  *  
  9.  * Contributors:  
  10.  *    Kai T枚 dter - initial API and implementation  
  11.  *******************************************************************************/   
  12.   
  13. package  com.siemens.ct.mp3m.ui.presentation;   
  14.   
  15. import  org.eclipse.swt.SWT;   
  16. import  org.eclipse.swt.events.DisposeEvent;   
  17. import  org.eclipse.swt.events.DisposeListener;   
  18. import  org.eclipse.swt.events.PaintEvent;   
  19. import  org.eclipse.swt.events.PaintListener;   
  20. import  org.eclipse.swt.graphics.Color;   
  21. import  org.eclipse.swt.graphics.GC;   
  22. import  org.eclipse.swt.graphics.Point;   
  23. import  org.eclipse.swt.graphics.Rectangle;   
  24. import  org.eclipse.swt.widgets.Composite;   
  25. import  org.eclipse.swt.widgets.Control;   
  26. import  org.eclipse.ui.IPropertyListener;   
  27. import  org.eclipse.ui.presentations.IPresentablePart;   
  28. import  org.eclipse.ui.presentations.IStackPresentationSite;   
  29. import  org.eclipse.ui.presentations.StackDropResult;   
  30. import  org.eclipse.ui.presentations.StackPresentation;   
  31.   
  32. public   class  Presentation  extends  StackPresentation {   
  33.   
  34.      private  Color borderColor;   
  35.   
  36.      private  IPresentablePart current;   
  37.   
  38.      private   final  PaintListener paintListener =  new  PaintListener() {   
  39.   
  40.          public   void  paintControl( final  PaintEvent e) {   
  41.              final  Rectangle clientArea = presentationControl.getClientArea();   
  42.              // Image img = new Image(e.display, clientArea.width,   
  43.              // clientArea.height);   
  44.              // GC gc = new GC(img);   
  45.              final  GC gc = e.gc;   
  46.   
  47.              final   int  border =  1 ;   
  48.             gc.setLineWidth(border);   
  49.             gc.setForeground(borderColor);   
  50.             gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - border,   
  51.                     clientArea.height - border);   
  52.   
  53.              // e.gc.drawImage(img, 0, 0);   
  54.              // gc.dispose();   
  55.              // img.dispose();   
  56.   
  57.         }   
  58.     };   
  59.   
  60.      /**  
  61.      * Listener attached to all child parts. It responds to changes in part  
  62.      * properties  
  63.      */   
  64.      private   final  IPropertyListener partPropertyChangeListener =  new  IPropertyListener() {   
  65.   
  66.          public   void  propertyChanged( final  Object source,  final   int  property) {   
  67.   
  68.              if  (source  instanceof  IPresentablePart) {   
  69.                 redraw();   
  70.             }   
  71.         }   
  72.     };   
  73.   
  74.      private  Composite presentationControl;   
  75.   
  76.      private  TabContainer tabContainer;   
  77.   
  78.      private  Title titleBar;   
  79.   
  80.      private  Color toolBarColor;   
  81.   
  82.      public  Presentation( final  Composite parent,  final  IStackPresentationSite site) {   
  83.          super (site);   
  84.          // Create a top-level control for the presentation.   
  85.         presentationControl =  new  Composite(parent, SWT.NONE);   
  86.         borderColor =  new  Color(presentationControl.getDisplay(),  50 50 50 );   
  87.         toolBarColor =  new  Color(presentationControl.getDisplay(),  203 220 235 );   
  88.   
  89.         presentationControl.addPaintListener(paintListener);   
  90.   
  91.         titleBar =  new  Title(presentationControl, SWT.NONE, getSite());   
  92.         tabContainer =  new  TabContainer(presentationControl, SWT.NONE);   
  93.   
  94.          /*  
  95.          * Add a dispose listener. Important because dispose() may // not always  
  96.          * be called.  
  97.          */   
  98.         presentationControl.addDisposeListener( new  DisposeListener() {   
  99.   
  100.              public   void  widgetDisposed( final  DisposeEvent e) {   
  101.                 presentationDisposed();   
  102.             }   
  103.         });   
  104.   
  105.     }   
  106.   
  107.      protected  Presentation( final  IStackPresentationSite stackSite) {   
  108.          super (stackSite);   
  109.          // TODO Auto-generated constructor stub   
  110.     }   
  111.   
  112.      @Override   
  113.      public   void  addPart( final  IPresentablePart newPart,  final  Object cookie) {   
  114.         newPart.addPropertyListener(partPropertyChangeListener);   
  115.         tabContainer.addPart(newPart,  this , getSite());   
  116.     }   
  117.   
  118.      @Override   
  119.      public   int  computePreferredSize( final   boolean  width,  final   int  availableParallel,   
  120.              final   int  availablePerpendicular,  final   int  preferredResult) {   
  121.          if  (width) {   
  122.              return  Math.max(preferredResult,  100 );   
  123.         }  else  {   
  124.              return  tabContainer.getHeight() + titleBar.getHeight();   
  125.         }   
  126.     }   
  127.   
  128.      @Override   
  129.      public   void  dispose() {   
  130.         presentationDisposed();   
  131.     }   
  132.   
  133.      @Override   
  134.      public  StackDropResult dragOver( final  Control currentControl,  final  Point location) {   
  135.          // TODO Auto-generated method stub   
  136.          return   null ;   
  137.     }   
  138.   
  139.      /**  
  140.      * Gets the colorBorder.  
  141.      *   
  142.      * @return Returns the colorBorder.  
  143.      */   
  144.      public  Color getColorBorder() {   
  145.          return  borderColor;   
  146.     }   
  147.   
  148.      @Override   
  149.      public  Control getControl() {   
  150.          return  presentationControl;   
  151.     }   
  152.   
  153.      @Override   
  154.      public  Control[] getTabList( final  IPresentablePart part) {   
  155.          return   new  Control[] { part.getControl() };   
  156.     }   
  157.   
  158.      @Override   
  159.      public   void  removePart( final  IPresentablePart oldPart) {   
  160.         oldPart.removePropertyListener(partPropertyChangeListener);   
  161.         tabContainer.removePart(oldPart);   
  162.         titleBar.removePart(oldPart);   
  163.          if  (current == oldPart) {   
  164.             current =  null ;   
  165.         }   
  166.         redraw();   
  167.     }   
  168.   
  169.      @Override   
  170.      public   void  selectPart( final  IPresentablePart toSelect) {   
  171.          // Ignore redundant selections   
  172.          if  (toSelect == current) {   
  173.              return ;   
  174.         }   
  175.   
  176.          // If there was an existing part selected, make it invisible   
  177.          if  (current !=  null ) {   
  178.             current.setVisible( false );   
  179.         }   
  180.          // Select the new part   
  181.         current = toSelect;   
  182.   
  183.          // Make the part visible before setBounds, or the call to setBounds   
  184.          // may be ignored.   
  185.          if  (current !=  null ) {   
  186.             current.setVisible( true );   
  187.             setBounds(presentationControl.getBounds());   
  188.             titleBar.setPresentablePart(current);   
  189.             tabContainer.setPresentablePart(current);   
  190.         }   
  191.     }   
  192.   
  193.      @Override   
  194.      public   void  setActive( final   int  newState) {   
  195.          // TODO Auto-generated method stub   
  196.   
  197.     }   
  198.   
  199.      @Override   
  200.      public   void  setBounds( final  Rectangle bounds) {   
  201.          // Set the bounds of the presentation widget   
  202.         presentationControl.setBounds(bounds);   
  203.   
  204.          final   int  titlebarHeight = titleBar.getHeight();   
  205.          final  Rectangle clientArea = presentationControl.getClientArea();   
  206.         titleBar   
  207.                 .setBounds(clientArea.x +  1 , clientArea.y +  1 , clientArea.width -  2 , titlebarHeight);   
  208.          final   int  tabPaneHeight = tabContainer.getHeight();   
  209.         tabContainer.setBounds(clientArea.x, clientArea.y + clientArea.height - tabPaneHeight,   
  210.                 clientArea.width, tabPaneHeight);   
  211.          if  (current !=  null ) {   
  212.              final  Rectangle contentArea = presentationControl.getBounds();   
  213.              int  toolBarHeight =  0 ;   
  214.              final  Control toolBar = current.getToolBar();   
  215.              if  (toolBar !=  null ) {   
  216.                 toolBar.setBackground(toolBarColor);   
  217.                 toolBarHeight = toolBar.getBounds().height;   
  218.                 toolBar.setBounds(clientArea.x +  1 , clientArea.y +  1  + titlebarHeight,   
  219.                         clientArea.width -  2 , toolBarHeight);   
  220.             }   
  221.             contentArea.x +=  1 ;   
  222.             contentArea.y += titlebarHeight + toolBarHeight;   
  223.             contentArea.width -=  2 ;   
  224.             contentArea.height -= titlebarHeight + tabPaneHeight + toolBarHeight;   
  225.              if  (tabPaneHeight ==  0 ) {   
  226.                 contentArea.height -=  1 ;   
  227.             }   
  228.             current.setBounds(contentArea);   
  229.         }   
  230.     }   
  231.   
  232.      @Override   
  233.      public   void  setState( final   int  state) {   
  234.          // TODO Auto-generated method stub   
  235.   
  236.     }   
  237.   
  238.      @Override   
  239.      public   void  setVisible( final   boolean  isVisible) {   
  240.          // Make the presentation widget visible   
  241.         presentationControl.setVisible(isVisible);   
  242.         titleBar.setVisible(isVisible);   
  243.   
  244.          // Make the currently visible part visible   
  245.          if  (current !=  null ) {   
  246.             current.setVisible(isVisible);   
  247.   
  248.              if  (isVisible) {   
  249.                  // Restore the bounds of the currently visible part.   
  250.                  // IPartPresentations can be used by multiple   
  251.                  // StackPresentations,   
  252.                  // although only one such presentation is ever visible at a   
  253.                  // time.   
  254.                  // It is possible that some other presentation has changed the   
  255.                  // bounds of the part since it was last visible, so we need to   
  256.                  // update the part's bounds when the presentation becomes   
  257.                  // visible.   
  258.   
  259.                 setBounds(presentationControl.getBounds());   
  260.             }   
  261.         }   
  262.     }   
  263.   
  264.      @Override   
  265.      public   void  showPaneMenu() {   
  266.          // TODO Auto-generated method stub   
  267.     }   
  268.   
  269.      @Override   
  270.      public   void  showSystemMenu() {   
  271.          // TODO Auto-generated method stub   
  272.     }   
  273.   
  274.      protected   void  presentationDisposed() {   
  275.          // Remove any listeners that were attached to any   
  276.          // global Eclipse resources. This is necessary in order to prevent   
  277.          // memory leaks.   
  278.         borderColor.dispose();   
  279.         toolBarColor.dispose();   
  280.         presentationControl.removePaintListener(paintListener);   
  281.         presentationControl.dispose();   
  282.         presentationControl =  null ;   
  283.     }   
  284.   
  285.      protected   void  redraw() {   
  286.          if  (presentationControl !=  null ) {   
  287.             presentationControl.redraw();   
  288.             titleBar.redraw();   
  289.             tabContainer.redraw();   
  290.         }   
  291.     }   
  292. }  
/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai T枚dter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackDropResult;
import org.eclipse.ui.presentations.StackPresentation;

public class Presentation extends StackPresentation {

    private Color borderColor;

    private IPresentablePart current;

    private final PaintListener paintListener = new PaintListener() {

        public void paintControl(final PaintEvent e) {
            final Rectangle clientArea = presentationControl.getClientArea();
            // Image img = new Image(e.display, clientArea.width,
            // clientArea.height);
            // GC gc = new GC(img);
            final GC gc = e.gc;

            final int border = 1;
            gc.setLineWidth(border);
            gc.setForeground(borderColor);
            gc.drawRectangle(clientArea.x, clientArea.y, clientArea.width - border,
                    clientArea.height - border);

            // e.gc.drawImage(img, 0, 0);
            // gc.dispose();
            // img.dispose();

        }
    };

    /**
     * Listener attached to all child parts. It responds to changes in part
     * properties
     */
    private final IPropertyListener partPropertyChangeListener = new IPropertyListener() {

        public void propertyChanged(final Object source, final int property) {

            if (source instanceof IPresentablePart) {
                redraw();
            }
        }
    };

    private Composite presentationControl;

    private TabContainer tabContainer;

    private Title titleBar;

    private Color toolBarColor;

    public Presentation(final Composite parent, final IStackPresentationSite site) {
        super(site);
        // Create a top-level control for the presentation.
        presentationControl = new Composite(parent, SWT.NONE);
        borderColor = new Color(presentationControl.getDisplay(), 50, 50, 50);
        toolBarColor = new Color(presentationControl.getDisplay(), 203, 220, 235);

        presentationControl.addPaintListener(paintListener);

        titleBar = new Title(presentationControl, SWT.NONE, getSite());
        tabContainer = new TabContainer(presentationControl, SWT.NONE);

        /*
         * Add a dispose listener. Important because dispose() may // not always
         * be called.
         */
        presentationControl.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(final DisposeEvent e) {
                presentationDisposed();
            }
        });

    }

    protected Presentation(final IStackPresentationSite stackSite) {
        super(stackSite);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void addPart(final IPresentablePart newPart, final Object cookie) {
        newPart.addPropertyListener(partPropertyChangeListener);
        tabContainer.addPart(newPart, this, getSite());
    }

    @Override
    public int computePreferredSize(final boolean width, final int availableParallel,
            final int availablePerpendicular, final int preferredResult) {
        if (width) {
            return Math.max(preferredResult, 100);
        } else {
            return tabContainer.getHeight() + titleBar.getHeight();
        }
    }

    @Override
    public void dispose() {
        presentationDisposed();
    }

    @Override
    public StackDropResult dragOver(final Control currentControl, final Point location) {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * Gets the colorBorder.
     * 
     * @return Returns the colorBorder.
     */
    public Color getColorBorder() {
        return borderColor;
    }

    @Override
    public Control getControl() {
        return presentationControl;
    }

    @Override
    public Control[] getTabList(final IPresentablePart part) {
        return new Control[] { part.getControl() };
    }

    @Override
    public void removePart(final IPresentablePart oldPart) {
        oldPart.removePropertyListener(partPropertyChangeListener);
        tabContainer.removePart(oldPart);
        titleBar.removePart(oldPart);
        if (current == oldPart) {
            current = null;
        }
        redraw();
    }

    @Override
    public void selectPart(final IPresentablePart toSelect) {
        // Ignore redundant selections
        if (toSelect == current) {
            return;
        }

        // If there was an existing part selected, make it invisible
        if (current != null) {
            current.setVisible(false);
        }
        // Select the new part
        current = toSelect;

        // Make the part visible before setBounds, or the call to setBounds
        // may be ignored.
        if (current != null) {
            current.setVisible(true);
            setBounds(presentationControl.getBounds());
            titleBar.setPresentablePart(current);
            tabContainer.setPresentablePart(current);
        }
    }

    @Override
    public void setActive(final int newState) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setBounds(final Rectangle bounds) {
        // Set the bounds of the presentation widget
        presentationControl.setBounds(bounds);

        final int titlebarHeight = titleBar.getHeight();
        final Rectangle clientArea = presentationControl.getClientArea();
        titleBar
                .setBounds(clientArea.x + 1, clientArea.y + 1, clientArea.width - 2, titlebarHeight);
        final int tabPaneHeight = tabContainer.getHeight();
        tabContainer.setBounds(clientArea.x, clientArea.y + clientArea.height - tabPaneHeight,
                clientArea.width, tabPaneHeight);
        if (current != null) {
            final Rectangle contentArea = presentationControl.getBounds();
            int toolBarHeight = 0;
            final Control toolBar = current.getToolBar();
            if (toolBar != null) {
                toolBar.setBackground(toolBarColor);
                toolBarHeight = toolBar.getBounds().height;
                toolBar.setBounds(clientArea.x + 1, clientArea.y + 1 + titlebarHeight,
                        clientArea.width - 2, toolBarHeight);
            }
            contentArea.x += 1;
            contentArea.y += titlebarHeight + toolBarHeight;
            contentArea.width -= 2;
            contentArea.height -= titlebarHeight + tabPaneHeight + toolBarHeight;
            if (tabPaneHeight == 0) {
                contentArea.height -= 1;
            }
            current.setBounds(contentArea);
        }
    }

    @Override
    public void setState(final int state) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setVisible(final boolean isVisible) {
        // Make the presentation widget visible
        presentationControl.setVisible(isVisible);
        titleBar.setVisible(isVisible);

        // Make the currently visible part visible
        if (current != null) {
            current.setVisible(isVisible);

            if (isVisible) {
                // Restore the bounds of the currently visible part.
                // IPartPresentations can be used by multiple
                // StackPresentations,
                // although only one such presentation is ever visible at a
                // time.
                // It is possible that some other presentation has changed the
                // bounds of the part since it was last visible, so we need to
                // update the part's bounds when the presentation becomes
                // visible.

                setBounds(presentationControl.getBounds());
            }
        }
    }

    @Override
    public void showPaneMenu() {
        // TODO Auto-generated method stub
    }

    @Override
    public void showSystemMenu() {
        // TODO Auto-generated method stub
    }

    protected void presentationDisposed() {
        // Remove any listeners that were attached to any
        // global Eclipse resources. This is necessary in order to prevent
        // memory leaks.
        borderColor.dispose();
        toolBarColor.dispose();
        presentationControl.removePaintListener(paintListener);
        presentationControl.dispose();
        presentationControl = null;
    }

    protected void redraw() {
        if (presentationControl != null) {
            presentationControl.redraw();
            titleBar.redraw();
            tabContainer.redraw();
        }
    }
}


然后就是生产Presentation 的工厂:

Java代码
  1. /*******************************************************************************  
  2.  * Copyright (c) 2009 Siemens AG  
  3.  *   
  4.  * All rights reserved. This program and the accompanying materials  
  5.  * are made available under the terms of the Eclipse Public License v1.0  
  6.  * which accompanies this distribution, and is available at  
  7.  * http://www.eclipse.org/legal/epl-v10.html  
  8.  *  
  9.  * Contributors:  
  10.  *    Kai T枚 dter - initial API and implementation  
  11.  *******************************************************************************/   
  12.   
  13. package  com.siemens.ct.mp3m.ui.presentation;   
  14.   
  15. import  org.eclipse.swt.widgets.Composite;   
  16. import  org.eclipse.ui.presentations.AbstractPresentationFactory;   
  17. import  org.eclipse.ui.presentations.IStackPresentationSite;   
  18. import  org.eclipse.ui.presentations.StackPresentation;   
  19.   
  20. public   class  PresentationFactory  extends  AbstractPresentationFactory {   
  21.      public  StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site) {   
  22.          return   new  Presentation(parent, site);   
  23.     }   
  24.   
  25.      public  StackPresentation createViewPresentation(Composite parent, IStackPresentationSite site) {   
  26.          return   new  Presentation(parent, site);   
  27.     }   
  28.   
  29.      public  StackPresentation createStandaloneViewPresentation(Composite parent,   
  30.             IStackPresentationSite site,  boolean  showTitle) {   
  31.          return   new  Presentation(parent, site);   
  32.     }   
  33. }  
/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai T枚dter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.presentations.AbstractPresentationFactory;
import org.eclipse.ui.presentations.IStackPresentationSite;
import org.eclipse.ui.presentations.StackPresentation;

public class PresentationFactory extends AbstractPresentationFactory {
    public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site) {
        return new Presentation(parent, site);
    }

    public StackPresentation createViewPresentation(Composite parent, IStackPresentationSite site) {
        return new Presentation(parent, site);
    }

    public StackPresentation createStandaloneViewPresentation(Composite parent,
            IStackPresentationSite site, boolean showTitle) {
        return new Presentation(parent, site);
    }
}


辅助类:

Java代码
  1. /*******************************************************************************  
  2.  * Copyright (c) 2009 Siemens AG  
  3.  *   
  4.  * All rights reserved. This program and the accompanying materials  
  5.  * are made available under the terms of the Eclipse Public License v1.0  
  6.  * which accompanies this distribution, and is available at  
  7.  * http://www.eclipse.org/legal/epl-v10.html  
  8.  *  
  9.  * Contributors:  
  10.  *    Kai T枚 dter - initial API and implementation  
  11.  *******************************************************************************/   
  12.   
  13. package  com.siemens.ct.mp3m.ui.presentation;   
  14.   
  15. import  java.util.ArrayList;   
  16. import  java.util.List;   
  17.   
  18. import  org.eclipse.swt.widgets.Composite;   
  19. import  org.eclipse.ui.presentations.IPresentablePart;   
  20. import  org.eclipse.ui.presentations.IStackPresentationSite;   
  21.   
  22. public   class  TabContainer  extends  Composite {   
  23.   
  24.      protected  List<Tab> tabItems =  new  ArrayList<Tab>();   
  25.   
  26.      protected  IPresentablePart part;   
  27.   
  28.      protected   int  style;   
  29.   
  30.      public  TabContainer(Composite parent,  int  style) {   
  31.          super (parent, style);   
  32.          this .style = style;   
  33.     }   
  34.   
  35.      public   void  addPart(IPresentablePart part, Presentation presentation,   
  36.             IStackPresentationSite site) {   
  37.         Tab tab =  new  Tab( this , style, presentation, site);   
  38.         tab.setPresentablePart(part);   
  39.         tabItems.add(tab);   
  40.         redraw();   
  41.     }   
  42.   
  43.      public   void  setPresentablePart(IPresentablePart part) {   
  44.          this .part = part;   
  45.          for  (Tab b : tabItems) {   
  46.             b.setSected(b.checkPart(part));   
  47.         }   
  48.         redraw();   
  49.     }   
  50.   
  51.      public   int  getHeight() {   
  52.          if  (tabItems.size() <  2 ) {   
  53.              return   0 ;   
  54.         }   
  55.          return  tabItems.size() * tabItems.get( 0 ).getHeight() - tabItems.size() +  1 ;   
  56.     }   
  57.   
  58.      @Override   
  59.      public   void  setBounds( int  x,  int  y,  int  width,  int  height) {   
  60.          int  y2 =  0 ;   
  61.          int  h =  21 ;   
  62.          for  (Tab b : tabItems) {   
  63.             b.setBounds(x, y2, width, h);   
  64.             y2 +=  20 ;   
  65.         }   
  66.          super .setBounds(x, y, width, height);   
  67.     }   
  68.   
  69.      public   void  redraw() {   
  70.          if  (tabItems.size() <  2 ) {   
  71.              return ;   
  72.         }   
  73.          for  (Tab b : tabItems) {   
  74.             b.redraw();   
  75.         }   
  76.     }   
  77.   
  78.      public   void  removePart(IPresentablePart oldPart) {   
  79.         Tab foundTab =  null ;   
  80.          for  (Tab b : tabItems) {   
  81.              if  (b.getPart() == oldPart) {   
  82.                 foundTab = b;   
  83.                  break ;   
  84.             }   
  85.         }   
  86.          if  (foundTab !=  null ) {   
  87.             tabItems.remove(foundTab);   
  88.             foundTab.dispose();   
  89.         }   
  90.     }   
  91. }  
/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai T枚dter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;

public class TabContainer extends Composite {

    protected List<Tab> tabItems = new ArrayList<Tab>();

    protected IPresentablePart part;

    protected int style;

    public TabContainer(Composite parent, int style) {
        super(parent, style);
        this.style = style;
    }

    public void addPart(IPresentablePart part, Presentation presentation,
            IStackPresentationSite site) {
        Tab tab = new Tab(this, style, presentation, site);
        tab.setPresentablePart(part);
        tabItems.add(tab);
        redraw();
    }

    public void setPresentablePart(IPresentablePart part) {
        this.part = part;
        for (Tab b : tabItems) {
            b.setSected(b.checkPart(part));
        }
        redraw();
    }

    public int getHeight() {
        if (tabItems.size() < 2) {
            return 0;
        }
        return tabItems.size() * tabItems.get(0).getHeight() - tabItems.size() + 1;
    }

    @Override
    public void setBounds(int x, int y, int width, int height) {
        int y2 = 0;
        int h = 21;
        for (Tab b : tabItems) {
            b.setBounds(x, y2, width, h);
            y2 += 20;
        }
        super.setBounds(x, y, width, height);
    }

    public void redraw() {
        if (tabItems.size() < 2) {
            return;
        }
        for (Tab b : tabItems) {
            b.redraw();
        }
    }

    public void removePart(IPresentablePart oldPart) {
        Tab foundTab = null;
        for (Tab b : tabItems) {
            if (b.getPart() == oldPart) {
                foundTab = b;
                break;
            }
        }
        if (foundTab != null) {
            tabItems.remove(foundTab);
            foundTab.dispose();
        }
    }
}

 

Java代码
  1. /*******************************************************************************  
  2.  * Copyright (c) 2009 Siemens AG  
  3.  *   
  4.  * All rights reserved. This program and the accompanying materials  
  5.  * are made available under the terms of the Eclipse Public License v1.0  
  6.  * which accompanies this distribution, and is available at  
  7.  * http://www.eclipse.org/legal/epl-v10.html  
  8.  *  
  9.  * Contributors:  
  10.  *    Kai T枚 dter - initial API and implementation  
  11.  *******************************************************************************/   
  12.   
  13. package  com.siemens.ct.mp3m.ui.presentation;   
  14.   
  15. import  org.eclipse.swt.SWT;   
  16. import  org.eclipse.swt.events.MouseAdapter;   
  17. import  org.eclipse.swt.events.MouseEvent;   
  18. import  org.eclipse.swt.events.MouseListener;   
  19. import  org.eclipse.swt.events.PaintEvent;   
  20. import  org.eclipse.swt.events.PaintListener;   
  21. import  org.eclipse.swt.graphics.Color;   
  22. import  org.eclipse.swt.graphics.Font;   
  23. import  org.eclipse.swt.graphics.GC;   
  24. import  org.eclipse.swt.graphics.Image;   
  25. import  org.eclipse.swt.graphics.Rectangle;   
  26. import  org.eclipse.swt.widgets.Composite;   
  27. import  org.eclipse.ui.presentations.IPresentablePart;   
  28. import  org.eclipse.ui.presentations.IStackPresentationSite;   
  29.   
  30. public   class  Tab  extends  AbstractClosable  implements  PaintListener {   
  31.   
  32.      private   final  Presentation presentation;   
  33.   
  34.      private   final  IStackPresentationSite site;   
  35.   
  36.      protected   final  Color unselectedTop =  new  Color(getDisplay(),  250 250 250 );   
  37.   
  38.      protected   final  Color unselectedBottom =  new  Color(getDisplay(),  200 225 255 );   
  39.   
  40.      protected   final  Color selectedTop =  new  Color(getDisplay(),  250 230 150 );   
  41.   
  42.      protected   final  Color selectedBottom =  new  Color(getDisplay(),  240 155 30 );   
  43.   
  44.      protected   final  Color mouseOverTop =  new  Color(getDisplay(),  255 248 223 );   
  45.   
  46.      protected   final  Color mouseOverBottom =  new  Color(getDisplay(),  255 225 120 );   
  47.   
  48.      protected  Font font =  new  Font(getDisplay(),  "Default" 10 , SWT.NORMAL);   
  49.   
  50.      private   boolean  isSelected;   
  51.   
  52.      /**  
  53.      * This listener responds to selection events in all tabs.  
  54.      */   
  55.      private   final  MouseListener mouseListener =  new  MouseAdapter() {   
  56.          @Override   
  57.          public   void  mouseDown(MouseEvent e) {   
  58.              if  (part !=  null ) {   
  59.                 part.setFocus();   
  60.                  if  (isCloseSelected()) {   
  61.                     site.close( new  IPresentablePart[] { part });   
  62.                 }  else  {   
  63.                     site.selectPart(part);   
  64.                     presentation.selectPart(part);   
  65.                 }   
  66.             }   
  67.         }   
  68.     };   
  69.   
  70.      public  Tab(Composite parent,  int  style, Presentation presentation, IStackPresentationSite site) {   
  71.          super (parent, style | SWT.NO_BACKGROUND);   
  72.          this .presentation = presentation;   
  73.          this .site = site;   
  74.   
  75.         setSected( false );   
  76.         addPaintListener( this );   
  77.         addMouseListener(mouseListener);   
  78.     }   
  79.   
  80.      @Override   
  81.      public   void  setPresentablePart(IPresentablePart part) {   
  82.          this .part = part;   
  83.         setToolTipText(part.getTitleToolTip());   
  84.         layout();   
  85.         redraw();   
  86.     }   
  87.   
  88.      public   boolean  checkPart(IPresentablePart part) {   
  89.          return  ( this .part == part);   
  90.     }   
  91.   
  92.      public   void  setSected( boolean  selected) {   
  93.         isSelected = selected;   
  94.     }   
  95.   
  96.      /**  
  97.      * Paint the title bar  
  98.      */   
  99.      public   void  paintControl(PaintEvent e) {   
  100.         Rectangle clientArea = getBounds();   
  101.         Image img =  new  Image(e.display, clientArea.width, clientArea.height);   
  102.         GC gc =  new  GC(img);   
  103.   
  104.         gc.setForeground(presentation.getColorBorder());   
  105.         gc.drawRectangle( 0 0 , clientArea.width -  1 , clientArea.height -  1 );   
  106.   
  107.         Color colorTop;   
  108.         Color colorBottom;   
  109.   
  110.          if  (isMouseOver) {   
  111.              if  (isSelected) {   
  112.                 colorTop = selectedBottom;   
  113.                 colorBottom = selectedTop;   
  114.             }  else  {   
  115.                 colorTop = mouseOverTop;   
  116.                 colorBottom = mouseOverBottom;   
  117.             }   
  118.         }  else  {   
  119.              if  (isSelected) {   
  120.                 colorTop = selectedTop;   
  121.                 colorBottom = selectedBottom;   
  122.             }  else  {   
  123.                 colorTop = unselectedTop;   
  124.                 colorBottom = unselectedBottom;   
  125.             }   
  126.         }   
  127.         gc.setForeground(colorTop);   
  128.         gc.setBackground(colorBottom);   
  129.         gc.fillGradientRectangle( 1 1 , clientArea.width -  2 , clientArea.height -  2 true );   
  130.   
  131.          if  (part !=  null ) {   
  132.             Image partImage = part.getTitleImage();   
  133.             gc.drawImage(partImage,  2 2 );   
  134.   
  135.             Color colorText =  new  Color(getDisplay(),  0 0 0 );   
  136.              // gc.setFont(font);   
  137.             gc.setForeground(colorText);   
  138.             String dirty =  "" ;   
  139.              if  (part.isDirty()) {   
  140.                 dirty =  "*" ;   
  141.             }   
  142.              int  closeImageOffset =  0 ;   
  143.              if  (part.isCloseable()) {   
  144.                 closeImageOffset =  20 ;   
  145.             }   
  146.             String text = shortenText(gc, dirty + part.getTitle(), clientArea.width -  25   
  147.                     - closeImageOffset);   
  148.             gc.drawText(text, partImage.getBounds().width +  7 3 true );   
  149.         }   
  150.   
  151.          if  (part.isCloseable()) {   
  152.              if  (isCloseSelected) {   
  153.                 gc.drawImage(closeSelectedImage, clientArea.width -  20 3 );   
  154.             }  else  {   
  155.                 gc.drawImage(closeUnselectedImage, clientArea.width -  20 3 );   
  156.             }   
  157.         }   
  158.   
  159.         e.gc.drawImage(img,  0 0 );   
  160.         gc.dispose();   
  161.         img.dispose();   
  162.     }   
  163.   
  164.      public  IPresentablePart getPart() {   
  165.          return  part;   
  166.     }   
  167.   
  168.      public   boolean  isCloseSelected() {   
  169.          return  isCloseSelected;   
  170.     }   
  171.   
  172.      /*  
  173.      * (non-Javadoc)  
  174.      *   
  175.      * @see org.eclipse.swt.widgets.Widget#dispose()  
  176.      */   
  177.      @Override   
  178.      public   void  dispose() {   
  179.         unselectedTop.dispose();   
  180.         unselectedBottom.dispose();   
  181.         selectedTop.dispose();   
  182.         selectedBottom.dispose();   
  183.         mouseOverTop.dispose();   
  184.         mouseOverBottom.dispose();   
  185.         font.dispose();   
  186.          super .dispose();   
  187.     }   
  188. }  
/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai T枚dter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;

public class Tab extends AbstractClosable implements PaintListener {

    private final Presentation presentation;

    private final IStackPresentationSite site;

    protected final Color unselectedTop = new Color(getDisplay(), 250, 250, 250);

    protected final Color unselectedBottom = new Color(getDisplay(), 200, 225, 255);

    protected final Color selectedTop = new Color(getDisplay(), 250, 230, 150);

    protected final Color selectedBottom = new Color(getDisplay(), 240, 155, 30);

    protected final Color mouseOverTop = new Color(getDisplay(), 255, 248, 223);

    protected final Color mouseOverBottom = new Color(getDisplay(), 255, 225, 120);

    protected Font font = new Font(getDisplay(), "Default", 10, SWT.NORMAL);

    private boolean isSelected;

    /**
     * This listener responds to selection events in all tabs.
     */
    private final MouseListener mouseListener = new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent e) {
            if (part != null) {
                part.setFocus();
                if (isCloseSelected()) {
                    site.close(new IPresentablePart[] { part });
                } else {
                    site.selectPart(part);
                    presentation.selectPart(part);
                }
            }
        }
    };

    public Tab(Composite parent, int style, Presentation presentation, IStackPresentationSite site) {
        super(parent, style | SWT.NO_BACKGROUND);
        this.presentation = presentation;
        this.site = site;

        setSected(false);
        addPaintListener(this);
        addMouseListener(mouseListener);
    }

    @Override
    public void setPresentablePart(IPresentablePart part) {
        this.part = part;
        setToolTipText(part.getTitleToolTip());
        layout();
        redraw();
    }

    public boolean checkPart(IPresentablePart part) {
        return (this.part == part);
    }

    public void setSected(boolean selected) {
        isSelected = selected;
    }

    /**
     * Paint the title bar
     */
    public void paintControl(PaintEvent e) {
        Rectangle clientArea = getBounds();
        Image img = new Image(e.display, clientArea.width, clientArea.height);
        GC gc = new GC(img);

        gc.setForeground(presentation.getColorBorder());
        gc.drawRectangle(0, 0, clientArea.width - 1, clientArea.height - 1);

        Color colorTop;
        Color colorBottom;

        if (isMouseOver) {
            if (isSelected) {
                colorTop = selectedBottom;
                colorBottom = selectedTop;
            } else {
                colorTop = mouseOverTop;
                colorBottom = mouseOverBottom;
            }
        } else {
            if (isSelected) {
                colorTop = selectedTop;
                colorBottom = selectedBottom;
            } else {
                colorTop = unselectedTop;
                colorBottom = unselectedBottom;
            }
        }
        gc.setForeground(colorTop);
        gc.setBackground(colorBottom);
        gc.fillGradientRectangle(1, 1, clientArea.width - 2, clientArea.height - 2, true);

        if (part != null) {
            Image partImage = part.getTitleImage();
            gc.drawImage(partImage, 2, 2);

            Color colorText = new Color(getDisplay(), 0, 0, 0);
            // gc.setFont(font);
            gc.setForeground(colorText);
            String dirty = "";
            if (part.isDirty()) {
                dirty = "*";
            }
            int closeImageOffset = 0;
            if (part.isCloseable()) {
                closeImageOffset = 20;
            }
            String text = shortenText(gc, dirty + part.getTitle(), clientArea.width - 25
                    - closeImageOffset);
            gc.drawText(text, partImage.getBounds().width + 7, 3, true);
        }

        if (part.isCloseable()) {
            if (isCloseSelected) {
                gc.drawImage(closeSelectedImage, clientArea.width - 20, 3);
            } else {
                gc.drawImage(closeUnselectedImage, clientArea.width - 20, 3);
            }
        }

        e.gc.drawImage(img, 0, 0);
        gc.dispose();
        img.dispose();
    }

    public IPresentablePart getPart() {
        return part;
    }

    public boolean isCloseSelected() {
        return isCloseSelected;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.widgets.Widget#dispose()
     */
    @Override
    public void dispose() {
        unselectedTop.dispose();
        unselectedBottom.dispose();
        selectedTop.dispose();
        selectedBottom.dispose();
        mouseOverTop.dispose();
        mouseOverBottom.dispose();
        font.dispose();
        super.dispose();
    }
}

 

Java代码
  1. /*******************************************************************************  
  2.  * Copyright (c) 2009 Siemens AG  
  3.  *   
  4.  * All rights reserved. This program and the accompanying materials  
  5.  * are made available under the terms of the Eclipse Public License v1.0  
  6.  * which accompanies this distribution, and is available at  
  7.  * http://www.eclipse.org/legal/epl-v10.html  
  8.  *  
  9.  * Contributors:  
  10.  *    Kai T枚 dter - initial API and implementation  
  11.  *******************************************************************************/   
  12.   
  13. package  com.siemens.ct.mp3m.ui.presentation;   
  14.   
  15. import  org.eclipse.jface.resource.JFaceResources;   
  16. import  org.eclipse.swt.SWT;   
  17. import  org.eclipse.swt.events.MouseAdapter;   
  18. import  org.eclipse.swt.events.MouseEvent;   
  19. import  org.eclipse.swt.events.MouseListener;   
  20. import  org.eclipse.swt.events.PaintEvent;   
  21. import  org.eclipse.swt.graphics.Color;   
  22. import  org.eclipse.swt.graphics.Font;   
  23. import  org.eclipse.swt.graphics.GC;   
  24. import  org.eclipse.swt.graphics.Image;   
  25. import  org.eclipse.swt.graphics.Rectangle;   
  26. import  org.eclipse.swt.widgets.Composite;   
  27. import  org.eclipse.ui.presentations.IPresentablePart;   
  28. import  org.eclipse.ui.presentations.IStackPresentationSite;   
  29.   
  30. public   class  Title  extends  AbstractClosable {   
  31.      private  IStackPresentationSite site;   
  32.   
  33.     Color colorTop =  new  Color(getDisplay(),  135 135 135 );   
  34.   
  35.     Color colorBottom =  new  Color(getDisplay(),  50 50 50 );   
  36.   
  37.     Color colorText =  new  Color(getDisplay(),  255 255 255 );   
  38.   
  39.      protected  Font font =  new  Font(getDisplay(),  "Default" 10 , SWT.BOLD);   
  40.   
  41.      /**  
  42.      * This listener responds to selection events in all tab buttons.  
  43.      */   
  44.      private  MouseListener mouseListener =  new  MouseAdapter() {   
  45.          public   void  mouseDown(MouseEvent e) {   
  46.              if  (part !=  null ) {   
  47.                 part.setFocus();   
  48.                  if  (isCloseSelected) {   
  49.                     site.close( new  IPresentablePart[] { part });   
  50.                 }   
  51.             }   
  52.         }   
  53.     };   
  54.   
  55.      public  Title(Composite parent,  int  style, IStackPresentationSite site) {   
  56.          super (parent, style | SWT.NO_BACKGROUND);   
  57.          this .site = site;   
  58.         addPaintListener( this );   
  59.         addMouseListener(mouseListener);   
  60.     }   
  61.   
  62.      /**  
  63.      * Paint the title  
  64.      */   
  65.      public   void  paintControl(PaintEvent e) {   
  66.         Rectangle clientArea = getBounds();   
  67.         Image img =  new  Image(e.display, clientArea.width, clientArea.height);   
  68.         GC gc =  new  GC(img);   
  69.   
  70.         gc.setForeground(colorTop);   
  71.         gc.setBackground(colorBottom);   
  72.         gc.fillGradientRectangle( 0 0 , clientArea.width, clientArea.height,  true );   
  73.   
  74.          if  (part !=  null ) {   
  75.             gc.setFont(JFaceResources.getBannerFont());   
  76.             gc.setForeground(colorText);   
  77.             String dirty =  "" ;   
  78.              if  (part.isDirty()) {   
  79.                 dirty =  "*" ;   
  80.             }   
  81.             String text = shortenText(gc,dirty + part.getTitle(), clientArea.width -  30 );   
  82.             gc.drawText(text,  5 2 true );   
  83.   
  84.              if  (part.isCloseable()) {   
  85.                  if  (isCloseSelected) {   
  86.                     gc.drawImage(closeSelectedImage, clientArea.width -  20 2 );   
  87.                 }  else  {   
  88.                     gc.drawImage(closeUnselectedImage, clientArea.width -  20 2 );   
  89.                 }   
  90.             }   
  91.         }   
  92.   
  93.         e.gc.drawImage(img,  0 0 );   
  94.         gc.dispose();   
  95.         img.dispose();   
  96.     }   
  97.   
  98.      /*  
  99.      * (non-Javadoc)  
  100.      *   
  101.      * @see org.eclipse.swt.widgets.Widget#dispose()  
  102.      */   
  103.      @Override   
  104.      public   void  dispose() {   
  105.         colorTop.dispose();   
  106.         colorBottom.dispose();   
  107.         colorText.dispose();   
  108.         font.dispose();   
  109.          super .dispose();   
  110.     }   
  111.   
  112. }  
/*******************************************************************************
 * Copyright (c) 2009 Siemens AG
 * 
 * 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:
 *    Kai T枚dter - initial API and implementation
 *******************************************************************************/

package com.siemens.ct.mp3m.ui.presentation;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.presentations.IPresentablePart;
import org.eclipse.ui.presentations.IStackPresentationSite;

public class Title extends AbstractClosable {
    private IStackPresentationSite site;

    Color colorTop = new Color(getDisplay(), 135, 135, 135);

    Color colorBottom = new Color(getDisplay(), 50, 50, 50);

    Color colorText = new Color(getDisplay(), 255, 255, 255);

    protected Font font = new Font(getDisplay(), "Default", 10, SWT.BOLD);

    /**
     * This listener responds to selection events in all tab buttons.
     */
    private MouseListener mouseListener = new MouseAdapter() {
        public void mouseDown(MouseEvent e) {
            if (part != null) {
                part.setFocus();
                if (isCloseSelected) {
                    site.close(new IPresentablePart[] { part });
                }
            }
        }
    };

    public Title(Composite parent, int style, IStackPresentationSite site) {
        super(parent, style | SWT.NO_BACKGROUND);
        this.site = site;
        addPaintListener(this);
        addMouseListener(mouseListener);
    }

    /**
     * Paint the title
     */
    public void paintControl(PaintEvent e) {
        Rectangle clientArea = getBounds();
        Image img = new Image(e.display, clientArea.width, clientArea.height);
        GC gc = new GC(img);

        gc.setForeground(colorTop);
        gc.setBackground(colorBottom);
        gc.fillGradientRectangle(0, 0, clientArea.width, clientArea.height, true);

        if (part != null) {
            gc.setFont(JFaceResources.getBannerFont());
            gc.setForeground(colorText);
            String dirty = "";
            if (part.isDirty()) {
                dirty = "*";
            }
            String text = shortenText(gc,dirty + part.getTitle(), clientArea.width - 30);
            gc.drawText(text, 5, 2, true);

            if (part.isCloseable()) {
                if (isCloseSelected) {
                    gc.drawImage(closeSelectedImage, clientArea.width - 20, 2);
                } else {
                    gc.drawImage(closeUnselectedImage, clientArea.width - 20, 2);
                }
            }
        }

        e.gc.drawImage(img, 0, 0);
        gc.dispose();
        img.dispose();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.widgets.Widget#dispose()
     */
    @Override
    public void dispose() {
        colorTop.dispose();
        colorBottom.dispose();
        colorText.dispose();
        font.dispose();
        super.dispose();
    }

}


我这里在提供两种调用的方法
方法一:
在plugin.xml中加入

Java代码
  1. <extension   
  2.         point= "org.eclipse.ui.presentationFactories" >   
  3.      <factory   
  4.             class = "com.siemens.ct.mp3m.ui.presentation.PresentationFactory"   
  5.            id= "com.siemens.ct.mp3m.ui.presentation.PresentationFactory"   
  6.            name= "Siemens CT Presentation" />   
  7.   </extension>  
 <extension
         point="org.eclipse.ui.presentationFactories">
      <factory
            class="com.siemens.ct.mp3m.ui.presentation.PresentationFactory"
            id="com.siemens.ct.mp3m.ui.presentation.PresentationFactory"
            name="Siemens CT Presentation"/>
   </extension>


第二种方法就是在ini文件中加入

Java代码
  1. org.eclipse.ui/presentationFactoryId=com.siemens.ct.mp3m.ui.presentation.PresentationFactory  
org.eclipse.ui/presentationFactoryId=com.siemens.ct.mp3m.ui.presentation.PresentationFactory


代码不难摘自MP3M,相信大家能理解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值