[Schmitzm-commits] r214 - in trunk/src/schmitzm: geotools/feature jfree jfree/chart/style jfree/resource jfree/resource/images jfree/resource/locales swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jul 13 19:30:42 CEST 2009


Author: alfonx
Date: 2009-07-13 19:30:41 +0200 (Mon, 13 Jul 2009)
New Revision: 214

Added:
   trunk/src/schmitzm/jfree/resource/images/
   trunk/src/schmitzm/jfree/resource/images/ChartType_BAR.png
   trunk/src/schmitzm/jfree/resource/images/ChartType_PIE.png
Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/jfree/JFreeChartUtil.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
   trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties
   trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle_de.properties
   trunk/src/schmitzm/swing/SwingUtil.java
Log:
* Extended the ChartStype.ChartType-Enum to provide more information about itself (like icon, title, desc). 
* Created a frist version of a CharWizard to create ChartStyles in GP.. Have a look at ChartWizard.main() !

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-07-13 17:30:41 UTC (rev 214)
@@ -82,6 +82,13 @@
    *  hinterlegt. */
   public static ResourceProvider RESOURCE = new ResourceProvider( LangUtil.extendPackagePath(FeatureUtil.class,"resource.locales.FeatureResourceBundle"), Locale.ENGLISH );
 
+	/**
+	 * Convenience method to access the {@link ResourceProvider}.
+	*/
+	public static String R(String key, Object... values) {
+		return RESOURCE.getString(key, values);
+	}
+
   private static final Logger LOGGER = LangUtil.createLogger(FeatureUtil.class);
 
   private static final String DEFAULT_VECTOR_STYLE_NAME = "default vector style";

Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java	2009-07-13 17:30:41 UTC (rev 214)
@@ -87,6 +87,13 @@
    *  hinterlegt. */
   public static ResourceProvider RESOURCE = new ResourceProvider( LangUtil.extendPackagePath(JFreeChartUtil.class,"resource.locales.JFreeResourceBundle"), Locale.ENGLISH );
 
+	/**
+	 * Convenience method to access the {@link ResourceProvider}.
+	*/
+	public static String R(String key, Object... values) {
+		return RESOURCE.getString(key, values);
+	}
+
   /** Instance of {@link ChartStyleXMLFactory}. */
   public static final ChartStyleXMLFactory<ChartStyle> CHART_STYLE_FACTORY = new ChartStyleXMLFactory<ChartStyle>();
 

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyle.java	2009-07-13 17:30:41 UTC (rev 214)
@@ -12,11 +12,18 @@
 package schmitzm.jfree.chart.style;
 
 import java.awt.Paint;
+import java.awt.image.BufferedImage;
+import java.net.URL;
 
+import javax.swing.ImageIcon;
+
+import org.apache.log4j.Logger;
 import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.Plot;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.data.general.Dataset;
+
+import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.lang.ResourceProvider;
 
 /**
  * This interface is a general super class for a design style of a {@link JFreeChart}.
@@ -27,7 +34,9 @@
  * @author <a href="mailto:Martin.Schmitz at koeln.de">Martin Schmitz</a>
  * @version 1.0
  */
