Example usage for java.awt.geom GeneralPath moveTo

List of usage examples for java.awt.geom GeneralPath moveTo

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath moveTo.

Prototype

public abstract void moveTo(double x, double y);

Source Link

Document

Adds a point to the path by moving to the specified coordinates specified in double precision.

Usage

From source file:CustomStrokes.java

public Shape createStrokedShape(Shape shape) {
    GeneralPath newshape = new GeneralPath(); // Start with an empty shape

    // Iterate through the specified shape, perturb its coordinates, and
    // use them to build up the new shape.
    float[] coords = new float[6];
    for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
        int type = i.currentSegment(coords);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            perturb(coords, 2);//from w w w.  j  a  v  a2s . c  o m
            newshape.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_LINETO:
            perturb(coords, 2);
            newshape.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_QUADTO:
            perturb(coords, 4);
            newshape.quadTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            perturb(coords, 6);
            newshape.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;
        case PathIterator.SEG_CLOSE:
            newshape.closePath();
            break;
        }
    }

    // Finally, stroke the perturbed shape and return the result
    return stroke.createStrokedShape(newshape);
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java

/**
 * Build the legend/*ww w.j  av a2 s  .c  o  m*/
 *
 */
protected void buildLegend() {

    LegendTitle legend = pcaChart.getLegend();
    LegendItemSource[] sources = new LegendItemSource[1];
    PcaLegendItemSource legendSrc = new PcaLegendItemSource();
    LegendItem item = null;

    //Rect=survival less than 10 months
    item = new LegendItem("Survival less than 10 months", null, null, null, new Rectangle2D.Double(0, 0, 8, 8),
            Color.BLACK);
    legendSrc.addLegendItem(item);

    //Circle=survival 10 months or more
    item = new LegendItem("Survival over 10 months", null, null, null, new Ellipse2D.Double(0, 0, 8, 8),
            Color.BLACK);
    legendSrc.addLegendItem(item);

    //Triangle if data if survival data is missing
    GeneralPath triangle = new GeneralPath();
    //     triangle.moveTo(1.0f,0.0f);
    //     triangle.moveTo(0.0f,1.0f);
    //     triangle.moveTo(1.0f,1.0f);
    triangle.moveTo(0.0f, -4.0f);
    triangle.lineTo(4.0f, 4.0f);
    triangle.lineTo(-4.0f, 4.0f);
    triangle.closePath();
    //triangle.closePath();
    item = new LegendItem("Survival Unknown", null, null, null, triangle, Color.BLACK);
    legendSrc.addLegendItem(item);

    //Diamond=survival N/A, for non_tumor/normal
    Shape r = new Rectangle2D.Double(0, 0, 8, 8);
    Shape d = ShapeUtilities.rotateShape(r, new Double(0.785398163), new Float(0), new Float(0));
    item = new LegendItem("Survival N/A", null, null, null, d, Color.BLACK);
    legendSrc.addLegendItem(item);

    if (colorBy == PCAcolorByType.Disease) {
        //go through the disease color map and add legend items
        String diseaseName = null;
        Color diseaseColor = null;
        DiseaseType[] diseases = DiseaseType.values();
        for (int i = 0; i < diseases.length; i++) {
            diseaseName = diseases[i].name();
            if (diseases[i].equals(DiseaseType.UNCLASSIFIED)) {
                continue; //remove unclassified from the legend
            }
            diseaseColor = diseases[i].getColor();
            item = new LegendItem(diseaseName, null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), diseaseColor);
            //item = new LegendItem(diseaseName, null, null, null, new Rectangle2D.Double(0,0,6,6), diseaseColor);
            legendSrc.addLegendItem(item);
        }
        //      item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.GRAY);
        //      legendSrc.addLegendItem(item);
    } else if (colorBy == PCAcolorByType.Gender) {
        String genderName = null;
        Color genderColor = null;
        GenderType[] genderTypes = GenderType.values();
        for (int i = 0; i < genderTypes.length; i++) {
            genderName = genderTypes[i].toString();
            genderColor = genderTypes[i].getColor();
            item = new LegendItem(genderName, null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), genderColor);
            legendSrc.addLegendItem(item);
        }
        //        item = new LegendItem("Male", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.BLUE);
        //        legendSrc.addLegendItem(item);
        //        item = new LegendItem("Female", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), Color.PINK);
        //        legendSrc.addLegendItem(item);
        //        item = new LegendItem("Unknown", null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f),Color.GRAY);
        //        legendSrc.addLegendItem(item);
    }

    sources[0] = legendSrc;
    legend.setSources(sources);
}

