Example usage for java.awt.geom Rectangle2D getMaxX

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

Introduction

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

Prototype

public double getMaxX() 

Source Link

Document

Returns the largest X coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2           the graphics device.
 * @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./*from w w w .ja  va  2  s .c o m*/
 * @param rangeAxis    the range axis.
 * @param dataset      the dataset.
 * @param series       the series index (zero-based).
 * @param item         the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass         the pass index.
 */
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 (!getItemVisible(series, item))
        return;
    PlotOrientation orientation = plot.getOrientation();
    java.awt.Paint seriesPaint = getItemPaint(series, item);
    java.awt.Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);
    double x0 = dataset.getXValue(series, item);
    double y0 = dataset.getYValue(series, item);
    if (java.lang.Double.isNaN(y0))
        return;
    org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double x1 = 0, y1 = 0;
    if (item < dataset.getItemCount(series) - 1) {
        x1 = dataset.getXValue(series, item + 1);
        y1 = dataset.getYValue(series, item + 1);
    } else {
        x1 = dataArea.getMaxX();
        y1 = dataArea.getMaxY();
    }

    boolean useFillPaint = getUseFillPaint();
    ;
    boolean drawOutlines = getDrawOutlines();
    if (!java.lang.Double.isNaN(y0)) {
        double transX1;
        double transY1;
        if (item < dataset.getItemCount(series) - 1) {
            transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
        } else {
            transX1 = x1;
            transY1 = y1;
        }
        Line2D line = state.workingLine;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(transY0, transX0, transY0, transX1);
            g2.draw(line);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line.setLine(transX0, transY0, transX1, transY0);
            g2.draw(line);
        }
    }
    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0);
        else if (orientation == PlotOrientation.VERTICAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0);
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (useFillPaint)
                    g2.setPaint(getItemFillPaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.fill(shape);
            }
            if (drawOutlines) {
                if (getUseOutlinePaint())
                    g2.setPaint(getItemOutlinePaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }
    if (isItemLabelVisible(series, item)) {
        double xx = transX0;
        double yy = transY0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY0;
            yy = transX0;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D);
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0,
            orientation);
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            int r = getDefaultEntityRadius();
            java.awt.Shape shape = orientation != PlotOrientation.VERTICAL
                    ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r,
                            transX0 - (double) r, 2 * r, 2 * r)))
                    : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r,
                            transY0 - (double) r, 2 * r, 2 * r)));
            if (shape != null) {
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null)
                    tip = generator.generateToolTip(dataset, series, item);
                String url = null;
                if (getURLGenerator() != null)
                    url = getURLGenerator().generateURL(dataset, series, item);
                XYItemEntity entity = new XYItemEntity(shape, dataset, series, item, tip, url);
                entities.add(entity);
            }
        }
    }
}

From source file:gda.plots.TurboXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself.//from w  ww .j a  v  a 2  s.co m
 * 
 * @param g2
 *            the graphics device.
 * @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.
 */
