diff options
Diffstat (limited to 'src/share/classes/sun/swing/SwingUtilities2.java')
-rw-r--r-- | src/share/classes/sun/swing/SwingUtilities2.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/share/classes/sun/swing/SwingUtilities2.java b/src/share/classes/sun/swing/SwingUtilities2.java index 443fb90d1..6358d9870 100644 --- a/src/share/classes/sun/swing/SwingUtilities2.java +++ b/src/share/classes/sun/swing/SwingUtilities2.java @@ -44,6 +44,8 @@ import javax.swing.text.JTextComponent; import javax.swing.text.DefaultHighlighter; import javax.swing.text.DefaultCaret; import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; + import sun.swing.PrintColorUIResource; import sun.swing.ImageIconUIResource; import sun.print.ProxyPrintGraphics; @@ -1807,4 +1809,54 @@ public class SwingUtilities2 { boolean three) { return liesIn(rect, p, false, false, three); } + + /** + * Maps the index of the column in the view at + * {@code viewColumnIndex} to the index of the column + * in the table model. Returns the index of the corresponding + * column in the model. If {@code viewColumnIndex} + * is less than zero, returns {@code viewColumnIndex}. + * + * @param cm the table model + * @param viewColumnIndex the index of the column in the view + * @return the index of the corresponding column in the model + * + * @see JTable#convertColumnIndexToModel(int) + * @see javax.swing.plaf.basic.BasicTableHeaderUI + */ + public static int convertColumnIndexToModel(TableColumnModel cm, + int viewColumnIndex) { + if (viewColumnIndex < 0) { + return viewColumnIndex; + } + return cm.getColumn(viewColumnIndex).getModelIndex(); + } + + /** + * Maps the index of the column in the {@code cm} at + * {@code modelColumnIndex} to the index of the column + * in the view. Returns the index of the + * corresponding column in the view; returns {@code -1} if this column + * is not being displayed. If {@code modelColumnIndex} is less than zero, + * returns {@code modelColumnIndex}. + * + * @param cm the table model + * @param modelColumnIndex the index of the column in the model + * @return the index of the corresponding column in the view + * + * @see JTable#convertColumnIndexToView(int) + * @see javax.swing.plaf.basic.BasicTableHeaderUI + */ + public static int convertColumnIndexToView(TableColumnModel cm, + int modelColumnIndex) { + if (modelColumnIndex < 0) { + return modelColumnIndex; + } + for (int column = 0; column < cm.getColumnCount(); column++) { + if (cm.getColumn(column).getModelIndex() == modelColumnIndex) { + return column; + } + } + return -1; + } } |