Author: pwang
Date: 2010-01-15 15:56:15 -0800 (Fri, 15 Jan 2010)
New Revision: 18944
Modified:
cytoscape/trunk/src/cytoscape/util/swing/ColumnResizer.java
Log:
Add a new method
Modified: cytoscape/trunk/src/cytoscape/util/swing/ColumnResizer.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/swing/ColumnResizer.java 2010-01-15
23:55:18 UTC (rev 18943)
+++ cytoscape/trunk/src/cytoscape/util/swing/ColumnResizer.java 2010-01-15
23:56:15 UTC (rev 18944)
@@ -40,6 +40,7 @@
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
+import java.util.HashMap;
/**
@@ -106,4 +107,58 @@
column.setPreferredWidth(maxwidth + 20);
} // for col
}
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param table DOCUMENT ME!
+ */
+ public static HashMap<String, Integer> getColumnPreferredWidths(JTable
table) {
+
+ HashMap<String, Integer> retMap = new HashMap<String,
Integer>();
+
+ // 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++) {
+ 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);
+ 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);
+ maxwidth = Math.max(maxwidth,
headerComp.getPreferredSize().width);
+
+ /*
+ * If the value is too big, adjust to fixed maximum val.
+ */
+ if (DEFLMAX_WIDTH < maxwidth) {
+ maxwidth = DEFLMAX_WIDTH;
+ }
+
+ retMap.put(headerValue.toString(), new Integer(maxwidth
+ 20));
+ } // for col
+
+ return retMap;
+ }
+
+
}
--
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.