Example usage for org.jfree.chart ChartMouseEvent getTrigger

List of usage examples for org.jfree.chart ChartMouseEvent getTrigger

Introduction

In this page you can find the example usage for org.jfree.chart ChartMouseEvent getTrigger.

Prototype

public MouseEvent getTrigger() 

Source Link

Document

Returns the mouse event that triggered this event.

Usage

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

/**
 * Add the action listener to the graph.
 *//*w w  w  . j a v a  2 s.com*/
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);
            }
        }

    });

}

From source file:org.adempiere.apps.graph.PerformanceIndicator.java

/**
*    Init Graph Display/*from w w  w . ja v  a 2  s .  co  m*/
*  Kinamo (pelgrim)
*/
private void init() {
    chartPanel = new ChartPanel(createChart(), //chart
            false, //boolean properties
            false, // boolean save
            false, //boolean print
            false, //boolean zoom
            true //boolean tooltips
    );
    chartPanel.setPreferredSize(indicatordimension);

    chartPanel.addChartMouseListener(new org.jfree.chart.ChartMouseListener() {
        public void chartMouseClicked(org.jfree.chart.ChartMouseEvent e) {
            //plot p = (MeterPlot) e.getSource();
            MouseEvent me = e.getTrigger();
            if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() > 1)
                fireActionPerformed(me);
            if (SwingUtilities.isRightMouseButton(me))
                popupMenu.show((Component) me.getSource(), me.getX(), me.getY());
        }

        public void chartMouseMoved(org.jfree.chart.ChartMouseEvent e) {

        }
    });

    this.add(chartPanel, BorderLayout.NORTH);
    this.setMinimumSize(paneldimension);
    this.setMaximumSize(paneldimension);
    //---------------------------------------------

    invalidate();
}

From source file:jmeanshift.ChartProof.java

@Override
public void chartMouseClicked(ChartMouseEvent cme) {
    ChartEntity chartentity = cme.getEntity();
    if (chartentity != null) {
        Point2D p = chartPanel.translateScreenToJava2D(cme.getTrigger().getPoint());
        final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        int i = (int) plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
        int j = (int) plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
        series.addOrUpdate(i, j);/*from  w  w  w .jav a2  s  .  co m*/
        data1.add((double) i);
        data2.add((double) j);
    } else {

    }

}

From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java

/**
 *
 * @param arg0/*from www  . ja va 2  s . c om*/
 */

@Override
public void chartMouseMoved(final ChartMouseEvent arg0) {
    final ChartPanelMouseListener cpml = this;

    if (arg0.getEntity() != null) {
        if (arg0.getEntity() instanceof XYItemEntity) {
            if (arg0.getTrigger().isAltDown()) {
                XYPlot xyp = arg0.getChart().getXYPlot();
                if (xyp != null) {
                    fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml));
                }
                XYItemEntityMovedEvent xyie = new XYItemEntityMovedEvent((XYItemEntity) arg0.getEntity(), cpml);
                fireEvent(xyie);
            }
        }
        if (arg0.getEntity() instanceof XYAnnotationEntity) {
            ChartRenderingInfo cri = cp.getChartRenderingInfo();
            EntityCollection entities = cri.getEntityCollection();
            ChartEntity ce = entities.getEntity(arg0.getTrigger().getX(), arg0.getTrigger().getY());
            if (ce instanceof XYItemEntity) {
                //                    System.out.println("Entity at position: " + ce.getClass().
                //                            getName() + " " + ((XYItemEntity) ce));
                XYItemEntityMouseOverEvent xyie = new XYItemEntityMouseOverEvent((XYItemEntity) ce, cpml);
                fireEvent(xyie);
            }
        }
    }
}

From source file:org.openaltimeter.desktopapp.annotations.AltimeterChartMouseListener.java

@Override
public void chartMouseClicked(final ChartMouseEvent event) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            XYPlot xyplot = (XYPlot) cp.getChart().getPlot();

            double x, y;
            x = xyplot.getDomainCrosshairValue();
            y = xyplot.getRangeCrosshairValue();

            am.addUserHeightAnnotation(x, y);

            int onmask = InputEvent.SHIFT_DOWN_MASK;
            if ((event.getTrigger().getModifiersEx() & (onmask)) == onmask)
                am.addUserVarioAnnotation(lastAnnotationX, lastAnnotationY, x, y);

            lastAnnotationX = x;//from   ww  w  .  ja  v  a 2s  .com
            lastAnnotationY = y;
        }
    });
}

From source file:jgnash.ui.report.compiled.IncomeExpensePieChart.java

