< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableUI.java

Print this page




 733                 int leadCol = getAdjustedLead(table, false);
 734                 return !(table.isEditing() || table.isCellSelected(leadRow, leadCol));
 735             } else if (key == FOCUS_HEADER && sender instanceof JTable) {
 736                 JTable table = (JTable)sender;
 737                 return table.getTableHeader() != null;
 738             }
 739 
 740             return true;
 741         }
 742     }
 743 
 744 
 745 //
 746 //  The Table's Key listener
 747 //
 748 
 749     /**
 750      * This class should be treated as a &quot;protected&quot; inner class.
 751      * Instantiate it only within subclasses of {@code BasicTableUI}.
 752      * <p>As of Java 2 platform v1.3 this class is no longer used.
 753      * Instead <code>JTable</code>
 754      * overrides <code>processKeyBinding</code> to dispatch the event to
 755      * the current <code>TableCellEditor</code>.
 756      */
 757      public class KeyHandler implements KeyListener {
 758         // NOTE: This class exists only for backward compatibility. All
 759         // its functionality has been moved into Handler. If you need to add
 760         // new functionality add it to the Handler, but make sure this
 761         // class calls into the Handler.
 762         public void keyPressed(KeyEvent e) {
 763             getHandler().keyPressed(e);
 764         }
 765 
 766         public void keyReleased(KeyEvent e) {
 767             getHandler().keyReleased(e);
 768         }
 769 
 770         public void keyTyped(KeyEvent e) {
 771             getHandler().keyTyped(e);
 772         }
 773     }
 774 
 775 //


1773 
1774     /**
1775      * Return the maximum size of the table. The maximum height is the
1776      * row heighttimes the number of rows.
1777      * The maximum width is the sum of the maximum widths of each column.
1778      */
1779     public Dimension getMaximumSize(JComponent c) {
1780         long width = 0;
1781         Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
1782         while (enumeration.hasMoreElements()) {
1783             TableColumn aColumn = enumeration.nextElement();
1784             width = width + aColumn.getMaxWidth();
1785         }
1786         return createTableSize(width);
1787     }
1788 
1789 //
1790 //  Paint methods and support
1791 //
1792 
1793     /** Paint a representation of the <code>table</code> instance
1794      * that was set in installUI().
1795      */
1796     public void paint(Graphics g, JComponent c) {
1797         Rectangle clip = g.getClipBounds();
1798 
1799         Rectangle bounds = table.getBounds();
1800         // account for the fact that the graphics has already been translated
1801         // into the table's bounds
1802         bounds.x = bounds.y = 0;
1803 
1804         if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
1805                 // this check prevents us from painting the entire table
1806                 // when the clip doesn't intersect our bounds at all
1807                 !bounds.intersects(clip)) {
1808 
1809             paintDropLines(g);
1810             return;
1811         }
1812 
1813         boolean ltr = table.getComponentOrientation().isLeftToRight();


1965         if (horizontal) {
1966             rect.x = 0;
1967             rect.width = table.getWidth();
1968         } else {
1969             rect.y = 0;
1970 
1971             if (table.getRowCount() != 0) {
1972                 Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
1973                 rect.height = lastRect.y + lastRect.height;
1974             } else {
1975                 rect.height = table.getHeight();
1976             }
1977         }
1978 
1979         return rect;
1980     }
1981 
1982     /*
1983      * Paints the grid lines within <I>aRect</I>, using the grid
1984      * color set with <I>setGridColor</I>. Paints vertical lines
1985      * if <code>getShowVerticalLines()</code> returns true and paints
1986      * horizontal lines if <code>getShowHorizontalLines()</code>
1987      * returns true.
1988      */
1989     private void paintGrid(Graphics g, int rMin, int rMax, int cMin, int cMax) {
1990         g.setColor(table.getGridColor());
1991 
1992         Rectangle minCell = table.getCellRect(rMin, cMin, true);
1993         Rectangle maxCell = table.getCellRect(rMax, cMax, true);
1994         Rectangle damagedArea = minCell.union( maxCell );
1995 
1996         if (table.getShowHorizontalLines()) {
1997             int tableWidth = damagedArea.x + damagedArea.width;
1998             int y = damagedArea.y;
1999             for (int row = rMin; row <= rMax; row++) {
2000                 y += table.getRowHeight(row);
2001                 g.drawLine(damagedArea.x, y - 1, tableWidth - 1, y - 1);
2002             }
2003         }
2004         if (table.getShowVerticalLines()) {
2005             TableColumnModel cm = table.getColumnModel();
2006             int tableHeight = damagedArea.y + damagedArea.height;




 733                 int leadCol = getAdjustedLead(table, false);
 734                 return !(table.isEditing() || table.isCellSelected(leadRow, leadCol));
 735             } else if (key == FOCUS_HEADER && sender instanceof JTable) {
 736                 JTable table = (JTable)sender;
 737                 return table.getTableHeader() != null;
 738             }
 739 
 740             return true;
 741         }
 742     }
 743 
 744 
 745 //
 746 //  The Table's Key listener
 747 //
 748 
 749     /**
 750      * This class should be treated as a &quot;protected&quot; inner class.
 751      * Instantiate it only within subclasses of {@code BasicTableUI}.
 752      * <p>As of Java 2 platform v1.3 this class is no longer used.
 753      * Instead {@code JTable}
 754      * overrides {@code processKeyBinding} to dispatch the event to
 755      * the current {@code TableCellEditor}.
 756      */
 757      public class KeyHandler implements KeyListener {
 758         // NOTE: This class exists only for backward compatibility. All
 759         // its functionality has been moved into Handler. If you need to add
 760         // new functionality add it to the Handler, but make sure this
 761         // class calls into the Handler.
 762         public void keyPressed(KeyEvent e) {
 763             getHandler().keyPressed(e);
 764         }
 765 
 766         public void keyReleased(KeyEvent e) {
 767             getHandler().keyReleased(e);
 768         }
 769 
 770         public void keyTyped(KeyEvent e) {
 771             getHandler().keyTyped(e);
 772         }
 773     }
 774 
 775 //


