Java 类org.eclipse.swt.graphics.Path 实例源码

项目:n4js    文件:GraphUtils.java   
/**
 * 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;
}
项目:neoscada    文件:Draw2DGraphics.java   
@Override
public void setClipping ( final Rectangle rect )
{
    if ( rect == null )
    {
        /*
         * As it seems the only way to reset clipping is to set it to null using the Path variant of setClip.
         * Since the rectangle version requires an object instance.
         */
        this.g.setClip ( (Path)null );
    }
    else
    {
        this.g.setClip ( new org.eclipse.draw2d.geometry.Rectangle ( rect.x, rect.y, rect.width, rect.height ) );
    }
}
项目:PhET    文件:SWTGraphics2D.java   
/**
 * Decreases the number of uses of this graphics 2d object.
 */
public static void decrementGCCount() {
    CACHE_COUNT--;

    if (CACHE_COUNT == 0) {
        for (final Iterator i = FONT_CACHE.values().iterator(); i.hasNext();) {
            final org.eclipse.swt.graphics.Font font = (org.eclipse.swt.graphics.Font) i.next();
            font.dispose();
        }
        for (final Iterator i = COLOR_CACHE.values().iterator(); i.hasNext();) {
            final org.eclipse.swt.graphics.Color color = (org.eclipse.swt.graphics.Color) i.next();
            color.dispose();
        }
        for (final Iterator i = SHAPE_CACHE.values().iterator(); i.hasNext();) {
            final Path path = (Path) i.next();
            path.dispose();
        }
    }
}
项目:SMVHunter    文件:TreeView.java   
public static Image paintToImage(DrawableViewNode tree) {
    Image image =
            new Image(Display.getDefault(), (int) Math.ceil(tree.bounds.width), (int) Math
                    .ceil(tree.bounds.height));

    Transform transform = new Transform(Display.getDefault());
    transform.identity();
    transform.translate((float) -tree.bounds.x, (float) -tree.bounds.y);
    Path connectionPath = new Path(Display.getDefault());
    GC gc = new GC(image);

    // Can't use Display.getDefault().getSystemColor in a non-UI thread.
    Color white = new Color(Display.getDefault(), 255, 255, 255);
    Color black = new Color(Display.getDefault(), 0, 0, 0);
    gc.setForeground(white);
    gc.setBackground(black);
    gc.fillRectangle(0, 0, image.getBounds().width, image.getBounds().height);
    gc.setTransform(transform);
    paintRecursive(gc, transform, tree, null, connectionPath);
    gc.drawPath(connectionPath);
    gc.dispose();
    connectionPath.dispose();
    white.dispose();
    black.dispose();
    return image;
}
项目:piccolo2d.java    文件:SWTGraphics2D.java   
/**
 * Decreases the number of uses of this graphics 2d object.
 */
public static void decrementGCCount() {
    CACHE_COUNT--;

    if (CACHE_COUNT == 0) {
        for (final Iterator i = FONT_CACHE.values().iterator(); i.hasNext();) {
            final org.eclipse.swt.graphics.Font font = (org.eclipse.swt.graphics.Font) i.next();
            font.dispose();
        }
        FONT_CACHE.clear();
        for (final Iterator i = COLOR_CACHE.values().iterator(); i.hasNext();) {
            final org.eclipse.swt.graphics.Color color = (org.eclipse.swt.graphics.Color) i.next();
            color.dispose();
        }
        COLOR_CACHE.clear();
        for (final Iterator i = SHAPE_CACHE.values().iterator(); i.hasNext();) {
            final Path path = (Path) i.next();
            path.dispose();
        }
        SHAPE_CACHE.clear();
    }
}
项目:gama    文件:FlatButton.java   
private void drawBackground(final GC gc, final Rectangle rect) {
    setBackground(getParent().getBackground());

    final GamaUIColor color = GamaColors.get(colorCode);
    final Color background = hovered ? color.lighter() : color.color();
    final Color foreground = GamaColors.getTextColorForBackground(background).color();
    gc.setForeground(foreground);
    gc.setBackground(background);

    if (down) {
        gc.fillRoundRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2, 5, 5);
    } else {
        final Path path = createClipping(rect);
        gc.setClipping(path);
        gc.fillRectangle(rect);
        gc.setClipping((Rectangle) null);
        path.dispose();
    }

}
项目:tesb-studio-se    文件:SearchControl.java   
@Override
    public void paintControl(PaintEvent e) {
        GC gc = e.gc;
        gc.setAntialias(SWT.ON);
        Rectangle bounds = getBounds();
        Path path = new Path(getDisplay());
        path.addArc(bounds.x, bounds.y, arcSize, arcSize, 90, 180);
//      path.addRectangle(bounds.x + arcSize / 2, bounds.y, bounds.width - arcSize,
//              arcSize);
        path.addArc(bounds.x + bounds.width - arcSize, bounds.y, arcSize, arcSize,
                270, 180);
//      gc.setClipping(path);
        Color b = gc.getBackground();
        gc.setBackground(backgroundColor);
        gc.fillPath(path);
        path.dispose();
        gc.setAntialias(SWT.OFF);
        gc.setBackground(b);
    }
