Example usage for java.awt.geom Rectangle2D getWidth

List of usage examples for java.awt.geom Rectangle2D getWidth

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getWidth.

Prototype

public abstract double getWidth();

Source Link

Document

Returns the width of the framing rectangle in double precision.

Usage

From source file:extern.NpairsBoxAndWhiskerRenderer.java

/**
 * Draws the visual representation of a single data item when the plot has
 * a vertical orientation.//from   w w w  .ja  v a  2  s.c om
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset (must be an instance of
 *                 {@link BoxAndWhiskerCategoryDataset}).
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {

    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;

    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    double widthToUse = Math.min(state.getBarWidth(), dataArea.getWidth() / 15);

    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (widthToUse * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        xx = xx + offset + (row * (widthToUse + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than the
        // category width
        double offset = (categoryWidth - widthToUse) / 2;
        xx = xx + offset;
    }

    double yyAverage = 0.0;
    double yyOutlier;

    Paint itemPaint = getItemPaint(row, column);
    g2.setPaint(itemPaint);
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    double aRadius = 0; // average radius

    RectangleEdge location = plot.getRangeAxisEdge();

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);
    Shape box = null;

    double xxmid = xx + widthToUse / 2.0;

    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {

        double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
        double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
        double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
        double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);

        // draw the upper shadow...
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xx, yyMax, xx + widthToUse, yyMax));

        // draw the lower shadow...
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xx, yyMin, xx + widthToUse, yyMin));

        // draw the body...
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), widthToUse, Math.abs(yyQ1 - yyQ3));
        if (this.fillBox) {
            g2.fill(box);
        }
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(box);
    }

    g2.setPaint(this.artifactPaint);

    // draw mean - SPECIAL AIMS REQUIREMENT...
    Number yMean = bawDataset.getMeanValue(row, column);

    if (yMean != null && !Double.isNaN(yMean.doubleValue())) {
        yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
        // THIS IS WHAT WE CHANGED
        //            aRadius = widthWeWannaUse / 4;
        aRadius = 4;
        // here we check that the average marker will in fact be visible
        // before drawing it...
        // WE HAD TO CHANGE THIS TOO I DON'T KNOW WHAT THEY WERE DOING
        if ((yyAverage > (dataArea.getMinY() - aRadius)) && (yyAverage < (dataArea.getMaxY() + aRadius))) {
            Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxmid - aRadius, yyAverage - aRadius,
                    aRadius * 2, aRadius * 2);

            g2.fill(avgEllipse);
            g2.draw(avgEllipse);
        }
    }

    // draw median...
    Number yMedian = bawDataset.getMedianValue(row, column);
    if (yMedian != null && !Double.isNaN(yMedian.doubleValue())) {
        double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
        g2.draw(new Line2D.Double(xx, yyMedian, xx + widthToUse, yyMedian));

        // add a line to connect the means of the boxes
        if (prevX != -1.0 && prevY != -1.0) {
            g2.draw(new Line2D.Double(prevX, prevY, xxmid, yyMedian));
        }

        prevX = xxmid;
        prevY = yyMedian;
    }

    // draw yOutliers...
    g2.setPaint(itemPaint);

    // draw outliers
    double oRadius = 4; // outlier radius
    List<Outlier> outliers = new ArrayList<Outlier>();

    // From outlier array sort out which are outliers and put these into a
    // list If there are any farouts, set the flag on the
    // OutlierListCollection
    List<Number> yOutliers = bawDataset.getOutliers(row, column);
    if (yOutliers != null) {
        for (int i = 0; i < yOutliers.size(); i++) {
            double outlier = yOutliers.get(i).doubleValue();

            yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
            outliers.add(new Outlier(xxmid, yyOutlier, oRadius));
        }

        // Process outliers. Each outlier is either added to the
        // appropriate outlier list or a new outlier list is made
        for (Outlier outlier : outliers) {
            Point2D point = outlier.getPoint();

            drawEllipse(point, oRadius, g2);
        }

        //            for (Iterator iterator = outlierListCollection.iterator();
        //                     iterator.hasNext();) {
        //                OutlierList list = (OutlierList) iterator.next();
        //                Outlier outlier = list.getAveragedOutlier();
        //                Point2D point = outlier.getPoint();
        //
        //                if (list.isMultiple()) {
        //                    drawMultipleEllipse(point, widthWeWannaUse, oRadius,
        //                            g2);
        //                }
        //                else {
        //                    drawEllipse(point, oRadius, g2);
        //                }
        //            }
        //
        //            // draw farout indicators
        //            if (outlierListCollection.isHighFarOut()) {
        //                drawHighFarOut(aRadius / 2.0, g2,
        //                        xx + widthWeWannaUse / 2.0, maxAxisValue);
        //            }
        //
        //            if (outlierListCollection.isLowFarOut()) {
        //                drawLowFarOut(aRadius / 2.0, g2,
        //                        xx + widthWeWannaUse / 2.0, minAxisValue);
        //            }
        //        }
        //        // collect entity and tool tip information...
        //        if (state.getInfo() != null && box != null) {
        //            EntityCollection entities = state.getEntityCollection();
        //            if (entities != null) {
        //                addItemEntity(entities, dataset, row, column, box);
        //            }
    }

}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as lines.
 *
 * @param g2  the graphics device./*  w  w w.  j  a va 2s  . c o m*/
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
protected void drawVerticalSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, CrosshairState crosshairState, int pass) {

    State s = (State) state;
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = dataArea.getWidth();
    double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth;
    double lowestVisibleY = rangeAxis.getLowerBound();
    double highestVisibleY = rangeAxis.getUpperBound();

    double lastX = Double.NEGATIVE_INFINITY;
    double lastY = 0.0;
    double highY = 0.0;
    double lowY = 0.0;
    double openY = 0.0;
    double closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    boolean pathStarted = false;
    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        double x = dataset.getXValue(series, itemIndex);
        double y = dataset.getYValue(series, itemIndex);
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            //System.out.println ("Breakpoint 736: pathStarted " + pathStarted);
            if (!pathStarted) {
                float startX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                float startY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                s.seriesPath.moveTo(startX, startY);
                pathStarted = true;
            }
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println ("Breakpoint 744: leaving interval ");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalPathX = 0.0f;
                float intervalPathStartY = 0.0f;
                float intervalPathEndY = 0.0f;
                float seriesPathCurrentX = 0.0f;
                float seriesPathCurrentY = 0.0f;
                float seriesPathLastX = 0.0f;
                float seriesPathLastY = 0.0f;

                //first set some variables
                intervalPathX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalPathStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalPathEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                seriesPathCurrentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                seriesPathLastX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                seriesPathCurrentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                seriesPathLastY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                /*if((lowY - highY) < 1){
                lastPointInInterval = false;
                }*/
                //Double[] values = new Double[]{new Double(openY), new Double(closeY), new Double(highY), new Double(lowY), new Double(lastX)};
                /*MessageFormat mf = new MessageFormat("openY {0,number, integer},"
                    + " closeY {1,number, integer}"
                    + " highY {2,number, integer}"
                    + " lowY {3,number, integer}"
                    + "lastX {4,number, integer}");*/
                //String text = mf.format(values);
                //System.out.println("Breakpoint 772"  + text);
                boolean drawInterval = false;
                if (openY >= closeY) {
                    if (highY > openY || lowY < closeY) {
                        drawInterval = true;
                    }
                }
                if (openY < closeY) {
                    if (lowY < openY || highY > closeY) {
                        drawInterval = true;
                    }
                }
                //System.out.println("Breakpoint 784, drawInterval "  + drawInterval);
                if (drawInterval) {
                    s.intervalPath.moveTo(intervalPathX, intervalPathStartY);
                    s.intervalPath.lineTo(intervalPathX, intervalPathEndY);
                }
                lastIntervalDone = true;

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood && !lastPointInInterval) {//last point not valid --
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                } else {//last point valid
                    //if the last point was visible and not part of an interval,
                    //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line
                    //thus we only need to draw a line to the current position
                    if (lastPointInInterval && lastPointGood) {
                        s.seriesPath.lineTo(seriesPathLastX, seriesPathLastY);
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    } //if the last point was not visible or part of an interval, we have just stored the y values of the last point
                      //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing
                      //and draw a line to the current position.
                    else {
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = y;
                openY = y;
                closeY = y;
                lastPointInInterval = false;
            } else {
                lastIntervalDone = false;
                lastPointInInterval = true;
                highY = Math.max(highY, y);
                lowY = Math.min(lowY, y);
                closeY = y;
            }
            lastPointGood = true;
        } else {
            lastPointGood = false;
        }
    }
    // if this is the last item, draw the path ...
    // draw path, but first check whether we need to complete an interval
    if (!lastIntervalDone) {
        if (lowY < highY) {
            float intervalX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            float intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
            float intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            s.intervalPath.moveTo(intervalX, intervalStartY);
            s.intervalPath.lineTo(intervalX, intervalEndY);
        }
    }
    PathIterator pi = s.seriesPath.getPathIterator(null);
    g2.setStroke(getItemStroke(series, 0));
    g2.setPaint(getItemPaint(series, 0));
    g2.draw(s.seriesPath);
    g2.draw(s.intervalPath);
}

