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:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

protected void drawSeriesLine(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;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = (orientation == PlotOrientation.HORIZONTAL) ? dataArea.getHeight() : 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 closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    int intervalCount = 0;
    int badPoints = 0;
    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)) {
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println("Breakpoint 1: leaving interval");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalStartX = 0.0f;
                float intervalEndX = 0.0f;
                float intervalStartY = 0.0f;
                float intervalEndY = 0.0f;
                float currentX = 0.0f;
                float currentY = 0.0f;
                float lastFX = 0.0f;
                float lastFY = 0.0f;

                //first set some variables
                if (orientation == PlotOrientation.VERTICAL) {
                    intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    currentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                } else {
                    intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentX = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFX = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                    currentY = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                }// ww w .  java2 s  .  co  m
                if ((lowY - highY) < 1) {
                    //System.out.println("Breakpoint 2: setting lastPointInInterval");
                    lastPointInInterval = false;
                }
                //System.out.println("Breakpoint 3: lastPointInInterval: " +lastPointInInterval);
                if ((lowY < highY)) {
                    intervalCount++;
                    //System.out.println("Breakpoint 4: adding segment to interval path:" );
                    //System.out.println("xStart" + intervalStartX + ", yStart " + intervalStartY + ", xEnd " + intervalEndX + ", yEnd " + intervalEndY);
                    s.intervalPath.moveTo(intervalStartX, intervalStartY);
                    s.intervalPath.lineTo(intervalEndX, intervalEndY);
                    lastIntervalDone = true;
                }

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood) {//last point not valid --
                    badPoints++;
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(currentX, currentY);
                    }
                } 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 (lastPointVisible && !lastPointInInterval) {
                        s.seriesPath.lineTo(currentX, currentY);
                    } //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.moveTo(lastFX, lastFY);
                        s.seriesPath.lineTo(currentX, currentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = 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 intervalStartX = 0.0f;
            float intervalEndX = 0.0f;
            float intervalStartY = 0.0f;
            float intervalEndY = 0.0f;
            if (orientation == PlotOrientation.VERTICAL) {
                intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            } else {
                intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            }
            intervalCount++;
            s.intervalPath.moveTo(intervalStartX, intervalStartY);
            s.intervalPath.lineTo(intervalEndX, 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);
    //System.out.println("Interval count " + intervalCount);
    //System.out.println("Bad points " + badPoints);
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * @param selection .//from   w w  w .  ja  v a2 s  .  c o  m
 * @return range[] rangos del rectangulo
 */
public Range[] getRange(Rectangle2D selection) {

    Range[] rangos = new Range[2];

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof ScatterPlotChart) {
            ScatterPlotChart z = (ScatterPlotChart) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                rangos[0] = z.getRangeX(vLower, vUpper, plotInfo, selectOrigin);
                rangos[1] = z.getRangeY(hLower, hUpper, plotInfo, selectOrigin);
            } else {
                // devolver las coordenadas del rectangulo.
                rangos[0] = z.getRangeX(hLower, hUpper, plotInfo, selectOrigin);
                rangos[1] = z.getRangeY(vLower, vUpper, plotInfo, selectOrigin);
            }
        }

    }

    return rangos;
}

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

/**
 * Zooms in on a selected region./*from   w  w  w .  j av a  2  s. com*/
 *
 * @param selection  the selected region.
 */
public void zoom(Rectangle2D selection) {

    double hLower = 0.0;
    double hUpper = 0.0;
    double vLower = 0.0;
    double vUpper = 0.0;

    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        Rectangle2D scaledDataArea = getScaledDataArea();
        hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomHorizontalAxes(hLower, hUpper);
            plot.zoomVerticalAxes(vLower, vUpper);
        }

    }

}

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

