Package org.eclipse.draw2d

Examples of org.eclipse.draw2d.SWTGraphics


     * IMAGE_JPEG, IMAGE_PNG.
     * @param stream
     * @param format
     */
    public void createImage(OutputStream stream, int format) {
        SWTGraphics g = null;
        GC gc = null;
        Image image = null;
        LayerManager layerManager = (LayerManager)
            getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
        IFigure figure = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
        Rectangle r = figure.getBounds();
        try {
            image = new Image(Display.getDefault(), r.width, r.height);
            gc = new GC(image);
            g = new SWTGraphics(gc);
            g.translate(r.x * -1, r.y * -1);
            figure.paint(g);
            ImageLoader imageLoader = new ImageLoader();
            imageLoader.data = new ImageData[] { image.getImageData() };
            imageLoader.save(stream, format);
        } catch (Throwable t) {
            DroolsEclipsePlugin.log(t);
        } finally {
            if (g != null) {
                g.dispose();
            }
            if (gc != null) {
                gc.dispose();
            }
            if (image != null) {
View Full Code Here


      Image image = new Image(Display.getCurrent(), bounds.width,
          bounds.height);

      // Paints the figure on it using SWT graphics
      GC gc = new GC(image);
      Graphics swtGraphics = new SWTGraphics(gc);
      paintFigure(shape, backgroundColor, bounds, swtGraphics);

      // Draws the image on the original graphics
      graphics.drawImage(image, 0, 0);

      // Disposes image (and GC btw) and SWT graphics
      image.dispose();
      swtGraphics.dispose();
    }
  }
View Full Code Here

        imageLoader.save(imagePath + ".tr.gif", SWT.IMAGE_GIF);
    }

    public static void paintAndSave(IFigure figure, String outputPath) {
        Image image = new Image(Display.getDefault(), 17, 17);
        SWTGraphics g = new SWTGraphics(new GC(image));
        g.setAntialias(SWT.ON);
        figure.paint(g);
        ImageLoader imageLoader = new ImageLoader();
        imageLoader.data = new ImageData[] { image.getImageData() };
        int whitePixel = imageLoader.data[0].palette.getPixel(new RGB(255,255,255));
        for (int i = 0; i < imageLoader.data.length; i++) {
View Full Code Here

    public void doSave(IProgressMonitor monitor) {
        // we remove the selection in order to generate valid graph picture
        getGraphicalViewer().deselectAll();
        getGraphicalViewer().flush();

        SWTGraphics g = null;
        GC gc = null;
        Image image = null;

        LayerManager lm = (LayerManager) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
        IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);

        try {
            Rectangle r = figure.getBounds();
            editor.getDefinition().setDimension(new Dimension(r.width, r.height));
            image = new Image(Display.getDefault(), r.width, r.height);
            gc = new GC(image);
            g = new SWTGraphics(gc);
            g.translate(r.x * -1, r.y * -1);
            figure.paint(g);
            ImageLoader imageLoader = new ImageLoader();
            imageLoader.data = new ImageData[] { ImageHelper.downSample(image) };
            imageLoader.save(getImageSavePath(), SWT.IMAGE_JPEG);
        } catch (Exception e) {
            DesignerLogger.logError(e);
        } finally {
            if (g != null) {
                g.dispose();
            }
            if (gc != null) {
                gc.dispose();
            }
            if (image != null) {
View Full Code Here

  }

  private static Image getIconImage(IFigure figure) {
    imageBuffer = new Image(null, LOW_WIDTH, LOW_HEIGHT);
    imageGC = new GC(imageBuffer, (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT));
    swtGraphics = new SWTGraphics(imageGC);
    figure.paint(swtGraphics);
    return imageBuffer;
  }
View Full Code Here

    {
      gc.setAntialias(SWT.OFF);
      gc.setTextAntialias(SWT.OFF);
    }
   
    Graphics graphics = new SWTGraphics(gc);
    rootFigure.paint(graphics);
    graphics.dispose();

    ImageLoader loader = new ImageLoader();
    loader.data = new ImageData[]{image.getImageData()};

    ByteArrayOutputStream os = new ByteArrayOutputStream();
View Full Code Here

    {
      gc.setAntialias(SWT.OFF);
      gc.setTextAntialias(SWT.OFF);
    }
   
    Graphics graphics = new SWTGraphics(gc);
    rootFigure.paint(graphics);
    graphics.dispose();

    ImageLoader loader = new ImageLoader();
    loader.data = new ImageData[]{image.getImageData()};

    ByteArrayOutputStream os = new ByteArrayOutputStream();
View Full Code Here

          .getClientArea().height));
      fig4.setBackgroundColor(ColorConstants.white);
      img = new Image(Display.getCurrent(), fig1.getClientArea().width,
          fig1.getClientArea().height);
      imageGC = new GC(img);
      Graphics g = new SWTGraphics(imageGC);
      fig4.paint(g);
      fig3.paint(g);
      fig2.paint(g);
      fig1.paint(g);
      g.dispose();
      exportImageJob(img, imageGC, saveLocation,
          fileDialog.getFilterIndex());
    }
  }
View Full Code Here

            fig1.getClientArea().height, 24, new PaletteData(0xFF,
                0xFF00, 0xFF000));
        monitor.worked(2);
        img = new Image(Display.getCurrent(), data);
        imageGC = new GC(img);
        Graphics g = new SWTGraphics(imageGC);
        monitor.worked(3);
        fig1.paint(g);
        g.dispose();
        imageGC.dispose();
        img.dispose();
        monitor.done();
        return Status.OK_STATUS;
      }
View Full Code Here

    // Creates a new image of width x height on the current display
    Image image = new Image(Display.getCurrent(), width, height);

    // Paints the figure on it
    GC gc = new GC(image);
    Graphics graphics = new SWTGraphics(gc);
    figure.paint(graphics);

    // Get the image data back
    ImageData data = image.getImageData();
    ImageDescriptor id = ImageDescriptor.createFromImageData(data);

    // Disposes image (and GC btw) and SWT graphics
    image.dispose();
    graphics.dispose();

    return id;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.draw2d.SWTGraphics

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.