Java Code Examples for org.eclipse.swt.graphics.GC#fillRectangle()

The following examples show how to use org.eclipse.swt.graphics.GC#fillRectangle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManageableTableTreeEx.java    From SWET with MIT License 6 votes vote down vote up
TableTreeItem(TableTree parent, TableTreeItem parentItem, int style,
		int index) {
	super(parent, style);
	this.parent = parent;
	this.parentItem = parentItem;
	if (parentItem == null) {
		int tableIndex = parent.addItem(this, index);
		tableItem = new TableItem(parent.getTable(), style, tableIndex);
		tableItem.setData(this);
		addCheck();
		if (parent.sizeImage == null) {
			int itemHeight = parent.getItemHeight();
			parent.sizeImage = new Image(null, itemHeight, itemHeight);
			GC gc = new GC(parent.sizeImage);
			gc.setBackground(parent.getBackground());
			gc.fillRectangle(0, 0, itemHeight, itemHeight);
			gc.dispose();
			tableItem.setImage(0, parent.sizeImage);
		}
	} else {
		parentItem.addItem(this, index);
	}
}
 
Example 2
Source File: ImageCellRender.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
		IColumn column, boolean drawFocus, boolean selected, boolean printing) {
	drawBackground(gc, drawingArea, cellStyle, selected, printing);
	Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
	Rectangle rect = applyInsets(drect);
	Object value = column.getValue(row);
	String key = keyMap.get(value);

	if (key != null) {
		Image img = null;
		img = getImageRegistry().get(key);
		int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
		int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
		gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
				scaleY(img.getBounds().height));
	} else {
		Color bg = gc.getBackground();
		gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
		gc.fillRectangle(rect);
		gc.setBackground(bg);
	}
	if (drawFocus) {
		drawFocus(gc, drect);
	}
	drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
 
Example 3
Source File: DefaultTopLeftRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

    gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width - 1,
                     getBounds().height + 1);

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));

    
    gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x
                                                                      + getBounds().width - 1,
                getBounds().y + getBounds().height);

    gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x
                                                                       + getBounds().width,
                getBounds().y + getBounds().height - 1);

}
 
Example 4
Source File: RangeSlider.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw the background
 *
 * @param gc graphic context
 */
private void drawBackgroundHorizontal(final GC gc) {
	final Rectangle clientArea = getClientArea();

	gc.setBackground(getBackground());
	gc.fillRectangle(clientArea);

	if (isEnabled()) {
		gc.setForeground(getForeground());
	} else {
		gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
	}
	gc.drawRoundRectangle(9, 9, clientArea.width - 20, clientArea.height - 20, 3, 3);

	final float pixelSize = computePixelSizeForHorizontalSlider();
	final int startX = (int) (pixelSize * lowerValue);
	final int endX = (int) (pixelSize * upperValue);
	if (isEnabled()) {
		gc.setBackground(getForeground());
	} else {
		gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
	}
	gc.fillRectangle(12 + startX, 9, endX - startX - 6, clientArea.height - 20);

}
 
Example 5
Source File: DefaultTopLeftRenderer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

    gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width - 1,
                     getBounds().height + 1);

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));

    
    gc.drawLine(getBounds().x + getBounds().width - 1, getBounds().y, getBounds().x
                                                                      + getBounds().width - 1,
                getBounds().y + getBounds().height);

    gc.drawLine(getBounds().x, getBounds().y + getBounds().height - 1, getBounds().x
                                                                       + getBounds().width,
                getBounds().y + getBounds().height - 1);

}
 
Example 6
Source File: CTreeCell.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
void paintCell(GC gc, Point offset) {
	if(activeBackground != null) gc.setBackground(activeBackground);
	if(activeForeground != null) gc.setForeground(activeForeground);

	// background
	gc.fillRectangle(
			bounds.x+offset.x,
			bounds.y+offset.y,
			bounds.width,
			bounds.height
	);

	// images
	for(int i = 0; i < iBounds.length; i++) {
		if(!images[i].isDisposed()) {
			gc.drawImage(images[i], offset.x+iBounds[i].x, offset.y+iBounds[i].y);
		}
	}

	// text
	if(getText().length() > 0) {
		Font bf = gc.getFont();
		if(getFont() != null) gc.setFont(getFont());
		gc.drawText(getText(), offset.x+tBounds.x, offset.y+tBounds.y);
		if(getFont() != null) gc.setFont(bf);
	}
	
	if(((CTreeItem) item).getTreeCell() == this) {
		paintChildLines(gc, offset);
	}
	
	// toggle (it changes the colors again so paint it last...)
	if(toggleVisible) {
		paintToggle(gc, offset);
	}
}
 
