List of usage examples for org.jfree.chart ChartPanel getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:script.imglib.analysis.ChartUtils.java
public static final Image<RGBALegacyType> asImage(final JFreeChart chart, int width, int height) { ChartPanel panel = new ChartPanel(chart); Dimension d = panel.getPreferredSize(); if (-1 == width && -1 == height) { width = d.width;//from w w w. ja va 2s . c o m height = d.height; panel.setSize(d); } else { panel.setSize(width, height); } layoutComponent(panel); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); if (!panel.isOpaque()) { g.setColor(panel.getBackground()); g.fillRect(0, 0, width, height); } panel.paint(g); int[] pixels = new int[width * height]; PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { } g.dispose(); Array<RGBALegacyType, IntAccess> a = new Array<RGBALegacyType, IntAccess>(new ArrayContainerFactory(), new IntArray(pixels), new int[] { width, height }, 1); // create a Type that is linked to the container final RGBALegacyType linkedType = new RGBALegacyType(a); // pass it to the DirectAccessContainer a.setLinkedType(linkedType); return new Image<RGBALegacyType>(a, new RGBALegacyType()); }
From source file:net.imglib2.script.analysis.ChartUtils.java
public static final Img<ARGBType> asImage(final JFreeChart chart, int width, int height) { final ChartPanel panel = new ChartPanel(chart); final Dimension d = panel.getPreferredSize(); if (-1 == width && -1 == height) { width = d.width;//from w ww . j a va 2s. c om height = d.height; panel.setSize(d); } else { panel.setSize(width, height); } layoutComponent(panel); final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); if (!panel.isOpaque()) { g.setColor(panel.getBackground()); g.fillRect(0, 0, width, height); } panel.paint(g); final int[] pixels = new int[width * height]; final PixelGrabber pg = new PixelGrabber(bi, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (final InterruptedException e) { } g.dispose(); final ArrayImg<ARGBType, IntArray> a = new ArrayImg<ARGBType, IntArray>(new IntArray(pixels), new long[] { width, height }, 1); // create a Type that is linked to the container final ARGBType linkedType = new ARGBType(a); // pass it to the DirectAccessContainer a.setLinkedType(linkedType); return a; }
From source file:hr.restart.util.chart.ChartBase.java
final public void print() throws Exception { //System.out.println("(CHARTBASE) print"); try {/*w w w . j a va 2s. com*/ ChartPanel chartPanel = initGraph(); chartPanel.setSize(chartPanel.getPreferredSize()); chartPanel.createChartPrintJob(); } catch (Exception e) { e.printStackTrace(); preview(); } }
From source file:hr.restart.util.chart.ChartBase.java
final public void export() throws Exception { //System.out.println("(CHARTBASE) export"); try {//from w w w. j a v a 2 s . c o m ChartPanel chartPanel = initGraph(); chartPanel.setSize(chartPanel.getPreferredSize()); chartPanel.doSaveAs(); } catch (Exception e) { e.printStackTrace(); preview(); } }
From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java
private JComponent createRankProbChart() { final CategoryDataset dataset = d_pm.getRankProbabilityDataset(); final JFreeChart chart = ChartFactory.createBarChart("Rank Probability", "Treatment", "Probability", dataset, PlotOrientation.VERTICAL, true, true, false); chart.addSubtitle(new org.jfree.chart.title.ShortTextTitle(d_pm.getRankProbabilityRankChartNote())); final FormLayout layout = new FormLayout("fill:0:grow", "p, 3dlu, p"); final PanelBuilder builder = new PanelBuilder(layout); final CellConstraints cc = new CellConstraints(); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(chartPanel.getPreferredSize().width, chartPanel.getPreferredSize().height + 1); chartPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); builder.add(chartPanel, cc.xy(1, 1)); final ButtonBarBuilder2 bbuilder = new ButtonBarBuilder2(); bbuilder.addButton(createSaveImageButton(chart)); builder.add(bbuilder.getPanel(), cc.xy(1, 3)); return builder.getPanel(); }
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. */// w w w.ja v a 2 s.c o m private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }