Java Code Examples for org.eclipse.draw2d.Graphics#setAntialias()

The following examples show how to use org.eclipse.draw2d.Graphics#setAntialias() . 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: Circle.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fills the circle using a graphics object. This should not be called
 * manually, but by the system.
 */
@Override
protected void fillShape(Graphics g) {
	// Makes sure the circles drawn are pretty, not jagged.
	g.setAntialias(SWT.ON);

	// Compute the center point.
	int centerX = bounds.x + bounds.width / 2;
	int centerY = bounds.y + bounds.height / 2;

	// Compute the radius in pixels.
	int r = (int) (Math.min(bounds.width, bounds.height) * radius
			/ (2.0 * maxRadius));

	// Use the computed bounds to draw the circle.
	g.fillOval(centerX - r, centerY - r, r * 2, r * 2);
}
 
Example 2
Source File: ERDecoration.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void paintFigure(final Graphics graphics) {
    final ERDiagramConnection connection = (ERDiagramConnection) getParent();

    graphics.setAntialias(SWT.ON);

    final Color color = connection.getColor();

    if (color != null) {
        graphics.setForegroundColor(color);
        graphics.setBackgroundColor(color);
    }

    super.paintFigure(graphics);
}
 
Example 3
Source File: GaugeFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	Pattern pattern = null;
	graphics.setBackgroundColor(GRAY_COLOR);
	if(support3D == null)
		support3D = GraphicsUtil.testPatternSupported(graphics);
	if(effect3D && support3D){		
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x, bounds.y,
					bounds.x + bounds.width, bounds.y + bounds.height, WHITE_COLOR, BORDER_COLOR);
			graphics.setBackgroundPattern(pattern);							
	}			
	super.fillShape(graphics);
	if(effect3D && support3D)
		pattern.dispose();			
}
 
Example 4
Source File: CrossAnnotation.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	if (trace != null && currentSnappedSample == null && !pointerDragged)
		updateToDefaultPosition();

	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);

	graphics.setForegroundColor(getForegroundColor());
	xValue = currentSnappedSample.getXValue();
	yValue = currentSnappedSample.getYValue();
	int x = xAxis.getValuePosition(xValue, false);
	int y = yAxis.getValuePosition(yValue, false);
	Point p = new Point();
	p.setLocation(y, x);

	graphics.drawLine(x - CROSS_SIZE, y - CROSS_SIZE, x + CROSS_SIZE, y + CROSS_SIZE);
	graphics.drawLine(x - CROSS_SIZE, y + CROSS_SIZE, x + CROSS_SIZE, y - CROSS_SIZE);
	graphics.drawLine(x, y + CROSS_SIZE, x, y - CROSS_SIZE);
	graphics.drawLine(x - CROSS_SIZE, y, x + CROSS_SIZE, y);
}
 
Example 5
Source File: KnobFigure.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	Pattern pattern = null;
	graphics.setBackgroundColor(thumbColor);
	boolean support3D = GraphicsUtil.testPatternSupported(graphics);
	if(support3D && effect3D){
		try {
			graphics.setBackgroundColor(thumbColor);
			super.fillShape(graphics);
			pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), bounds.x, bounds.y,
					bounds.x + bounds.width, bounds.y + bounds.height, 
					WHITE_COLOR, 0, WHITE_COLOR, 255);
			graphics.setBackgroundPattern(pattern);
		} catch (Exception e) {
			support3D = false;
			pattern.dispose();
		}				
	}			
	super.fillShape(graphics);
	if(effect3D && support3D)
		pattern.dispose();
	graphics.setForegroundColor(thumbColor);
}
 
Example 6
Source File: RoundScaleTickMarks.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void paintClientArea(Graphics graphics) {
graphics.translate(bounds.x, bounds.y);
graphics.setAntialias(SWT.ON);
ArrayList<Double> tickLabelPositions = scale
            .getScaleTickLabels().getTickLabelPositions(); 
   drawTickMarks(graphics, tickLabelPositions);
 
   }
 
Example 7
Source File: Annotation.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {
	super.paintClientArea(graphics);
	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);
	// draw X-cross point
	Rectangle clientArea = getClientArea().getCopy().shrink(POINT_SIZE / 2, POINT_SIZE / 2);
	graphics.drawLine(clientArea.x, clientArea.y, clientArea.x + clientArea.width,
			clientArea.y + clientArea.height);
	graphics.drawLine(clientArea.x + clientArea.width, clientArea.y, clientArea.x,
			clientArea.y + clientArea.height);

}
 