Example 7
Source File: ClassImageRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
        IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    Object value = column.getValue(row);
    String key = getKeyForClass(value.getClass());

    if (key != null) {
        Image img = null;
        img = getImageRegistry().get(key);
        int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
        int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
        gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
                scaleY(img.getBounds().height));
    } else {
        // indicate error with red fill
        Color bg = gc.getBackground();
        gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
        gc.fillRectangle(rect);
        gc.setBackground(bg);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

}
 
Example 8
Source File: ClassImageRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row,
        IColumn column, boolean drawFocus, boolean selected, boolean printing) {
    drawBackground(gc, drawingArea, cellStyle, selected, printing);
    Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
    Rectangle rect = applyInsets(drect);
    Object value = column.getValue(row);
    String key = getKeyForClass(value.getClass());

    if (key != null) {
        Image img = null;
        img = getImageRegistry().get(key);
        int x = rect.x + (rect.width - scaleX(img.getBounds().width)) / 2;
        int y = rect.y + (rect.height - scaleY(img.getBounds().height)) / 2;
        gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x, y, scaleX(img.getBounds().width),
                scaleY(img.getBounds().height));
    } else {
        // indicate error with red fill
        Color bg = gc.getBackground();
        gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA));
        gc.fillRectangle(rect);
        gc.setBackground(bg);
    }
    if (drawFocus) {
        drawFocus(gc, drect);
    }
    drawSelection(gc, drawingArea, cellStyle, selected, printing);

}
 
Example 9
Source File: ConditionEditor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void drawNegated( GC gc, int x, int y, Condition condition ) {
  Color color = gc.getForeground();

  if ( hover_not ) {
    gc.setBackground( gray );
  }
  gc.fillRectangle( Real2Screen( size_not ) );
  gc.drawRectangle( Real2Screen( size_not ) );

  if ( condition.isNegated() ) {
    if ( hover_not ) {
      gc.setForeground( green );
    }
    gc.drawText( STRING_NOT, size_not.x + 5 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT );
    gc.drawText( STRING_NOT, size_not.x + 6 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT );
    if ( hover_not ) {
      gc.setForeground( color );
    }
  } else {
    if ( hover_not ) {
      gc.setForeground( red );
      gc.drawText( STRING_NOT, size_not.x + 5 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT );
      gc.drawText( STRING_NOT, size_not.x + 6 + offsetx, size_not.y + 2 + offsety, SWT.DRAW_TRANSPARENT );
      gc.setForeground( color );
    }
  }

  if ( hover_not ) {
    gc.setBackground( bg );
  }
}
 
Example 10
Source File: SimpleToolBarEx.java    From SWET with MIT License 5 votes vote down vote up
private static Image getMissingImage() {
	Image image = new Image(Display.getCurrent(), IMAGE_SIZE, IMAGE_SIZE);
	GC gc = new GC(image);
	gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
	gc.fillRectangle(0, 0, IMAGE_SIZE, IMAGE_SIZE);
	gc.dispose();
	return image;
}
 
Example 11
Source File: DefaultEmptyColumnHeaderRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));

    gc.fillRectangle(getBounds().x, getBounds().y, getBounds().width + 1,
                     getBounds().height + 1);

}
 
Example 12
Source File: SWTResourceManager.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return the small {@link Image} that can be used as placeholder for missing image.
 */
private static Image getMissingImage(){
	Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
	//
	GC gc = new GC(image);
	gc.setBackground(getColor(SWT.COLOR_RED));
	gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
	gc.dispose();
	//
	return image;
}
 
Example 13
Source File: HierarchyWizardEditor.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Paints the intervals and fanouts.
 *
 * @param gc
 */
protected void paint(GC gc) {
    
    model.getRenderer().update(gc);
    
    gc.setBackground(HierarchyWizardEditorRenderer.WIDGET_BACKGROUND);
    Point size = canvascomposite.getSize();
    gc.fillRectangle(0, 0, size.x, size.y);
    
    for (RenderedComponent<T> component : model.getRenderer().getComponents()) {
        
        Color foreground = HierarchyWizardEditorRenderer.NORMAL_FOREGROUND;
        Color alternative = HierarchyWizardEditorRenderer.ALTERNATIVE_FOREGROUND;
        Color background = HierarchyWizardEditorRenderer.NORMAL_BACKGROUND;
        
        if (isSelected(component)) {
            background = HierarchyWizardEditorRenderer.SELECTED_BACKGROUND;
            alternative = background;
        }
        
        if (!component.enabled) {
            foreground = HierarchyWizardEditorRenderer.DISABLED_FOREGROUND;
            background = HierarchyWizardEditorRenderer.DISABLED_BACKGROUND;
            alternative = background;
        }

        gc.setBackground(background);
        gc.fillRectangle(component.rectangle1);
        gc.setForeground(foreground);
        gc.drawRectangle(component.rectangle1);
        drawString(gc, component.bounds, component.rectangle1);

        gc.setBackground(foreground);
        gc.fillRectangle(component.rectangle2);
        gc.drawRectangle(component.rectangle2);
        gc.setForeground(alternative);
        drawString(gc, component.label, component.rectangle2);
    }
    scrolledcomposite.setMinSize(model.getRenderer().getMinSize());
}
 
