1 19 package org.netbeans.modules.debugger.jpda.ui; 20 21 import java.awt.Container ; 22 import java.awt.Dialog ; 23 import java.awt.Dimension ; 24 import java.awt.FontMetrics ; 25 import java.awt.event.ComponentEvent ; 26 import java.awt.event.ComponentListener ; 27 import java.awt.event.KeyEvent ; 28 import java.awt.event.KeyListener ; 29 import java.net.MalformedURLException ; 30 import java.net.URL ; 31 import javax.swing.text.Document ; 32 import javax.swing.text.EditorKit ; 33 import javax.swing.text.Keymap ; 34 import org.netbeans.api.debugger.DebuggerEngine; 35 import org.netbeans.api.debugger.DebuggerManager; 36 import org.netbeans.api.debugger.jpda.CallStackFrame; 37 import org.netbeans.api.debugger.jpda.JPDADebugger; 38 import org.openide.awt.Mnemonics; 39 import org.openide.filesystems.FileObject; 40 import org.openide.filesystems.URLMapper; 41 import org.openide.loaders.DataObject; 42 import org.openide.loaders.DataObjectNotFoundException; 43 import org.openide.util.NbBundle; 44 45 import javax.swing.*; 46 import javax.swing.border.EmptyBorder ; 47 import javax.swing.border.CompoundBorder ; 48 import java.util.*; 49 import java.awt.BorderLayout ; 50 51 56 public class WatchPanel { 57 58 private JPanel panel; 59 private JEditorPane editorPane; 60 private String expression; 61 62 public WatchPanel(String expression) { 63 this.expression = expression; 64 } 65 66 public static void setupContext(JEditorPane editorPane) { 67 DebuggerEngine en = DebuggerManager.getDebuggerManager ().getCurrentEngine(); 68 JPDADebugger d = (JPDADebugger) en.lookupFirst(null, JPDADebugger.class); 69 CallStackFrame csf = d.getCurrentCallStackFrame(); 70 if (csf != null) { 71 DataObject dobj = null; 72 SourcePath sp = (SourcePath) en.lookupFirst(null, SourcePath.class); 73 String url = sp.getURL(csf, "Java"); 74 FileObject file; 75 try { 76 file = URLMapper.findFileObject (new URL (url)); 77 if (file != null) { 78 try { 79 dobj = DataObject.find (file); 80 } catch (DataObjectNotFoundException ex) { 81 } 83 } 84 } catch (MalformedURLException e) { 85 } 87 editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj); 88 } 89 } 90 91 public JComponent getPanel() { 92 if (panel != null) return panel; 93 94 panel = new JPanel(); 95 ResourceBundle bundle = NbBundle.getBundle(WatchPanel.class); 96 97 panel.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_WatchPanel")); JLabel textLabel = new JLabel(); 99 Mnemonics.setLocalizedText(textLabel, bundle.getString ("CTL_Watch_Name")); editorPane = new JEditorPane("text/x-java", expression); editorPane.setKeymap(new FilteredKeymap(editorPane.getKeymap())); 102 103 setupContext(editorPane); 104 105 JScrollPane sp = new JScrollPane(editorPane, JScrollPane.VERTICAL_SCROLLBAR_NEVER, 106 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 107 108 textLabel.setBorder (new EmptyBorder (0, 0, 5, 0)); 109 panel.setLayout (new BorderLayout ()); 110 panel.setBorder (new EmptyBorder (11, 12, 1, 11)); 111 panel.add (BorderLayout.NORTH, textLabel); 112 panel.add (BorderLayout.CENTER, sp); 113 114 FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont()); 115 int size = 2*fm.getLeading() + fm.getMaxAscent() + fm.getMaxDescent() + 4; 116 117 editorPane.setPreferredSize(new Dimension (30*size, (int) (1*size))); 118 119 editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); editorPane.setBorder ( 121 new CompoundBorder (editorPane.getBorder (), 122 new EmptyBorder (2, 0, 2, 0)) 123 ); 124 editorPane.setText (expression); 125 editorPane.selectAll (); 126 127 textLabel.setLabelFor (editorPane); 128 editorPane.requestFocus (); 129 130 return panel; 131 } 132 133 public String getExpression() { 134 return editorPane.getText().trim(); 135 } 136 } 137 | Popular Tags |