Example 8
Source File: CircleAnnotation.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	if (trace != null && currentSnappedSample == null && !pointerDragged)
		updateToDefaultPosition();

	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);

	graphics.setForegroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
	xValue = currentSnappedSample.getXValue();
	yValue = currentSnappedSample.getYValue();
	int x = xAxis.getValuePosition(xValue, false);
	int y = yAxis.getValuePosition(yValue, false);
	graphics.drawOval(x - (CIRCLE_DIAMETER / 2), y - (CIRCLE_DIAMETER / 2), CIRCLE_DIAMETER, CIRCLE_DIAMETER);
}
 
Example 9
Source File: ProgressBarFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	//if(horizontal) 
		rightPoint = getPoints().getPoint(2);
	//else
	//	rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	setOutline(effect3D && support3D);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			fillColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(fillColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example 10
Source File: ThermometerFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	boolean support3D = false;
	if(effect3D)
		 support3D = GraphicsUtil.testPatternSupported(graphics);
	
	if(effect3D && support3D){
		graphics.setBackgroundColor(fillColor);
		super.fillShape(graphics);
		//int l = (int) ((bounds.width - lineWidth)*0.293/2);
		Pattern backPattern = null;
		
		 backPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), 
			bounds.x + lineWidth, bounds.y + lineWidth, 
			bounds.x+bounds.width-lineWidth, bounds.y+bounds.height-lineWidth,
			WHITE_COLOR,255, fillColor, 0);			
		graphics.setBackgroundPattern(backPattern);
		super.fillShape(graphics);
		backPattern.dispose();
		
	}else{
		graphics.setBackgroundColor(fillColor);				
		super.fillShape(graphics);
	}				
	
	String valueString = getValueText();
	Dimension valueSize = 
		FigureUtilities.getTextExtents(valueString, getFont());
	if(valueSize.width < bounds.width) {				
		graphics.setForegroundColor(contrastFillColor);
		graphics.drawText(valueString, new Point(
				bounds.x + bounds.width/2 - valueSize.width/2,
				bounds.y + bounds.height/2 - valueSize.height/2));				
	}			
}
 
Example 11
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void fillShape(Graphics g) {	
	g.setAntialias(SWT.ON);
	g.setClip(new Rectangle(getBounds().x, getBounds().y, getBounds().width, getBounds().height));
	g.setBackgroundColor(WHITE_COLOR);
	super.fillShape(g);
	Point leftPoint = getPoints().getPoint(0);
	Point rightPoint;
	if(horizontal) 
		rightPoint = getPoints().getPoint(4);
	else
		rightPoint = getPoints().getPoint(1);//.translate(0, -BREADTH/2);
	Pattern thumbPattern = null;
	boolean support3D = GraphicsUtil.testPatternSupported(g);
	if(effect3D && support3D) {
		thumbPattern = GraphicsUtil.createScaledPattern(g, Display.getCurrent(),
			leftPoint.x, leftPoint.y, rightPoint.x, rightPoint.y, WHITE_COLOR, 0, 
			thumbColor, 255);
		g.setBackgroundPattern(thumbPattern);		
	}else
		g.setBackgroundColor(thumbColor);
		
	g.fillPolygon(getPoints());
	
	if(effect3D && support3D)
		thumbPattern.dispose();
			
}
 
Example 12
Source File: Bulb.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void paintClientArea(Graphics graphics) {		
	graphics.setAntialias(SWT.ON);
	
	if(effect3D && GraphicsUtil.testPatternSupported(graphics)) {			
		// Fills the circle with solid bulb color
        graphics.setBackgroundColor(bulbColor);
        graphics.fillOval(bounds);
        
		//diagonal linear gradient
			Pattern p = new Pattern(Display.getCurrent(), bounds.x,	bounds.y,
					bounds.x + getWidth(), bounds.y + getHeight(),
					COLOR_WHITE, 255, bulbColor, 0);
        try {				
			graphics.setBackgroundPattern(p);
			graphics.fillOval(bounds);		
			p.dispose();
		} catch (Exception e) {
			p.dispose();				
		}
		
	} else {			
		graphics.setBackgroundColor(bulbColor);
		graphics.fillOval(bounds);
	}		
	
	super.paintClientArea(graphics);
}
 
Example 13
Source File: MeterFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void fillShape(Graphics g) {
	g.setAntialias(SWT.ON);
	super.fillShape(g);
}
 