private JPanel createPanel() {
    EnumSet<AccountType> set = EnumSet.of(AccountType.INCOME, AccountType.EXPENSE);

    JButton refreshButton = new JButton(rb.getString("Button.Refresh"));

    startField = new DatePanel();

    endField = new DatePanel();

    showEmptyCheck = new JCheckBox(rb.getString("Label.ShowEmptyAccounts"));

    showPercentCheck = new JCheckBox(rb.getString("Button.ShowPercentValues"));

    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);

    combo = AccountListComboBox.getParentTypeInstance(engine.getRootAccount(), set);

    final LocalDate dStart = DateUtils.getFirstDayOfTheMonth(LocalDate.now()).minusYears(1);

    long start = pref.getLong(START_DATE, DateUtils.asEpochMilli(dStart));

    startField.setDate(DateUtils.asLocalDate(start));

    currentAccount = combo.getSelectedAccount();
    JFreeChart chart = createPieChart(currentAccount);
    chartPanel = new ChartPanel(chart, true, true, true, false, true);
    //                         (chart, properties, save, print, zoom, tooltips)

    FormLayout layout = new FormLayout("p, 4dlu, 70dlu, 8dlu, p, 4dlu, 70dlu, 8dlu, p, 4dlu:g, left:p",
            "f:d, 3dlu, f:d, 6dlu, f:p:g");
    DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    layout.setRowGroups(new int[][] { { 1, 3 } });

    builder.append(combo, 9);//ww w . jav a  2 s  .com
    builder.append(showEmptyCheck);
    builder.nextLine();

    builder.nextLine();

    builder.append(rb.getString("Label.StartDate"), startField);
    builder.append(rb.getString("Label.EndDate"), endField);
    builder.append(refreshButton);

    builder.append(showPercentCheck);
    builder.nextLine();
    builder.nextLine();

    builder.append(chartPanel, 11);

    JPanel panel = builder.getPanel();

    combo.addActionListener(e -> {
        setCurrentAccount(combo.getSelectedAccount());
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    refreshButton.addActionListener(e -> {
        setCurrentAccount(currentAccount);
        pref.putLong(START_DATE, DateUtils.asEpochMilli(startField.getLocalDate()));
    });

    showEmptyCheck.addActionListener(e -> setCurrentAccount(currentAccount));

    showPercentCheck.addActionListener(e -> ((PiePlot) chartPanel.getChart().getPlot())
            .setLabelGenerator(showPercentCheck.isSelected() ? percentLabels : defaultLabels));

    ChartMouseListener mouseListener = new ChartMouseListener() {

        @Override
        public void chartMouseClicked(final ChartMouseEvent event) {
            MouseEvent me = event.getTrigger();
            if (me.getID() == MouseEvent.MOUSE_CLICKED && me.getClickCount() == 1) {
                try {
                    ChartEntity entity = event.getEntity();
                    // expand sections if interesting, back out if in nothing
                    if (entity instanceof PieSectionEntity) {
                        Account a = (Account) ((PieSectionEntity) entity).getSectionKey();
                        if (a.getChildCount() > 0) {
                            setCurrentAccount(a);
                        }
                    } else if (entity == null) {
                        Account parent = currentAccount;
                        if (parent == null) {
                            return;
                        }
                        parent = parent.getParent();
                        if (parent == null || parent instanceof RootAccount) {
                            return;
                        }
                        setCurrentAccount(parent);
                    }
                } catch (final Exception e) {
                    Logger.getLogger(IncomeExpensePieChart.class.getName()).log(Level.SEVERE,
                            e.getLocalizedMessage(), e);
                }
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            setChartCursor(chartPanel, event.getEntity(), event.getTrigger().getPoint());
        }
    };

    chartPanel.addChartMouseListener(mouseListener);

    return panel;
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent chartMouseEvent) {
    ChartEntity entity = chartMouseEvent.getEntity();
    MouseEvent mouseEvent = chartMouseEvent.getTrigger();

    if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) {
        java.util.List<String> names = dataset.getTransactionTypeNames();
        PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
        int idx = pieSectionEntity.getSectionIndex();

        String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type",
                "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, "");

        if (name != null) {
            if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) {
                JOptionPane.showMessageDialog(null,
                        "Please enter a different name for the transaction type.\nEach name has to be unique.",
                        "Warning", JOptionPane.WARNING_MESSAGE);
            } else {
                PieDataset oldDataset = pieSectionEntity.getDataset();
                DefaultPieDataset newDataset = new DefaultPieDataset();

                PiePlot plot = (PiePlot) chart.getPlot();
                String oldName = (String) oldDataset.getKey(idx);
                names.set(idx, name);/*from w w  w.  j av  a 2 s.com*/
                dataset.setTransactionTypeName(idx, name);

                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    Number number = oldDataset.getValue(i);

                    if (key.equals(oldName)) {
                        if (name.isEmpty())
                            newDataset.setValue("Transaction Type " + (i + 1), number);
                        else
                            newDataset.setValue(name, number);
                    } else {
                        newDataset.setValue(key, number);
                    }
                }

                Paint[] tempPaint = new Paint[oldDataset.getItemCount()];
                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    tempPaint[i] = plot.getSectionPaint(key);
                }

                ((DefaultPieDataset) oldDataset).clear();
                plot.setDataset(newDataset);

                for (int i = 0; i < newDataset.getItemCount(); ++i) {
                    String key = (String) newDataset.getKey(i);
                    plot.setSectionPaint(key, tempPaint[i]);
                }
            }
        }
    }
}

