[Schmitzm-commits] r2384 - in trunk/schmitzm-core/src/main: java/de/schmitzm/swing java/de/schmitzm/swing/table resources/de/schmitzm/swing/resource/icons/small

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Aug 9 15:36:44 CEST 2013


Author: mojays
Date: 2013-08-09 15:36:44 +0200 (Fri, 09 Aug 2013)
New Revision: 2384

Added:
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/eye.png
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractMutableListPanel.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractTableModel.java
Log:
SwingUtil.resetCursor(.): modification to avoid glass pane window automatically graps the focus
AbstractTableModel/SelectableJTable: possibility of CellEditor/CellRenderers initialization via TableModel
AbstractMutableListPanel: possibility to add/remove action buttons by instance holder



Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java	2013-08-06 19:53:45 UTC (rev 2383)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java	2013-08-09 13:36:44 UTC (rev 2384)
@@ -41,6 +41,7 @@
 import javax.swing.table.TableModel;
 
 import de.schmitzm.swing.event.FontZoomListener;
+import de.schmitzm.swing.table.AbstractTableModel;
 import de.schmitzm.swing.table.SelectionTableModel;
 
 /**
@@ -77,6 +78,11 @@
    *  using ALT key in combination with +/- keys or mouse wheel.
    *  To remove this behavior use {@link FontZoomListener#disconnectFromComponent() getFontZoomListener.removeFromComponent()}. */
   protected FontZoomListener fontZoomListener = null;
+  
+  /** Internal flag to check whether {@link #initializeLocalVars()} was already called.
+   *  Needed especially to check (during initialization), whether {@link #setDefaultRenderer(Class, TableCellRenderer)}
+   *  or {@link #setDefaultEditor(Class, javax.swing.table.TableCellEditor)} can be called. */
+  protected boolean localVarsInitialized;
 
 
   /**
@@ -145,9 +151,34 @@
     // enable text zoom by +/- key and mouse wheel (combined with ALT)
     fontZoomListener = new FontZoomListener(this);
     fontZoomListener.connectToComponent();
+    setModel( getModel() );
   }
   
   /**
+   * Sets the flag {@link #localVarsInitialized} after return from super method.
+   */
+  protected void initializeLocalVars() {
+    super.initializeLocalVars();
+    this.localVarsInitialized = true;
+  }
+  
+  /**
+   * Besides calling the super method, {@link AbstractTableModel#initCellRenderers(JTable)}
+   * is invoked if new model is a {@link AbstractTableModel}. 
+   */
+  @Override
+  public void setModel(TableModel model) {
+    super.setModel(model);
+    // When local variables (especially "defaultRenderersByColumnClass" and "defaultEditorsByColumnClass")
+    // are not yet initialized, AbstractTableModel.initCellRenderers(.) should not be called
+    // because setDefaultRenderer(.) and setDefaultEditor(.) create an NPE.
+    if ( !localVarsInitialized )
+      return;
+    if ( model instanceof AbstractTableModel )
+      ((AbstractTableModel)model).initCellRenderers(this);
+  }
+  
+  /**
    * Returns the listener which automatically allows to resize the table's font
    * (zoom) by using ALT key in combination with +/- keys or mouse wheel.
    * To remove this behavior use {@link FontZoomListener#disconnectFromComponent()}.

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-08-06 19:53:45 UTC (rev 2383)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SwingUtil.java	2013-08-09 13:36:44 UTC (rev 2384)
@@ -2873,7 +2873,10 @@
             rootPane.getGlassPane().removeFocusListener(DUMMY_FOCUSLISTENER);
             KeyListener keyListener = waitCursorKeyListenerCache.remove(comp);
             rootPane.getGlassPane().removeKeyListener(keyListener); // no problem if listener is NULL!
-            rootPane.getGlassPane().setVisible(false);
+// The following has the disadvantage that the glass pane (window) re-grabs the focus, e.g. of a
+// recently (during wait cursor) opened dialog.
+// Because the command seems to be not necessary, I simply removed it!            
+//            rootPane.getGlassPane().setVisible(false);
           }
         }
       });

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractMutableListPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractMutableListPanel.java	2013-08-06 19:53:45 UTC (rev 2383)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractMutableListPanel.java	2013-08-09 13:36:44 UTC (rev 2384)
@@ -32,6 +32,7 @@
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.ArrayList;
 
 import javax.swing.Action;
 import javax.swing.ImageIcon;
@@ -60,6 +61,15 @@
   /** Holds the "readonly" property of the panel. */
   protected boolean readonly = false;
 
