Refine search
private String truncateName( String name ) { GC gc = new GC( toolBar ); Point size = gc.textExtent( name ); if ( size.x <= MAX_REPO_NAME_PIXEL_LENGTH ) { // repository name is small enough to fit just return it. gc.dispose(); return name; } String originalName = name; while ( gc.textExtent( name + "..." ).x > MAX_REPO_NAME_PIXEL_LENGTH ) { name = name.substring( 0, name.length() - 1 ); } gc.dispose(); name = name + "..."; return name; } }
@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; }
String leftText = newText.substring( 0, e.start ); String rightText = newText.substring( e.end, newText.length() ); GC gc = new GC( text ); Point size = gc.textExtent( leftText + e.text + rightText ); gc.dispose(); size = text.computeSize( size.x, SWT.DEFAULT ); editor.horizontalAlignment = SWT.LEFT;
String leftText = newText.substring( 0, e.start ); String rightText = newText.substring( e.end, newText.length() ); GC gc = new GC( text ); Point size = gc.textExtent( leftText + e.text + rightText ); gc.dispose(); size = text.computeSize( size.x, SWT.DEFAULT ); editor.horizontalAlignment = SWT.LEFT;
String leftText = newText.substring( 0, e.start ); String rightText = newText.substring( e.end, newText.length() ); GC gc = new GC( text ); Point size = gc.textExtent( leftText + e.text + rightText ); gc.dispose(); size = text.computeSize( size.x, SWT.DEFAULT ); editor.horizontalAlignment = SWT.LEFT;
/** * @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; } }
void layout() { Composite parent = canvas.getParent(); Rectangle rect = parent.getClientArea(); int width = 0; String[] items = list.getItems(); GC gc = new GC( list ); for ( int i = 0; i < objects.length; i++ ) { width = Math.max( width, gc.stringExtent( items[i] ).x ); } gc.dispose(); Point size1 = start.computeSize( SWT.DEFAULT, SWT.DEFAULT ); Point size2 = stop.computeSize( SWT.DEFAULT, SWT.DEFAULT ); Point size3 = check.computeSize( SWT.DEFAULT, SWT.DEFAULT ); Point size4 = label.computeSize( SWT.DEFAULT, SWT.DEFAULT ); width = Math.max( size1.x, Math.max( size2.x, Math.max( size3.x, width ) ) ); width = Math.max( 64, Math.max( size4.x, list.computeSize( width, SWT.DEFAULT ).x ) ); start.setBounds( 0, 0, width, size1.y ); stop.setBounds( 0, size1.y, width, size2.y ); check.setBounds( 0, size1.y + size2.y, width, size3.y ); label.setBounds( 0, rect.height - size4.y, width, size4.y ); int height = size1.y + size2.y + size3.y; list.setBounds( 0, height, width, rect.height - height - size4.y ); text.setBounds( width, 0, rect.width - width, rect.height ); canvas.setBounds( width, 0, rect.width - width, rect.height ); }
/** * 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 ); } }
private static void createSpace(Composite parent) { Label vfiller = new Label(parent, SWT.LEFT); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan= 2; GC gc = new GC(parent); gridData.heightHint = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1) / 2; gc.dispose(); vfiller.setLayoutData(gridData); }