1 7 8 package org.gjt.jclasslib.browser.detail.attributes.code; 9 10 import org.gjt.jclasslib.browser.*; 11 import org.gjt.jclasslib.structures.attributes.CodeAttribute; 12 13 import javax.swing.*; 14 import javax.swing.tree.TreePath ; 15 import java.awt.*; 16 import java.awt.event.*; 17 18 24 public class ByteCodeDetailPane extends AbstractDetailPane { 25 26 private static final Rectangle RECT_ORIGIN = new Rectangle(0, 0, 0, 0); 27 28 30 private ByteCodeDisplay byteCodeDisplay; 31 private CounterDisplay counterDisplay; 32 private JScrollPane scrollPane; 33 private JButton btnCopy; 34 35 39 public ByteCodeDetailPane(BrowserServices services) { 40 super(services); 41 } 42 43 protected void setupComponent() { 44 45 setLayout(new BorderLayout()); 46 btnCopy = new JButton("Copy to clipboard"); 47 btnCopy.addActionListener(new ActionListener() { 48 public void actionPerformed(ActionEvent event) { 49 byteCodeDisplay.copyToClipboard(); 50 } 51 }); 52 Box box = Box.createHorizontalBox(); 53 box.add(Box.createHorizontalGlue()); 54 box.add(btnCopy); 55 56 add(box, BorderLayout.SOUTH); 57 add(buildByteCodeScrollPane(), BorderLayout.CENTER); 58 59 DocumentLinkListener listener = new DocumentLinkListener(byteCodeDisplay); 60 byteCodeDisplay.addMouseListener(listener); 61 byteCodeDisplay.addMouseMotionListener(listener); 62 } 63 64 public void show(TreePath treePath) { 65 66 CodeAttribute attribute = (CodeAttribute)findAttribute(treePath); 67 if (byteCodeDisplay.getCodeAttribute() != attribute) { 68 69 BrowserComponent browserComponent = services.getBrowserComponent(); 70 browserComponent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 71 byteCodeDisplay.setCodeAttribute(attribute, services.getClassFile()); 72 counterDisplay.init(byteCodeDisplay); 73 74 byteCodeDisplay.scrollRectToVisible(RECT_ORIGIN); 75 76 scrollPane.validate(); 77 scrollPane.repaint(); 78 browserComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 79 } 80 } 81 82 86 public void scrollToOffset(int offset) { 87 88 byteCodeDisplay.scrollToOffset(offset); 89 } 90 91 private JScrollPane buildByteCodeScrollPane() { 92 93 byteCodeDisplay = new ByteCodeDisplay(this); 94 scrollPane = new JScrollPane(byteCodeDisplay); 95 scrollPane.getViewport().setBackground(Color.WHITE); 96 counterDisplay = new CounterDisplay(); 97 scrollPane.setRowHeaderView(counterDisplay); 98 99 MouseAdapter mouseListener = new MouseAdapter() { 100 public void mousePressed(MouseEvent event) { 101 scrollPane.requestFocus(); 102 } 103 }; 104 byteCodeDisplay.addMouseListener(mouseListener); 105 scrollPane.getHorizontalScrollBar().addMouseListener(mouseListener); 106 scrollPane.getVerticalScrollBar().addMouseListener(mouseListener); 107 scrollPane.addMouseWheelListener(new MouseWheelListener() { 108 public void mouseWheelMoved(MouseWheelEvent event) { 109 scrollPane.requestFocus(); 110 } 111 }); 112 113 return scrollPane; 114 } 115 116 private class DocumentLinkListener extends MouseAdapter 117 implements MouseMotionListener 118 { 119 120 private ByteCodeDisplay byteCodeDisplay; 121 122 private Cursor defaultCursor; 123 private int defaultCursorType; 124 private Cursor handCursor; 125 126 private DocumentLinkListener(ByteCodeDisplay byteCodeDisplay) { 127 this.byteCodeDisplay = byteCodeDisplay; 128 129 defaultCursor = Cursor.getDefaultCursor(); 130 defaultCursorType = defaultCursor.getType(); 131 handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 132 } 133 134 public void mouseClicked(MouseEvent event) { 135 136 byteCodeDisplay.link(event.getPoint()); 137 } 138 139 public void mouseDragged(MouseEvent event) { 140 } 141 142 public void mouseMoved(MouseEvent event) { 143 144 boolean link = byteCodeDisplay.isLink(event.getPoint()); 145 if (byteCodeDisplay.getCursor().getType() == defaultCursorType && link) { 146 byteCodeDisplay.setCursor(handCursor); 147 } else if (!link) { 148 byteCodeDisplay.setCursor(defaultCursor); 149 } 150 } 151 152 } 153 154 155 } 156 157 | Popular Tags |