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

The following examples show how to use org.eclipse.swt.graphics.GC#fillGradientRectangle() . 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: GuiResource.java    From hop with Apache License 2.0 6 votes vote down vote up
public void drawGradient( Display display, GC gc, Rectangle rect, boolean vertical ) {
  if ( !vertical ) {
    gc.setForeground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.setBackground( GuiResource.getInstance().getColorHop() );
    gc.fillGradientRectangle( rect.x, rect.y, 2 * rect.width / 3, rect.height, vertical );
    gc.setForeground( GuiResource.getInstance().getColorHop() );
    gc.setBackground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.fillGradientRectangle( rect.x + 2 * rect.width / 3, rect.y, rect.width / 3 + 1, rect.height, vertical );
  } else {
    gc.setForeground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.setBackground( GuiResource.getInstance().getColorHop() );
    gc.fillGradientRectangle( rect.x, rect.y, rect.width, 2 * rect.height / 3, vertical );
    gc.setForeground( GuiResource.getInstance().getColorHop() );
    gc.setBackground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.fillGradientRectangle( rect.x, rect.y + 2 * rect.height / 3, rect.width, rect.height / 3 + 1, vertical );
  }
}
 
Example 2
Source File: DefaultGalleryGroupRenderer.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw group background using system default gradient or the user-defined
 * color.
 * 
 * @param gc
 * @param item
 *            TODO
 * @param x
 * @param y
 * @param width
 * @param height
 */
protected void drawGroupBackground(GC gc, GalleryItem item, int x, int y,
		int width, int height) {
	Color itemLocalBackground = item.getBackground(true);
	if (!titleBackgroundGradient || itemLocalBackground != null) {
		// User defined background
		gc.setBackground(itemLocalBackground != null ? itemLocalBackground
				: titleBackground);
		gc.fillRectangle(x, y, width, height);
	} else {
		// Default gradient Background
		gc.setBackground(this.titleBackground);
		gc.setForeground(this.titleBackground2);
		gc.fillGradientRectangle(x, y, width, height, true);
	}
}
 
Example 3
Source File: BoxDecoratorImpl.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
void fillRectangle(final Color c, final GC gc, final int x, final int y, final int width, final int height) {
	if (c == null) { return; }

	gc.setBackground(c);
	if (settings.getRoundBox()) {
		gc.fillRoundRectangle(x, y, width, height, ROUND_BOX_ARC, ROUND_BOX_ARC);
	} else {
		if (settings.getFillGradient() && settings.getFillGradientColor() != null) {
			gc.setBackground(settings.getFillGradientColor());
			gc.setForeground(c);
			gc.fillGradientRectangle(x, y, width, height, false);
		} else {
			gc.fillRectangle(x, y, width, height);
		}
	}
}
 
Example 4
Source File: TitleControl.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void onPaint(PaintEvent e) {
	GC gc = e.gc;
	Point s = getSize();
	int w = s.x;
	int h = s.y;

	gc.setForeground(gradient1Color);
	gc.setBackground(gradient2Color);
	gc.fillGradientRectangle(0, 0, w, h - 1, true);

	Rectangle imgsize = new Rectangle(0, 0, 0, 0);
	if (image != null) {
		imgsize = image.getBounds();
		gc.drawImage(image, 12, 0);
	}
	gc.setForeground(bottomLineColor);
	gc.drawLine(0, h - 1, w, h - 1);

	gc.setFont(font);
	gc.setForeground(writingColor);
	Point textSize = gc.stringExtent(text);
	int ty = (h - textSize.y) / 2;
	gc.drawString(text, 22 + imgsize.width, TOP_SPACE + ty, true);
}
 
Example 5
Source File: TabbedPropertyTitle.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param e
 */
