Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Pattern


            IConfigRegistry configRegistry) {
        // Save GC settings
        Color originalBackground = gc.getBackground();
        Color originalForeground = gc.getForeground();

        Pattern pattern = new Pattern(Display.getCurrent(), bgImage);
        gc.setBackgroundPattern(pattern);

        gc.fillRectangle(rectangle);

        gc.setBackgroundPattern(null);
        pattern.dispose();

        if (isNotNull(separatorColor)) {
            gc.setForeground(separatorColor);
            gc.drawLine(rectangle.x - 1, rectangle.y, rectangle.x - 1,
                    rectangle.y + rectangle.height);
View Full Code Here


    }

    @Override
    public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle,
            IConfigRegistry configRegistry) {
        Pattern originalBackgroundPattern = gc.getBackgroundPattern();

        double factor = Math.min(1.0,
                ((Double) cell.getDataValue()).doubleValue());
        factor = Math.max(0.0, factor);

        Rectangle bar = new Rectangle(rectangle.x, rectangle.y,
                (int) (rectangle.width * factor), rectangle.height);
        Rectangle bounds = cell.getBounds();

        Color color1 = CellStyleUtil.getCellStyle(cell, configRegistry)
                .getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_START_COLOR);
        Color color2 = CellStyleUtil.getCellStyle(cell, configRegistry)
                .getAttributeValue(PERCENTAGE_BAR_COMPLETE_REGION_END_COLOR);
        if (color1 == null)
            color1 = DEFAULT_COMPLETE_REGION_START_COLOR;
        if (color2 == null)
            color2 = DEFAULT_COMPLETE_REGION_END_COLOR;

        Pattern pattern = new Pattern(Display.getCurrent(), bounds.x, bounds.y,
                bounds.x + bounds.width, bounds.y + bounds.height, color1,
                color2);
        gc.setBackgroundPattern(pattern);
        gc.fillRectangle(bar);

        gc.setBackgroundPattern(originalBackgroundPattern);
        pattern.dispose();

        Color incompleteRegionColor = CellStyleUtil.getCellStyle(cell,
                configRegistry).getAttributeValue(
                PERCENTAGE_BAR_INCOMPLETE_REGION_COLOR);
        if (incompleteRegionColor != null) {
View Full Code Here

    gc.setLineWidth(20);
    gc.setLineJoin(joinValues[joinCb.getSelectionIndex()]);

    // set the foreground color or pattern
    Pattern pattern = null;
    if (shapeColor.getBgColor1() != null)
      gc.setForeground(shapeColor.getBgColor1());
    else if (shapeColor.getBgImage() != null) {
      pattern = new Pattern(device, shapeColor.getBgImage());
      gc.setForegroundPattern(pattern);
    }

    // draw the shape
    Path path = new Path(device);
    path.moveTo(width / 2, 25);
    path.lineTo(2 * width / 3, height / 3);
    path.lineTo(width - 25, height / 2);
    path.lineTo(2 * width / 3, 2 * height / 3);
    path.lineTo(width / 2, height - 25);
    path.lineTo(width / 3, 2 * height / 3);
    path.lineTo(25, height / 2);
    path.lineTo(width / 3, height / 3);
    path.lineTo(width / 2, 25);
    path.close();
    gc.drawPath(path);
    path.dispose();

    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

    case 6: // default
      gc.setClipping(0, 0, width, height);
      break;
    }

    Pattern pattern = null;
    if (background.getBgColor1() != null)
      gc.setBackground(background.getBgColor1());
    else if (background.getBgImage() != null) {
      pattern = new Pattern(device, background.getBgImage());
      gc.setBackgroundPattern(pattern);
    }
    gc.fillRectangle(0, 0, width, height);
    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

   */
  static Image createImage(Device device, Color color1, Color color2, int width, int height) {
    Image image = new Image(device, width, height);
    GC gc = new GC(image);
    Rectangle rect = image.getBounds();
    Pattern pattern = new Pattern(device, rect.x, rect.y, rect.width - 1, rect.height - 1, color1, color2);
    gc.setBackgroundPattern(pattern);
    gc.fillRectangle(rect);
    gc.drawRectangle(rect.x, rect.y, rect.width - 1, rect.height - 1);
    gc.dispose();
    pattern.dispose();
    return image;
  }
View Full Code Here

    canvas.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event event) {
        GC gc = event.gc;
        Rectangle rect = canvas.getClientArea();
        Device device = gc.getDevice();
        Pattern pattern = null;
        if (background.getBgColor1() != null) {
          if (background.getBgColor2() != null) { // gradient
            pattern = new Pattern(device, 0, 0, rect.width, rect.height, background.getBgColor1(),
                background.getBgColor2());
            gc.setBackgroundPattern(pattern);
          } else
            gc.setBackground(background.getBgColor1());
        } else if (background.getBgImage() != null) { // image
          pattern = new Pattern(device, background.getBgImage());
          gc.setBackgroundPattern(pattern);
        }
        gc.fillRectangle(rect);
        GraphicsTab tab = getTab();
        if (tab != null)
          tab.paint(gc, rect.width, rect.height);
        if (pattern != null)
          pattern.dispose();
      }
    });
  }
