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

The following examples show how to use org.eclipse.swt.graphics.GC#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: Pics.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get the system image resized in 16x16 (only used in connectors label provider)
 *
 * @param id
 * @return
 */
public static Image getSystemImage(final int id) {
    final ImageRegistry reg = plugin.getImageRegistry();

    final String imageName = id + "";
    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }
    result = Display.getCurrent().getSystemImage(id);
    final Image scaled = new Image(Display.getDefault(), 16, 16);
    final GC gc = new GC(scaled);
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.HIGH);
    gc.drawImage(result, 0, 0, result.getBounds().width, result.getBounds().height, 0, 0, 16, 16);
    gc.dispose();
    result = scaled;
    reg.remove(imageName);
    reg.put(imageName, result);
    return result;
}
 
Example 2
Source File: SearchControl.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
	public void paintControl(PaintEvent e) {
		GC gc = e.gc;
		gc.setAntialias(SWT.ON);
		Rectangle bounds = getBounds();
		Path path = new Path(getDisplay());
		path.addArc(bounds.x, bounds.y, arcSize, arcSize, 90, 180);
//		path.addRectangle(bounds.x + arcSize / 2, bounds.y, bounds.width - arcSize,
//				arcSize);
		path.addArc(bounds.x + bounds.width - arcSize, bounds.y, arcSize, arcSize,
				270, 180);
//		gc.setClipping(path);
		Color b = gc.getBackground();
		gc.setBackground(backgroundColor);
		gc.fillPath(path);
		path.dispose();
		gc.setAntialias(SWT.OFF);
		gc.setBackground(b);
	}
 
Example 3
Source File: ToolbarItem.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Calculate size of item.
 */
public void calculateSize()
{
	Image calcSizeImage = new Image(Display.getDefault(), 1, 1);

	GC gc = new GC(calcSizeImage);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.OFF);
	gc.setFont(parent.getFont());

	width = 10;

	if (image != null)
	{
		width += image.getImageData().width;
	}

	if (text.length() > 0)
	{
		width += getTextWidth(gc, text) + 9;
	}

	gc.dispose();
	calcSizeImage.dispose();
}
 
Example 4
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 5
Source File: AdvancedGC.java    From swt-bling with MIT License 6 votes vote down vote up
public static void setAdvanced(GC gc, boolean targetSetting) {
    if (targetSetting) {
        try {
            gc.setAdvanced(true);
            gc.setAntialias(SWT.ON);
            gc.setTextAntialias(SWT.ON);
            gc.setInterpolation(SWT.HIGH);
        } catch (SWTException e) {
            if (!loggedAdvanced) {
                log.log(Level.WARNING, "Unable to set advanced drawing", e);
                loggedAdvanced = true;
            }
        }
    } else {
        gc.setAdvanced(false);
    }

}
 
Example 6
Source File: AttributePainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 7
Source File: TextPainter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
	Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
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: InteractiveDecorator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO: move to UtilityClass
 * 
 * This method disposes the input image and returns a new Image.
 * 
 * @param image
 * @param width
 * @param height
 * @return
 */
protected Image resize(Image image, int width, int height) {
	Image scaled = new Image(image.getDevice(), width, height);
	GC gc = new GC(scaled);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(image, 0, 0, image.getBounds().width,
			image.getBounds().height, 0, 0, width, height);
	gc.dispose();
	image.dispose();
	return scaled;
}
 
Example 10
Source File: TmxEditorTextPainter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void setupGCFromConfig(GC gc, IStyle cellStyle) {
	Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
	Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);

	gc.setAntialias(GUIHelper.DEFAULT_ANTIALIAS);
	gc.setTextAntialias(GUIHelper.DEFAULT_TEXT_ANTIALIAS);
	gc.setFont(font);
	gc.setForeground(fg != null ? fg : GUIHelper.COLOR_LIST_FOREGROUND);
	gc.setBackground(bg != null ? bg : GUIHelper.COLOR_LIST_BACKGROUND);
}
 
Example 11
Source File: SimpleToolBarEx.java    From SWET with MIT License 5 votes vote down vote up
private Image resize(Image image, int width, int height) {
	Image scaled = new Image(display, width, height);
	GC gc = new GC(scaled);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height,
			0, 0, width, height);
	gc.dispose();
	image.dispose();
	return scaled;
}
 
Example 12
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 13
Source File: NebulaSlider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void paintControl(GC gc) {
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);

	if (xPosition < 0) {
		// Compute xPosition
		xPosition = computeXPosition();
	}

	drawBar(gc);
	drawSelectionPart(gc);
	drawSelector(gc);
}
 
Example 14
Source File: SComposite.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void paintControl(GC gc) {
	if((borderStyle & BORDER) != 0) {
		if(advancedGraphics) {
			gc.setAntialias(SWT.ON);
		}

		gc.setLineWidth(borderWidth);

		Rectangle r = getClientArea();

		if((borderStyle & SQUARE) != 0) {
			if((borderStyle & FLAT) == 0) {
				gc.setForeground(WHITE);
				gc.drawLine(r.x+1,r.y+1, r.x+1,r.y+r.height-3);
				gc.drawLine(r.x+1,r.y+1, r.x+r.width-3,r.y+1);
			}
			gc.setForeground(borderColor);
			gc.drawRectangle(r.x,r.y, r.width-1,r.height-1);
		} else {
			if((borderStyle & FLAT) == 0) {
				gc.setForeground(WHITE);
				gc.drawLine(r.x+1,r.y+1, r.x+1,r.y+r.height-3);
				gc.drawLine(r.x+1,r.y+1, r.x+r.width-3,r.y+1);
			}
			gc.setForeground(borderColor);
			gc.drawRoundRectangle(r.x+(borderWidth/2),r.y+(borderWidth/2), r.width-borderWidth,r.height-borderWidth, borderWidth*5, borderWidth*5);
		}
	}
}
 
