[Schmitzm-commits] r2336 - in trunk/schmitzm-core/src/main/java/de/schmitzm: swing versionnumber
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sun Jun 9 17:06:36 CEST 2013
Author: mojays
Date: 2013-06-09 17:06:36 +0200 (Sun, 09 Jun 2013)
New Revision: 2336
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java
trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java
Log:
InfoDialog: frame automatically centered relatively to parent frame, each time the InfoFrame becomes visible
ReleaseUtil: new methods to generate date from build number
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java 2013-06-08 15:48:02 UTC (rev 2335)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/InfoDialog.java 2013-06-09 15:06:36 UTC (rev 2336)
@@ -84,6 +84,17 @@
}
/**
+ * Automatically centers the dialog according to parent each time
+ * the dialog becomes visible.
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ if ( !isVisible() && visible )
+ SwingUtil.setRelativeFramePosition(this, getOwner(), 0.5, 0.5);
+ super.setVisible(visible);
+ }
+
+ /**
* Creates the table model instance.
*/
protected InfoTableModel createTableModel() {
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java 2013-06-08 15:48:02 UTC (rev 2335)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/versionnumber/ReleaseUtil.java 2013-06-09 15:06:36 UTC (rev 2336)
@@ -4,8 +4,11 @@
import java.io.FileWriter;
import java.io.InputStream;
import java.net.URL;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
@@ -137,7 +140,52 @@
}
- /**
+ /**
+ * Generates the date from build number. Requires that build number is stored
+ * as "yyyyMMddHHmm" in release.properties.
+ * @param clazz
+ * Pass a class that resides in the same "project" or jar, where the /release.properties resides as well.
+ *
+ * @Return the timestamp (generated from {@link #getVersionBuild(Class)})
+ */
+ public static Date getVersionDate(Class<?> clazz) {
+ String build = getVersionBuild(clazz);
+ if ( StringUtils.isBlank(build) )
+ return null;
+ try {
+ DateFormat format = new SimpleDateFormat("yyyyMMddHHmm");
+ return format.parse(build);
+ } catch (final Exception e) {
+ log.warn("build number in /release.properties can not be parsed to Date: " + build);
+ return null;
+ }
+ }
+
+ /**
+ * Generates the date from build number. Requires that build number is stored
+ * as "yyyyMMddHHmm" in release.properties.
+ * @param clazz
+ * Pass a class that resides in the same "project" or jar, where the /release.properties resides as well.
+ * @param date format pattern (see {@link SimpleDateFormat})
+ *
+ * @Return the timestamp (generated from {@link #getVersionBuild(Class)}) formated to given {@link SimpleDateFormat} pattern
+ */
+ public static String getVersionDateStr(Class<?> clazz, String pattern) {
+ if ( StringUtils.isBlank(pattern) )
+ pattern = "dd.MM.yyyy";
+ Date versionDate = getVersionDate(clazz);
+ if ( versionDate == null )
+ return null;
+ try {
+ DateFormat format = new SimpleDateFormat(pattern);
+ return format.format(versionDate);
+ } catch (final Exception e) {
+ log.error("date can not be formated: " + versionDate+" --> "+pattern);
+ return null;
+ }
+ }
+
+ /**
* @param clazz
* Pass a class that resides in the same "project" or jar, where the /release.properties resides as well.
*
More information about the Schmitzm-commits
mailing list