From source file:com.bwc.ora.views.LrpDisplayFrame.java

private LrpDisplayFrame() {
    //set up frame and chart
    //configure initial display setting for the panel
    chartPanel = new ChartPanel(null);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    this.setSize(800, 800);
    add(chartPanel, BorderLayout.CENTER);

    //make it so this jframe can't gain focus
    setFocusableWindowState(false);/*ww  w  .  j  a v a2 s.  c  o m*/

    //add listener to check to see which LRP should be displayed
    lrps.addListSelectionListener((ListSelectionEvent e) -> {
        if (!e.getValueIsAdjusting()) {
            if (lrps.getSelectedIndex() > -1) {
                setChart(lrps.getSelectedValue().getAllSeriesData());
                setVisible(true);
            } else {
                setVisible(false);
            }
        }
    });

    //add listener to check for updates to lrp selection to change lrp
    lrpSettings.addPropertyChangeListener(e -> {
        if (lrps.getSelectedIndex() > -1) {
            if (e.getPropertyName().equals(LrpSettings.PROP_LRP_WIDTH)) {
                Lrp newLrp;
                try {
                    newLrp = new Lrp(Collections.getInstance().getLrpCollection().getSelectedValue().getName(),
                            Collections.getInstance().getLrpCollection().getSelectedValue()
                                    .getLrpCenterXPosition(),
                            Collections.getInstance().getLrpCollection().getSelectedValue()
                                    .getLrpCenterYPosition(),
                            ModelsCollection.getInstance().getLrpSettings().getLrpWidth(),
                            ModelsCollection.getInstance().getLrpSettings().getLrpHeight(),
                            Collections.getInstance().getLrpCollection().getSelectedValue().getType());
                } catch (LRPBoundaryViolationException e1) {
                    JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error",
                            JOptionPane.ERROR_MESSAGE);
                    lrpSettings.setLrpWidth((int) e.getOldValue());
                    return;
                }
                Collections.getInstance().getLrpCollection().setLrp(newLrp,
                        Collections.getInstance().getLrpCollection().getSelectedIndex());
            } else {
                updateSeries(lrps.getSelectedValue().getAllSeriesData());
            }
        }
    });

    //add listener to check for updates to oct settings to change lrp
    octSettings.addPropertyChangeListener(e -> {
        if (lrps.getSelectedIndex() > -1) {
            switch (e.getPropertyName()) {
            case OctSettings.PROP_APPLY_CONTRAST_ADJUSTMENT:
            case OctSettings.PROP_APPLY_NOISE_REDUCTION:
            case OctSettings.PROP_DISPLAY_LOG_OCT:
            case OctSettings.PROP_SHARPEN_KERNEL_RADIUS:
            case OctSettings.PROP_SHARPEN_WEIGHT:
            case OctSettings.PROP_SMOOTHING_FACTOR:
                updateSeries(lrps.getSelectedValue().getAllSeriesData());
            default:
                break;
            }
        }
    });

    //add listener to see if the LRP display needs updating when a selection on oct changes
    lrps.addListDataChangeListener(new ListDataListener() {
        @Override
        public void intervalAdded(ListDataEvent e) {
        }

        @Override
        public void intervalRemoved(ListDataEvent e) {
        }

        @Override
        public void contentsChanged(ListDataEvent e) {
            clearAnnotations();
            updateSeries(lrps.getSelectedValue().getAllSeriesData());
        }
    });

    //add mouse listener for chart to detect when to display labels for
    //peaks in the pop-up menu, also specify what to do when label is clicked
    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseClicked(ChartMouseEvent cme) {
            ChartEntity entity = cme.getEntity();
            if (entity instanceof XYItemEntity && cme.getTrigger().getButton() == MouseEvent.BUTTON1) {

                XYItemEntity item = (XYItemEntity) entity;
                LabelPopupMenu labelMenu = new LabelPopupMenu(chartPanel, item, lrps.getSelectedValue());

                labelMenu.show(chartPanel, cme.getTrigger().getX(), cme.getTrigger().getY());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent cme) {
            //do nothing
        }

    });
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 *
 * @param event
 */
protected void updateMouseMarker(ChartMouseEvent event) {
    updateMouseMarker(event.getTrigger().getPoint());
}

From source file:com.haskins.cloudtrailviewer.feature.MetricsFeature.java

@Override
public void chartMouseMoved(ChartMouseEvent event) {

    Rectangle2D dataArea = this.chartPanel.getScreenDataArea();
    JFreeChart chart = event.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis xAxis = plot.getDomainAxis();

    double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM);

    this.xCrosshair.setValue(x);
}