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

The following examples show how to use org.eclipse.swt.graphics.GC#fillRoundRectangle() . 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: Node.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Paints the Node
 */
public void paint(GC gc) {
	gc.setBackground(getBackgroundColor());
	gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));

	gc.fillRoundRectangle(Math.round(x), Math.round(y), Math.round(width), Math.round(height), 5, 5);
	GraphUtils.drawString(gc, title, x, y, width, height, 0);

	if (hasOutgoingCrossLinksInternal || hasOutgoingCrossLinksExternal) {
		Color colorRed = gc.getDevice().getSystemColor(SWT.COLOR_RED);
		gc.setBackground(colorRed);
		gc.setForeground(colorRed);

		int ovalX = Math.round(x + width - SIZE_CROSS_LINKS_MARKER - 2);
		int ovalY = Math.round(y + 2);
		int ovalSize = Math.round(SIZE_CROSS_LINKS_MARKER);
		if (hasOutgoingCrossLinksInternal) {
			gc.fillOval(ovalX, ovalY, ovalSize, ovalSize);
		} else {
			gc.drawOval(ovalX, ovalY, ovalSize, ovalSize);
		}
	}

	gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
}
 
Example 2
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 3
Source File: GamaIcons.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static GamaIcon createColorIcon(final String s, final GamaUIColor gcolor, final int width,
		final int height) {
	final String name = COLOR_PREFIX + s;
	GamaIcon icon = getInstance().getIcon(s);
	if (icon == null) {
		// Color color = gcolor.color();
		// RGB c = new RGB(color.getRed(), color.getGreen(),
		// color.getBlue());
		final Image image = new Image(WorkbenchHelper.getDisplay(), width, height);
		final GC gc = new GC(image);
		gc.setAntialias(SWT.ON);
		gc.setBackground(gcolor.color());
		gc.fillRoundRectangle(0, 0, width, height, width / 3, height / 3);
		gc.dispose();
		final ImageData data = image.getImageData();
		data.transparentPixel = data.palette.getPixel(new RGB(255, 255, 255));
		icon = new GamaIcon(name);
		getInstance().putImageInCache(name, new Image(WorkbenchHelper.getDisplay(), data));
		image.dispose();
		getInstance().putIconInCache(name, icon);
	}
	return icon;
}
 
Example 4
Source File: FlatButton.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void drawBackground(final GC gc, final Rectangle rect) {
	setBackground(getParent().getBackground());

	final GamaUIColor color = GamaColors.get(colorCode);
	final Color background = hovered ? color.lighter() : color.color();
	final Color foreground = GamaColors.getTextColorForBackground(background).color();
	gc.setForeground(foreground);
	gc.setBackground(background);

	if (down) {
		gc.fillRoundRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2, 5, 5);
	} else {
		final Path path = createClipping(rect);
		gc.setClipping(path);
		gc.fillRectangle(rect);
		gc.setClipping((Rectangle) null);
		path.dispose();
	}

}
 
Example 5
Source File: NebulaSlider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawBar(GC gc) {
	final Rectangle rect = getClientArea();
	gc.setForeground(barBorderColor);
	gc.setBackground(barInsideColor);

	final int x = H_MARGIN + SELECTOR_WIDTH / 2;
	final int y = (rect.height - BAR_HEIGHT) / 2;
	final int width = rect.width - H_MARGIN * 2 - SELECTOR_WIDTH;

	gc.fillRoundRectangle(x, y, width, BAR_HEIGHT, BAR_HEIGHT, BAR_HEIGHT);
	gc.drawRoundRectangle(x, y, width, BAR_HEIGHT, BAR_HEIGHT, BAR_HEIGHT);
}
 
Example 6
Source File: NebulaSlider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawSelectionPart(GC gc) {
	final Rectangle rect = getClientArea();
	gc.setForeground(barBorderColor);
	gc.setBackground(barSelectionColor);

	final int x = H_MARGIN + SELECTOR_WIDTH / 2;
	final int y = (rect.height - BAR_HEIGHT) / 2;

	gc.fillRoundRectangle(x, y, xPosition, BAR_HEIGHT, BAR_HEIGHT, BAR_HEIGHT);
	gc.drawRoundRectangle(x, y, xPosition, BAR_HEIGHT, BAR_HEIGHT, BAR_HEIGHT);
}
 
