Author: kono
Date: 2011-11-17 14:47:13 -0800 (Thu, 17 Nov 2011)
New Revision: 27519
Modified:
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
Log:
Performance issue had been fixed for the column resizer.
Modified:
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
===================================================================
---
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
2011-11-17 21:43:40 UTC (rev 27518)
+++
core3/impl/trunk/table-browser-impl/src/main/java/org/cytoscape/browser/internal/util/ColumnResizer.java
2011-11-17 22:47:13 UTC (rev 27519)
@@ -22,47 +22,42 @@
*
*/
public class ColumnResizer {
- private static final int DEFLMAX_WIDTH = 280;
+
+ private static final int DEFLMAX_WIDTH = 300;
+
+ /**
+ * Simplified version of column width adjuster.
+ * Looks into only column titles, not actual values.
+ * This is for performance.
+ *
+ * @param table target JTable.
+ */
public static void adjustColumnPreferredWidths(JTable table) {
// strategy - get max width for cells in column and
// make that the preferred width
- TableColumnModel columnModel = table.getColumnModel();
-
- for (int col = 0; col < table.getColumnCount(); col++) {
+ final TableColumnModel columnModel = table.getColumnModel();
+ final int colCount = table.getColumnCount();
+
+ for (int col = 0; col < colCount; col++) {
int maxwidth = 0;
-
- for (int row = 0; row < table.getRowCount(); row++) {
- TableCellRenderer rend =
table.getCellRenderer(row, col);
- Object value = table.getValueAt(row, col);
- Component comp =
rend.getTableCellRendererComponent(table, value, false, false, row, col);
- maxwidth =
Math.max(comp.getPreferredSize().width, maxwidth);
- } // for row
-
- /*
- * this version of the width set considers the column
header's
- * preferred width too
- */
- TableColumn column = columnModel.getColumn(col);
+
+ final TableColumn column = columnModel.getColumn(col);
TableCellRenderer headerRenderer =
column.getHeaderRenderer();
if (headerRenderer == null)
headerRenderer =
table.getTableHeader().getDefaultRenderer();
- Object headerValue = column.getHeaderValue();
- Component headerComp =
headerRenderer.getTableCellRendererComponent(table, headerValue, false, false,
0,
- col);
+ final Object headerValue = column.getHeaderValue();
+ final Component headerComp =
headerRenderer.getTableCellRendererComponent(table, headerValue, false, false,
0, col);
maxwidth = Math.max(maxwidth,
headerComp.getPreferredSize().width);
- /*
- * If the value is too big, adjust to fixed maximum val.
- */
- if (DEFLMAX_WIDTH < maxwidth) {
+ // If the value is too big, adjust to fixed maximum val.
+ if (DEFLMAX_WIDTH < maxwidth)
maxwidth = DEFLMAX_WIDTH;
- }
column.setPreferredWidth(maxwidth + 20);
- } // for col
+ }
}
public static HashMap<String, Integer> getColumnPreferredWidths(JTable
table) {
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.