protected void drawTitleBackground(PaintEvent e) {
	Rectangle bounds = getClientArea();
	label.setBackground(new Color[] {
			factory.getColors().getColor(IFormColors.H_GRADIENT_END),
			factory.getColors().getColor(IFormColors.H_GRADIENT_START) },
			new int[] { 100 }, true);
	Color bg = factory.getColors().getColor(IFormColors.H_GRADIENT_END);
	Color gbg = factory.getColors().getColor(IFormColors.H_GRADIENT_START);
	GC gc = e.gc;
	gc.setForeground(bg);
	gc.setBackground(gbg);
	gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width,
			bounds.height, true);
	// background bottom separator
	gc.setForeground(factory.getColors().getColor(
			IFormColors.H_BOTTOM_KEYLINE1));
	gc.drawLine(bounds.x, bounds.height - 2, bounds.x + bounds.width - 1,
			bounds.height - 2);
	gc.setForeground(factory.getColors().getColor(
			IFormColors.H_BOTTOM_KEYLINE2));
	gc.drawLine(bounds.x, bounds.height - 1, bounds.x + bounds.width - 1,
			bounds.height - 1);
}
 
Example 6
Source File: Breadcrumb.java    From SWET with MIT License 5 votes vote down vote up
private void drawBackground(final GC gc, final int width, final int height) {
	gc.setForeground(START_GRADIENT_COLOR);
	gc.setBackground(END_GRADIENT_COLOR);
	gc.fillGradientRectangle(0, 0, width, height, true);

	if (this.hasBorder) {
		gc.setForeground(BORDER_COLOR);
		gc.drawRectangle(0, 0, width - 1, height - 1);
	}
}
 
Example 7
Source File: GUIResource.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void drawPentahoGradient( Display display, GC gc, Rectangle rect, boolean vertical ) {
  gc.setForeground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
  gc.setBackground( GUIResource.getInstance().getColorPentaho() );
  if ( !vertical ) {
    gc.fillGradientRectangle( rect.x, rect.y, 2 * rect.width / 3, rect.height, false );
    gc.setForeground( GUIResource.getInstance().getColorPentaho() );
    gc.setBackground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.fillGradientRectangle( rect.x + 2 * rect.width / 3, rect.y, rect.width / 3 + 1, rect.height, false );
  } else {
    gc.fillGradientRectangle( rect.x, rect.y, rect.width, 2 * rect.height / 3, true );
    gc.setForeground( GUIResource.getInstance().getColorPentaho() );
    gc.setBackground( display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ) );
    gc.fillGradientRectangle( rect.x, rect.y + 2 * rect.height / 3, rect.width, rect.height / 3 + 1, true );
  }
}
 