Example 14
Source File: Annotation.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void paintFigure(Graphics graphics) {
	super.paintFigure(graphics);
	if (trace != null && currentSnappedSample == null && !pointerDragged)
		updateToDefaultPosition();

	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);
	Color tempColor;
	if (annotationColor == null) {
		tempColor = yAxis.getForegroundColor();
	} else
		tempColor = annotationColor;
	infoLabel.setForegroundColor(tempColor);
	pointer.setForegroundColor(tempColor);
	if (vLine != null)
		vLine.setForegroundColor(tempColor);
	if (hLine != null)
		hLine.setForegroundColor(tempColor);
	graphics.setForegroundColor(tempColor);

	if (infoLabelArmed) // draw infoLabel Armed rect
		graphics.drawRectangle(infoLabel.getBounds());
	if (showName || showPosition || showSampleInfo) {
		// draw indicate line
		graphics.drawLine(currentPosition.x + (int) dx, currentPosition.y + (int) dy, currentPosition.x,
				currentPosition.y);
		// draw Arrow
		int x1 = (int) (ARROW_LINE_LENGTH * Math.cos(Math.atan(-dy / dx) - Math.PI / 9));
		int y1 = (int) (ARROW_LINE_LENGTH * Math.sin(Math.atan(-dy / dx) - Math.PI / 9));
		if (dx < 0) {
			x1 = -x1;
			y1 = -y1;
		}
		graphics.drawLine(currentPosition.x + x1, currentPosition.y - y1, currentPosition.x, currentPosition.y);
		x1 = (int) (ARROW_LINE_LENGTH * Math.cos(Math.atan(-dy / dx) + Math.PI / 9));
		y1 = (int) (ARROW_LINE_LENGTH * Math.sin(Math.atan(-dy / dx) + Math.PI / 9));
		if (dx < 0) {
			x1 = -x1;
			y1 = -y1;
		}
		graphics.drawLine(currentPosition.x + x1, currentPosition.y - y1, currentPosition.x, currentPosition.y);
	}
	// draw Cursor Line
	switch (cursorLineStyle) {
	case NONE:
		// left
		graphics.drawLine(currentPosition.x - POINT_SIZE / 2, currentPosition.y,
				currentPosition.x - POINT_SIZE / 2 - CURSOR_LINE_LENGTH, currentPosition.y);
		// right
		graphics.drawLine(currentPosition.x + POINT_SIZE / 2, currentPosition.y,
				currentPosition.x + POINT_SIZE / 2 + CURSOR_LINE_LENGTH, currentPosition.y);
		// up
		graphics.drawLine(currentPosition.x, currentPosition.y - POINT_SIZE / 2, currentPosition.x,
				currentPosition.y - POINT_SIZE / 2 - CURSOR_LINE_LENGTH);
		// down
		graphics.drawLine(currentPosition.x, currentPosition.y + POINT_SIZE / 2, currentPosition.x,
				currentPosition.y + POINT_SIZE / 2 + CURSOR_LINE_LENGTH);
		break;
	case FOUR_DIRECTIONS:
	case LEFT_RIGHT:
		// left
		graphics.drawLine(currentPosition.x - POINT_SIZE / 2, currentPosition.y,
				xAxis.getValuePosition(xAxis.getRange().getLower(), false), currentPosition.y);
		// right
		graphics.drawLine(currentPosition.x + POINT_SIZE / 2, currentPosition.y,
				xAxis.getValuePosition(xAxis.getRange().getUpper(), false), currentPosition.y);
		if (cursorLineStyle != CursorLineStyle.FOUR_DIRECTIONS)
			break;
	case UP_DOWN:
		// up
		graphics.drawLine(currentPosition.x, currentPosition.y - POINT_SIZE / 2, currentPosition.x,
				yAxis.getValuePosition(yAxis.getRange().getUpper(), false));
		// down
		graphics.drawLine(currentPosition.x, currentPosition.y + POINT_SIZE / 2, currentPosition.x,
				yAxis.getValuePosition(yAxis.getRange().getLower(), false));
		break;
	default:
		break;
	}

}
 
