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

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 10 19:33:09 CET 2013


Author: mojays
Date: 2013-01-10 19:33:09 +0100 (Thu, 10 Jan 2013)
New Revision: 2187

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ButtonGroup.java
Log:
LangUtil: proprietary method createUmlauts(.)
ButtonGroup: when ButtonGroup is used for JCheckBox a click on last selected check box clears the selection

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2013-01-09 17:28:36 UTC (rev 2186)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2013-01-10 18:33:09 UTC (rev 2187)
@@ -217,6 +217,28 @@
     }
 
     /**
+     * Replaces all 'ae', 'oe', 'ue' and 'ss' occurrences by umlauts.
+     * Note: This method may not be very save, because grammer is not taken into account!
+     * E.g. a word-splitting 'ae' is also replaced by 'ä' or 'ss' in 'Wasser' is replaced by
+     * 'ß', although the result is not correctly spelled!
+     */
+    public static String createUmlauts(String str) {
+        if ( str == null )
+          return null;
+        str = str.replaceAll("ae","ä");
+        str = str.replaceAll("oe","ö");
+        str = str.replaceAll("ue","ü");
+        str = str.replaceAll("ss","ß");
+        str = str.replaceAll("AE","Ä");
+        str = str.replaceAll("OE","Ö");
+        str = str.replaceAll("UE","Ü");
+        str = str.replaceAll("Ae","Ä");
+        str = str.replaceAll("Oe","Ö");
+        str = str.replaceAll("Ue","Ü");
+        return str;
+    }
+
+    /**
 	 * Returns "+" for positive values and "-" for negative values.
 	 * 
 	 * @param value

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ButtonGroup.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ButtonGroup.java	2013-01-09 17:28:36 UTC (rev 2186)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ButtonGroup.java	2013-01-10 18:33:09 UTC (rev 2187)
@@ -29,8 +29,16 @@
  ******************************************************************************/
 package de.schmitzm.swing;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.swing.AbstractButton;
 import javax.swing.ButtonModel;
+import javax.swing.JCheckBox;
 import javax.swing.JRadioButton;
 
 /**
@@ -41,9 +49,12 @@
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  * @version 1.0
  */
-public class ButtonGroup extends javax.swing.ButtonGroup {
+public class ButtonGroup extends javax.swing.ButtonGroup implements ActionListener {
   private JRadioButton deactivationButton = new JRadioButton();
 
+  /** Holds the last selected button. */
+  protected AbstractButton lastSelectedButton = null;
+
   /**
    * Erzeugt eine neue Button-Gruppe.
    */
@@ -88,4 +99,38 @@
     }
     return null;
   }
+
+  /**
+   * Besides calling the super method, an {@link ActionListener} is
+   * added for {@link JCheckBox}, which allows to deactivate the checkbox.
+   */
+  @Override
+  public void add(AbstractButton button) {
+    super.add(button);
+    if ( button instanceof JCheckBox ) {
+      button.addActionListener(this);
+      if ( button.isSelected() )
+        lastSelectedButton = button;
+    }
+  }
+
+  
+  /**
+   * Listens to the {@link JCheckBox} actions. When an already selected
+   * {@link JCheckBox} is clicked again, the {@link ButtonGroup} is
+   * set unselected.
+   */
+  @Override
+  public void actionPerformed(ActionEvent e) {
+    if ( !(e.getSource() instanceof AbstractButton) )
+      return;
+    AbstractButton button = (AbstractButton)e.getSource();
+    // if last selected button is clicked again the selection 
+    // is cleared
+    if ( e.getSource() == lastSelectedButton ) {
+      setUnselected();
+      lastSelectedButton = null;
+    } else
+      lastSelectedButton = button;
+  }
 }



More information about the Schmitzm-commits mailing list