This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git commit f419ff5ec8ffd9465784ed884e74556284d7fe23 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Dec 4 09:59:39 2014 +0100 refs-80 #3590: Introduces JTables --- .../application/swing/util/ApplicationUIUtil.java | 80 ++++++------------ .../src/main/java/jaxx/runtime/swing/JTables.java | 95 ++++++++++++++++++++++ 2 files changed, 118 insertions(+), 57 deletions(-) diff --git a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java index 50ff596..2d5c749 100644 --- a/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java +++ b/jaxx-application-swing/src/main/java/org/nuiton/jaxx/application/swing/util/ApplicationUIUtil.java @@ -23,6 +23,7 @@ package org.nuiton.jaxx.application.swing.util; */ import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.JTables; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; @@ -164,79 +165,44 @@ public class ApplicationUIUtil { } } + /** + * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnFirstRowAndStopEditing(JTable)} + */ + @Deprecated public static void selectFirstCellOnFirstRowAndStopEditing(JXTable table) { - // select first cell - doSelectCell(table, 0, 0); + JTables.selectFirstCellOnFirstRowAndStopEditing(table); - if (table.isEditing()) { - - // but no edit it - table.getCellEditor().stopCellEditing(); - } } + /** + * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnLastRow(JTable)} + */ + @Deprecated public static void selectFirstCellOnLastRow(JXTable table) { - // select first cell - doSelectCell(table, table.getRowCount() - 1, 0); + JTables.selectFirstCellOnLastRow(table); + } + /** + * @deprecated since 2.18, use instead {@link JTables#selectFirstCellOnRow(JTable, int, boolean)} + */ + @Deprecated public static void selectFirstCellOnRow(JXTable table, int row, boolean stopEdit) { - // select first cell - doSelectCell(table, row, 0); + JTables.selectFirstCellOnRow(table, row, stopEdit); - if (stopEdit && table.isEditing()) { - - table.getCellEditor().stopCellEditing(); - } } - public static void doSelectCell(JTable table, - int rowIndex, - int columnIndex) { - - int rowCount = table.getRowCount(); - if (rowCount == 0) { + /** + * @deprecated since 2.18, use instead {@link JTables#doSelectCell(JTable, int, int)} + */ + @Deprecated + public static void doSelectCell(JTable table, int rowIndex, int columnIndex) { - // no row, can not selected any cell - if (log.isWarnEnabled()) { - log.warn("No row in table, can not select any cell"); - } - return; - } - int columnCount = table.getColumnCount(); - if (columnCount == 0) { - - // no column, can not selected any cell - if (log.isWarnEnabled()) { - log.warn("No column in table, can not select any cell"); - } - return; - } - if (columnIndex > columnCount) { - if (log.isWarnEnabled()) { - log.warn(String.format("ColumnIndex: %s is more than columnCount %s", columnIndex, columnCount)); - } - columnIndex = columnCount - 1; - } - if (columnIndex < 0) { - columnIndex = 0; - } - if (rowIndex >= rowCount) { - if (log.isWarnEnabled()) { - log.warn(String.format("RowIndex: %s is more than rowCount %s", rowIndex, rowCount)); - } - rowIndex = rowCount - 1; - } - if (rowIndex < 0) { - rowIndex = 0; - } + JTables.doSelectCell(table, rowIndex, columnIndex); - table.setColumnSelectionInterval(columnIndex, columnIndex); - table.setRowSelectionInterval(rowIndex, rowIndex); - table.editCellAt(rowIndex, columnIndex); } } diff --git a/jaxx-runtime/src/main/java/jaxx/runtime/swing/JTables.java b/jaxx-runtime/src/main/java/jaxx/runtime/swing/JTables.java new file mode 100644 index 0000000..7fc4e4d --- /dev/null +++ b/jaxx-runtime/src/main/java/jaxx/runtime/swing/JTables.java @@ -0,0 +1,95 @@ +package jaxx.runtime.swing; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTable; + +/** + * Some usefull methods on {@link JTable}. + * + * Created on 12/4/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.18 + */ +public class JTables { + + /** Logger. */ + private static final Log log = LogFactory.getLog(JTables.class); + + public static void selectFirstCellOnFirstRowAndStopEditing(JTable table) { + + // select first cell + doSelectCell(table, 0, 0); + + if (table.isEditing()) { + + // but no edit it + table.getCellEditor().stopCellEditing(); + } + } + + public static void selectFirstCellOnLastRow(JTable table) { + + // select first cell + doSelectCell(table, table.getRowCount() - 1, 0); + } + + public static void selectFirstCellOnRow(JTable table, int row, boolean stopEdit) { + + // select first cell + doSelectCell(table, row, 0); + + if (stopEdit && table.isEditing()) { + + table.getCellEditor().stopCellEditing(); + } + } + + public static void doSelectCell(JTable table, + int rowIndex, + int columnIndex) { + + int rowCount = table.getRowCount(); + if (rowCount == 0) { + + // no row, can not selected any cell + if (log.isWarnEnabled()) { + log.warn("No row in table, can not select any cell"); + } + return; + } + int columnCount = table.getColumnCount(); + if (columnCount == 0) { + + // no column, can not selected any cell + if (log.isWarnEnabled()) { + log.warn("No column in table, can not select any cell"); + } + return; + } + if (columnIndex > columnCount) { + if (log.isWarnEnabled()) { + log.warn(String.format("ColumnIndex: %s is more than columnCount %s", columnIndex, columnCount)); + } + columnIndex = columnCount - 1; + } + if (columnIndex < 0) { + columnIndex = 0; + } + if (rowIndex >= rowCount) { + if (log.isWarnEnabled()) { + log.warn(String.format("RowIndex: %s is more than rowCount %s", rowIndex, rowCount)); + } + rowIndex = rowCount - 1; + } + if (rowIndex < 0) { + rowIndex = 0; + } + + table.setColumnSelectionInterval(columnIndex, columnIndex); + table.setRowSelectionInterval(rowIndex, rowIndex); + table.editCellAt(rowIndex, columnIndex); + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.