diff --git a/spi.debugger.ui/manifest.mf b/spi.debugger.ui/manifest.mf --- a/spi.debugger.ui/manifest.mf +++ b/spi.debugger.ui/manifest.mf @@ -2,6 +2,6 @@ OpenIDE-Module: org.netbeans.spi.debugger.ui/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/debugger/ui/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/debugger/resources/mf-layer.xml -OpenIDE-Module-Specification-Version: 2.22 +OpenIDE-Module-Specification-Version: 2.23 OpenIDE-Module-Provides: org.netbeans.spi.debugger.ui OpenIDE-Module-Install: org/netbeans/modules/debugger/ui/DebuggerModule.class diff --git a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchPanel.java b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchPanel.java --- a/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchPanel.java +++ b/spi.debugger.ui/src/org/netbeans/modules/debugger/ui/WatchPanel.java @@ -58,6 +58,7 @@ import org.netbeans.api.editor.DialogBinding; import org.netbeans.editor.EditorUI; import org.netbeans.spi.debugger.ui.EditorContextDispatcher; +import org.netbeans.spi.debugger.ui.Utilities; import org.openide.ErrorManager; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; @@ -97,13 +98,13 @@ editorPane = new JEditorPane();//expression); // NOI18N editorPane.setText(expression); - setupContext(editorPane, + Utilities.setContext(editorPane, EditorContextDispatcher.getDefault().getMostRecentFile(), EditorContextDispatcher.getDefault().getMostRecentLineNumber()); editorPane.setText (expression); editorPane.selectAll (); - JScrollPane sp = createScrollableLineEditor(editorPane); + JScrollPane sp = Utilities.createScrollableLineEditor(editorPane); int h = sp.getPreferredSize().height; int w = Math.min(70*editorPane.getFontMetrics(editorPane.getFont()).charWidth('a'), org.openide.windows.WindowManager.getDefault().getMainWindow().getSize().width); @@ -128,106 +129,6 @@ return panel; } - private static void setupUI(final JEditorPane editorPane) { - Runnable runnable = new Runnable() { - public void run() { - EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane); - if (eui == null) { - return; - } - editorPane.putClientProperty( - "HighlightsLayerExcludes", //NOI18N - "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N - ); - // Do not draw text limit line - try { - java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N - textLimitLineField.setAccessible(true); - textLimitLineField.set(eui, false); - } catch (Exception ex) {} - } - }; - if (SwingUtilities.isEventDispatchThread()) { - runnable.run(); - } else { - SwingUtilities.invokeLater(runnable); - } - } - - private static void setupContext(JEditorPane editorPane, FileObject file, int line) { - if (line < 1) { - line = 1; - } - StyledDocument doc; - if (file == null) { - return; - } - try { - DataObject dobj = DataObject.find (file); - EditorCookie ec = dobj.getCookie(EditorCookie.class); - if (ec == null) { - return; - } - try { - doc = ec.openDocument(); - } catch (IOException ex) { - ErrorManager.getDefault().notify(ex); - return; - } - } catch (DataObjectNotFoundException ex) { - // null dobj - return; - } - try { - int offset = NbDocument.findLineOffset(doc, line - 1); // findLineOffset() expects zero based line numbers - //editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj); - //System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")"); - DialogBinding.bindComponentToDocument(doc, offset, 0, editorPane); - } catch (IndexOutOfBoundsException ioobex) { - ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioobex); - } - setupUI(editorPane); - } - - private static JScrollPane createScrollableLineEditor(JEditorPane editorPane) { - editorPane.setKeymap(new FilteredKeymap(editorPane)); - final JScrollPane sp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER, - JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); - - editorPane.setBorder ( - new CompoundBorder (editorPane.getBorder(), - new EmptyBorder (0, 0, 0, 0)) - ); - - JTextField referenceTextField = new JTextField("M"); - JPanel panel = new JPanel(new GridBagLayout()); - panel.setBackground(referenceTextField.getBackground()); - sp.setBorder(referenceTextField.getBorder()); - sp.setBackground(referenceTextField.getBackground()); - - GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; - gridBagConstraints.weightx = 1.0; - panel.add(editorPane, gridBagConstraints); - sp.setViewportView(panel); - - int preferredHeight = referenceTextField.getPreferredSize().height; - if (sp.getPreferredSize().height < preferredHeight) { - sp.setPreferredSize(referenceTextField.getPreferredSize()); - } - sp.setMinimumSize(sp.getPreferredSize()); - - setupUI(editorPane); - - Set tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); - editorPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, tfkeys); - tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); - editorPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, tfkeys); - return sp; - } - - public String getExpression() { return editorPane.getText().trim(); } diff --git a/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/Utilities.java b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/Utilities.java new file mode 100644 --- /dev/null +++ b/spi.debugger.ui/src/org/netbeans/spi/debugger/ui/Utilities.java @@ -0,0 +1,188 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2010 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.debugger.ui; + +import java.awt.AWTKeyStroke; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.KeyboardFocusManager; +import java.io.IOException; +import java.util.Set; +import javax.swing.JEditorPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.text.StyledDocument; +import org.netbeans.api.editor.DialogBinding; +import org.netbeans.editor.EditorUI; +import org.netbeans.modules.debugger.ui.FilteredKeymap; +import org.openide.ErrorManager; +import org.openide.cookies.EditorCookie; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.text.NbDocument; + +/** + * UI Utilities. + * + * @since 2.23 + * @author Martin Entlicher + */ +public class Utilities { + + /** + * Create a single-line scroll pane component containing the editor pane, + * which is suitable as an entry field for dialogs. + * + * @param editorPane The editor pane + * @return Scroll pane containing single-line editor. + */ + public static JScrollPane createScrollableLineEditor(JEditorPane editorPane) { + editorPane.setKeymap(new FilteredKeymap(editorPane)); + final JScrollPane sp = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + editorPane.setBorder ( + new CompoundBorder (editorPane.getBorder(), + new EmptyBorder (0, 0, 0, 0)) + ); + + JTextField referenceTextField = new JTextField("M"); + JPanel panel = new JPanel(new GridBagLayout()); + panel.setBackground(referenceTextField.getBackground()); + sp.setBorder(referenceTextField.getBorder()); + sp.setBackground(referenceTextField.getBackground()); + + GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; + gridBagConstraints.weightx = 1.0; + panel.add(editorPane, gridBagConstraints); + sp.setViewportView(panel); + + int preferredHeight = referenceTextField.getPreferredSize().height; + if (sp.getPreferredSize().height < preferredHeight) { + sp.setPreferredSize(referenceTextField.getPreferredSize()); + } + sp.setMinimumSize(sp.getPreferredSize()); + + setupUI(editorPane); + + Set tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); + editorPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, tfkeys); + tfkeys = referenceTextField.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); + editorPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, tfkeys); + return sp; + } + + /** + * Set the context of given file and line to the editor pane. + * It adds code-completion corresponding to the file and line context. + * + * @param editorPane The editor pane + * @param file The context file + * @param line The context line + */ + public static void setContext(JEditorPane editorPane, FileObject file, int line) { + if (line < 1) { + line = 1; + } + StyledDocument doc; + if (file == null) { + return; + } + try { + DataObject dobj = DataObject.find (file); + EditorCookie ec = dobj.getCookie(EditorCookie.class); + if (ec == null) { + return; + } + try { + doc = ec.openDocument(); + } catch (IOException ex) { + ErrorManager.getDefault().notify(ex); + return; + } + } catch (DataObjectNotFoundException ex) { + // null dobj + return; + } + try { + int offset = NbDocument.findLineOffset(doc, line - 1); // findLineOffset() expects zero based line numbers + //editorPane.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj); + //System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")"); + DialogBinding.bindComponentToDocument(doc, offset, 0, editorPane); + } catch (IndexOutOfBoundsException ioobex) { + ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioobex); + } + setupUI(editorPane); + } + + private static void setupUI(final JEditorPane editorPane) { + Runnable runnable = new Runnable() { + public void run() { + EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane); + if (eui == null) { + return; + } + editorPane.putClientProperty( + "HighlightsLayerExcludes", //NOI18N + "^org\\.netbeans\\.modules\\.editor\\.lib2\\.highlighting\\.CaretRowHighlighting$" //NOI18N + ); + // Do not draw text limit line + try { + java.lang.reflect.Field textLimitLineField = EditorUI.class.getDeclaredField("textLimitLineVisible"); // NOI18N + textLimitLineField.setAccessible(true); + textLimitLineField.set(eui, false); + } catch (Exception ex) {} + } + }; + if (SwingUtilities.isEventDispatchThread()) { + runnable.run(); + } else { + SwingUtilities.invokeLater(runnable); + } + } + +}