[Schmitzm-commits] r1774 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Nov 10 16:09:49 CET 2011


Author: mojays
Date: 2011-11-10 16:09:49 +0100 (Thu, 10 Nov 2011)
New Revision: 1774

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/InputOption.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultiLineTextInputOption.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultipleOptionPane.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
Log:
InputOption: store the possible ScrollPane in protected variable
MultipleOptionPane: possibility to make the dialog resizable
MultiLineTextInputOption: BugFix with preferred size; apply preferred size to complete InputOption (instead of TextPane)
SelectionInputOption: BugFix with preferred size; apply preferred size to complete InputOption (instead of JList)


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/InputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/InputOption.java	2011-11-08 20:20:44 UTC (rev 1773)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/InputOption.java	2011-11-10 15:09:49 UTC (rev 1774)
@@ -70,6 +70,9 @@
 	protected JLabel inputNeededLabel = null;
 	/** Speichert die Eingabe-Komponente der Option. */
 	protected JComponent inpComp = null;
+	/** ScrollPanel, dass die Eingabe-Komponente umgibt (kann {@code null} sein). */
+	protected JScrollPane scrollPane = null;
+	
 	/**
 	 * Kann eine Fehlermeldung enthalten, wenn die Eingabe nicht valide ist.
 	 * Kann direkt von {@link #performIsInputValid()} befuellt werden. Wird
@@ -208,8 +211,10 @@
 	  
 	  // Elemente dem Container hinzufuegen
 	  Component inputPanel = inpComp;
-	  if ( isScrollPaneNeeded() )
-	    inputPanel = new JScrollPane(inputPanel);
+	  if ( isScrollPaneNeeded() ) {
+	    scrollPane = new JScrollPane(inputPanel);
+	    inputPanel = scrollPane;
+	  }
 	  if (label != null) {
 	    // put description and mandatory indicator in an
 	    // container first

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultiLineTextInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultiLineTextInputOption.java	2011-11-08 20:20:44 UTC (rev 1773)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultiLineTextInputOption.java	2011-11-10 15:09:49 UTC (rev 1774)
@@ -40,8 +40,9 @@
       super();
       this.width = cols;
       this.height = rows;
-      init(label, inputNeeded, false);
+      init(label, inputNeeded, true);
       ((JTextComponent)inpComp).setText(defValue);
+      ((JTextComponent)inpComp).setCaretPosition(0);
       
   }
 
@@ -156,7 +157,6 @@
      */
     public TextArea(String label, boolean inputNeeded, String defValue, int rows, int cols) {
         super(label,inputNeeded,defValue,rows,cols);
-        
     }
 
     /**
@@ -232,7 +232,7 @@
      */
     public TextPane(String label, boolean inputNeeded, String defValue, int height, int width) {
         super(label,inputNeeded,defValue,height,width);
-        
+        setPreferredSize( new Dimension(width,height) );
     }
 
     /**
@@ -279,8 +279,6 @@
     @Override
     protected JTextPane createInputComponent() {
       JTextPane textPane = new JTextPane();
-      textPane.setPreferredSize( new Dimension(width, height) );
-      
       return textPane;
     }
   }

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultipleOptionPane.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultipleOptionPane.java	2011-11-08 20:20:44 UTC (rev 1773)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/MultipleOptionPane.java	2011-11-10 15:09:49 UTC (rev 1774)
@@ -118,11 +118,28 @@
    *         verlassen wurde
    */
   public static Object[] showMultipleInputDialog(Component parent, String title, InputOption... option) {
+    return showMultipleInputDialog(parent, false, title, option);
+  }
+  
+  /**
+   * Zeigt einen modalen Ok/Abbrechen-Dialog mit mehrfachen Eingabefeldern an.
+   * @param parent Uebergeordnetes Fenster, in dem der Dialog angezeigt wird
+   *               (kann <code>null</code> sein)
+   * @param title  Titel fuer den Dialog
+   * @param resizable Bestimmt, ob die Groesse des Dialog durch den Benutzer
+   *                  geaendert werden kann
+   * @param option Eingabefelder
+   * @return die Werte, die in den einzelnen Feldern gemacht wurden, oder
+   *         <code>null</code>, falls der Dialog nicht ueber die Ok-Option
+   *         verlassen wurde
+   */
+  public static Object[] showMultipleInputDialog(Component parent, boolean resizable, String title, InputOption... option) {
 	  
 	  // SwingUtil.checkOnEDT();
 	  
     MultipleOptionPane pane   = new MultipleOptionPane(option);
     JDialog            dialog = pane.createDialog(parent,title);
+    dialog.setResizable(resizable); 
     InputOption        invalidOption = null;
     do {
       dialog.setVisible(true);

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2011-11-08 20:20:44 UTC (rev 1773)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2011-11-10 15:09:49 UTC (rev 1774)
@@ -29,6 +29,7 @@
  ******************************************************************************/
 package de.schmitzm.swing.input;
 
+import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -44,6 +45,7 @@
 import javax.swing.JComboBox;
 import javax.swing.JList;
 import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
@@ -638,8 +640,7 @@
      */
     public List(String label, boolean inputNeeded, E[] value, int defIdx, Object[] display, int height, int width) {
       super(label,inputNeeded,value,defIdx, display);
-      ((JList)inpComp).setPreferredSize( new Dimension(width,height) );
-      ((JList)inpComp).revalidate();
+      setPreferredSize( new Dimension(width,height) );
     }
 
     /**
@@ -655,8 +656,7 @@
      */
     public List(String label, boolean inputNeeded, E[] value, E defvalue, Object[] display, int height, int width) {
       super(label,inputNeeded,value,defvalue, display);
-      ((JList)inpComp).setPreferredSize( new Dimension(width,height) );
-      ((JList)inpComp).revalidate();
+      setPreferredSize( new Dimension(width,height) );
     }
 
     /**
@@ -689,8 +689,7 @@
      */
     public List(String label, boolean inputNeeded, E[] value, E defValue, Object[] display, int height, int width, Map<Object,String> tooltip) {
       super(label,inputNeeded,value,defValue,display,tooltip);
-      ((JList)inpComp).setPreferredSize( new Dimension(width,height) );
-      ((JList)inpComp).revalidate();
+      setPreferredSize( new Dimension(width,height) );
     }
 
     /**
@@ -719,6 +718,16 @@
     }
 
     /**
+     * Sets {@code centerInputComp} always to {@code true}, so that {@link JList} (and
+     * {@link JScrollPane}) are put to {@link BorderLayout#CENTER}. This is important 
+     * for the correct behaviour of {@link JScrollPane}.
+     */
+    @Override
+    protected void init(String label, boolean inputNeeded, boolean centerInputComp) {
+      super.init(label, inputNeeded, true);
+    }
+    
+    /**
      * Erzeugt eine neue Instanz von {@link JList}.
      */
     protected JList createInputComponent() {
@@ -736,7 +745,6 @@
         }
       });
       list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
-      list.setPreferredSize( new Dimension(10,10) );
       // Change Listener
       list.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
         Object oldValue = null;



More information about the Schmitzm-commits mailing list