/** * TODO: not used. */ public static Image getImage( Display display, Class<?> resourceClass, String filename ) { try { return new Image( display, resourceClass.getResourceAsStream( filename ) ); } catch ( Exception e ) { try { return new Image( display, resourceClass.getResourceAsStream( "/" + filename ) ); } catch ( Exception e2 ) { return getImage( display, filename ); } } }
/** * TODO: Load job and step images. */ public static Image getImage( Display display, ClassLoader classLoader, String filename ) { try { return new Image( display, classLoader.getResourceAsStream( filename ) ); } catch ( Exception e ) { try { return new Image( display, classLoader.getResourceAsStream( "/" + filename ) ); } catch ( Exception e2 ) { return getImage( display, filename ); } } }
/** * TODO: Load splash and common images. */ public static Image getImageAsResource( Display display, String location ) { return new Image( display, getImageInputStream( display, location ) ); }
public void handleEvent( Event event ) { cancelButton.setImage( new Image( display, GoogleAuthorizationDialog.class.getResourceAsStream( "/images/close-button.png" ) ) ); } } );
/** * TODO: GUI resources. */ public static Image getImage( Display display, String location ) { // TODO: find other instances of getImage (plugin, steps) and transition them to new model through an laf manager try { InputStream is = KettleVFS.getInputStream( location ); Image im = new Image( display, is ); is.close(); return im; } catch ( Exception e ) { try { return new Image( display, ImageUtil.class.getClassLoader().getResourceAsStream( location ) ); } catch ( Exception npe ) { throw new RuntimeException( "Unable to load image with name [" + location + "]", e ); } } }
private Image loadAsResource( Display display, String location, int size ) { SwtUniversalImage img = SwtSvgImageUtil.getImageAsResource( display, location ); Image image; if ( size > 0 ) { image = new Image( display, img.getAsBitmapForSize( display, size, size ), SWT.IMAGE_COPY ); } else { image = new Image( display, img.getAsBitmap( display ), SWT.IMAGE_COPY ); } img.dispose(); return image; }
/** * Load image from InputStream as bitmap image, or SVG image conversion to bitmap image. */ private static SwtUniversalImage loadImage( Display display, InputStream in, String filename ) { if ( !SvgSupport.isSvgName( filename ) ) { // bitmap image return new SwtUniversalImageBitmap( new Image( display, in ) ); } else { // svg image - need to convert to bitmap try { return new SwtUniversalImageSvg( SvgSupport.loadSvgImage( in ) ); } catch ( Exception ex ) { throw new RuntimeException( ex ); } } } }
public void handleEvent( Event event ) { cancelButton.setImage( new Image( display, GoogleAuthorizationDialog.class.getResourceAsStream( "/images/close-button-hover.png" ) ) ); cancelButton.setCursor( new Cursor( display, SWT.CURSOR_HAND ) ); } } );
/** * Loads an image from a location once. The second time, the image comes from a cache. Because of this, it's important * to never dispose of the image you get from here. (easy!) The images are automatically disposed when the application * ends. * * @param location the location of the image resource to load * @param width The height to resize the image to * @param height The width to resize the image to * @return the loaded image */ public Image getImage( String location, int width, int height ) { Image image = imageMap.get( location ); if ( image == null ) { SwtUniversalImage svg = SwtSvgImageUtil.getImage( display, location ); image = new Image( display, svg.getAsBitmapForSize( display, width, height ), SWT.IMAGE_COPY ); svg.dispose(); imageMap.put( location, image ); } return image; }
/** * Loads an image from a location once. The second time, the image comes from a cache. Because of this, it's important * to never dispose of the image you get from here. (easy!) The images are automatically disposed when the application * ends. * * @param location the location of the image resource to load * @param classLoader the ClassLoader to use to locate resources * @param width The height to resize the image to * @param height The width to resize the image to * @return the loaded image */ public Image getImage( String location, ClassLoader classLoader, int width, int height ) { Image image = imageMap.get( location ); if ( image == null ) { SwtUniversalImage svg = SwtSvgImageUtil.getUniversalImage( display, classLoader, location ); image = new Image( display, svg.getAsBitmapForSize( display, width, height ), SWT.IMAGE_COPY ); svg.dispose(); imageMap.put( location, image ); } return image; }
public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) { ImageData imageData = tempImage.getImageData(); int pixelIndex = imageData.palette.getPixel( transparentColor ); imageData.transparentPixel = pixelIndex; Image image = new Image( display, imageData ); tempImage.dispose(); return image; }
private Image loadAsResource( Display display, String location ) { SwtUniversalImage img = SwtSvgImageUtil.getImageAsResource( display, location ); Image image = new Image( display, img.getAsBitmap( display ), SWT.IMAGE_COPY ); img.dispose(); return image; }
/** * 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 ); } }
@Override public void drawImage( BufferedImage image, int x, int y ) { ImageData imageData = ImageUtil.convertToSWT( image ); Image swtImage = new Image( gc.getDevice(), imageData ); gc.drawImage( swtImage, x, y ); swtImage.dispose(); } }
@Override public void drawImage( BufferedImage image, int x, int y ) { ImageData imageData = ImageUtil.convertToSWT( image ); Image swtImage = new Image( gc.getDevice(), imageData ); gc.drawImage( swtImage, x, y ); swtImage.dispose(); } }
@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; }
/** * @return the small {@link Image} that can be used as placeholder for missing image. */ private static Image getMissingImage() { Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); // GC gc = new GC(image); gc.setBackground(getColor(SWT.COLOR_RED)); gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); gc.dispose(); // return image; } /**
@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; } }
/** * Get the image for when all other fallbacks have failed. This is an image * drawn on the canvas, a square with a red X. * * @param display the device to render the image to * @return the missing image */ public static SwtUniversalImage getMissingImage( Display display ) { Image img = new Image( display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE ); GC gc = new GC( img ); gc.setForeground( new Color( display, 0, 0, 0 ) ); gc.drawRectangle( 4, 4, ConstUI.ICON_SIZE - 8, ConstUI.ICON_SIZE - 8 ); gc.setForeground( new Color( display, 255, 0, 0 ) ); gc.drawLine( 4, 4, ConstUI.ICON_SIZE - 4, ConstUI.ICON_SIZE - 4 ); gc.drawLine( ConstUI.ICON_SIZE - 4, 4, 4, ConstUI.ICON_SIZE - 4 ); gc.dispose(); return new SwtUniversalImageBitmap( img ); }
public static final void setOptimalWidthOnColumns( Tree tree ) { int nrCols = tree.getColumnCount(); int[] max = new int[nrCols]; Image image = new Image( tree.getDisplay(), 10, 10 ); GC gc = new GC( image ); for ( int i = 0; i < max.length; i++ ) { TreeColumn treeColumn = tree.getColumn( i ); Point point = gc.textExtent( treeColumn.getText() ); max[i] = point.x; } getMaxWidths( tree.getItems(), max, gc ); gc.dispose(); image.dispose(); for ( int i = 0; i < max.length; i++ ) { TreeColumn treeColumn = tree.getColumn( i ); treeColumn.setWidth( max[i] + 30 ); } }