From source file:gov.nih.nci.caintegrator.application.graphing.BoxAndWhiskerDotsRenderer.java

/**
 * Draws the visual representation of a single data item when the plot has 
 * a horizontal orientation.//from   ww w  .j a  va2  s. c o  m
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawHorizontalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {

    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = Math.abs(categoryEnd - categoryStart);

    double yy = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        yy = yy + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than 
        // the category width
        double offset = (categoryWidth - state.getBarWidth()) / 2;
        yy = yy + offset;
    }

    Paint p = getItemPaint(row, column);
    if (p != null) {
        g2.setPaint(p);
    }
    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    RectangleEdge location = plot.getRangeAxisEdge();

    Number xQ1 = bawDataset.getQ1Value(row, column);
    Number xQ3 = bawDataset.getQ3Value(row, column);
    Number xMax = bawDataset.getMaxRegularValue(row, column);
    Number xMin = bawDataset.getMinRegularValue(row, column);

    Shape box = null;
    if (xQ1 != null && xQ3 != null && xMax != null && xMin != null) {

        double xxQ1 = rangeAxis.valueToJava2D(xQ1.doubleValue(), dataArea, location);
        double xxQ3 = rangeAxis.valueToJava2D(xQ3.doubleValue(), dataArea, location);
        double xxMax = rangeAxis.valueToJava2D(xMax.doubleValue(), dataArea, location);
        double xxMin = rangeAxis.valueToJava2D(xMin.doubleValue(), dataArea, location);
        double yymid = yy + state.getBarWidth() / 2.0;

        // draw the upper shadow...
        g2.draw(new Line2D.Double(xxMax, yymid, xxQ3, yymid));
        g2.draw(new Line2D.Double(xxMax, yy, xxMax, yy + state.getBarWidth()));

        // draw the lower shadow...
        g2.draw(new Line2D.Double(xxMin, yymid, xxQ1, yymid));
        g2.draw(new Line2D.Double(xxMin, yy, xxMin, yy + state.getBarWidth()));

        // draw the box...
        box = new Rectangle2D.Double(Math.min(xxQ1, xxQ3), yy, Math.abs(xxQ1 - xxQ3), state.getBarWidth());
        if (this.fillBox) {
            g2.fill(box);
        }
        g2.draw(box);

    }

    g2.setPaint(this.artifactPaint);
    double aRadius = 0; // average radius

    // draw mean - SPECIAL AIMS REQUIREMENT...
    Number xMean = bawDataset.getMeanValue(row, column);
    if (xMean != null) {
        double xxMean = rangeAxis.valueToJava2D(xMean.doubleValue(), dataArea, location);
        aRadius = state.getBarWidth() / 4;
        Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xxMean - aRadius, yy + aRadius, aRadius * 2,
                aRadius * 2);
        g2.fill(avgEllipse);
        g2.draw(avgEllipse);
    }

    // draw median...
    Number xMedian = bawDataset.getMedianValue(row, column);
    if (xMedian != null) {
        double xxMedian = rangeAxis.valueToJava2D(xMedian.doubleValue(), dataArea, location);
        g2.draw(new Line2D.Double(xxMedian, yy, xxMedian, yy + state.getBarWidth()));
    }

    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(box, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }

}

From source file:edu.dlnu.liuwenpeng.render.BarRenderer.java

/**    
* Calculates the bar width and stores it in the renderer state.    
*    // ww  w. j  a  v a 2  s  .  c  om
* @param plot  the plot.    
* @param dataArea  the data area.    
* @param rendererIndex  the renderer index.    
* @param state  the renderer state.    
*/
protected void calculateBarWidth(CategoryPlot plot, Rectangle2D dataArea, int rendererIndex,
        CategoryItemRendererState state) {

    CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
    CategoryDataset dataset = plot.getDataset(rendererIndex);
    if (dataset != null) {
        int columns = dataset.getColumnCount();
        int rows = dataset.getRowCount();
        double space = 0.0;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            space = dataArea.getHeight();
        } else if (orientation == PlotOrientation.VERTICAL) {
            space = dataArea.getWidth();
        }
        double maxWidth = space * getMaximumBarWidth();
        double categoryMargin = 0.0;
        double currentItemMargin = 0.0;
        if (columns > 1) {
            categoryMargin = domainAxis.getCategoryMargin();
        }
        if (rows > 1) {
            currentItemMargin = getItemMargin();
        }
        double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin
                - currentItemMargin);
        if ((rows * columns) > 0) {
            state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
        } else {
            state.setBarWidth(Math.min(used, maxWidth));
        }
    }
}

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