@Override
public void moveSelectedMask(int direction) {
    Abstract2DMask selectedMask = getSelectedMask();
    if (selectedMask == null) {
        return;//from www  .j a  va  2  s  . c  o m
    }
    double blockWidth = 0;
    double blockHeight = 0;
    try {
        XYBlockRenderer render = (XYBlockRenderer) ((XYPlot) getChart().getPlot()).getRenderer();
        blockWidth = render.getBlockWidth();
        blockHeight = render.getBlockHeight();
        if (getChart().getXYPlot().getDomainAxis().isInverted()) {
            blockWidth = -blockHeight;
        }
        if (getChart().getXYPlot().getRangeAxis().isInverted()) {
            blockHeight = -blockHeight;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
    Rectangle2D frame = selectedMask.getRectangleFrame();
    switch (direction) {
    case SWT.ARROW_UP:
        selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), frame.getMinY() + blockHeight,
                frame.getWidth(), frame.getHeight()));
        break;
    case SWT.ARROW_LEFT:
        selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX() - blockWidth, frame.getMinY(),
                frame.getWidth(), frame.getHeight()));
        break;
    case SWT.ARROW_RIGHT:
        selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX() + blockWidth, frame.getMinY(),
                frame.getWidth(), frame.getHeight()));
        break;
    case SWT.ARROW_DOWN:
        selectedMask.setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), frame.getMinY() - blockHeight,
                frame.getWidth(), frame.getHeight()));
        break;
    default:
        break;
    }
    repaint();
    fireMaskUpdateEvent(getSelectedMask());
}

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

private void moveMask(Point2D point) {
    if (maskMovePoint != null && getSelectedMask() != null) {
        Rectangle2D frame = getSelectedMask().getRectangleFrame();
        getSelectedMask().setRectangleFrame(new Rectangle2D.Double(
                frame.getMinX() + point.getX() - maskMovePoint.getX(),
                frame.getMinY() + point.getY() - maskMovePoint.getY(), frame.getWidth(), frame.getHeight()));
        maskMovePoint = point;//from   ww w  . j  a va 2  s. co  m
        fireMaskUpdateEvent(getSelectedMask());
    }
}

From source file:org.geoserver.wps.gs.download.DownloadProcessTest.java

/**
 * Test download of raster data. The output is scaled to fit exactly the provided size.
 * //from   ww w.j  a  v a2 s. c  o  m
 * @throws Exception the exception
 */