Example 14
Source File: SwtTextRenderer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param ipr
 * @param lo
 * @param la
 * @param b
 */
private void showTopValue( IPrimitiveRenderer ipr, Location lo, Label la,
		boolean b )
{
	GC gc = (GC) ( (IDeviceRenderer) ipr ).getGraphicsContext( );
	IChartComputation cComp = ( (IDeviceRenderer) ipr ).getChartComputation( );
	double dX = lo.getX( ), dY = lo.getY( );
	final FontDefinition fd = la.getCaption( ).getFont( );

	final int dAngleInDegrees = (int)fd.getRotation( );

	final Color clrBackground = (Color) _sxs.getColor( la.getShadowColor( ) );

	final ITextMetrics itm = cComp.getTextMetrics( _sxs, la, 0 );
	final double dFW = itm.getFullWidth( );
	final double dFH = itm.getFullHeight( );
	cComp.recycleTextMetrics( itm );

	double scaledThickness = SHADOW_THICKNESS
			* _sxs.getDpiResolution( )
			/ 72d;

	gc.setBackground( clrBackground );

	R31Enhance.setAlpha( gc, la.getShadowColor( ) );

	// HORIZONTAL TEXT
	if ( dAngleInDegrees == 0 )
	{
		gc.fillRectangle( (int) ( dX + scaledThickness ),
				(int) ( dY + scaledThickness ),
				(int) dFW,
				(int) dFH );
	}
	// TEXT AT POSITIVE 90 (TOP RIGHT HIGHER THAN TOP LEFT CORNER)
	else if ( dAngleInDegrees == 90 )
	{
		gc.fillRectangle( (int) ( dX + scaledThickness ),
				(int) ( dY - dFW - scaledThickness ),
				(int) dFH,
				(int) dFW );
	}
	// TEXT AT NEGATIVE 90 (TOP RIGHT LOWER THAN TOP LEFT CORNER)
	else if ( dAngleInDegrees == -90 )
	{
		gc.fillRectangle( (int) ( dX - dFH - scaledThickness ),
				(int) ( dY + scaledThickness ),
				(int) dFH,
				(int) dFW );
	}
	else
	{
		Transform transform = new Transform( getDevice( ) );
		transform.translate( (float) dX, (float) dY );
		transform.rotate( -dAngleInDegrees );
		gc.setTransform( transform );
		gc.fillRectangle( (int) scaledThickness,
				(int) scaledThickness,
				(int) dFW,
				(int) dFH );
		transform.dispose( );
		gc.setTransform( null );
	}
}
 
Example 15
Source File: ConditionEditor.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void repaint( GC dgc, int width, int height ) {
  Image im = new Image( display, width, height );
  GC gc = new GC( im );

  // Initialize some information
  size_not = getNotSize( gc );
  size_widget = getWidgetSize( gc );
  size_and_not = getAndNotSize( gc );
  size_up = getUpSize( gc );
  size_add = getAddSize( gc );
  size_left = null;
  size_fn = null;
  size_rightval = null;
  size_rightex = null;

  // Clear the background...
  gc.setBackground( white );
  gc.setForeground( black );
  gc.fillRectangle( 0, 0, width, height );

  // Set the fixed font:
  gc.setFont( fixed );

  // Atomic condition?
  if ( active_condition.isAtomic() ) {
    size_cond = null;
    drawNegated( gc, 0, 0, active_condition );

    drawAtomic( gc, 0, 0, active_condition );

    // gc.drawText("ATOMIC", 10, size_widget.height-20);
  } else {
    drawNegated( gc, 0, 0, active_condition );

    size_cond = new Rectangle[active_condition.nrConditions()];
    size_oper = new Rectangle[active_condition.nrConditions()];

    int basex = 10;
    int basey = size_not.y + 5;

    for ( int i = 0; i < active_condition.nrConditions(); i++ ) {
      Point to = drawCondition( gc, basex, basey, i, active_condition.getCondition( i ) );
      basey += size_and_not.height + to.y + 15;
    }
  }

  gc.drawImage( imageAdd, size_add.x, size_add.y );

  /*
   * Draw the up-symbol if needed...
   */
  if ( parents.size() > 0 ) {
    drawUp( gc );
  }

  if ( messageString != null ) {
    drawMessage( gc );
  }

  /*
   * Determine the maximum size of the displayed items... Normally, they are all size up already.
   */
  getMaxSize();

  /*
   * Set the scroll bars: show/don't show and set the size
   */
  setBars();

  // Draw the result on the canvas, all in 1 go.
  dgc.drawImage( im, 0, 0 );

  im.dispose();
}
 