From source file:com.cburch.draw.shapes.Poly.java

private GeneralPath getPath() {
    GeneralPath p = path;
    if (p == null) {
        p = new GeneralPath();
        Handle[] hs = handles;// www .j  a  va  2  s. c o m
        if (hs.length > 0) {
            boolean first = true;
            for (Handle h : hs) {
                if (first) {
                    p.moveTo(h.getX(), h.getY());
                    first = false;
                } else {
                    p.lineTo(h.getX(), h.getY());
                }
            }
        }
        path = p;
    }
    return p;
}

From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

private static void drawArrowToDestination(final Graphics2D gfx, final Rectangle2D start,
        final Rectangle2D destination, final Stroke lineStroke, final Stroke arrowStroke,
        final float arrowSize) {

    final double startx = start.getCenterX();
    final double starty = start.getCenterY();

    final Point2D arrowPoint = Utils.findRectEdgeIntersection(destination, startx, starty);

    if (arrowPoint != null) {
        gfx.setStroke(arrowStroke);//from w  w  w .j a  va  2s.c  o m

        double angle = findLineAngle(arrowPoint.getX(), arrowPoint.getY(), startx, starty);

        final double arrowAngle = Math.PI / 12.0d;

        final double x1 = arrowSize * Math.cos(angle - arrowAngle);
        final double y1 = arrowSize * Math.sin(angle - arrowAngle);
        final double x2 = arrowSize * Math.cos(angle + arrowAngle);
        final double y2 = arrowSize * Math.sin(angle + arrowAngle);

        final double cx = (arrowSize / 2.0f) * Math.cos(angle);
        final double cy = (arrowSize / 2.0f) * Math.sin(angle);

        final GeneralPath polygon = new GeneralPath();
        polygon.moveTo(arrowPoint.getX(), arrowPoint.getY());
        polygon.lineTo(arrowPoint.getX() + x1, arrowPoint.getY() + y1);
        polygon.lineTo(arrowPoint.getX() + x2, arrowPoint.getY() + y2);
        polygon.closePath();
        gfx.fill(polygon);

        gfx.setStroke(lineStroke);
        gfx.drawLine((int) startx, (int) starty, (int) (arrowPoint.getX() + cx),
                (int) (arrowPoint.getY() + cy));
    }
}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void buildLegend() {
    LegendTitle legend = corrChart.getLegend();
    LegendItemSource[] sources = new LegendItemSource[1];
    CorrLegendItemSource legendSrc = new CorrLegendItemSource();
    LegendItem item = null;/*from   ww  w . j a v  a  2 s.co  m*/

    //Rect=survival less than 10 months

    GeneralPath downtriangle = new GeneralPath();
    downtriangle.moveTo(-4.0f, -4.0f);
    downtriangle.lineTo(4.0f, -4.0f);
    downtriangle.lineTo(0.0f, 4.0f);
    downtriangle.closePath();
    item = new LegendItem("Tumor size reduced by 30% or more (MRI)", null, null, null, downtriangle,
            Color.BLACK);
    legendSrc.addLegendItem(item);

    item = new LegendItem("Tumor size reduced less than 30% or no change (MRI)", null, null, null,
            new Ellipse2D.Double(0, 0, 8, 8), Color.BLACK);
    legendSrc.addLegendItem(item);

    GeneralPath uptriangle = new GeneralPath();
    uptriangle.moveTo(0.0f, -4.0f);
    uptriangle.lineTo(4.0f, 4.0f);
    uptriangle.lineTo(-4.0f, 4.0f);
    uptriangle.closePath();
    item = new LegendItem("Tumor size increased (MRI)", null, null, null, uptriangle, Color.BLACK);
    legendSrc.addLegendItem(item);

    item = new LegendItem("Tumor size change N/A", null, null, null, new Rectangle2D.Double(0, 0, 8, 8),
            Color.BLACK);
    legendSrc.addLegendItem(item);

    if (colorBy == ColorByType.CLINICALRESPONSE) {

        for (ClinicalResponseType cr : ClinicalResponseType.values()) {
            item = new LegendItem(cr.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), cr.getColor());
            legendSrc.addLegendItem(item);
        }

    } else if (colorBy == ColorByType.DISEASESTAGE) {

        for (ClinicalStageType ds : ClinicalStageType.values()) {
            if (!ds.name().endsWith("ALL")) {
                item = new LegendItem(ds.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ds.getColor());
                legendSrc.addLegendItem(item);
            }
        }
    } else if (colorBy == ColorByType.TIMEPOINT) {
        for (TimepointType tp : TimepointType.values()) {
            item = new LegendItem(tp.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                    new BasicStroke(3.0f), tp.getColor());
            legendSrc.addLegendItem(item);
        }
    } else if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) {
        //         for (CorrScatterColorByIHCType ihcType : CorrScatterColorByIHCType.values()) {
        //          item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0,0,6,6), new BasicStroke(3.0f), ihcType.getColor());
        //         legendSrc.addLegendItem(item);  
        //         }
        if (ihcBiomarkerType == IHCBiomarkerType.BCL2) {
            for (BCL2ihcType ihcType : BCL2ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.EGFR) {
            for (EGFRihcType ihcType : EGFRihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.FAK) {
            for (FAKihcType ihcType : FAKihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.HER2) {
            for (HER2ihcType ihcType : HER2ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.KI67) {
            for (Ki67ihcType ihcType : Ki67ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.P27) {
            for (P27ihcType ihcType : P27ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.P53) {
            for (P53ihcType ihcType : P53ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        } else if (ihcBiomarkerType == IHCBiomarkerType.CYCLIN_D1) {
            for (CCND1ihcType ihcType : CCND1ihcType.values()) {
                item = new LegendItem(ihcType.toString(), null, null, null, new Line2D.Double(0, 0, 6, 6),
                        new BasicStroke(3.0f), ihcType.getColor());
                legendSrc.addLegendItem(item);
            }
        }

    }

    sources[0] = legendSrc;
    legend.setSources(sources);

}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * Draws the visual representation for one data item.
 *
 * @param g2  the graphics output target.
 * @param state  the renderer state.//from ww w. j av a2 s  .  co m
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index
 * @author Muhammad Omer Saeed.
 */

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!drawError) {
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
        return;
    }

    switch (currentMethod) {

    case PrismErrorRenderer.ERRORBARS:

        if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) {

            synchronized (dataset) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;

                PlotOrientation orientation = plot.getOrientation();
                // draw the error bar for the y-interval
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                double y0 = it.getYValue() + it.getError();
                double y1 = it.getYValue() - it.getError();
                double x = collection.getXValue(series, item);

                RectangleEdge edge = plot.getRangeAxisEdge();
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
                double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
                double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
                Line2D line;
                Line2D cap1;
                Line2D cap2;
                double adj = this.capLength / 2.0;
                if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(xx, yy0, xx, yy1);
                    cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
                    cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
                } else { // PlotOrientation.HORIZONTAL
                    line = new Line2D.Double(yy0, xx, yy1, xx);
                    cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
                    cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
                }

                g2.setPaint(getItemPaint(series, item));

                if (this.errorStroke != null) {
                    g2.setStroke(this.errorStroke);
                } else {
                    g2.setStroke(getItemStroke(series, item));
                }
                g2.draw(line);
                g2.draw(cap1);
                g2.draw(cap2);
            }

        }

        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);

        break;

    case PrismErrorRenderer.ERRORDEVIATION:

        synchronized (dataset) {
            // do nothing if item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            // first pass draws the shading
            if (pass == 0) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                State drState = (State) state;

                double x = collection.getXValue(series, item);
                double yLow = it.getYValue() - it.getError();
                double yHigh = it.getYValue() + it.getError();

                RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
                RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

                double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
                double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    drState.lowerCoordinates.add(new double[] { yyLow, xx });
                    drState.upperCoordinates.add(new double[] { yyHigh, xx });
                } else if (orientation == PlotOrientation.VERTICAL) {
                    drState.lowerCoordinates.add(new double[] { xx, yyLow });
                    drState.upperCoordinates.add(new double[] { xx, yyHigh });
                }

                if (item == (dataset.getItemCount(series) - 1)) {
                    // last item in series, draw the lot...
                    // set up the alpha-transparency...
                    Composite originalComposite = g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha));
                    g2.setPaint(getItemPaint(series, item));
                    GeneralPath area = new GeneralPath();
                    double[] coords = (double[]) drState.lowerCoordinates.get(0);
                    area.moveTo((float) coords[0], (float) coords[1]);
                    for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                        coords = (double[]) drState.lowerCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    int count = drState.upperCoordinates.size();
                    coords = (double[]) drState.upperCoordinates.get(count - 1);
                    area.lineTo((float) coords[0], (float) coords[1]);
                    for (int i = count - 2; i >= 0; i--) {
                        coords = (double[]) drState.upperCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    area.closePath();
                    g2.fill(area);
                    g2.setComposite(originalComposite);

                    drState.lowerCoordinates.clear();
                    drState.upperCoordinates.clear();
                }
            }
            if (isLinePass(pass)) {

                // the following code handles the line for the y-values...it's
                // all done by code in the super class
                if (item == 0) {
                    State s = (State) state;
                    s.seriesPath.reset();
                    s.setLastPointGood(false);
                }

                if (getItemLineVisible(series, item)) {
                    drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis,
                            dataArea);
                }
            }

            // second pass adds shapes where the items are ..
            else if (isItemPass(pass)) {

                // setup for collecting optional entity info...
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                }

                drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis,
                        crosshairState, entities);
            }

        }

        break;
    default:
        return;
    }
}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void createGlyphsAndAddToPlot(XYPlot plot, double xScale, double yScale) {
    XYShapeAnnotation glyph;//from   w  w  w.  j a va  2 s  .  c o  m
    Shape glyphShape = null;
    Color glyphColor;

    //double glyphSize = 8.0;   //pixels

    double glyphIncrementX = (glyphSize * xScale) / 2.0;
    double glyphIncrementY = (glyphSize * yScale) / 2.0;
    float gi_x = (float) glyphIncrementX;
    float gi_y = (float) glyphIncrementY;

    PatientData pd;

    double x, y;
    Double mriPctChange = null;
    for (ISPYPlotPoint corrPoint : dataPoints) {

        x = corrPoint.getX();
        y = corrPoint.getY();

        mriPctChange = corrPoint.getMRITumorPctChange();

        if (mriPctChange == null) {
            //data is missing
            Rectangle2D.Double rect = new Rectangle2D.Double();
            //rect.setFrameFromCenter(x,y, x+1.25,y+1.25);
            rect.setFrameFromCenter(x, y, x + glyphIncrementX, y + glyphIncrementY);
            glyphShape = rect;
        } else if (mriPctChange <= -30.0) {

            //tumor shrank by more than 30% (down arrow)
            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;

            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf - gi_x, yf + gi_y);
            gp.lineTo(xf + gi_x, yf + gi_y);
            gp.closePath();
            glyphShape = gp;
        } else if (mriPctChange > 0.0) {
            //tumor size increased (up arrow)

            GeneralPath gp = new GeneralPath();
            float xf = (float) x;
            float yf = (float) y;
            //make a triangle
            gp.moveTo(xf, yf);
            gp.lineTo(xf + gi_x, yf - gi_y);
            gp.lineTo(xf - gi_x, yf - gi_y);
            gp.closePath();
            glyphShape = gp;

            //            Ellipse2D.Double circle = new Ellipse2D.Double();
            //            circle.setFrameFromCenter(x,y, x+2, y+2);

        } else if ((mriPctChange > -30.0) && (mriPctChange <= 0.0)) {
            //no change or reduction in tumor size but less than 30% reduction
            Ellipse2D.Double circle = new Ellipse2D.Double();
            //circle.setFrameFromCenter(x,y,x+1.25,y+1.25);
            circle.setFrameFromCenter(x, y, x + gi_x, y + gi_y);
            glyphShape = circle;

        }

        //glyphColor = Color.BLUE; 
        //later can set color based on 
        glyphColor = getColorForDataPoint(corrPoint);

        glyph = new XYShapeAnnotation(glyphShape, new BasicStroke(1.0f), Color.BLACK, glyphColor);

        String tooltip = corrPoint.getTag();

        glyph.setToolTipText(tooltip);
        plot.addAnnotation(glyph);
    }

}