-public interface ChartStyle {
+public interface ChartStyle {
+	
+	final static Logger LOGGER = Logger.getLogger(ChartStyle.class);
   /**
    * Enum representing the style type of a chart (bar, line, area)
    */
@@ -49,7 +58,63 @@
     /** Represents all spider chart styles */
     SPIDER,
     /** Represents all scatter chart styles */
-    SCATTER
+    SCATTER;
+
+	    /**
+		 * Returns an image of 300x200 pixels that shows a hypothetical
+		 * chart of the given type. Never returns <code>null</code>, but rather
+		 * a default image. The images are not cached, so if ut's called often,
+		 * cache it yourself.
+		 */
+		public ImageIcon getIcon() {
+			final String fileName = getClass().getSimpleName() + "_"
+					+ toString();
+
+			final String imageResPath = "../../resource/images/" + fileName
+					+ ".png";
+
+			// LOGGER.debug("Looking for image " + imageResPath);
+			final URL imageUrl = ChartStyle.class.getResource(imageResPath);
+
+			if (imageUrl == null) {
+				// Create a default icon
+				final BufferedImage bufferedImage = new BufferedImage(300, 200,
+						BufferedImage.TYPE_INT_RGB);
+				bufferedImage.getGraphics().drawString("no preview available",
+						20, 110); // i8n
+				return new ImageIcon(bufferedImage);
+
+			}
+			return new ImageIcon(imageUrl);
+		}
+		
+		/**
+		 * Returns a description of this kind of chart. Can be used for
+		 * tool-tips. May return <code>null</code> if no localized String found.
+		 */
+		public String getDescription() {
+			final String resource = JFreeChartUtil.R(getClass().getSimpleName()
+					+ "_" + toString() + ".Desc");
+			if (resource == null
+					|| resource
+							.equals(ResourceProvider.MISSING_RESOURCE_STRING))
+				return null;
+			return resource;
+		}
+
+		/**
+		 * Returns a localized title of this kind of chart. If no localized
+		 * string found, return the Enum.toString()
+		 */
+		public String getTitle() {
+			final String resource = JFreeChartUtil.R(getClass().getSimpleName()
+					+ "_" + toString() + ".Title");
+			if (resource == null
+					|| resource
+							.equals(ResourceProvider.MISSING_RESOURCE_STRING))
+				return toString();
+			return resource;
+		}
   };
   
   /** Constant for the domain axis (X). */

Added: trunk/src/schmitzm/jfree/resource/images/ChartType_BAR.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/schmitzm/jfree/resource/images/ChartType_BAR.png
___________________________________________________________________
Name: svn:mime-type
   + image/png

Added: trunk/src/schmitzm/jfree/resource/images/ChartType_PIE.png
===================================================================
(Binary files differ)


Property changes on: trunk/src/schmitzm/jfree/resource/images/ChartType_PIE.png
___________________________________________________________________
Name: svn:mime-type
   + image/png

Modified: trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties
===================================================================
--- trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle.properties	2009-07-13 17:30:41 UTC (rev 214)
@@ -8,3 +8,6 @@
 diagram.lines=Lines
 diagram.bars=Bars
 diagram.areas=Areas
+
+ChartType_BAR.Desc=Its a great thing to have a few barcharts at hand.
+ChartType_BAR.Title=bar-chart
\ No newline at end of file

Modified: trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle_de.properties
===================================================================
--- trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle_de.properties	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/jfree/resource/locales/JFreeResourceBundle_de.properties	2009-07-13 17:30:41 UTC (rev 214)
@@ -8,3 +8,6 @@
 diagram.lines=Linien
 diagram.bars=Balken
 diagram.areas=Flächen
+
+ChartType_BAR.Desc=<html>Ein Balkendiagram ist eine tolle Sache.</html>
+ChartType_BAR.Title=Balkendiagramm
\ No newline at end of file

Modified: trunk/src/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/src/schmitzm/swing/SwingUtil.java	2009-07-13 17:13:17 UTC (rev 213)
+++ trunk/src/schmitzm/swing/SwingUtil.java	2009-07-13 17:30:41 UTC (rev 214)
@@ -69,14 +69,8 @@
 					"resource.locales.SwingResourceBundle"), Locale.ENGLISH);
 
 	/**
-	 * Convenience method to access the {@link AtlasCreator}s translation
-	 * resources.
-	 * 
-	 * @param key
-	 *            the key for the Geopublisher.properties file
-	 * @param values
-	 *            optional values
-	 */
+	 * Convenience method to access the translation resources.
+	*/
 	public static String R(String key, Object... values) {
 		return RESOURCE.getString(key, values);
 	}



More information about the Schmitzm-commits mailing list