Example 15
Source File: ScaledSliderFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
		protected void fillShape(Graphics graphics) {		
			
			graphics.setAntialias(SWT.ON);			
			int valuePosition = ((LinearScale) scale).getValuePosition(getCoercedValue(), false);
			boolean support3D = GraphicsUtil.testPatternSupported(graphics);
			if(effect3D && support3D) {		
				//fill background
				graphics.setBackgroundColor(fillBackgroundColor);
				super.fillShape(graphics);
				Pattern backGroundPattern; 
				if(horizontal)
					backGroundPattern= GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x, bounds.y + bounds.height,
						WHITE_COLOR, 255,
						fillBackgroundColor, 0);
				else
					backGroundPattern= GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x + bounds.width, bounds.y,
						WHITE_COLOR, 255,
						fillBackgroundColor, 0);
				graphics.setBackgroundPattern(backGroundPattern);
				super.fillShape(graphics);
				graphics.setForegroundColor(fillBackgroundColor);
				outlineShape(graphics);
				backGroundPattern.dispose();
				
				//fill value
				if(horizontal)
					backGroundPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x, bounds.y + bounds.height,
						WHITE_COLOR, 255,
						fillColor, 0);
				else
					backGroundPattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(),
						bounds.x, bounds.y,
						bounds.x + bounds.width, bounds.y,
						WHITE_COLOR, 255,
						fillColor, 0);
				
				graphics.setBackgroundColor(fillColor);
				graphics.setForegroundColor(fillColor);
				if(horizontal){
					int fillWidth = valuePosition - bounds.x;				
					graphics.fillRectangle(new Rectangle(bounds.x,
						bounds.y, fillWidth, bounds.height));
					graphics.setBackgroundPattern(backGroundPattern);
					graphics.fillRectangle(new Rectangle(bounds.x,
						bounds.y, fillWidth, bounds.height));
					
					graphics.drawRectangle(new Rectangle(bounds.x + lineWidth / 2,
						bounds.y + lineWidth / 2, 
						fillWidth - Math.max(1, lineWidth),
						bounds.height - Math.max(1, lineWidth)));
					
					
				}else {
					int fillHeight = bounds.height - (valuePosition - bounds.y);				
					graphics.fillRectangle(new Rectangle(bounds.x,
						valuePosition, bounds.width, fillHeight));
					graphics.setBackgroundPattern(backGroundPattern);
					graphics.fillRectangle(new Rectangle(bounds.x,
						valuePosition, bounds.width, fillHeight));
					
					graphics.drawRectangle(new Rectangle(bounds.x + lineWidth / 2,
						valuePosition+ lineWidth / 2, 
						bounds.width- Math.max(1, lineWidth),
						fillHeight - Math.max(1, lineWidth)));
				}		
				
				backGroundPattern.dispose();
				
				
				
				
			}else {
				graphics.setBackgroundColor(fillBackgroundColor);
				super.fillShape(graphics);				
				graphics.setBackgroundColor(fillColor);
				if(horizontal)
					graphics.fillRectangle(new Rectangle(bounds.x,
							bounds.y, 						
							valuePosition - bounds.x, 
							bounds.height));
				else
					graphics.fillRectangle(new Rectangle(bounds.x,
							valuePosition,
							bounds.width,
							bounds.height - (valuePosition - bounds.y)));
//				graphics.setForegroundColor(outlineColor);
			}			
		}
 
Example 16
Source File: Legend.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void drawTraceLegend(Trace trace, Graphics graphics, int hPos, int vPos) {
	graphics.pushState();
	if (Preferences.useAdvancedGraphics())
		graphics.setAntialias(SWT.ON);
	graphics.setForegroundColor(trace.getTraceColor());

	// limit size of symbol to ICON_WIDTH - INNER_GAP
	int maxSize = ((trace.getPointSize() > Math.floor((ICON_WIDTH - OUT_GAP) / 2))
			? (int) Math.floor((ICON_WIDTH - OUT_GAP))
			: trace.getPointSize());

	// draw symbol
	switch (trace.getTraceType()) {
	case BAR:
		trace.drawLine(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2 ),
				new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	case LINE_AREA:
		graphics.drawPolyline(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH - 1, vPos + ICON_WIDTH / 2, });
	case AREA:
		graphics.setBackgroundColor(trace.getTraceColor());
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(trace.getAreaAlpha());
		graphics.fillPolygon(new int[] { hPos, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH / 2, vPos + maxSize / 2,
				hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2, hPos + ICON_WIDTH, vPos + ICON_WIDTH, hPos,
				vPos + ICON_WIDTH });
		if (Preferences.useAdvancedGraphics())
			graphics.setAlpha(255);
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + maxSize / 2));
		break;
	default:
		trace.drawLine(graphics, new Point(hPos, vPos + ICON_WIDTH / 2),
				new Point(hPos + ICON_WIDTH, vPos + ICON_WIDTH / 2));
		trace.drawPoint(graphics, new Point(hPos + ICON_WIDTH / 2, vPos + ICON_WIDTH / 2));
		break;
	}

	// draw text
	Font previousFont = super.getFont();
	if (font != null) {
		graphics.setFont(font);
	}
	
	graphics.drawText(trace.getName(), hPos + ICON_WIDTH + INNER_GAP,
			vPos + ICON_WIDTH / 2 - FigureUtilities.getTextExtents(trace.getName(), getFont()).height / 2);
	
	graphics.setFont(previousFont);
	graphics.popState();
}
 
Example 17
Source File: GaugeFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void fillShape(Graphics g) {
	g.setAntialias(SWT.ON);
	super.fillShape(g);
}
 
Example 18
Source File: ERDecoration.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
public void paintFigure(Graphics graphics) {
    graphics.setAntialias(SWT.ON);
    super.paintFigure(graphics);
}
 
Example 19
Source File: ComponentMeterFigure.java    From arx with Apache License 2.0 4 votes vote down vote up
@Override
protected void fillShape(Graphics g) {
    g.setAntialias(SWT.ON);
    super.fillShape(g);
}
 
Example 20
Source File: ERDecoration.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void paintFigure(Graphics graphics) {
	graphics.setAntialias(SWT.ON);
	super.paintFigure(graphics);
}