1 7 8 package org.gjt.jclasslib.browser.detail.attributes; 9 10 import org.gjt.jclasslib.browser.BrowserServices; 11 import org.gjt.jclasslib.browser.detail.ListDetailPane; 12 import org.gjt.jclasslib.structures.AttributeInfo; 13 14 import javax.swing.*; 15 import javax.swing.table.*; 16 import javax.swing.tree.TreePath ; 17 import java.util.WeakHashMap ; 18 19 28 public abstract class AbstractAttributeListDetailPane extends ListDetailPane { 29 30 31 protected static final int NUMBER_COLUMN_WIDTH = 60; 32 33 protected static final int LINK_COLUMN_WIDTH = 80; 34 35 protected static final int VERBOSE_COLUMN_WIDTH = 250; 36 37 private static final int COLUMN_MIN_WIDTH = 20; 38 private static final int ROW_NUMBER_COLUMN_WIDTH = 35; 39 40 private static WeakHashMap attributeToTableModel = new WeakHashMap (); 41 42 private AbstractAttributeTableModel tableModel; 43 44 48 protected AbstractAttributeListDetailPane(BrowserServices services) { 49 super(services); 50 } 51 52 protected TableModel getTableModel(TreePath treePath) { 53 AttributeInfo attribute = findAttribute(treePath); 54 55 tableModel = getCachedTableModel(attribute); 56 return tableModel; 57 } 58 59 protected void link(int row, int column) { 60 tableModel.link(row, column); 61 } 62 63 69 protected abstract AbstractAttributeTableModel createTableModel(AttributeInfo attribute); 70 71 76 protected int getColumnWidth(int column) { 77 return tableModel.getColumnWidth(column); 78 } 79 80 protected void createTableColumnModel(JTable table, TableModel tableModel) { 81 AbstractAttributeTableModel attributeTableModel = 82 (AbstractAttributeTableModel)tableModel; 83 84 TableColumnModel tableColumnModel = attributeTableModel.getTableColumnModel(); 85 if (tableColumnModel == null) { 86 table.createDefaultColumnsFromModel(); 87 tableColumnModel = table.getColumnModel(); 88 attributeTableModel.setTableColumnModel(tableColumnModel); 89 90 } else { 91 table.setColumnModel(tableColumnModel); 92 } 93 adjustColumns(table, tableColumnModel); 94 } 95 96 97 private void adjustColumns(JTable table, TableColumnModel tableColumnModel) { 98 99 TableColumn tableColumn; 100 for (int i = 0; i < tableColumnModel.getColumnCount(); i++) { 101 tableColumn = tableColumnModel.getColumn(i); 102 tableColumn.setMinWidth(COLUMN_MIN_WIDTH); 103 104 int width = (i == 0) ? ROW_NUMBER_COLUMN_WIDTH : getColumnWidth(i); 105 106 tableColumn.setWidth(width); 107 tableColumn.setPreferredWidth(width); 108 109 } 110 111 } 112 113 private AbstractAttributeTableModel getCachedTableModel(AttributeInfo attribute) { 114 115 AbstractAttributeTableModel tableModel = 116 (AbstractAttributeTableModel)attributeToTableModel.get(attribute); 117 118 if (tableModel == null) { 119 tableModel = createTableModel(attribute); 120 121 attributeToTableModel.put(attribute, tableModel); 122 123 } 124 125 return tableModel; 126 } 127 128 } 129 130 | Popular Tags |