1 7 8 package org.gjt.jclasslib.browser.detail; 9 10 import org.gjt.jclasslib.browser.AbstractDetailPane; 11 import org.gjt.jclasslib.browser.BrowserServices; 12 import org.gjt.jclasslib.browser.detail.attributes.LinkRenderer; 13 14 import javax.swing.*; 15 import javax.swing.table.TableModel ; 16 import javax.swing.tree.TreePath ; 17 import java.awt.*; 18 import java.awt.event.*; 19 20 27 public abstract class ListDetailPane extends AbstractDetailPane { 28 29 31 private JTable table; 32 33 37 protected ListDetailPane(BrowserServices services) { 38 super(services); 39 } 40 41 protected void setupComponent() { 42 43 setLayout(new BorderLayout()); 44 45 table = new JTable(); 46 table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 47 table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 48 float rowHeightFactor = getRowHeightFactor(); 49 if (rowHeightFactor != 1f) { 50 table.setRowHeight((int)(table.getRowHeight() * rowHeightFactor)); 51 } 52 53 TableLinkListener linkListener = new TableLinkListener(); 54 table.addMouseListener(linkListener); 55 table.addMouseMotionListener(linkListener); 56 57 58 JScrollPane scrollPane = new JScrollPane(table); 59 60 add(scrollPane, BorderLayout.CENTER); 61 } 62 63 public void show(TreePath treePath) { 64 TableModel tableModel = getTableModel(treePath); 65 table.setModel(tableModel); 66 67 createTableColumnModel(table, tableModel); 68 ((JLabel)table.getDefaultRenderer(Number .class)).setVerticalAlignment(JLabel.TOP); 69 ((JLabel)table.getDefaultRenderer(String .class)).setVerticalAlignment(JLabel.TOP); 70 table.setDefaultRenderer(Link.class, new LinkRenderer()); 71 72 } 73 74 79 protected float getRowHeightFactor() { 80 return 1f; 81 } 82 83 88 protected void createTableColumnModel(JTable table, TableModel tableModel) { 89 table.createDefaultColumnsFromModel(); 90 } 91 92 97 protected abstract TableModel getTableModel(TreePath treePath); 98 99 104 protected Object createCommentLink(int index) { 105 return new LinkRenderer.LinkCommentValue( 106 CPINFO_LINK_TEXT + String.valueOf(index), 107 getConstantPoolEntryName(index) 108 ); 109 } 110 111 117 protected void link(int row, int column) { 118 } 119 120 123 public static class ColumnCache { 124 125 private Object [][] cache; 126 127 132 public ColumnCache(int rowNumber, int columnNumber) { 133 cache = new Object [rowNumber][columnNumber]; 134 } 135 136 142 public Object getValueAt(int row, int column) { 143 return cache[row][column]; 144 } 145 146 152 public void setValueAt(int row, int column, Object value) { 153 cache[row][column] = value; 154 } 155 156 } 157 158 162 public static class Link { 163 } 164 165 private class TableLinkListener extends MouseAdapter 166 implements MouseMotionListener 167 { 168 169 private Cursor defaultCursor; 170 private int defaultCursorType; 171 private Cursor handCursor; 172 173 private TableLinkListener() { 174 175 defaultCursor = Cursor.getDefaultCursor(); 176 defaultCursorType = defaultCursor.getType(); 177 handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 178 } 179 180 public void mouseClicked(MouseEvent event) { 181 182 Point point = event.getPoint(); 183 184 if (isLink(point)) { 185 link(table.rowAtPoint(point), table.columnAtPoint(point)); 186 } 187 } 188 189 public void mouseDragged(MouseEvent event) { 190 } 191 192 public void mouseMoved(MouseEvent event) { 193 194 Point point = event.getPoint(); 195 196 if (table.getCursor().getType() == defaultCursorType && isLink(point)) { 197 table.setCursor(handCursor); 198 } else if (!isLink(point)) { 199 table.setCursor(defaultCursor); 200 } 201 } 202 203 private boolean isLink(Point point) { 204 205 int column = table.columnAtPoint(point); 206 int row = table.rowAtPoint(point); 207 208 return row >= 0 && column >= 0 && 209 table.getColumnClass(column).equals(Link.class) && 210 !table.getModel().getValueAt(row, column).toString().equals(CPINFO_LINK_TEXT + "0"); 211 } 212 213 214 } 215 216 } 217 218 | Popular Tags |