org.eclipse.swt.graphics.Device Java Examples

The following examples show how to use org.eclipse.swt.graphics.Device. 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: DesignerRepresentation.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void showNullChart( Dimension dSize )
{
	// Display error message for null chart. This behavior is consistent
	// with invalid table.
	String MSG = Messages.getString( "DesignerRepresentation.msg.InvalidChart" ); //$NON-NLS-1$
	logger.log( ILogger.ERROR,
			Messages.getString( "DesignerRepresentation.log.UnableToFind" ) ); //$NON-NLS-1$

	Device dv = Display.getCurrent( );
	Font font = FontManager.getFont( "Dialog", 10, SWT.ITALIC ); //$NON-NLS-1$
	gc.setFont( font );
	FontMetrics fm = gc.getFontMetrics( );
	gc.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
	gc.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
	gc.fillRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
	gc.drawRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
	String[] texts = splitOnBreaks( MSG, font, dSize.width - 10 );
	int y = 5;
	for ( String text : texts )
	{
		gc.drawText( text, 5, y );
		y += fm.getHeight( );
	}
}
 
Example #2
Source File: RotatePrint.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
RotateIterator(Print target, int angle, Device device, GC gc) {
	Util.notNull(target, device, gc);

	this.device = device;
	this.target = target.iterator(device, gc);
	this.angle = checkAngle(angle); // returns 90, 180, or 270 only

	Point min = this.target.minimumSize();
	Point pref = this.target.preferredSize();

	if (this.angle == 180) {
		this.minimumSize = new Point(min.x, min.y);
		this.preferredSize = new Point(pref.x, pref.y);
	} else { // flip x and y sizes if rotating by 90 or 270 degrees
		this.minimumSize = new Point(min.y, min.x);
		this.preferredSize = new Point(pref.y, pref.x);
	}
}
 
Example #3
Source File: SWTUtils.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
 
Example #4
Source File: SVGFigure.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts an AWT based buffered image into an SWT <code>Image</code>. This will always return an <code>Image</code> that
 * has 24 bit depth regardless of the type of AWT buffered image that is passed into the method.
 * 
 * @param awtImage the {@link java.awt.image.BufferedImage} to be converted to an <code>Image</code>
 * @return an <code>Image</code> that represents the same image data as the AWT <code>BufferedImage</code> type.
 */
protected static org.eclipse.swt.graphics.Image toSWT(final Device device, final BufferedImage awtImage) {
    // We can force bitdepth to be 24 bit because BufferedImage getRGB
    // allows us to always retrieve 24 bit data regardless of source color depth.
    final PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
    final ImageData swtImageData = new ImageData(awtImage.getWidth(), awtImage.getHeight(), 24, palette);
    // Ensure scansize is aligned on 32 bit.
    final int scansize = (awtImage.getWidth() * 3 + 3) * 4 / 4;
    final WritableRaster alphaRaster = awtImage.getAlphaRaster();
    final byte[] alphaBytes = new byte[awtImage.getWidth()];
    for (int y = 0; y < awtImage.getHeight(); y++) {
        final int[] buff = awtImage.getRGB(0, y, awtImage.getWidth(), 1, null, 0, scansize);
        swtImageData.setPixels(0, y, awtImage.getWidth(), buff, 0);
        if (alphaRaster != null) {
            final int[] alpha = alphaRaster.getPixels(0, y, awtImage.getWidth(), 1, (int[]) null);
            for (int i = 0; i < awtImage.getWidth(); i++) {
                alphaBytes[i] = (byte) alpha[i];
            }
            swtImageData.setAlphas(0, y, awtImage.getWidth(), alphaBytes, 0);
        }
    }
    return new org.eclipse.swt.graphics.Image(device, swtImageData);
}
 
Example #5
Source File: SWTUtils.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
 
Example #6
Source File: SwtUniversalImageBitmap.java    From hop with Apache License 2.0 6 votes vote down vote up
@Override
protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  Image result = new Image( device, width * 2, height * 2 );

  GC gc = new GC( result );

  int bw = bitmap.getBounds().width;
  int bh = bitmap.getBounds().height;
  Transform affineTransform = new Transform( device );
  affineTransform.translate( width, height );
  affineTransform.rotate( (float) Math.toDegrees( angleRadians ) );
  affineTransform.scale( (float) zoomFactor * width / bw, (float) zoomFactor * height / bh );
  gc.setTransform( affineTransform );

  gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh );

  gc.dispose();

  return result;
}
 