Example 16
Source File: InnerTagRender.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public void draw(GC gc, InnerTagBean innerTagBean, int x, int y) {
	Point tagSize = calculateTagSize(innerTagBean);
	if (tag != null && tag.isSelected()) {
		Color b = gc.getBackground();
		gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
		gc.fillRectangle(0, 0, tagSize.x, tagSize.y);
		gc.setBackground(b);
	}
	int[] tagAreaPoints = calculateTagArea(tagSize, innerTagBean, x, y);
	String strInx = String.valueOf(innerTagBean.getIndex());
	Color gcBgColor = gc.getBackground();
	Color gcFgColor = gc.getForeground();
	Font gcFont = gc.getFont();
	gc.setFont(TAG_FONT);
	// gc.setBackground(ColorConfigBean.getInstance().getTm90Color());
	// Point p = calculateTagSize(innerTagBean);
	// gc.fillRectangle(x, y, p.x, p.y);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	gc.fillPolygon(tagAreaPoints);
	// gc.drawPolygon(tagAreaPoints);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	switch (innerTagBean.getType()) {
	case START:
		gc.drawText(strInx, tagAreaPoints[0] + MARGIN_H, tagAreaPoints[1] + MARGIN_V);
		break;
	default:
		gc.drawText(strInx, tagAreaPoints[2] + MARGIN_H, tagAreaPoints[3] + MARGIN_V);
		break;
	}
	gc.setBackground(gcBgColor);
	gc.setForeground(gcFgColor);
	gc.setFont(gcFont);
}
 
Example 17
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void innerDraw(GC gc) {
    gc.fillRectangle(getBounds());
}
 
