Example usage for org.jfree.chart.plot XYPlot getRangeAxisEdge

List of usage examples for org.jfree.chart.plot XYPlot getRangeAxisEdge

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRangeAxisEdge.

Prototype

public RectangleEdge getRangeAxisEdge() 

Source Link

Document

Returns the edge for the primary range axis.

Usage

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private Point2D.Double _getPointForCandlestick(int plotIndex, int seriesIndex, int dataIndex) {
    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();
    final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
    final ValueAxis domainAxis = plot.getDomainAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

    final org.jfree.data.xy.DefaultHighLowDataset defaultHighLowDataset = (org.jfree.data.xy.DefaultHighLowDataset) plot
            .getDataset(seriesIndex);//  www .ja  v  a  2  s  . co  m

    if (dataIndex >= defaultHighLowDataset.getItemCount(0)) {
        /* Not ready yet. */
        return null;
    }

    final double xValue = defaultHighLowDataset.getXDate(0, dataIndex).getTime();
    final double yValue = defaultHighLowDataset.getCloseValue(0, dataIndex);
    final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(plotIndex)
            .getDataArea();
    final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge);
    final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge);
    // Use Double version, to avoid from losing precision.
    return new Point2D.Double(xJava2D, yJava2D);
}

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

/**    
* Initialises the renderer and returns a state object that should be     
* passed to all subsequent calls to the drawItem() method.  Here we     
* calculate the Java2D y-coordinate for zero, since all the bars have     
* their bases fixed at zero.    //w ww.j a  v a 2  s  .c  om
*    
* @param g2  the graphics device.    
* @param dataArea  the area inside the axes.    
* @param plot  the plot.    
* @param dataset  the data.    
* @param info  an optional info collection object to return data back to     
*              the caller.    
*    
* @return A state object.    
*/
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset,
        PlotRenderingInfo info) {

    XYBarRendererState state = new XYBarRendererState(info);
    ValueAxis rangeAxis = plot.getRangeAxisForDataset(plot.indexOf(dataset));
    state.setG2Base(rangeAxis.valueToJava2D(this.base, dataArea, plot.getRangeAxisEdge()));
    return state;

}

From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java

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) {

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);

    double value0;
    double value1;
    if (getUseYInterval()) {
        value0 = intervalDataset.getStartYValue(series, item);
        value1 = intervalDataset.getEndYValue(series, item);
    } else {/*from w w  w .j ava2  s  . co m*/
        value0 = getBase();
        value1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double x1 = intervalDataset.getStartXValue(series, item);
    double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);

    double x2 = intervalDataset.getEndXValue(series, item);
    double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation);

    double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1));
    double translatedHeight = Math.abs(translatedValue0 - translatedValue1);

    /*
     * With BlueDragon, this value is always false so it's safe to comment this
     * code out. if (this.centerBarAtStartValue) { translatedX1 -=
     * translatedWidth / 2; }
     */

    PlotOrientation orientation = plot.getOrientation();
    if (getMargin() > 0.0) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            // BEGIN fix for horizontal bar charts that have a margin
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 - cut / 2;
            // END fix for horizontal bar charts that have a margin
        } else if (orientation == PlotOrientation.VERTICAL) {
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 + cut / 2;
        }
    }

    int numSeries = dataset.getSeriesCount();
    double seriesBarWidth = translatedWidth / numSeries;

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1),
                translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {

        bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series,
                Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight);

    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) {
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(bar);
    }

    // TODO: we need something better for the item labels
    if (isItemLabelVisible(series, item)) {
        // Change parameters passed to this method to call our local version
        drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0);
    }

    // add an entity for the item...
    if (info != null) {
        EntityCollection entities = info.getOwner().getEntityCollection();
        if (entities != 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(bar, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:org.trade.ui.chart.renderer.PivotRenderer.java

/**
 * Draws the visual representation of a single data item.
 * //  ww w  .  ja  v  a 2 s.c  o  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 (horizontal) axis.
 * @param rangeAxis
 *            the range (vertical) 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.
 * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D,
 *      XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot,
 *      ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)
 */
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) {

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

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (!Double.isNaN(y)) {
        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
        double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

        g2.setPaint(getItemPaint(series, item));
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
        } else if (orientation == PlotOrientation.VERTICAL) {
            g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);

        PivotDataset pivotDataset = (PivotDataset) dataset;
        if (null != pivotDataset.getPivotSide(series, item)) {
            String ledgend = "Pivot";
            if (pivotDataset.getPivotSide(series, item).equals(Side.BOT)) {
                drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, 45d, x,
                        pivotDataset.getPivotValue(series, item), ledgend);
            } else {
                drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, -45d, x,
                        pivotDataset.getPivotValue(series, item), ledgend);
            }
        }
    }

}