Example #7
Source File: SwtUniversalImageBitmap.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  Image result = new Image( device, width * 2, height * 2 );

  GC gc = new GC( result );

  int bw = bitmap.getBounds().width;
  int bh = bitmap.getBounds().height;
  Transform affineTransform = new Transform( device );
  affineTransform.translate( width, height );
  affineTransform.rotate( (float) Math.toDegrees( angleRadians ) );
  affineTransform.scale( (float) 1.0 * width / bw, (float) 1.0 * height / bh );
  gc.setTransform( affineTransform );

  gc.drawImage( bitmap, 0, 0, bw, bh, -bw / 2, -bh / 2, bw, bh );

  gc.dispose();

  return result;
}
 
Example #8
Source File: GraphicsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static Cursor createCursor(Device device, ImageData imageData, int width, int height) {
	try {
		return Cursor.class.getConstructor(Device.class, ImageData.class, int.class, int.class).newInstance(device,
				imageData, width, height);
	} catch (Exception ne) {
		return null;
	}
}
 
Example #9
Source File: SwtUniversalImage.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Method getAsBitmapForSize(..., angle) can't be called, because it returns bigger picture.
 */
public synchronized Image getAsBitmapForSize( Device device, int width, int height ) {
  checkDisposed();

  String key = width + "x" + height;
  Image result = cache.get( key );
  if ( result == null ) {
    result = renderSimple( device, width, height );
    cache.put( key, result );
  }
  return result;
}
 
Example #10
Source File: GapBorder.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
GapBorderPainter(GapBorder target, Device device) {
	Point dpi = device.getDPI();

	this.top = toPixels(target.top, dpi.y);
	this.bottom = toPixels(target.bottom, dpi.y);
	this.openTop = toPixels(target.openTop, dpi.y);
	this.openBottom = toPixels(target.openBottom, dpi.y);

	this.left = toPixels(target.left, dpi.x);
	this.right = toPixels(target.right, dpi.x);
}
 
Example #11
Source File: SWTUtils.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
 
Example #12
Source File: SwtUniversalImage.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use getAsBitmapForSize() instead.
 */
@Deprecated
public synchronized Image getAsBitmap( Device device ) {
  checkDisposed();

  Image result = cache.get( "" );

  if ( result == null ) {
    result = renderSimple( device );
    cache.put( "", result );
  }
  return result;
}
 
Example #13
Source File: SwtUniversalImageSvg.java    From hop with Apache License 2.0 5 votes vote down vote up
@Override
protected Image renderRotated( Device device, int width, int height, double angleRadians ) {
  BufferedImage doubleArea = SwingUniversalImage.createDoubleBitmap( width, height );

  Graphics2D gc = SwingUniversalImage.createGraphics( doubleArea );
  SwingUniversalImageSvg.render( gc, svgGraphicsNode, svgGraphicsSize, doubleArea.getWidth() / 2, doubleArea
    .getHeight() / 2, width, height, angleRadians );

  gc.dispose();

  return swing2swt( device, doubleArea );
}
 
Example #14
Source File: TextPiece.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public TextPiece(Device device, TextStyle style, String[] text, Point size,
		int ascent) {
	Util.notNull(device, size, style);
	Util.noNulls(text);
	this.size = size;
	this.lines = text;
	this.style = style;
	this.ascent = ascent;

	this.resources = ResourcePool.forDevice(device);
}
 
