List of usage examples for org.jfree.chart ChartPanel revalidate
public void revalidate()
From source file:gui.images.CodebookVectorProfilePanel.java
/** * Sets the data to be shown./*from w w w.j a v a 2 s. co m*/ * * @param occurrenceProfile Double array that is the neighbor occurrence * profile of this visual word. * @param codebookIndex Integer that is the index of this visual word. * @param classColors Color[] of class colors. * @param classNames String[] of class names. */ public void setResults(double[] occurrenceProfile, int codebookIndex, Color[] classColors, String[] classNames) { int numClasses = Math.min(classNames.length, occurrenceProfile.length); this.codebookIndex = codebookIndex; this.occurrenceProfile = occurrenceProfile; DefaultPieDataset pieData = new DefaultPieDataset(); for (int cIndex = 0; cIndex < numClasses; cIndex++) { pieData.setValue(classNames[cIndex], occurrenceProfile[cIndex]); } JFreeChart chart = ChartFactory.createPieChart3D("codebook vect " + codebookIndex, pieData, true, true, false); PiePlot plot = (PiePlot) chart.getPlot(); plot.setDirection(Rotation.CLOCKWISE); plot.setForegroundAlpha(0.5f); PieRenderer prend = new PieRenderer(classColors); prend.setColor(plot, pieData); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(140, 140)); chartPanel.setVisible(true); chartPanel.revalidate(); chartPanel.repaint(); JPanel jp = new JPanel(); jp.setPreferredSize(new Dimension(140, 140)); jp.setMinimumSize(new Dimension(140, 140)); jp.setMaximumSize(new Dimension(140, 140)); jp.setSize(new Dimension(140, 140)); jp.setLayout(new FlowLayout()); jp.add(chartPanel); jp.setVisible(true); jp.validate(); jp.repaint(); JFrame frame = new JFrame(); frame.setBackground(Color.WHITE); frame.setUndecorated(true); frame.getContentPane().add(jp); frame.pack(); BufferedImage bi = new BufferedImage(jp.getWidth(), jp.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); jp.print(graphics); graphics.dispose(); frame.dispose(); imPanel.removeAll(); imPanel.setImage(bi); imPanel.setVisible(true); imPanel.revalidate(); imPanel.repaint(); }
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
/** * takes Only Width in account/*from w w w. j a v a 2 s.c om*/ * * @param chart * @param sett * @throws Exception */ public static void writeChartToImage(ChartPanel chart, GraphicsExportParameters sett) throws Exception { boolean repaint = false; FixedSize fixed = sett.getFixedSize(); double oldW = sett.getWidthPixel(); double oldH = sett.getHeightPixel(); // Size only by width? if (sett.isUseOnlyWidth()) { // fixed size for chart or plot if (fixed.equals(FixedSize.Chart)) { sett.setHeightPixel(ChartLogics.calcHeightToWidth(chart, oldW, false)); } else { // fixed plot width sett.setPixelSize(ChartLogics.calcSizeForPlotWidth(chart, oldW)); } } else if (fixed.equals(FixedSize.Plot)) { // fixed plot size - width and height are given sett.setPixelSize(ChartLogics.calcSizeForPlotSize(chart, oldW, oldH)); } Dimension size = sett.getPixelSize(); // resize chart.setPreferredSize(size); chart.setMaximumSize(size); chart.setMinimumSize(size); // repaint if (repaint) { chart.revalidate(); chart.repaint(); } writeChartToImage(chart.getChart(), sett, chart.getChartRenderingInfo()); // reset size sett.setPixelSize(oldW, oldH); }
From source file:org.schreibubi.JCombinations.ui.GridChartPanel.java
private void updateDisplay(ArrayList<TreePath> selection) { GridChartPanel.logger.info("updateDisplay called"); removeAll();//from w ww . jav a 2 s .c o m repaint(); ArrayList<ExtendedJFreeChart> charts = this.dm.getCharts(selection); if ((charts.size() > 0) && (charts.size() < 20)) { int n = charts.size(); double aspectratio = Math.sqrt(2); double y = Math.sqrt(n / aspectratio); double x = y * aspectratio; int xi = (int) Math.ceil(x); int yi = (int) Math.ceil(y); setLayout(new GridLayout(xi, yi)); setPreferredSize(new Dimension(yi * GridChartPanel.DEFAULT_WIDTH, xi * GridChartPanel.DEFAULT_HEIGHT)); revalidate(); setTransferHandler(new ImageTransferHandler()); fireSetupProgress(this, 0, charts.size() - 1); for (int i = 0; i < charts.size(); i++) { JFreeChart chart = charts.get(i); ChartPanel chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize( new Dimension(GridChartPanel.DEFAULT_WIDTH, GridChartPanel.DEFAULT_HEIGHT)); chartPanel.revalidate(); chartPanel.setMouseZoomable(true); add(chartPanel); fireProgressIncremented(this, i); } fireProgressEnded(this); } }