@Test
public void testDownloadScaledRaster() throws Exception {
    // Estimator process for checking limits
    DownloadEstimatorProcess limits = new DownloadEstimatorProcess(new StaticDownloadServiceConfiguration(),
            getGeoServer());
    final WPSResourceManager resourceManager = getResourceManager();
    // Creates the new process for the download
    DownloadProcess downloadProcess = new DownloadProcess(getGeoServer(), limits, resourceManager);

    ///////////////////////////////////////
    //      test full coverage           //
    ///////////////////////////////////////

    // Download the coverage as tiff
    File rasterZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName
            null, // filter
            "image/tiff", // outputFormat
            null, // targetCRS
            CRS.decode("EPSG:4326", true), // roiCRS
            null, // roi
            false, // cropToGeometry
            null, // interpolation
            80, // targetSizeX
            80, // targetSizeY
            null, // bandSelectIndices
            new NullProgressListener() // progressListener
    );

    // Final checks on the result
    Assert.assertNotNull(rasterZip);
    GeoTiffReader reader = null;
    GridCoverage2D gc = null;
    try {
        final File[] tiffFiles = extractTIFFFile(rasterZip);
        Assert.assertNotNull(tiffFiles);
        Assert.assertTrue(tiffFiles.length > 0);
        reader = new GeoTiffReader(tiffFiles[0]);
        gc = reader.read(null);

        Assert.assertNotNull(gc);

        // check coverage size
        Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange();
        Assert.assertEquals(80, Math.round(originalGridRange.getWidth()));
        Assert.assertEquals(80, Math.round(originalGridRange.getHeight()));

        // check envelope
        Assert.assertEquals(-130.8866985, gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6);
        Assert.assertEquals(48.5552613, gc.getEnvelope().getLowerCorner().getOrdinate(1), 1E-6);
        Assert.assertEquals(-123.8830077, gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6);
        Assert.assertEquals(54.1420339, gc.getEnvelope().getUpperCorner().getOrdinate(1), 1E-6);
    } finally {
        if (gc != null) {
            CoverageCleanerCallback.disposeCoverage(gc);
        }
        if (reader != null) {
            reader.dispose();
        }

        // clean up process
        resourceManager.finished(resourceManager.getExecutionId(true));
    }

    ///////////////////////////////////////
    //      test partial input           //
    ///////////////////////////////////////

    // Download the coverage as tiff
    File largerZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName
            null, // filter
            "image/tiff", // outputFormat
            null, // targetCRS
            CRS.decode("EPSG:4326", true), // roiCRS
            null, // roi
            false, // cropToGeometry
            null, // interpolation
            160, // targetSizeX
            null, // targetSizeY not specified, will be calculated based on targetSizeX and aspect ratio of the original image
            null, // bandSelectIndices
            new NullProgressListener() // progressListener
    );

    // Final checks on the result
    Assert.assertNotNull(largerZip);
    try {
        final File[] tiffFiles = extractTIFFFile(largerZip);
        Assert.assertNotNull(tiffFiles);
        Assert.assertTrue(tiffFiles.length > 0);
        reader = new GeoTiffReader(tiffFiles[0]);
        gc = reader.read(null);

        Assert.assertNotNull(gc);

        // check coverage size
        Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange();
        Assert.assertEquals(160, Math.round(originalGridRange.getWidth()));
        Assert.assertEquals(160, Math.round(originalGridRange.getHeight()));
    } finally {
        if (gc != null) {
            CoverageCleanerCallback.disposeCoverage(gc);
        }
        if (reader != null) {
            reader.dispose();
        }

        // clean up process
        resourceManager.finished(resourceManager.getExecutionId(true));
    }

    //////////////////////////////////
    //      test with ROI           //
    //////////////////////////////////

    Polygon roi = (Polygon) new WKTReader2().read(
            "POLYGON (( -127.57473954542964 54.06575021619523, -130.88669845369998 52.00807146727025, -129.50812897394974 49.85372324691927, -130.5300633861675 49.20465679591609, -129.25955033314003 48.60392508062591, -128.00975216684665 50.986137055052474, -125.8623089087404 48.63154492960477, -123.984159178178 50.68231871628503, -126.91186316993704 52.15307567440926, -125.3444367403868 53.54787804784162, -127.57473954542964 54.06575021619523 ))");
    roi.setSRID(4326);

    // Download the coverage as tiff
    File resampledZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName
            null, // filter
            "image/tiff", // outputFormat
            null, // targetCRS
            CRS.decode("EPSG:4326", true), // roiCRS
            roi, // roi
            true, // cropToGeometry
            null, // interpolation
            80, // targetSizeX
            80, // targetSizeY
            null, // bandSelectIndices
            new NullProgressListener() // progressListener
    );

    // Final checks on the result
    Assert.assertNotNull(resampledZip);
    try {
        final File[] tiffFiles = extractTIFFFile(resampledZip);
        Assert.assertNotNull(tiffFiles);
        Assert.assertTrue(tiffFiles.length > 0);
        reader = new GeoTiffReader(tiffFiles[0]);
        gc = reader.read(null);

        Assert.assertNotNull(gc);

        // check coverage size
        Rectangle2D originalGridRange = (GridEnvelope2D) reader.getOriginalGridRange();
        Assert.assertEquals(80, Math.round(originalGridRange.getWidth()));
        Assert.assertEquals(80, Math.round(originalGridRange.getHeight()));

        // check envelope
        Assert.assertEquals(-130.88669845369998, gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6);
        Assert.assertEquals(48.611129008700004, gc.getEnvelope().getLowerCorner().getOrdinate(1), 1E-6);
        Assert.assertEquals(-123.95304462109999, gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6);
        Assert.assertEquals(54.0861661371, gc.getEnvelope().getUpperCorner().getOrdinate(1), 1E-6);
    } finally {
        if (gc != null) {
            CoverageCleanerCallback.disposeCoverage(gc);
        }
        if (reader != null) {
            reader.dispose();
        }

        // clean up process
        resourceManager.finished(resourceManager.getExecutionId(true));
    }
}

From source file:probe.com.view.body.quantdatasetsoverview.quantproteinstabsheet.studies.ProteinStudyComparisonScatterPlotLayout.java

/**
 * Creates a sample jFreeChart./*from  ww w . j  a  va2 s .c  o m*/
 *
 * @param dataset the dataset.
 *
 * @return The jFreeChart.
 */