Example 8
Source File: XViewerGradient.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleEvent(Event event) {
   try {
      XViewerColumn xViewerColumn =
         ((IXViewerLabelProvider) xViewer.getLabelProvider()).getTreeColumnOffIndex(event.index);
      TreeItem item = (TreeItem) event.item;
      if (item.getData() == null) {
         return;
      }
      int percent =
         ((IXViewerLabelProvider) xViewer.getLabelProvider()).getColumnGradient(item.getData(), xViewerColumn,
            event.index);
      if (percent == 0 || percent > 100 || percent < 0) {
         return;
      }
      GC gc = event.gc;
      Color foreground = gc.getForeground();
      Color background = gc.getBackground();
      gc.setForeground(xViewer.getTree().getDisplay().getSystemColor(SWT.COLOR_GREEN));
      gc.setBackground(xViewer.getTree().getDisplay().getSystemColor(SWT.COLOR_YELLOW));
      int width = (xViewerColumn.getWidth() - 1) * percent / 100;
      gc.fillGradientRectangle(event.x, event.y, width, event.height, true);
      Rectangle rect2 = new Rectangle(event.x, event.y, width - 1, event.height - 1);
      gc.setForeground(xViewer.getTree().getDisplay().getSystemColor(SWT.COLOR_BLACK));

      gc.drawRectangle(rect2);
      gc.setForeground(xViewer.getTree().getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
      String text =
         ((IXViewerLabelProvider) xViewer.getLabelProvider()).getColumnText(item.getData(), xViewerColumn,
            event.index);
      Point size = event.gc.textExtent(text);
      int offset = Math.max(0, (event.height - size.y) / 2 + 1);
      gc.drawText(text, event.x + 5, event.y + offset, true);
      gc.setForeground(background);
      gc.setBackground(foreground);
   } catch (Exception ex) {
      XViewerLog.log(XViewerGradient.class, Level.SEVERE, ex);
      return;
   }
}
 
Example 9
Source File: GanttControlParent.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public void paintControl(PaintEvent e) {
    GC gc = e.gc;

    Rectangle bounds = getBounds();
    if (__ganttChart != null) {
        IColorManager colorManager = __ganttChart.getColorManager();
        gc.setForeground(colorManager.getWeekdayBackgroundColorTop());
        gc.setBackground(colorManager.getWeekdayBackgroundColorBottom());
        gc.fillGradientRectangle(0, 0, bounds.width, bounds.height, true);
    } else {
        gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        gc.fillRectangle(bounds);
    }
}
 
Example 10
Source File: ChoiceWidget.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw the composite
 */
private void drawComposite() {

	final Rectangle rect = getClientArea();
	final Image newImage = new Image(getDisplay(), Math.max(1, rect.width), Math.max(1, rect.height));

	final GC gc = new GC(newImage);

	final boolean inside = insideComposite || insideImage || insideInstruction || insideText;

	if (!inside && !selection) {
		gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
		gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
		gc.drawRectangle(rect.x, rect.y, rect.width, rect.height);
	} else {
		// The mouse is over OR the item is selected
		final Color gradientColor = inside ? new Color(getDisplay(), 220, 231, 243) : new Color(getDisplay(), 241, 241, 241);
		final Color borderColor = inside ? new Color(getDisplay(), 35, 107, 178) : new Color(getDisplay(), 192, 192, 192);

		gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
		gc.setBackground(gradientColor);
		gc.fillGradientRectangle(rect.x, rect.y, rect.width, rect.height, true);

		gc.setForeground(borderColor);
		gc.drawRoundRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1, 2, 2);

		gradientColor.dispose();
		borderColor.dispose();
	}
	gc.dispose();

	setBackgroundImage(newImage);
	if (oldImage != null) {
		oldImage.dispose();
	}
	oldImage = newImage;
}
 
Example 11
Source File: RoundedToolbar.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawBorders(final GC gc, final int width, final int height) {
	final AdvancedPath path = new AdvancedPath(getDisplay());
	path.addRoundRectangle(0, 0, width, height, cornerRadius, cornerRadius);
	gc.setClipping(path);

	gc.setForeground(START_GRADIENT_COLOR);
	gc.setBackground(END_GRADIENT_COLOR);
	gc.fillGradientRectangle(0, 0, width, height, true);

	gc.setForeground(BORDER_COLOR);
	gc.drawRoundRectangle(0, 0, width - 1, height - 1, cornerRadius, cornerRadius);

	gc.setClipping((Rectangle) null);
}
 