@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 (_item > 0)
        return;
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);
    if (!sxys.isVisible()) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

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

    try {
        int x0 = -1; // the x position in pixels of the previous point
        int y0 = -1; // the y position in pixels of the previous point
        int x1 = -1; // the x position in pixels of the current point
        int y1 = -1; // the y position in pixels of the current point
        int xmin = (int) dataArea.getMinX();
        int xmax = (int) dataArea.getMaxX();
        int ymin = (int) dataArea.getMinY();
        int ymax = (int) dataArea.getMaxY();
        GeneralPath path = null;

        /*
         * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear
         * maths
         */
        double xl = 0., mx = Double.NaN, cx = 0.;
        if (domainAxis instanceof SimpleNumberAxis) {
            xl = domainAxis.getRange().getLowerBound();
            mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl);
            cx = xmin;
        }
        double yl = 0., my = Double.NaN, cy = 0.;
        if (rangeAxis instanceof SimpleNumberAxis) {
            yl = rangeAxis.getRange().getLowerBound();
            my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl);
            cy = ymax;
        }
        List<XYDataItem> list = sxys.getData();

        boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my);
        Paint paint = sxys.getPaint();
        Stroke stroke = sxys.getStroke();
        Paint paint_symbol = sxys.getSymbolPaint();
        Stroke stroke_symbol = new BasicStroke();
        drawLines = sxys.isDrawLines();
        boolean filled = sxys.getFilled();
        Shape shape = sxys.getSymbol();
        boolean drawMarkers = sxys.isDrawMarkers() & shape != null;
        int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */
        if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) {
            Rectangle shapeBoundingBox = shape.getBounds();
            tooltipThresholdCounts = (int) dataArea.getWidth()
                    / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold);
        }

        java.util.Vector<ddouble> markerPositions = null;
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        boolean prevLineAdded = false;
        // In case the iterator does not work then use the TODO comment iterator use and why not always
        // comment variables
        synchronized (list) {
            Iterator<XYDataItem> iter = list.iterator();
            /*
             * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The
             * variable addThis determines if the current point is to be added to the path If previous line was
             * added that the current must be even if off the screen - but in this case the flag prevLineAdded is
             * set false so that the next does not have to be added.
             */
            for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) {
                XYDataItem dataitem = iter.next();
                double x = dataitem.getX().doubleValue();
                double y = dataitem.getY().doubleValue();
                x = xValueTransformer.transformValue(x);

                x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation)
                        : (int) ((x - xl) * mx + cx);
                y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation)
                        : (int) ((y - yl) * my + cy);

                boolean addThis = true;
                if (item == 0) {
                    x0 = x1;
                    y0 = y1;
                    if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) {
                        addThis = false;
                    }
                } else {
                    if (x1 == x0 && y1 == y0) {
                        addThis = false;
                    }
                    if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin)
                            || (y1 > ymax && y0 > ymax)) {
                        if (prevLineAdded) {
                            path = addPointToLine(path, orientation, x1, y1);
                        }
                        addThis = false;
                    }
                }
                if (addThis) {
                    /*
                     * If the current point is to be added then ensure previous one is as well to prevent lines
                     * not crossing the edge of the screen
                     */
                    if (!prevLineAdded) {
                        path = addPointToLine(path, orientation, x0, y0);
                    }
                    path = addPointToLine(path, orientation, x1, y1);
                    prevLineAdded = true;
                }
                prevLineAdded = addThis;
                if (addThis && drawMarkers) {
                    if (markerPositions == null) {
                        markerPositions = new java.util.Vector<ddouble>();
                    }
                    markerPositions.add(new ddouble(item, x1, y1));
                    if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) {
                        drawMarkers = false;
                        markerPositions = null;
                    }
                }
            }
            if (path != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(path);
            }
            if (markerPositions != null) {
                if (drawMarkers) {
                    g2.setPaint(paint_symbol);
                    g2.setStroke(stroke_symbol);
                    for (ddouble dd : markerPositions) {
                        Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y);
                        if (filled) {
                            g2.fill(shape_item);
                        } else {
                            g2.draw(shape_item);
                        }
                        entityArea = shape_item;
                        // add an entity for the item...
                        if (entities != null) {
                            addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y);
                        }
                    }
                    g2.setPaint(paint);
                    g2.setStroke(stroke);
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:KIDLYRenderer.java

/**
 * Calculates the item label anchor point.
 *
 * @param anchor  the anchor.//  w w  w. java 2  s  .  c  o m
 * @param bar  the bar.
 * @param orientation  the plot orientation.
 *
 * @return The anchor point.
 */
