[Schmitzm-commits] r236 - in trunk/src: schmitzm/jfree/chart/style skrueger skrueger/jnlp

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jul 27 12:40:36 CEST 2009


Author: alfonx
Date: 2009-07-27 12:40:35 +0200 (Mon, 27 Jul 2009)
New Revision: 236

Added:
   trunk/src/schmitzm/jfree/chart/style/ChartType.java
   trunk/src/skrueger/jnlp/
   trunk/src/skrueger/jnlp/JNLPUtil.java
Log:
* Created a new utility class JNLPUtil in schmitzm
* Added JNLP SingleInstance support to AV and GP

Added: trunk/src/schmitzm/jfree/chart/style/ChartType.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartType.java	2009-07-19 11:53:01 UTC (rev 235)
+++ trunk/src/schmitzm/jfree/chart/style/ChartType.java	2009-07-27 10:40:35 UTC (rev 236)
@@ -0,0 +1,90 @@
+package schmitzm.jfree.chart.style;
+
+import java.awt.image.BufferedImage;
+import java.net.URL;
+
+import javax.swing.ImageIcon;
+
+import org.apache.log4j.Logger;
+
+import schmitzm.jfree.JFreeChartUtil;
+import schmitzm.lang.ResourceProvider;
+
+/**
+ * Enum representing the style type of a chart (bar, line, area)
+ */
+public enum ChartType {
+
+	/** Represents all bar chart styles */
+	BAR,
+	/** Represents all line chart styles */
+	LINE,
+	/** Represents all area chart styles */
+	AREA,
+	/** Represents all point chart styles */
+	POINT,
+	/** Represents all pie chart styles */
+	PIE,
+	/** Represents all gantt chart styles */
+	GANTT,
+	/** Represents all timeseries chart styles */
+	TIMESERIES,
+	/** Represents all spider chart styles */
+	SPIDER,
+	/** Represents all scatter chart styles */
+	SCATTER;
+
+	final static Logger LOGGER = Logger.getLogger(ChartType.class);
+
+	/**
+	 * 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;
+	}
+};
\ No newline at end of file


Property changes on: trunk/src/schmitzm/jfree/chart/style/ChartType.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/src/skrueger/jnlp/JNLPUtil.java
===================================================================
--- trunk/src/skrueger/jnlp/JNLPUtil.java	2009-07-19 11:53:01 UTC (rev 235)
+++ trunk/src/skrueger/jnlp/JNLPUtil.java	2009-07-27 10:40:35 UTC (rev 236)
@@ -0,0 +1,51 @@
+package skrueger.jnlp;
+
+import javax.jnlp.ServiceManager;
+import javax.jnlp.SingleInstanceListener;
+import javax.jnlp.SingleInstanceService;
+import javax.jnlp.UnavailableServiceException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * A utility class with static methods that deal with JNLP / JavaWebStart
+ * related stuff.
+ * 
+ * @author Stefan Alfons Krueger
+ * 
+ */
+public class JNLPUtil {
+	
+	/**
+	 * Registers the given instance to the {@link SingleInstanceService} - if we
+	 * are running in JavaWebStart context.
+	 * 
+	 * @param instance
+	 *            The {@link SingleInstanceListener} instance.
+	 * @param add
+	 *            If <code>true</code> the instance will be added to the
+	 *            {@link SingleInstanceService}. Otherwise it will be removed.
+	 */
+	public static void registerAsSingleInstance(
+			SingleInstanceListener instance, boolean add) {
+
+		Logger LOGGER = Logger.getLogger(instance.getClass());
+
+		try {
+			SingleInstanceService singleInstanceService = (SingleInstanceService) ServiceManager
+					.lookup("javax.jnlp.SingleInstanceService");
+			// add the listener to this application!
+
+			if (add) {
+				LOGGER.info("Registering as a JNLP SingleInstance...");
+				singleInstanceService.addSingleInstanceListener(instance);
+			} else {
+				LOGGER.info("Un-registering as a JNLP SingleInstance...");
+				singleInstanceService.removeSingleInstanceListener(instance);
+			}
+			LOGGER.info(" ...OK!");
+		} catch (UnavailableServiceException use) {
+		}
+
+	}
+}


Property changes on: trunk/src/skrueger/jnlp/JNLPUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list