private void generateScatterplotchart(DiseaseGroupsComparisonsProteinLayout cp, int w, int h) {

    final XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries downSer = new XYSeries(0);
    XYSeries stableSer = new XYSeries(1);
    XYSeries upSer = new XYSeries(2);

    XYSeries novalueProvidedSer = new XYSeries(3);

    XYSeries downSerII = new XYSeries(4);
    XYSeries stableSerII = new XYSeries(5);
    XYSeries upSerII = new XYSeries(6);
    XYSeries novalueProvidedSerII = new XYSeries(7);

    //        XYSeries plusSeries = new XYSeries(6);
    double downCounter = 1;
    double stableCounter = 3;
    double upCounter = 5;
    double novalueProvidedCounter = 3;

    patientGroupsNumToDsIdMap.clear();

    final Map<Integer, int[]> paTGrNumbtrendMap = new HashMap<Integer, int[]>();
    double maxPatNumber = -1.0;
    for (String protTrend : cp.getPatientsNumToTrindMap().keySet()) {
        List<Integer> patNums = cp.getPatientsNumToTrindMap().get(protTrend);
        int coun = 0;
        for (int i : patNums) {
            if (i > maxPatNumber) {
                maxPatNumber = i;
            }
            if (!patientGroupsNumToDsIdMap.containsKey(i)) {
                ComparisonDetailsBean pGr = new ComparisonDetailsBean();
                patientGroupsNumToDsIdMap.put(i, pGr);

            }
            if (!paTGrNumbtrendMap.containsKey(i)) {
                int[] values = new int[4];
                paTGrNumbtrendMap.put(i, values);
            }

            int[] values = paTGrNumbtrendMap.get(i);
            ComparisonDetailsBean pGr = patientGroupsNumToDsIdMap.get(i);
            if (protTrend.equalsIgnoreCase("noValueProvided")) {
                values[3] = values[3] + 1;
                pGr.addNovalueProvided(cp.getDSID(3, coun));

            } else if (protTrend.equalsIgnoreCase("up")) {
                values[2] = values[2] + 1;

                pGr.addUpRegulated(cp.getDSID(0, coun));

            } else if (protTrend.equalsIgnoreCase("down")) {
                values[0] = values[0] + 1;
                pGr.addDownRegulated(cp.getDSID(2, coun));
            } else {
                values[1] = values[1] + 1;
                pGr.addNotRegulated(cp.getDSID(1, coun));
            }
            paTGrNumbtrendMap.put(i, values);
            patientGroupsNumToDsIdMap.put(i, pGr);
            coun++;
        }

    }

    for (int i : paTGrNumbtrendMap.keySet()) {
        int[] values = paTGrNumbtrendMap.get(i);
        if ((values[2] > 1)) {
            upSer.add(upCounter, i);
            upSerII.add(upCounter, i);
        } else if ((values[2] == 1)) {
            upSer.add(upCounter, i);
        }
        if ((values[1] == 1)) {
            stableSer.add(stableCounter, i);
        } else if ((values[1] > 1)) {
            stableSer.add(stableCounter, i);
            stableSerII.add(stableCounter, i);
        }

        if ((values[0] > 1)) {
            downSer.add(downCounter, i);
            downSerII.add(downCounter, i);
        } else if ((values[0] == 1)) {
            downSer.add(downCounter, i);
        }
        if ((values[3] == 1)) {
            novalueProvidedSer.add(novalueProvidedCounter, i);
        } else if ((values[3] > 1)) {
            novalueProvidedSer.add(stableCounter, i);
            novalueProvidedSerII.add(stableCounter, i);
        }

    }

    dataset.addSeries(downSer);
    dataset.addSeries(stableSer);
    dataset.addSeries(upSer);
    dataset.addSeries(novalueProvidedSer);
    dataset.addSeries(downSerII);
    dataset.addSeries(stableSerII);
    dataset.addSeries(upSerII);
    dataset.addSeries(novalueProvidedSerII);
    //        if((downSerII.getItemCount()+stableSerII.getItemCount()+upSerII.getItemCount()+downSer.getItemCount()+stableSer.getItemCount()+upSer.getItemCount())==0)
    //            return;
    //        dataset.addSeries(plusSeries);
    final String[] labels = new String[] { " ", ("Decreased (" + cp.getSignificantDown() + ")"), " ",
            ("Equal (" + cp.getStable() + ")"), " ", ("Increased (" + cp.getSignificantUp() + ")"), "" };
    final Color[] labelsColor = new Color[] { Color.LIGHT_GRAY, new Color(80, 183, 71), Color.LIGHT_GRAY,
            new Color(1, 141, 244), Color.LIGHT_GRAY, Color.RED, Color.LIGHT_GRAY };
    final SymbolAxis domainAxis = new SymbolAxis("X", labels) {

        @Override
        protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea,
                boolean firstGridBandIsDark, List ticks) {
            List udatedTicksList = new ArrayList();

            for (Object tick : ticks) {
                if (tick.toString().equalsIgnoreCase(labels[custTrend + 1])) {
                    udatedTicksList.add(tick);
                }
            }
            //                System.out.println("at ticks is "+ticks);
            //                 System.out.println("at udatedTicksList is "+udatedTicksList);
            //                int factor = (int) ((plotArea.getHeight() / 5) * 0.25);
            //
            //                Rectangle2D up = new Rectangle((int) drawArea.getX(), (int) drawArea.getY() - factor, (int) drawArea.getWidth(), (int) drawArea.getHeight());
            //                Rectangle2D pa = new Rectangle((int) plotArea.getX(), (int) plotArea.getY() - factor, (int) plotArea.getWidth(), (int) plotArea.getHeight());

            super.drawGridBandsVertical(g2, drawArea, plotArea, firstGridBandIsDark, udatedTicksList); //To change body of generated methods, choose Tools | Templates.
        }

        int x = 0;

        @Override
        public Paint getTickLabelPaint() {
            if (x >= labels.length) {
                x = 0;
            }
            return labelsColor[x++];
        }

    };
    domainAxis.setAutoRangeIncludesZero(false);
    Font f = new Font("Verdana", Font.PLAIN, 11);
    domainAxis.setTickLabelFont(f);
    domainAxis.setAutoRange(false);
    domainAxis.setLabel(null);

    //        domainAxis.setGridBandsVisible(false);
    String xTile = "#Patients";

    JFreeChart jFreeChart = ChartFactory.createScatterPlot(null, null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            false, // include legend
            false, // tooltips?
            false // URLs?
    );
    XYPlot plot1 = (XYPlot) jFreeChart.getPlot();
    XYPlot xyplot = new XYPlot(dataset, plot1.getDomainAxis(), plot1.getRangeAxis(), plot1.getRenderer()) {

        @Override
        public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea, List ticks) {

            if (custTrend == -1) {
                super.drawDomainTickBands(g2, dataArea, ticks);
                return;

            }
            List udatedTicksList = new ArrayList();
            for (Object tick : ticks) {
                if (tick.toString().equalsIgnoreCase(labels[custTrend + 1])) {
                    udatedTicksList.add(tick);
                }
            }
            Rectangle2D up;
            int factor = (int) ((dataArea.getHeight() / 5) * 0.5);
            if (custTrend == 4) {
                up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() + factor,
                        (int) dataArea.getWidth(), (int) dataArea.getHeight());

            } else if (custTrend == 2) {
                up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() - factor,
                        (int) dataArea.getWidth(), (int) dataArea.getHeight());

            } else {
                up = new Rectangle((int) dataArea.getX(), (int) dataArea.getY() - factor,
                        (int) dataArea.getWidth(), (int) dataArea.getHeight());
            }

            super.drawDomainTickBands(g2, up, udatedTicksList); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
            super.drawDomainGridlines(g2, dataArea, ticks); //To change body of generated methods, choose Tools | Templates.
        }

        private int x = 0;

        @Override
        public Paint getDomainGridlinePaint() {
            if (x >= labels.length) {
                x = 0;
            }
            if (x == 1 || x == 3 || x == 5) {
                x++;
                return Color.WHITE;
            } else {
                x++;
                return super.getDomainGridlinePaint(); //To change body of generated methods, choose Tools | Templates.
            }
        }
    };
    if (custTrend != -1) {
        domainAxis.setGridBandsVisible(true);
        if (custTrend == 4) {
            domainAxis.setGridBandPaint(Color.decode("#ffe5e5"));
            xyplot.setDomainTickBandPaint(Color.decode("#ffe5e5"));
            domainAxis.setGridBandAlternatePaint(Color.decode("#ffe5e5"));
        } else if (custTrend == 0) {
            domainAxis.setGridBandPaint(Color.decode("#e5ffe5"));
            xyplot.setDomainTickBandPaint(Color.white);
        } else if (custTrend == 2) {
            domainAxis.setGridBandPaint(Color.decode("#e6f4ff"));
            xyplot.setDomainTickBandPaint(Color.white);
        }

    } else {
        domainAxis.setGridBandsVisible(false);
    }
    xyplot.setOrientation(PlotOrientation.HORIZONTAL);
    JFreeChart tempScatterPlot = new JFreeChart(xyplot);
    tempScatterPlot.setBackgroundPaint(Color.WHITE);
    tempScatterPlot.getLegend().setVisible(false);
    Color c = new Color(242, 242, 242);
    xyplot.setDomainAxis(domainAxis);
    xyplot.setDomainGridlinePaint(Color.GRAY);
    xyplot.setDomainGridlinesVisible(true);
    xyplot.setRangeGridlinesVisible(true);
    xyplot.setRangeGridlinePaint(Color.GRAY);
    xyplot.setOutlinePaint(Color.GRAY);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    ValueAxis va = xyplot.getDomainAxis();
    va.setAutoRange(false);
    va.setMinorTickCount(0);
    va.setVisible(true);
    maxPatNumber = Math.ceil(maxPatNumber / 100.0) * 100;
    xyplot.getRangeAxis().setRange(0, maxPatNumber);
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setLabel(xTile);
    rangeAxis.setLabelFont(f);
    rangeAxis.setLabelPaint(Color.GRAY);

    va.setRange(0, 6);
    xyplot.setBackgroundPaint(Color.WHITE);
    renderer.setUseOutlinePaint(true);

    Color c0 = new Color(80, 183, 71);
    renderer.setSeriesPaint(0, c0);
    renderer.setSeriesOutlinePaint(0, Color.WHITE);

    Color c1 = new Color(1, 141, 244);
    renderer.setSeriesPaint(1, c1);
    renderer.setSeriesOutlinePaint(1, Color.WHITE);

    Color c2 = new Color(204, 0, 0);
    renderer.setSeriesPaint(2, c2);
    renderer.setSeriesOutlinePaint(2, Color.WHITE);

    renderer.setSeriesPaint(3, Color.decode("#b5babb"));
    renderer.setSeriesOutlinePaint(3, Color.WHITE);

    renderer.setSeriesPaint(4, new Color(150, 212, 145));
    renderer.setSeriesOutlinePaint(4, new Color(150, 212, 145));

    renderer.setSeriesPaint(5, new Color(103, 187, 248));
    renderer.setSeriesOutlinePaint(5, new Color(103, 187, 248));

    renderer.setSeriesPaint(6, new Color(224, 102, 102));
    renderer.setSeriesOutlinePaint(6, new Color(224, 102, 102));

    renderer.setSeriesPaint(7, Color.decode("#b5babb"));
    renderer.setSeriesOutlinePaint(7, Color.GRAY);

    //        renderer.setSeriesPaint(6, Color.BLACK);
    //        renderer.setSeriesOutlinePaint(6, Color.BLACK);
    Shape downArr = ShapeUtilities.createDownTriangle(7f);
    Shape notRShape = ShapeUtilities.createDiamond(7f);
    Shape upArr = ShapeUtilities.createUpTriangle(7);

    Shape downArrII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createDownTriangle(6f), 5, -5);
    Shape notRShapeII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createDiamond(6f), 0, -7);
    Shape upArrII = ShapeUtilities.createTranslatedShape(ShapeUtilities.createUpTriangle(6f), 4, -4);

    //        Shape plus = ShapeUtilities.createTranslatedShape(ShapeUtilities.createRegularCross(3f, 0.4f), 11, -7);
    renderer.setSeriesShape(0, downArr);
    renderer.setSeriesShape(1, notRShape);
    renderer.setSeriesShape(2, upArr);

    renderer.setSeriesShape(3, notRShape);

    renderer.setSeriesShape(4, downArrII);
    renderer.setSeriesShape(5, notRShapeII);
    renderer.setSeriesShape(6, upArrII);

    renderer.setSeriesShape(7, notRShapeII);
    //       renderer.setSeriesShape(6, plus);

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new SymbolicXYItemLabelGenerator() {
        private final int[] indexer = new int[] { 0, 1, 2, 3, 0, 1, 2, 3 };

        @Override
        public String generateLabel(XYDataset dataset, int series, int category) {
            if (series > 3) {
                int patNumber = (int) dataset.getYValue(series, category);
                //                    int trend = (int) dataset.getXValue(series, category);
                if (series == 7 || series == 5) {
                    return "\t  " + paTGrNumbtrendMap.get(patNumber)[indexer[series]];
                } else {
                    return "\t   " + paTGrNumbtrendMap.get(patNumber)[indexer[series]];
                }

            }

            return ""; //To change body of generated methods, choose Tools | Templates.
        }

    });
    ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT,
            TextAnchor.TOP_LEFT, 0.0);

    renderer.setSeriesPositiveItemLabelPosition(4, position);
    renderer.setSeriesPositiveItemLabelPosition(5, position);
    renderer.setSeriesPositiveItemLabelPosition(6, position);
    renderer.setSeriesPositiveItemLabelPosition(7, position);

    renderer.setBaseItemLabelFont(f);

    tempScatterPlot.setBorderVisible(false);

    xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE);

    heighlightedScatterPlottImgUrl = saveToFile(tempScatterPlot, w, h, defaultScatterPlotRenderingInfo);

    xyplot.setBackgroundPaint(Color.WHITE);
    defaultScatterPlottImgUrl = saveToFile(tempScatterPlot, w, h, defaultScatterPlotRenderingInfo);

    //        xyplot.setBackgroundPaint(c);

    if (custTrend != -1) {
        domainAxis.setGridBandsVisible(true);
        if (custTrend == 4) {
            domainAxis.setGridBandPaint(Color.decode("#ffe5e5"));
            xyplot.setDomainTickBandPaint(Color.decode("#ffe5e5"));
            domainAxis.setGridBandAlternatePaint(Color.decode("#ffe5e5"));
        } else if (custTrend == 0) {
            domainAxis.setGridBandPaint(Color.decode("#e5ffe5"));
            xyplot.setDomainTickBandPaint(c);
        } else if (custTrend == 2) {
            domainAxis.setGridBandPaint(Color.decode("#e6f4ff"));
            xyplot.setDomainTickBandPaint(c);
        }

    }

    String textTitle = comparisonTitle.getValue().split("bold;'>")[1].replace("</font>", "");
    TextTitle title = new TextTitle(textTitle, f);

    scatterPlot = new JFreeChart(xyplot);
    scatterPlot.setTitle(title);

    scatterPlot.setBorderVisible(false);
    scatterPlot.setBackgroundPaint(Color.WHITE);
    scatterPlot.getLegend().setVisible(false);
    dsKeyDatasetMap.clear();
    for (int i = 0; i < defaultScatterPlotRenderingInfo.getEntityCollection().getEntityCount(); i++) {
        final ChartEntity entity = defaultScatterPlotRenderingInfo.getEntityCollection().getEntity(i);
        if (entity instanceof XYItemEntity) {

            int x = ((XYItemEntity) entity).getSeriesIndex();
            int y = ((XYItemEntity) entity).getItem();

            if (((XYItemEntity) entity).getDataset().getYValue(x,
                    y) > (int) ((XYItemEntity) entity).getDataset().getYValue(x, y)) {
                continue;
            }
            if (((XYItemEntity) entity).getSeriesIndex() > 3) {

                continue;
            }

            String[] arr = ((XYItemEntity) entity).getShapeCoords().split(",");
            int xSer = Integer.valueOf(arr[0]);
            int ySer = Integer.valueOf(arr[1]);
            int ySerEnd = Integer.valueOf(arr[3]);
            int patGrNumber = (int) ((XYItemEntity) entity).getDataset().getYValue(x, y);
            int trend = Integer.valueOf(((XYItemEntity) entity).getDataset()
                    .getSeriesKey(((XYItemEntity) entity).getSeriesIndex()).toString());

            ComparisonDetailsBean cpDetails = patientGroupsNumToDsIdMap.get(patGrNumber);
            List<Integer> dsList = cpDetails.getRegulatedList(trend);
            StringBuilder sb = new StringBuilder();

            for (int dsId : dsList) {
                QuantDatasetObject ds;

                sb.append("<h4>").append((Quant_Central_Manager.getFullQuantDatasetMap().get(dsId)).getAuthor())
                        .append(" ")
                        .append((Quant_Central_Manager.getFullQuantDatasetMap().get(dsId)).getYear())
                        .append("<h4/>");
                sb.append("<p></p>");
                ds = Quant_Central_Manager.getFullQuantDatasetMap().get(dsId);

                dsKeyDatasetMap.put("_-_" + dsId + "_-_" + comparisonProtein.getProteinAccssionNumber() + "_-_",
                        ds);
            }
            String tooltip = sb.toString().substring(0, sb.toString().length() - 7);
            SquaredDot square = new SquaredDot("squared");
            if (paTGrNumbtrendMap.get(patGrNumber)[trend] > 1) {
                square.setWidth(20 + "px");
                square.setHeight(15 + "px");
            } else {
                square.setWidth(10 + "px");
                square.setHeight(10 + "px");
            }
            square.setDescription(tooltip);
            square.setParam("trend", trend);
            square.setParam("pGrNumber", patGrNumber);
            int top = (ySer - 4);
            if (ySer > ySerEnd) {
                top = ySerEnd - 3;
            }
            defaultChartLayout.addComponent(square, "left: " + (xSer - 5) + "px; top: " + top + "px;");
        }
    }

}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Is mouse on top axis/*from w  w  w  .  j a va  2 s.  c o m*/
 *
 * @param mouseEvent the event
 *
 * @return On top axis
 */
