[Schmitzm-commits] r1814 - in trunk/schmitzm-core/src/main/java/de/schmitzm: lang swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Jan 9 16:27:06 CET 2012
Author: mojays
Date: 2012-01-09 16:27:04 +0100 (Mon, 09 Jan 2012)
New Revision: 1814
Modified:
trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SortableJTable.java
trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
Log:
SwingUtil: new methods setAutoStopTableCellEditing(.) and stopTableCellEditing(.)
SelectableJTable: Automatically apply "terminateEditOnFocusLost" property by calling SwingUtil.setAutoStopTableCellEditing(this, true);
SortableJTable: call of super.initTable() to take new "terminateEditOnFocusLost" property into account
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-01-09 15:24:14 UTC (rev 1813)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/LangUtil.java 2012-01-09 15:27:04 UTC (rev 1814)
@@ -1901,6 +1901,8 @@
return false;
if (trimmedLowcase.startsWith("false"))
return false;
+ if (trimmedLowcase.startsWith("falsch"))
+ return false;
if (trimmedLowcase.startsWith("0"))
return false;
if (trimmedLowcase.startsWith("yes"))
@@ -1921,8 +1923,10 @@
return false;
if (trimmedLowcase.contains("vorhanden"))
return true;
- if (trimmedLowcase.contains("existie"))
+ if (trimmedLowcase.contains("wahr"))
return true;
+ if (trimmedLowcase.contains("existie"))
+ return true;
// Default
return null;
}
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java 2012-01-09 15:24:14 UTC (rev 1813)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java 2012-01-09 15:27:04 UTC (rev 1814)
@@ -120,9 +120,10 @@
/**
* Called by every constructor to initialize the extended
- * functionalities. Currently does nothing.
+ * functionalities.
*/
protected void initTable() {
+ SwingUtil.setAutoStopTableCellEditing(this, true);
}
/**
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SortableJTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SortableJTable.java 2012-01-09 15:24:14 UTC (rev 1813)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SortableJTable.java 2012-01-09 15:27:04 UTC (rev 1814)
@@ -124,7 +124,8 @@
* functionalities.
*/
protected void initTable() {
- setAutoCreateRowSorter(true);
+ super.initTable();
+ setAutoCreateRowSorter(true);
}
/**
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2012-01-09 15:24:14 UTC (rev 1813)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java 2012-01-09 15:27:04 UTC (rev 1814)
@@ -91,6 +91,8 @@
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
@@ -1764,8 +1766,55 @@
return textComp;
}
+
+ /**
+ * Applies a client property to the table that the cell editing is automatically
+ * finished on focus lost.
+ */
+ public static void setAutoStopTableCellEditing(JTable table, boolean enabled) {
+ table.putClientProperty("terminateEditOnFocusLost", Boolean.valueOf(enabled) );
+ }
/**
+ * Calls {@code JTable.getCellEditor().stopCellEditing} (recursively) for all tables
+ * in the given component (panel, scrollpane, ...).<br>
+ * <b>Note:</b><br>
+ * This method is a workaround only for the situation when a window functions (minimize,
+ * maximize, close) is invoked. In this case the {@code terminateEditOnFocusLost} property
+ * does not work!
+ * @see #setAutoStopTableCellEditing(JTable, boolean)
+ */
+ public static void stopTableCellEditing(Component component) {
+ if ( component == null )
+ return;
+
+ // Stop editing
+ if ( component instanceof JTable ) {
+ if ( ((JTable)component).isEditing() )
+ ((JTable)component).getCellEditor().stopCellEditing();
+ }
+
+ // recursive components
+ if ( component instanceof javax.swing.JPanel )
+ for (Component comp : ((javax.swing.JPanel)component).getComponents())
+ stopTableCellEditing(comp);
+ if ( component instanceof JScrollPane )
+ for (Component comp : ((JScrollPane)component).getComponents())
+ stopTableCellEditing(comp);
+ if ( component instanceof JSplitPane )
+ for (Component comp : ((JSplitPane)component).getComponents())
+ stopTableCellEditing(comp);
+ if ( component instanceof JViewport )
+ stopTableCellEditing(((JViewport)component).getView());
+ // For {@link JTabbedPane} only the active tab must applied recursively.
+ // The tables on other tabs should automatically be taken into account by
+ // the {@code terminateEditOnFocusLost} property when tab changes or a button
+ // is clicked!
+ if ( component instanceof JTabbedPane )
+ stopTableCellEditing(((JTabbedPane)component).getSelectedComponent());
+ }
+
+ /**
* Create a {@link JMenu} that allows to switch the Log-Level of the root
* logger.
*/
More information about the Schmitzm-commits
mailing list