org.eclipse.swt.graphics.Region Java Examples
The following examples show how to use
org.eclipse.swt.graphics.Region.
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: TabBar.java From nebula with Eclipse Public License 2.0 | 6 votes |
Region createRoundedTopRegion(int xOffset, int yOffset, int width, int height) { Region reg = new Region(getDisplay()); reg.add(xOffset, yOffset, width, height); reg.subtract(xOffset + 0, yOffset + 0, 5, 1); reg.subtract(xOffset + 0, yOffset + 1, 3, 1); reg.subtract(xOffset + 0, yOffset + 2, 2, 1); reg.subtract(xOffset + 0, yOffset + 3, 1, 1); reg.subtract(xOffset + 0, yOffset + 4, 1, 1); reg.subtract(xOffset + width - 5, yOffset + 0, 5, 1); reg.subtract(xOffset + width - 3, yOffset + 1, 3, 1); reg.subtract(xOffset + width - 2, yOffset + 2, 2, 1); reg.subtract(xOffset + width - 1, yOffset + 3, 1, 1); reg.subtract(xOffset + width - 1, yOffset + 4, 1, 1); return reg; }
Example #2
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 #3
Source File: Sleak.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
void refreshLabel () { int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0, regions = 0; for (int i=0; i<objects.length; i++) { Object object = objects [i]; if (object instanceof Color) colors++; if (object instanceof Cursor) cursors++; if (object instanceof Font) fonts++; if (object instanceof GC) gcs++; if (object instanceof Image) images++; if (object instanceof Region) regions++; } String string = ""; //$NON-NLS-1$ if (colors != 0) string += colors + " Color(s)\n"; //$NON-NLS-1$ if (cursors != 0) string += cursors + " Cursor(s)\n"; //$NON-NLS-1$ if (fonts != 0) string += fonts + " Font(s)\n"; //$NON-NLS-1$ if (gcs != 0) string += gcs + " GC(s)\n"; //$NON-NLS-1$ if (images != 0) string += images + " Image(s)\n"; //$NON-NLS-1$ if (regions != 0) string += regions + " Region(s)\n"; //$NON-NLS-1$ if (string.length () != 0) { string = string.substring (0, string.length () - 1); } label.setText (string); }
Example #4
Source File: PopOverShell.java From swt-bling with MIT License | 6 votes |
/** * Shows the PopOverShell in a suitable location relative to the parent component. Classes extending PopOverShell will * provide the <code>Region</code> via the abstract <code>getAppropriatePopOverRegion()</code> method. */ public void show() { runBeforeShowPopOverShell(); Point popOverShellSize = getAppropriatePopOverSize(); popOverRegion = new Region(); popOverRegion.add(new Rectangle(0, 0, popOverShellSize.x, popOverShellSize.y)); Point location = getPopOverShellLocation(parentShell, poppedOverItem, popOverRegion); popOverShell.setRegion(popOverRegion); popOverShell.setSize(popOverRegion.getBounds().width, popOverRegion.getBounds().height); popOverShell.setLocation(location); popOverShell.setAlpha(FULLY_VISIBLE_ALPHA); popOverShell.setVisible(true); }
Example #5
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 6 votes |
public void setClip( ClipRenderEvent cre ) { final Location[] loa = cre.getVertices( ); if ( loa == null ) { _gc.setClipping( (Region) null ); } else { Region rgClipping = new Region( ); rgClipping.add( getCoordinatesAsInts( loa, TRUNCATE, dTranslateX, dTranslateY, dScale ) ); _gc.setClipping( rgClipping ); rgClipping.dispose( ); } }
Example #6
Source File: Sleak.java From swt-bling with MIT License | 6 votes |
void refreshLabel () { int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0, regions = 0; for (int i=0; i<objects.length; i++) { Object object = objects [i]; if (object instanceof Color) colors++; if (object instanceof Cursor) cursors++; if (object instanceof Font) fonts++; if (object instanceof GC) gcs++; if (object instanceof Image) images++; if (object instanceof Region) regions++; } String string = ""; if (colors != 0) string += colors + " Color(s)\n"; if (cursors != 0) string += cursors + " Cursor(s)\n"; if (fonts != 0) string += fonts + " Font(s)\n"; if (gcs != 0) string += gcs + " GC(s)\n"; if (images != 0) string += images + " Image(s)\n"; /* Currently regions are not counted. */ // if (regions != 0) string += regions + " Region(s)\n"; if (string.length () != 0) { string = string.substring (0, string.length () - 1); } label.setText (string); }
Example #7
Source File: RegionAction.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * RegionAction constructor taking a polygon to define the region * * @param oSource * StructureSource * @param loa * Polygon points * @param ac * Action * @param dTranslateX * X Translation to apply on polygon coordinates * @param dTranslateY * Y Translation to apply on polygon coordinates * @param dScale * Scale to apply on polygon coordinates * @param clipping * Clipping area, points outside it will be clipped */ RegionAction( StructureSource oSource, Location[] loa, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping ) { _oSource = oSource; final int[] i2a = SwtRendererImpl.getCoordinatesAsInts( loa, SwtRendererImpl.TRUNCATE, dTranslateX, dTranslateY, dScale ); Region sh = new Region( ); sh.add( i2a ); if ( clipping != null ) { sh.intersect( clipping ); } _ac = ac; this.region = sh; }
Example #8
Source File: RegionAction.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * This constructor supports shape definition via a rectangle. * * @param oSource * StructureSource * @param bo * Rectangle * @param ac * Action * @param dTranslateX * X translation to apply to rectangle * @param dTranslateY * Y translation to apply to rectangle * @param dScale * scale to apply to rectangle * @param clipping * Clipping area, points outside it will be clipped */ RegionAction( StructureSource oSource, Bounds bo, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping ) { _oSource = oSource; bo = goFactory.copyOf( bo ); bo.translate( dTranslateX, dTranslateY ); bo.scale( dScale ); Rectangle rect = new Rectangle( (int) bo.getLeft( ), (int) bo.getTop( ), (int) bo.getWidth( ), (int) bo.getHeight( ) ); Region sh = new Region( ); sh.add( rect ); if ( clipping != null ) { sh.intersect( clipping ); } _ac = ac; this.region = sh; }
Example #9
Source File: PopOverShell.java From swt-bling with MIT License | 5 votes |
private Point getPopOverLocationControlOffscreen(Rectangle displayBounds, Region popOverRegion, Point poppedOverItemLocationRelativeToDisplay, Point popOverOffscreenLocation) { Point appropriateDisplayLocation = popOverOffscreenLocation; Rectangle popOverRegionBounds = popOverRegion.getBounds(); if (!displayBounds.contains(new Point(poppedOverItemLocationRelativeToDisplay.x + popOverRegionBounds.width, 0))) { appropriateDisplayLocation.x = displayBounds.width - popOverRegionBounds.width; } if (!displayBounds.contains(new Point(0, poppedOverItemLocationRelativeToDisplay.y + popOverRegionBounds.height))) { appropriateDisplayLocation.y = displayBounds.height - popOverRegionBounds.height; } return appropriateDisplayLocation; }
Example #10
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 #11
Source File: ResourceQueryTest.java From swt-bling with MIT License | 5 votes |
@Test public void getResources_Create4Regions_CountEquals4() { Map<String, Integer> counts = ResourceQuery.getAllocatedResourceCounts(display); for (int i = 10; i < 14; i++) { Region r = new Region(display); r.add(0,0, i,i); } Assert.assertEquals(4, ResourceQuery.getAllocatedResourceCounts(display).get(Region.class.getName()).intValue()); }
Example #12
Source File: RegionAction.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * This constructor supports shape definition via an elliptical arc * * @param oSource * @param boEllipse * @param dStart * @param dExtent * @param iArcType * @param ac */ RegionAction( StructureSource oSource, Bounds boEllipse, double dStart, double dExtent, int iArcType, Action ac, double dTranslateX, double dTranslateY, double dScale, Region clipping ) { _oSource = oSource; boEllipse = goFactory.copyOf( boEllipse ); boEllipse.translate( dTranslateX, dTranslateY ); boEllipse.scale( dScale ); Shape shape = new Arc2D.Double( boEllipse.getLeft( ), boEllipse.getTop( ), boEllipse.getWidth( ), boEllipse.getHeight( ), dStart, dExtent, toSwingArcType( iArcType ) ); int[] i2a = shape2polyCoords( shape ); Region sh = new Region( ); sh.add( i2a ); if ( clipping != null ) { sh.intersect( clipping ); } _ac = ac; this.region = sh; }
Example #13
Source File: DynamicAddRemoveLineComposite.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
/** * @param parent * @param style */ public DynamicAddRemoveLineComposite(Composite parent, int style) { super(parent, style); if(getWidgetFactory() != null) { this.setBackground(ColorConstants.white); } this.setLayout(new GridLayout(2, false)); imageplus = Pics.getImage(PicsConstants.plusBlack); imagemoins = Pics.getImage(PicsConstants.remove); minusGD = GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).create(); // circle button regionForAdd = new Region(); regionForAdd.add(createCircle(13, 13, 10)); addButton = createAddButton(this); addButton.setLayoutData(GridDataFactory.swtDefaults().span(2, 1).create()) ; addButton.addSelectionListener(new SelectionAdapter() { /* * (non-Javadoc) * * @see * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse * .swt.events.SelectionEvent) */ @Override public void widgetSelected(SelectionEvent e) { addLine(null); } }); }
Example #14
Source File: RegionAction.java From birt with Eclipse Public License 1.0 | 4 votes |
private RegionAction( StructureSource source, Region region, Action ac ) { this._oSource = source; this._ac = ac; this.region = region; }
Example #15
Source File: PopOverShell.java From swt-bling with MIT License | 4 votes |
private Point getPopOverShellLocation(Shell parentShell, PoppedOverItem poppedOverItem, Region popOverRegion) { Point location; Rectangle displayBounds = null; try { Display display = displaySafe.getLatestDisplay(); displayBounds = display.getBounds(); } catch (DisplaySafe.NullDisplayException nde) { LOG.warning("Could not find display"); } Rectangle popOverBounds = popOverRegion.getBounds(); Point poppedOverItemLocationRelativeToDisplay = getPoppedOverItemRelativeLocation(poppedOverItem); // Guess on the location first location = getPopOverDisplayPoint(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay, popOverEdgeCenteredOnParent, popOverAboveOrBelowParent); // Adjust as needed if (popOverAboveOrBelowParent == VerticalLocation.BELOW) { if (isBottomCutOff(displayBounds, location, popOverBounds)) { popOverAboveOrBelowParent = VerticalLocation.ABOVE; location.y = getPopOverYLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay, popOverAboveOrBelowParent); } } else { if (isTopCutOff(location)) { popOverAboveOrBelowParent = VerticalLocation.BELOW; location.y = getPopOverYLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay, popOverAboveOrBelowParent); } } if (popOverEdgeCenteredOnParent == CenteringEdge.LEFT) { if (isRightCutOff(displayBounds, location, popOverBounds)) { popOverEdgeCenteredOnParent = CenteringEdge.RIGHT; location.x = getPopOverXLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay, popOverEdgeCenteredOnParent); } } else { if (isLeftCutOff(location)) { popOverEdgeCenteredOnParent = CenteringEdge.LEFT; location.x = getPopOverXLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay, popOverEdgeCenteredOnParent); } } if (isStillOffScreen(displayBounds, location, popOverBounds)) { location = getPopOverLocationControlOffscreen(displayBounds, popOverRegion, poppedOverItemLocationRelativeToDisplay, location); } return location; }
Example #16
Source File: Sleak.java From pentaho-kettle with Apache License 2.0 | 4 votes |
void refreshLabel() { int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0; int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0; for ( int i = 0; i < objects.length; i++ ) { Object object = objects[i]; if ( object instanceof Color ) { colors++; } if ( object instanceof Cursor ) { cursors++; } if ( object instanceof Font ) { fonts++; } if ( object instanceof GC ) { gcs++; } if ( object instanceof Image ) { images++; } if ( object instanceof Path ) { paths++; } if ( object instanceof Pattern ) { patterns++; } if ( object instanceof Region ) { regions++; } if ( object instanceof TextLayout ) { textLayouts++; } if ( object instanceof Transform ) { transforms++; } } String string = ""; if ( colors != 0 ) { string += colors + " Color(s)\n"; } if ( cursors != 0 ) { string += cursors + " Cursor(s)\n"; } if ( fonts != 0 ) { string += fonts + " Font(s)\n"; } if ( gcs != 0 ) { string += gcs + " GC(s)\n"; } if ( images != 0 ) { string += images + " Image(s)\n"; } if ( paths != 0 ) { string += paths + " Paths(s)\n"; } if ( patterns != 0 ) { string += patterns + " Pattern(s)\n"; } if ( regions != 0 ) { string += regions + " Region(s)\n"; } if ( textLayouts != 0 ) { string += textLayouts + " TextLayout(s)\n"; } if ( transforms != 0 ) { string += transforms + " Transform(s)\n"; } if ( string.length() != 0 ) { string = string.substring( 0, string.length() - 1 ); } label.setText( string ); }
Example #17
Source File: Sleak.java From hop with Apache License 2.0 | 4 votes |
void refreshLabel() { int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0; int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0; for ( int i = 0; i < objects.length; i++ ) { Object object = objects[ i ]; if ( object instanceof Color ) { colors++; } if ( object instanceof Cursor ) { cursors++; } if ( object instanceof Font ) { fonts++; } if ( object instanceof GC ) { gcs++; } if ( object instanceof Image ) { images++; } if ( object instanceof Path ) { paths++; } if ( object instanceof Pattern ) { patterns++; } if ( object instanceof Region ) { regions++; } if ( object instanceof TextLayout ) { textLayouts++; } if ( object instanceof Transform ) { transforms++; } } String string = ""; if ( colors != 0 ) { string += colors + " Color(s)\n"; } if ( cursors != 0 ) { string += cursors + " Cursor(s)\n"; } if ( fonts != 0 ) { string += fonts + " Font(s)\n"; } if ( gcs != 0 ) { string += gcs + " GC(s)\n"; } if ( images != 0 ) { string += images + " Image(s)\n"; } if ( paths != 0 ) { string += paths + " Paths(s)\n"; } if ( patterns != 0 ) { string += patterns + " Pattern(s)\n"; } if ( regions != 0 ) { string += regions + " Region(s)\n"; } if ( textLayouts != 0 ) { string += textLayouts + " TextLayout(s)\n"; } if ( transforms != 0 ) { string += transforms + " Transform(s)\n"; } if ( string.length() != 0 ) { string = string.substring( 0, string.length() - 1 ); } label.setText( string ); }
Example #18
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public final void setProperty( final String sProperty, final Object oValue ) { if ( sProperty.equals( IDeviceRenderer.UPDATE_NOTIFIER ) ) { _iun = (IUpdateNotifier) oValue; iv.reset( ); iv.setUpdateNotifier( _iun ); cleanUpTriggers( ); Object obj = _iun.peerInstance( ); if ( obj instanceof Composite ) { Composite jc = (Composite) obj; if ( _eh != null ) { // We can't promise to remove all the old swtEventHandler // due to SWT limitation here, so be sure to just attach the // update_notifier only to one renderer. jc.removeMouseListener( _eh ); jc.removeMouseMoveListener( _eh ); jc.removeMouseTrackListener( _eh ); jc.removeKeyListener( _eh ); jc.removeFocusListener( _eh ); _eh.dispose( ); } _eh = new SwtEventHandler( iv, _lhmAllTriggers, _iun, getULocale( ) ); jc.addMouseListener( _eh ); jc.addMouseMoveListener( _eh ); jc.addMouseTrackListener( _eh ); jc.addKeyListener( _eh ); jc.addFocusListener( _eh ); } } else if ( sProperty.equals( IDeviceRenderer.GRAPHICS_CONTEXT ) ) { _gc = (GC) oValue; if ( R31Enhance.isR31Available( ) ) { Region rg = new Region( ); _gc.getClipping( rg ); R31Enhance.setAdvanced( _gc, true, rg ); R31Enhance.setAntialias( _gc, SWT.ON ); R31Enhance.setTextAntialias( _gc, SWT.ON ); rg.dispose( ); } _ids.setGraphicsContext(_gc ); logger.log( ILogger.INFORMATION, Messages.getString( "SwtRendererImpl.info.graphics.context",//$NON-NLS-1$ new Object[]{ _gc.getClass( ).getName( ), _gc }, getULocale( ) ) ); } else if ( sProperty.equals( IDeviceRenderer.DPI_RESOLUTION ) ) { getDisplayServer( ).setDpiResolution( ( (Integer) oValue ).intValue( ) ); } else if ( sProperty.equals( IDeviceRenderer.EXPECTED_BOUNDS ) ) { Bounds bo = (Bounds)oValue; int x = (int)Math.round( bo.getLeft( ) ); int y = (int)Math.round( bo.getTop( ) ); int width = (int)Math.round( bo.getWidth( ) ); int height = (int)Math.round( bo.getHeight( ) ); this._gc.setClipping( x, y, width, height ); } }
Example #19
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 #20
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 #21
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(); }