Example 12
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 13
Source File: AbstractPaintManager.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawCheckpointMarker(final GC gc, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final boolean threeDee, final int x, final int y, final int width, final int height, final Rectangle bounds) {
    final float fHoriSpacer = width * 0.17f;
    final int hSpacer = (int) fHoriSpacer;

    final float fVertiSpacer = height * 0.23f;
    final int vSpacer = (int) fVertiSpacer;

    final Rectangle topToBottom = new Rectangle(x + hSpacer, y, width - (hSpacer * 2), height + vSpacer);
    final Rectangle leftToRight = new Rectangle(x, y + vSpacer, width, height - vSpacer);
    final Rectangle inner = new Rectangle(x + hSpacer, y + vSpacer, width - (hSpacer * 2), height - (vSpacer * 2));

    Color cEvent = event.getStatusColor();
    Color gradient = event.getGradientStatusColor();

    if (cEvent == null) {
        cEvent = settings.getDefaultEventColor();
    }
    if (gradient == null) {
        gradient = settings.getDefaultGradientEventColor();
    }

    gc.setForeground(gradient);
    gc.setBackground(cEvent);
    gc.fillRectangle(topToBottom);
    gc.fillRectangle(leftToRight);
    gc.fillGradientRectangle(inner.x, inner.y, inner.width, inner.height, true);

    gc.setForeground(colorManager.getBlack());

    gc.drawRectangle(topToBottom);
    gc.drawRectangle(leftToRight);

    if (threeDee) {
        final boolean alpha = (colorManager.useAlphaDrawing() || colorManager.useAlphaDrawingOn3DEventDropShadows());
        if (alpha) {
            gc.setAlpha(200);
        }

        gc.setForeground(colorManager.getFadeOffColor1());
        // horizontal line.. ends a few pixles right of bottom right corner
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 1, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 1);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 1, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 1);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 1, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        // vertical line at end, starts slightly below top right corner
        gc.drawLine(leftToRight.x + leftToRight.width + 1, leftToRight.y + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(100);
        }

        gc.setForeground(colorManager.getFadeOffColor2());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 2, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 2);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 2, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 2);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 2, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 2);

        gc.drawLine(leftToRight.x + leftToRight.width + 2, leftToRight.y + 3, leftToRight.x + leftToRight.width + 2, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(50);
        }

        gc.setForeground(colorManager.getFadeOffColor3());
        gc.drawLine(leftToRight.x, leftToRight.y + leftToRight.height + 3, leftToRight.x + hSpacer - 1, leftToRight.y + leftToRight.height + 3);
        gc.drawLine(leftToRight.x + hSpacer, leftToRight.y + leftToRight.height + vSpacer + 3, leftToRight.x - hSpacer + leftToRight.width, leftToRight.y + leftToRight.height + vSpacer + 3);
        gc.drawLine(leftToRight.x + leftToRight.width - hSpacer + 1, leftToRight.y + leftToRight.height + 3, leftToRight.x + leftToRight.width + 1, leftToRight.y + leftToRight.height + 3);

        gc.drawLine(leftToRight.x + leftToRight.width + 3, leftToRight.y + 4, leftToRight.x + leftToRight.width + 3, leftToRight.y + leftToRight.height + 1);

        if (alpha) {
            gc.setAlpha(255);
            gc.setAdvanced(false);
        }

    }
}
 
Example 14
Source File: AdvancedTooltipDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static void drawBorders(final GC gc, final IColorManager colorManager, final Rectangle bounds) {
	gc.setForeground(colorManager.getAdvancedTooltipInnerFillTopColor());
	gc.setBackground(colorManager.getAdvancedTooltipInnerFillBottomColor());

	gc.fillGradientRectangle(bounds.x, bounds.y, bounds.width, bounds.height, true);

	// draw border
	gc.setForeground(colorManager.getAdvancedTooltipBorderColor());
	gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);

	// what would would the world be without faded gradient corners? boring!
	// so let's draw a few.

	// draw corners
	gc.setForeground(colorManager.getAdvancedTooltipShadowCornerOuterColor());
	// top left
	gc.drawLine(bounds.x + 1, bounds.y, bounds.x + 1, bounds.y);
	gc.drawLine(bounds.x, bounds.y + 1, bounds.x, bounds.y + 1);
	// top right
	gc.drawLine(bounds.x + bounds.width - 2, bounds.y, bounds.x + bounds.width - 2, bounds.y);
	gc.drawLine(bounds.x + bounds.width - 1, bounds.y + 1, bounds.x + bounds.width - 1, bounds.y + 1);
	// bottom right
	gc.drawLine(bounds.x + bounds.width - 1, bounds.y + bounds.height - 2, bounds.x + bounds.width - 1, bounds.y + bounds.height - 2);
	gc.drawLine(bounds.x + bounds.width - 2, bounds.y + bounds.height - 1, bounds.x + bounds.width - 2, bounds.y + bounds.height - 1);
	// bottom left
	gc.drawLine(bounds.x + 1, bounds.y + bounds.height - 1, bounds.x + 1, bounds.y + bounds.height - 1);
	gc.drawLine(bounds.x, bounds.y + bounds.height - 2, bounds.x, bounds.y + bounds.height - 2);

	// shadowed corner inside the above
	gc.setForeground(colorManager.getAdvancedTooltipShadowCornerInnerColor());
	// top left
	gc.drawLine(bounds.x + 2, bounds.y, bounds.x + 2, bounds.y);
	gc.drawLine(bounds.x, bounds.y + 2, bounds.x, bounds.y + 2);
	// top right
	gc.drawLine(bounds.x + bounds.width - 3, bounds.y, bounds.x + bounds.width - 3, bounds.y);
	gc.drawLine(bounds.x + bounds.width - 1, bounds.y + 2, bounds.x + bounds.width - 1, bounds.y + 2);
	// bottom right
	gc.drawLine(bounds.x + bounds.width - 1, bounds.y + bounds.height - 3, bounds.x + bounds.width - 1, bounds.y + bounds.height - 3);
	gc.drawLine(bounds.x + bounds.width - 3, bounds.y + bounds.height - 1, bounds.x + bounds.width - 3, bounds.y + bounds.height - 1);
	// bottom left
	gc.drawLine(bounds.x + 2, bounds.y + bounds.height - 1, bounds.x + 2, bounds.y + bounds.height - 1);
	gc.drawLine(bounds.x, bounds.y + bounds.height - 3, bounds.x, bounds.y + bounds.height - 3);

	// draw inner corner pixel in each corner
	gc.setForeground(colorManager.getAdvancedTooltipShadowInnerCornerColor());
	// top left
	gc.drawLine(bounds.x + 1, bounds.y + 1, bounds.x + 1, bounds.y + 1);
	// top right
	gc.drawLine(bounds.x + bounds.width - 2, bounds.y + 1, bounds.x + bounds.width - 2, bounds.y + 1);
	// bottom right
	gc.drawLine(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2, bounds.x + bounds.width - 2, bounds.y + bounds.height - 2);
	// bottom left
	gc.drawLine(bounds.x + 1, bounds.y + bounds.height - 2, bounds.x + 1, bounds.y + bounds.height - 2);

}
 