1773 
1774     /**
1775      * Return the maximum size of the table. The maximum height is the
1776      * row heighttimes the number of rows.
1777      * The maximum width is the sum of the maximum widths of each column.
1778      */
1779     public Dimension getMaximumSize(JComponent c) {
1780         long width = 0;
1781         Enumeration<TableColumn> enumeration = table.getColumnModel().getColumns();
1782         while (enumeration.hasMoreElements()) {
1783             TableColumn aColumn = enumeration.nextElement();
1784             width = width + aColumn.getMaxWidth();
1785         }
1786         return createTableSize(width);
1787     }
1788 
1789 //
1790 //  Paint methods and support
1791 //
1792 
1793     /** Paint a representation of the {@code table} instance
1794      * that was set in installUI().
1795      */
1796     public void paint(Graphics g, JComponent c) {
1797         Rectangle clip = g.getClipBounds();
1798 
1799         Rectangle bounds = table.getBounds();
1800         // account for the fact that the graphics has already been translated
1801         // into the table's bounds
1802         bounds.x = bounds.y = 0;
1803 
1804         if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 ||
1805                 // this check prevents us from painting the entire table
1806                 // when the clip doesn't intersect our bounds at all
1807                 !bounds.intersects(clip)) {
1808 
1809             paintDropLines(g);
1810             return;
1811         }
1812 
1813         boolean ltr = table.getComponentOrientation().isLeftToRight();


1965         if (horizontal) {
1966             rect.x = 0;
1967             rect.width = table.getWidth();
1968         } else {
1969             rect.y = 0;
1970 
1971             if (table.getRowCount() != 0) {
1972                 Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true);
1973                 rect.height = lastRect.y + lastRect.height;
1974             } else {
1975                 rect.height = table.getHeight();
1976             }
1977         }
1978 
1979         return rect;
1980     }
1981 
1982     /*
1983      * Paints the grid lines within <I>aRect</I>, using the grid
1984      * color set with <I>setGridColor</I>. Paints vertical lines
1985      * if {@code getShowVerticalLines()} returns true and paints
1986      * horizontal lines if {@code getShowHorizontalLines()}
1987      * returns true.
1988      */
1989     private void paintGrid(Graphics g, int rMin, int rMax, int cMin, int cMax) {
1990         g.setColor(table.getGridColor());
1991 
1992         Rectangle minCell = table.getCellRect(rMin, cMin, true);
1993         Rectangle maxCell = table.getCellRect(rMax, cMax, true);
1994         Rectangle damagedArea = minCell.union( maxCell );
1995 
1996         if (table.getShowHorizontalLines()) {
1997             int tableWidth = damagedArea.x + damagedArea.width;
1998             int y = damagedArea.y;
1999             for (int row = rMin; row <= rMax; row++) {
2000                 y += table.getRowHeight(row);
2001                 g.drawLine(damagedArea.x, y - 1, tableWidth - 1, y - 1);
2002             }
2003         }
2004         if (table.getShowVerticalLines()) {
2005             TableColumnModel cm = table.getColumnModel();
2006             int tableHeight = damagedArea.y + damagedArea.height;


< prev index next >