Java Code Examples for org.eclipse.swt.graphics.Image#getBounds()
The following examples show how to use
org.eclipse.swt.graphics.Image#getBounds() .
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: ImageUtils.java From ermasterr with Apache License 2.0 | 6 votes |
public static void drawAtBufferedImage(final BufferedImage bimg, final Image image, final int x, final int y) throws InterruptedException { final ImageData data = image.getImageData(); for (int i = 0; i < image.getBounds().width; i++) { for (int j = 0; j < image.getBounds().height; j++) { final int tmp = 4 * (j * image.getBounds().width + i); if (data.data.length > tmp + 2) { final int r = 0xff & data.data[tmp + 2]; final int g = 0xff & data.data[tmp + 1]; final int b = 0xff & data.data[tmp]; bimg.setRGB(i + x, j + y, 0xFF << 24 | r << 16 | g << 8 | b << 0); } } } }
Example 2
Source File: CenteredContentCellPaint.java From ermasterr with Apache License 2.0 | 6 votes |
@Override public void handleEvent(final Event event) { if (event.index == colIndex) { if (event.type == SWT.EraseItem) { event.detail &= (Integer.MAX_VALUE ^ SWT.FOREGROUND); } else if (event.type == SWT.PaintItem) { final TableItem item = (TableItem) event.item; final Image img = item.getImage(colIndex); if (img != null) { final Rectangle size = img.getBounds(); final Table tbl = (Table) event.widget; event.gc.drawImage(img, event.x + (tbl.getColumn(colIndex).getWidth() - size.width) / 2, event.y + (tbl.getItemHeight() - size.height) / 2); } } } }
Example 3
Source File: JobGraph.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void paintControl( PaintEvent e ) { Point area = getArea(); if ( area.x == 0 || area.y == 0 ) { return; // nothing to do! } Display disp = shell.getDisplay(); Image img = getJobImage( disp, area.x, area.y, magnification ); e.gc.drawImage( img, 0, 0 ); if ( jobMeta.nrJobEntries() == 0 ) { e.gc.setForeground( GUIResource.getInstance().getColorCrystalTextPentaho() ); e.gc.setBackground( GUIResource.getInstance().getColorBackground() ); e.gc.setFont( GUIResource.getInstance().getFontMedium() ); Image pentahoImage = GUIResource.getInstance().getImageJobCanvas(); int leftPosition = ( area.x - pentahoImage.getBounds().width ) / 2; int topPosition = ( area.y - pentahoImage.getBounds().height ) / 2; e.gc.drawImage( pentahoImage, leftPosition, topPosition ); } img.dispose(); }
Example 4
Source File: ExportToImageManager.java From ermaster-b with Apache License 2.0 | 6 votes |
private void drawAtBufferedImage(BufferedImage bimg, Image image, int x, int y) throws InterruptedException { ImageData data = image.getImageData(); for (int i = 0; i < image.getBounds().width; i++) { for (int j = 0; j < image.getBounds().height; j++) { int tmp = 4 * (j * image.getBounds().width + i); if (data.data.length > tmp + 2) { int r = 0xff & data.data[tmp + 2]; int g = 0xff & data.data[tmp + 1]; int b = 0xff & data.data[tmp]; bimg.setRGB(i + x, j + y, 0xFF << 24 | r << 16 | g << 8 | b << 0); } this.doPostTask(); } } }
Example 5
Source File: SeverityColumnLabelProvider.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public void paint(final Event event, final Object element) { super.paint(event, element); final Marker marker = (Marker) element; if (marker != null && marker.exists()) { try { final int severity = (Integer) marker.getAttribute("severity"); final Image image = getImageForSeverity(severity); final Rectangle bounds = ((TableItem) event.item) .getBounds(event.index); final Rectangle imgBounds = image.getBounds(); bounds.width /= 2; bounds.width -= imgBounds.width / 2; bounds.height /= 2; bounds.height -= imgBounds.height / 2; final int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x; final int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y; event.gc.drawImage(image, x, y); } catch (final CoreException e) { BonitaStudioLog.error(e); } } }
Example 6
Source File: AbstractGalleryItemRenderer.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Draw overlay images for one corner. * * @param gc * @param x * @param y * @param ratio * @param images */ protected void drawOverlayImages(GC gc, int x, int y, double ratio, Image[] images) { if (images == null) return; int position = 0; for (int i = 0; i < images.length; i++) { Image img = images[i]; gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, x + position, y, (int) (img .getBounds().width * ratio), (int) (img.getBounds().height * ratio)); position += img.getBounds().width * ratio; } }
Example 7
Source File: ImagePainter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, bounds, configRegistry); } Image image = getImage(cell, configRegistry); if (image != null) { Rectangle imageBounds = image.getBounds(); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height)); } }
Example 8
Source File: DefaultGalleryGroupRenderer.java From nebula with Eclipse Public License 2.0 | 5 votes |
private int drawGroupImage(GC gc, GalleryItem group, int x, int y, Point imageSize2) { if (imageSize2 == null) return 0; Image img = group.getImage(); Rectangle imgSize = img.getBounds(); Point offset = RendererHelper.getImageOffset(imageSize2.x, imageSize2.y, maxImageWidth, getGroupHeight(group)); gc.drawImage(img, 0, 0, imgSize.width, imgSize.height, x + offset.x, y + offset.y, imageSize2.x, imageSize2.y); return maxImageWidth + 2 * minMargin; }
Example 9
Source File: SwtGc.java From hop with Apache License 2.0 | 5 votes |
@Override public void drawImage( SvgFile svgFile, int x, int y, int desiredWidth, int desiredHeight, float magnification, double angle ) throws HopException { // SvgCacheEntry cacheEntry = SvgCache.loadSvg( svgFile ); SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg( new SvgImage(cacheEntry.getSvgDocument()) ); Image img = imageSvg.getAsBitmapForSize( gc.getDevice(), Math.round( desiredWidth * magnification ), Math.round( desiredHeight * magnification ), angle ); Rectangle bounds = img.getBounds(); int hx = Math.round( bounds.width / magnification ); int hy = Math.round( bounds.height / magnification ); gc.drawImage( img, 0, 0, bounds.width, bounds.height, x - hx / 2, y - hy / 2, hx, hy ); }
Example 10
Source File: ImageCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) { drawBackground(gc, drawingArea, cellStyle, selected, printing); Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing); Rectangle rect = applyInsets(drect); Object value = column.getValue(row); if (value != null) { if (value instanceof Image) { Image img = (Image) value; int x = rect.x + (rect.width - img.getBounds().width) / 2; int y = rect.y + (rect.height - img.getBounds().height) / 2; gc.drawImage(img, x, y); } else { // indicate error with red fill Color bg = gc.getBackground(); gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); gc.fillRectangle(rect); gc.setBackground(bg); } } if (drawFocus) { drawFocus(gc, drawingArea); } drawSelection(gc, drawingArea, cellStyle, selected, printing); }
Example 11
Source File: ExportToImageManager.java From erflute with Apache License 2.0 | 5 votes |
private void writePNGorGIF(Image image, String saveFilePath, String formatName) throws IOException, InterruptedException { try { final ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(saveFilePath, format); } catch (final SWTException e) { e.printStackTrace(); final BufferedImage bufferedImage = new BufferedImage(image.getBounds().width, image.getBounds().height, BufferedImage.TYPE_INT_RGB); drawAtBufferedImage(bufferedImage, image, 0, 0); ImageIO.write(bufferedImage, formatName, new File(saveFilePath)); } }
Example 12
Source File: AlwStartPage.java From XPagesExtensionLibrary with Apache License 2.0 | 4 votes |
public static int getImageHeight(final Image img) { if (img != null) { return img.getBounds().height; } return 0; }
Example 13
Source File: TBSearchCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Point computeSize(GC gc, int wHint, int hHint, Object value) { GridItem item = (GridItem) value; gc.setFont(item.getFont(getColumn())); int x = 0; x += leftMargin; if (isTree()) { x += getToggleIndent(item); x += toggleRenderer.getBounds().width + insideMargin; } if (isCheck()) { x += checkRenderer.getBounds().width + insideMargin; } int y = 0; Image image = item.getImage(getColumn()); if (image != null) { y = topMargin + image.getBounds().height + bottomMargin; x += image.getBounds().width + insideMargin; } // MOPR-DND // MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns) // // x += gc.stringExtent(item.getText(column)).x + rightMargin; // // y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin); // // with this code: int textHeight = 0; if (!isWordWrap()) { x += gc.textExtent(item.getText(getColumn())).x + rightMargin; textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin; } else { int plainTextWidth; if (wHint == SWT.DEFAULT) plainTextWidth = getBounds().width - x - rightMargin; else plainTextWidth = wHint - x - rightMargin; TextLayout currTextLayout = new TextLayout(gc.getDevice()); currTextLayout.setFont(gc.getFont()); currTextLayout.setText(item.getText(getColumn())); currTextLayout.setAlignment(getAlignment()); currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth); x += plainTextWidth + rightMargin; textHeight += topMargin + textTopMargin; for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height; textHeight += textBottomMargin + bottomMargin; currTextLayout.dispose(); } y = Math.max(y, textHeight); return new Point(x, y); }
Example 14
Source File: DefaultCellRenderer.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public Point computeSize(GC gc, int wHint, int hHint, Object value) { GridItem item = (GridItem)value; gc.setFont(item.getFont(getColumn())); int x = 0; x += leftMargin; if (isTree()) { x += getToggleIndent(item); x += toggleRenderer.getBounds().width + insideMargin; } if (isCheck()) { x += checkRenderer.getBounds().width + insideMargin; } int y = 0; Image image = item.getImage(getColumn()); if (image != null) { y = topMargin + image.getBounds().height + bottomMargin; x += image.getBounds().width + insideMargin; } // MOPR-DND // MOPR: replaced this code (to get correct preferred height for cells in word-wrap columns) // // x += gc.stringExtent(item.getText(column)).x + rightMargin; // // y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + bottomMargin); // // with this code: int textHeight = 0; if(!isWordWrap()) { x += gc.textExtent(item.getText(getColumn())).x + rightMargin; textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin; } else { int plainTextWidth; if (wHint == SWT.DEFAULT) plainTextWidth = gc.textExtent(item.getText(getColumn())).x; else plainTextWidth = wHint - x - rightMargin; TextLayout currTextLayout = new TextLayout(gc.getDevice()); currTextLayout.setFont(gc.getFont()); currTextLayout.setText(item.getText(getColumn())); currTextLayout.setAlignment(getAlignment()); currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth); x += plainTextWidth + rightMargin; textHeight += topMargin + textTopMargin; for(int cnt=0;cnt<currTextLayout.getLineCount();cnt++) textHeight += currTextLayout.getLineBounds(cnt).height; textHeight += textBottomMargin + bottomMargin; currTextLayout.dispose(); } y = Math.max(y, textHeight); return new Point(x, y); }
Example 15
Source File: DefaultCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Rectangle getTextBounds(GridItem item, boolean preferred) { int x = leftMargin; if (isTree()) { x += getToggleIndent(item); x += toggleRenderer.getBounds().width + insideMargin; } if (isCheck()) { x += checkRenderer.getBounds().width + insideMargin; } Image image = item.getImage(getColumn()); if (image != null) { x += image.getBounds().width + insideMargin; } Rectangle bounds = new Rectangle(x,topMargin + textTopMargin,0,0); GC gc = new GC(item.getParent()); gc.setFont(item.getFont(getColumn())); Point size = gc.stringExtent(item.getText(getColumn())); bounds.height = size.y; if (preferred) { bounds.width = size.x - 1; } else { bounds.width = getBounds().width - x - rightMargin; } gc.dispose(); return bounds; }
Example 16
Source File: InsertedImageFigure.java From erflute with Apache License 2.0 | 4 votes |
public void setImg(Image image, boolean fixAspectRatio, int alpha) { this.image = image; this.fixAspectRatio = fixAspectRatio; this.alpha = alpha; this.imageSize = new Dimension(image.getBounds().width, image.getBounds().height); }
Example 17
Source File: ResetImageOriginalSizeAction.java From birt with Eclipse Public License 1.0 | 4 votes |
@Override public void run( ) { CommandStack stack = imageHandle.getModuleHandle( ).getCommandStack( ); stack.startTrans( Messages.getString("ResetImageOriginalSizeAction.trans.label") ); //$NON-NLS-1$ String defaultUnit = imageHandle.getModuleHandle( ).getDefaultUnits( ); Image image = getImage( ); int width = image.getBounds( ).width; int height = image.getBounds( ).height; //String url = imageHandle.getURI( ); try { if ( type == BYORIGINAL ) { imageHandle.setWidth( width + DesignChoiceConstants.UNITS_PX ); imageHandle.setHeight( height + DesignChoiceConstants.UNITS_PX ); } else { int dpi = 0; if ( type == BYSCREENDPI ) { dpi = UIUtil.getScreenResolution( )[0]; } else if ( type == BYREPORTDPI ) { dpi = ( (ReportDesignHandle) imageHandle.getModuleHandle( ) ).getImageDPI( ); } else if ( type == BYIMAGEDPI ) { dpi = getImageDPI( ); } double inch = ( (double) width ) / dpi; DimensionValue value = DimensionUtil.convertTo( inch, DesignChoiceConstants.UNITS_IN, defaultUnit ); imageHandle.getWidth( ).setValue( value ); inch = ( (double) height ) / dpi; value = DimensionUtil.convertTo( inch, DesignChoiceConstants.UNITS_IN, defaultUnit ); imageHandle.getHeight( ).setValue( value ); } } catch ( SemanticException e ) { stack.rollbackAll( ); ExceptionHandler.handle( e ); return ; } stack.commit( ); }
Example 18
Source File: CellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Point computeSize(GC gc, int wHint, int hHint, Object value) { GridItem item = (GridItem) value; gc.setFont(item.getFont(getColumn())); int x = 0; x += leftMargin; if (isTree()) { x += getToggleIndent(item); x += toggleRenderer.getBounds().width + insideMargin; } if (isCheck()) { x += checkRenderer.getBounds().width + insideMargin; } int y = 0; Image image = item.getImage(getColumn()); if (image != null) { y = topMargin + image.getBounds().height + bottomMargin; x += image.getBounds().width + insideMargin; } // MOPR-DND // MOPR: replaced this code (to get correct preferred height for cells // in word-wrap columns) // // x += gc.stringExtent(item.getText(column)).x + rightMargin; // // y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + // bottomMargin); // // with this code: int textHeight = 0; if (!isWordWrap()) { x += gc.textExtent(item.getText(getColumn())).x + rightMargin; textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin; } else { int plainTextWidth; if (wHint == SWT.DEFAULT) plainTextWidth = getBounds().width - x - rightMargin; else plainTextWidth = wHint - x - rightMargin; TextLayout currTextLayout = new TextLayout(gc.getDevice()); currTextLayout.setFont(gc.getFont()); currTextLayout.setText(item.getText(getColumn())); currTextLayout.setAlignment(getAlignment()); currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth); x += plainTextWidth + rightMargin; textHeight += topMargin + textTopMargin; for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height; textHeight += textBottomMargin + bottomMargin; currTextLayout.dispose(); } y = Math.max(y, textHeight); return new Point(x, y); }
Example 19
Source File: CellRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public Point computeSize(GC gc, int wHint, int hHint, Object value) { GridItem item = (GridItem) value; gc.setFont(item.getFont(getColumn())); int x = 0; x += leftMargin; if (isTree()) { x += getToggleIndent(item); x += toggleRenderer.getBounds().width + insideMargin; } if (isCheck()) { x += checkRenderer.getBounds().width + insideMargin; } int y = 0; Image image = item.getImage(getColumn()); if (image != null) { y = topMargin + image.getBounds().height + bottomMargin; x += image.getBounds().width + insideMargin; } // MOPR-DND // MOPR: replaced this code (to get correct preferred height for cells // in word-wrap columns) // // x += gc.stringExtent(item.getText(column)).x + rightMargin; // // y = Math.max(y,topMargin + gc.getFontMetrics().getHeight() + // bottomMargin); // // with this code: int textHeight = 0; if (!isWordWrap()) { x += gc.textExtent(item.getText(getColumn())).x + rightMargin; textHeight = topMargin + textTopMargin + gc.getFontMetrics().getHeight() + textBottomMargin + bottomMargin; } else { int plainTextWidth; if (wHint == SWT.DEFAULT) plainTextWidth = getBounds().width - x - rightMargin; else plainTextWidth = wHint - x - rightMargin; TextLayout currTextLayout = new TextLayout(gc.getDevice()); currTextLayout.setFont(gc.getFont()); currTextLayout.setText(item.getText(getColumn())); currTextLayout.setAlignment(getAlignment()); currTextLayout.setWidth(plainTextWidth < 1 ? 1 : plainTextWidth); x += plainTextWidth + rightMargin; textHeight += topMargin + textTopMargin; for (int cnt = 0; cnt < currTextLayout.getLineCount(); cnt++) textHeight += currTextLayout.getLineBounds(cnt).height; textHeight += textBottomMargin + bottomMargin; currTextLayout.dispose(); } y = Math.max(y, textHeight); return new Point(x, y); }
Example 20
Source File: TextVarWarning.java From hop with Apache License 2.0 | 4 votes |
public TextVarWarning( IVariables variables, Composite composite, int flags ) { super( composite, SWT.NONE ); warningInterfaces = new ArrayList<IWarning>(); FormLayout formLayout = new FormLayout(); formLayout.marginWidth = 0; formLayout.marginHeight = 0; formLayout.marginTop = 0; formLayout.marginBottom = 0; this.setLayout( formLayout ); // add a text field on it... wText = new TextVar( variables, this, flags ); warningControlDecoration = new ControlDecoration( wText, SWT.CENTER | SWT.RIGHT ); Image warningImage = GuiResource.getInstance().getImageWarning(); warningControlDecoration.setImage( warningImage ); warningControlDecoration.setDescriptionText( BaseMessages.getString( PKG, "TextVar.tooltip.FieldIsInUse" ) ); warningControlDecoration.hide(); // If something has changed, check the warning interfaces // wText.addModifyListener( new ModifyListener() { public void modifyText( ModifyEvent arg0 ) { // Verify all the warning interfaces. // Show the first that has a warning to show... // boolean foundOne = false; for ( IWarning warningInterface : warningInterfaces ) { IWarningMessage warningSituation = warningInterface.getWarningSituation( wText.getText(), wText, this ); if ( warningSituation.isWarning() ) { foundOne = true; warningControlDecoration.show(); warningControlDecoration.setDescriptionText( warningSituation.getWarningMessage() ); break; } } if ( !foundOne ) { warningControlDecoration.hide(); } } } ); FormData fdText = new FormData(); fdText.top = new FormAttachment( 0, 0 ); fdText.left = new FormAttachment( 0, 0 ); fdText.right = new FormAttachment( 100, -warningImage.getBounds().width ); wText.setLayoutData( fdText ); }