Example 15
Source File: BreadcrumbViewer.java    From birt 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 16
Source File: Win7GridColumnHeaderRenderer.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw the column header based on the given colors
 * @param graphics
 * @param bounds
 * @param colors
 */
protected static void drawColumnHeader(GC graphics, Rectangle bounds, Color[] colors){
    int x = bounds.x;
    int y = bounds.y;

    int topRectHeight = (int)Math.round((bounds.height-3)*.45);
    int bottomRectHeight = bounds.height-3-topRectHeight;
    int bottomRectY = y+topRectHeight+1;

    //1 - top highlight
    graphics.setForeground(colors[0]);
    graphics.drawLine(x, y, x+bounds.width-1, y);

    //2 - left upper
    graphics.setBackground(colors[1]);
    graphics.fillRectangle(x, y+1, 1, topRectHeight);

    //3 - upper fill
    graphics.setBackground(colors[2]);
    graphics.fillRectangle(x+1, y+1, bounds.width-3, topRectHeight);

    //4 - right upper
    graphics.setBackground(colors[3]);
    graphics.fillRectangle(x+bounds.width-2, y+1, 1, topRectHeight);

    //5 - right upper gradient (shadow/highlight)
    graphics.setBackground(colors[5]);
    if ( colors[4] != null ){
        graphics.setForeground(colors[4]);
        graphics.fillGradientRectangle(x+bounds.width-1, y+1, 1, topRectHeight, true);
    } else {
        graphics.fillRectangle(x+bounds.width-1, y+1, 1, topRectHeight);
    }

    //6 - left bottom gradient (shadow/hightlight)
    graphics.setBackground(colors[7]);
    if ( colors[6] != null ){
        graphics.setForeground(colors[6]);
        graphics.fillGradientRectangle(x, bottomRectY, 1, bottomRectHeight, true);
    } else {
        graphics.fillRectangle(x, bottomRectY, 1, bottomRectHeight);
    }

    //7 - bottom fill
    graphics.setBackground(colors[9]);
    if ( colors[8] != null ){
        graphics.setForeground(colors[8]);
        graphics.fillGradientRectangle(x+1, bottomRectY, bounds.width-3, bottomRectHeight, true);
    } else {
        graphics.fillRectangle(x+1, bottomRectY, bounds.width-3, bottomRectHeight);
    }

    //8 - right bottom gradient (shadow/highlight)
    graphics.setBackground(colors[11]);
    if ( colors[10] != null ){
        graphics.setForeground(colors[10]);
        graphics.fillGradientRectangle(x+bounds.width-2, bottomRectY, 1, bottomRectHeight, true);
    } else {
        graphics.fillRectangle(x+bounds.width-2, bottomRectY, 1, bottomRectHeight);
    }

    //9 - right bottom cell border
    graphics.setBackground(colors[13]);
    if ( colors[12] != null ){
        graphics.setForeground(colors[12]);
        graphics.fillGradientRectangle(x+bounds.width-1, bottomRectY, 1, bottomRectHeight, true);
    } else {
        graphics.fillRectangle(x+bounds.width-1, bottomRectY, 1, bottomRectHeight);
    }

    //10 - bottom shadow
    graphics.setForeground(colors[14]);
    graphics.drawLine(x, y+bounds.height-2, x+bounds.width-1, y+bounds.height-2);

    //11 - bottom cell border
    graphics.setForeground(colors[15]);
    graphics.drawLine(x, y+bounds.height-1, x+bounds.width-1, y+bounds.height-1);
}
 
