Java Code Examples for org.eclipse.swt.graphics.Path#moveTo()
The following examples show how to use
org.eclipse.swt.graphics.Path#moveTo() .
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: GraphUtils.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Paints an looping arc from scr to tgt. * <p/> * <b>Assumption:</b> The tgt is located right/below of the src. */ public static float[] arcSelf(GC gc, Point src, Point tgt) { Path path = new Path(gc.getDevice()); int diffH = 10; int diff = diffH * 3; path.moveTo((int) src.x, (int) src.y); path.cubicTo( (int) src.x + diff, (int) src.y - diffH, (int) tgt.x, (int) tgt.y - diff, (int) tgt.x, (int) tgt.y); gc.drawPath(path); float[] pp = path.getPathData().points; return pp; }
Example 2
Source File: DisplayOverlay.java From gama with GNU General Public License v3.0 | 5 votes |
void paintScale(final GC gc) { gc.setBackground(IGamaColors.BLACK.color()); final int BAR_WIDTH = 1; final int BAR_HEIGHT = 8; final int x = 0; final int y = 0; final int margin = 20; final int width = scalebar.getBounds().width - 2 * margin; final int height = scalebar.getBounds().height; final int barStartX = x + 1 + BAR_WIDTH / 2 + margin; final int barStartY = y + height - BAR_HEIGHT / 2; final Path path = new Path(WorkbenchHelper.getDisplay()); path.moveTo(barStartX, barStartY - BAR_HEIGHT + 2); path.lineTo(barStartX, barStartY + 2); path.moveTo(barStartX, barStartY - BAR_HEIGHT / 2 + 2); path.lineTo(barStartX + width, barStartY - BAR_HEIGHT / 2 + 2); path.moveTo(barStartX + width, barStartY - BAR_HEIGHT + 2); path.lineTo(barStartX + width, barStartY + 2); gc.setForeground(IGamaColors.WHITE.color()); gc.setLineStyle(SWT.LINE_SOLID); gc.setLineWidth(BAR_WIDTH); gc.drawPath(path); gc.setFont(coord.getFont()); drawStringCentered(gc, "0", barStartX, barStartY - 6, false); drawStringCentered(gc, getScaleRight(), barStartX + width, barStartY - 6, false); path.dispose(); }
Example 3
Source File: SWTGraphics2D.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 4
Source File: SWTGraphics2D.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 5
Source File: SWTGraphics2D.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 6
Source File: SWTGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 7
Source File: SWTGraphics2D.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 8
Source File: SWTGraphics2D.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 9
Source File: SWTGraphics2D.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path. */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
Example 10
Source File: GraphUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Paints an arc from src to tgt. * <p/> * <b>Assumption:</b> The tgt is located below of the src. */ public static float[] arcReversed(GC gc, Point src, Point tgt) { Path path = new Path(gc.getDevice()); int ydiff = (int) ((tgt.y - src.y) / 3); path.moveTo((int) src.x, (int) src.y); path.cubicTo((int) src.x, (int) src.y + ydiff, (int) tgt.x, (int) tgt.y - ydiff * 2, (int) tgt.x, (int) tgt.y); gc.drawPath(path); float[] pp = path.getPathData().points; return pp; }
Example 11
Source File: GraphUtils.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** Paints an arc from src to tgt using the given control point ctr. */ public static float[] arc(GC gc, Point ctr, Point src, Point tgt) { Path path = new Path(gc.getDevice()); path.moveTo((int) src.x, (int) src.y); path.quadTo((int) ctr.x, (int) ctr.y, (int) tgt.x, (int) tgt.y); gc.drawPath(path); float[] pp = path.getPathData().points; return pp; }
Example 12
Source File: StepRenderer.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override protected void performRender ( final Graphics g, final Rectangle clientRect ) { final XAxis xAxis = this.seriesData.getXAxis (); final YAxis yAxis = this.seriesData.getYAxis (); final NavigableSet<DataEntry> entries = this.seriesData.getViewData ().getEntries (); if ( entries.isEmpty () ) { return; } final Path path = g.createPath (); try { boolean first = true; final DataPoint point = new DataPoint (); Float previousX = null; Float previousY = null; logger.trace ( "Render steps" ); final long now = System.currentTimeMillis (); for ( final DataEntry entry : entries ) { final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry ); logger.trace ( "Entry - {}, hasData: {}, point: {}", new Object[] { entry, hasData, point } ); final boolean skip = this.noFuture && entry.getTimestamp () > now; if ( hasData && !skip ) { if ( first ) { first = false; path.moveTo ( point.x, point.y ); } else { if ( previousX != null && previousX + 1 == point.x ) { /* is the special case were we only advance one pixel. * so we can draw a direct line and allow the * antialiasing to kick in */ path.lineTo ( point.x, point.y ); } else { path.lineTo ( point.x, previousY ); path.lineTo ( point.x, point.y ); } } previousX = point.x; previousY = point.y; } else { first = true; if ( previousY != null ) { path.lineTo ( point.x, previousY ); previousY = null; } previousX = null; } } g.setAlpha ( 255 ); g.setLineAttributes ( this.lineAttributes ); g.setForeground ( this.lineColor ); g.setAntialias ( true ); g.setClipping ( clientRect ); g.drawPath ( path ); } finally { path.dispose (); } }
Example 13
Source File: LinearRenderer.java From neoscada with Eclipse Public License 1.0 | 4 votes |
@Override protected void performRender ( final Graphics g, final Rectangle clientRect ) { final Path path = g.createPath (); try { // eval min/max final XAxis xAxis = this.seriesData.getXAxis (); final YAxis yAxis = this.seriesData.getYAxis (); final SortedSet<DataEntry> entries = this.seriesData.getViewData ().getEntries (); if ( entries.isEmpty () ) { return; } boolean first = true; final DataPoint point = new DataPoint (); for ( final DataEntry entry : entries ) { final boolean hasData = translateToPoint ( clientRect, xAxis, yAxis, point, entry ); if ( hasData ) { if ( first ) { first = false; path.moveTo ( point.x, point.y ); } else { path.lineTo ( point.x, point.y ); } } else { first = true; } } g.setAlpha ( 255 ); g.setLineAttributes ( this.lineAttributes ); g.setForeground ( this.lineColor ); g.setClipping ( clientRect ); g.drawPath ( path ); } finally { path.dispose (); } }
Example 14
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void fillRectangle( RectangleRenderEvent rre ) throws ChartException { iv.modifyEvent( rre ); final Fill flBackground = validateMultipleFill( rre.getBackground( ) ); if ( isFullTransparent( flBackground ) ) { return; } final Bounds bo = normalizeBounds( rre.getBounds( ) ); final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ), (int) ( ( bo.getTop( ) + dTranslateY ) * dScale ), (int) Math.ceil( bo.getWidth( ) * dScale ), (int) Math.ceil( bo.getHeight( ) * dScale ) ); final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); pt.moveTo( r.x, r.y ); pt.lineTo( r.x, r.y + r.height ); pt.lineTo( r.x + r.width, r.y + r.height ); pt.lineTo( r.x + r.width, r.y ); try { if ( flBackground instanceof ColorDefinition ) { fillPathColor( pt, (ColorDefinition) flBackground ); } if ( flBackground instanceof Gradient ) { fillPathGradient( pt, (Gradient) flBackground, r ); } else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image ) { fillPathImage( pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground ); } } finally { pt.dispose( ); } }
Example 15
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void fillPolygon( PolygonRenderEvent pre ) throws ChartException { iv.modifyEvent( pre ); // DUE TO RESTRICTIVE SWT API, WE SET A CLIPPED POLYGON REGION // AND RENDER THE POLYGON BY RENDERING A CONTAINING RECTANGLE WHERE // THE RECTANGLE BOUNDS CORRESPOND TO THE POLYGON BOUNDS // NOTE: SOME INCOMPLETE PAINTING ERRORS SEEM TO EXIST FOR GRADIENT POLY // FILLS final Fill flBackground = validateMultipleFill( pre.getBackground( ) ); if ( isFullTransparent( flBackground ) ) { return; } final Bounds bo = normalizeBounds( pre.getBounds( ) ); final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ), (int) ( ( bo.getTop( ) + dTranslateY ) * dScale ), (int) Math.ceil( bo.getWidth( ) * dScale ), (int) Math.ceil( bo.getHeight( ) * dScale ) ); float[] points = convertDoubleToFloat( getDoubleCoordinatesAsInts( pre.getPoints( ), TRUNCATE, dTranslateX, dTranslateY, dScale ) ); if ( points.length < 1 ) { return; } final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); pt.moveTo( points[0], points[1] ); for ( int i = 1; i < points.length / 2; i++ ) { pt.lineTo( points[2 * i], points[2 * i + 1] ); } try { if ( flBackground instanceof ColorDefinition ) { fillPathColor( pt, (ColorDefinition) flBackground ); } else if ( flBackground instanceof Gradient ) { fillPathGradient( pt, (Gradient) flBackground, r ); } else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image ) { fillPathImage( pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground ); } } finally { pt.dispose( ); } }
Example 16
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void drawArea( AreaRenderEvent are ) throws ChartException { iv.modifyEvent( are ); // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline( ); if ( !validateLineAttributes( are.getSource( ), lia ) ) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor( lia.getColor( ), are.getBackground( ), _ids ); if ( cFG == null ) // IF UNDEFINED, EXIT { return; } // BUILD THE GENERAL PATH STRUCTURE final Path gp = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); PrimitiveRenderEvent pre; for ( int i = 0; i < are.getElementCount( ); i++ ) { pre = are.getElement( i ); if ( pre instanceof ArcRenderEvent ) { final ArcRenderEvent acre = (ArcRenderEvent) pre; gp.addArc( (float) acre.getTopLeft( ).getX( ), (float) acre.getTopLeft( ).getY( ), (float) acre.getWidth( ), (float) acre.getHeight( ), (float) acre.getStartAngle( ), (float) acre.getAngleExtent( ) ); } else if ( pre instanceof LineRenderEvent ) { final LineRenderEvent lre = (LineRenderEvent) pre; gp.moveTo( (float) lre.getStart( ).getX( ), (float) lre.getStart( ).getY( ) ); gp.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( ) .getY( ) ); } } // DRAW THE PATH final int iOldLineStyle = _gc.getLineStyle( ); final int iOldLineWidth = _gc.getLineWidth( ); int iLineStyle = SWT.LINE_SOLID; switch ( lia.getStyle( ).getValue( ) ) { case ( LineStyle.DOTTED ) : iLineStyle = SWT.LINE_DOT; break; case ( LineStyle.DASH_DOTTED ) : iLineStyle = SWT.LINE_DASHDOT; break; case ( LineStyle.DASHED ) : iLineStyle = SWT.LINE_DASH; break; } _gc.setLineStyle( iLineStyle ); _gc.setLineWidth( lia.getThickness( ) ); _gc.setForeground( cFG ); R31Enhance.setAlpha( _gc, lia.getColor( ) ); _gc.drawPath( gp ); // Restore state _gc.setLineStyle( iOldLineStyle ); _gc.setLineWidth( iOldLineWidth ); // Free resource gp.dispose( ); cFG.dispose( ); }
Example 17
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void fillArea( AreaRenderEvent are ) throws ChartException { iv.modifyEvent( are ); Fill flBackground = validateMultipleFill( are.getBackground( ) ); if ( isFullTransparent( flBackground ) ) { return; } // BUILD THE GENERAL PATH STRUCTURE final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); PrimitiveRenderEvent pre; for ( int i = 0; i < are.getElementCount( ); i++ ) { pre = are.getElement( i ); if ( pre instanceof ArcRenderEvent ) { final ArcRenderEvent acre = (ArcRenderEvent) pre; pt.addArc( (float) acre.getTopLeft( ).getX( ), (float) acre.getTopLeft( ).getY( ), (float) acre.getWidth( ), (float) acre.getHeight( ), (float) acre.getStartAngle( ), (float) acre.getAngleExtent( ) ); } else if ( pre instanceof LineRenderEvent ) { final LineRenderEvent lre = (LineRenderEvent) pre; if ( i == 0 ) { pt.moveTo( (float) lre.getStart( ).getX( ), (float) lre.getStart( ).getY( ) ); } pt.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( ) .getY( ) ); } } try { if ( flBackground instanceof ColorDefinition ) { fillPathColor( pt, (ColorDefinition) flBackground ); } else if ( flBackground instanceof Gradient ) { final Bounds bo = are.getBounds( ); final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ), (int) ( ( bo.getTop( ) + dTranslateY ) * dScale ), (int) ( bo.getWidth( ) * dScale ), (int) ( bo.getHeight( ) * dScale ) ); fillPathGradient( pt, (Gradient) flBackground, r ); } else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image ) { fillPathImage( pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground ); } } finally { pt.dispose( ); } }
Example 18
Source File: LoginDialog.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Create a default image. It is a port of the image used by the Login Box * in the project SwingX * * @param w width * @param h height * @return a default image (blue wave) */ private Image createDefaultImage(final int w, final int h) { final Display display = Display.getCurrent(); final Color backgroundColor = new Color(display, 49, 121, 242); final Color gradientColor1 = new Color(display, 155, 185, 245); final Color gradientColor2 = new Color(display, 53, 123, 242); final Image img = new Image(display, w, h); final GC gc = new GC(img); gc.setAdvanced(true); gc.setAntialias(SWT.ON); gc.setBackground(backgroundColor); gc.fillRectangle(0, 0, w, h); final Path curveShape = new Path(display); curveShape.moveTo(0, h * .6f); curveShape.cubicTo(w * .167f, h * 1.2f, w * .667f, h * -.5f, w, h * .75f); curveShape.lineTo(w, h); curveShape.lineTo(0, h); curveShape.lineTo(0, h * .8f); curveShape.close(); final Pattern pattern = new Pattern(display, 0, 0, 1, h * 1.2f, gradientColor1, gradientColor2); gc.setBackgroundPattern(pattern); gc.fillPath(curveShape); final Font font = new Font(display, "Arial Bold", 30, SWT.NONE); gc.setFont(font); gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE)); final Point textSize = gc.stringExtent(ResourceManager.getLabel(ResourceManager.LOGIN)); gc.drawString(ResourceManager.getLabel(ResourceManager.LOGIN), (int) (w * .05f), (h - textSize.y) / 2, true); font.dispose(); curveShape.dispose(); pattern.dispose(); backgroundColor.dispose(); gradientColor1.dispose(); gradientColor2.dispose(); gc.dispose(); return img; }