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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Nov 16 10:48:58 CET 2011


Author: mojays
Date: 2011-11-16 10:48:57 +0100 (Wed, 16 Nov 2011)
New Revision: 1779

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/DateInputOption.java
Log:
SwingUtil: methods to update JProgressBar on EDT

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-11-14 10:44:19 UTC (rev 1778)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2011-11-16 09:48:57 UTC (rev 1779)
@@ -86,6 +86,7 @@
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
+import javax.swing.JProgressBar;
 import javax.swing.JRadioButtonMenuItem;
 import javax.swing.JScrollPane;
 import javax.swing.JSpinner;
@@ -1835,4 +1836,56 @@
         }
     }
 
+    /**
+     * Sets a {@link JProgressBar} to (in)determinate with the given maximum value.
+     * This is done using {@link SwingUtilities#invokeLater(Runnable)} if
+     * the method is not called on EDT.
+     * @param maxValue maximum value (if <=0 the bar is set to indeterminate!)
+     */
+    public static void setProgressBarDeterminateOnEDT(final JProgressBar bar, final int maxValue) {
+      if ( bar == null )
+        return;
+      final boolean indeterminate = (maxValue <= 0);
+      // define work
+      Runnable work = new Runnable() {
+        @Override
+        public void run() {
+          bar.setIndeterminate(indeterminate);
+          bar.setStringPainted(!indeterminate);
+          if ( !indeterminate ) {
+            bar.setMinimum(0);
+            bar.setMaximum(maxValue);
+          }
+        }
+      };
+      // do work on adaquate thread 
+      if ( SwingUtilities.isEventDispatchThread() )
+        work.run();
+      else
+        SwingUtilities.invokeLater(work);
+    }
+    
+    /**
+     * Updates the value of a {@link JProgressBar}.
+     * This is done using {@link SwingUtilities#invokeLater(Runnable)} if
+     * the method is not called on EDT.
+     */
+    public static void updateProgressBarValueOnEDT(final JProgressBar bar, final int newValue) {
+      if ( bar == null )
+        return;
+      // define work
+      Runnable work = new Runnable() {
+        @Override
+        public void run() {
+          bar.setValue(newValue);
+        }
+      };
+      // do work on adaquate thread 
+      if ( SwingUtilities.isEventDispatchThread() ) {
+        work.run();
+      } else {
+        SwingUtilities.invokeLater(work);
+      }
+    }
+
 }

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/DateInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/DateInputOption.java	2011-11-14 10:44:19 UTC (rev 1778)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/DateInputOption.java	2011-11-16 09:48:57 UTC (rev 1779)
@@ -11,6 +11,7 @@
 
 import de.schmitzm.lang.LangUtil;
 import de.schmitzm.swing.JPanel;
+import de.schmitzm.swing.SwingUtil;
 
 /**
  * Diese Klasse stellt eine Eingabe-Option dar, in der ein Datum
@@ -224,9 +225,12 @@
      */
     @Override
     protected JDateChooser createInputComponent() {
+      JDateChooser dateChooser = null;
       if ( formatMaskPattern != null && formatPlaceholder != null )
-        return new JDateChooser(formatPattern,formatMaskPattern,formatPlaceholder);
-      return new JDateChooser(null,formatPattern);
+        dateChooser = new JDateChooser(formatPattern,formatMaskPattern,formatPlaceholder);
+      else
+        dateChooser = new JDateChooser(null,formatPattern);
+      return dateChooser;
     }
 
     /**



More information about the Schmitzm-commits mailing list