Example #15
Source File: HopGuiPipelineGraph.java    From hop with Apache License 2.0 5 votes vote down vote up
public Image getPipelineImage( Device device, int x, int y, float magnificationFactor ) {

    IGc gc = new SwtGc( device, new Point( x, y ), iconsize );

    int gridSize =
      PropsUi.getInstance().isShowCanvasGridEnabled() ? PropsUi.getInstance().getCanvasGridSize() : 1;

    PipelinePainter pipelinePainter = new PipelinePainter( gc, pipelineMeta, new Point( x, y ), new SwtScrollBar( horizontalScrollBar ), new SwtScrollBar( verticalScrollBar ),
      candidate, drop_candidate, selectionRegion, areaOwners,
      PropsUi.getInstance().getIconSize(), PropsUi.getInstance().getLineWidth(), gridSize,
      PropsUi.getInstance().getNoteFont().getName(), PropsUi.getInstance()
      .getNoteFont().getHeight(), pipeline, PropsUi.getInstance().isIndicateSlowPipelineTransformsEnabled(), PropsUi.getInstance().getZoomFactor(), outputRowsMap );

    // correct the magnification with the overall zoom factor
    //
    float correctedMagnification = (float) ( magnificationFactor * PropsUi.getInstance().getZoomFactor() );

    pipelinePainter.setMagnification( correctedMagnification );
    pipelinePainter.setTransformLogMap( transformLogMap );
    pipelinePainter.setStartHopTransform( startHopTransform );
    pipelinePainter.setEndHopLocation( endHopLocation );
    pipelinePainter.setNoInputTransform( noInputTransform );
    pipelinePainter.setEndHopTransform( endHopTransform );
    pipelinePainter.setCandidateHopType( candidateHopType );
    pipelinePainter.setStartErrorHopTransform( startErrorHopTransform );

    try {
      pipelinePainter.buildPipelineImage();
    } catch(Exception e) {
      new ErrorDialog( hopGui.getShell(), "Error", "Error building pipeline image", e );
    }
    Image img = (Image) gc.getImage();

    gc.dispose();
    return img;
  }
 
Example #16
Source File: TextPainterWithPadding.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private Font getFont(int style) {
	Device device = Display.getDefault();
	switch (style) {
	case SWT.BOLD:
		return new Font(device, getFontData(style));
	case SWT.ITALIC:
		return new Font(device, getFontData(style));
	case SWT.BOLD | SWT.ITALIC:
		return new Font(device, getFontData(style));
	default:
		return font;
	}

}
 
Example #17
Source File: TextPrint.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
TextIterator(TextPrint print, Device device, GC gc) {
	this.device = device;
	this.gc = gc;

	this.text = print.text;
	this.lines = print.text.split("(\r)?\n"); //$NON-NLS-1$
	this.style = print.style;
	this.wordSplitting = print.wordSplitting;
	this.minimumSize = maxExtent(text.split("\\s")); //$NON-NLS-1$
	this.preferredSize = maxExtent(lines);

	this.row = 0;
	this.col = 0;
}
 
Example #18
Source File: LineBreakPrint.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static int calculateLineHeight(LineBreakPrint print, Device device,
		GC gc) {
	Font oldFont = gc.getFont();

	gc.setFont(ResourcePool.forDevice(device).getFont(print.font));
	int result = gc.getFontMetrics().getHeight();

	gc.setFont(oldFont);

	return result;
}
 
Example #19
Source File: DefaultGridLookPainter.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public DefaultGridLookPainter(DefaultGridLook look, Device device, GC gc) {
	super(device);

	Point dpi = device.getDPI();

	this.border = look.getCellBorder().createPainter(device, gc);
	this.cellPadding = calculateCellPadding(look, dpi);
	this.margins = calculateGridMargins(look, dpi);

	this.bodyBackground = look.getBodyBackgroundProvider();
	this.headerBackground = look.getHeaderBackgroundProvider();
	this.footerBackground = look.getFooterBackgroundProvider();

	this.resources = ResourcePool.forDevice(device);
}
 
Example #20
Source File: PatternImageEditorDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static void drawItem( GC gc, PatternImage patternImage, int x,
		int y )
{
	int width = VIEW_WIDTH;
	int height = VIEW_HEIGHT;
	Device device = gc.getDevice( );
	Image image = createImageFromPattern( patternImage );
	Pattern pattern = new Pattern( device, image );
	gc.setBackgroundPattern( pattern );
	gc.fillRectangle( x, y, width, height );
	pattern.dispose( );
	image.dispose( );
}
 
Example #21
Source File: SwtUniversalImage.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Converts BufferedImage to SWT/Image with alpha channel.
 */
protected Image swing2swt( Device device, BufferedImage img ) {
  PaletteData palette = new PaletteData( 0xFF0000, 0xFF00, 0xFF );
  ImageData data = new ImageData( img.getWidth(), img.getHeight(), 32, palette );
  for ( int y = 0; y < data.height; y++ ) {
    for ( int x = 0; x < data.width; x++ ) {
      int rgba = img.getRGB( x, y );
      int rgb = palette.getPixel( new RGB( ( rgba >> 16 ) & 0xFF, ( rgba >> 8 ) & 0xFF, rgba & 0xFF ) );
      int a = ( rgba >> 24 ) & 0xFF;
      data.setPixel( x, y, rgb );
      data.setAlpha( x, y, a );
    }
  }
  return new Image( device, data );
}
 
