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

The following examples show how to use org.eclipse.swt.graphics.GC#fillOval() . 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: ImageSelector.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private int drawCircles(final GC gc) {
	int x = 0;
	final Rectangle clientArea = getClientArea();
	rects.clear();
	for (int i = 0; i < carousel.getImages().size(); i++) {
		final Rectangle rect = new Rectangle(x, (clientArea.height - CIRCLE_DIAMETER) / 2, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		rects.add(rect);
		if (i == carousel.getSelection()) {
			gc.setBackground(circleBackground);
			gc.fillOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		} else if (i == indexHover) {
			//
			gc.setForeground(circleHoverColor);
			gc.drawOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		} else {
			gc.setForeground(circleForeground);
			gc.drawOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		}
		x += CIRCLE_DIAMETER + 5;
	}
	return x + CIRCLE_DIAMETER;

}
 
Example 2
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 3
Source File: EyeButton.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawEye(final GC gc, final Color clr) {
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setLineWidth(2);

	final Rectangle rect = getClientArea();
	final int eyeWidth = (int) (rect.width * .7);
	final int eyeHeight = (int) (rect.height * .5);
	gc.setForeground(clr);
	gc.drawOval((int) (rect.width * .15), (int) (rect.height * .25), eyeWidth, eyeHeight);

	gc.setBackground(clr);
	gc.fillOval(rect.width / 2 - CIRCLE_RAY / 2, rect.height / 2 - CIRCLE_RAY / 2, CIRCLE_RAY, CIRCLE_RAY);
}
 
Example 4
Source File: Chips.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawClose(final GC gc, final int x) {
	final Color foreground = cursorInside ? closeButtonHoverForeground : closeButtonForeground;
	final Color background = cursorInside ? closeButtonHoverBackground : closeButtonBackground;
	final Rectangle rect = getClientArea();

	gc.setBackground(background);
	gc.setForeground(foreground);
	closeCenter = new Point(x + 4 + CLOSE_CIRCLE_RAY, (rect.height - 2 * CLOSE_CIRCLE_RAY) / 2 + CLOSE_CIRCLE_RAY);
	gc.fillOval(x + 4, (rect.height - 2 * CLOSE_CIRCLE_RAY) / 2, 2 * CLOSE_CIRCLE_RAY, 2 * CLOSE_CIRCLE_RAY);

	// Cross
	gc.setLineWidth(2);
	gc.drawLine(closeCenter.x - 3, closeCenter.y - 3, closeCenter.x + 3, closeCenter.y + 3);
	gc.drawLine(closeCenter.x + 3, closeCenter.y - 3, closeCenter.x - 3, closeCenter.y + 3);
}
 
Example 5
Source File: AbstractIntersectionExample.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draws an ellipse with the given GC at the control points location.
 *
 * @param gc
 */
public void draw(GC gc) {
	// System.out.println(ellipse.toString());
	gc.setBackground(Display.getCurrent().getSystemColor(color));
	gc.fillOval((int) ellipse.getX(), (int) ellipse.getY(),
			(int) ellipse.getWidth(), (int) ellipse.getHeight());
}
 
Example 6
Source File: AbstractContainmentExample.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Draws an ellipse with the given GC at the control points location.
 *
 * @param gc
 */
public void draw(GC gc) {
	// System.out.println(ellipse.toString());
	gc.setBackground(Display.getCurrent().getSystemColor(color));
	gc.fillOval((int) ellipse.getX(), (int) ellipse.getY(),
			(int) ellipse.getWidth(), (int) ellipse.getHeight());
}
 
