This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 181523
Collapse All | Expand All

(-)a/spi.debugger.ui/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
2
OpenIDE-Module: org.netbeans.spi.debugger.ui/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml
5
OpenIDE-Module-Specification-Version: 2.22
5
OpenIDE-Module-Specification-Version: 2.23
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
6
OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
7
OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class
(-)a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchPanel.java (-102 / +3 lines)
Lines 58-63 Link Here
58
import org.netbeans.api.editor.DialogBinding;
58
import org.netbeans.api.editor.DialogBinding;
59
import org.netbeans.editor.EditorUI;
59
import org.netbeans.editor.EditorUI;
60
import org.netbeans.spi.debugger.ui.EditorContextDispatcher;
60
import org.netbeans.spi.debugger.ui.EditorContextDispatcher;
61
import org.netbeans.spi.debugger.ui.Utilities;
61
import org.openide.ErrorManager;
62
import org.openide.ErrorManager;
62
import org.openide.cookies.EditorCookie;
63
import org.openide.cookies.EditorCookie;
63
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileObject;
Lines 97-109 Link Here
97
        editorPane = new JEditorPane();//expression); // NOI18N
98
        editorPane = new JEditorPane();//expression); // NOI18N
98
        editorPane.setText(expression);
99
        editorPane.setText(expression);
99
100
100
        setupContext(editorPane,
101
        Utilities.setContext(editorPane,
101
                     EditorContextDispatcher.getDefault().getMostRecentFile(),
102
                     EditorContextDispatcher.getDefault().getMostRecentFile(),
102
                     EditorContextDispatcher.getDefault().getMostRecentLineNumber());
103
                     EditorContextDispatcher.getDefault().getMostRecentLineNumber());
103
        editorPane.setText (expression);
104
        editorPane.setText (expression);
104
        editorPane.selectAll ();
105
        editorPane.selectAll ();
105
106
106
        JScrollPane sp = createScrollableLineEditor(editorPane);
107
        JScrollPane sp = Utilities.createScrollableLineEditor(editorPane);
107
        int h = sp.getPreferredSize().height;
108
        int h = sp.getPreferredSize().height;
108
        int w = Math.min(70*editorPane.getFontMetrics(editorPane.getFont()).charWidth('a'),
109
        int w = Math.min(70*editorPane.getFontMetrics(editorPane.getFont()).charWidth('a'),
109
                         org.openide.windows.WindowManager.getDefault().getMainWindow().getSize().width);
110
                         org.openide.windows.WindowManager.getDefault().getMainWindow().getSize().width);
Lines 128-233 Link Here
128
        return panel;
129
        return panel;
129
    }
130
    }
130
131
131
    private static void setupUI(final JEditorPane editorPane) {
132
        Runnable runnable = new Runnable() {
133
            public void run() {
134
                EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane);
135
                if (eui == null) {
136
                    return;
137
                }
138
                editorPane.putClientProperty(
139
                    "HighlightsLayerExcludes", //NOI18N
140
                    "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N
141
                );
142
                // Do not draw text limit line
143
                try {
144
                    java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N
145
                    textLimitLineField.setAccessible(true);
146
                    textLimitLineField.set(eui, false);
147
                } catch (Exception ex) {}
148
            }
149
        };
150
        if (SwingUtilities.isEventDispatchThread()) {
151
            runnable.run();
152
        } else {
153
            SwingUtilities.invokeLater(runnable);
154
        }
155
    }
156
157
    private static void setupContext(JEditorPane editorPane, FileObject file, int line) {
158
        if (line < 1) {
159
            line = 1;
160
        }
161
        StyledDocument doc;
162
        if (file == null) {
163
            return;
164
        }
165
        try {
166
            DataObject dobj = DataObject.find (file);
167
            EditorCookie ec = dobj.getCookie(EditorCookie.class);
168
            if (ec == null) {
169
                return;
170
            }
171
            try {
172
                doc = ec.openDocument();
173
            } catch (IOException ex) {
174
                ErrorManager.getDefault().notify(ex);
175
                return;
176
            }
177
        } catch (DataObjectNotFoundException ex) {
178
            // null dobj
179
            return;
180
        }
181
        try {
182
            int offset = NbDocument.findLineOffset(doc, line - 1); // findLineOffset() expects zero based line numbers
183
            //editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj);
184
            //System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")");
185
            DialogBinding.bindComponentToDocument(doc, offset, 0, editorPane);
186
        } catch (IndexOutOfBoundsException ioobex) {
187
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioobex);
188
        }
189
        setupUI(editorPane);
190
    }
191
192
    private static JScrollPane createScrollableLineEditor(JEditorPane editorPane) {
193
        editorPane.setKeymap(new FilteredKeymap(editorPane));
194
        final JScrollPane sp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER,
195
                                         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
196
197
        editorPane.setBorder (
198
            new CompoundBorder (editorPane.getBorder(),
199
            new EmptyBorder (0, 0, 0, 0))
200
        );
201
202
        JTextField referenceTextField = new JTextField("M");
203
        JPanel panel = new JPanel(new GridBagLayout());
204
        panel.setBackground(referenceTextField.getBackground());
205
        sp.setBorder(referenceTextField.getBorder());
206
        sp.setBackground(referenceTextField.getBackground());
207
208
        GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
209
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
210
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
211
        gridBagConstraints.weightx = 1.0;
212
        panel.add(editorPane, gridBagConstraints);
213
        sp.setViewportView(panel);
214
215
        int preferredHeight = referenceTextField.getPreferredSize().height;
216
        if (sp.getPreferredSize().height < preferredHeight) {
217
            sp.setPreferredSize(referenceTextField.getPreferredSize());
218
        }
219
        sp.setMinimumSize(sp.getPreferredSize());
220
221
        setupUI(editorPane);
222
223
        Set<AWTKeyStroke> tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
224
        editorPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, tfkeys);
