[Schmitzm-commits] r1769 - in trunk/schmitzm-core/src/main/java/de/schmitzm: lang swing swing/input

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 2 18:05:07 CET 2011


Author: mojays
Date: 2011-11-02 18:05:07 +0100 (Wed, 02 Nov 2011)
New Revision: 1769

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java
Log:
ManualInputOption.Double: optional use of decimal comma for input
ApplicationProps: method getChar()
ApplicationFrame: handle null value for icon name in createAction(.)

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java	2011-10-29 23:22:03 UTC (rev 1768)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ApplicationProps.java	2011-11-02 17:05:07 UTC (rev 1769)
@@ -177,6 +177,12 @@
     return get(key,String.class,defaultValue[0]);
   }
   
+  public Character getChar(KEYS key, Character... defaultValue) {
+    if ( defaultValue.length == 0 )
+      return get(key,Character.class);
+    return get(key,Character.class,defaultValue[0]);
+  }
+
   //***************************************************
   //************* SETTER ******************************
   //***************************************************

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java	2011-10-29 23:22:03 UTC (rev 1768)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ApplicationFrame.java	2011-11-02 17:05:07 UTC (rev 1769)
@@ -125,8 +125,11 @@
    *        under {@code 'resource/icons/small/..'} in {@link SwingUtil} resource path) 
    */
   protected Action createAction(String title, String commandID, String desc, String iconName) {
-    String iconPath = "resource/icons/small/"+iconName;
-    ImageIcon icon = SwingUtil.createImageIconFromResourcePath(iconPath, null);
+    ImageIcon icon = null;
+    if ( iconName != null ) {
+      String iconPath = "resource/icons/small/"+iconName;
+      icon = SwingUtil.createImageIconFromResourcePath(iconPath, null);
+    }
     return SwingUtil.createAction(title, this.menuActionListener, commandID, desc, icon);
   }
 

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java	2011-10-29 23:22:03 UTC (rev 1768)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java	2011-11-02 17:05:07 UTC (rev 1769)
@@ -317,6 +317,10 @@
 	 * @version 1.0
 	 */
 	public static class Double extends ManualInputOption {
+	    /** Flag whether a comma should be uses as decimal sign (Default:
+	     *  FALSE = decimal dot) */
+	    public static boolean DECIMAL_COMMA = false;
+	    
 		/**
 		 * Erzeugt eine neue Eingabe-Option.
 		 * 
@@ -375,9 +379,9 @@
          */
         @Override
         protected JTextField createInputComponent() {
+            int style = DECIMAL_COMMA ? LimitedDocument.STYLE_DECIMAL_COMMA : LimitedDocument.STYLE_DECIMAL;  
             return SwingUtil.createLimitedTextField(
-                LimitedDocument.STYLE_NO_LIMIT,
-                LimitedDocument.STYLE_DECIMAL);
+                LimitedDocument.STYLE_NO_LIMIT,style);
         }
 
 		/**
@@ -401,17 +405,29 @@
 		protected java.lang.Double performGetValue() {
 			if (inputEmpty())
 				return null;
-			return java.lang.Double.parseDouble(((JTextField) inpComp)
-					.getText());
+//			return java.lang.Double.parseDouble(((JTextField) inpComp)
+//					.getText());
+			return convertCurrentValue();
 		}
 
+		private java.lang.Double convertCurrentValue() {
+          String doubleStr = ((JTextField)inpComp).getText();
+          if ( DECIMAL_COMMA && doubleStr != null )
+            doubleStr = doubleStr.replaceAll(",", ".");
+          return java.lang.Double.parseDouble(doubleStr);
+		}
+		
 		/**
 		 * Prueft, ob ein gueltiger Double-Wert im Feld eingegeben wurde.
 		 */
 		@Override
 		protected boolean performIsInputValid() {
 			try {
-				java.lang.Double.parseDouble(((JTextField) inpComp).getText());
+//			  String doubleStr = ((JTextField)inpComp).getText();
+//			  if ( DECIMAL_COMMA && doubleStr != null )
+//			    doubleStr = doubleStr.replaceAll(",", ".");
+//			  java.lang.Double.parseDouble(doubleStr);
+			  convertCurrentValue();
 			} catch (NumberFormatException err) {
 				return false;
 			}



More information about the Schmitzm-commits mailing list