Example usage for org.jfree.chart.axis DateAxis java2DToValue

List of usage examples for org.jfree.chart.axis DateAxis java2DToValue

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateAxis java2DToValue.

Prototype

@Override
public double java2DToValue(double java2DValue, Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Translates a Java2D coordinate into the corresponding data value.

Usage

From source file:ec.ui.view.RevisionSaSeriesView.java

private void showSelectionPopup(Rectangle2D rectangle) {
    XYPlot plot = chartpanel_.getChart().getXYPlot();
    Rectangle2D dataArea = chartpanel_.getScreenDataArea();
    DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    double minX = domainAxis.java2DToValue(rectangle.getMinX(), dataArea, plot.getDomainAxisEdge());
    double maxX = domainAxis.java2DToValue(rectangle.getMaxX(), dataArea, plot.getDomainAxisEdge());

    Date startDate = new Date((long) minX);
    Date endDate = new Date((long) maxX);
    TsPeriod start = new TsPeriod(firstPeriod.getFrequency(), startDate);
    TsPeriod end = new TsPeriod(firstPeriod.getFrequency(), endDate);

    if (end.minus(start) == 0) {
        return;/*from  w w w .  j  a va 2s  .  c om*/
    }

    TsPeriodSelector sel = new TsPeriodSelector();
    sel.between(start.firstday(), end.lastday());
    List<TsData> listSeries = history_.Select(info_, startDate, endDate);
    List<TsData> revSeries = new ArrayList<>();

    for (TsData t : listSeries) {
        revSeries.add(t.select(sel));
    }

    Point pt = new Point((int) rectangle.getX(), (int) rectangle.getY());
    pt.translate(3, 3);
    SwingUtilities.convertPointToScreen(pt, chartpanel_);
    popup.setLocation(pt);
    popup.setChartTitle(info_.toUpperCase() + " First estimations");
    popup.setTsData(sRef.select(sel), revSeries);
    popup.setVisible(true);
    chartpanel_.repaint();
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java

/**
 * Add the action listener to the graph.
 *//*from  ww w .  j  a  va 2 s. c  om*/
private void setAction() {
    gui.pnlGraph.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent e) {
            if (e.getEntity() instanceof PlotEntity) {
                Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint());
                CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot();
                Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea();

                DateAxis rangeAxis = (DateAxis) plot.getRangeAxis();
                RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

                CategoryAxis catAxis = plot.getDomainAxis();
                RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();

                double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge);

                CategoryDataset categories = (CategoryDataset) plot.getDataset(0);

                int categoryCount = categories.getColumnCount();

                for (int i = 0; i < categoryCount; i++) {
                    double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge);
                    double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge);

                    if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) {
                        new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i),
                                new Day(new Date((long) chartY)), parent);
                    }

                }
            } else {

                CategoryItemEntity item = (CategoryItemEntity) e.getEntity();
                CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot();
                Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea();
                RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

                DateAxis dateAxis = (DateAxis) plot.getRangeAxis();

                double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea,
                        rangeAxisEdge);
                double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX()
                        + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge);

                Date startDate = new Date((long) d);
                Date endDate = new Date((long) d2);

                CategoryDataset categories = (CategoryDataset) plot.getDataset(0);
                int workerIndex = categories.getColumnIndex(item.getColumnKey());
                Worker worker = gui.function.getWorkers().get(workerIndex);

                Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate,
                        endDate);
                Availability foundAv = found.toArray(new Availability[1])[0];

                if (foundAv != null) {
                    new EditAvailabilityController(gui.function, foundAv, parent);
                } else {
                    found = CalendarService.getProjectAvailability(startDate, endDate);
                    foundAv = found.toArray(new Availability[1])[0];
                    if (foundAv != null) {
                        new EditAvailabilityController(gui.function, foundAv, parent);
                    } else {
                        JOptionPane.showMessageDialog(
                                new JFrame(LocalizedStrings.getGeneralStrings().warning()),
                                LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged());
                    }
                }
            }

        }

        @Override
        public void chartMouseMoved(final ChartMouseEvent arg0) {

        }

    });
    /**
     * ActionListener
     */
    gui.btnNext.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            gui.function.increment();
        }

    });
    /**
     * ActionListener
     */
    gui.btnPrev.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            gui.function.decrement();
        }

    });

    for (int i = 0; i < gui.buttons.length; i++) {
        addButtonListener(i);
    }
    /**
     * ActionListener
     */
    gui.btnManualAv.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                gui.function.setManualAv(true);
            } else {
                gui.function.setManualAv(false);
            }
        }

    });

}