From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java

@Override
public void resetView() {
    AttackManager.getSingleton().addManagerListener(this);
    //setup renderer and general view
    // ((DoItYourselfAttackTableModel) jAttackTable.getModel()).clear();

    HighlightPredicate.ColumnHighlightPredicate colu = new HighlightPredicate.ColumnHighlightPredicate(0, 1, 2,
            3, 6);/*from w ww  .ja  va 2  s. c o  m*/
    jAttackTable.setRowHeight(24);
    jAttackTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
    jAttackTable.setHighlighters(new CompoundHighlighter(colu,
            HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B)));
    jAttackTable.setColumnControlVisible(true);
    jAttackTable.setDefaultEditor(UnitHolder.class, new UnitCellEditor());
    jAttackTable.setDefaultEditor(Village.class, new VillageCellEditor());
    jAttackTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer());
    jAttackTable.setDefaultRenderer(Integer.class,
            new NoteIconCellRenderer(NoteIconCellRenderer.ICON_TYPE.NOTE));
    jAttackTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer());
    jAttackTable.setDefaultRenderer(Long.class, new ColoredCoutdownCellRenderer());
    jAttackTable.setDefaultEditor(Date.class, new DateSpinEditor());
    jAttackTable.setDefaultEditor(Integer.class, new NoteIconCellEditor(NoteIconCellEditor.ICON_TYPE.NOTE));
    BufferedImage back = ImageUtils.createCompatibleBufferedImage(5, 5, BufferedImage.BITMASK);
    Graphics2D g = back.createGraphics();
    GeneralPath p = new GeneralPath();
    p.moveTo(0, 0);
    p.lineTo(5, 0);
    p.lineTo(5, 5);
    p.closePath();
    g.setColor(Color.GREEN.darker());
    g.fill(p);
    g.dispose();
    jAttackTable.addHighlighter(new PainterHighlighter(HighlightPredicate.EDITABLE,
            new ImagePainter(back, HorizontalAlignment.RIGHT, VerticalAlignment.TOP)));

    DefaultComboBoxModel model = new DefaultComboBoxModel();
    DefaultComboBoxModel model2 = new DefaultComboBoxModel();
    for (UnitHolder unit : DataHolder.getSingleton().getUnits()) {
        model.addElement(unit);
        model2.addElement(unit);
    }
    jUnitBox.setModel(model);
    jUnitComboBox.setModel(model2);
    jUnitBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitComboBox.setSelectedItem(DataHolder.getSingleton().getUnitByPlainName("ram"));
    jUnitBox.setRenderer(new UnitListCellRenderer());
    jAttackTypeComboBox.setRenderer(new StandardAttackListCellRenderer());

    DefaultComboBoxModel typeModel = new DefaultComboBoxModel();

    for (ManageableType t : StandardAttackManager.getSingleton().getAllElements()) {
        StandardAttack a = (StandardAttack) t;
        typeModel.addElement(a);
    }
    jAttackTypeComboBox.setModel(typeModel);

    jUnitComboBox.setRenderer(new UnitListCellRenderer());

    jSourceVillage.setValue(new Point(500, 500));
    jTargetVillage.setValue(new Point(500, 500));
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            jSourceVillage.updateUI();
            jTargetVillage.updateUI();
        }
    });

}