Example 18
Source File: GeoMapHelper.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
void paintTile(GC gc, int dx, int dy, int x, int y) {
	boolean DRAW_IMAGES = true;
	boolean DEBUG = false;
	boolean DRAW_OUT_OF_BOUNDS = !false;

	boolean imageDrawn = false;
	int xTileCount = 1 << zoom;
	int yTileCount = 1 << zoom;
	boolean tileInBounds = x >= 0 && x < xTileCount && y >= 0
			&& y < yTileCount;
	boolean drawImage = DRAW_IMAGES && tileInBounds;
	if (drawImage) {
		TileRef tileRef = new TileRef(x, y, zoom);
		AsyncImage image = cache.get(tileRef);
		if (image == null) {
			image = new AsyncImage(this, tileRef,
					tileServer.getTileURL(tileRef));
			cache.put(tileRef, image);
		}
		Image swtImage = image.getImage(getDisplay());
		if (swtImage != null) {
			gc.drawImage(swtImage, dx, dy);
			imageDrawn = true;
		} else {
			// reuse tile from lower zoom level, i.e. half the resolution
			tileRef = new TileRef(x / 2, y / 2, zoom - 1);
			image = cache.get(tileRef);
			if (image != null) {
				swtImage = image.getImage(getDisplay());
				if (swtImage != null) {
					gc.drawImage(swtImage, x % 2 == 0 ? 0 : TILE_SIZE / 2,
							y % 2 == 0 ? 0 : TILE_SIZE / 2, TILE_SIZE / 2,
							TILE_SIZE / 2, dx, dy, TILE_SIZE, TILE_SIZE);
					imageDrawn = true;
				}
			}
		}
		for (InternalGeoMapListener listener : internalGeoMapListeners) {
			listener.tilePainted(tileRef);
		}
	}
	if (DEBUG && !imageDrawn && (tileInBounds || DRAW_OUT_OF_BOUNDS)) {
		gc.setBackground(display.getSystemColor(
				tileInBounds ? SWT.COLOR_GREEN : SWT.COLOR_RED));
		gc.fillRectangle(dx + 4, dy + 4, TILE_SIZE - 8, TILE_SIZE - 8);
		gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
		String s = "T " + x + ", " + y + (!tileInBounds ? " #" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
		gc.drawString(s, dx + 4 + 8, dy + 4 + 12);
	} else if (!DEBUG && !imageDrawn && tileInBounds) {
		gc.setBackground(waitBackground);
		gc.fillRectangle(dx, dy, TILE_SIZE, TILE_SIZE);
		gc.setForeground(waitForeground);
		for (int yl = 0; yl < TILE_SIZE; yl += 32) {
			gc.drawLine(dx, dy + yl, dx + TILE_SIZE, dy + yl);
		}
		for (int xl = 0; xl < TILE_SIZE; xl += 32) {
			gc.drawLine(dx + xl, dy, dx + xl, dy + TILE_SIZE);
		}
	}
}
 
Example 19
Source File: BreadcrumbViewer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * The image to use for the breadcrumb background as specified in
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=221477
 * 
 * @param height the height of the image to create
 * @param display the current display
 * @return the image for the breadcrumb background
 */
private Image createGradientImage(int height, Display display) {
  int width = 50;

  Image result = new Image(display, width, height);

  GC gc = new GC(result);

  Color colorC = createColor(SWT.COLOR_WIDGET_BACKGROUND,
      SWT.COLOR_LIST_BACKGROUND, 35, display);
  Color colorD = createColor(SWT.COLOR_WIDGET_BACKGROUND,
      SWT.COLOR_LIST_BACKGROUND, 45, display);
  Color colorE = createColor(SWT.COLOR_WIDGET_BACKGROUND,
      SWT.COLOR_LIST_BACKGROUND, 80, display);
  Color colorF = createColor(SWT.COLOR_WIDGET_BACKGROUND,
      SWT.COLOR_LIST_BACKGROUND, 70, display);
  Color colorG = createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_WHITE,
      45, display);
  Color colorH = createColor(SWT.COLOR_WIDGET_NORMAL_SHADOW,
      SWT.COLOR_LIST_BACKGROUND, 35, display);

  try {
    drawLine(width, 0, colorC, gc);
    drawLine(width, 1, colorC, gc);

    gc.setForeground(colorD);
    gc.setBackground(colorE);
    gc.fillGradientRectangle(0, 2, width, 2 + 8, true);

    gc.setBackground(colorE);
    gc.fillRectangle(0, 2 + 9, width, height - 4);

    drawLine(width, height - 3, colorF, gc);
    drawLine(width, height - 2, colorG, gc);
    drawLine(width, height - 1, colorH, gc);

  } finally {
    gc.dispose();

    colorC.dispose();
    colorD.dispose();
    colorE.dispose();
    colorF.dispose();
    colorG.dispose();
    colorH.dispose();
  }

  return result;
}
 
Example 20
Source File: NavigationPageGraphics.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void onPaint(GC gc) {
	gc.setAdvanced(true);
	if (gc.getAdvanced())
		gc.setTextAntialias(SWT.ON);
	if (items == null) {
		return;
	}
	computeBoundsIfNeeded(gc);

	Color fg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
	Color bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);

	boolean separator = false;
	int x, y, width, height = 0;
	boolean selected = false;
	boolean enabled = false;

	for (NavigationPageGraphicsItem pageItem : items) {
		selected = pageItem.equals(selectedItem);
		enabled = pageItem.isEnabled();
		separator = pageItem.isSeparator();

		x = pageItem.getBounds().x;
		y = pageItem.getBounds().y;
		width = pageItem.getBounds().width;
		height = pageItem.getBounds().height;

		// Fill rectangle
		Color filledRectangleColor = getFilledRectangleColor(selected,
				!separator ? enabled : true, bg);
		if (filledRectangleColor != null) {
			gc.setBackground(filledRectangleColor);
			if (round != null) {
				gc.fillRoundRectangle(x, y, width, height, round, round);
			} else {
				gc.fillRectangle(x, y, width, height);
			}
		}

		// Border rectangle
		if (!separator) {
			Color borderRectangleColor = getBorderRectangleColor(selected,
					enabled, bg);
			if (borderRectangleColor != null) {
				gc.setForeground(borderRectangleColor);
				if (round != null) {
					gc.drawRoundRectangle(x, y, width, height, round, round);
				} else {
					gc.drawRectangle(x, y, width, height);
				}
			}
		}

		// Foreground text
		Color textColor = getTextColor(selected, enabled);
		if (textColor != null) {
			gc.setForeground(textColor);
		} else {
			gc.setForeground(fg);
		}
		gc.drawString(pageItem.getText(), x + 3, y, true);
	}
}