225
        tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
226
        editorPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, tfkeys);
227
        return sp;
228
    }
229
230
231
    public String getExpression() {
132
    public String getExpression() {
232
        return editorPane.getText().trim();
133
        return editorPane.getText().trim();
233
    }
134
    }
(-)a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/Utilities.java (+188 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.debugger.ui;
41
42
import java.awt.AWTKeyStroke;
43
import java.awt.GridBagConstraints;
44
import java.awt.GridBagLayout;
45
import java.awt.KeyboardFocusManager;
46
import java.io.IOException;
47
import java.util.Set;
48
import javax.swing.JEditorPane;
49
import javax.swing.JPanel;
50
import javax.swing.JScrollPane;
51
import javax.swing.JTextField;
52
import javax.swing.SwingUtilities;
53
import javax.swing.border.CompoundBorder;
54
import javax.swing.border.EmptyBorder;
55
import javax.swing.text.StyledDocument;
56
import org.netbeans.api.editor.DialogBinding;
57
import org.netbeans.editor.EditorUI;
58
import org.netbeans.modules.debugger.ui.FilteredKeymap;
59
import org.openide.ErrorManager;
60
import org.openide.cookies.EditorCookie;
61
import org.openide.filesystems.FileObject;
62
import org.openide.loaders.DataObject;
63
import org.openide.loaders.DataObjectNotFoundException;
64
import org.openide.text.NbDocument;
65
66
/**
67
 * UI Utilities.
68
 *
69
 * @since 2.23
70
 * @author Martin Entlicher
71
 */
72
public class Utilities {
73
74
    /**
75
     * Create a single-line scroll pane component containing the editor pane,
76
     * which is suitable as an entry field for dialogs.
77
     *
78
     * @param editorPane The editor pane
79
     * @return Scroll pane containing single-line editor.
80
     */
81
    public static JScrollPane createScrollableLineEditor(JEditorPane editorPane) {
82
        editorPane.setKeymap(new FilteredKeymap(editorPane));
83
        final JScrollPane sp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER,
84
                                         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
85
86
        editorPane.setBorder (
87
            new CompoundBorder (editorPane.getBorder(),
88
            new EmptyBorder (0, 0, 0, 0))
89
        );
90
91
        JTextField referenceTextField = new JTextField("M");
92
        JPanel panel = new JPanel(new GridBagLayout());
93
        panel.setBackground(referenceTextField.getBackground());
94
        sp.setBorder(referenceTextField.getBorder());
95
        sp.setBackground(referenceTextField.getBackground());
96
97
        GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
98
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
99
        gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
100
        gridBagConstraints.weightx = 1.0;
101
        panel.add(editorPane, gridBagConstraints);
102
        sp.setViewportView(panel);
103
104
        int preferredHeight = referenceTextField.getPreferredSize().height;
105
        if (sp.getPreferredSize().height < preferredHeight) {
106
            sp.setPreferredSize(referenceTextField.getPreferredSize());
107
        }
108
        sp.setMinimumSize(sp.getPreferredSize());
109
110
        setupUI(editorPane);
111
112
        Set<AWTKeyStroke> tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
113
        editorPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, tfkeys);
114
        tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
115
        editorPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, tfkeys);
116
        return sp;
117
    }
118
119
    /**
120
     * Set the context of given file and line to the editor pane.
121
     * It adds code-completion corresponding to the file and line context.
122
     *
123
     * @param editorPane    The editor pane
124
     * @param file          The context file
125
     * @param line          The context line
126
     */
127
    public static void setContext(JEditorPane editorPane, FileObject file, int line) {
128
        if (line < 1) {
129
            line = 1;
130
        }
131
        StyledDocument doc;
132
        if (file == null) {
133
            return;
134
        }
135
        try {
136
            DataObject dobj = DataObject.find (file);
137
            EditorCookie ec = dobj.getCookie(EditorCookie.class);
138
            if (ec == null) {
139
                return;
140
            }
141
            try {
142
                doc = ec.openDocument();
143
            } catch (IOException ex) {
144
                ErrorManager.getDefault().notify(ex);
145
                return;
146
            }
147
        } catch (DataObjectNotFoundException ex) {
148
            // null dobj
149
            return;
150
        }
151
        try {
152
            int offset = NbDocument.findLineOffset(doc, line - 1); // findLineOffset() expects zero based line numbers
153
            //editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj);
154
            //System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")");
155
            DialogBinding.bindComponentToDocument(doc, offset, 0, editorPane);
156
        } catch (IndexOutOfBoundsException ioobex) {
157
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioobex);
158
        }
159
        setupUI(editorPane);
160
    }
161
162
    private static void setupUI(final JEditorPane editorPane) {
163
        Runnable runnable = new Runnable() {
164
            public void run() {
165
                EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane);
166
                if (eui == null) {
167
                    return;
168
                }
169
                editorPane.putClientProperty(
170
                    "HighlightsLayerExcludes", //NOI18N
171
                    "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N
172
                );
173
                // Do not draw text limit line
174
                try {
175
                    java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N
176
                    textLimitLineField.setAccessible(true);
177
                    textLimitLineField.set(eui, false);
178
                } catch (Exception ex) {}
179
            }
180
        };
181
        if (SwingUtilities.isEventDispatchThread()) {
182
            runnable.run();
183
        } else {
184
            SwingUtilities.invokeLater(runnable);
185
        }
186
    }
187
188
}

Return to bug 181523