View Full Code Here

    Point size = gc.stringExtent(text);
    int textWidth = size.x;
    int textHeight = size.y;

    Pattern pattern = null;
    if (fontForeground.getBgColor1() != null)
      gc.setForeground(fontForeground.getBgColor1());
    else if (fontForeground.getBgImage() != null) {
      pattern = new Pattern(device, fontForeground.getBgImage());
      gc.setForegroundPattern(pattern);
    }

    gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);

    font.dispose();
    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

    text = GraphicsExample.getResourceString("Round"); //$NON-NLS-1$
    size = gc.stringExtent(text);
    gc.drawString(text, (width - size.x) / 2, 7 * height / 12, true);
    font.dispose();

    Pattern pattern = null;
    if (foreground.getBgColor1() != null)
      gc.setForeground(foreground.getBgColor1());
    else if (foreground.getBgImage() != null) {
      pattern = new Pattern(device, foreground.getBgImage());
      gc.setForegroundPattern(pattern);
    }

    // draw lines with caps
    gc.setLineWidth(20);
    gc.setLineCap(SWT.CAP_FLAT);
    gc.drawLine(3 * width / 16, 2 * height / 6, 13 * width / 16, 2 * height / 6);
    gc.setLineCap(SWT.CAP_SQUARE);
    gc.drawLine(3 * width / 16, 3 * height / 6, 13 * width / 16, 3 * height / 6);
    gc.setLineCap(SWT.CAP_ROUND);
    gc.drawLine(3 * width / 16, 4 * height / 6, 13 * width / 16, 4 * height / 6);

    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

    // set line attributes
    gc.setLineWidth(20);
    gc.setLineCap(SWT.CAP_ROUND); // round line ends
    gc.setAntialias(SWT.ON); // smooth jagged edges

    Pattern pattern = null;
    if (foreground.getBgColor1() != null)
      gc.setForeground(foreground.getBgColor1());
    else if (foreground.getBgImage() != null) {
      pattern = new Pattern(device, foreground.getBgImage());
      gc.setForegroundPattern(pattern);
    }

    // draw petals for the spiral
    Transform transform;
    int n = petalSpinner.getSelection();
    for (int i = 0; i < n; i++) {
      transform = new Transform(device);
      transform.translate(width / 2, height / 2);
      transform.rotate(-(angle + 360 / n * i));
      gc.setTransform(transform);
      gc.drawArc(0, 0, width / 3, height / 6, 0, 180);
      transform.dispose();
    }

    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

  public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
      return;
    Device device = gc.getDevice();

    Pattern pattern = null;
    if (background.getBgColor1() != null)
      gc.setBackground(background.getBgColor1());
    else if (background.getBgImage() != null) {
      pattern = new Pattern(device, background.getBgImage());
      gc.setBackgroundPattern(pattern);
    }

    gc.setAntialias(SWT.ON);
    gc.setAlpha(alphaSpinner.getSelection());

    // rotate on center
    Transform transform = new Transform(device);
    transform.translate(width / 2, height / 2);
    transform.rotate(-angle);
    transform.translate(-width / 2, -height / 2);
    gc.setTransform(transform);
    transform.dispose();

    // choose the smallest between height and width
    int diameter = height < width ? height : width;

    Path path = new Path(device);
    path.addArc((width - diameter / 5) / 2, (height - diameter / 5) / 2, diameter / 5, diameter / 5, 0, 360);
    path.addArc(5 * (width - diameter / 8) / 12, 4 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0,
        360);
    path.addArc(7 * (width - diameter / 8) / 12, 8 * (height - diameter / 8) / 12, diameter / 8, diameter / 8, 0,
        360);
    path.addArc(6 * (width - diameter / 12) / 12, 3 * (height - diameter / 12) / 12, diameter / 12, diameter / 12,
        0, 360);
    path.addArc(6 * (width - diameter / 12) / 12, 9 * (height - diameter / 12) / 12, diameter / 12, diameter / 12,
        0, 360);
    path.addArc(11.5f * (width - diameter / 18) / 20, 5 * (height - diameter / 18) / 18, diameter / 18,
        diameter / 18, 0, 360);
    path.addArc(8.5f * (width - diameter / 18) / 20, 13 * (height - diameter / 18) / 18, diameter / 18,
        diameter / 18, 0, 360);
    path.addArc(62f * (width - diameter / 25) / 100, 32 * (height - diameter / 25) / 100, diameter / 25,
        diameter / 25, 0, 360);
    path.addArc(39f * (width - diameter / 25) / 100, 67 * (height - diameter / 25) / 100, diameter / 25,
        diameter / 25, 0, 360);

    gc.fillPath(path);
    path.dispose();

    if (pattern != null)
      pattern.dispose();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.swt.graphics.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.