private Point2D calculateLabelAnchorPoint(ItemLabelAnchor anchor, Rectangle2D bar,
        PlotOrientation orientation) {

    Point2D result = null;
    double offset = getItemLabelAnchorOffset();
    double x0 = bar.getX() - offset;
    double x1 = bar.getX();
    double x2 = bar.getX() + offset;
    double x3 = bar.getCenterX();
    double x4 = bar.getMaxX() - offset;
    double x5 = bar.getMaxX();
    double x6 = bar.getMaxX() + offset;

    double y0 = bar.getMaxY() + offset;
    double y1 = bar.getMaxY();
    double y2 = bar.getMaxY() - offset;
    double y3 = bar.getCenterY();
    double y4 = bar.getMinY() + offset;
    double y5 = bar.getMinY();
    double y6 = bar.getMinY() - offset;

    if (anchor == ItemLabelAnchor.CENTER) {
        result = new Point2D.Double(x3, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE1) {
        result = new Point2D.Double(x4, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE2) {
        result = new Point2D.Double(x4, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE3) {
        result = new Point2D.Double(x4, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE4) {
        result = new Point2D.Double(x4, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE5) {
        result = new Point2D.Double(x4, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE6) {
        result = new Point2D.Double(x3, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE7) {
        result = new Point2D.Double(x2, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE8) {
        result = new Point2D.Double(x2, y2);
    } else if (anchor == ItemLabelAnchor.INSIDE9) {
        result = new Point2D.Double(x2, y3);
    } else if (anchor == ItemLabelAnchor.INSIDE10) {
        result = new Point2D.Double(x2, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE11) {
        result = new Point2D.Double(x2, y4);
    } else if (anchor == ItemLabelAnchor.INSIDE12) {
        result = new Point2D.Double(x3, y4);
    } else if (anchor == ItemLabelAnchor.OUTSIDE1) {
        result = new Point2D.Double(x5, y6);
    } else if (anchor == ItemLabelAnchor.OUTSIDE2) {
        result = new Point2D.Double(x6, y5);
    } else if (anchor == ItemLabelAnchor.OUTSIDE3) {
        result = new Point2D.Double(x6, y3);
    } else if (anchor == ItemLabelAnchor.OUTSIDE4) {
        result = new Point2D.Double(x6, y1);
    } else if (anchor == ItemLabelAnchor.OUTSIDE5) {
        result = new Point2D.Double(x5, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE6) {
        result = new Point2D.Double(x3, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE7) {
        result = new Point2D.Double(x1, y0);
    } else if (anchor == ItemLabelAnchor.OUTSIDE8) {
        result = new Point2D.Double(x0, y1);
    } else if (anchor == ItemLabelAnchor.OUTSIDE9) {
        result = new Point2D.Double(x0, y3);
    } else if (anchor == ItemLabelAnchor.OUTSIDE10) {
        result = new Point2D.Double(x0, y5);
    } else if (anchor == ItemLabelAnchor.OUTSIDE11) {
        result = new Point2D.Double(x1, y6);
    } else if (anchor == ItemLabelAnchor.OUTSIDE12) {
        result = new Point2D.Double(x3, y6);
    }

    return result;

}

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

@Override
protected void drawToolTipFollower(Graphics2D g2, int x, int y) {
    Rectangle2D dataArea = getScreenDataArea();
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() < y)
            && (y < (int) dataArea.getMaxY())) {
        String text = String.format("(%." + mouseFollowerXPrecision + "f, %." + mouseFollowerYPrecision
                + "f, %." + mouseFollowerZPrecision + "f)", getChartX(), getChartY(), getChartZ());
        int xLoc = x + 10;
        int yLoc = y + 20;
        double width = text.length() * 5.5;
        double height = 15;
        if (xLoc + width > dataArea.getMaxX()) {
            xLoc = (int) (x - width);
        }//from  w ww. jav a  2s  .  c  o m
        if (yLoc + height > dataArea.getMaxY()) {
            yLoc = (int) (y - height);
        }

        Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height);
        g2.setColor(Color.white);
        g2.fill(toolTipArea);
        g2.setColor(Color.black);
        g2.drawString(text, xLoc + 3, yLoc + 11);
    }
}

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

private void changeMaskXMin(double x) {
    Rectangle2D frame = getSelectedMask().getRectangleFrame();
    getSelectedMask().setRectangleFrame(new Rectangle2D.Double(Math.min(frame.getMaxX(), x), frame.getMinY(),
            Math.abs(frame.getMaxX() - x), frame.getHeight()));
}

From source file:org.tsho.dmc2.core.chart.Bifurcation2DRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {

    int numVar = model.getNVar();

    if (model instanceof ODE) {

        boolean pointBeyondPoincareSection;
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();

        int dim = initialValue.length;

        final int colorArrayLen = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length;
        final Paint[] colorArray = new Color[colorArrayLen];
        for (int i = 0; i < colorArrayLen; i++) {
            colorArray[i] = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i];
        }/* ww w .j ava 2 s  . co m*/

        double[] fPars = new double[fixedParameters.length];
        System.arraycopy(fixedParameters, 0, fPars, 0, fixedParameters.length);
        double[] initVars = new double[initialValue.length];
        System.arraycopy(initialValue, 0, initVars, 0, initialValue.length);

        double[] result = new double[dim];
        double[][] periodArray = new double[period][dim];

        for (double i = dataArea.getMinX(); i <= dataArea.getMaxX(); i += 1) {

            fPars[firstParameterIdx] = domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM);

            for (double j = dataArea.getMinY(); j < dataArea.getMaxY(); j += 1) {

                fPars[secondParameterIdx] = rangeAxis.java2DToValue(j, dataArea, RectangleEdge.LEFT);

                stepper.setParameters(fPars);
                stepper.setInitialValue(initVars);
                stepper.initialize();
                stepper.step();
                stepper.getCurrentValue(result);

                int h = 0;
                int transX, transY;

                double[] currentPoint = new double[numVar];
                double[] previousPoint = new double[numVar];
                stepper.getCurrentValue(currentPoint);
                stepper.getCurrentValue(previousPoint);
                pointBeyondPoincareSection = positionWrtPoincareSection(currentPoint);

                Paint color = Color.white;
                double[] cycleStartPoint = new double[numVar];
                int actualPeriod = period + 1;

                for (int jj = 0; jj < time / step; jj++) {
                    stepper.step();
                    stepper.getCurrentValue(currentPoint);

                    if (positionWrtPoincareSection(currentPoint) == pointBeyondPoincareSection) {
                        stepper.getCurrentValue(previousPoint);
                        continue;
                    }

                    pointBeyondPoincareSection = !pointBeyondPoincareSection;
                    double[] pointOnSection = pointOnPoincareSection(previousPoint, currentPoint);
                    stepper.setInitialValue(pointOnSection);
                    stepper.initialize();
                    stepper.getCurrentValue(currentPoint);
                    stepper.getCurrentValue(previousPoint);

                    h++;

                    if (h == transients) {
                        for (int kk = 0; kk < numVar; kk++)
                            cycleStartPoint[kk] = currentPoint[kk];
                    }
                    if (h > transients) {
                        if (distance(currentPoint, cycleStartPoint) < epsilon) {
                            actualPeriod = h - transients;
                            break;
                        }
                        if (h >= transients + period)
                            break;
                    }
                }

                stepper.getCurrentValue(result);

                for (h = 0; h < dim; h++) {
                    if (Math.abs(result[h]) > infinity || Double.isNaN(result[h])) {
                        color = Color.black; // black == infinity
                    }
                }

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }

                if (actualPeriod <= period) { // found period
                    color = colorArray[actualPeriod - 1];
                }

                g2.setPaint(color);
                g2.drawRect((int) i, (int) j, 1, 1);

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }

        }
        state = STATE_FINISHED;

    } else {
        ValueAxis domainAxis = plot.getDomainAxis();
        ValueAxis rangeAxis = plot.getRangeAxis();

        int dim = initialValue.length;

        final int colorArrayLen = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length;
        final Paint[] colorArray = new Color[colorArrayLen];
        for (int i = 0; i < colorArrayLen; i++) {
            colorArray[i] = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i];
        }

        double[] fPars = new double[fixedParameters.length];
        System.arraycopy(fixedParameters, 0, fPars, 0, fixedParameters.length);
        double[] initVars = new double[initialValue.length];
        System.arraycopy(initialValue, 0, initVars, 0, initialValue.length);

        double[] result = new double[dim];
        double[][] periodArray = new double[period + 1][dim];

        for (double i = dataArea.getMinX(); i <= dataArea.getMaxX(); i += 1) {

            fPars[firstParameterIdx] = domainAxis.java2DToValue(i, dataArea, RectangleEdge.BOTTOM);

            for (double j = dataArea.getMinY(); j < dataArea.getMaxY(); j += 1) {

                fPars[secondParameterIdx] = rangeAxis.java2DToValue(j, dataArea, RectangleEdge.LEFT);

                stepper.setParameters(fPars);
                stepper.setInitialValue(initVars);
                stepper.initialize();
                stepper.step();
                stepper.getCurrentValue(result);

                for (int h = 1; h < transients; h++) {
                    if (stopped) {
                        state = STATE_STOPPED;
                        return;
                    }
                    stepper.step();
                }

                stepper.getCurrentValue(result);

                Paint color = Color.white; // white == longer period
                for (int h = 0; h < dim; h++) {
                    if (Math.abs(result[h]) > infinity || Double.isNaN(result[h])) {
                        color = Color.black; // black == infinity
                        break;
                    }
                }

                if (color != Color.black) {
                    // get maxPeriod next values
                    for (int h = 0; h <= period; h++) {
                        if (stopped) {
                            state = STATE_STOPPED;
                            return;
                        }

                        stepper.step();
                        stepper.getCurrentValue(result);

                        for (int k = 0; k < dim; k++) {
                            periodArray[h][k] = result[k];
                        }
                    }

                    int h, k = -1;
                    for (h = 1; h <= period; h++) {
                        for (k = 0; k < dim; k++) {
                            if (Math.abs(periodArray[0][k] - periodArray[h][k]) >= epsilon) {
                                break;
                            }
                        }
                        if (k == dim) {
                            break;
                        }
                    }

                    if (h <= period) { // found period
                        color = colorArray[h - 1];
                    }
                }
                g2.setPaint(color);
                g2.drawRect((int) i, (int) j, 1, 1);

                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }
        }
        state = STATE_FINISHED;
    }

}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

private double userX(MouseEvent event) {
    Rectangle2D rectangle = getScaledDataArea();
    double minX = rectangle.getMinX();
    double maxX = rectangle.getMaxX();

    Plot plot = chart.getPlot();//from   w w w  .jav a2 s.c  o m

    int xc = event.getX();

    ValueAxis xa = this.getHorizontalValueAxis(plot);

    double xmin = xa.getLowerBound();
    double xmax = xa.getUpperBound();

    double u = (xc - minX) / (maxX - minX);
    return (u * (xmax - xmin) + xmin);
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeLegendWidth(Point2D point) {
    if (isInternalLegendEnabled && isInternalLegendSelected && legendPoint != null) {
        Rectangle2D screenArea = getScreenDataArea();
        if (point.getX() < screenArea.getMaxX()) {
            internalLegendSetup.setRect(internalLegendSetup.getX(), internalLegendSetup.getY(),
                    point.getX() - screenArea.getMaxX() + internalLegendSetup.getX(),
                    internalLegendSetup.getHeight());
        }/*from  ww w  .j a  v a2  s.c  om*/
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeLegendX(Point2D point) {
    if (isInternalLegendEnabled && isInternalLegendSelected && legendPoint != null) {
        Rectangle2D screenArea = getScreenDataArea();
        if (point.getX() < screenArea.getMaxX()) {
            internalLegendSetup.setRect(
                    screenArea.getMaxX() - point.getX(), internalLegendSetup.getY(), screenArea.getMaxX()
                            - internalLegendSetup.getX() + internalLegendSetup.getWidth() - point.getX(),
                    internalLegendSetup.getHeight());
        }/*w  w  w .j  ava 2  s.com*/
    }
}

From source file:com.vgi.mafscaling.LogView.java

private void createGraghPanel() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);//from w  ww .  ja v a 2  s. com
    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setPopupMenu(null);
    chart.setBackgroundPaint(new Color(60, 60, 65));

    rpmDataset = new XYSeriesCollection();
    rpmPlotRenderer = new XYLineAndShapeRenderer();
    dataset = new XYSeriesCollection();
    plotRenderer = new XYLineAndShapeRenderer();

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickLabelPaint(Color.WHITE);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickLabelPaint(Color.WHITE);
    yAxis.setAutoRangeIncludesZero(false);
    NumberAxis y2Axis = new NumberAxis();
    y2Axis.setTickLabelsVisible(false);
    y2Axis.setTickLabelPaint(Color.WHITE);
    y2Axis.setAutoRangeIncludesZero(false);

    plot = chartPanel.getChart().getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(new Color(80, 80, 85));

    plot.setDataset(0, rpmDataset);
    plot.setRenderer(0, rpmPlotRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    plot.setDataset(1, dataset);
    plot.setRenderer(1, plotRenderer);
    plot.setRangeAxis(1, y2Axis);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    LegendTitle legend = new LegendTitle(plot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemPaint(Color.WHITE);
    chart.addLegend(legend);

    xyMarker = new XYDomainMutilineAnnotation();
    plot.addAnnotation(xyMarker);

    chartMouseListener = new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
                Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
                double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
                boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                if (setMarkers(x, isLeft)) {
                    try {
                        int selectedCol = logDataTable.getTable().getSelectedColumn();
                        if (selectedCol < 0)
                            selectedCol = 0;
                        if (logPlayWindow == null || startMarker != null || endMarker != null) {
                            logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
                            logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
                        } else {
                            logPlayWindow.setProgressBar((int) x);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            if (logPlayWindow == null)
                return;
            if (xyMarker.count() == 0)
                return;
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
            double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
            if (x < 0 || (int) x >= logDataTable.getRowCount())
                return;
            if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
                if (startMarker == null) {
                    startMarker = new ValueMarker(x);
                    startMarker.setPaint(Color.GREEN);
                    startMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(startMarker);
                } else {
                    plot.removeDomainMarker(startMarker);
                    startMarker = null;
                }
            } else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
                if (endMarker == null) {
                    endMarker = new ValueMarker(x);
                    endMarker.setPaint(Color.GREEN);
                    endMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(endMarker);
                } else {
                    plot.removeDomainMarker(endMarker);
                    endMarker = null;
                }
            }
            chartPanel.repaint();
            logPlayWindow.setStartEndArea(startMarker, endMarker);
        }
    };

    chartPanel.addChartMouseListener(chartMouseListener);
}