From source file:org.mwc.cmap.grideditor.chart.DataPointsDragTracker.java

public void chartMouseMoved(final ChartMouseEvent event) {
    if (!myDragSubject.isEmpty()) {
        myChartPanel.forgetZoomPoints();

        // Rectangle clientArea = myChartPanel.getClientArea();
        // int screenX = event.getTrigger().getX() - clientArea.x;
        // int screenY = event.getTrigger().getY() - clientArea.y;

        // [IM] don't bother with sorting out the client area offset
        // - we've stopped using it in the FixedChartComposite calling method
        final int screenX = event.getTrigger().getX();
        final int screenY = event.getTrigger().getY();

        // deliberately switch axes for following line, now that we've switched
        // the axes to put time
        // down the LH side.
        final Point2D point2d = new Point2D.Double(screenY, screenX);
        final XYPlot xyplot = myChartPanel.getChart().getXYPlot();
        final ChartRenderingInfo renderingInfo = myChartPanel.getChartRenderingInfo();
        Rectangle2D dataArea = renderingInfo.getPlotInfo().getDataArea();

        // WORKAROUND: when the grid graph gets really wide, the labels on the
        // y-axis get stretched.
        // but, the dataArea value doesn't reflect this.
        // So, get the width values from the getScreenDataArea method - which
        // does reflect the scaling applied to the y axis.
        // - and all works well now.
        final Rectangle dataArea2 = myChartPanel.getScreenDataArea();
        dataArea = new Rectangle2D.Double(dataArea2.x, dataArea.getY(), dataArea2.width, dataArea.getHeight());

        final ValueAxis domainAxis = xyplot.getDomainAxis();
        final RectangleEdge domainEdge = xyplot.getDomainAxisEdge();
        final ValueAxis valueAxis = xyplot.getRangeAxis();
        final RectangleEdge valueEdge = xyplot.getRangeAxisEdge();
        double domainX = domainAxis.java2DToValue(point2d.getX(), dataArea, domainEdge);
        final double domainY = valueAxis.java2DToValue(point2d.getY(), dataArea, valueEdge);

        if (myAllowVerticalMovesOnly) {
            domainX = myDragSubject.getDraggedItem().getXValue();
        }/*ww  w.j a va 2 s  .  co  m*/

        if (!myDragSubject.isEmpty())
            myDragSubject.setProposedValues(domainX, domainY);
        myChartPanel.redrawCanvas();
    }
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

private void setXYValues(ChartMouseEvent cme) {

    double pointX = cme.getTrigger().getPoint().x;
    double pointY = cme.getTrigger().getPoint().y;

    Rectangle2D plotArea = getChartPanel().getScreenDataArea();
    XYPlot plot = (XYPlot) getChart().getPlot();
    Double chartX = plot.getDomainAxis().java2DToValue(pointX, plotArea, plot.getDomainAxisEdge());
    Double chartY = plot.getRangeAxis().java2DToValue(pointY, plotArea, plot.getRangeAxisEdge());

    if (!stillChanging) {
        mouseDownPoint = new Point2D.Double(chartX, chartY);
        stillChanging = true;/*from w w  w  .  j ava 2s .co m*/
    } else {
        mouseUpPoint = new Point2D.Double(chartX, chartY);
    }

    if (mouseDownPoint != null && mouseUpPoint != null) {

        double dn = mouseDownPoint.getX();
        double up = mouseUpPoint.getX();

        double x0 = Math.min(dn, up);
        double x1 = Math.max(dn, up);

        dn = mouseDownPoint.getY();
        up = mouseUpPoint.getY();

        double y0 = Math.min(dn, up);
        double y1 = Math.max(dn, up);

        setSelectionRange(x0, y0, x1, y1);
    }
}

From source file:com.att.aro.main.PacketPlots.java

/**
 * The utility method that creates the packet plots from a packet series map
 *//*from   www.j a v a  2  s .c  om*/
private XYPlot createPlot() {

    // Create the plot renderer
    YIntervalRenderer renderer = new YIntervalRenderer() {
        private static final long serialVersionUID = 1L;

        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) {

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

            IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

            double x = intervalDataset.getXValue(series, item);
            double yLow = intervalDataset.getStartYValue(series, item);
            double yHigh = intervalDataset.getEndYValue(series, item);

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

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

            Paint p = getItemPaint(series, item);
            Stroke s = getItemStroke(series, item);

            Line2D line = null;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                line = new Line2D.Double(yyLow, xx, yyHigh, xx);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line = new Line2D.Double(xx, yyLow, xx, yyHigh);
            }
            g2.setPaint(p);
            g2.setStroke(s);
            g2.draw(line);

            // add an entity for the item...
            if (entities != null) {
                if (entityArea == null) {
                    entityArea = line.getBounds();
                }
                String tip = null;
                XYToolTipGenerator generator = getToolTipGenerator(series, item);
                if (generator != null) {
                    tip = generator.generateToolTip(dataset, series, item);
                }
                XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null);
                entities.add(entity);
            }

        }

    };
    renderer.setAdditionalItemLabelGenerator(null);
    renderer.setBaseShape(new Rectangle());
    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setBasePaint(Color.GRAY);

    // Create the plot
    XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    plot.getRangeAxis().setVisible(false);

    return plot;
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Main entry point./*ww w  . j  av a 2  s  .  c  o  m*/
 * 
 * @param args
 * 
 * @throws IOException 
 * 
 */