项目:gef-gwt    文件:SWTGraphics.java   
/**
 * Simple implementation of clipping a Path within the context of current
 * clipping rectangle for now (not region) <li>Note that this method wipes
 * out the clipping rectangle area, hence if clients need to reset it call
 * {@link #restoreState()}
 * 
 * @see org.eclipse.draw2d.Graphics#clipPath(org.eclipse.swt.graphics.Path)
 */
public void clipPath(Path path) {
    initTransform(false);
    if (((appliedState.graphicHints ^ currentState.graphicHints) & FILL_RULE_MASK) != 0) {
        // If there is a pending change to the fill rule, apply it first.
        gc.setFillRule(((currentState.graphicHints & FILL_RULE_MASK) >> FILL_RULE_SHIFT)
                - FILL_RULE_WHOLE_NUMBER);
        // As long as the FILL_RULE is stored in a single bit, just toggling
        // it works.
        appliedState.graphicHints ^= FILL_RULE_MASK;
    }
    Rectangle clipping = currentState.relativeClip != null ? getClip(new Rectangle())
            : new Rectangle();
    if (!clipping.isEmpty()) {
        Path flatPath = new Path(path.getDevice(), path, 0.01f);
        PathData pathData = flatPath.getPathData();
        flatPath.dispose();
        Region region = new Region(path.getDevice());
        loadPath(region, pathData.points, pathData.types);
        region.intersect(new org.eclipse.swt.graphics.Rectangle(clipping.x,
                clipping.y, clipping.width, clipping.height));
        gc.setClipping(region);
        appliedState.relativeClip = currentState.relativeClip = null;
        region.dispose();
    }
}
项目:birt    文件:SwtRendererImpl.java   
private final void fillPathColor( Path path, ColorDefinition g )
        throws ChartException
{
    // skip full transparency for optimization.
    if ( !( g.isSetTransparency( ) && g.getTransparency( ) == 0 ) )
    {
        final Color cBG = (Color) _ids.getColor( g );
        final Color cPreviousBG = _gc.getBackground( );
        _gc.setBackground( cBG );

        R31Enhance.setAlpha( _gc, g );

        _gc.fillPath( path );

        cBG.dispose( );
        _gc.setBackground( cPreviousBG );
    }
}
项目:n4js    文件:GraphUtils.java   
/** 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;
}
项目:n4js    文件:GraphUtils.java   
/**
 * 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;
}
项目:parabuild-ci    文件:SWTGraphics2D.java   
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 * 
 * @param shape  the shape.
 * 
 * @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;
}
项目:parabuild-ci    文件:SWTGraphics2D.java   
/** fill an arbitrary shape on the swt graphic composite 
 * with the current stroke and paint.
 * note that for consistency with the awt method, it is needed 
 * to switch temporarily the foreground and background colors.
 * @see java.awt.Graphics2D#fill(java.awt.Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
项目:parabuild-ci    文件:SWTGraphics2D.java   
public void setClip(Shape clip) {
    if (clip == null) 
        return;
    Path clipPath = toSwtPath(clip);
    gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:ccu-historian    文件:SWTGraphics2D.java   
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:ccu-historian    文件:SWTGraphics2D.java   
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
项目:ccu-historian    文件:SWTGraphics2D.java   
/**
 * 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;
}
项目:PhET    文件:SWTGraphics2D.java   
/**
 * Converts a java 2d path iterator to a SWT path.
 * 
 * @param iter specifies the iterator to be converted.
 * @return the corresponding path object. Must be disposed() when no longer
 *         used.
 */