Example 7
Source File: SwtScatterChart.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void drawSelectedDot(GC gc) {
    for (SwtChartPoint point : getSelection().getPoints()) {
        ISeries series = point.getSeries();
        Point coor = series.getPixelCoordinates(point.getIndex());
        int symbolSize = ((ILineSeries) series).getSymbolSize();

        Color symbolColor = ((ILineSeries) series).getSymbolColor();
        if (symbolColor == null) {
            continue;
        }
        Color darkColor = IChartViewer.getCorrespondingColor(symbolColor);
        /* Create a colored dot for selection */
        gc.setBackground(darkColor);
        gc.fillOval(coor.x - symbolSize, coor.y - symbolSize, symbolSize * 2, symbolSize * 2);

        /* Configure cross settings */
        gc.setLineWidth(2);
        gc.setLineStyle(SWT.LINE_SOLID);
        int drawingDelta = 2 * symbolSize;

        /* Vertical line */
        gc.drawLine(coor.x, coor.y - drawingDelta, coor.x, coor.y + drawingDelta);

        /* Horizontal line */
        gc.drawLine(coor.x - drawingDelta, coor.y, coor.x + drawingDelta, coor.y);
    }
}
 
Example 8
Source File: ViewList.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
   * Dynamically creates an image with the given color
   * @param color
   * @return
   */
  private Image getSymbol(Color color) {
      
      // Check cache
      if (symbols.containsKey(color)) {
          return symbols.get(color);
      }
      
      // Define
      final int WIDTH = 16;
      final int HEIGHT = 16;

      // "Fix" for Bug #50163
      Image image = IS_LINUX ? getTransparentImage(table.getDisplay(), WIDTH, HEIGHT) : 
                               new Image(table.getDisplay(), WIDTH, HEIGHT);
      
      // Prepare
      GC gc = new GC(image);
      gc.setBackground(color);

      // Render
if (!IS_LINUX) {
	gc.fillRectangle(0, 0, WIDTH, HEIGHT);
} else {
	gc.setAntialias(SWT.ON);
	gc.fillOval(0, 0, WIDTH, HEIGHT);
	gc.setAntialias(SWT.OFF);
}

// Cleanup
      gc.dispose();
      
      // Store in cache and return
      symbols.put(color, image);
      return image;
  }
 
Example 9
Source File: MapView.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void renderPoint(GC gc, LayerConfig conf, Feature f, Point point) {
	int[] p = translation.translate(point);
	Color fillColor = conf.getFillColor(f);
	int r = 5 + zoom;
	if (fillColor != null) {
		gc.setBackground(fillColor);
		gc.fillOval(p[0], p[1], r, r);
	} else {
		gc.drawOval(p[0], p[1], r, r);
	}
}
 
Example 10
Source File: ProgressCircle.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void paintControl(final PaintEvent e) {
	firstDisplay = false;
	final GC gc = e.gc;
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);

	// Draw the selected part
	final Path pathHighlight = new Path(getDisplay());
	float ratio = 1.0f * value / (maximum - minimum);
	if (minimum < 0 && maximum < 0) {
		ratio = -1.0f * (minimum - value) / (maximum - minimum);
	}

	float angle = ratio * 360f;
	if (minimum < 0 && maximum > 0) {
		angle += 180;
	}

	pathHighlight.addArc(MARGIN, MARGIN, circleSize, circleSize, 90, -angle);
	pathHighlight.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	pathHighlight.close();

	gc.setBackground(getHighlightColor());
	gc.fillPath(pathHighlight);
	pathHighlight.dispose();

	// Draw the unselected part
	final Path path = new Path(getDisplay());
	final float unselectedAngle = 360f - angle;

	path.addArc(MARGIN, MARGIN, circleSize, circleSize, 90 - angle, -unselectedAngle);
	path.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2);
	path.close();

	gc.setBackground(getForeground());
	gc.fillPath(path);
	pathHighlight.dispose();

	// Draw the hole
	gc.setBackground(getBackground());
	gc.fillOval(MARGIN + thickness, MARGIN + thickness, circleSize - thickness * 2, circleSize - thickness * 2);

	if (showText) {
		gc.setForeground(getHighlightColor());
		final String text;
		if (isTimer) {
			final LocalTime time = LocalTime.ofSecondOfDay(value);
			if (time.getHour() == 0) {
				if (time.getMinute() == 0) {
					// Seconds only
					text = String.format("%02d", time.getSecond());
				} else {
					// Minutes+secondes
					text = String.format("%02d:%02d", time.getMinute(), time.getSecond());
				}
			} else {
				// Hour/Min/sec
				text = String.format("%02d:%02d:%02d", time.getHour(), time.getMinute(), time.getSecond());
			}
		} else {
			text = String.format(textPattern, value);
		}
		final Point textSize = gc.stringExtent(text);
		final int x = MARGIN + (circleSize - textSize.x) / 2;
		final int y = (circleSize - textSize.y) / 2;
		gc.drawText(text, x, y, true);
	}
}
 
