List of usage examples for org.jfree.chart ChartPanel getChart
public JFreeChart getChart()
From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java
/** * * @param g2/*from w ww. j a va 2 s. com*/ * @param chartPanel */ @Override public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) { if (visible) { Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); g2.clip(dataArea); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); paint(g2, plot, dataArea, xAxis, yAxis, plot.getDomainAxisEdge(), plot.getRangeAxisEdge(), chartPanel); g2.setClip(savedClip); } }
From source file:edu.fullerton.viewerplugin.PluginSupport.java
public void saveImageAsPNGFile(ChartPanel cp, String fname) throws WebUtilException { FileOutputStream fos = null;/* w w w . j av a 2 s . co m*/ try { JFreeChart chart = cp.getChart(); fos = new FileOutputStream(fname); ChartUtilities.writeChartAsPNG(fos, chart, width, height); fos.close(); fos = null; } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (Exception ex) { throw new WebUtilException("Saving image: " + ex.getClass() + " - " + ex.getLocalizedMessage()); } } }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.Chromatogram1DViewTopComponent.java
private void hideShowSeriesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideShowSeriesActionPerformed SeriesItem s = (SeriesItem) seriesComboBox.getSelectedItem(); Chromatogram1DDataset dataset = getLookup().lookup(Chromatogram1DDataset.class); ChartPanel cp = jp.getLookup().lookup(ChartPanel.class); for (int i = 0; i < dataset.getSeriesCount(); i++) { if (dataset.getSeriesKey(i).equals(s.getSeriesKey())) { XYPlot p = cp.getChart().getXYPlot(); if (p != null) { XYItemRenderer renderer = p.getRenderer(); if (renderer != null) { boolean isVisible = renderer.isSeriesVisible(i); renderer.setSeriesVisible(i, !isVisible); s.setVisible(!isVisible); } else { Logger.getLogger(Chromatogram1DViewTopComponent.class.getName()) .fine("XYItemRenderer is null!"); }// ww w . ja va2s . c o m } else { Logger.getLogger(Chromatogram1DViewTopComponent.class.getName()).fine("XYPlot is null!"); } } } }
From source file:jamel.gui.JamelWindow.java
/** * Sets the chart in the specified panel. * @param tabIndex the index of the tab to customize. * @param panelIndex the id of the ChartPanel to customize. * @param chartPanelName the name of the ChartPanel to set. * @throws ClassNotFoundException .../*from w w w.jav a2 s .c om*/ * @throws NoSuchMethodException ... * @throws InvocationTargetException ... * @throws IllegalAccessException ... * @throws InstantiationException ... * @throws SecurityException ... * @throws IllegalArgumentException ... */ public void setChart(int tabIndex, int panelIndex, String chartPanelName) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { final ChartPanel chartPanel = (ChartPanel) Class .forName(chartPanelName, false, ClassLoader.getSystemClassLoader()).getConstructor().newInstance(); ((ChartPanel) ((JPanel) tabbedPane.getComponent(tabIndex)).getComponent(panelIndex)) .setChart(chartPanel.getChart()); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java
private void addChangeListener(ChartPanel chartPanel) { chartPanel.getChart().addChangeListener(new ChartChangeListener() { @Override//from w w w. j av a 2s .c o m public void chartChanged(ChartChangeEvent event) { if (event.getType() == ChartChangeEventType.GENERAL) { // Sequence is important. We will use invest information box as master. // ROI information box will be adjusted accordingly. investmentFlowLayerUI.updateInvestPoint(); investmentFlowLayerUI.updateROIPoint(); } } }); }
From source file:statistic.graph.Controller.java
public void notify(DiagramEvent event) { LOGGER.entering("Controller", "notify", event); DiagramData data = event.getDiagram(); if (data == null) { return;/*from w w w.ja v a 2s. c o m*/ } if (event instanceof DiagramChangedEvent) { ChartPanel chartPanel = chartPanels.get(data); if (chartPanel != null) { if (event instanceof DiagramTitleChangedEvent) { chartPanel.getChart().setTitle(((DiagramTitleChangedEvent) event).getNewTitle()); } else if (event instanceof DiagramXAxisLabelChangedEvent) { chartPanel.getChart().getXYPlot().getDomainAxis() .setLabel(((DiagramXAxisLabelChangedEvent) event).getNewXAxisLabel()); } else if (event instanceof DiagramYAxisLabelChangedEvent) { chartPanel.getChart().getXYPlot().getRangeAxis() .setLabel(((DiagramYAxisLabelChangedEvent) event).getNewYAxisLabel()); } else { throw new AssertionError("This should not happen."); } chartPanel.chartChanged( new ChartChangeEvent(event, chartPanel.getChart(), ChartChangeEventType.GENERAL)); } } else if (event instanceof DiagramSelectionChangedEvent) { } else { if (event instanceof DiagramAddedEvent) { if (data.getType() == DiagramType.TABLE) { JTable table = createTable(data); JScrollPane pane = new JScrollPane(table); pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300)); tableScrollPanes.put(data, pane); contentPane.add(pane); } else { ChartPanel chartPanel = createChartPanel(data); //chartPanel.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300)); chartPanels.put(data, chartPanel); contentPane.add(chartPanel); } } else if (event instanceof DiagramRemovedEvent) { if (data.getType() == DiagramType.TABLE) { JScrollPane pane = tableScrollPanes.remove(data); contentPane.remove(pane); } else { ChartPanel chartPanel = chartPanels.remove(data); contentPane.remove(chartPanel); } } else if (event instanceof DiagramSequenceChangedEvent) { DiagramData data2 = ((DiagramSequenceChangedEvent) event).getDiagram2(); Component component1 = getComponent(data); LOGGER.finest("1. Komponente: " + component1); Component component2 = getComponent(data2); LOGGER.finest("2. Komponente: " + component2); int index = 0; for (Component component : contentPane.getComponents()) { if (component == component1) { break; } index++; } LOGGER.finest("1. Komponente befindet sich an Index: " + index); LOGGER.finest("Entferne 2. Komponente"); contentPane.remove(component2); LOGGER.finest("Fge 2. Komponent an Index " + index + " wieder ein."); contentPane.add(component2, index); } else if (event instanceof DiagramTypeChangedEvent) { Component component = null; if (chartPanels.containsKey(data)) { component = chartPanels.get(data); } else if (tableScrollPanes.containsKey(data)) { component = tableScrollPanes.get(data); } int index = 0; for (Component c : contentPane.getComponents()) { if (c == component) { break; } index++; } contentPane.remove(component); if (component instanceof ChartPanel) { chartPanels.remove(data); } else if (component instanceof JScrollPane) { tableScrollPanes.remove(data); } if (data.getType() == DiagramType.TABLE) { JTable table = createTable(data); JScrollPane pane = new JScrollPane(table); pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300)); component = pane; tableScrollPanes.put(data, pane); } else { ChartPanel panel = createChartPanel(data); component = panel; chartPanels.put(data, panel); } contentPane.add(component, index); } else { throw new AssertionError("This should not happen."); } scrollPane.validate(); scrollPane.repaint(); } }
From source file:ec.util.chart.swing.Charts.java
public static void saveChart(@Nonnull ChartPanel chartPanel) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileFilter defaultFilter = new FileNameExtensionFilter("PNG (.png)", "png"); fileChooser.addChoosableFileFilter(defaultFilter); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG (.jpg) (.jpeg)", "jpg", "jpeg")); if (Charts.canWriteChartAsSVG()) { fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG (.svg)", "svg")); fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Compressed SVG (.svgz)", "svgz")); }/*from w w w.j a v a 2s .c o m*/ fileChooser.setFileFilter(defaultFilter); File currentDir = chartPanel.getDefaultDirectoryForSaveAs(); if (currentDir != null) { fileChooser.setCurrentDirectory(currentDir); } if (fileChooser.showSaveDialog(chartPanel) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try (OutputStream stream = Files.newOutputStream(file.toPath())) { writeChart(getMediaType(file), stream, chartPanel.getChart(), chartPanel.getWidth(), chartPanel.getHeight()); } chartPanel.setDefaultDirectoryForSaveAs(fileChooser.getCurrentDirectory()); } }
From source file:vteaexploration.plotgatetools.gates.PolygonGate.java
@Override public void createInChartSpace(ChartPanel chart) { int[] x1Points = new int[vertices.size()]; int[] y1Points = new int[vertices.size()]; double xChartPoint; double yChartPoint; for (int i = 0; i <= vertices.size() - 1; i++) { x1Points[i] = (int) ((Point2D) vertices.get(i)).getX(); y1Points[i] = (int) ((Point2D) vertices.get(i)).getY(); }/*from ww w . java2s . c o m*/ for (int index = 0; index < x1Points.length; index++) { Rectangle2D plotArea = chart.getScreenDataArea(); XYPlot plot = (XYPlot) chart.getChart().getPlot(); xChartPoint = plot.getDomainAxis().java2DToValue(x1Points[index], plotArea, plot.getDomainAxisEdge()); yChartPoint = plot.getRangeAxis().java2DToValue(y1Points[index], plotArea, plot.getRangeAxisEdge()); this.verticesInChartSpace.add(new Point2D.Double(xChartPoint, yChartPoint)); } }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)// w w w.j a v a2 s . c o m * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
From source file:net.bioclipse.plugins.views.ChartView.java
/** * Displays a chart in ChartView and sets up its mouse listener * @param chart/*from ww w . ja v a2 s . c om*/ */ public void display(JFreeChart chart) { final ChartDescriptor cd = ChartUtils.getChartDescriptor(chart); JFreeChartTab chartTab = new JFreeChartTab(tabFolder, SWT.CLOSE); chartTab.setText(chart.getTitle().getText()); chartTab.setChart(chart); Composite composite = new Composite(tabFolder, SWT.EMBEDDED | SWT.NO_BACKGROUND); chartTab.setControl(composite); frame = SWT_AWT.new_Frame(composite); final ChartPanel chartPanel = new ChartPanel(chart); //Since methods are called on a java.awt.Frame it has to be called on the swing/awt thread SwingUtilities.invokeLater(new Runnable() { public void run() { frame.removeAll(); frame.add(chartPanel); frame.setVisible(true); if (cd.getPlotType() == ChartConstants.SCATTER_PLOT) { //Listens for mouseclicks on points XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); plot.setRenderer(new ScatterPlotRenderer(false, true)); if (ChartView.IS_MACOS) { frame.addMouseListener(pmh); frame.addMouseMotionListener(pmh); } else { chartPanel.addMouseListener(pmh); frame.addMouseMotionListener(pmh); } } } }); tabFolder.setSelection(chartTab); tabFolder.forceFocus(); tabFolder.layout(); ChartUtils.setActiveChart(chart); //Make sure actions are enabled when the chart has been created saveImageActionJPG.setEnabled(true); saveImageActionPNG.setEnabled(true); saveImageActionSVG.setEnabled(true); }