private Path pathIterator2Path(final PathIterator iter) {
    final float[] coords = new float[6];

    final Path path = new Path(device);

    while (!iter.isDone()) {
        final int type = iter.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_CLOSE:
                path.close();
                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;
            default:
                // log this?
        }

        iter.next();
    }
    return path;
}
项目:aya-lang    文件:SWTGraphics2D.java   
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:aya-lang    文件:SWTGraphics2D.java   
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
项目:aya-lang    文件:SWTGraphics2D.java   
/**
 * 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;
}
项目:ForgedUI-Eclipse    文件:ScrollableViewFigureAndroid.java   
protected void paintLeftArrow(Graphics graphics){
    int width = pagingControlHeight / 4;
    Rectangle r = getBounds().getCopy();
    Point start = new Point(r.getRight().x - 10, r.getCenter().y);
    Path triangle = new Path(null);
    triangle.moveTo(start.x, start.y);
    triangle.lineTo(start.x - width, start.y - pagingControlHeight/2);
    triangle.lineTo(start.x - width, start.y + pagingControlHeight/2);
    graphics.fillPath(triangle);
}
项目:ForgedUI-Eclipse    文件:ScrollableViewFigureAndroid.java   
protected void paintRightArrow(Graphics graphics){
    int width = pagingControlHeight / 4;
    Rectangle r = getBounds().getCopy();
    Point start = new Point(r.x + 10, r.getCenter().y);
    Path triangle = new Path(null);
    triangle.moveTo(start.x, start.y);
    triangle.lineTo(start.x + width, start.y - pagingControlHeight/2);
    triangle.lineTo(start.x + width, start.y + pagingControlHeight/2);
    graphics.fillPath(triangle);
}
项目:ForgedUI-Eclipse    文件:Drawer.java   
public static Path getTopRoundedRectangle(PrecisionRectangle tempRect, float radius,boolean drawLeftSide,boolean drawRightSide){
    if (radius <= 0) return getRoundedRectangle(tempRect, radius,drawLeftSide,drawRightSide);
    float width = radius * 2;
    float dy = radius - tempRect.height;
    float dx = radius - (float) Math.sqrt(radius*radius - dy*dy);
    float alpha =  dy > 0 ? (float)(Math.acos(dy/radius)*180/Math.PI) : 90;
    Path p = new Path(null);
    float x = (float) tempRect.preciseX;
    float y = (float) tempRect.preciseY;
    float right = (float) tempRect.preciseRight();
    float bottom = (float) tempRect.preciseBottom();

    if (dy < 0){
        p.moveTo(x, y + radius);
    } else {
        p.moveTo(x + dx, y - dy);
    }
    p.addArc(x, y, width, width, 90 + alpha, -alpha);
    p.addArc(right-width, y, width, width, 90, -alpha);

    if (dy < 0){
        p.lineTo(right, bottom);//rightBottom
        p.lineTo(x, bottom);//leftBottom
    }

    return p;
}
项目:ForgedUI-Eclipse    文件:Drawer.java   
public static Path getBottomRoundedRectangle(PrecisionRectangle tempRect, float radius,boolean drawLeftSide,boolean drawRightSide){
    if (radius <= 0) return getRoundedRectangle(tempRect, radius,drawLeftSide,drawRightSide);
    float width = radius * 2;
    float dy = radius - tempRect.height;
    float dx = radius - (float) Math.sqrt(radius*radius - dy*dy);
    float alpha =  dy > 0 ? (float)(Math.acos(dy/radius)*180/Math.PI) : 90;
    Path p = new Path(null);
    float x = (float) tempRect.preciseX;
    float y = (float) tempRect.preciseY;
    float right = (float) tempRect.preciseRight();
    float bottom = (float) tempRect.preciseBottom();

    if (dy < 0){
        p.moveTo(x, bottom - radius);
    } else {
        p.moveTo(x + dx, y);
    }
    p.addArc(x, bottom - 2*radius, width, width, 270 - alpha, alpha);
    p.addArc(right-width, bottom - 2*radius, width, width, 270, alpha);

    if (dy < 0){
        p.lineTo(right, y);//rightTop
        p.lineTo(x, y);//leftTop
    }

    return p;
}
项目:ForgedUI-Eclipse    文件:PickerFigure.java   
protected void paintButton(Graphics graphics) {
    graphics.setBackgroundColor(ColorConstants.black);
    Rectangle bounds = getBounds().getCopy();
    Path path = new Path(null);
    path.moveTo(bounds.right() - BUTTON_SIZE.width / 2,
            bounds.getCenter().y - BUTTON_SIZE.height / 2);
    path.lineTo(bounds.right()- 3*BUTTON_SIZE.width / 2,
            bounds.getCenter().y - BUTTON_SIZE.height / 2);
    path.lineTo(bounds.right() - BUTTON_SIZE.width,
            bounds.getCenter().y + BUTTON_SIZE.height / 2);
    graphics.fillPath(path);
}
项目:ForgedUI-Eclipse    文件:TableViewFigure.java   
@Override
protected void paintFigure(Graphics graphics) {
    super.paintFigure(graphics);
    Rectangle bounds = getBounds();
    graphics.setBackgroundColor(headerColor);
    float bw =  getBorder().getBorderWidth();
    if (hasHeader()){
        PrecisionRectangle top = new PrecisionRectangle();
        top.setX(bounds.x + bw);
        top.setY(bounds.y + bw);
        top.setWidth(bounds.width - 2*bw);
        top.setHeight(getTitleHeight());
        //Path topPath = Drawer.getPartlyRoundedRectangle(top, getBorder().getBorderRadius() - bw, true, true, false, false);
        Path topPath = Drawer.getTopRoundedRectangle(top, getBorder().getActualBorderRadius(getBounds()) - bw);
        graphics.fillPath(topPath);
    }
    if (footerTitle != null || hasFooterView){
        PrecisionRectangle bottom = new PrecisionRectangle();
        bottom.setX(bounds.x + bw);
        bottom.setY(bounds.bottom() - bw - getTitleHeight());
        bottom.setWidth(bounds.width - 2*bw);
        bottom.setHeight(getTitleHeight());
        //Path bottomPath = Drawer.getPartlyRoundedRectangle(bottom, getBorder().getBorderRadius() - bw, false, false, true, true);
        Path bottomPath = Drawer.getBottomRoundedRectangle(bottom, getBorder().getActualBorderRadius(getBounds()) - bw);
        graphics.fillPath(bottomPath);
    }
    graphics.restoreState();
    this.paintString(graphics, headerTitle, true);
    this.paintString(graphics, footerTitle, false);
}
项目:statecharts    文件:ExitFigure.java   
@Override
public void paint(Graphics graphics) {
    graphics.pushState();
    graphics.setForegroundColor(getForegroundColor());
    graphics.setBackgroundColor(getBackgroundColor());
    super.paint(graphics);
    Path path = new Path(Display.getDefault());
    path.addArc(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height - 1, 0, 360);
    graphics.setClip(path);
    graphics.setLineWidth(2);
    graphics.drawLine(bounds.getTopLeft(), bounds.getBottomRight());
    graphics.drawLine(bounds.getTopRight(), bounds.getBottomLeft());
    path.dispose();
    graphics.popState();
}
项目:SMVHunter    文件:TreeViewOverview.java   
@Override
public void paintControl(PaintEvent e) {
    synchronized (TreeViewOverview.this) {
        if (mTree != null) {
            e.gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
            e.gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
            e.gc.fillRectangle(0, 0, getBounds().width, getBounds().height);
            e.gc.setTransform(mTransform);
            e.gc.setLineWidth((int) Math.ceil(0.7 / mScale));
            Path connectionPath = new Path(Display.getDefault());
            paintRecursive(e.gc, mTree, connectionPath);
            e.gc.drawPath(connectionPath);
            connectionPath.dispose();

            if (mViewport != null) {
                e.gc.setAlpha(50);
                e.gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
                e.gc.fillRectangle((int) mViewport.x, (int) mViewport.y, (int) Math
                        .ceil(mViewport.width), (int) Math.ceil(mViewport.height));

                e.gc.setAlpha(255);
                e.gc
                        .setForeground(Display.getDefault().getSystemColor(
                                SWT.COLOR_DARK_GRAY));
                e.gc.setLineWidth((int) Math.ceil(2 / mScale));
                e.gc.drawRectangle((int) mViewport.x, (int) mViewport.y, (int) Math
                        .ceil(mViewport.width), (int) Math.ceil(mViewport.height));
            }
        }
    }
}
项目:SMVHunter    文件:TreeViewOverview.java   
private void paintRecursive(GC gc, DrawableViewNode node, Path connectionPath) {
    if (mSelectedNode == node && node.viewNode.filtered) {
        gc.drawImage(sFilteredSelectedImage, node.left, (int) Math.round(node.top));
    } else if (mSelectedNode == node) {
        gc.drawImage(sSelectedImage, node.left, (int) Math.round(node.top));
    } else if (node.viewNode.filtered) {
        gc.drawImage(sFilteredImage, node.left, (int) Math.round(node.top));
    } else {
        gc.drawImage(sNotSelectedImage, node.left, (int) Math.round(node.top));
    }
    int N = node.children.size();
    if (N == 0) {
        return;
    }
    float childSpacing =
            (1.0f * (DrawableViewNode.NODE_HEIGHT - 2 * TreeView.LINE_PADDING)) / N;
    for (int i = 0; i < N; i++) {
        DrawableViewNode child = node.children.get(i);
        paintRecursive(gc, child, connectionPath);
        float x1 = node.left + DrawableViewNode.NODE_WIDTH;
        float y1 =
                (float) node.top + TreeView.LINE_PADDING + childSpacing * i + childSpacing / 2;
        float x2 = child.left;
        float y2 = (float) child.top + DrawableViewNode.NODE_HEIGHT / 2.0f;
        float cx1 = x1 + TreeView.BEZIER_FRACTION * DrawableViewNode.PARENT_CHILD_SPACING;
        float cy1 = y1;
        float cx2 = x2 - TreeView.BEZIER_FRACTION * DrawableViewNode.PARENT_CHILD_SPACING;
        float cy2 = y2;
        connectionPath.moveTo(x1, y1);
        connectionPath.cubicTo(cx1, cy1, cx2, cy2, x2, y2);
    }
}
项目:piccolo2d.java    文件:SWTGraphics2D.java   
/**
 * Converts a java 2d path iterator to a SWT path.
 * 
 * @param iter specifies the iterator to be converted.
 * @return the corresponding path object. Must be disposed() when no longer
 *         used.
 */