Example 7
Source File: NebulaSlider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawSelector(GC gc) {
	final Rectangle rect = getClientArea();
	gc.setForeground(selectorColorBorder);
	gc.setBackground(selectorColor);

	final int y = (rect.height - SELECTOR_HEIGHT) / 2;

	// Draw the body
	gc.fillRoundRectangle(H_MARGIN + xPosition, y, SELECTOR_WIDTH, SELECTOR_HEIGHT, SELECTOR_HEIGHT, SELECTOR_HEIGHT);
	gc.drawRoundRectangle(H_MARGIN + xPosition, y, SELECTOR_WIDTH, SELECTOR_HEIGHT, SELECTOR_HEIGHT, SELECTOR_HEIGHT);

	// Draw the arrows
	gc.setForeground(arrowColor);
	gc.setLineWidth(3);
	final int baseY = y + SELECTOR_HEIGHT / 2;
	gc.drawLine(H_MARGIN + xPosition + 10, baseY, H_MARGIN + xPosition + 17, baseY - 7);
	gc.drawLine(H_MARGIN + xPosition + 10, baseY, H_MARGIN + xPosition + 17, baseY + 7);

	gc.drawLine(H_MARGIN + xPosition + SELECTOR_WIDTH - 10, baseY, H_MARGIN + xPosition + SELECTOR_WIDTH - 17, baseY - 7);
	gc.drawLine(H_MARGIN + xPosition + SELECTOR_WIDTH - 10, baseY, H_MARGIN + xPosition + SELECTOR_WIDTH - 17, baseY + 7);

	// And the value
	gc.setForeground(selectorTextColor);
	gc.setFont(textFont);
	final String valueAsString = String.valueOf(value);
	final Point textSize = gc.textExtent(valueAsString);

	final int xText = H_MARGIN + xPosition + SELECTOR_WIDTH / 2;
	gc.drawText(valueAsString, xText - textSize.x / 2, y + 2, true);
}
 
Example 8
Source File: Chips.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private int drawBackground(final GC gc) {
	final Rectangle rect = getClientArea();

	final Color color = determineBackgroundColor();
	gc.setBackground(color);
	gc.fillRoundRectangle(0, 0, rect.width, rect.height, rect.height, rect.height);

	return rect.height / 2 + 2;
}
 
Example 9
Source File: Histogram.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draw a time range window
 *
 * @param imageGC
 *            the GC
 * @param rangeStartTime
 *            the range start time
 * @param rangeDuration
 *            the range duration
 */
protected void drawTimeRangeWindow(GC imageGC, long rangeStartTime, long rangeDuration) {

    if (fScaledData == null) {
        return;
    }

    // Map times to histogram coordinates
    double bucketSpan = fScaledData.fBucketDuration;
    long startTime = Math.min(rangeStartTime, rangeStartTime + rangeDuration);
    double rangeWidth = (Math.abs(rangeDuration) / bucketSpan);

    int left = (int) ((startTime - fDataModel.getFirstBucketTime()) / bucketSpan);
    int right = (int) (left + rangeWidth);
    int center = (left + right) / 2;
    int height = fCanvas.getSize().y;
    int arc = Math.min(15, (int) rangeWidth);

    // Draw the selection window
    imageGC.setForeground(fTimeRangeColor);
    imageGC.setLineWidth(1);
    imageGC.setLineStyle(SWT.LINE_SOLID);
    imageGC.drawRoundRectangle(left, 0, (int) rangeWidth, height - 1, arc, arc);

    // Fill the selection window
    imageGC.setBackground(fTimeRangeColor);
    imageGC.setAlpha(35);
    imageGC.fillRoundRectangle(left + 1, 1, (int) rangeWidth - 1, height - 2, arc, arc);
    imageGC.setAlpha(255);

    // Draw the cross hair
    imageGC.setForeground(fTimeRangeColor);
    imageGC.setLineWidth(1);
    imageGC.setLineStyle(SWT.LINE_SOLID);

    int chHalfWidth = ((rangeWidth < 60) ? (int) ((rangeWidth * 2) / 3) : 40) / 2;
    imageGC.drawLine(center - chHalfWidth, height / 2, center + chHalfWidth, height / 2);
    imageGC.drawLine(center, (height / 2) - chHalfWidth, center, (height / 2) + chHalfWidth);
}
 
Example 10
Source File: SimpleSlider.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Method paintControl()
 *
 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
 */
@Override
public void paintControl(final PaintEvent e) {
	final GC gc = e.gc;
	final Rectangle r = getClientArea();
	gc.setBackground(getParent().getBackground());
	gc.fillRectangle(r);
	gc.setBackground(color);
	r.y = (int) ((double) parent.getSize().y / 2 - 2d);
	r.height = 3;
	gc.fillRoundRectangle(r.x, r.y, r.width, r.height, 3, 3);
}
 
Example 11
Source File: MandantSelectionContributionItem.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static Image getBoxSWTColorImage(Color color){
	Display display = Display.getCurrent();
	Image image = new Image(display, 16, 16);
	GC gc = new GC(image);
	gc.setBackground(color);
	gc.fillRoundRectangle(0, 0, 16, 16, 8, 8);
	gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
	gc.dispose();
	return image;
}
 
Example 12
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);
	}
}
 
Example 13
Source File: TimeGraphRender.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void innerDraw(GC gc) {
    Rectangle bounds = getBounds();
    gc.fillRoundRectangle(bounds.x, bounds.y, bounds.width, bounds.height, fArc, fArc);
}
 
