# HG changeset patch # User Mario Torre # Date 1347971663 -7200 # Node ID 6a179175bb1b130f58dd8cfd7728c42161bd5fb6 # Parent a325470a7366e5df828f08c3208a896f610563b6 Charts refactoring review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003207.html reviewed-by: rkennke diff -r a325470a7366 -r 6a179175bb1b client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java --- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java Tue Sep 18 10:48:11 2012 +0200 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java Tue Sep 18 14:34:23 2012 +0200 @@ -57,9 +57,8 @@ import org.jfree.data.time.TimeSeriesCollection; import com.redhat.thermostat.charts.BytesTickUnit; -import com.redhat.thermostat.charts.Chart; -public class OverviewChart extends Chart { +public class OverviewChart { private static final ColorUIResource MAIN_BAR_BASE_COLOR = new ColorUIResource(0x4A90D9); @@ -84,8 +83,7 @@ used.setDescription(secondarySeries); } - @Override - protected JFreeChart createChart(int width, int height, Color bgColor) { + public JFreeChart createChart(int height, Color bgColor) { TimeSeriesCollection dataset = new TimeSeriesCollection(); diff -r a325470a7366 -r 6a179175bb1b client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java --- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java Tue Sep 18 10:48:11 2012 +0200 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java Tue Sep 18 14:34:23 2012 +0200 @@ -122,7 +122,7 @@ @Override public void run() { - ChartPanel charts = new ChartPanel(model); + ChartPanel charts = new ChartPanel(model.createChart(stats.getWidth(), stats.getBackground())); stats.setChartPanel(charts); stats.setMax(capacity); diff -r a325470a7366 -r 6a179175bb1b client/swing-components/src/main/java/com/redhat/thermostat/charts/Chart.java --- a/client/swing-components/src/main/java/com/redhat/thermostat/charts/Chart.java Tue Sep 18 10:48:11 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright 2012 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * . - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.charts; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; - -import org.jfree.chart.JFreeChart; - -public abstract class Chart { - - public BufferedImage getChart(int width, int height, Color bgColor) { - JFreeChart chart = createChart(width, height, bgColor); - - BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - chart.draw((Graphics2D) image.getGraphics(), new Rectangle2D.Double(0, 0, width, height), null); - - return image; - } - - protected abstract JFreeChart createChart(int width, int height, Color bgColor); -} diff -r a325470a7366 -r 6a179175bb1b client/swing-components/src/main/java/com/redhat/thermostat/swing/ChartPanel.java --- a/client/swing-components/src/main/java/com/redhat/thermostat/swing/ChartPanel.java Tue Sep 18 10:48:11 2012 +0200 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/ChartPanel.java Tue Sep 18 14:34:23 2012 +0200 @@ -41,20 +41,31 @@ import javax.swing.JPanel; -import com.redhat.thermostat.charts.Chart; +import org.jfree.chart.ChartRenderingInfo; +import org.jfree.chart.JFreeChart; @SuppressWarnings("serial") public class ChartPanel extends JPanel { - private Chart chart; + private JFreeChart chart; + private ChartRenderingInfo info; - public ChartPanel(Chart chart) { + public ChartPanel(JFreeChart chart) { this.chart = chart; } + public ChartPanel(JFreeChart chart, ChartRenderingInfo info) { + this.chart = chart; + this.info = info; + } + @Override protected void paintComponent(Graphics g) { - BufferedImage image = chart.getChart(getWidth(), getHeight(), getBackground()); + BufferedImage image = chart.createBufferedImage(getWidth(), getHeight(), info); g.drawImage(image, 0, 0, null); } + + public ChartRenderingInfo getChartRenderingInfo() { + return info; + } } diff -r a325470a7366 -r 6a179175bb1b thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/LivingDaemonThreadDifferenceChart.java --- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/LivingDaemonThreadDifferenceChart.java Tue Sep 18 10:48:11 2012 +0200 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/LivingDaemonThreadDifferenceChart.java Tue Sep 18 14:34:23 2012 +0200 @@ -47,7 +47,6 @@ import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.TickUnits; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYDifferenceRenderer; @@ -56,10 +55,7 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; -import com.redhat.thermostat.charts.BytesTickUnit; -import com.redhat.thermostat.charts.Chart; - -public class LivingDaemonThreadDifferenceChart extends Chart { +public class LivingDaemonThreadDifferenceChart { private static final ColorUIResource MAIN_BAR_BASE_COLOR = new ColorUIResource(0x4A90D9); @@ -85,8 +81,7 @@ used.setDescription(secondarySeries); } - @Override - protected JFreeChart createChart(int width, int height, Color bgColor) { + public JFreeChart createChart(int height, Color bgColor) { TimeSeriesCollection dataset = new TimeSeriesCollection(); @@ -116,12 +111,13 @@ plot.setDomainPannable(true); XYDifferenceRenderer r = new XYDifferenceRenderer(paint, paint2, false); r.setRoundXCoordinates(true); + plot.setDomainCrosshairLockedOnData(true); plot.setRangeCrosshairLockedOnData(true); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setRenderer(r); - + ValueAxis domainAxis = new DateAxis(xAxis); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); diff -r a325470a7366 -r 6a179175bb1b thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/ThreadDeatailsPieChart.java --- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/ThreadDeatailsPieChart.java Tue Sep 18 10:48:11 2012 +0200 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/ThreadDeatailsPieChart.java Tue Sep 18 14:34:23 2012 +0200 @@ -36,18 +36,15 @@ package com.redhat.thermostat.thread.client.common.chart; -import java.awt.Color; - import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.labels.StandardPieSectionLabelGenerator; import org.jfree.chart.plot.PiePlot3D; import org.jfree.data.general.DefaultPieDataset; -import com.redhat.thermostat.charts.Chart; import com.redhat.thermostat.thread.client.common.ThreadTableBean; -public class ThreadDeatailsPieChart extends Chart { +public class ThreadDeatailsPieChart { private ThreadTableBean thread; @@ -55,8 +52,7 @@ this.thread = thread; } - @Override - protected JFreeChart createChart(int width, int height, Color bgColor) { + public JFreeChart createChart() { DefaultPieDataset dataset = new DefaultPieDataset(); @@ -76,13 +72,11 @@ chart.setAntiAlias(true); PiePlot3D plot = (PiePlot3D) chart.getPlot(); - plot.setBackgroundPaint(bgColor); plot.setStartAngle(290); plot.setForegroundAlpha(0.5f); plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} - {2}")); - plot.setBackgroundPaint(bgColor); plot.setInteriorGap(0.0); diff -r a325470a7366 -r 6a179175bb1b thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadDetailsView.java --- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadDetailsView.java Tue Sep 18 10:48:11 2012 +0200 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadDetailsView.java Tue Sep 18 14:34:23 2012 +0200 @@ -82,7 +82,7 @@ ThreadDetailsChart threadChart = new ThreadDetailsChart(); - ChartPanel threadSummary = new ChartPanel(new ThreadDeatailsPieChart(thread)); + ChartPanel threadSummary = new ChartPanel(new ThreadDeatailsPieChart(thread).createChart()); threadChart.add(threadSummary); details.add(threadChart); diff -r a325470a7366 -r 6a179175bb1b thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java --- a/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Tue Sep 18 10:48:11 2012 +0200 +++ b/thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java Tue Sep 18 14:34:23 2012 +0200 @@ -207,7 +207,7 @@ JPanel pane = timelinePanel.getTimelinePanel(); pane.removeAll(); - ChartPanel charts = new ChartPanel(model); + ChartPanel charts = new ChartPanel(model.createChart(pane.getWidth(), pane.getBackground())); pane.add(charts); pane.revalidate(); pane.repaint();