Package org.eclipse.swt.graphics

Examples of org.eclipse.swt.graphics.Device


   * @see org.eclipse.swt.examples.graphics.GraphicsTab#paint(org.eclipse.swt.graphics.GC, int, int)
   */
  public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
      return;
    Device device = gc.getDevice();

    // horizontal rectangle
    Transform transform = new Transform(device);
    transform.translate(0, translateY);
    gc.setTransform(transform);
    transform.dispose();

    Path path = new Path(device);
    path.addRectangle(0, 0, width, 50);
    Pattern pattern = new Pattern(device, 0, 0, width, 50, device.getSystemColor(SWT.COLOR_BLUE), 0x7f, device
        .getSystemColor(SWT.COLOR_RED), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // vertical rectangle
    transform = new Transform(device);
    transform.translate(translateX, 0);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(0, 0, 50, height);
    pattern.dispose();
    pattern = new Pattern(device, 0, 0, 50, height, device.getSystemColor(SWT.COLOR_DARK_CYAN), 0x7f, device
        .getSystemColor(SWT.COLOR_WHITE), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // diagonal rectangle from bottom right corner
    Rectangle rect = new Rectangle(0, 0, 50, height);
    transform = new Transform(device);
    transform.translate(width - diagTranslateX1, height / 2 - diagTranslateY1);

    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device
        .getSystemColor(SWT.COLOR_DARK_GREEN), 0x7f, device.getSystemColor(SWT.COLOR_DARK_MAGENTA), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();

    // diagonal rectangle from top right corner
    transform = new Transform(device);
    transform.translate(width - diagTranslateX2, height / 2 - diagTranslateY2);

    // rotate on center of rectangle
    transform.translate(rect.width / 2, rect.height / 2);
    transform.rotate(-45);
    transform.translate(-rect.width / 2, -rect.height / 2);
    gc.setTransform(transform);
    transform.dispose();

    path = new Path(device);
    path.addRectangle(rect.x, rect.y, rect.width, rect.height);
    pattern.dispose();
    pattern = new Pattern(device, rect.x, rect.y, rect.width, rect.height, device
        .getSystemColor(SWT.COLOR_DARK_RED), 0x7f, device.getSystemColor(SWT.COLOR_YELLOW), 0x7f);
    gc.setBackgroundPattern(pattern);
    gc.fillPath(path);
    gc.drawPath(path);
    pattern.dispose();
    path.dispose();
View Full Code Here


   * Paint the receiver into the specified GC.
   */
  public void paint(GC gc, int width, int height) {
    if (!example.checkAdvancedGraphics())
      return;
    Device device = gc.getDevice();

    if (alphaImg1 == null) {
      alphaImg1 = GraphicsExample.loadImage(device, GraphicsExample.class, "alpha_img1.png");
      alphaImg2 = GraphicsExample.loadImage(device, GraphicsExample.class, "alpha_img2.png");
    }

    Rectangle rect = alphaImg1.getBounds();

    gc.setAlpha(alphaValue);
    gc.drawImage(alphaImg1, rect.x, rect.y, rect.width, rect.height, width / 2, height / 2, width / 4, height / 4);

    gc.drawImage(alphaImg1, rect.x, rect.y, rect.width, rect.height, 0, 0, width / 4, height / 4);

    gc.setAlpha(255 - alphaValue);
    gc.drawImage(alphaImg2, rect.x, rect.y, rect.width, rect.height, width / 2, 0, width / 4, height / 4);

    gc.drawImage(alphaImg2, rect.x, rect.y, rect.width, rect.height, 0, 3 * height / 4, width / 4, height / 4);

    // pentagon
    gc.setBackground(device.getSystemColor(SWT.COLOR_DARK_MAGENTA));
    gc.fillPolygon(new int[] { width / 10, height / 2, 3 * width / 10, height / 2 - width / 6, 5 * width / 10,
        height / 2, 4 * width / 10, height / 2 + width / 6, 2 * width / 10, height / 2 + width / 6 });

    gc.setBackground(device.getSystemColor(SWT.COLOR_RED));

    // square
    gc.setAlpha(alphaValue);
    gc.fillRectangle(width / 2, height - 75, 75, 75);

    // triangle
    gc.setAlpha(alphaValue + 15);
    gc.fillPolygon(new int[] { width / 2 + 75, height - 2 * 75, width / 2 + 75, height - 75, width / 2 + 2 * 75,
        height - 75 });

    // triangle
    gc.setAlpha(alphaValue + 30);
    gc.fillPolygon(new int[] { width / 2 + 80, height - 2 * 75, width / 2 + 2 * 75, height - 2 * 75,
        width / 2 + 2 * 75, height - 80 });

    // triangle
    gc.setAlpha(alphaValue + 45);
    gc.fillPolygon(new int[] { width / 2 + 2 * 75, height - 2 * 75, width / 2 + 3 * 75, height - 2 * 75,
        width / 2 + 3 * 75, height - 3 * 75 });

    // triangle
    gc.setAlpha(alphaValue + 60);
    gc.fillPolygon(new int[] { width / 2 + 2 * 75, height - (2 * 75 + 5), width / 2 + 2 * 75, height - 3 * 75,
        width / 2 + 3 * 75 - 5, height - 3 * 75 });

    // square
    gc.setAlpha(alphaValue + 75);
    gc.fillRectangle(width / 2 + 3 * 75, height - 4 * 75, 75, 75);

    gc.setBackground(device.getSystemColor(SWT.COLOR_GREEN));

    // circle in top right corner
    gc.setAlpha(alphaValue2);
    gc.fillOval(width - 100, 0, 100, 100);

    // triangle
    gc.setAlpha(alphaValue + 90);
    gc.fillPolygon(new int[] { width - 300, 10, width - 100, 10, width - 275, 50 });

    // triangle
    gc.setAlpha(alphaValue + 105);
    gc.fillPolygon(new int[] { width - 10, 100, width - 10, 300, width - 50, 275 });

    // quadrilateral shape
    gc.setAlpha(alphaValue + 120);
    gc.fillPolygon(new int[] { width - 100, 100, width - 200, 150, width - 200, 200, width - 150, 200 });

    // blue circles
    gc.setBackground(device.getSystemColor(SWT.COLOR_BLUE));
    int size = 50;
    int alpha = 20;
    for (int i = 0; i < 10; i++) {
      gc.setAlpha(alphaValue + alpha);
      if (i % 2 > 0)
        gc.fillOval(width - (i + 1) * size, height - size, size, size);
      else
        gc.fillOval(width - (i + 1) * size, height - 3 * size / 2, size, size);
      alpha = alpha + 20;
    }

    // SWT string appearing randomly
    gc.setAlpha(alphaValue2);
    String text = GraphicsExample.getResourceString("SWT");
    Font font = AlphaTab.createFont(device, 100, SWT.NONE);
    gc.setFont(font);

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

    if (alphaValue2 == 0) {
      randX = (int) (width * Math.random());
      randY = (int) (height * Math.random());
      randX = randX > textWidth ? randX - textWidth : randX;
      randY = randY > textHeight ? randY - textHeight : randY;
    }

    gc.drawString(text, randX, randY, true);
    font.dispose();

    // gray donut
    gc.setAlpha(100);
    Path path = new Path(device);
    path.addArc((width - diameter) / 2, (height - diameter) / 2, diameter, diameter, 0, 360);
    path.close();
    path.addArc((width - diameter + 25) / 2, (height - diameter + 25) / 2, diameter - 25, diameter - 25, 0, 360);
    path.close();
    gc.setBackground(device.getSystemColor(SWT.COLOR_GRAY));
    gc.fillPath(path);
    gc.drawPath(path);
    path.dispose();
  }
View Full Code Here

  @Test
  public void fontOption() {
    // SETUP
    String input = "create_line\n    font=('Arial', 8, 'normal')\n";
    BufferedReader reader = new BufferedReader(new StringReader(input));
    Device device = null; // null is OK for test.
   
    // EXEC
    CanvasReader canvasReader = new CanvasReader(reader);
    CanvasCommand command = canvasReader.read();
    Font font = command.getFontOption(device, "font");
View Full Code Here

     *
     * @since 3.1
     */
    public ImageRegistry(ResourceManager manager) {
        Assert.isNotNull(manager);
        Device dev = manager.getDevice();
        if (dev instanceof Display) {
            this.display = (Display)dev;
        }
        this.manager = manager;
        manager.disposeExec(disposeRunnable);
View Full Code Here

   * @return the bytes of an encoded image for the specified viewer
   */
  public byte[] createImage(int format) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    Device device = getGraphicalViewer().getControl().getDisplay();
    LayerManager lm = (LayerManager) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
    IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
    Rectangle r = figure.getClientArea();

    Image image = null;
View Full Code Here

   * @return the bytes of an encoded image for the specified viewer
   */
  public byte[] createImage(int format) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    Device device = getGraphicalViewer().getControl().getDisplay();
    LayerManager lm = (LayerManager) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
    IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
    Rectangle r = figure.getClientArea();

    Image image = null;
View Full Code Here

   * @return the bytes of an encoded image for the specified viewer
   */
  public byte[] createImage(int format) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    Device device = editor.getGraphicalViewer().getControl().getDisplay();
    LayerManager lm = (LayerManager) editor.getGraphicalViewer().getEditPartRegistry().get(
        LayerManager.ID);
    IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
    Rectangle r = figure.getClientArea();

View Full Code Here

   * @return the bytes of an encoded image for the specified viewer
   */
  public byte[] createImage(int format) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    Device device = this.editor.getGraphViewer().getControl().getDisplay();
    LayerManager lm = (LayerManager) this.editor.getGraphViewer()
        .getEditPartRegistry().get(LayerManager.ID);
    IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
    Rectangle r = figure.getClientArea();

View Full Code Here

TOP

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

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.