Lines 40-46
Link Here
|
40 |
*/ |
40 |
*/ |
41 |
package org.netbeans.modules.debugger.ui; |
41 |
package org.netbeans.modules.debugger.ui; |
42 |
|
42 |
|
43 |
import java.awt.AWTKeyStroke; |
|
|
44 |
import org.openide.awt.Mnemonics; |
43 |
import org.openide.awt.Mnemonics; |
45 |
import org.openide.util.NbBundle; |
44 |
import org.openide.util.NbBundle; |
46 |
|
45 |
|
Lines 49-70
Link Here
|
49 |
import javax.swing.border.CompoundBorder; |
48 |
import javax.swing.border.CompoundBorder; |
50 |
import java.util.*; |
49 |
import java.util.*; |
51 |
import java.awt.BorderLayout; |
50 |
import java.awt.BorderLayout; |
52 |
import java.awt.Dimension; |
51 |
import javax.swing.text.JTextComponent; |
53 |
import java.awt.GridBagConstraints; |
|
|
54 |
import java.awt.GridBagLayout; |
55 |
import java.awt.KeyboardFocusManager; |
56 |
import java.awt.event.KeyEvent; |
57 |
import java.io.IOException; |
58 |
import javax.swing.text.StyledDocument; |
59 |
import org.netbeans.api.editor.DialogBinding; |
52 |
import org.netbeans.api.editor.DialogBinding; |
60 |
import org.netbeans.editor.EditorUI; |
53 |
import org.netbeans.editor.Utilities; |
61 |
import org.netbeans.spi.debugger.ui.EditorContextDispatcher; |
54 |
import org.netbeans.spi.debugger.ui.EditorContextDispatcher; |
62 |
import org.openide.ErrorManager; |
|
|
63 |
import org.openide.cookies.EditorCookie; |
64 |
import org.openide.filesystems.FileObject; |
55 |
import org.openide.filesystems.FileObject; |
65 |
import org.openide.loaders.DataObject; |
|
|
66 |
import org.openide.loaders.DataObjectNotFoundException; |
67 |
import org.openide.text.NbDocument; |
68 |
|
56 |
|
69 |
/** |
57 |
/** |
70 |
* A GUI panel for customizing a Watch. |
58 |
* A GUI panel for customizing a Watch. |
Lines 74-80
Link Here
|
74 |
public class WatchPanel { |
62 |
public class WatchPanel { |
75 |
|
63 |
|
76 |
private JPanel panel; |
64 |
private JPanel panel; |
77 |
private JEditorPane editorPane; |
65 |
private JTextComponent editorPane; |
78 |
private String expression; |
66 |
private String expression; |
79 |
|
67 |
|
80 |
public WatchPanel(String expression) { |
68 |
public WatchPanel(String expression) { |
Lines 94-116
Link Here
|
94 |
panel.setLayout (new BorderLayout ()); |
82 |
panel.setLayout (new BorderLayout ()); |
95 |
panel.setBorder (new EmptyBorder (11, 12, 1, 11)); |
83 |
panel.setBorder (new EmptyBorder (11, 12, 1, 11)); |
96 |
panel.add (BorderLayout.NORTH, textLabel); |
84 |
panel.add (BorderLayout.NORTH, textLabel); |
|
|
85 |
|
86 |
FileObject file = EditorContextDispatcher.getDefault().getMostRecentFile(); |
87 |
int line = EditorContextDispatcher.getDefault().getMostRecentLineNumber(); |
88 |
|
97 |
//Add JEditorPane and context |
89 |
//Add JEditorPane and context |
98 |
editorPane = new JEditorPane();//expression); // NOI18N |
90 |
JComponent [] editorComponents = Utilities.createSingleLineEditor(file.getMIMEType()); |
|
|
91 |
editorPane = (JTextComponent) editorComponents[1]; |
92 |
DialogBinding.bindComponentToFile(file, line, 0, 0, editorPane); |
99 |
editorPane.setText(expression); |
93 |
editorPane.setText(expression); |
100 |
|
94 |
|
101 |
setupContext(editorPane, |
|
|
102 |
EditorContextDispatcher.getDefault().getMostRecentFile(), |
103 |
EditorContextDispatcher.getDefault().getMostRecentLineNumber()); |
104 |
editorPane.setText (expression); |
95 |
editorPane.setText (expression); |
105 |
editorPane.selectAll (); |
96 |
editorPane.selectAll (); |
106 |
|
97 |
|
107 |
JScrollPane sp = createScrollableLineEditor(editorPane); |
98 |
panel.add (BorderLayout.CENTER, editorComponents[0]); |
108 |
int h = sp.getPreferredSize().height; |
|
|
109 |
int w = Math.min(70*editorPane.getFontMetrics(editorPane.getFont()).charWidth('a'), |
110 |
org.openide.windows.WindowManager.getDefault().getMainWindow().getSize().width); |
111 |
sp.setPreferredSize(new Dimension(w, h)); |
112 |
|
113 |
panel.add (BorderLayout.CENTER, sp); |
114 |
editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N |
99 |
editorPane.getAccessibleContext ().setAccessibleDescription (bundle.getString ("ACSD_CTL_Watch_Name")); // NOI18N |
115 |
editorPane.setBorder ( |
100 |
editorPane.setBorder ( |
116 |
new CompoundBorder (editorPane.getBorder (), |
101 |
new CompoundBorder (editorPane.getBorder (), |
Lines 129-242
Link Here
|
129 |
return panel; |
114 |
return panel; |
130 |
} |
115 |
} |
131 |
|
116 |
|
132 |
private static void setupUI(final JEditorPane editorPane) { |
|
|
133 |
Runnable runnable = new Runnable() { |
134 |
public void run() { |
135 |
EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane); |
136 |
if (eui == null) { |
137 |
return; |
138 |
} |
139 |
editorPane.putClientProperty( |
140 |
"HighlightsLayerExcludes", //NOI18N |
141 |
"^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N |
142 |
); |
143 |
// Do not draw text limit line |
144 |
try { |
145 |
java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N |
146 |
textLimitLineField.setAccessible(true); |
147 |
textLimitLineField.set(eui, false); |
148 |
} catch (Exception ex) {} |
149 |
} |
150 |
}; |
151 |
if (SwingUtilities.isEventDispatchThread()) { |
152 |
runnable.run(); |
153 |
} else { |
154 |
SwingUtilities.invokeLater(runnable); |
155 |
} |
156 |
} |
157 |
|
158 |
private static void setupContext(JEditorPane editorPane, FileObject file, int line) { |
159 |
if (line < 1) { |
160 |
line = 1; |
161 |
} |
162 |
StyledDocument doc; |
163 |
if (file == null) { |
164 |
return; |
165 |
} |
166 |
try { |
167 |
DataObject dobj = DataObject.find (file); |
168 |
EditorCookie ec = dobj.getCookie(EditorCookie.class); |
169 |
if (ec == null) { |
170 |
return; |
171 |
} |
172 |
try { |
173 |
doc = ec.openDocument(); |
174 |
} catch (IOException ex) { |
175 |
ErrorManager.getDefault().notify(ex); |
176 |
return; |
177 |
} |
178 |
} catch (DataObjectNotFoundException ex) { |
179 |
// null dobj |
180 |
return; |
181 |
} |
182 |
try { |
183 |
int offset = NbDocument.findLineOffset(doc, line - 1); // findLineOffset() expects zero based line numbers |
184 |
//editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj); |
185 |
//System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")"); |
186 |
DialogBinding.bindComponentToDocument(doc, offset, 0, editorPane); |
187 |
} catch (IndexOutOfBoundsException ioobex) { |
188 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioobex); |
189 |
} |
190 |
setupUI(editorPane); |
191 |
} |
192 |
|
193 |
private static JScrollPane createScrollableLineEditor(JEditorPane editorPane) { |
194 |
// Remove control keys: |
195 |
KeyStroke enterKs = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); |
196 |
KeyStroke escKs = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); |
197 |
KeyStroke tabKs = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); |
198 |
InputMap im = editorPane.getInputMap(); |
199 |
im.put(enterKs, "none"); |
200 |
im.put(escKs, "none"); |
201 |
im.put(tabKs, "none"); |
202 |
|
203 |
final JScrollPane sp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER, |
204 |
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
205 |
|
206 |
editorPane.setBorder ( |
207 |
new CompoundBorder (editorPane.getBorder(), |
208 |
new EmptyBorder (0, 0, 0, 0)) |
209 |
); |
210 |
|
211 |
JTextField referenceTextField = new JTextField("M"); |
212 |
JPanel panel = new JPanel(new GridBagLayout()); |
213 |
panel.setBackground(referenceTextField.getBackground()); |
214 |
sp.setBorder(referenceTextField.getBorder()); |
215 |
sp.setBackground(referenceTextField.getBackground()); |
216 |
|
217 |
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); |
218 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
219 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; |
220 |
gridBagConstraints.weightx = 1.0; |
221 |
panel.add(editorPane, gridBagConstraints); |
222 |
sp.setViewportView(panel); |
223 |
|
224 |
int preferredHeight = referenceTextField.getPreferredSize().height; |
225 |
if (sp.getPreferredSize().height < preferredHeight) { |
226 |
sp.setPreferredSize(referenceTextField.getPreferredSize()); |
227 |
} |
228 |
sp.setMinimumSize(sp.getPreferredSize()); |
229 |
|
230 |
setupUI(editorPane); |
231 |
|
232 |
Set<AWTKeyStroke> tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); |
233 |
editorPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, tfkeys); |
234 |
tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); |
235 |
editorPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, tfkeys); |
236 |
return sp; |
237 |
} |
238 |
|
239 |
|
240 |
public String getExpression() { |
117 |
public String getExpression() { |
241 |
return editorPane.getText().trim(); |
118 |
return editorPane.getText().trim(); |
242 |
} |
119 |
} |