[Schmitzm-commits] r2121 - trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sun Nov 4 16:30:09 CET 2012


Author: mojays
Date: 2012-11-04 16:30:08 +0100 (Sun, 04 Nov 2012)
New Revision: 2121

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/TablePopupMenuListener.java
Log:
new TablePopupMenuListener

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/TablePopupMenuListener.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/TablePopupMenuListener.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/event/TablePopupMenuListener.java	2012-11-04 15:30:08 UTC (rev 2121)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ ******************************************************************************/
+package de.schmitzm.swing.event;
+
+import java.awt.event.MouseEvent;
+
+import javax.swing.JPopupMenu;
+import javax.swing.JTable;
+
+/**
+ * Diese Klasse implementiert einen MouseListener, der auf einen
+ * PopupTrigger speziell auf {@link JTable} lauscht.
+ * Sofern beim Popup-Trigger noch keine Zeile in der Tabelle selektiert ist,
+ * wird die Zeile unterhalb des Mausklicks automatisch selektiert.
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * @version 1.0
+ */
+public class TablePopupMenuListener extends PopupMenuListener {
+  protected JTable table;
+
+  /**
+   * Erzeugt einen neuen Listener
+   * @param menu Popup-Menue, welches geoeffnet werden soll
+   * @param table 
+   */
+  public TablePopupMenuListener(JPopupMenu menu, JTable table) {
+    super(menu);
+    this.table = table;
+  }
+
+  /**
+   * Wenn boch keine Zeile selektiert ist, wird die Zeile unter
+   * dem Mausklick autom. selektiert.
+   */
+  @Override
+  protected void checkPopupSignal(MouseEvent e) {
+    super.checkPopupSignal(e);
+    // Wenn noch keine Zeile (oder nur eine Zeile) markiert ist, die Selektion
+    // automatisch auf die geklickte Zeile einstellen
+    if ( e.isPopupTrigger() && table.getSelectedRowCount() <= 1 ) {
+      int row = table.rowAtPoint(e.getPoint());
+      if ( row >= 0 )
+        table.getSelectionModel().setSelectionInterval(row, row);
+    }
+  }
+}



More information about the Schmitzm-commits mailing list