changeset 618:6a179175bb1b

Charts refactoring review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003207.html reviewed-by: rkennke
author Mario Torre <neugens.limasoftware@gmail.com>
date Tue, 18 Sep 2012 14:34:23 +0200
parents a325470a7366
children 8172d6f0f918
files client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/chart/OverviewChart.java client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java client/swing-components/src/main/java/com/redhat/thermostat/charts/Chart.java client/swing-components/src/main/java/com/redhat/thermostat/swing/ChartPanel.java thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/LivingDaemonThreadDifferenceChart.java thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/chart/ThreadDeatailsPieChart.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadDetailsView.java thread/client-swing/src/main/java/com/redhat/thermostat/thread/client/swing/impl/SwingThreadView.java
diffstat 8 files changed, 26 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- 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();
         
--- 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);
--- 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
- * <http://www.gnu.org/licenses/>.
- *
- * 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);
-}
--- 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;
+    }
 }
--- 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);
--- 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);
         
--- 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);
--- 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();