/**
 * Draws the visual representation of a single data item when the plot has 
 * a vertical orientation.//w w w.  ja v  a2  s . c o  m
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param plot  the plot (can be used to obtain standard color information 
 *              etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param row  the row index (zero-based).
 * @param column  the column index (zero-based).
 */
public void drawVerticalItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea,
        CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row,
        int column) {

    BoxAndWhiskerCategoryDataset bawDataset = (BoxAndWhiskerCategoryDataset) dataset;

    double categoryEnd = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryStart = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
            plot.getDomainAxisEdge());
    double categoryWidth = categoryEnd - categoryStart;

    double xx = categoryStart;
    int seriesCount = getRowCount();
    int categoryCount = getColumnCount();

    if (seriesCount > 1) {
        double seriesGap = dataArea.getWidth() * getItemMargin() / (categoryCount * (seriesCount - 1));
        double usedWidth = (state.getBarWidth() * seriesCount) + (seriesGap * (seriesCount - 1));
        // offset the start of the boxes if the total width used is smaller
        // than the category width
        double offset = (categoryWidth - usedWidth) / 2;
        xx = xx + offset + (row * (state.getBarWidth() + seriesGap));
    } else {
        // offset the start of the box if the box width is smaller than the 
        // category width
        double offset = (categoryWidth - state.getBarWidth()) / 2;
        xx = xx + offset;
    }

    double yyAverage = 0.0;
    double yyOutlier;

    //      bar colors are determined by the Paint p obtained here in a rotational
    //manner (from a Color array).  By switching the column and raw values,
    //you can get a different color pattern for the bar:  In the method 
    //getItemPaint(), only the first argument counts for the color. The original
    //code Paint p = getItemPaint(row, column); is commented out for a difference.
    Paint p = null;
    if (this.getPlotColor() != null) {
        p = PaintUtilities.stringToColor(getPlotColor()); // coin plot should all be one color
    } else {
        p = getItemPaint(row, column);
    }

    // Paint p = PaintUtilities.stringToColor("red"); 
    if (p != null) {
        g2.setPaint(p);
    }

    Stroke s = getItemStroke(row, column);
    g2.setStroke(s);

    double aRadius = 0; // average radius

    RectangleEdge location = plot.getRangeAxisEdge();

    Number yQ1 = bawDataset.getQ1Value(row, column);
    Number yQ3 = bawDataset.getQ3Value(row, column);
    Number yMax = bawDataset.getMaxRegularValue(row, column);
    Number yMin = bawDataset.getMinRegularValue(row, column);
    Shape box = null;
    if (yQ1 != null && yQ3 != null && yMax != null && yMin != null) {

        double yyQ1 = rangeAxis.valueToJava2D(yQ1.doubleValue(), dataArea, location);
        double yyQ3 = rangeAxis.valueToJava2D(yQ3.doubleValue(), dataArea, location);
        double yyMax = rangeAxis.valueToJava2D(yMax.doubleValue(), dataArea, location);
        double yyMin = rangeAxis.valueToJava2D(yMin.doubleValue(), dataArea, location);
        double xxmid = xx + state.getBarWidth() / 2.0;

        // draw the upper shadow...
        g2.draw(new Line2D.Double(xxmid, yyMax, xxmid, yyQ3));
        g2.draw(new Line2D.Double(xx, yyMax, xx + state.getBarWidth(), yyMax));

        // draw the lower shadow...
        g2.draw(new Line2D.Double(xxmid, yyMin, xxmid, yyQ1));
        g2.draw(new Line2D.Double(xx, yyMin, xx + state.getBarWidth(), yyMin));

        // draw the body...
        box = new Rectangle2D.Double(xx, Math.min(yyQ1, yyQ3), state.getBarWidth(), Math.abs(yyQ1 - yyQ3));
        if (getFillBox()) {
            g2.fill(box);
        }
        g2.draw(box);

    }

    g2.setPaint(getArtifactPaint());

    if (this.isDisplayMean()) {
        // draw mean - SPECIAL AIMS REQUIREMENT...
        Number yMean = bawDataset.getMeanValue(row, column);
        if (yMean != null) {
            yyAverage = rangeAxis.valueToJava2D(yMean.doubleValue(), dataArea, location);
            aRadius = state.getBarWidth() / 4;
            Ellipse2D.Double avgEllipse = new Ellipse2D.Double(xx + aRadius, yyAverage - aRadius, aRadius * 2,
                    aRadius * 2);
            g2.fill(avgEllipse);
            g2.draw(avgEllipse);
        }
    }

    if (this.isDisplayMedian()) {
        // draw median...
        Number yMedian = bawDataset.getMedianValue(row, column);
        if (yMedian != null) {
            double yyMedian = rangeAxis.valueToJava2D(yMedian.doubleValue(), dataArea, location);
            g2.draw(new Line2D.Double(xx, yyMedian, xx + state.getBarWidth(), yyMedian));
        }
    }

    // draw yOutliers...
    double maxAxisValue = rangeAxis.valueToJava2D(rangeAxis.getUpperBound(), dataArea, location) + aRadius;
    double minAxisValue = rangeAxis.valueToJava2D(rangeAxis.getLowerBound(), dataArea, location) - aRadius;

    g2.setPaint(p);

    if (this.isDisplayCoinCloud()) {
        //draw coin clouds
        drawCoinCloud(g2, state, dataArea, location, rangeAxis, xx, row, column, bawDataset);
    }
    //caIntegrator: oRadius is the radius of the outlier circles. It was used to be 3.
    // draw outliers
    double oRadius = state.getBarWidth() / this.outlierRadiusDenominator; // outlier radius
    List outliers = new ArrayList();
    OutlierListCollection outlierListCollection = new OutlierListCollection();

    List yOutliers = bawDataset.getOutliers(row, column);
    if (yOutliers != null) {
        for (int i = 0; i < yOutliers.size(); i++) {
            double outlier = ((Number) yOutliers.get(i)).doubleValue();
            Number minOutlier = bawDataset.getMinOutlier(row, column);
            Number maxOutlier = bawDataset.getMaxOutlier(row, column);
            Number minRegular = bawDataset.getMinRegularValue(row, column);
            Number maxRegular = bawDataset.getMaxRegularValue(row, column);
            if (outlier > maxOutlier.doubleValue()) {
                outlierListCollection.setHighFarOut(true);
            } else if (outlier < minOutlier.doubleValue()) {
                outlierListCollection.setLowFarOut(true);
            } else if (outlier > maxRegular.doubleValue()) {
                yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
            } else if (outlier < minRegular.doubleValue()) {
                yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
            }

            Collections.sort(outliers);
        }
        //display farouts as JFreeChart Implemetation
        if (!displayAllOutliers) {
            // Process outliers. Each outlier is either added to the 
            // appropriate outlier list or a new outlier list is made
            for (int i = 0; i < yOutliers.size(); i++) {
                Number minRegular = bawDataset.getMinRegularValue(row, column);
                Number maxRegular = bawDataset.getMaxRegularValue(row, column);
                double outlier = ((Number) yOutliers.get(i)).doubleValue();
                if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) {
                    yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                    outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
                }
            }

            for (Iterator iterator = outliers.iterator(); iterator.hasNext();) {
                Outlier outlier = (Outlier) iterator.next();
                outlierListCollection.add(outlier);
            }

            for (Iterator iterator = outlierListCollection.iterator(); iterator.hasNext();) {
                OutlierList list = (OutlierList) iterator.next();
                Outlier outlier = list.getAveragedOutlier();
                Point2D point = outlier.getPoint();

                if (list.isMultiple()) {
                    drawMultipleEllipse(point, state.getBarWidth(), oRadius, g2);
                } else {
                    drawEllipse(point, oRadius, g2);
                }
            }
            // draw farout indicators
            if (outlierListCollection.isHighFarOut()) {
                drawHighFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, maxAxisValue);
            }

            if (outlierListCollection.isLowFarOut()) {
                drawLowFarOut(aRadius / 2.0, g2, xx + state.getBarWidth() / 2.0, minAxisValue);
            }
        } else {
            for (int i = 0; i < yOutliers.size(); i++) {
                Number minRegular = bawDataset.getMinRegularValue(row, column);
                Number maxRegular = bawDataset.getMaxRegularValue(row, column);
                double outlier = ((Number) yOutliers.get(i)).doubleValue();
                if (outlier < minRegular.doubleValue() || outlier > maxRegular.doubleValue()) {
                    yyOutlier = rangeAxis.valueToJava2D(outlier, dataArea, location);
                    outliers.add(new Outlier(xx + state.getBarWidth() / 2.0, yyOutlier, oRadius));
                }
            }
            Collections.sort(outliers);
            for (Iterator iterator = outliers.iterator(); iterator.hasNext();) {
                Outlier outlier = (Outlier) iterator.next();
                Point2D point = outlier.getPoint();

                drawEllipse(point, oRadius, g2);
            }
        }
    }
    // collect entity and tool tip information...
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
            if (tipster != null) {
                tip = tipster.generateToolTip(dataset, row, column);
            }
            String url = null;
            if (getItemURLGenerator(row, column) != null) {
                url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
            }
            CategoryItemEntity entity = new CategoryItemEntity(box, tip, url, dataset, row,
                    dataset.getColumnKey(column), column);
            entities.add(entity);
        }
    }

}

