public void paintControl(PaintEvent pe) { Color cBackground = null; Color clrTransparencyBackground = Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND); GC gc = pe.gc; if (!this.isEnabled()) { gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); Color cFore = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); gc.setForeground(cFore); if (fCurrent == null || fCurrent instanceof ColorDefinition && ((ColorDefinition) fCurrent).getTransparency() == 0) { gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y); gc.drawText(Messages.getString("FillCanvas.Transparent"), 2, 2); } else { gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y); gc.setBackground(cFore); gc.fillRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4); } } else { if (fCurrent == null || fCurrent instanceof ColorDefinition && ((ColorDefinition) fCurrent).getTransparency() == 0) { gc.setBackground(clrTransparencyBackground); gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y); Color cText = new Color(this.getDisplay(), 0, 0, 0); gc.setForeground(cText); gc.drawText(Messages.getString("FillCanvas.Transparent"), 2, 2); cText.dispose(); } else { if (fCurrent instanceof ColorDefinition) { cBackground = new Color(Display.getDefault(), ((ColorDefinition) fCurrent).getRed(), ((ColorDefinition) fCurrent).getGreen(), ((ColorDefinition) fCurrent).getBlue()); gc.setBackground(cBackground); gc.fillRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4); } else if (fCurrent instanceof Image) { gc.fillRectangle(2, 2, getSize().x - 4, this.getSize().y - 4); gc.drawImage(getSWTImage((Image) fCurrent), 2, 2); } else if (fCurrent instanceof Gradient) { if (((Gradient) fCurrent).getStartColor() == null && ((Gradient) fCurrent).getEndColor() == null) { return; } Color clrStart = null; Color clrEnd = null; if (((Gradient) fCurrent).getStartColor() != null) { clrStart = new Color(Display.getDefault(), ((Gradient) fCurrent).getStartColor().getRed(), ((Gradient) fCurrent).getStartColor().getGreen(), ((Gradient) fCurrent).getStartColor() .getBlue()); gc.setForeground(clrStart); } if (((Gradient) fCurrent).getEndColor() != null) { clrEnd = new Color(Display.getDefault(), ((Gradient) fCurrent).getEndColor().getRed(), ((Gradient) fCurrent).getEndColor().getGreen(), ((Gradient) fCurrent).getEndColor() .getBlue()); gc.setBackground(clrEnd); } gc.fillGradientRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4, false); } } } if (cBackground != null) { cBackground.dispose(); } }
public void paintControl( PaintEvent pe ) { Color cBackground = null;  try { Color clrTransparencyBackground = Display.getCurrent( ) .getSystemColor( SWT.COLOR_LIST_BACKGROUND ); GC gc = pe.gc; if ( !this.isEnabled( ) ) { gc.setBackground( Display.getCurrent( ) .getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) ); Color cFore = Display.getCurrent( ) .getSystemColor( SWT.COLOR_DARK_GRAY ); gc.setForeground( cFore ); if ( fCurrent == null || fCurrent instanceof ColorDefinition && ( (ColorDefinition) fCurrent ).getTransparency( ) == 0 ) { gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y ); gc.drawText( Messages.getString( "FillCanvas.Transparent" ), 2, 2 ); } else { gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y ); gc.setBackground( cFore ); gc.fillRectangle( 2, 2, this.getSize( ).x - 4, this.getSize( ).y - 4 ); } } else { if ( fCurrent == null || fCurrent instanceof ColorDefinition && ( (ColorDefinition) fCurrent ).getTransparency( ) == 0 ) { gc.setBackground( clrTransparencyBackground ); gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y ); Color cText = new Color( this.getDisplay( ), 0, 0, 0 ); gc.setForeground( cText ); gc.drawText( Messages.getString( "FillCanvas.Transparent" ), 2, 2 ); cText.dispose( ); } else { if ( fCurrent instanceof ColorDefinition ) { cBackground = new Color( Display.getDefault( ), ( (ColorDefinition) fCurrent ).getRed( ), ( (ColorDefinition) fCurrent ).getGreen( ), ( (ColorDefinition) fCurrent ).getBlue( ) ); gc.setBackground( cBackground ); gc.fillRectangle( 2, 2, this.getSize( ).x - 4, this.getSize( ).y - 4 ); } else if ( fCurrent instanceof Image ) { gc.fillRectangle( 2, 2, getSize( ).x - 4, this.getSize( ).y - 4 ); gc.drawImage( getSWTImage( (Image) fCurrent ), 2, 2 ); } else if ( fCurrent instanceof Gradient ) { if ( ( (Gradient) fCurrent ).getStartColor( ) == null && ( (Gradient) fCurrent ).getEndColor( ) == null ) { return; } Color clrStart = null; Color clrEnd = null; if ( ( (Gradient) fCurrent ).getStartColor( ) != null ) { clrStart = new Color( Display.getDefault( ), ( (Gradient) fCurrent ).getStartColor( ) .getRed( ), ( (Gradient) fCurrent ).getStartColor( ) .getGreen( ), ( (Gradient) fCurrent ).getStartColor( ) .getBlue( ) ); gc.setForeground( clrStart ); } if ( ( (Gradient) fCurrent ).getEndColor( ) != null ) { clrEnd = new Color( Display.getDefault( ), ( (Gradient) fCurrent ).getEndColor( ) .getRed( ), ( (Gradient) fCurrent ).getEndColor( ) .getGreen( ), ( (Gradient) fCurrent ).getEndColor( ) .getBlue( ) ); gc.setBackground( clrEnd ); } gc.fillGradientRectangle( 2, 2, this.getSize( ).x - 4, this.getSize( ).y - 4, false ); } } } } catch ( Exception ex ) { logger.log( ex ); } finally { if ( cBackground != null ) { cBackground.dispose( ); } } }
    public void paintControl(PaintEvent pe)    {        Color cBackground = null;        Color clrTransparencyBackground = Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND);        GC gc = pe.gc;        if (!this.isEnabled())        {            gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));            Color cFore = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);            gc.setForeground(cFore);            if (fCurrent == null || fCurrent instanceof ColorDefinition                && ((ColorDefinition) fCurrent).getTransparency() == 0)            {                gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y);                gc.drawText(Messages.getString("FillCanvas.Transparent"), 2, 2); //$NON-NLS-1$            }            else            {                gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y);                gc.setBackground(cFore);                gc.fillRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4);            }        }        else        {            if (fCurrent == null || fCurrent instanceof ColorDefinition                && ((ColorDefinition) fCurrent).getTransparency() == 0)            {                gc.setBackground(clrTransparencyBackground);                gc.fillRectangle(0, 0, this.getSize().x, this.getSize().y);                Color cText = new Color(this.getDisplay(), 0, 0, 0);                gc.setForeground(cText);                gc.drawText(Messages.getString("FillCanvas.Transparent"), 2, 2); //$NON-NLS-1$                cText.dispose();            }            else            {                if (fCurrent instanceof ColorDefinition)                {                    cBackground = new Color(Display.getDefault(), ((ColorDefinition) fCurrent).getRed(),                        ((ColorDefinition) fCurrent).getGreen(), ((ColorDefinition) fCurrent).getBlue());                    gc.setBackground(cBackground);                    gc.fillRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4);                }                else if (fCurrent instanceof Image)                {                    gc.fillRectangle(2, 2, getSize().x - 4, this.getSize().y - 4);                    gc.drawImage(getSWTImage((Image) fCurrent), 2, 2);                }                else if (fCurrent instanceof Gradient)                {                    if (((Gradient) fCurrent).getStartColor() == null && ((Gradient) fCurrent).getEndColor() == null)                    {                        return;                    }                    Color clrStart = null;                    Color clrEnd = null;                    if (((Gradient) fCurrent).getStartColor() != null)                    {                        clrStart = new Color(Display.getDefault(), ((Gradient) fCurrent).getStartColor().getRed(),                            ((Gradient) fCurrent).getStartColor().getGreen(), ((Gradient) fCurrent).getStartColor()                                .getBlue());                        gc.setForeground(clrStart);                    }                    if (((Gradient) fCurrent).getEndColor() != null)                    {                        clrEnd = new Color(Display.getDefault(), ((Gradient) fCurrent).getEndColor().getRed(),                            ((Gradient) fCurrent).getEndColor().getGreen(), ((Gradient) fCurrent).getEndColor()                                .getBlue());                        gc.setBackground(clrEnd);                    }                    gc.fillGradientRectangle(2, 2, this.getSize().x - 4, this.getSize().y - 4, false);                }            }        }        if (cBackground != null)        {            cBackground.dispose();        }    }