[Schmitzm-commits] r2422 - in trunk/schmitzm-core/src/main: java/de/schmitzm/lang resources/de/schmitzm/swing/resource/icons/large resources/de/schmitzm/swing/resource/icons/small
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Thu Jul 14 19:39:29 CEST 2016
Author: mojays
Date: 2016-07-14 19:39:29 +0200 (Thu, 14 Jul 2016)
New Revision: 2422
Added:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/DefaultApplicationProps.java
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/large/java_coffee_cup.png
trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/java_coffee_cup.png
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java
Log:
ApplicationProps: method to retrieve date property
DefaultApplicationProps: default implementation of ApplicationProps
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java 2016-06-23 15:50:57 UTC (rev 2421)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java 2016-07-14 17:39:29 UTC (rev 2422)
@@ -38,8 +38,12 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -65,6 +69,9 @@
/** TODO: Rethink where this "default" shall be used. */
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
+ /** Default format to encode data values */
+ public static final DateFormat DEFAULT_DATE_FORMAT = SimpleDateFormat.getDateTimeInstance();
+
/**
* This stores the properties
*/
@@ -252,6 +259,28 @@
return get(key,String.class,defaultValue[0]);
}
+ public Date getDate(KEYS key, Date... defaultValue) throws ParseException {
+ return getDate(key, (DateFormat)null, defaultValue);
+ }
+
+ public Date getDate(KEYS key, String dateFormat, Date... defaultValue) {
+ return getDate(key, new SimpleDateFormat(dateFormat), defaultValue);
+ }
+
+ public Date getDate(KEYS key, DateFormat format, Date... defaultValue) {
+ if (format == null)
+ format = DEFAULT_DATE_FORMAT;
+ String dateStr = getString(key, "");
+ if ( StringUtils.isBlank(dateStr) )
+ return defaultValue.length > 0 ? defaultValue[0] : null;
+ try {
+ Date date = format.parse(dateStr);
+ return date;
+ } catch (ParseException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
/**
* Parses a map from string.
* @param key key to semicolon-separated list of "key:value" pairs
Added: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/DefaultApplicationProps.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/DefaultApplicationProps.java (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/DefaultApplicationProps.java 2016-07-14 17:39:29 UTC (rev 2422)
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ *
+ * This file is part of the SCHMITZM library - a collection of utility
+ * classes based on Java 1.6, focusing (not only) on Java Swing
+ * and the Geotools library.
+ *
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Martin O. J. Schmitz - initial API and implementation
+ * Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.lang;
+
+import java.net.URL;
+
+/**
+ * Default implementation of {@link ApplicationProps}, which uses a fixed application
+ * name for properties file and folder. The default properties file has to be located
+ * in the application project root folder!
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class DefaultApplicationProps<KEYS> extends ApplicationProps<KEYS> {
+ /** Application name used for properties file name and folder */
+ protected String applName;
+ /** Defines the resource folder for the default properties file */
+ protected Class applResourceBase;
+
+ /**
+ * Creates a new instance
+ * @param applName Application name used for properties file name and folder
+ * @param resourceBase defines the resource folder for the default properties file
+ * @param load indicates whether to immediately load the properties from file
+ * @param autoSave indicates whether to immediately store the properties file after
+ * a property was changed
+ */
+ public DefaultApplicationProps(String applName, Class resourceBase, boolean load, boolean autoSave) {
+ super(false, autoSave);
+ this.applName = applName;
+ this.applResourceBase = resourceBase;
+ if (load)
+ load();
+ }
+
+ /**
+ * Creates a new instance with class name as application name.
+ * @param applClass Application used for properties file name and folder
+ * @param load indicates whether to immediately load the properties from file
+ * @param autoSave indicates whether to immediately store the properties file after
+ * a property was changed
+ */
+ public DefaultApplicationProps(Class applClass, boolean load, boolean autoSave) {
+ this(applClass.getSimpleName(), applClass, load, autoSave);
+ }
+
+ /**
+ * Returns the location of the default properties file used if there is no one in the user home.
+ */
+ @Override
+ public URL getDefaultPropertiesFile() {
+ URL defaultPropsFile = applResourceBase.getResource("/" + applName+".default.properties");
+ return defaultPropsFile;
+ }
+
+ /**
+ * Returns the folder of the properties file in the user home.
+ */
+ @Override
+ public String getPropertiesFolderName() {
+ return "."+applName;
+ }
+
+ /**
+ * Returns the name of the properties file.
+ */
+ @Override
+ public String getPropertiesFilename() {
+ return applName + ".properties";
+ }
+
+ /**
+ * Returns the name of the properties file.
+ */
+ @Override
+ public String getPropertiesFileDescription() {
+ return "This file contains the parameters/defaults for the "+applName+" application.";
+ }
+
+}
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/large/java_coffee_cup.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/large/java_coffee_cup.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/java_coffee_cup.png
===================================================================
(Binary files differ)
Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/java_coffee_cup.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Schmitzm-commits
mailing list