From source file:de.tor.tribes.ui.panels.MinimapPanel.java

private boolean redraw() {
    Village[][] mVisibleVillages = DataHolder.getSingleton().getVillages();

    if (mVisibleVillages == null || mBuffer == null) {
        return false;
    }/*from w  w w  .  ja  v a  2 s.c om*/

    Graphics2D g2d = (Graphics2D) mBuffer.getGraphics();
    Composite tempC = g2d.getComposite();
    //clear
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
    g2d.fillRect(0, 0, mBuffer.getWidth(), mBuffer.getHeight());

    //reset composite
    g2d.setComposite(tempC);

    boolean markPlayer = GlobalOptions.getProperties().getBoolean("mark.villages.on.minimap");
    if (ServerSettings.getSingleton().getMapDimension() == null) {
        //could not draw minimap if dimensions are not loaded yet
        return false;
    }
    boolean showBarbarian = GlobalOptions.getProperties().getBoolean("show.barbarian");

    Color DEFAULT = Constants.DS_DEFAULT_MARKER;
    try {
        int mark = Integer.parseInt(GlobalOptions.getProperty("default.mark"));
        if (mark == 0) {
            DEFAULT = Constants.DS_DEFAULT_MARKER;
        } else if (mark == 1) {
            DEFAULT = Color.RED;
        } else if (mark == 2) {
            DEFAULT = Color.WHITE;
        }
    } catch (Exception e) {
        DEFAULT = Constants.DS_DEFAULT_MARKER;
    }

    Rectangle mapDim = ServerSettings.getSingleton().getMapDimension();
    double wField = mapDim.getWidth() / (double) visiblePart.width;
    double hField = mapDim.getHeight() / (double) visiblePart.height;

    UserProfile profile = GlobalOptions.getSelectedProfile();
    Tribe currentTribe = InvalidTribe.getSingleton();
    if (profile != null) {
        currentTribe = profile.getTribe();
    }

    for (int i = visiblePart.x; i < (visiblePart.width + visiblePart.x); i++) {
        for (int j = visiblePart.y; j < (visiblePart.height + visiblePart.y); j++) {
            Village v = mVisibleVillages[i][j];
            if (v != null) {
                Color markerColor = null;
                boolean isLeft = false;
                if (v.getTribe() == Barbarians.getSingleton()) {
                    isLeft = true;
                } else {
                    if ((currentTribe != null) && (v.getTribe().getId() == currentTribe.getId())) {
                        //village is owned by current player. mark it dependent on settings
                        if (markPlayer) {
                            markerColor = Color.YELLOW;
                        }
                    } else {
                        try {
                            Marker marker = MarkerManager.getSingleton().getMarker(v.getTribe());
                            if (marker != null && !marker.isShownOnMap()) {
                                marker = null;
                                markerColor = DEFAULT;
                            }

                            if (marker == null) {
                                marker = MarkerManager.getSingleton().getMarker(v.getTribe().getAlly());
                                if (marker != null && marker.isShownOnMap()) {
                                    markerColor = marker.getMarkerColor();
                                }
                            } else {
                                if (marker.isShownOnMap()) {
                                    markerColor = marker.getMarkerColor();
                                }
                            }
                        } catch (Exception e) {
                            markerColor = null;
                        }
                    }
                }

                if (!isLeft) {
                    if (markerColor != null) {
                        g2d.setColor(markerColor);
                    } else {
                        g2d.setColor(DEFAULT);
                    }
                    g2d.fillRect((int) Math.round((i - visiblePart.x) * wField),
                            (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField),
                            (int) Math.floor(hField));
                } else {
                    if (showBarbarian) {
                        g2d.setColor(Color.LIGHT_GRAY);
                        g2d.fillRect((int) Math.round((i - visiblePart.x) * wField),
                                (int) Math.round((j - visiblePart.y) * hField), (int) Math.floor(wField),
                                (int) Math.floor(hField));
                    }
                }
            }
        }
    }

    try {
        if (GlobalOptions.getProperties().getBoolean("map.showcontinents")) {
            g2d.setColor(Color.BLACK);
            Composite c = g2d.getComposite();
            Composite a = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
            Font f = g2d.getFont();
            Font t = new Font("Serif", Font.BOLD, (int) Math.round(30 * hField));
            g2d.setFont(t);
            int fact = 10;
            int mid = (int) Math.round(50 * wField);

            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    g2d.setComposite(a);

                    String conti = "K" + (j * 10 + i);
                    Rectangle2D bounds = g2d.getFontMetrics(t).getStringBounds(conti, g2d);
                    int cx = i * fact * 10 - visiblePart.x;
                    int cy = j * fact * 10 - visiblePart.y;
                    cx = (int) Math.round(cx * wField);
                    cy = (int) Math.round(cy * hField);
                    g2d.drawString(conti, (int) Math.rint(cx + mid - bounds.getWidth() / 2),
                            (int) Math.rint(cy + mid + bounds.getHeight() / 2));
                    g2d.setComposite(c);
                    int wk = 100;
                    int hk = 100;

                    if (i == 9) {
                        wk -= 1;
                    }
                    if (j == 9) {
                        hk -= 1;
                    }

                    g2d.drawRect(cx, cy, (int) Math.round(wk * wField), (int) Math.round(hk * hField));
                }
            }
            g2d.setFont(f);
        }
    } catch (Exception e) {
        logger.error("Creation of Minimap failed", e);
    }
    g2d.dispose();
    return true;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot,
        CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) {

    // check the value we are plotting...
    Number dataValue = dataset.getValue(row, column);
    if (dataValue == null) {
        return;//from w  ww  . ja  v  a 2  s . c om
    }

    double value = dataValue.doubleValue();

    Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(),
            dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());

    PlotOrientation orientation = plot.getOrientation();

    double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column);
    double[] barL0L1 = calculateBarL0L1(value);
    if (barL0L1 == null) {
        return; // the bar is not visible
    }

    RectangleEdge edge = plot.getRangeAxisEdge();
    double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
    double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
    double barL0 = Math.min(transL0, transL1);
    double barLength = Math.abs(transL1 - transL0);

    // draw the bar...
    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());
    } else {
        bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);
    }
    Paint itemPaint = getItemPaint(row, column);
    if (itemPaint instanceof GradientPaint) {
        itemPaint = getGradientPaintTransformer().transform((GradientPaint) itemPaint, bar);
    }
    g2.setPaint(itemPaint);
    g2.fill(bar);

    double x0 = bar.getMinX();
    double x1 = x0 + getXOffset();
    double x2 = bar.getMaxX();
    double x3 = x2 + getXOffset();

    double y0 = bar.getMinY() - getYOffset();
    double y1 = bar.getMinY();
    double y2 = bar.getMaxY() - getYOffset();
    double y3 = bar.getMaxY();

    GeneralPath bar3dRight = null;
    GeneralPath bar3dTop = null;
    if (barLength > 0.0) {
        bar3dRight = new GeneralPath();
        bar3dRight.moveTo((float) x2, (float) y3);
        bar3dRight.lineTo((float) x2, (float) y1);
        bar3dRight.lineTo((float) x3, (float) y0);
        bar3dRight.lineTo((float) x3, (float) y2);
        bar3dRight.closePath();

        if (itemPaint instanceof Color) {
            g2.setPaint(((Color) itemPaint).darker());
        } else if (itemPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) itemPaint;
            g2.setPaint(new StandardGradientPaintTransformer().transform(new GradientPaint(gp.getPoint1(),
                    gp.getColor1().darker(), gp.getPoint2(), gp.getColor2().darker(), gp.isCyclic()),
                    bar3dRight));
        }
        g2.fill(bar3dRight);
    }

    bar3dTop = new GeneralPath();
    bar3dTop.moveTo((float) x0, (float) y1);
    bar3dTop.lineTo((float) x1, (float) y0);
    bar3dTop.lineTo((float) x3, (float) y0);
    bar3dTop.lineTo((float) x2, (float) y1);
    bar3dTop.closePath();
    g2.fill(bar3dTop);

    if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
        g2.setStroke(getItemOutlineStroke(row, column));
        g2.setPaint(getItemOutlinePaint(row, column));
        g2.draw(bar);
        if (bar3dRight != null) {
            g2.draw(bar3dRight);
        }
        if (bar3dTop != null) {
            g2.draw(bar3dTop);
        }
    }

    CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
    if (generator != null && isItemLabelVisible(row, column)) {
        drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
    }

    // add an item entity, if this information is being collected
    EntityCollection entities = state.getEntityCollection();
    if (entities != null) {
        GeneralPath barOutline = new GeneralPath();
        barOutline.moveTo((float) x0, (float) y3);
        barOutline.lineTo((float) x0, (float) y1);
        barOutline.lineTo((float) x1, (float) y0);
        barOutline.lineTo((float) x3, (float) y0);
        barOutline.lineTo((float) x3, (float) y2);
        barOutline.lineTo((float) x2, (float) y3);
        barOutline.closePath();
        addItemEntity(entities, dataset, row, column, barOutline);
    }
}