Example 15
Source File: LauncherLabel.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Draw the content of the LLabel
 *
 * @param event paintevent
 */
private void onPaint(final PaintEvent event) {
	final Rectangle rect = getClientArea();
	if (rect.width == 0 || rect.height == 0) {
		return;
	}

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

	final GC gc = new GC(bufferImage);
	gc.setForeground(getForeground());
	gc.setBackground(getBackground());

	gc.fillRectangle(rect);

	final Point extent = getTotalSize(image.getBounds().width, image.getBounds().height);
	final int xImage = (rect.width - image.getBounds().width) / 2;
	final int yImage = (rect.height - extent.y) / 2;
	gc.drawImage(image, xImage, yImage);

	gc.setFont(font);
	final int xText = (rect.width - textSize.x) / 2;
	final int yText = yImage + image.getBounds().height + GAP - textSize.y / 2;
	gc.drawString(text, xText, yText);

	if (animationStep != 0) {
		final float zoom = 1f + animationStep * (Math.max(extent.x, extent.y) - Math.max(image.getBounds().width, image.getBounds().height)) / MAX_NUMBER_OF_STEPS / 100f;

		final int newSizeX = (int) (image.getBounds().width * zoom);
		final int newSizeY = (int) (image.getBounds().height * zoom);

		gc.setAntialias(SWT.ON);
		gc.setInterpolation(SWT.HIGH);

		gc.setAlpha(255 - 255 / MAX_NUMBER_OF_STEPS * animationStep);

		final Point extentZoomedImage = getTotalSize(newSizeX, newSizeY);
		final int xZoomedImage = (rect.width - newSizeX) / 2;
		final int yZoomedImage = (rect.height - extentZoomedImage.y) / 2;
		gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, xZoomedImage, yZoomedImage, (int) (image.getBounds().width * zoom), (int) (image.getBounds().height * zoom));

	}

	gc.dispose();

	event.gc.drawImage(bufferImage, 0, 0);

	bufferImage.dispose();

}
 
Example 16
Source File: LoginDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Create a default image. It is a port of the image used by the Login Box
 * in the project SwingX
 *
 * @param w width
 * @param h height
 * @return a default image (blue wave)
 */
private Image createDefaultImage(final int w, final int h) {
	final Display display = Display.getCurrent();
	final Color backgroundColor = new Color(display, 49, 121, 242);
	final Color gradientColor1 = new Color(display, 155, 185, 245);
	final Color gradientColor2 = new Color(display, 53, 123, 242);

	final Image img = new Image(display, w, h);
	final GC gc = new GC(img);
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setBackground(backgroundColor);
	gc.fillRectangle(0, 0, w, h);

	final Path curveShape = new Path(display);
	curveShape.moveTo(0, h * .6f);
	curveShape.cubicTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f);
	curveShape.lineTo(w, h);
	curveShape.lineTo(0, h);
	curveShape.lineTo(0, h * .8f);
	curveShape.close();

	final Pattern pattern = new Pattern(display, 0, 0, 1, h * 1.2f, gradientColor1, gradientColor2);
	gc.setBackgroundPattern(pattern);
	gc.fillPath(curveShape);

	final Font font = new Font(display, "Arial Bold", 30, SWT.NONE);
	gc.setFont(font);
	gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
	final Point textSize = gc.stringExtent(ResourceManager.getLabel(ResourceManager.LOGIN));
	gc.drawString(ResourceManager.getLabel(ResourceManager.LOGIN), (int) (w * .05f), (h - textSize.y) / 2, true);

	font.dispose();
	curveShape.dispose();
	pattern.dispose();
	backgroundColor.dispose();
	gradientColor1.dispose();
	gradientColor2.dispose();
	gc.dispose();
	return img;
}
 
Example 17
Source File: PrintPreview.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void configureAntialiasing(GC printerGC) {
	printerGC.setAdvanced(true);
	printerGC.setAntialias(SWT.ON);
	printerGC.setTextAntialias(SWT.ON);
	printerGC.setInterpolation(SWT.HIGH);
}
 
Example 18
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 19
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 20
Source File: Plotter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void paintControl(Event e) {

		for (int c = 0; c < this.chan.length; c++) {

			// Go calculate the line
			Object[] result = calculate(c);
			int[] l1 = (int[]) result[0];
			int[] l2 = (int[]) result[1];

			PositionPolyLine(l1);
			PositionPolyLine(l2);

			// Draw it
			GC gc = e.gc;
			gc.setForeground(getForeground(c));
			gc.setAdvanced(true);
			gc.setAntialias(this.chan[c].antiAlias ? SWT.ON : SWT.OFF);
			gc.setLineWidth(getLineWidth(c));

			// Fade tail
			if (isFade(c)) {
				gc.setAlpha(0);
				double fade = 0;
				double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
				for (int i = 0; i < l1.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
					i += 2;
				}

				for (int i = 0; i < l2.length - 4;) {
					fade += (fadeOutStep / 2);
					setAlpha(gc, fade);
					gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
					i += 2;
				}

			} else {
				gc.drawPolyline(l1);
				gc.drawPolyline(l2);
			}

			// Connects the head with the tail
			if (isConnect(c) && !isFade(c) && this.chan[c].originalTailSize == TAILSIZE_MAX && l1.length > 0
					&& l2.length > 0) {
				gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
			}
		}
	}