List of usage examples for org.jfree.chart ChartMouseListener ChartMouseListener
ChartMouseListener
From source file:com.philng.telemetrydisplay.GraphDisplay.java
/** * Build all the initial data//from ww w . j a v a2s. c om */ public GraphDisplay() { voltage = new TimeSeries("Voltage"); current = new TimeSeries("Current"); this.setLayout(new BorderLayout()); final JFreeChart chart = createChart(createDatasetVoltage()); final ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); chartPanel.setVisible(true); setVisible(true); // Add a mouse listener for when the user double clicks the mousse // on the graph, it will reset the zoome ChartMouseListener cml = new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent chartMouseEvent) { if (chartMouseEvent.getTrigger().getClickCount() == 2) { chartPanel.restoreAutoBounds(); } } @Override public void chartMouseMoved(ChartMouseEvent chartMouseEvent) { } }; chartPanel.addChartMouseListener(cml); }
From source file:org.rhwlab.ace3d.VolumeIntensityPlot.java
public VolumeIntensityPlot(ImagedEmbryo emb) { this.embryo = emb; collect = new XYSeriesCollection(); series = new XYSeries("Nuclei"); collect.addSeries(series);//www . j a v a2s . c o m chart = ChartFactory.createScatterPlot("", "Volume", "AvgIntensity", collect, PlotOrientation.VERTICAL, false, true, true); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotHeight(4); renderer.setDotWidth(4); // plot.setRenderer(renderer); ChartPanel panel = new ChartPanel(chart); panel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { ChartEntity entity = event.getEntity(); if (entity instanceof XYItemEntity) { XYItemEntity xyEntity = (XYItemEntity) entity; NucleusPlotDataItem item = (NucleusPlotDataItem) series.getDataItem(xyEntity.getItem()); embryo.setSelectedNucleus(item.nuc); } } @Override public void chartMouseMoved(ChartMouseEvent event) { } }); this.add(panel); embryo.getNucleusFile().addSelectionOberver(this); }
From source file:edu.cmu.sv.modelinference.eventtool.charting.DataChart.java
private void createChartPanel(JFreeChart chart) { chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override// ww w . j a v a 2s .c om public void chartMouseClicked(ChartMouseEvent arg0) { //ignore } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = 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); ValueAxis yAxis = plot.getRangeAxis(); double y = yAxis.java2DToValue(event.getTrigger().getY(), dataArea, RectangleEdge.LEFT); //Alternatively, obtain y for one of the subplots, which would be very neat. //We should find the "nearest" subplot to the cursor -- this is easy //double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); } }); CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); chartPanel.setPreferredSize(new java.awt.Dimension(800, 600)); setContentPane(chartPanel); }
From source file:GUI.ResponseStatistics.java
/** * Creates a sample dataset */ private void InitPieChart(JFreeChart chart) { ChartPanel chartPanel = new ChartPanel(chart); // default size chartPanel.setSize(560, 800);/* w w w. ja v a 2 s . c o m*/ Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - chartPanel.getWidth()) / 2); int y = (int) ((dimension.getHeight() - chartPanel.getHeight()) / 2); chartPanel.setLocation(WIDTH, WIDTH); // add it to our application setContentPane(chartPanel); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent e) { wait = false; } public void chartMouseMoved(ChartMouseEvent e) { } }); }
From source file:slash.navigation.converter.gui.elevationview.ElevationView.java
public ElevationView(PositionsModel positionsModel, final PositionsSelectionModel positionsSelectionModel) { this.positionsModel = positionsModel; XYSeriesCollection dataset = createDataset(positionsModel); JFreeChart chart = createChart(dataset); plot = createPlot(chart);/*from w ww .j a v a 2s . c o m*/ chartPanel = new ChartPanel(chart, false, true, true, true, true); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent e) { ChartEntity entity = e.getEntity(); if (!(entity instanceof XYItemEntity)) return; int index = ((XYItemEntity) entity).getItem(); positionsSelectionModel.setSelectedPositions(new int[] { index }); } public void chartMouseMoved(ChartMouseEvent e) { } }); }
From source file:org.mwc.debrief.sensorfusion.views.MouseClickProblemDemo.java
/** * @param title/*w w w. ja va 2 s . co m*/ * the frame title. */ public MouseClickProblemDemo(final String title) { super(title); final TimeSeries s1 = new TimeSeries("Series to click"); s1.add(new Month(2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 158.8); s1.add(new Month(7, 2001), 148.3); s1.add(new Month(8, 2001), 153.9); s1.add(new Month(9, 2001), 142.7); s1.add(new Month(10, 2001), 123.2); final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); final JFreeChart chart = ChartFactory.createTimeSeriesChart("[Alt]-click to switch orientation", // title "Time axis", // x-axis label "Value axis", // y-axis label dataset, // data false, // create legend? false, // generate tooltips? false // generate URLs? ); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(final ChartMouseEvent arg0) { } public void chartMouseClicked(final ChartMouseEvent arg0) { System.out.println("clicked on:" + arg0.getEntity()); if (arg0.getTrigger().isAltDown()) { if (chart.getXYPlot().getOrientation() == PlotOrientation.HORIZONTAL) chart.getXYPlot().setOrientation(PlotOrientation.VERTICAL); else chart.getXYPlot().setOrientation(PlotOrientation.HORIZONTAL); } } }); setContentPane(chartPanel); }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java
/** * Add the action listener to the graph. *//* w ww .j av a 2 s . c o m*/ 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.jfree.chart.demo.Graphic.java
public ChartPanel get_ChartPanel(int width, int height) { chr = new ChartPanel(chart); chr.setBackground(Color.blue); chr.setBounds(5, 5, width - 5, height - 10); chr.setVisible(true);/*from w w w . j av a 2 s . c o m*/ chr.setMouseWheelEnabled(true); chr.addChartMouseListener(new ChartMouseListener() { public void chartMouseMoved(ChartMouseEvent chartmouseevent) { } public void chartMouseClicked(ChartMouseEvent chartmouseevent) { SwingUtilities.invokeLater(new Runnable() { public void run() { XYPlot xyplot = (XYPlot) chr.getChart().getPlot(); xyplot.clearAnnotations(); double x, y; x = new BigDecimal(xyplot.getDomainCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); y = new BigDecimal(xyplot.getRangeCrosshairValue()).setScale(3, RoundingMode.UP) .doubleValue(); XYTextAnnotation annotation = new XYTextAnnotation("(" + x + ", " + y + ")", new BigDecimal(x).setScale(3, RoundingMode.UP).doubleValue(), y); annotation.setFont(new Font("serif", Font.BOLD, 15)); annotation.setTextAnchor(TextAnchor.BOTTOM_CENTER); xyplot.addAnnotation(annotation); } }); } }); return chr; }
From source file:scheduler.benchmarker.manager.CreateSimpleSplineChart.java
public ChartPanel createChartPanel() { XYDataset dataset = createDataset(); NumberAxis numberaxis = new NumberAxis("EMAILS"); numberaxis.setAutoRangeIncludesZero(true); numberaxis.setRange(0, dataset.getItemCount(1)); numberaxis.setVisible(false);// w w w . j a va 2 s. co m NumberAxis numberaxis1 = new NumberAxis("TIME CONSUMED"); numberaxis1.setAutoRangeIncludesZero(false); XYSplineRenderer xysplinerenderer = new XYSplineRenderer(); XYPlot xyplot = new XYPlot(dataset, numberaxis, numberaxis1, xysplinerenderer); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); //xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); JFreeChart jfreechart = new JFreeChart("PLAN VALUES FOR '" + sName + "' SCHEDULER", new Font(Font.SANS_SERIF, Font.PLAIN, 11), xyplot, true); chartPanel = new ChartPanel(jfreechart, true); //Creating listener chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { ChartEntity entity = e.getEntity(); if (entity != null && (entity instanceof XYItemEntity)) { XYItemEntity item = (XYItemEntity) entity; String chartTitle = "RULE ARRANGEMENT INFORMATION FOR EMAIL \"" + dataSource.get(item.getItem()).getEmailName() + "\""; createSubChart( new CreateStackedBarChart3D(dataSource.get(item.getItem()), pluginColor, chartTitle) .createChartPanel()); } } @Override public void chartMouseMoved(ChartMouseEvent e) { //DO NOTHING } }); return chartPanel; }
From source file:it.cnr.istc.iloc.gui.TimelinesChart.java
public TimelinesChart() { super(CHART); setBorder(null);/*from ww w . jav a2s. c om*/ addTimelineVisualizer(new StateVariableVisualizer()); addChartMouseListener(new ChartMouseListener() { private Object getDataItem(ChartEntity entity) { XYItemEntity e = ((XYItemEntity) entity); XYDataset ds = e.getDataset(); if (ds instanceof XYIntervalSeriesCollection) { XYIntervalSeries theSerie = ((XYIntervalSeriesCollection) ds).getSeries(e.getSeriesIndex()); return theSerie.getDataItem(e.getItem()); } else if (ds instanceof XYSeriesCollection) { XYSeries theSerie = ((XYSeriesCollection) ds).getSeries(e.getSeriesIndex()); return theSerie.getDataItem(e.getItem()); } else { return null; } } @Override public void chartMouseClicked(ChartMouseEvent cme) { if (cme.getEntity() != null && cme.getEntity() instanceof XYItemEntity) { Object dataItem = getDataItem(cme.getEntity()); visualizers.values().forEach(visualizer -> { visualizer.mouseClicked(dataItem); }); } } @Override public void chartMouseMoved(ChartMouseEvent cme) { if (cme.getEntity() != null && cme.getEntity() instanceof XYItemEntity) { setCursor(HAND_CURSOR); } else { setCursor(DEFAULT_CURSOR); } } }); }