From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java

/**
 * Returns a cartesian point from a polar angle, length and bounding box
 *
 * @param bounds  the area inside which the point needs to be.
 * @param angle  the polar angle, in degrees.
 * @param length  the relative length. Given in percent of maximum extend.
 *
 * @return The cartesian point.//from   w  w  w .  j ava2  s.com
 */
protected Point2D getWebPoint(Rectangle2D bounds, double angle, double length) {

    double angrad = Math.toRadians(angle);
    double x = Math.cos(angrad) * length * bounds.getWidth() / 2;
    double y = -Math.sin(angrad) * length * bounds.getHeight() / 2;

    return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2,
            bounds.getY() + y + bounds.getHeight() / 2);
}

From source file:org.geotools.utils.imagemosaic.MosaicIndexBuilder.java

/**
 * This method is responsible for computing the resolutions in for the
 * provided grid geometry in the provided crs.
 * //from w  w w  .  j av a 2 s  .  c om
 * <P>
 * It is worth to note that the returned resolution array is of length of 2
 * and it always is lon, lat for the moment.<br>
 * It might be worth to remove the axes reordering code when we are
 * confident enough with the code to handle the north-up crs.
 * <p>
 * TODO use orthodromic distance?
 * 
 * @param envelope
 *            the GeneralEnvelope
 * @param dim
 * @param crs
 * @throws DataSourceException
 */
