Exemplo n.º 1
0
 public void translate(double tx, double ty) {
   if (_transform == null) {
     _transform = new Transform(_gc.getDevice());
   }
   _transform.translate((int) tx, (int) ty);
   _gc.setTransform(_transform);
   if (_clippingArea != null) {
     AffineTransform t = new AffineTransform();
     t.translate(-tx, -ty);
     _clippingArea.transform(t);
   }
 }
Exemplo n.º 2
0
 public void setClip(Shape s) {
   Path path = convertToPath(s);
   if (path == null) {
     _gc.setClipping((Rectangle) null);
   } else {
     _gc.setClipping(path);
   }
   if (_clippingPath != null) {
     _clippingPath.dispose();
   }
   _clippingPath = path;
   _clippingArea = (s == null ? null : new Area(s));
 }
Exemplo n.º 3
0
  public void setStroke(Stroke s) {
    _stroke = s;

    /*
     * Code borrowed from SwingWT
     */
    if (s == null) {
      _gc.setLineWidth(1);
      _gc.setLineCap(SWT.CAP_SQUARE);
      _gc.setLineJoin(SWT.JOIN_MITER);
      _gc.setLineDash(null);
      return;
    }

    if (!(s instanceof BasicStroke)) {
      return;
    }

    BasicStroke bs = (BasicStroke) s;

    // Setup the line width
    _gc.setLineWidth((int) bs.getLineWidth());

    // Setup the line cap
    int gcCap = SWT.CAP_SQUARE;
    switch (bs.getEndCap()) {
      case BasicStroke.CAP_BUTT:
        gcCap = SWT.CAP_FLAT;
        break;
      case BasicStroke.CAP_ROUND:
        gcCap = SWT.CAP_ROUND;
        break;
      case BasicStroke.CAP_SQUARE:
        gcCap = SWT.CAP_SQUARE;
        break;
    }
    _gc.setLineCap(gcCap);

    // Setup the line Join
    int gcJoin = SWT.JOIN_MITER;
    switch (bs.getLineJoin()) {
      case BasicStroke.JOIN_BEVEL:
        gcJoin = SWT.JOIN_BEVEL;
        break;
      case BasicStroke.JOIN_MITER:
        gcJoin = SWT.JOIN_MITER;
        break;
      case BasicStroke.JOIN_ROUND:
        gcJoin = SWT.JOIN_ROUND;
    }
    _gc.setLineJoin(gcJoin);

    float d[] = bs.getDashArray();
    int[] dashes = new int[d.length];
    for (int i = 0; i < d.length; i++) {
      dashes[i] = (int) d[i];
    }
    _gc.setLineDash(dashes);
  }
Exemplo n.º 4
0
  public void setColor(java.awt.Color color) {
    if (color.equals(_awt_color)) {
      return;
    }

    Color col = new Color(_gc.getDevice(), color.getRed(), color.getGreen(), color.getBlue());
    _gc.setForeground(col);
    _gc.setBackground(col);
    _gc.setAlpha(color.getAlpha());
    if (_color != null) {
      _color.dispose();
    }
    _color = col;
    _awt_color = color;
  }
Exemplo n.º 5
0
 /** Clean used resources. */
 public void clean() {
   if (_clippingPath != null) {
     _gc.setClipping((Rectangle) null);
     _clippingPath.dispose();
     _clippingPath = null;
     _clippingArea = null;
   }
   if (_color != null) {
     _color.dispose();
     _color = null;
   }
   if (_transform != null) {
     _gc.setTransform(null);
     _transform.dispose();
   }
 }
Exemplo n.º 6
0
 /**
  * Convert an AWT Shape to an SWT Path.
  *
  * @param shape
  * @return the SWT Path or <code>null</code> if <code>shape == null</code>
  */
 private Path convertToPath(Shape shape) {
   if (shape == null) {
     return null;
   }
   Path path = new Path(_gc.getDevice());
   PathIterator iter = shape.getPathIterator(null);
   float[] coords = new float[6];
   while (!iter.isDone()) {
     int op = iter.currentSegment(coords);
     switch (op) {
       case PathIterator.SEG_MOVETO:
         path.moveTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_LINETO:
         path.lineTo(coords[0], coords[1]);
         break;
       case PathIterator.SEG_QUADTO:
         path.quadTo(coords[0], coords[1], coords[2], coords[3]);
         break;
       case PathIterator.SEG_CUBICTO:
         path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
         break;
       case PathIterator.SEG_CLOSE:
         path.close();
         break;
     }
     iter.next();
   }
   return path;
 }
Exemplo n.º 7
0
 public void setRenderingHint(Key key, Object value) {
   if (RenderingHints.KEY_ANTIALIASING.equals(key)) {
     int antialias = SWT.DEFAULT;
     if (RenderingHints.VALUE_ANTIALIAS_OFF.equals(value)) {
       antialias = SWT.OFF;
     } else if (RenderingHints.VALUE_ANTIALIAS_ON.equals(value)) {
       antialias = SWT.ON;
     }
     _gc.setAntialias(antialias);
   }
 }
Exemplo n.º 8
0
 public Object getRenderingHint(Key key) {
   if (RenderingHints.KEY_ANTIALIASING.equals(key)) {
     switch (_gc.getAntialias()) {
       case SWT.DEFAULT:
         return RenderingHints.VALUE_ANTIALIAS_DEFAULT;
       case SWT.OFF:
         return RenderingHints.VALUE_ANTIALIAS_OFF;
       case SWT.ON:
         return RenderingHints.VALUE_ANTIALIAS_ON;
     }
   }
   return null;
 }
Exemplo n.º 9
0
 public void setFont(FSFont font) {
   _gc.setFont(((SWTFSFont) font).getSWTFont());
 }
Exemplo n.º 10
0
 public void fillOval(int x, int y, int width, int height) {
   _gc.fillOval(x, y, width, height);
 }
Exemplo n.º 11
0
 public void fillRect(int x, int y, int width, int height) {
   _gc.fillRectangle(x, y, width, height);
 }
Exemplo n.º 12
0
 public void fill(Shape s) {
   Path p = convertToPath(s);
   _gc.fillPath(p);
   p.dispose();
 }
Exemplo n.º 13
0
 public void drawRect(int x, int y, int width, int height) {
   _gc.drawRectangle(x, y, width, height);
 }
Exemplo n.º 14
0
 public void drawOval(int x, int y, int width, int height) {
   _gc.drawOval(x, y, width, height);
 }
Exemplo n.º 15
0
 public void drawImage(FSImage image, int x, int y) {
   Image img = ((SWTFSImage) image).getImage();
   if (img == null) {
     int width = image.getWidth();
     int height = image.getHeight();
     Color oldBG = _gc.getBackground();
     Color oldFG = _gc.getForeground();
     _gc.setBackground(_gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
     _gc.setForeground(_gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
     _gc.fillRectangle(x, y, width, height);
     _gc.drawRectangle(x, y, width, height);
     _gc.drawLine(x, y, x + width - 1, y + height - 1);
     _gc.drawLine(x, y + height - 1, x + width - 1, y);
     _gc.setBackground(oldBG);
     _gc.setForeground(oldFG);
   } else {
     Rectangle bounds = img.getBounds();
     _gc.drawImage(
         img, 0, 0, bounds.width, bounds.height, x, y, image.getWidth(), image.getHeight());
   }
 }
Exemplo n.º 16
0
 protected void drawLine(int x1, int y1, int x2, int y2) {
   _gc.drawLine(x1, y1, x2, y2);
 }