Example 17
Source File: Win7ColumnHeaderUtil.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw the column header based on the given colors
 *
 * @param graphics
 * @param bounds
 * @param palette
 */
protected static void drawColumnHeader(GC graphics, Rectangle bounds, Palette palette) {
	int x = bounds.x;
	int y = bounds.y;

	int topRectHeight = (int) Math.round((bounds.height - 3) * .45);
	int bottomRectHeight = bounds.height - 3 - topRectHeight;
	int bottomRectY = y + topRectHeight + 1;

	// 2 - left upper
	graphics.setBackground(palette.getColors()[1]);
	graphics.fillRectangle(x, y, 1, topRectHeight + 1);

	// 3 - upper fill
	graphics.setBackground(palette.getColors()[2]);
	graphics.fillRectangle(x + 1, y, bounds.width - 3, topRectHeight + 1);

	// 4 - right upper
	graphics.setBackground(palette.getColors()[3]);
	graphics.fillRectangle(x + bounds.width - 2, y, 1, topRectHeight + 1);

	// 5 - right upper gradient (shadow/highlight)
	graphics.setBackground(palette.getColors()[5]);
	if (palette.getColors()[4] != null) {
		graphics.setForeground(palette.getColors()[4]);
		graphics.fillGradientRectangle(x + bounds.width - 1, y, 1, topRectHeight + 1, true);
	} else {
		graphics.fillRectangle(x + bounds.width - 1, y, 1, topRectHeight + 1);
	}

	// 6 - left bottom gradient (shadow/hightlight)
	graphics.setBackground(palette.getColors()[7]);
	if (palette.getColors()[6] != null) {
		graphics.setForeground(palette.getColors()[6]);
		graphics.fillGradientRectangle(x, bottomRectY, 1, bottomRectHeight, true);
	} else {
		graphics.fillRectangle(x, bottomRectY, 1, bottomRectHeight);
	}

	// 7 - bottom fill
	graphics.setBackground(palette.getColors()[9]);
	if (palette.getColors()[8] != null) {
		graphics.setForeground(palette.getColors()[8]);
		graphics.fillGradientRectangle(x + 1, bottomRectY, bounds.width - 3, bottomRectHeight, true);
	} else {
		graphics.fillRectangle(x + 1, bottomRectY, bounds.width - 3, bottomRectHeight);
	}

	// 8 - right bottom gradient (shadow/highlight)
	graphics.setBackground(palette.getColors()[11]);
	if (palette.getColors()[10] != null) {
		graphics.setForeground(palette.getColors()[10]);
		graphics.fillGradientRectangle(x + bounds.width - 2, bottomRectY, 1, bottomRectHeight, true);
	} else {
		graphics.fillRectangle(x + bounds.width - 2, bottomRectY, 1, bottomRectHeight);
	}

	// 9 - right bottom cell border
	graphics.setBackground(palette.getColors()[13]);
	if (palette.getColors()[12] != null) {
		graphics.setForeground(palette.getColors()[12]);
		graphics.fillGradientRectangle(x + bounds.width - 1, bottomRectY, 1, bottomRectHeight, true);
	} else {
		graphics.fillRectangle(x + bounds.width - 1, bottomRectY, 1, bottomRectHeight);
	}

	// 10 - bottom shadow
	graphics.setForeground(palette.getColors()[14]);
	graphics.drawLine(x, y + bounds.height - 2, x + bounds.width - 1, y + bounds.height - 2);

	// 11 - bottom cell border
	graphics.setForeground(palette.getColors()[15]);
	graphics.drawLine(x, y + bounds.height - 1, x + bounds.width - 1, y + bounds.height - 1);
}
 