+  /** Holds the possible buttons in the {@link #buttonPanel}. When panel switches
+   *  to readonly the add and remove buttons are not only made invisible, but 
+   *  removed completely from {@link #buttonPanel}. To keep the correct button
+   *  order on re-insert (switch to not-readonly) the buttons are additionally
+   *  maintained by this list.<br>
+   *  This is not directly important for this implementation but e.g. for sub-classes
+   *  which add more actions to the button panel. */
+  protected ArrayList<JButton> buttonOrder = new ArrayList<>();
+
   protected JPanel buttonPanel;
   protected ActionListener buttonActionListener;
   protected Action addAction;
@@ -167,12 +177,32 @@
                                           ICON_RECORD_REMOVE); 
     addButton = new JButton(addAction);
     removeButton = new JButton(removeAction);
-    this.buttonPanel.add( addButton, "growx, height 20" );
-    this.buttonPanel.add( removeButton, "growx, height 20" );
+    addAction(addButton);
+    addAction(removeButton);
+//    updateActions();
+  }
+  
+  /**
+   * Adds an action button to the panel.
+   */
+  public void addAction(JButton button) {
+    // Keep button additionally in "buttonOrder" list
+    buttonOrder.add(button);
+    // re-arrange buttons in panel
     updateActions();
   }
 
   /**
+   * Removes an action button completely from panel.
+   */
+  public void removeAction(JButton button) {
+    // Keep button additionally in "buttonOrder" list
+    buttonOrder.remove(button);
+    // re-arrange buttons in panel
+    updateActions();
+  }
+
+  /**
    *  Updates the button visibility according to read-only state.
    */
   protected void updateActions() {
@@ -184,8 +214,11 @@
       buttonPanel.remove(addButton);
       buttonPanel.remove(removeButton);
     } else {
-      buttonPanel.add(addButton);
-      buttonPanel.add(removeButton);
+//      buttonPanel.add(addButton,"growx, height 20");
+//      buttonPanel.add(removeButton, "growx, height 20");
+      buttonPanel.removeAll();
+      for (JButton b : buttonOrder)
+        buttonPanel.add(b, "growx, height 20");
     }
     validate();
   }

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractTableModel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractTableModel.java	2013-08-06 19:53:45 UTC (rev 2383)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/AbstractTableModel.java	2013-08-09 13:36:44 UTC (rev 2384)
@@ -29,6 +29,11 @@
  ******************************************************************************/
 package de.schmitzm.swing.table;
 
+import javax.swing.JTable;
+import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableModel;
+
 /**
  * Erweitert das Java {@link javax.swing.table.AbstractTableModel} in dem die
  * Methoden {@code #getColumnName(int)} und {@link #getColumnCount()} bereits
@@ -43,7 +48,22 @@
    *  @see #createColumnNames() */
   protected String[] colNames = createColumnNames();
 
+  
   /**
+   * In vielen Faellen sind die in der {@link JTable} zu verwendenen {@link TableCellRenderer}
+   * und {@link TableCellEditor} durch die Spalten des {@link TableModel} bestimmt.
+   * Die Methode ermoeglicht es, deren Initialisierung ebenfalls direkt durch das {@link TableModel}
+   * zu implementieren. Diese Methode muss jedoch explizit aufgerufen werden; idealerweise durch den
+   * Konstruktor der {@link JTable}.<br>
+   * Diese Methode macht nichts, kann jedoch durch die indiviuellen Unter-Klassen ueberschrieben
+   * werden.
+   * @param table Tabelle deren {@link TableCellRenderer} und {@link TableCellEditor} initialisiert
+   *              werden
+   */
+  public void initCellRenderers(JTable table) {
+  }
+  
+  /**
    * Ruft {@link #createColumnNames()} auf und anschliessend
    * {@link #fireTableStructureChanged()}.
    */

Added: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/eye.png
===================================================================
(Binary files differ)


Property changes on: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/icons/small/eye.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream



More information about the Schmitzm-commits mailing list