protected final double[] getResolution(GeneralEnvelope envelope, Rectangle2D dim, CoordinateReferenceSystem crs)
        throws DataSourceException {
    double[] requestedRes = null;
    try {
        if (dim != null && envelope != null) {
            // do we need to transform the originalEnvelope?
            final CoordinateReferenceSystem crs2D = CRSUtilities
                    .getCRS2D(envelope.getCoordinateReferenceSystem());

            if (crs != null && !CRS.equalsIgnoreMetadata(crs, crs2D)) {
                final MathTransform tr = CRS.findMathTransform(crs2D, crs);
                if (!tr.isIdentity())
                    envelope = CRS.transform(tr, envelope);
            }
            requestedRes = new double[2];
            requestedRes[0] = envelope.getLength(0) / dim.getWidth();
            requestedRes[1] = envelope.getLength(1) / dim.getHeight();
        }
        return requestedRes;
    } catch (TransformException e) {
        throw new DataSourceException("Unable to get the resolution", e);
    } catch (FactoryException e) {
        throw new DataSourceException("Unable to get the resolution", e);
    }
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void changeMaskYMax(double y) {
    Rectangle2D frame = getSelectedMask().getRectangleFrame();
    getSelectedMask().setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), Math.min(frame.getMinY(), y),
            frame.getWidth(), Math.abs(frame.getMinY() - y)));
}