Example #22
Source File: PageNumberPrint.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
PageNumberPiece(PageNumberIterator iter, Device device, Point size) {
	this.device = device;
	this.size = size;
	this.pageNumber = iter.pageNumber;
	this.textStyle = iter.textStyle;
	this.format = iter.format;
}
 
Example #23
Source File: SWTUtils.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
 
Example #24
Source File: SWTUtils.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
 
Example #25
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public ReportPrintGraphicalViewerOperation( GraphicalViewer g,
		Drawable drawable, Device device, Rectangle region )
{
	this.device = device;
	this.region = region;
	this.drawable = drawable;
	this.viewer = g;

	LayerManager lm = (LayerManager) viewer.getEditPartRegistry( )
			.get( LayerManager.ID );
	IFigure f = lm.getLayer( LayerConstants.PRINTABLE_LAYERS );

	this.printSource = f;
}
 
Example #26
Source File: ScalePrint.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
ScalePiece(Device device, PrintPiece target, double scale, int maxWidth,
		int maxHeight) {
	Util.notNull(device, target);
	this.device = device;
	this.target = target;
	this.scale = scale;
	Point targetSize = target.getSize();
	this.size = new Point(Math.min((int) Math.ceil(targetSize.x * scale),
			maxWidth), Math.min((int) Math.ceil(targetSize.y * scale),
			maxHeight));
}
 
Example #27
Source File: SwtUniversalImageBitmap.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
protected Image renderSimple( Device device, int width, int height ) {
  int xsize = bitmap.getBounds().width;
  int ysize = bitmap.getBounds().height;
  Image result = new Image( device, width, height );
  GC gc = new GC( result );
  gc.drawImage( bitmap, 0, 0, xsize, ysize, 0, 0, width, height );
  gc.dispose();
  return result;
}
 
Example #28
Source File: ResourcePool.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns a SharedGraphics which creates resources on the given device.
 *
 * @param device
 *            the device which resources will be created on.
 * @return a SharedGraphics which creates resources on the given device.
 */
public synchronized static ResourcePool forDevice(Device device) {
	Util.notNull(device);
	notDisposed(device);

	ResourcePool sharedGraphics = devices.get(device);
	if (sharedGraphics == null) {
		sharedGraphics = new ResourcePool(device);
		devices.put(device, sharedGraphics);
	}
	return sharedGraphics;
}
 
Example #29
Source File: GridIterator.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param grid
 * @param device
 * @param gc
 */
public GridIterator(GridPrint grid, Device device, GC gc) {
	this.device = device;
	this.dpi = device.getDPI();
	this.columns = new GridColumn[grid.getColumns().length];
	System.arraycopy(grid.getColumns(), 0, this.columns, 0,
			grid.getColumns().length);
	this.columnGroups = grid.getColumnGroups();

	this.header = createGridCellIterators(grid.getHeaderCells(), device,
			gc);
	this.body = createGridCellIterators(grid.getBodyCells(), device, gc);
	this.footer = createGridCellIterators(grid.getFooterCells(), device,
			gc);

	this.cellClippingEnabled = grid.isCellClippingEnabled();

	this.look = grid.getLook().getPainter(device, gc);

	this.minimumColSizes = computeColumnSizes(PrintSizeStrategy.MINIMUM);
	this.preferredColSizes = computeColumnSizes(
			PrintSizeStrategy.PREFERRED);

	this.minimumSize = computeSize(PrintSizeStrategy.MINIMUM,
			minimumColSizes);
	this.preferredSize = computeSize(PrintSizeStrategy.PREFERRED,
			preferredColSizes);

	row = 0;
	rowStarted = false;
}
 
Example #30
Source File: GridIterator.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private static GridCellIterator[][] createGridCellIterators(
		GridCell[][] gridCells, Device device, GC gc) {
	GridCellIterator[][] result = new GridCellIterator[gridCells.length][];
	for (int rowIndex = 0; rowIndex < result.length; rowIndex++)
		result[rowIndex] = createRowCellIterators(gridCells[rowIndex],
				device, gc);
	return result;
}