Java Code Examples for org.eclipse.swt.graphics.GC#setClipping()
The following examples show how to use
org.eclipse.swt.graphics.GC#setClipping() .
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: BigPrint.java From nebula with Eclipse Public License 2.0 | 6 votes |
public void paint(GC gc, int x, int y) { // Remember clipping region Region region = new Region(); gc.getClipping(region); // Set clipping region so only the portion of the target we want is // printed. gc.setClipping(x, y, size.x, size.y); // Paint the target. target.paint(gc, x - offset.x, y - offset.y); // Restore clipping region gc.setClipping(region); region.dispose(); }
Example 2
Source File: CompositeFreezeLayer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
@Override public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) { super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); gc.setClipping(rectangle); Color oldFg = gc.getForeground(); gc.setForeground(GUIHelper.COLOR_BLUE); final int freezeWidth = freezeLayer.getWidth() - 1; if (freezeWidth > 0) { gc.drawLine(xOffset + freezeWidth, yOffset, xOffset + freezeWidth, yOffset + getHeight() - 1); } final int freezeHeight = freezeLayer.getHeight() - 1; if (freezeHeight > 0) { gc.drawLine(xOffset, yOffset + freezeHeight, xOffset + getWidth() - 1, yOffset + freezeHeight); } gc.setForeground(oldFg); }
Example 3
Source File: CompositeLayer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configuration) { int x = xOffset; for (int layoutX = 0; layoutX < layoutXCount; layoutX++) { int y = yOffset; for (int layoutY = 0; layoutY < layoutYCount; layoutY++) { ILayer childLayer = childLayerLayout[layoutX][layoutY]; Rectangle childLayerRectangle = new Rectangle(x, y, childLayer.getWidth(), childLayer.getHeight()); childLayerRectangle = rectangle.intersection(childLayerRectangle); Rectangle originalClipping = gc.getClipping(); gc.setClipping(childLayerRectangle); childLayer.getLayerPainter().paintLayer(natLayer, gc, x, y, childLayerRectangle, configuration); gc.setClipping(originalClipping); y += childLayer.getHeight(); } x += childLayerLayout[layoutX][0].getWidth(); } }
Example 4
Source File: CompositeFreezeLayer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
@Override public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) { super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry); gc.setClipping(rectangle); Color oldFg = gc.getForeground(); gc.setForeground(GUIHelper.COLOR_BLUE); final int freezeWidth = freezeLayer.getWidth() - 1; if (freezeWidth > 0) { gc.drawLine(xOffset + freezeWidth, yOffset, xOffset + freezeWidth, yOffset + getHeight() - 1); } final int freezeHeight = freezeLayer.getHeight() - 1; if (freezeHeight > 0) { gc.drawLine(xOffset, yOffset + freezeHeight, xOffset + getWidth() - 1, yOffset + freezeHeight); } gc.setForeground(oldFg); }
Example 5
Source File: RoundedToolbar.java From nebula with Eclipse Public License 2.0 | 5 votes |
private void drawBorders(final GC gc, final int width, final int height) { final AdvancedPath path = new AdvancedPath(getDisplay()); path.addRoundRectangle(0, 0, width, height, cornerRadius, cornerRadius); gc.setClipping(path); gc.setForeground(START_GRADIENT_COLOR); gc.setBackground(END_GRADIENT_COLOR); gc.fillGradientRectangle(0, 0, width, height, true); gc.setForeground(BORDER_COLOR); gc.drawRoundRectangle(0, 0, width - 1, height - 1, cornerRadius, cornerRadius); gc.setClipping((Rectangle) null); }
Example 6
Source File: R31Enhance.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Equivalent to <code><b>GC.setAdvanced()</b></code> in r3.1. * * @param gc * @param value */ static void setAdvanced( GC gc, boolean value, Region clipping ) { if ( R31_AVAILABLE ) { gc.setAdvanced( value ); // setAdvanced will clean the clipping info, restore it here. gc.setClipping( clipping ); } }
Example 7
Source File: TextPainter.java From swt-bling with MIT License | 5 votes |
/** * Paints text and/or returns a Rectangle representing the computed bounds * of the text. You may only want they rectangle if you are trying to lay the * text out. * * @param gc * @param paint * @return Rectangle representing the computed bounds */ Rectangle conditionallyPaintText(final GC gc, final boolean paint) { final Rectangle clip = gc.getClipping(); final Color bg = gc.getBackground(); if (clipping) { gc.setClipping(this.bounds); } hyperlinks.clear(); int y = bounds.y + paddingTop; List<List<DrawData>> lines = buildLines(gc); for (int i = 0; i < lines.size(); i++) { if(justification == SWT.RIGHT) { y += drawRightJustified(gc, paint, lines.get(i), y); } else if (justification == SWT.LEFT) { y += drawLeftJustified(gc, paint, lines.get(i), y); } else if (justification == SWT.CENTER) { y += drawCenterJustified(gc, paint, lines.get(i), y); } } if (drawBounds) { gc.setForeground(boundaryColor); gc.drawRectangle(bounds); } Rectangle calculatedBounds = new Rectangle(bounds.x, bounds.y, bounds.width, y - bounds.y); if (drawCalculatedBounds) { gc.setForeground(ColorFactory.getColor(gc.getDevice(), 0, 255, 0)); gc.drawRectangle(calculatedBounds); } gc.setClipping(clip); gc.setBackground(bg); return calculatedBounds; }
Example 8
Source File: TextPainter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, rectangle, configRegistry); } Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); String text = convertDataType(cell, configRegistry); // Draw Text String originalText = text; int originalTextWidth = getWidthFromCache(gc, originalText); text = getAvailableTextToDisplay(gc, rectangle, text); int contentWidth = Math.min(originalTextWidth, rectangle.width); int fontHeight = gc.getFontMetrics().getHeight(); int contentHeight = fontHeight * getNumberOfNewLines(text); gc.drawText( text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true ); gc.setClipping(originalClipping); }
Example 9
Source File: TextPainter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, rectangle, configRegistry); } Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); String text = convertDataType(cell, configRegistry); // Draw Text String originalText = text; int originalTextWidth = getWidthFromCache(gc, originalText); text = getAvailableTextToDisplay(gc, rectangle, text); int contentWidth = Math.min(originalTextWidth, rectangle.width); int fontHeight = gc.getFontMetrics().getHeight(); int contentHeight = fontHeight * getNumberOfNewLines(text); gc.drawText( text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true ); gc.setClipping(originalClipping); }
Example 10
Source File: ViewLattice.java From arx with Apache License 2.0 | 5 votes |
/** * Utility method which centers a text in a rectangle. * * @param gc * @param text * @param x * @param y * @param width * @param height */ private void drawText(final GC gc, final String text, final int x, final int y, final int width, final int height) { Point size = canvas.getSize(); Point extent = gc.textExtent(text); gc.setClipping(x, y, width, height); int xx = x + (width - extent.x) / 2; int yy = y + height / 2 - extent.y / 2; gc.drawText(text, xx, yy, true); gc.setClipping(0, 0, size.x, size.y); }
Example 11
Source File: Chart3DViewer.java From birt with Eclipse Public License 1.0 | 4 votes |
private final void showException( GC g2d, Exception ex ) { String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; while ( ex.getCause( ) != null ) { ex = (Exception) ex.getCause( ); } String sException = ex.getClass( ).getName( ); if ( sWrappedException.equals( sException ) ) { sWrappedException = null; } String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>";//$NON-NLS-1$ } StackTraceElement[] stea = ex.getStackTrace( ); Point d = this.getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setClipping( 20, 20, d.x - 40, d.y - 40 ); int x = 25, y = 20 + fm.getHeight( ); g2d.drawString( "Exception:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sException, x, y ); x = 25; y += fm.getHeight( ); if ( sWrappedException != null ) { g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sWrappedException, x, y ); x = 25; y += fm.getHeight( ); } g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Message:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) ); g2d.drawString( sMessage, x, y ); x = 25; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Trace:", x, y );//$NON-NLS-1$ x = 40; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) ); for ( int i = 0; i < stea.length; i++ ) { g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$ + stea[i].getMethodName( ) + "(...):"//$NON-NLS-1$ + stea[i].getLineNumber( ), x, y ); x = 40; y += fm.getHeight( ); } fo.dispose( ); }
Example 12
Source File: TabBar.java From nebula with Eclipse Public License 2.0 | 4 votes |
private void onPaint(PaintEvent e) { GC gc = e.gc; int y = getBounds().height - barHeight; int totalWidth = horzMargin + (itemWidth * items.size()) + (itemSpacing * items.size()) - itemSpacing + horzMargin; int croppedWidth = Math.max(totalWidth,getBounds().width); // Region reg = createRoundedTopRegion(0,y,croppedWidth,getClientArea().height - y); // gc.setClipping(reg); Pattern p = new Pattern(getDisplay(), 0, y, 0, y + barHeight, bottom, 255, getBackground(), 0); gc.setBackgroundPattern(p); gc.fillRectangle(0, y,croppedWidth, barHeight); p.dispose(); // reg.dispose(); gc.setClipping((Region)null); gc.setBackgroundPattern(null); int x = horzMargin; if ((getStyle() & SWT.RIGHT) != 0) { if (getBounds().width > totalWidth) { x += getBounds().width - totalWidth; } } y = (getBounds().height - barHeight) - itemHeight; for (Iterator iterator = items.iterator(); iterator.hasNext();) { TabBarItem item = (TabBarItem)iterator.next(); renderer.setBounds(new Rectangle(x,y,itemWidth,itemHeight)); renderer.setSelected(item == selectedItem); renderer.paint(gc, item); x += itemWidth + itemSpacing; } }
Example 13
Source File: SwtChartViewerSelector.java From birt with Eclipse Public License 1.0 | 4 votes |
private final void showException( GC g2d, Exception ex ) { String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; while ( ex.getCause( ) != null ) { ex = (Exception) ex.getCause( ); } String sException = ex.getClass( ).getName( ); if ( sWrappedException.equals( sException ) ) { sWrappedException = null; } String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>";//$NON-NLS-1$ } StackTraceElement[] stea = ex.getStackTrace( ); Point d = this.getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setClipping( 20, 20, d.x - 40, d.y - 40 ); int x = 25, y = 20 + fm.getHeight( ); g2d.drawString( "Exception:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sException, x, y ); x = 25; y += fm.getHeight( ); if ( sWrappedException != null ) { g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sWrappedException, x, y ); x = 25; y += fm.getHeight( ); } g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Message:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) ); g2d.drawString( sMessage, x, y ); x = 25; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Trace:", x, y );//$NON-NLS-1$ x = 40; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) ); for ( int i = 0; i < stea.length; i++ ) { g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$ + stea[i].getMethodName( ) + "(...):"//$NON-NLS-1$ + stea[i].getLineNumber( ), x, y ); x = 40; y += fm.getHeight( ); } fo.dispose( ); }
Example 14
Source File: CurveFittingViewer.java From birt with Eclipse Public License 1.0 | 4 votes |
private final void showException( GC g2d, Exception ex ) { String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; while ( ex.getCause( ) != null ) { ex = (Exception) ex.getCause( ); } String sException = ex.getClass( ).getName( ); if ( sWrappedException.equals( sException ) ) { sWrappedException = null; } String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>";//$NON-NLS-1$ } StackTraceElement[] stea = ex.getStackTrace( ); Point d = this.getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setClipping( 20, 20, d.x - 40, d.y - 40 ); int x = 25, y = 20 + fm.getHeight( ); g2d.drawString( "Exception:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sException, x, y ); x = 25; y += fm.getHeight( ); if ( sWrappedException != null ) { g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sWrappedException, x, y ); x = 25; y += fm.getHeight( ); } g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Message:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) ); g2d.drawString( sMessage, x, y ); x = 25; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Trace:", x, y );//$NON-NLS-1$ x = 40; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) ); for ( int i = 0; i < stea.length; i++ ) { g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$ + stea[i].getMethodName( ) + "(...):"//$NON-NLS-1$ + stea[i].getLineNumber( ), x, y ); x = 40; y += fm.getHeight( ); } fo.dispose( ); }
Example 15
Source File: JavaViewer.java From birt with Eclipse Public License 1.0 | 4 votes |
private final void showException( GC g2d, Exception ex ) { String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; while ( ex.getCause( ) != null ) { ex = (Exception) ex.getCause( ); } String sException = ex.getClass( ).getName( ); if ( sWrappedException.equals( sException ) ) { sWrappedException = null; } String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>";//$NON-NLS-1$ } StackTraceElement[] stea = ex.getStackTrace( ); Point d = this.getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 16 );//$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( 20, 20, d.x - 40, d.y - 40 ); g2d.setClipping( 20, 20, d.x - 40, d.y - 40 ); int x = 25, y = 20 + fm.getHeight( ); g2d.drawString( "Exception:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Exception:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sException, x, y ); x = 25; y += fm.getHeight( ); if ( sWrappedException != null ) { g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( "Wrapped In:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Wrapped In:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawString( sWrappedException, x, y ); x = 25; y += fm.getHeight( ); } g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Message:", x, y );//$NON-NLS-1$ x += g2d.textExtent( "Message:" ).x + 5;//$NON-NLS-1$ g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLUE ) ); g2d.drawString( sMessage, x, y ); x = 25; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); y += 10; g2d.drawString( "Trace:", x, y );//$NON-NLS-1$ x = 40; y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_DARK_GREEN ) ); for ( int i = 0; i < stea.length; i++ ) { g2d.drawString( stea[i].getClassName( ) + ":"//$NON-NLS-1$ + stea[i].getMethodName( ) + "(...):"//$NON-NLS-1$ + stea[i].getLineNumber( ), x, y ); x = 40; y += fm.getHeight( ); } fo.dispose( ); }
Example 16
Source File: DesignerRepresentation.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Show the exception message that prevented to draw the chart * * @param g2d * @param ex * The exception that occured */ private final void showException( GC g2d, Exception ex ) { Point pTLC = new Point( 0, 0 ); // String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>"; //$NON-NLS-1$ } // StackTraceElement[] stea = ex.getStackTrace( ); Dimension d = getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 12 ); //$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); Region rgPrev = new Region( ); g2d.getClipping( rgPrev ); g2d.setClipping( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); int x = pTLC.x + 25, y = pTLC.y + 20 + fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( ERROR_MSG, x, y ); y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawText( sMessage, x, y ); g2d.setClipping( rgPrev ); rgPrev.dispose( ); fo.dispose( ); }
Example 17
Source File: NatTableCustomCellPainter.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@Override public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry){ if (paintBg) { bgPainter.paintCell(cell, gc, rectangle, configRegistry); } if (paintFg) { Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); int fontHeight = gc.getFontMetrics().getHeight(); String text = convertDataType(cell, configRegistry); // Draw Text text = getTextToDisplay(cell, gc, rectangle.width, text); int numberOfNewLines = getNumberOfNewLines(text); //if the content height is bigger than the available row height //we're extending the row height (only if word wrapping is enabled) int contentHeight = (fontHeight * numberOfNewLines) + (spacing * 2); int contentToCellDiff = (cell.getBounds().height - rectangle.height); if (performRowResize(contentHeight, rectangle)) { ILayer layer = cell.getLayer(); layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff)); } //draw every line by itself int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight); String[] lines = text.split("\n"); //$NON-NLS-1$ for (String line : lines) { int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width); drawLine(gc, yStartPos, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + spacing, line); //after every line calculate the y start pos new yStartPos += fontHeight; } gc.setClipping(originalClipping); } }
Example 18
Source File: TimeGraphControl.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
/** * Draw the markers * * @param bounds * The rectangle of the area * @param timeProvider * The time provider * @param markers * The list of markers * @param foreground * true to draw the foreground markers, false otherwise * @param nameSpace * The width reserved for the names * @param gc * Reference to the SWT GC object * @since 2.0 */ protected void drawMarkers(Rectangle bounds, ITimeDataProvider timeProvider, List<IMarkerEvent> markers, boolean foreground, int nameSpace, GC gc) { if (!fMarkersVisible || markers == null || markers.isEmpty()) { return; } gc.setClipping(new Rectangle(nameSpace, 0, bounds.width - nameSpace, bounds.height)); /* the list can grow concurrently but cannot shrink */ int size = markers.size(); for (int i = 0; i < size; i++) { IMarkerEvent marker = markers.get(i); if (marker.isForeground() == foreground) { drawMarker(marker, bounds, timeProvider, nameSpace, gc); } } gc.setClipping((Rectangle) null); TraceCompassLogUtils.traceCounter(LOGGER, Level.FINER, fDrawMarkersCountLabel, size); }
Example 19
Source File: AbstractGridGroupRenderer.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Draw a child item. Only used when useGroup is true. * * @param gc * @param index * @param selected * @param parent */ protected void drawItem(GC gc, int index, boolean selected, GalleryItem parent, int offsetY) { if (Gallery.DEBUG) System.out.println("Draw item ? " + index); //$NON-NLS-1$ if (index < parent.getItemCount()) { int hCount = ((Integer) parent.getData(H_COUNT)).intValue(); int vCount = ((Integer) parent.getData(V_COUNT)).intValue(); if (Gallery.DEBUG) System.out.println("hCount : " + hCount + " vCount : " //$NON-NLS-1$//$NON-NLS-2$ + vCount); int posX, posY; if (gallery.isVertical()) { posX = index % hCount; posY = (index - posX) / hCount; } else { posY = index % vCount; posX = (index - posY) / vCount; } Item item = parent.getItem(index); // No item ? return if (item == null) return; GalleryItem gItem = (GalleryItem) item; int xPixelPos, yPixelPos; if (gallery.isVertical()) { xPixelPos = posX * (itemWidth + margin) + margin; yPixelPos = posY * (itemHeight + minMargin) - gallery.translate /* + minMargin */ + ((parent == null) ? 0 : (parent.y) + offsetY); gItem.x = xPixelPos; gItem.y = yPixelPos + gallery.translate; } else { xPixelPos = posX * (itemWidth + minMargin) - gallery.translate /* + minMargin */ + ((parent == null) ? 0 : (parent.x) + offsetY); yPixelPos = posY * (itemHeight + margin) + margin; gItem.x = xPixelPos + gallery.translate; gItem.y = yPixelPos; } gItem.height = itemHeight; gItem.width = itemWidth; gallery.sendPaintItemEvent(item, index, gc, xPixelPos, yPixelPos, this.itemWidth, this.itemHeight); if (gallery.getItemRenderer() != null) { // gc.setClipping(xPixelPos, yPixelPos, itemWidth, itemHeight); gallery.getItemRenderer().setSelected(selected); if (Gallery.DEBUG) System.out.println("itemRender.draw"); //$NON-NLS-1$ Rectangle oldClipping = gc.getClipping(); gc.setClipping(oldClipping.intersection(new Rectangle(xPixelPos, yPixelPos, itemWidth, itemHeight))); gallery.getItemRenderer().draw(gc, gItem, index, xPixelPos, yPixelPos, itemWidth, itemHeight); gc.setClipping(oldClipping); if (Gallery.DEBUG) System.out.println("itemRender done"); //$NON-NLS-1$ } } }
Example 20
Source File: PieUtils.java From BiglyBT with GNU General Public License v2.0 | 2 votes |
public static void drawPie( GC gc,Image image, int x, int y,int width,int height,int percent, boolean draw_border ) { Rectangle image_size = image.getBounds(); int width_pad = ( width - image_size.width )/2; int height_pad = ( height - image_size.height )/2; int angle = (percent * 360) / 100; if(angle<4){ angle = 0; // workaround fillArc rendering bug } Region old_clipping = new Region(); gc.getClipping(old_clipping); Path path_done = new Path(gc.getDevice()); path_done.addArc(x,y,width,height,90,-angle); path_done.lineTo( x+width/2, y+height/2); path_done.close(); gc.setClipping( path_done ); gc.drawImage(image, x+width_pad, y+height_pad+1); Path path_undone = new Path(gc.getDevice()); path_undone.addArc(x,y,width,height,90-angle,angle-360); path_undone.lineTo( x+width/2, y+height/2); path_undone.close(); gc.setClipping( path_undone ); gc.setAlpha( 75 ); gc.drawImage(image, x+width_pad, y+height_pad+1); gc.setAlpha( 255 ); gc.setClipping( old_clipping ); if ( draw_border ){ gc.setForeground(Colors.blue); if ( percent == 100 ){ gc.drawOval(x , y , width-1, height-1); }else{ if ( angle > 0 ){ gc.drawPath( path_done ); } } } path_done.dispose(); path_undone.dispose(); old_clipping.dispose(); }