Example 18
Source File: GraphicUtils.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void fillGradientRectangle(GC gc, int x, int y, int width, int height,
                                         Color[] gradientColors, int[] gradientPercents,
                                         boolean vertical)
{
    final Color oldBackground = gc.getBackground();
    if (gradientColors.length == 1)
    {
        if (gradientColors[0] != null)
            gc.setBackground(gradientColors[0]);
        gc.fillRectangle(x, y, width, height);
    }
    else
    {
        final Color oldForeground = gc.getForeground();
        Color lastColor = gradientColors[0];
        if (lastColor == null)
            lastColor = oldBackground;
        int pos = 0;
        for (int i = 0; i < gradientPercents.length; ++i)
        {
            gc.setForeground(lastColor);
            lastColor = gradientColors[i + 1];
            if (lastColor == null)
                lastColor = oldBackground;
            gc.setBackground(lastColor);
            if (vertical)
            {
                final int gradientHeight = (gradientPercents[i] * height / 100) - pos;
                gc.fillGradientRectangle(x, y + pos, width, gradientHeight, true);
                pos += gradientHeight;
            }
            else
            {
                final int gradientWidth = (gradientPercents[i] * width / 100) - pos;
                gc.fillGradientRectangle(x + pos, y, gradientWidth, height, false);
                pos += gradientWidth;
            }
        }
        if (vertical && pos < height)
        {
            gc.setBackground(oldBackground);
            gc.fillRectangle(x, y + pos, width, height - pos);
        }
        if (!vertical && pos < width)
        {
            gc.setBackground(oldBackground);
            gc.fillRectangle(x + pos, y, width - pos, height);
        }
        gc.setForeground(oldForeground);
    }
    gc.setBackground(oldBackground);
}
 