public ProcessAllSwathcal() {

    // Path to AllSwathcal.dat file
    File allSwathcal = new File(
            "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat");

    // Read file contents into the List
    try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) {
        String sourceStr;
        while ((sourceStr = in.readLine()) != null) {
            Source source = Source.parseSource(sourceStr);
            if (source != null) {
                allSources.add(source);
            }
        }
    } catch (IOException e) {
    }

    logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat");

    // Initialise chart
    cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources));
    cmdPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            // Capture mouse click location, transform to graph coordinates and add
            // a point to the polygonal selection box.
            Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint());
            Rectangle2D plotArea = cmdPanel.getScreenDataArea();
            XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
            points.add(new double[] { chartX, chartY });
            cmdPanel.setChart(plotCmd());
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });

    // Create colour combo boxes
    final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters);

    // Set initial values
    magComboBox.setSelectedItem(magFilter);
    col1ComboBox.setSelectedItem(col1Filter);
    col2ComboBox.setSelectedItem(col2Filter);

    // Create an action listener for these
    ActionListener al = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == magComboBox) {
                magFilter = (Filter) magComboBox.getSelectedItem();
            }
            if (evt.getSource() == col1ComboBox) {
                col1Filter = (Filter) col1ComboBox.getSelectedItem();
            }
            if (evt.getSource() == col2ComboBox) {
                col2Filter = (Filter) col2ComboBox.getSelectedItem();
            }
            // Changed colour(s), so reset selection box coordinates
            points.clear();
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magComboBox.addActionListener(al);
    col1ComboBox.addActionListener(al);
    col2ComboBox.addActionListener(al);
    // Add a bit of padding to space things out
    magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Set up statistic sliders
    final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f");
    final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f");
    final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");
    final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");

    // Set intial values
    magErrMaxSlider.setValue(
            (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin)));
    chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin)));
    sharpMinSlider
            .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));
    sharpMaxSlider
            .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));

    // Set labels & initial values
    final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel());
    final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel());
    final JLabel sharpMinLabel = new JLabel(getSharpMinLabel());
    final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel());

    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == magErrMaxSlider) {
                // Compute max mag error from slider position
                double newMagErrMax = magErrorRangeMin
                        + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0);
                magErrMax = newMagErrMax;
                magErrMaxLabel.setText(getMagErrMaxLabel());
            }
            if (source == chi2MaxSlider) {
                // Compute Chi2 max from slider position
                double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0);
                chi2Max = newChi2Max;
                chi2MaxLabel.setText(getChi2MaxLabel());
            }
            if (source == sharpMinSlider) {
                // Compute sharp min from slider position
                double newSharpMin = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMin = newSharpMin;
                sharpMinLabel.setText(getSharpMinLabel());
            }
            if (source == sharpMaxSlider) {
                // Compute sharp max from slider position
                double newSharpMax = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMax = newSharpMax;
                sharpMaxLabel.setText(getSharpMaxLabel());
            }
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magErrMaxSlider.addChangeListener(cl);
    chi2MaxSlider.addChangeListener(cl);
    sharpMinSlider.addChangeListener(cl);
    sharpMaxSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Text field to store distance modulus
    final JTextField distanceModulusField = new JTextField(Double.toString(mu));
    distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5));

    Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5),
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

    final JButton lfButton = new JButton("Luminosity function for selection");
    lfButton.setBorder(compound);
    lfButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            // Read distance modulus field
            try {
                double mu_new = Double.parseDouble(distanceModulusField.getText());
                mu = mu_new;
            } catch (NullPointerException | NumberFormatException ex) {
                JOptionPane.showMessageDialog(lfButton,
                        "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (boxedSources.isEmpty()) {
                JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                computeAndPlotLuminosityFunction(boxedSources);
            }
        }
    });
    final JButton clearSelectionButton = new JButton("Clear selection");
    clearSelectionButton.setBorder(compound);
    clearSelectionButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            points.clear();
            cmdPanel.setChart(plotCmd());
        }
    });

    JPanel controls = new JPanel(new GridLayout(9, 2));
    controls.setBorder(new EmptyBorder(10, 10, 10, 10));
    controls.add(new JLabel("Magnitude = "));
    controls.add(magComboBox);
    controls.add(new JLabel("Colour 1 = "));
    controls.add(col1ComboBox);
    controls.add(new JLabel("Colour 2 = "));
    controls.add(col2ComboBox);
    controls.add(magErrMaxLabel);
    controls.add(magErrMaxSlider);
    controls.add(chi2MaxLabel);
    controls.add(chi2MaxSlider);
    controls.add(sharpMinLabel);
    controls.add(sharpMinSlider);
    controls.add(sharpMaxLabel);
    controls.add(sharpMaxSlider);
    controls.add(new JLabel("Adopted distance modulus = "));
    controls.add(distanceModulusField);
    controls.add(lfButton);
    controls.add(clearSelectionButton);

    this.setLayout(new BorderLayout());
    this.add(cmdPanel, BorderLayout.CENTER);
    this.add(controls, BorderLayout.SOUTH);

    this.validate();
}

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

