[Schmitzm-commits] r61 - trunk/src/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 17 19:39:14 CEST 2009


Author: mojays
Date: 2009-04-17 19:39:13 +0200 (Fri, 17 Apr 2009)
New Revision: 61

Added:
   trunk/src/schmitzm/swing/SortedJTable.java
Log:
new SortedJTable.java

Added: trunk/src/schmitzm/swing/SortedJTable.java
===================================================================
--- trunk/src/schmitzm/swing/SortedJTable.java	2009-04-17 17:37:34 UTC (rev 60)
+++ trunk/src/schmitzm/swing/SortedJTable.java	2009-04-17 17:39:13 UTC (rev 61)
@@ -0,0 +1,150 @@
+/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
+
+    This library 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 2.1 of the License, or (at your option) any later version.
+    This library 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 Lesser General Public License for more details.
+    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
+
+    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
+    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
+    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
+ **/
+package schmitzm.swing;
+
+import java.util.Vector;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableModel;
+
+/**
+ * Extends the {@link JTable} with automatic sort functionality.
+ * This class redefines the following methods so that manually calling
+ * {@link JTable#convertRowIndexToModel(int)} and {@link JTable#convertRowIndexToView(int)}
+ * is not necessary:
+ * <ul>
+ *   <li></li>
+ * </ul>   
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ */
+public class SortedJTable extends JTable {
+
+  /**
+   * Creates an empty table.
+   */
+  public SortedJTable() {
+    super();
+    initTable();
+  }
+
+  /**
+   * Creates an empty table.
+   */
+  public SortedJTable(int numRows, int numColumns) {
+    super(numRows, numColumns);
+    initTable();
+  }
+
+  /**
+   * Creates a new table.
+   */
+  public SortedJTable(Object[][] rowData, Object[] columnNames) {
+    super(rowData, columnNames);
+    initTable();
+  }
+
+  /**
+   * Creates a new table.
+   */
+  public SortedJTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
+    super(dm, cm, sm);
+    initTable();
+  }
+
+  /**
+   * Creates a new table.
+   */
+  public SortedJTable(TableModel dm, TableColumnModel cm) {
+    super(dm, cm);
+    initTable();
+  }
+
+  /**
+   * Creates a new table.
+   */
+  public SortedJTable(TableModel dm) {
+    super(dm);
+    initTable();
+  }
+
+  /**
+   * Creates a new table.
+   */
+  public SortedJTable(Vector rowData, Vector columnNames) {
+    super(rowData, columnNames);
+    initTable();
+  }
+  
+  
+  /**
+   * Called by every constructor to initialize the extended
+   * functionalities.
+   */
+  protected void initTable() {
+    setAutoCreateRowSorter(true);
+  }
+  
+  /**
+   * Returns the index of the currently edited row according to
+   * the table model.
+   */
+  public int getEditingRow() {
+    return convertRowIndexToModel(super.getEditingRow());
+  }
+
+  /**
+   * Returns the index of the selected row according to
+   * the table model.
+   */
+  @Override
+  public int getSelectedRow() {
+    return convertRowIndexToModel(super.getSelectedRow());
+  }
+
+  /**
+   * Returns the indices of the selected rows according to
+   * the table model.
+   */
+  @Override
+  public int[] getSelectedRows() {
+    int[] rows = super.getSelectedRows();
+    for (int i=0; i<rows.length; i++)
+      rows[i] = convertRowIndexToModel(rows[i]);
+    return rows;
+  }
+  
+//  /**
+//   * Extends the current selection by the given index interval
+//   * according to the table model.
+//   */
+//  public void addRowSelectionInterval(int index0, int index1) {
+//    for (int i=index0; i<=index1; i++) {
+//      int viewIdx = convertRowIndexToView(i);
+//      super.addRowSelectionInterval(viewIdx, viewIdx);
+//    }
+//  }
+//
+//  /**
+//   * Sets the current selection to the given index interval
+//   * according to the table model.
+//   */
+//  public void setRowSelectionInterval(int index0, int index1) {
+//    clearSelection();
+//    for (int i=index0; i<=index1; i++) {
+//      int viewIdx = convertRowIndexToView(i);
+//      super.addRowSelectionInterval(viewIdx, viewIdx);
+//    }
+//  }
+//  
+
+}



More information about the Schmitzm-commits mailing list