private Path pathIterator2Path(final PathIterator iter) {
    final float[] coords = new float[6];

    final Path path = new Path(device);

    while (!iter.isDone()) {
        final int type = iter.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_CLOSE:
                path.close();
                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;
            default:
                // log this?
        }

        iter.next();
    }
    return path;
}
项目:gama    文件:DisplayOverlay.java   
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();
}
项目:nabs    文件:SWTGraphics2D.java   
/**
 * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>.
 * 
 * @param shape  the shape.
 * 
 * @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;
}
项目:nabs    文件:SWTGraphics2D.java   
/** fill an arbitrary shape on the swt graphic composite 
 * with the current stroke and paint.
 * note that for consistency with the awt method, it is needed 
 * to switch temporarily the foreground and background colors.
 * @see java.awt.Graphics2D#fill(java.awt.Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
项目:nabs    文件:SWTGraphics2D.java   
public void setClip(Shape clip) {
    if (clip == null) 
        return;
    Path clipPath = toSwtPath(clip);
    gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:ECG-Viewer    文件:SWTGraphics2D.java   
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:ECG-Viewer    文件:SWTGraphics2D.java   
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}
项目:ECG-Viewer    文件:SWTGraphics2D.java   
/**
 * 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;
}
项目:astor    文件:SWTGraphics2D.java   
/**
 * Sets the clip region.
 *
 * @param clip  the clip.
 */
public void setClip(Shape clip) {
    if (clip == null) {
        return;
    }
    Path clipPath = toSwtPath(clip);
    this.gc.setClipping(clipPath);
    clipPath.dispose();
}
项目:astor    文件:SWTGraphics2D.java   
/**
 * Fills the specified shape using the current paint.
 *
 * @param shape  the shape (<code>null</code> not permitted).
 *
 * @see #getPaint()
 * @see #draw(Shape)
 */
public void fill(Shape shape) {
    Path path = toSwtPath(shape);
    // Note that for consistency with the AWT implementation, it is
    // necessary to switch temporarily the foreground and background
    // colours
    switchColors();
    this.gc.fillPath(path);
    switchColors();
    path.dispose();
}