/** Draws the visual representation of a single data item.
 *///from  ww  w .  jav  a  2 s . c o m
@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 crosshairInfo, int pass) {

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

    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    Number x1n = dataset.getX(series, item);
    Number y1n = dataset.getY(series, item);
    if (y1n == null || x1n == null) {
        return;
    }

    double x1 = x1n.doubleValue();
    double y1 = y1n.doubleValue();
    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    PlotOrientation orientation = plot.getOrientation();

    if (item > 0) {
        // get the previous data point...
        Number x0n = dataset.getX(series, item - 1);
        Number y0n = dataset.getY(series, item - 1);
        if (y0n != null && x0n != null) {
            double x0 = x0n.doubleValue();
            double y0 = y0n.doubleValue();

            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }

            if (orientation == PlotOrientation.HORIZONTAL) {
                line.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line.setLine(transX0, transY0, transX1, transY1);
            }

            if (y1n instanceof RangeInfo) {
                RangeInfo y1r = (RangeInfo) y1n;
                double transY1low = rangeAxis.valueToJava2D(y1r.getRangeLowerBound(false), dataArea,
                        yAxisLocation);
                double transY1high = rangeAxis.valueToJava2D(y1r.getRangeUpperBound(false), dataArea,
                        yAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1, transY1low, transX1, transY1high);

            } else if (x1n instanceof RangeInfo) {
                RangeInfo x1r = (RangeInfo) x1n;
                double transX1low = domainAxis.valueToJava2D(x1r.getRangeLowerBound(false), dataArea,
                        xAxisLocation);
                double transX1high = domainAxis.valueToJava2D(x1r.getRangeUpperBound(false), dataArea,
                        xAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1low, transY1, transX1high, transY1);

            } else if (line.intersects(dataArea)) {
                g2.draw(line);
            }
        }
    } else if (dataset.getItemCount(series) == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;
    }

    if (entities != null && (dataArea.contains(transX1, transY1) || entityArea != null)) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2             the graphics device.
 * @param state          the state.//from  w w w . jav  a  2s .c  om
 * @param dataArea       the data area.
 * @param info           the plot rendering info.
 * @param plot           the plot.
 * @param domainAxis     the x-axis.
 * @param rangeAxis      the y-axis.
 * @param dataset        the dataset.
 * @param series         the series index.
 * @param item           the item index.
 * @param crosshairState the crosshair state.
 * @param pass           the pass index.
 */
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) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    double max = paintScale.getUpperBound();
    double min = paintScale.getLowerBound();

    if (dataset instanceof XYZDataset)
        z = ((XYZDataset) dataset).getZValue(series, item);

    //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009)
    if (z > max)
        z = max;

    if (z < min)
        z = min;

    Color p = (Color) this.paintScale.getPaint(z);

    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    } else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setColor(p);
    g2.fill(block);

    if (gridLinesEnabled) {
        boolean aaOn = false;
        if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            aaOn = true;
        }
        g2.setPaint(gridLineColor);
        g2.setStroke(gridLineStroke);
        g2.draw(block);
        if (aaOn)
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        g2.setStroke(basicStroke);
        g2.draw(block);
    }
}