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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 5 16:13:37 CEST 2011


Author: mojays
Date: 2011-05-05 16:13:36 +0200 (Thu, 05 May 2011)
New Revision: 1572

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
SwingUtil.setEditable(.) ueberarbeitet
neue Methode LangUtil.checkEqual(.) mit (null == null) = TRUE

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-04-28 20:55:09 UTC (rev 1571)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java	2011-05-05 14:13:36 UTC (rev 1572)
@@ -232,6 +232,14 @@
 	}
 
 	/**
+	 * Checks whether both objects are {@code null} or equal.
+	 */
+	public static boolean checkEqual(Object o1, Object o2) {
+	  return o1 == null && o2 == null ||
+	         o1 != null && o2 != null && o1.equals(o2);
+	}
+ 
+	/**
 	 * Haengt Strings aneinander, getrennt durch Trennzeichen.
 	 * 
 	 * @param delim

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-04-28 20:55:09 UTC (rev 1571)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-05-05 14:13:36 UTC (rev 1572)
@@ -72,6 +72,7 @@
 import javax.swing.CellEditor;
 import javax.swing.DefaultCellEditor;
 import javax.swing.ImageIcon;
+import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JFormattedTextField;
@@ -86,6 +87,7 @@
 import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.JTree;
+import javax.swing.JViewport;
 import javax.swing.SwingUtilities;
 import javax.swing.table.TableCellEditor;
 import javax.swing.table.TableCellRenderer;
@@ -817,16 +819,25 @@
      * Enables or disables all input components ({@link JTextComponent}, {@link JComboBox},
      * ...) of a panel recursively..
      */
-    public static void setEditable(javax.swing.JPanel panel, boolean editable) {
-      for (Component comp : panel.getComponents()) {
-        if ( comp instanceof JTextComponent )
-          ((JTextComponent)comp).setEditable(editable);
-        if ( comp instanceof JComboBox )
-//          ((JComboBox)comp).setEditable(editable);
-          ((JComboBox)comp).setEnabled(editable);
-        if ( comp instanceof de.schmitzm.swing.JPanel )
-          ((de.schmitzm.swing.JPanel)comp).setEditable(editable);
-      }
+    public static void setEditable(Component component, boolean editable) {
+      // simple components
+      if ( component instanceof JTextComponent )
+//        ((JTextComponent)component).setEditable(editable);
+        ((JTextComponent)component).setEnabled(editable);
+      if ( component instanceof JComboBox )
+        ((JComboBox)component).setEnabled(editable);
+      if ( component instanceof JCheckBox )
+        ((JCheckBox)component).setEnabled(editable);
+      
+      // recursive components
+      if ( component instanceof javax.swing.JPanel )
+        for (Component comp : ((javax.swing.JPanel)component).getComponents())
+          setEditable(comp, editable);
+      if ( component instanceof JScrollPane )
+        for (Component comp : ((JScrollPane)component).getComponents())
+          setEditable(comp, editable);
+      if ( component instanceof JViewport )
+        setEditable(((JViewport)component).getView(), editable);
     }
 
 	/**



More information about the Schmitzm-commits mailing list