Example 14
Source File: NButton.java    From ldparteditor with MIT License 4 votes vote down vote up
private void paint(PaintEvent event) {
    final GC gc = event.gc;
    final Image img = this.img;
    final boolean focused = this.isFocusControl();
    final boolean enabled = this.isEnabled();
    final boolean hasImage = img != null;
    final int img_width = hasImage ? img.getImageData().width : 0;
    final int img_height = hasImage ? img.getImageData().height : 0;
    final int this_width = getBounds().width - 1;

    gc.setFont(Font.SYSTEM);
    // setFont before using textExtent, so that the size of the text
    // can be calculated correctly
    final Point textExtent = getText().isEmpty() ? new Point(0,0) : gc.textExtent(getText());

    // TODO 1. Calculate sizes


    // TODO 2. Draw Content

    if (selected && (canToggle || isRadio)) {
        gc.setBackground(SWTResourceManager.getColor(160, 160, 200));
        gc.fillRoundRectangle(0, 0, Math.max(img_width + 9 + textExtent.x, this_width), Math.max(textExtent.y, img_height) + 9, 5, 5);
        gc.setBackground(getBackground());
    }

    gc.setForeground(SWTResourceManager.getColor(255, 255, 255));

    if (hovered || focused) {
        gc.setForeground(SWTResourceManager.getColor(0, 0, 0));
    }
    if (pressed) {
        gc.setForeground(SWTResourceManager.getColor(220, 220, 220));
    }



    if (!canCheck && !hasBorder) {

        if (!enabled) {
            gc.setForeground(SWTResourceManager.getColor(200, 200, 200));
        }
        gc.drawRoundRectangle(0, 0, Math.max(img_width + 9 + textExtent.x, this_width), Math.max(textExtent.y, img_height) + 9, 5, 5);

        gc.setForeground(SWTResourceManager.getColor(60, 60, 60));

        if (hovered || focused) {
            gc.setBackground(SWTResourceManager.getColor(160, 160, 200));
            gc.fillRoundRectangle(1, 1, Math.max(img_width + 9 + textExtent.x, this_width) - 1, Math.max(textExtent.y, img_height) + 9 - 1, 5, 5);
            if (selected && (canToggle || isRadio)) {
                gc.setBackground(SWTResourceManager.getColor(160, 160, 200));
            } else {
                gc.setBackground(getBackground());
            }
            gc.fillRoundRectangle(2, 2, Math.max(img_width + 9 + textExtent.x, this_width) - 3, Math.max(textExtent.y, img_height) + 9 - 3, 5, 5);

        }
        if (pressed) {
            gc.setForeground(SWTResourceManager.getColor(30, 30, 30));
        }
        if (!enabled) {
            gc.setForeground(SWTResourceManager.getColor(200, 200, 200));
        }
        gc.drawRoundRectangle(1, 1, Math.max(img_width + 9 + textExtent.x, this_width) - 1, Math.max(textExtent.y, img_height) + 9 - 1, 5, 5);
    }

    if (hasImage) {

        gc.drawImage(img, 5, 5);
    }

    gc.setForeground(getForeground());

    gc.drawString(getText(), img_width + 5, 5, true);


    // 3. Paint custom forms
    for (PaintListener pl : painters) {
        pl.paintControl(event);
    }
}
 
Example 15
Source File: ColorLabel.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the color label
 *
 * @param e
 */
protected void onPaint(PaintEvent e) {
  GC gc = e.gc;

  int frameWidth = selected ? FRAME_WIDTH_SELECTED : FRAME_WIDTH_UNSELECTED;

  int x = frameWidth;
  int y = VERTICAL_OFFSET + frameWidth;
  int width = rectangleWidth - 2 * frameWidth;
  int height = rectangleHeight - 2 * frameWidth;

  if (enabledColor != null) {
    /*
     * Save the old background color and set it back to this after
     * drawing the rectangle. Otherwise the text will have the same
     * background color as the rectangle.
     */
    final Color oldBackground = gc.getBackground();
    final Color oldForeground = gc.getForeground();

    // set frame color
    Color colorToPaint = isEnabled() ? frameEnabledColor : frameDisabledColor;

    gc.setForeground(colorToPaint);
    gc.setBackground(colorToPaint);

    // Draw the frame
    gc.fillRoundRectangle(
        0, VERTICAL_OFFSET, rectangleWidth, rectangleHeight, RECTANGLE_ARC, RECTANGLE_ARC);

    // set label color
    colorToPaint = isEnabled() ? enabledColor : disabledColor;

    gc.setForeground(colorToPaint);
    gc.setBackground(colorToPaint);

    // Draw the label
    gc.fillRoundRectangle(x, y, width, height, RECTANGLE_ARC, RECTANGLE_ARC);
    // setting back the colors like they were before
    gc.setForeground(oldForeground);
    gc.setBackground(oldBackground);
  }
}
 
Example 16
Source File: PaintUtils.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
public static void drawRoundedRectangle(GC gc, Rectangle bounds, Color backgroundColor) {
  Color backupBackground = gc.getBackground();
  gc.setBackground(backgroundColor);
  gc.fillRoundRectangle(bounds.x, bounds.y, bounds.width, bounds.height, ARC, ARC);
  gc.setBackground(backupBackground);
}