private boolean isOnTopDomainAxis(MouseEvent mouseEvent) {
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    if (mouseEvent.getX() < dataArea.getX()) {
        return false;
    }
    if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) {
        return false;
    }
    double top = dataArea.getY();
    return mouseEvent.getY() <= top + 20;
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Is mouse on bottom axis/*ww  w .  j  av  a 2  s  .  c o m*/
 *
 * @param mouseEvent the event
 *
 * @return on bottom axis
 */
private boolean isOnBottomDomainAxis(MouseEvent mouseEvent) {
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    if (mouseEvent.getX() < dataArea.getX()) {
        return false;
    }
    if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) {
        return false;
    }

    double bottom = dataArea.getY() + dataArea.getHeight();
    return mouseEvent.getY() >= bottom - 20;
}

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

private int calcDropPosition(final AbstractElement destination, final Point dropPoint) {
    int result = DRAG_POSITION_UNKNOWN;
    if (destination.getClass() == ElementRoot.class) {
        result = dropPoint.getX() < destination.getBounds().getCenterX() ? DRAG_POSITION_LEFT
                : DRAG_POSITION_RIGHT;//from ww w.ja  v a 2s .co m
    } else {
        final boolean destinationIsLeft = destination.isLeftDirection();
        final Rectangle2D bounds = destination.getBounds();

        if (bounds != null && dropPoint != null) {
            final double edgeOffset = bounds.getWidth() * 0.2d;
            if (dropPoint.getX() >= (bounds.getX() + edgeOffset)
                    && dropPoint.getX() <= (bounds.getMaxX() - edgeOffset)) {
                result = dropPoint.getY() < bounds.getCenterY() ? DRAG_POSITION_TOP : DRAG_POSITION_BOTTOM;
            } else if (destinationIsLeft) {
                result = dropPoint.getX() < bounds.getCenterX() ? DRAG_POSITION_LEFT : DRAG_POSITION_UNKNOWN;
            } else {
                result = dropPoint.getX() > bounds.getCenterX() ? DRAG_POSITION_RIGHT : DRAG_POSITION_UNKNOWN;
            }
        }
    }
    return result;
}