Example 19
Source File: AbstractButtonPainter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void paintBackground(GC gc, IColorManager colorManager, ISettings settings, Rectangle bounds, boolean hover, boolean selected) {		
	switch (colorManager.getTheme()) {
		case IColorManager.SKIN_OFFICE_2007:		
		{
			if (!selected && !hover) {
				gc.setBackground(colorManager.getButtonBackgroundColorMiddle());
				gc.setForeground(colorManager.getButtonBackgroundColorTop());
				gc.fillGradientRectangle(bounds.x, 0, bounds.width, 19, true);
				gc.setBackground(colorManager.getButtonBackgroundColorBottom());
				gc.setForeground(colorManager.getButtonBackgroundColorMiddle());
				gc.fillGradientRectangle(bounds.x, 12, bounds.width, CustomButton.BUTTON_HEIGHT-12, true);		
			}
			else {
				if (selected && hover) {
					gc.setBackground(colorManager.getHoverSelectedButtonBackgroundColorMiddle());
					gc.setForeground(colorManager.getHoverSelectedButtonBackgroundColorTop());
					gc.fillGradientRectangle(bounds.x, 0, bounds.width, 19, true);
					gc.setBackground(colorManager.getHoverSelectedButtonBackgroundColorBottom());
					gc.setForeground(colorManager.getHoverSelectedButtonBackgroundColorMiddle());
					gc.fillGradientRectangle(bounds.x, 12, bounds.width, CustomButton.BUTTON_HEIGHT-12, true);		
				}
				else {
					if (hover) {
						gc.setBackground(colorManager.getHoverButtonBackgroundColorMiddle());
						gc.setForeground(colorManager.getHoverButtonBackgroundColorTop());
						gc.fillGradientRectangle(bounds.x, 0, bounds.width, 19, true);
						gc.setBackground(colorManager.getHoverButtonBackgroundColorBottom());
						gc.setForeground(colorManager.getHoverButtonBackgroundColorMiddle());
						gc.fillGradientRectangle(bounds.x, 12, bounds.width, CustomButton.BUTTON_HEIGHT-12, true);									
					}
					else {
						gc.setBackground(colorManager.getSelectedButtonBackgroundColorMiddle());
						gc.setForeground(colorManager.getSelectedButtonBackgroundColorTop());
						gc.fillGradientRectangle(bounds.x, 0, bounds.width, 19, true);
						gc.setBackground(colorManager.getSelectedButtonBackgroundColorBottom());
						gc.setForeground(colorManager.getSelectedButtonBackgroundColorMiddle());
						gc.fillGradientRectangle(bounds.x, 12, bounds.width, CustomButton.BUTTON_HEIGHT-12, true);									
					}
				}
			}
			break;
		}
		case IColorManager.SKIN_BLUE:
		case IColorManager.SKIN_OLIVE:
		case IColorManager.SKIN_SILVER:
		{
			if (!selected && !hover) {
				gc.setBackground(colorManager.getButtonBackgroundColorMiddle());
				gc.setForeground(colorManager.getButtonBackgroundColorBottom());
				gc.fillGradientRectangle(bounds.x, 0, bounds.width, CustomButton.BUTTON_HEIGHT, true);
			}
			else {
				if (selected && hover) {
					gc.setBackground(colorManager.getHoverSelectedButtonBackgroundColorMiddle());
					gc.setForeground(colorManager.getHoverSelectedButtonBackgroundColorBottom());
					gc.fillGradientRectangle(bounds.x, 0, bounds.width, CustomButton.BUTTON_HEIGHT, true);							
				}
				else {
					if (hover) {
						gc.setBackground(colorManager.getHoverButtonBackgroundColorMiddle());
						gc.setForeground(colorManager.getHoverButtonBackgroundColorBottom());
						gc.fillGradientRectangle(bounds.x, 0, bounds.width, CustomButton.BUTTON_HEIGHT, true);							
					}
					else {
						gc.setBackground(colorManager.getSelectedButtonBackgroundColorMiddle());
						gc.setForeground(colorManager.getSelectedButtonBackgroundColorBottom());
						gc.fillGradientRectangle(bounds.x, 0, bounds.width, CustomButton.BUTTON_HEIGHT, true);
					}
				}
			}
			
			break;
		}
	}		
}
 
Example 20
Source File: GraphicUtils.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void fillGradientRectangle(GC gc, int x, int y, int width, int height,
                                         Color[] gradientColors, int[] gradientPercents,
                                         boolean vertical)
{
    final Color oldBackground = gc.getBackground();
    if (gradientColors.length == 1)
    {
        if (gradientColors[0] != null)
            gc.setBackground(gradientColors[0]);
        gc.fillRectangle(x, y, width, height);
    }
    else
    {
        final Color oldForeground = gc.getForeground();
        Color lastColor = gradientColors[0];
        if (lastColor == null)
            lastColor = oldBackground;
        int pos = 0;
        for (int i = 0; i < gradientPercents.length; ++i)
        {
            gc.setForeground(lastColor);
            lastColor = gradientColors[i + 1];
            if (lastColor == null)
                lastColor = oldBackground;
            gc.setBackground(lastColor);
            if (vertical)
            {
                final int gradientHeight = (gradientPercents[i] * height / 100) - pos;
                gc.fillGradientRectangle(x, y + pos, width, gradientHeight, true);
                pos += gradientHeight;
            }
            else
            {
                final int gradientWidth = (gradientPercents[i] * width / 100) - pos;
                gc.fillGradientRectangle(x + pos, y, gradientWidth, height, false);
                pos += gradientWidth;
            }
        }
        if (vertical && pos < height)
        {
            gc.setBackground(oldBackground);
            gc.fillRectangle(x, y + pos, width, height - pos);
        }
        if (!vertical && pos < width)
        {
            gc.setBackground(oldBackground);
            gc.fillRectangle(x + pos, y, width - pos, height);
        }
        gc.setForeground(oldForeground);
    }
    gc.setBackground(oldBackground);
}