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

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri Jun 7 18:12:24 CEST 2013


Author: mojays
Date: 2013-06-07 18:12:23 +0200 (Fri, 07 Jun 2013)
New Revision: 2331

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/FontZoomListener.java
Log:
FontZoomListener automatically added to every SelectableJTable.

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java	2013-06-07 16:01:16 UTC (rev 2330)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/SelectableJTable.java	2013-06-07 16:12:23 UTC (rev 2331)
@@ -40,6 +40,7 @@
 import javax.swing.table.TableColumnModel;
 import javax.swing.table.TableModel;
 
+import de.schmitzm.swing.event.FontZoomListener;
 import de.schmitzm.swing.table.SelectionTableModel;
 
 /**
@@ -72,7 +73,12 @@
   /** Indicates whether alternating column background is enabled (Default: {@code false}). */
   protected boolean greyedBackgroundEnabled = false;
 
+  /** 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#removeFromComponent() getFontZoomListener.removeFromComponent()}. */
+  protected FontZoomListener fontZoomListener = null;
 
+
   /**
    * Creates an empty table.
    */
@@ -136,7 +142,19 @@
   protected void initTable() {
     setRowHeight(DEFAULT_ROW_HEIGHT);
     SwingUtil.setAutoStopTableCellEditing(this, true);
+    // enable text zoom by +/- key and mouse wheel
+    fontZoomListener = new FontZoomListener(this, false, false);
+    fontZoomListener.initComponent();
   }
+  
+  /**
+   * 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#removeFromComponent()}.
+   */
+  public FontZoomListener getFontZoomListener() {
+    return fontZoomListener;
+  }
 
   /**
    * If a {@link SelectionTableModel} is used, a click on the selection column must not

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/FontZoomListener.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/FontZoomListener.java	2013-06-07 16:01:16 UTC (rev 2330)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/FontZoomListener.java	2013-06-07 16:12:23 UTC (rev 2331)
@@ -58,6 +58,14 @@
   }
 
   /**
+   * Removed this listener from the component as {@link KeyListener} and {@link MouseWheelListener}.
+   */
+  public void removeFromComponent() {
+    comp.removeKeyListener(this);
+    comp.removeMouseWheelListener(this);
+  }
+
+  /**
    * Performs the font resizing.
    * @param resizeFactor 1 to increase the font, and -1 to descrease
    */



More information about the Schmitzm-commits mailing list