From source file:com.jhlabs.awt.TextStroke.java

public Shape createStrokedShape(Shape shape) {
    FontRenderContext frc = new FontRenderContext(null, true, true);
    GlyphVector glyphVector = font.createGlyphVector(frc, text);

    GeneralPath result = new GeneralPath();
    PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
    float points[] = new float[6];
    float moveX = 0, moveY = 0;
    float lastX = 0, lastY = 0;
    float thisX = 0, thisY = 0;
    int type = 0;
    float next = 0;
    int currentChar = 0;
    int length = glyphVector.getNumGlyphs();

    if (length == 0)
        return result;

    float factor = stretchToFit ? measurePathLength(shape) / (float) glyphVector.getLogicalBounds().getWidth()
            : 1.0f;//from   w  w  w .j  av  a2 s . c om
    float height = (float) glyphVector.getLogicalBounds().getHeight();
    float nextAdvance = 0;

    while (currentChar < length && !it.isDone()) {
        type = it.currentSegment(points);
        switch (type) {
        case PathIterator.SEG_MOVETO:
            moveX = lastX = points[0];
            moveY = lastY = points[1];
            result.moveTo(moveX, moveY);
            nextAdvance = glyphVector.getGlyphMetrics(currentChar).getAdvance() * 0.5f;
            next = nextAdvance;
            break;

        case PathIterator.SEG_CLOSE:
            points[0] = moveX;
            points[1] = moveY;
            // Fall into....

        case PathIterator.SEG_LINETO:
            thisX = points[0];
            thisY = points[1];
            float dx = thisX - lastX;
            float dy = thisY - lastY;
            float distance = (float) FastMath.sqrt(dx * dx + dy * dy);
            if (distance >= next) {
                float r = 1.0f / distance;
                float angle = (float) FastMath.atan2(dy, dx);
                while (currentChar < length && distance >= next) {
                    Shape glyph = glyphVector.getGlyphOutline(currentChar);
                    Point2D p = glyphVector.getGlyphPosition(currentChar);
                    float px = (float) p.getX();
                    float py = (float) p.getY();
                    float x = lastX + next * dx * r;
                    float y = lastY + next * dy * r;
                    float advance = nextAdvance;
                    nextAdvance = currentChar < length - 1
                            ? glyphVector.getGlyphMetrics(currentChar + 1).getAdvance() * 0.5f
                            : 0;
                    t.setToTranslation(x, y);
                    t.rotate(angle);
                    t.translate(-px - advance, -py + height * factor / 2.0f);
                    result.append(t.createTransformedShape(glyph), false);
                    next += (advance + nextAdvance) * factor;
                    currentChar++;
                    if (repeat)
                        currentChar %= length;
                }
            }
            next -= distance;
            lastX = thisX;
            lastY = thisY;
            break;
        }
        it.next();
    }

    return result;
}

From source file:edu.uchc.octane.OctaneWindowControl.java

/**
 * Draw trajectory overlay on images // w  ww  .j  av a2s.  c o  m
 */
protected void drawOverlay() {
    if (!showOverlay_) {
        imp_.setOverlay(null);
        return;
    }
    GeneralPath path = new GeneralPath();
    for (int i = 0; i < dataset_.getSize(); i++) {
        Trajectory v = dataset_.getTrajectoryByIndex(i);
        if (v.marked) {
            // path.append(new Arc2D.Double(v.get(0).x-0.15,v.get(0).y,0.3,0.3,0,360,Arc2D.OPEN), false);
            path.moveTo(v.get(0).x, v.get(0).y);
            for (int j = 1; j < v.size(); j++) {
                path.lineTo(v.get(j).x, v.get(j).y);
            }
            // path.append(new Rectangle2D.Double(v.get(v.size()-1).x-0.15,v.get(v.size()-1).y-0.15,0.3,0.3), false);
        }
    }
    imp_.setOverlay(path, Color.yellow, new BasicStroke(0.1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
}