Example 11
Source File: TableHierarchyRenderer.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
protected void drawLeaf(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    gc.fillOval(x + size / 2, y + size / 2, size / 2, size / 2);
    gc.setBackground(bg);
}
 
Example 12
Source File: TableHierarchyRenderer.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
protected void drawLeaf(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    gc.fillOval(x + size / 2, y + size / 2, size / 2, size / 2);
    gc.setBackground(bg);
}
 
Example 13
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a node.
 *
 * @param g
 */
private void drawNodes(final GC g) {

    // Prepare
    Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight);
    Transform transform = new Transform(g.getDevice());
    
    // Set style
    g.setLineWidth(STROKE_WIDTH_NODE);
    g.setFont(font);

    // Draw nodes
    for (List<ARXNode> level : lattice) {
        for (ARXNode node : level) {
            
            // Obtain coordinates
            double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER);
            bounds.x = (int)(center[0] - nodeWidth / 2d);
            bounds.y = (int)(center[1] - nodeHeight / 2d);
            
            // Clipping
            if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { 
                
                // Retrieve/compute text rendering data
                SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH);
                Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT);
                if (path == null || path.getPath() == null) {
                    String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL);
                    path = new SerializablePath(new Path(canvas.getDisplay()));
                    path.getPath().addString(text, 0, 0, font);
                    node.getAttributes().put(ATTRIBUTE_PATH, path);
                    extent = g.textExtent(text);
                    node.getAttributes().put(ATTRIBUTE_EXTENT, extent);
                }
        
                // Degrade if too far away
                if (bounds.width <= 4) {
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
        
                    // Draw real node
                } else {
                    
                    // Fill background
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    if (node != getSelectedNode()) {
                        g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw line
                    g.setLineWidth(getOuterStrokeWidth(node, bounds.width));
                    g.setForeground(getOuterColor(node));
                    g.setAntialias(SWT.ON);
                    if (node != getSelectedNode()) {
                        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw text
                    if (bounds.width >= 20) {
                        
                        // Enable anti-aliasing
                        g.setTextAntialias(SWT.ON);
                        
                        // Compute position and factor
                        float factor1 = (bounds.width * 0.7f) / (float)extent.x;
                        float factor2 = (bounds.height * 0.7f) / (float)extent.y;
                        float factor = Math.min(factor1, factor2);
                        int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); 
                        int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f);
                        
                        // Initialize transformation
                        transform.identity();
                        transform.translate(positionX, positionY);
                        transform.scale(factor, factor);
                        g.setTransform(transform);
                        
                        // Draw and reset
                        g.setBackground(COLOR_BLACK);
                        g.fillPath(path.getPath());
                        g.setTransform(null);
                        g.setTextAntialias(SWT.OFF);
                    }
                }
            }
        }
    }
    
    // Clean up
    transform.dispose();
}
 
Example 14
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Draw a circle
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawCircle(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    Color oldColor = gc.getBackground();
    gc.setBackground(color);
    gc.fillOval(centerX - symbolSize, centerY - symbolSize, symbolSize * 2, symbolSize * 2);
    gc.setBackground(oldColor);
}