diff -r 03b2f960a7c3 debugger.jpda.jsui/nbproject/project.properties --- a/debugger.jpda.jsui/nbproject/project.properties Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.jsui/nbproject/project.properties Tue Jun 07 13:52:54 2016 +0200 @@ -42,6 +42,6 @@ cp.extra=${tools.jar} javac.compilerargs=-Xlint:unchecked -javac.source=1.7 +javac.source=1.8 javadoc.arch=${basedir}/arch.xml requires.nb.javac=true diff -r 03b2f960a7c3 debugger.jpda.jsui/nbproject/project.xml --- a/debugger.jpda.jsui/nbproject/project.xml Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.jsui/nbproject/project.xml Tue Jun 07 13:52:54 2016 +0200 @@ -95,6 +95,15 @@ + org.netbeans.modules.editor.lib + + + + 3 + 4.7 + + + org.netbeans.modules.java.kit 1.0 @@ -106,7 +115,7 @@ 1 - 1.0 + 1.3 @@ -133,7 +142,7 @@ 1 - 2.34 + 2.54 @@ -234,14 +243,6 @@ - org.openide.util.ui - - - - 9.3 - - - org.openide.util @@ -258,6 +259,14 @@ + org.openide.util.ui + + + + 9.3 + + + org.openide.windows diff -r 03b2f960a7c3 debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/JPDADebuggerTooltipSupport.java --- a/debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/JPDADebuggerTooltipSupport.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2014 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.debugger.jpda.jsui.vars.tooltip; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.Closeable; -import java.io.IOException; -import org.netbeans.api.debugger.jpda.CallStackFrame; -import org.netbeans.api.debugger.jpda.JPDADebugger; -import org.netbeans.modules.javascript2.debug.ui.tooltip.DebuggerTooltipSupport; - -/** - * - * @author Martin Entlicher - */ -final class JPDADebuggerTooltipSupport implements DebuggerTooltipSupport, PropertyChangeListener { - - private final JPDADebugger debugger; - private final CallStackFrame frame; - private Closeable closeable; - - JPDADebuggerTooltipSupport(JPDADebugger debugger, CallStackFrame frame) { - this.debugger = debugger; - this.frame = frame; - } - - public JPDADebugger getDebugger() { - return debugger; - } - - public CallStackFrame getFrame() { - return frame; - } - - @Override - public void addCloseable(Closeable closeable) { - this.closeable = closeable; - debugger.addPropertyChangeListener(JPDADebugger.PROP_STATE, this); - } - - @Override - public void removeCloseable(Closeable closeable) { - debugger.removePropertyChangeListener(JPDADebugger.PROP_STATE, this); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - try { - closeable.close(); - } catch (IOException ex) {} - } - -} diff -r 03b2f960a7c3 debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/ToolTipAnnotation.java --- a/debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/ToolTipAnnotation.java Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/ToolTipAnnotation.java Tue Jun 07 13:52:54 2016 +0200 @@ -42,7 +42,10 @@ package org.netbeans.modules.debugger.jpda.jsui.vars.tooltip; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.concurrent.CancellationException; +import javax.swing.SwingUtilities; import org.netbeans.api.debugger.DebuggerEngine; import org.netbeans.api.debugger.Session; import org.netbeans.api.debugger.jpda.CallStackFrame; @@ -50,6 +53,7 @@ import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.api.debugger.jpda.ObjectVariable; import org.netbeans.api.debugger.jpda.Variable; +import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.modules.debugger.jpda.js.JSUtils; import org.netbeans.modules.debugger.jpda.js.vars.DebuggerSupport; import org.netbeans.modules.debugger.jpda.js.vars.JSVariable; @@ -60,10 +64,35 @@ * * @author Martin */ -public final class ToolTipAnnotation extends AbstractJSToolTipAnnotation { +public final class ToolTipAnnotation extends AbstractJSToolTipAnnotation { @Override - protected JPDADebuggerTooltipSupport getEngineDebugger(Session session, DebuggerEngine engine) { + protected void handleToolTipClose(DebuggerEngine engine, ToolTipSupport tts) { + JPDADebugger d = engine.lookupFirst(null, JPDADebugger.class); + if (d == null) { + return ; + } + PropertyChangeListener l = (PropertyChangeEvent evt) -> { + int state = ((Integer) evt.getNewValue()); + if (JPDADebugger.STATE_DISCONNECTED == state || + JPDADebugger.STATE_RUNNING == state) { + SwingUtilities.invokeLater(() -> + tts.setToolTipVisible(false) + ); + } + }; + d.addPropertyChangeListener(JPDADebugger.PROP_STATE, l); + tts.addPropertyChangeListener(pl -> { + if (ToolTipSupport.PROP_STATUS.equals(pl.getPropertyName()) && + !tts.isToolTipVisible()) { + d.removePropertyChangeListener(JPDADebugger.PROP_STATE, l); + } + }); + } + + @Override + protected Pair evaluate(String expression, DebuggerEngine engine) throws CancellationException { + Session session = engine.lookupFirst(null, Session.class); if (engine != session.getEngineForLanguage(JSUtils.JS_STRATUM)) { return null; } @@ -75,26 +104,20 @@ if (frame == null) { return null; } - return new JPDADebuggerTooltipSupport(d, frame); - } - - @Override - protected Pair evaluate(String expression, DebuggerEngine engine, JPDADebuggerTooltipSupport dbg) throws CancellationException { String toolTipText; - CallStackFrame frame = dbg.getFrame(); JSVariable jsresult = null; try { - Variable result = DebuggerSupport.evaluate(dbg.getDebugger(), frame, expression); + Variable result = DebuggerSupport.evaluate(d, frame, expression); if (result == null) { throw new CancellationException(); } if (result instanceof ObjectVariable) { - jsresult = JSVariable.createIfScriptObject(dbg.getDebugger(), (ObjectVariable) result, expression); + jsresult = JSVariable.createIfScriptObject(d, (ObjectVariable) result, expression); } if (jsresult != null) { toolTipText = expression + " = " + jsresult.getValue(); } else { - toolTipText = expression + " = " + DebuggerSupport.getVarValue(dbg.getDebugger(), result); + toolTipText = expression + " = " + DebuggerSupport.getVarValue(d, result); } } catch (InvalidExpressionException ex) { toolTipText = expression + " = >" + ex.getMessage () + "<"; diff -r 03b2f960a7c3 debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/ToolTipModel.java --- a/debugger.jpda.jsui/src/org/netbeans/modules/debugger/jpda/jsui/vars/tooltip/ToolTipModel.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2015 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2015 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.debugger.jpda.jsui.vars.tooltip; - -import org.netbeans.modules.debugger.jpda.jsui.vars.models.VariablesJSTreeModel; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractJSToolTipAnnotation; -import org.netbeans.spi.debugger.ContextProvider; -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.TreeModel; -import static org.netbeans.spi.viewmodel.TreeModel.ROOT; -import org.netbeans.spi.viewmodel.TreeModelFilter; -import org.netbeans.spi.viewmodel.UnknownTypeException; - -/** - * - * @author Martin - */ -@DebuggerServiceRegistration(path="netbeans-JPDASession/JS/ToolTipView", - types={ TreeModelFilter.class }, - position=360) -public class ToolTipModel extends VariablesJSTreeModel implements TreeModelFilter { - - public ToolTipModel(ContextProvider lookupProvider) { - super(lookupProvider); - } - - @Override - public Object[] getChildren(TreeModel original, Object parent, int from, int to) throws UnknownTypeException { - if (parent == ROOT) { - Object ttv = AbstractJSToolTipAnnotation.getTooltipVariable(); - if (ttv != null) { - return new Object[] { ttv }; - } else { - return new Object[] { }; - } - } else { - return super.getChildren(original, parent, from, to); - } - } - - @Override - public int getChildrenCount(TreeModel original, Object node) throws UnknownTypeException { - if (node == ROOT) { - return 1; - } else { - return super.getChildrenCount(original, node); - } - } - -} diff -r 03b2f960a7c3 debugger.jpda.projectsui/nbproject/project.xml --- a/debugger.jpda.projectsui/nbproject/project.xml Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.projectsui/nbproject/project.xml Tue Jun 07 13:52:54 2016 +0200 @@ -220,7 +220,7 @@ 1 - 2.34 + 2.54 diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/DebuggerStateChangeListener.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/DebuggerStateChangeListener.java Tue Jun 07 13:52:54 2016 +0200 @@ -0,0 +1,86 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2016 Sun Microsystems, Inc. + */ +package org.netbeans.modules.debugger.jpda.projectsui; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.SwingUtilities; +import org.netbeans.api.debugger.jpda.JPDADebugger; +import org.netbeans.editor.ext.ToolTipSupport; + +/** + * + * @author martin + */ +final class DebuggerStateChangeListener implements PropertyChangeListener, Runnable { + + private final ToolTipSupport tts; + + private DebuggerStateChangeListener(ToolTipSupport tts) { + this.tts = tts; + } + + static void attach(JPDADebugger d, ToolTipSupport tts) { + DebuggerStateChangeListener dscl = new DebuggerStateChangeListener(tts); + d.addPropertyChangeListener(JPDADebugger.PROP_STATE, dscl); + tts.addPropertyChangeListener(propListener -> { + if (ToolTipSupport.PROP_STATUS.equals(propListener.getPropertyName()) && + !tts.isToolTipVisible()) { + d.removePropertyChangeListener(JPDADebugger.PROP_STATE, dscl); + } + }); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + int state = ((Integer) evt.getNewValue()); + if (JPDADebugger.STATE_DISCONNECTED == state || + JPDADebugger.STATE_RUNNING == state) { + SwingUtilities.invokeLater(this); + } + } + + @Override + public void run() { + tts.setToolTipVisible(false); + } +} diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/PinWatchExpandAction.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/PinWatchExpandAction.java Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/PinWatchExpandAction.java Tue Jun 07 13:52:54 2016 +0200 @@ -41,41 +41,27 @@ */ package org.netbeans.modules.debugger.jpda.projectsui; -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.lang.ref.Reference; import java.lang.ref.WeakReference; -import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JEditorPane; -import javax.swing.UIManager; import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.api.debugger.jpda.ObjectVariable; -import org.netbeans.editor.EditorUI; -import org.netbeans.editor.Utilities; import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.debugger.ui.EditorContextDispatcher; +import org.netbeans.spi.debugger.ui.AbstractExpandToolTipAction; /** * * @author martin */ @DebuggerServiceRegistration(path = "netbeans-JPDASession/PinWatchHeadActions", types = Action.class) -public class PinWatchExpandAction extends AbstractAction { +public class PinWatchExpandAction extends AbstractExpandToolTipAction { - private final Icon toExpandIcon = UIManager.getIcon ("Tree.collapsedIcon"); // NOI18N - private final Icon toCollapsIcon = UIManager.getIcon ("Tree.expandedIcon"); // NOI18N private Reference debuggerRef; private String expression; private Reference varRef; - private boolean expanded; public PinWatchExpandAction() { - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); } @Override @@ -97,7 +83,7 @@ synchronized (this) { if (varRef == null || varRef.get() != value) { varRef = new WeakReference<>((ObjectVariable) value); - expanded = false; +// expanded = false; } } break; @@ -113,11 +99,10 @@ } @Override - public void actionPerformed(ActionEvent e) { + protected void openTooltipView() { JPDADebugger debugger = null; String exp; ObjectVariable var = null; - boolean expand; synchronized (this) { if (debuggerRef != null) { debugger = debuggerRef.get(); @@ -126,55 +111,13 @@ if (varRef != null) { var = varRef.get(); } - expanded = !expanded; - expand = expanded; } if (debugger != null && exp != null && var != null) { - if (expand) { - displayExpanded(debugger, expression, var); - putValue(Action.SMALL_ICON, toCollapsIcon); - putValue(Action.LARGE_ICON_KEY, toCollapsIcon); - } else { - collapse(); - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); + ToolTipSupport tts = openTooltipView(expression, var); + if (tts != null) { + DebuggerStateChangeListener.attach(debugger, tts); } } } - private void displayExpanded(JPDADebugger debugger, String expression, ObjectVariable var) { - ToolTipView toolTipView = ToolTipView.getToolTipView(debugger, expression, var); - JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor(); - EditorUI eui = Utilities.getEditorUI(currentEditor); - if (eui != null) { - final ToolTipSupport toolTipSupport = eui.getToolTipSupport(); - toolTipView.setToolTipSupport(toolTipSupport); - toolTipSupport.setToolTipVisible(true, false); - toolTipSupport.setToolTip(toolTipView); - toolTipSupport.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (ToolTipSupport.PROP_STATUS.equals(evt.getPropertyName())) { - if (!toolTipSupport.isToolTipVisible()) { - synchronized (PinWatchExpandAction.this) { - expanded = false; - } - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); - toolTipSupport.removePropertyChangeListener(this); - } - } - } - }); - } - } - - private void collapse() { - JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor(); - EditorUI eui = Utilities.getEditorUI(currentEditor); - if (eui != null) { - eui.getToolTipSupport().setToolTipVisible(false, false); - } - } - } diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipAnnotation.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipAnnotation.java Thu Jun 02 16:36:56 2016 +0200 +++ b/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipAnnotation.java Tue Jun 07 13:52:54 2016 +0200 @@ -51,6 +51,8 @@ import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -101,6 +103,8 @@ import org.netbeans.spi.debugger.ui.EditorContextDispatcher; import org.netbeans.spi.debugger.ui.EditorPin; import org.netbeans.spi.debugger.ui.PinWatchUISupport; +import org.netbeans.spi.debugger.ui.ToolTipUI; +import org.netbeans.spi.debugger.ui.ViewFactory; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; @@ -112,6 +116,7 @@ import org.openide.text.NbDocument; import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; +import org.openide.util.WeakListeners; public class ToolTipAnnotation extends Annotation implements Runnable { @@ -341,60 +346,22 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - boolean expandable = var != null; - final ToolTipView.ExpandableTooltip et = ToolTipView.createExpandableTooltip(toolTip, expandable); - if (expandable) { - et.addExpansionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - et.setBorder(BorderFactory.createLineBorder(et.getForeground())); - et.removeAll(); - et.setWidthCheck(false); - final ToolTipView ttView = ToolTipView.getToolTipView(d, expression, var); - et.add(ttView); - et.revalidate(); - et.repaint(); - SwingUtilities.invokeLater(new Runnable() { - public @Override void run() { - EditorUI eui = Utilities.getEditorUI(ep); - if (eui != null) { - ttView.setToolTipSupport(eui.getToolTipSupport()); - eui.getToolTipSupport().setToolTip(et, PopupManager.ViewPortBounds, PopupManager.AbovePreferred, 0, 0, ToolTipSupport.FLAGS_HEAVYWEIGHT_TOOLTIP); - } else { - firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); - } - } - }); - } - }); + EditorUI eui = Utilities.getEditorUI(ep); + if (eui == null) { + firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); + return ; } - et.addPinListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - EditorUI eui = Utilities.getEditorUI(ep); - Point location = et.getLocation(); - location = eui.getStickyWindowSupport().convertPoint(location); - eui.getToolTipSupport().setToolTipVisible(false); - DebuggerManager dbMgr = DebuggerManager.getDebuggerManager(); - Watch.Pin pin = new EditorPin(fo, line.getLineNumber(), location); - final Watch w = dbMgr.createPinnedWatch(expression, pin); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - try { - PinWatchUISupport.getDefault().pin(w, "org.netbeans.modules.debugger.jpda.PIN_VALUE_PROVIDER"); // NOI18N - } catch (IllegalArgumentException ex) { - Exceptions.printStackTrace(ex); - } - } - }); - } - }); - EditorUI eui = Utilities.getEditorUI(ep); - if (eui != null) { - eui.getToolTipSupport().setToolTip(et); - } else { - firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); + ToolTipUI.Expandable expandable = (var != null) ? + new ToolTipUI.Expandable(expression, var) : + null; + ToolTipUI.Pinnable pinnable = new ToolTipUI.Pinnable( + expression, + line.getLineNumber(), + "org.netbeans.modules.debugger.jpda.PIN_VALUE_PROVIDER"); // NOI18N + ToolTipUI toolTipUI = ViewFactory.getDefault().createToolTip(toolTip, expandable, pinnable); + ToolTipSupport tts = toolTipUI.show(ep); + if (tts != null) { + DebuggerStateChangeListener.attach(d, tts); } } }); diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipExpansionFilter.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipExpansionFilter.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2012 Sun Microsystems, Inc. - */ -package org.netbeans.modules.debugger.jpda.projectsui; - -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.ModelListener; -import org.netbeans.spi.viewmodel.TreeExpansionModel; -import org.netbeans.spi.viewmodel.TreeExpansionModelFilter; -import org.netbeans.spi.viewmodel.UnknownTypeException; - -/** - * Assures that the variable in tooltip is expanded automatically. - * - * @author Martin Entlicher - */ -@DebuggerServiceRegistration(path="netbeans-JPDASession/ToolTipView", - types=TreeExpansionModelFilter.class, - position=2000) -public class ToolTipExpansionFilter implements TreeExpansionModelFilter { - - @Override - public boolean isExpanded(TreeExpansionModel original, Object node) throws UnknownTypeException { - if (node == ToolTipView.getVariable()) { - return true; - } else { - return original.isExpanded(node); - } - } - - @Override - public void nodeExpanded(Object node) {} - - @Override - public void nodeCollapsed(Object node) {} - - @Override - public void addModelListener(ModelListener l) {} - - @Override - public void removeModelListener(ModelListener l) {} - -} diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipNodeModelFilter.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipNodeModelFilter.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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.modules.debugger.jpda.projectsui; - -import java.awt.datatransfer.Transferable; -import java.io.IOException; -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.ExtendedNodeModel; -import org.netbeans.spi.viewmodel.ExtendedNodeModelFilter; -import org.netbeans.spi.viewmodel.ModelListener; -import org.netbeans.spi.viewmodel.NodeModel; -import org.netbeans.spi.viewmodel.UnknownTypeException; -import org.openide.util.datatransfer.PasteType; - -/** - * - * @author martin - */ -@DebuggerServiceRegistration(path="netbeans-JPDASession/ToolTipView", - types=ExtendedNodeModelFilter.class, - position=375) -public class ToolTipNodeModelFilter implements ExtendedNodeModelFilter { - - @Override - public String getDisplayName(NodeModel original, Object node) throws UnknownTypeException { - String dn; - try { - dn = original.getDisplayName(node); - } catch (UnknownTypeException utex) { - dn = ""; - } - if (node == ToolTipView.getVariable() && dn.length() == 0) { - return ToolTipView.getExpression(); - } else { - return dn; - } - } - - @Override - public String getIconBase(NodeModel original, Object node) throws UnknownTypeException { - return original.getIconBase(node); - } - - @Override - public String getShortDescription(NodeModel original, Object node) throws UnknownTypeException { - return original.getShortDescription(node); - } - - @Override - public void addModelListener(ModelListener l) { - } - - @Override - public void removeModelListener(ModelListener l) { - } - - @Override - public boolean canRename(ExtendedNodeModel original, Object node) throws UnknownTypeException { - return original.canRename(node); - } - - @Override - public boolean canCopy(ExtendedNodeModel original, Object node) throws UnknownTypeException { - return original.canCopy(node); - } - - @Override - public boolean canCut(ExtendedNodeModel original, Object node) throws UnknownTypeException { - return original.canCut(node); - } - - @Override - public Transferable clipboardCopy(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException { - return original.clipboardCopy(node); - } - - @Override - public Transferable clipboardCut(ExtendedNodeModel original, Object node) throws IOException, UnknownTypeException { - return original.clipboardCut(node); - } - - @Override - public PasteType[] getPasteTypes(ExtendedNodeModel original, Object node, Transferable t) throws UnknownTypeException { - return original.getPasteTypes(node, t); - } - - @Override - public void setName(ExtendedNodeModel original, Object node, String name) throws UnknownTypeException { - original.setName(node, name); - } - - @Override - public String getIconBaseWithExtension(ExtendedNodeModel original, Object node) throws UnknownTypeException { - return original.getIconBaseWithExtension(node); - } - -} diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipTreeModelFilter.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipTreeModelFilter.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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.modules.debugger.jpda.projectsui; - -import org.netbeans.api.debugger.jpda.ObjectVariable; -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.ModelListener; -import org.netbeans.spi.viewmodel.TreeModel; -import org.netbeans.spi.viewmodel.TreeModelFilter; -import org.netbeans.spi.viewmodel.UnknownTypeException; - -/** - * - * @author martin - */ -@DebuggerServiceRegistration(path="netbeans-JPDASession/ToolTipView", - types=TreeModelFilter.class, - position=370) -public class ToolTipTreeModelFilter implements TreeModelFilter { - - @Override - public Object getRoot(TreeModel original) { - return original.getRoot(); - } - - @Override - public Object[] getChildren(TreeModel original, Object parent, int from, int to) throws UnknownTypeException { - if (parent == TreeModel.ROOT) { - ObjectVariable tooltipVar = ToolTipView.getVariable(); - if (tooltipVar != null) { - return new Object[] { tooltipVar }; - } else { - return new Object[] { }; - } - } else { - return original.getChildren(parent, from, to); - } - } - - @Override - public int getChildrenCount(TreeModel original, Object node) throws UnknownTypeException { - return Integer.MAX_VALUE; - } - - @Override - public boolean isLeaf(TreeModel original, Object node) throws UnknownTypeException { - return original.isLeaf(node); - } - - @Override - public void addModelListener(ModelListener l) { - } - - @Override - public void removeModelListener(ModelListener l) { - } - -} diff -r 03b2f960a7c3 debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipView.java --- a/debugger.jpda.projectsui/src/org/netbeans/modules/debugger/jpda/projectsui/ToolTipView.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,402 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.debugger.jpda.projectsui; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Insets; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.Icon; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.Keymap; -import org.netbeans.api.debugger.jpda.JPDADebugger; -import org.netbeans.api.debugger.jpda.ObjectVariable; -import org.netbeans.editor.ext.ToolTipSupport; -import org.netbeans.spi.debugger.ui.ViewFactory; -import org.openide.util.ImageUtilities; - - -// -// Implement HelpCtx.Provider interface to provide help ids for help system -// public class CallStackView extends TopComponent { -// ==== -public class ToolTipView extends JComponent implements org.openide.util.HelpCtx.Provider { -// - - public static final String TOOLTIP_VIEW_NAME = "ToolTipView"; - - private static volatile String expression; - private static volatile ObjectVariable variable; - - private transient JComponent contentComponent; - private transient JPDADebugger debugger; - private transient ToolTipSupport toolTipSupport; - private transient DebuggerStateChangeListener debuggerStateChangeListener; - private String name; // Store just the name persistently, we'll create the component from that - - private ToolTipView(JPDADebugger debugger, String expression, ObjectVariable v, String icon) { - this.debugger = debugger; - ToolTipView.expression = expression; - variable = v; - this.name = TOOLTIP_VIEW_NAME; - JComponent c = ViewFactory.getDefault().createViewComponent( - icon, - ToolTipView.TOOLTIP_VIEW_NAME, - "NetbeansDebuggerJPDAToolTipNode", - null); - setLayout (new BorderLayout ()); - add (c, BorderLayout.CENTER); //NOI18N - debuggerStateChangeListener = new DebuggerStateChangeListener(); - debugger.addPropertyChangeListener(JPDADebugger.PROP_STATE, debuggerStateChangeListener); - } - - static String getExpression() { - return expression; - } - - static ObjectVariable getVariable() { - return variable; - } - - void setToolTipSupport(ToolTipSupport toolTipSupport) { - this.toolTipSupport = toolTipSupport; - } - - private void closeToolTip() { - toolTipSupport.setToolTipVisible(false); - } - - //protected void componentHidden () { - @Override - public void removeNotify() { - super.removeNotify();//componentHidden (); - variable = null; - debugger.removePropertyChangeListener(JPDADebugger.PROP_STATE, debuggerStateChangeListener); - } - - // - // Implement getHelpCtx() with the correct help ID - @Override - public org.openide.util.HelpCtx getHelpCtx() { - return new org.openide.util.HelpCtx("NetbeansDebuggerJPDAToolTipNode"); - } - // - - @Override - public boolean requestFocusInWindow () { - super.requestFocusInWindow (); - if (contentComponent == null) { - return false; - } - return contentComponent.requestFocusInWindow (); - } - - /* - public void requestActive() { - super.requestActive(); - if (contentComponent != null) { - contentComponent.requestFocusInWindow (); - } - } - */ - - /* - public String getName () { - return NbBundle.getMessage (ToolTipView.class, displayNameResource); - } - - public String getToolTipText () { - return NbBundle.getMessage (ToolTipView.class, toolTipResource);// NOI18N - } - */ - - private class DebuggerStateChangeListener implements PropertyChangeListener, Runnable { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - int state = ((Integer) evt.getNewValue()).intValue(); - if (JPDADebugger.STATE_DISCONNECTED == state || - JPDADebugger.STATE_RUNNING == state) { - SwingUtilities.invokeLater(this); - } - } - - @Override - public void run() { - closeToolTip(); - } - - } - - - - /** Creates the view. */ - public static synchronized ToolTipView getToolTipView(JPDADebugger debugger, String expression, ObjectVariable v) { - return new ToolTipView( - debugger, - expression, - v, - "org/netbeans/modules/debugger/resources/localsView/local_variable_16.png" - ); - } - - - static ExpandableTooltip createExpandableTooltip(String toolTipText, boolean expandable) { - return new ExpandableTooltip(toolTipText, expandable); - } - - static class ExpandableTooltip extends JPanel { - - private static final String UI_PREFIX = "ToolTip"; // NOI18N - - private JButton expButton; - private JButton pinButton; - private JComponent textToolTip; - private boolean widthCheck = true; - private boolean sizeSet = false; - - public ExpandableTooltip(String toolTipText, boolean expandable) { - Font font = UIManager.getFont(UI_PREFIX + ".font"); // NOI18N - Color backColor = UIManager.getColor(UI_PREFIX + ".background"); // NOI18N - Color foreColor = UIManager.getColor(UI_PREFIX + ".foreground"); // NOI18N - - if (backColor != null) { - setBackground(backColor); - } - setOpaque(true); - setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(getForeground()), - BorderFactory.createEmptyBorder(0, 3, 0, 3) - )); - - setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - pinButton = new JButton(ImageUtilities.loadImageIcon("org/netbeans/editor/resources/pin.png", false)); - pinButton.setBorder(new javax.swing.border.EmptyBorder(0, 3, 0, 0)); - pinButton.setBorderPainted(false); - pinButton.setContentAreaFilled(false); - add(pinButton); - if (expandable) { - Icon expIcon = UIManager.getIcon ("Tree.collapsedIcon"); // NOI18N - expButton = new JButton(expIcon); - expButton.setBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 5)); - expButton.setBorderPainted(false); - expButton.setContentAreaFilled(false); - add(expButton); - } - //JLabel l = new JLabel(toolTipText); - // Multi-line tooltip: - JTextArea l = createMultiLineToolTip(toolTipText, true); - if (font != null) { - l.setFont(font); - } - if (foreColor != null) { - l.setForeground(foreColor); - } - if (backColor != null) { - l.setBackground(backColor); - } - l.setBorder(new javax.swing.border.EmptyBorder(0, 3, 0, 3)); - textToolTip = l; - add(l); - InputMap im = new InputMap(); - im.setParent(getInputMap()); - setInputMap(WHEN_FOCUSED, im); - ActionMap am = new ActionMap(); - am.setParent(getActionMap()); - setActionMap(am); - im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "expand"); // NOI18N - im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "pin"); // NOI18N - if (expandable) { - am.put("expand", new AbstractAction() { // NOI18N - @Override - public void actionPerformed(ActionEvent e) { - expButton.doClick(); - } - }); - } - am.put("pin", new AbstractAction() { // NOI18N - @Override - public void actionPerformed(ActionEvent e) { - SwingUtilities.invokeLater(() -> pinButton.doClick()); - } - }); - } - - void addExpansionListener(ActionListener treeExpansionListener) { - expButton.addActionListener(treeExpansionListener); - } - - void addPinListener(ActionListener treeExpansionListener) { - pinButton.addActionListener(treeExpansionListener); - } - - void setWidthCheck(boolean widthCheck) { - this.widthCheck = widthCheck; - } - - @Override - public Dimension getPreferredSize() { - if (!sizeSet) { - // Be big enough initially. - return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); - } - Dimension preferredSize = super.getPreferredSize(); - // Let the width be as long as it can be - return new Dimension(Integer.MAX_VALUE, preferredSize.height); - } - - @Override - public void setSize(int width, int height) { - Dimension prefSize = getPreferredSize(); - Dimension button1Size = (expButton != null) ? expButton.getPreferredSize() : new Dimension(0, 0); - Dimension button2Size = pinButton.getPreferredSize(); - if (widthCheck) { - Insets insets = getInsets(); - int textWidth = width - insets.left - button1Size.width - button2Size.width - insets.right; - height = Math.max(Math.max(height, button1Size.height), button2Size.height); - textToolTip.setSize(textWidth, height); - Dimension textPreferredSize = textToolTip.getPreferredSize(); - super.setSize( - insets.left + button1Size.width + button2Size.width + textPreferredSize.width + insets.right, - insets.top + Math.max(Math.max(button1Size.height, textPreferredSize.height), button2Size.height) + insets.bottom); - } else { - if (height >= prefSize.height) { // enough height - height = prefSize.height; - } - super.setSize(width, height); - } - sizeSet = true; - } - - private static JTextArea createMultiLineToolTip(String toolTipText, boolean wrapLines) { - JTextArea ta = new TextToolTip(wrapLines); - ta.setText(toolTipText); - return ta; - } - - private static class TextToolTip extends JTextArea { - - private static final String ELIPSIS = "..."; //NOI18N - - private final boolean wrapLines; - - public TextToolTip(boolean wrapLines) { - this.wrapLines = wrapLines; - setLineWrap(false); // It's necessary to have a big width of preferred size first. - } - - public @Override void setSize(int width, int height) { - Dimension prefSize = getPreferredSize(); - if (width >= prefSize.width) { - width = prefSize.width; - } else { // smaller available width - // Set line wrapping and do super.setSize() to determine - // the real height (it will change due to line wrapping) - if (wrapLines) { - setLineWrap(true); - setWrapStyleWord(true); - } - - super.setSize(width, Integer.MAX_VALUE); // the height is unimportant - prefSize = getPreferredSize(); // re-read new pref width - } - if (height >= prefSize.height) { // enough height - height = prefSize.height; - } else { // smaller available height - // Check how much can be displayed - cannot rely on line count - // because line wrapping may display single physical line - // into several visual lines - // Before using viewToModel() a setSize() must be called - // because otherwise the viewToModel() would return -1. - super.setSize(width, Integer.MAX_VALUE); - int offset = viewToModel(new Point(0, height)); - Document doc = getDocument(); - try { - if (offset > ELIPSIS.length()) { - offset -= ELIPSIS.length(); - doc.remove(offset, doc.getLength() - offset); - doc.insertString(offset, ELIPSIS, null); - } - } catch (BadLocationException ble) { - // "..." will likely not be displayed but otherwise should be ok - } - // Recalculate the prefSize as it may be smaller - // than the present preferred height - height = Math.min(height, getPreferredSize().height); - } - super.setSize(width, height); - } - - @Override - public void setKeymap(Keymap map) { - //#181722: keymaps are shared among components with the same UI - //a default action will be set to the Keymap of this component below, - //so it is necessary to use a Keymap that is not shared with other JTextAreas - super.setKeymap(addKeymap(null, map)); - } - } - } - -} diff -r 03b2f960a7c3 javascript.v8debug.ui/nbproject/project.xml --- a/javascript.v8debug.ui/nbproject/project.xml Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript.v8debug.ui/nbproject/project.xml Tue Jun 07 13:52:54 2016 +0200 @@ -86,6 +86,15 @@ + org.netbeans.modules.editor.lib + + + + 3 + 4.7 + + + org.netbeans.modules.javascript.v8debug @@ -109,7 +118,7 @@ 1 - 1.2 + 1.3 @@ -135,7 +144,7 @@ 1 - 2.49 + 2.54 diff -r 03b2f960a7c3 javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/PinWatchValueProvider.java --- a/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/PinWatchValueProvider.java Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/PinWatchValueProvider.java Tue Jun 07 13:52:54 2016 +0200 @@ -41,15 +41,11 @@ */ package org.netbeans.modules.javascript.v8debug.ui.vars.models; -import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.Map; -import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JEditorPane; -import javax.swing.UIManager; import org.netbeans.api.debugger.Watch; +import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.lib.v8debug.V8Command; import org.netbeans.lib.v8debug.V8Request; import org.netbeans.lib.v8debug.commands.Evaluate; @@ -57,14 +53,12 @@ import org.netbeans.modules.javascript.v8debug.V8Debugger; import org.netbeans.modules.javascript.v8debug.V8DebuggerEngineProvider; import org.netbeans.modules.javascript.v8debug.frames.CallFrame; -import org.netbeans.modules.javascript.v8debug.ui.vars.tooltip.V8DebuggerTooltipSupport; +import org.netbeans.modules.javascript.v8debug.ui.vars.tooltip.ToolTipAnnotation; import org.netbeans.modules.javascript.v8debug.vars.V8Evaluator; import org.netbeans.modules.javascript.v8debug.vars.Variable; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractExpandTooltipAction; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractJSToolTipAnnotation; import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.debugger.ui.EditorContextDispatcher; +import org.netbeans.spi.debugger.ui.AbstractExpandToolTipAction; import org.netbeans.spi.debugger.ui.PinWatchUISupport; import org.openide.util.RequestProcessor; @@ -229,7 +223,7 @@ } } - private class ExpandAction extends AbstractExpandTooltipAction { + private class ExpandAction extends AbstractExpandToolTipAction { private final Variable var; @@ -239,7 +233,10 @@ @Override protected void openTooltipView() { - openTooltipView(new V8DebuggerTooltipSupport(dbg, dbg.getCurrentFrame()), var.getName(), var); + ToolTipSupport tts = openTooltipView(var.getName(), var); + if (tts != null) { + ToolTipAnnotation.handleToolTipClose(dbg, tts); + } } } diff -r 03b2f960a7c3 javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/VariablesModel.java --- a/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/VariablesModel.java Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/models/VariablesModel.java Tue Jun 07 13:52:54 2016 +0200 @@ -76,6 +76,7 @@ import org.netbeans.modules.javascript2.debug.ui.models.ViewModelSupport; import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.spi.debugger.DebuggerServiceRegistration; +import org.netbeans.spi.debugger.DebuggerServiceRegistrations; import org.netbeans.spi.debugger.ui.Constants; import org.netbeans.spi.viewmodel.ExtendedNodeModel; import org.netbeans.spi.viewmodel.ModelEvent; @@ -92,8 +93,12 @@ * * @author Martin Entlicher */ -@DebuggerServiceRegistration(path=V8DebuggerEngineProvider.ENGINE_NAME+"/LocalsView", - types={ TreeModel.class, ExtendedNodeModel.class, TableModel.class }) +@DebuggerServiceRegistrations({ + @DebuggerServiceRegistration(path=V8DebuggerEngineProvider.ENGINE_NAME+"/LocalsView", + types={ TreeModel.class, ExtendedNodeModel.class, TableModel.class }), + @DebuggerServiceRegistration(path=V8DebuggerEngineProvider.ENGINE_NAME+"/ToolTipView", + types={ TreeModel.class, ExtendedNodeModel.class, TableModel.class }) +}) public class VariablesModel extends ViewModelSupport implements TreeModel, ExtendedNodeModel, TableModel, diff -r 03b2f960a7c3 javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/ToolTipAnnotation.java --- a/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/ToolTipAnnotation.java Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/ToolTipAnnotation.java Tue Jun 07 13:52:54 2016 +0200 @@ -43,8 +43,10 @@ package org.netbeans.modules.javascript.v8debug.ui.vars.tooltip; import java.util.concurrent.CancellationException; +import javax.swing.SwingUtilities; import org.netbeans.api.debugger.DebuggerEngine; import org.netbeans.api.debugger.Session; +import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.lib.v8debug.V8Frame; import org.netbeans.lib.v8debug.vars.V8Object; import org.netbeans.lib.v8debug.vars.V8Value; @@ -61,24 +63,61 @@ * * @author Martin Entlicher */ -public class ToolTipAnnotation extends AbstractJSToolTipAnnotation { +public class ToolTipAnnotation extends AbstractJSToolTipAnnotation { @Override - protected V8DebuggerTooltipSupport getEngineDebugger(Session session, DebuggerEngine engine) { + protected void handleToolTipClose(DebuggerEngine engine, final ToolTipSupport tts) { + V8Debugger debugger = engine.lookupFirst(null, V8Debugger.class); + if (debugger == null) { + return ; + } + handleToolTipClose(debugger, tts); + } + + public static void handleToolTipClose(V8Debugger debugger, final ToolTipSupport tts) { + V8Debugger.Listener listener = new V8Debugger.Listener() { + @Override + public void notifySuspended(boolean suspended) { + if (!suspended) { + doClose(); + } + } + + @Override + public void notifyCurrentFrame(CallFrame cf) { + doClose(); + } + + @Override + public void notifyFinished() { + doClose(); + } + + private void doClose() { + SwingUtilities.invokeLater(() -> + tts.setToolTipVisible(false) + ); + } + }; + debugger.addListener(listener); + tts.addPropertyChangeListener(pl -> { + if (ToolTipSupport.PROP_STATUS.equals(pl.getPropertyName()) && + !tts.isToolTipVisible()) { + debugger.removeListener(listener); + } + }); + } + + @Override + protected Pair evaluate(String expression, DebuggerEngine engine) throws CancellationException { + String toolTipText; + Variable var = null; V8Debugger debugger = engine.lookupFirst(null, V8Debugger.class); if (debugger == null || !debugger.isSuspended()) { return null; } - CallFrame currentFrame = debugger.getCurrentFrame(); - return new V8DebuggerTooltipSupport(debugger, currentFrame); - } - - @Override - protected Pair evaluate(String expression, DebuggerEngine engine, V8DebuggerTooltipSupport dbg) throws CancellationException { - String toolTipText; - Variable var = null; try { - V8Value value = V8Evaluator.evaluate(dbg.getDebugger(), expression); + V8Value value = V8Evaluator.evaluate(debugger, expression); if (value == null) { throw new CancellationException(); } diff -r 03b2f960a7c3 javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/ToolTipModel.java --- a/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/ToolTipModel.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2012 Sun Microsystems, Inc. - */ -package org.netbeans.modules.javascript.v8debug.ui.vars.tooltip; - -import org.netbeans.modules.javascript.v8debug.V8DebuggerEngineProvider; -import org.netbeans.modules.javascript.v8debug.ui.vars.models.VariablesModel; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractJSToolTipAnnotation; -import org.netbeans.spi.debugger.ContextProvider; -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.ExtendedNodeModel; -import org.netbeans.spi.viewmodel.TableModel; -import org.netbeans.spi.viewmodel.TreeExpansionModel; -import org.netbeans.spi.viewmodel.TreeExpansionModelFilter; -import org.netbeans.spi.viewmodel.TreeModel; -import org.netbeans.spi.viewmodel.UnknownTypeException; - -/** - * - * @author Martin - */ -@DebuggerServiceRegistration(path=V8DebuggerEngineProvider.ENGINE_NAME+"/ToolTipView", - types={ TreeModel.class, ExtendedNodeModel.class, - TableModel.class, TreeExpansionModelFilter.class }) -public class ToolTipModel extends VariablesModel implements TreeExpansionModelFilter { - - public ToolTipModel(ContextProvider contextProvider) { - super(contextProvider); - } - - @Override - public int getChildrenCount(Object parent) throws UnknownTypeException { - if (parent == ROOT) { - return 1; - } else { - return super.getChildrenCount(parent); - } - } - - @Override - public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException { - if (parent == ROOT) { - Object ttv = AbstractJSToolTipAnnotation.getTooltipVariable(); - if (ttv != null) { - return new Object[] { ttv }; - } else { - return new Object[] { }; - } - } else { - return super.getChildren(parent, from, to); - } - } - - @Override - public boolean isExpanded(TreeExpansionModel original, Object node) throws UnknownTypeException { - if (node == AbstractJSToolTipAnnotation.getTooltipVariable()) { - return true; - } else { - return original.isExpanded(node); - } - } - - @Override - public void nodeExpanded(Object node) {} - - @Override - public void nodeCollapsed(Object node) {} - -} diff -r 03b2f960a7c3 javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/V8DebuggerTooltipSupport.java --- a/javascript.v8debug.ui/src/org/netbeans/modules/javascript/v8debug/ui/vars/tooltip/V8DebuggerTooltipSupport.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2014 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.javascript.v8debug.ui.vars.tooltip; - -import java.io.Closeable; -import java.io.IOException; -import org.netbeans.modules.javascript.v8debug.V8Debugger; -import org.netbeans.modules.javascript.v8debug.frames.CallFrame; -import org.netbeans.modules.javascript2.debug.ui.tooltip.DebuggerTooltipSupport; - -/** - * - * @author Martin Entlicher - */ -public class V8DebuggerTooltipSupport implements DebuggerTooltipSupport { - - private final V8Debugger debugger; - private final CallFrame currentFrame; - private V8Debugger.Listener closeableListener; - - public V8DebuggerTooltipSupport(V8Debugger debugger, CallFrame currentFrame) { - this.debugger = debugger; - this.currentFrame = currentFrame; - } - - public V8Debugger getDebugger() { - return debugger; - } - - public CallFrame getCurrentFrame() { - return currentFrame; - } - - @Override - public void addCloseable(Closeable closeable) { - closeableListener = new TooltipCloseableListener(closeable); - debugger.addListener(closeableListener); - } - - @Override - public void removeCloseable(Closeable closeable) { - debugger.removeListener(closeableListener); - } - - private static final class TooltipCloseableListener implements V8Debugger.Listener { - - private final Closeable closeable; - - public TooltipCloseableListener(Closeable closeable) { - this.closeable = closeable; - } - - @Override - public void notifySuspended(boolean suspended) { - if (!suspended) { - doClose(); - } - } - - @Override - public void notifyCurrentFrame(CallFrame cf) { - doClose(); - } - - @Override - public void notifyFinished() { - doClose(); - } - - private void doClose() { - try { - closeable.close(); - } catch (IOException ex) {} - } - - } - -} diff -r 03b2f960a7c3 javascript2.debug.ui/manifest.mf --- a/javascript2.debug.ui/manifest.mf Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript2.debug.ui/manifest.mf Tue Jun 07 13:52:54 2016 +0200 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.javascript2.debug.ui/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/javascript2/debug/ui/Bundle.properties -OpenIDE-Module-Specification-Version: 1.2 +OpenIDE-Module-Specification-Version: 1.3 AutoUpdate-Show-In-Client: false diff -r 03b2f960a7c3 javascript2.debug.ui/nbproject/project.xml --- a/javascript2.debug.ui/nbproject/project.xml Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript2.debug.ui/nbproject/project.xml Tue Jun 07 13:52:54 2016 +0200 @@ -109,7 +109,7 @@ 1 - 2.13 + 2.54 diff -r 03b2f960a7c3 javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/AbstractExpandTooltipAction.java --- a/javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/AbstractExpandTooltipAction.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2016 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2016 Sun Microsystems, Inc. - */ -package org.netbeans.modules.javascript2.debug.ui.tooltip; - -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JEditorPane; -import javax.swing.UIManager; -import org.netbeans.editor.EditorUI; -import org.netbeans.editor.Utilities; -import org.netbeans.editor.ext.ToolTipSupport; -import org.netbeans.spi.debugger.ui.EditorContextDispatcher; - -/** - * - * @author Martin Entlicher - */ -public abstract class AbstractExpandTooltipAction extends AbstractAction { - - private final Icon toExpandIcon = UIManager.getIcon ("Tree.collapsedIcon"); // NOI18N - private final Icon toCollapsIcon = UIManager.getIcon ("Tree.expandedIcon"); // NOI18N - private boolean expanded; - - protected AbstractExpandTooltipAction() { - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); - } - - protected abstract void openTooltipView(); - - protected final void openTooltipView(DebuggerTooltipSupport dbg, String expression, Object var) { - ToolTipView toolTipView = ToolTipView.createToolTipView(dbg, expression, var); - JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor(); - EditorUI eui = Utilities.getEditorUI(currentEditor); - if (eui != null) { - final ToolTipSupport toolTipSupport = eui.getToolTipSupport(); - toolTipView.setToolTipSupport(toolTipSupport); - toolTipSupport.setToolTipVisible(true, false); - toolTipSupport.setToolTip(toolTipView); - toolTipSupport.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (ToolTipSupport.PROP_STATUS.equals(evt.getPropertyName())) { - if (!toolTipSupport.isToolTipVisible()) { - expanded = false; - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); - toolTipSupport.removePropertyChangeListener(this); - } - } - } - }); - } - - } - - @Override - public final void actionPerformed(ActionEvent e) { - expanded = !expanded; - if (expanded) { - openTooltipView(); - putValue(Action.SMALL_ICON, toCollapsIcon); - putValue(Action.LARGE_ICON_KEY, toCollapsIcon); - } else { - collapse(); - putValue(Action.SMALL_ICON, toExpandIcon); - putValue(Action.LARGE_ICON_KEY, toExpandIcon); - } - } - - private void collapse() { - JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor(); - EditorUI eui = Utilities.getEditorUI(currentEditor); - if (eui != null) { - eui.getToolTipSupport().setToolTipVisible(false, false); - } - } -} diff -r 03b2f960a7c3 javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/AbstractJSToolTipAnnotation.java --- a/javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/AbstractJSToolTipAnnotation.java Thu Jun 02 16:36:56 2016 +0200 +++ b/javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/AbstractJSToolTipAnnotation.java Tue Jun 07 13:52:54 2016 +0200 @@ -42,15 +42,11 @@ package org.netbeans.modules.javascript2.debug.ui.tooltip; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.concurrent.CancellationException; -import javax.swing.BorderFactory; import javax.swing.JEditorPane; import javax.swing.SwingUtilities; import javax.swing.text.BadLocationException; @@ -59,14 +55,12 @@ import org.netbeans.api.debugger.DebuggerEngine; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.debugger.Session; -import org.netbeans.api.debugger.Watch; import org.netbeans.editor.EditorUI; -import org.netbeans.editor.PopupManager; import org.netbeans.editor.Utilities; import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.spi.debugger.ui.EditorContextDispatcher; -import org.netbeans.spi.debugger.ui.EditorPin; -import org.netbeans.spi.debugger.ui.PinWatchUISupport; +import org.netbeans.spi.debugger.ui.ToolTipUI; +import org.netbeans.spi.debugger.ui.ViewFactory; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; @@ -75,7 +69,6 @@ import org.openide.text.DataEditorSupport; import org.openide.text.Line; import org.openide.text.NbDocument; -import org.openide.util.Exceptions; import org.openide.util.Pair; import org.openide.util.RequestProcessor; @@ -83,7 +76,7 @@ * * @author Martin Entlicher */ -public abstract class AbstractJSToolTipAnnotation extends Annotation { +public abstract class AbstractJSToolTipAnnotation extends Annotation { private static final Set JS_KEYWORDS = new HashSet<>(Arrays.asList(new String[] { "break", "case", "catch", "class", "continue", @@ -100,21 +93,6 @@ private static final RequestProcessor RP = new RequestProcessor(AbstractJSToolTipAnnotation.class); - public static Object getTooltipVariable() { - return ToolTipView.getVariable(); - } - - public static void openTooltipView(DebuggerTooltipSupport dbg, String expression, Object var) { - ToolTipView toolTipView = ToolTipView.createToolTipView(dbg, expression, var); - JEditorPane currentEditor = EditorContextDispatcher.getDefault().getMostRecentEditor(); - EditorUI eui = Utilities.getEditorUI(currentEditor); - if (eui != null) { - toolTipView.setToolTipSupport(eui.getToolTipSupport()); - eui.getToolTipSupport().setToolTipVisible(true, false); - eui.getToolTipSupport().setToolTip(toolTipView); - } - } - @Override public String getShortDescription () { final Session session = DebuggerManager.getDebuggerManager ().getCurrentSession(); @@ -125,10 +103,6 @@ if (engine == null) { return null; } - final Debugger dbg = getEngineDebugger(session, engine); - if (dbg == null) { - return null; - } final Line.Part lp = (Line.Part) getAttachedAnnotatable(); if (lp == null) { @@ -149,7 +123,7 @@ @Override public void run() { - evaluate(session, engine, dbg, lp, ec); + evaluate(session, engine/*, dbg*/, lp, ec); } }; RequestProcessor rp = engine.lookupFirst(null, RequestProcessor.class); @@ -161,16 +135,16 @@ return null; } - protected abstract Debugger getEngineDebugger(Session session, DebuggerEngine engine); + protected abstract void handleToolTipClose(DebuggerEngine engine, ToolTipSupport tts); - protected abstract Pair evaluate(String expression, DebuggerEngine engine, Debugger dbg) throws CancellationException; + protected abstract Pair evaluate(String expression, DebuggerEngine engine) throws CancellationException; @Override public String getAnnotationType() { return null; } - private void evaluate(Session session, DebuggerEngine engine, final Debugger dbg, + private void evaluate(Session session, final DebuggerEngine engine, //final Debugger dbg, Line.Part lp, EditorCookie ec) { final Line line = lp.getLine(); if (line == null) { @@ -209,70 +183,34 @@ Pair toolTipTextAndVar; try { - toolTipTextAndVar = evaluate(expression, engine, dbg); + toolTipTextAndVar = evaluate(expression, engine); } catch (CancellationException ex) { return ; } + if (toolTipTextAndVar == null) { + return ; + } final String toolTip = truncateLongText(toolTipTextAndVar.first()); final Object var = toolTipTextAndVar.second(); - final boolean expandable = var != null; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - final ToolTipView.ExpandableTooltip et = ToolTipView.createExpandableTooltip(toolTip, expandable); - if (expandable) { - et.addExpansionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - et.setBorder(BorderFactory.createLineBorder(et.getForeground())); - et.removeAll(); - et.setWidthCheck(false); - final ToolTipView ttView = ToolTipView.createToolTipView(dbg, expression, var); - et.add(ttView); - et.revalidate(); - et.repaint(); - SwingUtilities.invokeLater(new Runnable() { - public @Override void run() { - EditorUI eui = Utilities.getEditorUI(ep); - if (eui != null) { - ttView.setToolTipSupport(eui.getToolTipSupport()); - eui.getToolTipSupport().setToolTip(et, PopupManager.ViewPortBounds, PopupManager.AbovePreferred, 0, 0, ToolTipSupport.FLAGS_HEAVYWEIGHT_TOOLTIP); - } else { - firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); - } - } - }); - } - }); + EditorUI eui = Utilities.getEditorUI(ep); + if (eui == null) { + firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); + return ; } - et.addPinListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - EditorUI eui = Utilities.getEditorUI(ep); - Point location = et.getLocation(); - location = eui.getStickyWindowSupport().convertPoint(location); - eui.getToolTipSupport().setToolTipVisible(false); - DebuggerManager dbMgr = DebuggerManager.getDebuggerManager(); - Watch.Pin pin = new EditorPin(fo, line.getLineNumber(), location); - final Watch w = dbMgr.createPinnedWatch(expression, pin); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - String valueProviderId = "org.netbeans.modules.javascript2.debug.PIN_VALUE_PROVIDER"; // NOI18N - try { - PinWatchUISupport.getDefault().pin(w, valueProviderId); - } catch (IllegalArgumentException ex) { - Exceptions.printStackTrace(ex); - } - } - }); - } - }); - EditorUI eui = Utilities.getEditorUI(ep); - if (eui != null) { - eui.getToolTipSupport().setToolTip(et); - } else { - firePropertyChange (PROP_SHORT_DESCRIPTION, null, toolTip); + ToolTipUI.Expandable expandable = (var != null) ? + new ToolTipUI.Expandable(expression, var) : + null; + ToolTipUI.Pinnable pinnable = new ToolTipUI.Pinnable( + expression, + line.getLineNumber(), + "org.netbeans.modules.javascript2.debug.PIN_VALUE_PROVIDER"); // NOI18N + ToolTipUI toolTipUI = ViewFactory.getDefault().createToolTip(toolTip, expandable, pinnable); + ToolTipSupport tts = toolTipUI.show(ep); + if (tts != null) { + handleToolTipClose(engine, tts); } } }); diff -r 03b2f960a7c3 javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/DebuggerTooltipSupport.java --- a/javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/DebuggerTooltipSupport.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2014 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.javascript2.debug.ui.tooltip; - -import java.io.Closeable; - -/** - * An abstract debugger tool-tip support. - * - * @author Martin Entlicher - */ -public interface DebuggerTooltipSupport { - - /** - * Add a closeable tool-tip. - * The debugger should call it when the tool-tip should close - - * e.g. when debugger resumes or finishes. - * @param closeable To be called to close the tool-tip. - */ - void addCloseable(Closeable closeable); - - /** - * Clean-up the closeable. - * Called when the closeable no longer lives. - * @param closeable - */ - void removeCloseable(Closeable closeable); - -} diff -r 03b2f960a7c3 javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/ToolTipView.java --- a/javascript2.debug.ui/src/org/netbeans/modules/javascript2/debug/ui/tooltip/ToolTipView.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,366 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.modules.javascript2.debug.ui.tooltip; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Insets; -import java.awt.Point; -import java.awt.event.ActionListener; -import java.io.Closeable; -import java.io.IOException; -import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.Keymap; -import org.netbeans.editor.ext.ToolTipSupport; -import org.netbeans.spi.debugger.ui.ViewFactory; -import org.openide.util.ImageUtilities; - -// -// Implement HelpCtx.Provider interface to provide help ids for help system -// public class CallStackView extends TopComponent { -// ==== -final class ToolTipView extends JComponent implements org.openide.util.HelpCtx.Provider { -// - - public static final String TOOLTIP_VIEW_NAME = "ToolTipView"; - - private static volatile String expression; - private static volatile Object variable; - - private transient JComponent contentComponent; - private final DebuggerTooltipSupport dbgts; - private final DebuggerStateChangeListener debuggerStateChangeListener; - private ToolTipSupport toolTipSupport; - private String name; // Store just the name persistently, we'll create the component from that - - private ToolTipView(DebuggerTooltipSupport dbgts, String expression, Object v, String icon) { - this.dbgts = dbgts; - ToolTipView.expression = expression; - variable = v; - this.name = TOOLTIP_VIEW_NAME; - JComponent c = ViewFactory.getDefault().createViewComponent( - icon, - ToolTipView.TOOLTIP_VIEW_NAME, - "NetbeansDebuggerJSToolTipNode", - null); - setLayout (new BorderLayout ()); - add (c, BorderLayout.CENTER); //NOI18N - debuggerStateChangeListener = new DebuggerStateChangeListener(); - dbgts.addCloseable(debuggerStateChangeListener); - } - - static String getExpression() { - return expression; - } - - static Object getVariable() { - return variable; - } - - void setToolTipSupport(ToolTipSupport toolTipSupport) { - this.toolTipSupport = toolTipSupport; - } - - private void closeToolTip() { - if (!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - toolTipSupport.setToolTipVisible(false); - } - }); - } else { - toolTipSupport.setToolTipVisible(false); - } - } - - //protected void componentHidden () { - @Override - public void removeNotify() { - super.removeNotify();//componentHidden (); - variable = null; - dbgts.removeCloseable(debuggerStateChangeListener); - } - - // - // Implement getHelpCtx() with the correct help ID - @Override - public org.openide.util.HelpCtx getHelpCtx() { - return new org.openide.util.HelpCtx("NetbeansDebuggerJSToolTipNode"); - } - // - - @Override - public boolean requestFocusInWindow () { - super.requestFocusInWindow (); - if (contentComponent == null) return false; - return contentComponent.requestFocusInWindow (); - } - - /* - public void requestActive() { - super.requestActive(); - if (contentComponent != null) { - contentComponent.requestFocusInWindow (); - } - } - */ - - /* - public String getName () { - return NbBundle.getMessage (ToolTipView.class, displayNameResource); - } - - public String getToolTipText () { - return NbBundle.getMessage (ToolTipView.class, toolTipResource);// NOI18N - } - */ - - - /** Creates the view. */ - public static synchronized ToolTipView createToolTipView(DebuggerTooltipSupport dbg, String expression, Object variable) { - return new ToolTipView( - dbg, - expression, - variable, - "org/netbeans/modules/debugger/resources/localsView/local_variable_16.png" - ); - } - - - static ExpandableTooltip createExpandableTooltip(String toolTipText, boolean expandable) { - return new ExpandableTooltip(toolTipText, expandable); - } - - static class ExpandableTooltip extends JPanel { - - private static final String UI_PREFIX = "ToolTip"; // NOI18N - - private JButton expButton; - private JButton pinButton; - private JComponent textToolTip; - private boolean widthCheck = true; - private boolean sizeSet = false; - - public ExpandableTooltip(String toolTipText, boolean expandable) { - Font font = UIManager.getFont(UI_PREFIX + ".font"); // NOI18N - Color backColor = UIManager.getColor(UI_PREFIX + ".background"); // NOI18N - Color foreColor = UIManager.getColor(UI_PREFIX + ".foreground"); // NOI18N - - if (backColor != null) { - setBackground(backColor); - } - setOpaque(true); - setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(getForeground()), - BorderFactory.createEmptyBorder(0, 3, 0, 3) - )); - - setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); - pinButton = new JButton(ImageUtilities.loadImageIcon("org/netbeans/editor/resources/pin.png", false)); - pinButton.setBorder(new javax.swing.border.EmptyBorder(0, 3, 0, 0)); - pinButton.setBorderPainted(false); - pinButton.setContentAreaFilled(false); - add(pinButton); - if (expandable) { - Icon expIcon = UIManager.getIcon ("Tree.collapsedIcon"); // NOI18N - expButton = new JButton(expIcon); - expButton.setBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 5)); - expButton.setBorderPainted(false); - expButton.setContentAreaFilled(false); - add(expButton); - } - //JLabel l = new JLabel(toolTipText); - // Multi-line tooltip: - JTextArea l = createMultiLineToolTip(toolTipText, true); - if (font != null) { - l.setFont(font); - } - if (foreColor != null) { - l.setForeground(foreColor); - } - if (backColor != null) { - l.setBackground(backColor); - } - textToolTip = l; - add(l); - } - - void addExpansionListener(ActionListener treeExpansionListener) { - expButton.addActionListener(treeExpansionListener); - } - - void addPinListener(ActionListener treeExpansionListener) { - pinButton.addActionListener(treeExpansionListener); - } - - void setWidthCheck(boolean widthCheck) { - this.widthCheck = widthCheck; - } - - @Override - public Dimension getPreferredSize() { - if (!sizeSet) { - // Be big enough initially. - return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); - } - return super.getPreferredSize(); - } - - @Override - public void setSize(int width, int height) { - Dimension prefSize = getPreferredSize(); - Dimension button1Size = (expButton != null) ? expButton.getPreferredSize() : new Dimension(0, 0); - Dimension button2Size = pinButton.getPreferredSize(); - if (widthCheck) { - Insets insets = getInsets(); - int textWidth = width - insets.left - button1Size.width - button2Size.width - insets.right; - height = Math.max(Math.max(height, button1Size.height), button2Size.height); - textToolTip.setSize(textWidth, height); - Dimension textPreferredSize = textToolTip.getPreferredSize(); - super.setSize( - insets.left + button1Size.width + button2Size.width + textPreferredSize.width + insets.right, - insets.top + Math.max(Math.max(button1Size.height, textPreferredSize.height), button2Size.height) + insets.bottom); - } else { - if (height >= prefSize.height) { // enough height - height = prefSize.height; - } - super.setSize(width, height); - } - sizeSet = true; - } - - private static JTextArea createMultiLineToolTip(String toolTipText, boolean wrapLines) { - JTextArea ta = new TextToolTip(wrapLines); - ta.setText(toolTipText); - return ta; - } - - private static class TextToolTip extends JTextArea { - - private static final String ELIPSIS = "..."; //NOI18N - - private final boolean wrapLines; - - public TextToolTip(boolean wrapLines) { - this.wrapLines = wrapLines; - setLineWrap(false); // It's necessary to have a big width of preferred size first. - } - - public @Override void setSize(int width, int height) { - Dimension prefSize = getPreferredSize(); - if (width >= prefSize.width) { - width = prefSize.width; - } else { // smaller available width - // Set line wrapping and do super.setSize() to determine - // the real height (it will change due to line wrapping) - if (wrapLines) { - setLineWrap(true); - setWrapStyleWord(true); - } - - super.setSize(width, Integer.MAX_VALUE); // the height is unimportant - prefSize = getPreferredSize(); // re-read new pref width - } - if (height >= prefSize.height) { // enough height - height = prefSize.height; - } else { // smaller available height - // Check how much can be displayed - cannot rely on line count - // because line wrapping may display single physical line - // into several visual lines - // Before using viewToModel() a setSize() must be called - // because otherwise the viewToModel() would return -1. - super.setSize(width, Integer.MAX_VALUE); - int offset = viewToModel(new Point(0, height)); - Document doc = getDocument(); - try { - if (offset > ELIPSIS.length()) { - offset -= ELIPSIS.length(); - doc.remove(offset, doc.getLength() - offset); - doc.insertString(offset, ELIPSIS, null); - } - } catch (BadLocationException ble) { - // "..." will likely not be displayed but otherwise should be ok - } - // Recalculate the prefSize as it may be smaller - // than the present preferred height - height = Math.min(height, getPreferredSize().height); - } - super.setSize(width, height); - } - - @Override - public void setKeymap(Keymap map) { - //#181722: keymaps are shared among components with the same UI - //a default action will be set to the Keymap of this component below, - //so it is necessary to use a Keymap that is not shared with other JTextAreas - super.setKeymap(addKeymap(null, map)); - } - } - } - - private class DebuggerStateChangeListener implements Closeable { - - @Override - public void close() { - closeToolTip(); - } - - } - -} diff -r 03b2f960a7c3 web.javascript.debugger/nbproject/project.xml --- a/web.javascript.debugger/nbproject/project.xml Thu Jun 02 16:36:56 2016 +0200 +++ b/web.javascript.debugger/nbproject/project.xml Tue Jun 07 13:52:54 2016 +0200 @@ -74,7 +74,7 @@ 1 - 1.2 + 1.3 @@ -160,7 +160,7 @@ 1 - 2.49 + 2.54 diff -r 03b2f960a7c3 web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/PinWatchValueProvider.java --- a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/PinWatchValueProvider.java Thu Jun 02 16:36:56 2016 +0200 +++ b/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/PinWatchValueProvider.java Tue Jun 07 13:52:54 2016 +0200 @@ -41,17 +41,12 @@ */ package org.netbeans.modules.web.javascript.debugger.annotation; -import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.UIManager; import org.netbeans.api.debugger.Watch; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractExpandTooltipAction; -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractJSToolTipAnnotation; +import org.netbeans.editor.ext.ToolTipSupport; import org.netbeans.modules.web.javascript.debugger.eval.Evaluator; import org.netbeans.modules.web.javascript.debugger.locals.VariablesModel; import org.netbeans.modules.web.webkit.debugging.api.Debugger; @@ -60,6 +55,7 @@ import org.netbeans.modules.web.webkit.debugging.api.debugger.RemoteObject.Type; import org.netbeans.spi.debugger.ContextProvider; import org.netbeans.spi.debugger.DebuggerServiceRegistration; +import org.netbeans.spi.debugger.ui.AbstractExpandToolTipAction; import org.netbeans.spi.debugger.ui.PinWatchUISupport; import org.openide.util.RequestProcessor; @@ -233,7 +229,7 @@ } } - private class ExpandAction extends AbstractExpandTooltipAction { + private class ExpandAction extends AbstractExpandToolTipAction { private final VariablesModel.ScopedRemoteObject sr; private final String expression; @@ -245,9 +241,10 @@ @Override protected void openTooltipView() { - openTooltipView( - new WebJSDebuggerTooltipSupport(dbg, dbg.getCurrentCallFrame()), - expression, sr); + ToolTipSupport tts = openTooltipView(expression, sr); + if (tts != null) { + ToolTipAnnotation.handleToolTipClose(dbg, tts); + } } } diff -r 03b2f960a7c3 web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/ToolTipAnnotation.java --- a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/ToolTipAnnotation.java Thu Jun 02 16:36:56 2016 +0200 +++ b/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/ToolTipAnnotation.java Tue Jun 07 13:52:54 2016 +0200 @@ -96,22 +96,61 @@ "# {0} - variable name", "var.undefined={0} is not defined" }) -public class ToolTipAnnotation extends AbstractJSToolTipAnnotation +public class ToolTipAnnotation extends AbstractJSToolTipAnnotation { @Override - protected WebJSDebuggerTooltipSupport getEngineDebugger(Session session, DebuggerEngine engine) { + protected void handleToolTipClose(DebuggerEngine engine, ToolTipSupport tts) { + Debugger d = engine.lookupFirst(null, Debugger.class); + if (d == null || !d.isSuspended()) { + return ; + } + handleToolTipClose(d, tts); + } + + static void handleToolTipClose(Debugger d, final ToolTipSupport tts) { + Debugger.Listener dl = new Debugger.Listener() { + @Override + public void paused(List callStack, String reason) {} + + @Override + public void resumed() { + doClose(); + } + + @Override + public void reset() { + doClose(); + } + + @Override + public void enabled(boolean enabled) { + if (!enabled) { + doClose(); + } + } + + private void doClose() { + tts.setToolTipVisible(false); + } + }; + d.addListener(dl); + tts.addPropertyChangeListener(pl -> { + if (ToolTipSupport.PROP_STATUS.equals(pl.getPropertyName()) && + !tts.isToolTipVisible()) { + d.removeListener(dl); + } + }); + } + + @Override + protected Pair evaluate(String expression, DebuggerEngine engine) throws CancellationException { Debugger d = engine.lookupFirst(null, Debugger.class); if (d == null || !d.isSuspended()) { return null; } CallFrame currentCallFrame = d.getCurrentCallFrame(); - return new WebJSDebuggerTooltipSupport(d, currentCallFrame); - } - - @Override - protected Pair evaluate(String expression, DebuggerEngine engine, WebJSDebuggerTooltipSupport dbg) throws CancellationException { - VariablesModel.ScopedRemoteObject sv = Evaluator.evaluateExpression(dbg.getFrame(), expression, true); + VariablesModel.ScopedRemoteObject sv = Evaluator.evaluateExpression(currentCallFrame, expression, true); Object tooltipVariable = null; String tooltipText; if (sv != null) { diff -r 03b2f960a7c3 web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/ToolTipModel.java --- a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/ToolTipModel.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2012 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2012 Sun Microsystems, Inc. - */ -package org.netbeans.modules.web.javascript.debugger.annotation; - -import org.netbeans.modules.javascript2.debug.ui.tooltip.AbstractJSToolTipAnnotation; -import org.netbeans.modules.web.javascript.debugger.locals.VariablesModel; -import org.netbeans.spi.debugger.ContextProvider; -import org.netbeans.spi.debugger.DebuggerServiceRegistration; -import org.netbeans.spi.viewmodel.ExtendedNodeModel; -import org.netbeans.spi.viewmodel.TableModel; -import org.netbeans.spi.viewmodel.TreeExpansionModel; -import org.netbeans.spi.viewmodel.TreeExpansionModelFilter; -import org.netbeans.spi.viewmodel.TreeModel; -import org.netbeans.spi.viewmodel.UnknownTypeException; - -/** - * - * @author Martin - */ -@DebuggerServiceRegistration(path="javascript-debuggerengine/ToolTipView", types={ TreeModel.class, ExtendedNodeModel.class, TableModel.class, TreeExpansionModelFilter.class }) -public class ToolTipModel extends VariablesModel implements TreeExpansionModelFilter { - - public ToolTipModel(ContextProvider contextProvider) { - super(contextProvider); - } - - @Override - public int getChildrenCount(Object parent) throws UnknownTypeException { - if (parent == ROOT) { - return 1; - } else { - return super.getChildrenCount(parent); - } - } - - @Override - public Object[] getChildren(Object parent, int from, int to) throws UnknownTypeException { - if (parent == ROOT) { - Object ttv = AbstractJSToolTipAnnotation.getTooltipVariable(); - if (ttv != null) { - return new Object[] { ttv }; - } else { - return new Object[] { }; - } - } else { - return super.getChildren(parent, from, to); - } - } - - @Override - public boolean isExpanded(TreeExpansionModel original, Object node) throws UnknownTypeException { - if (node == AbstractJSToolTipAnnotation.getTooltipVariable()) { - return true; - } else { - return original.isExpanded(node); - } - } - - @Override - public void nodeExpanded(Object node) {} - - @Override - public void nodeCollapsed(Object node) {} - -} diff -r 03b2f960a7c3 web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/WebJSDebuggerTooltipSupport.java --- a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/annotation/WebJSDebuggerTooltipSupport.java Thu Jun 02 16:36:56 2016 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2014 Oracle and/or its affiliates. All rights reserved. - * - * Oracle and Java are registered trademarks of Oracle and/or its affiliates. - * Other names may be trademarks of their respective owners. - * - * 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle 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 2014 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.web.javascript.debugger.annotation; - -import java.io.Closeable; -import java.io.IOException; -import java.util.List; -import org.netbeans.modules.javascript2.debug.ui.tooltip.DebuggerTooltipSupport; -import org.netbeans.modules.web.webkit.debugging.api.Debugger; -import org.netbeans.modules.web.webkit.debugging.api.debugger.CallFrame; -import org.openide.util.Exceptions; - -/** - * - * @author Martin Entlicher - */ -public class WebJSDebuggerTooltipSupport implements DebuggerTooltipSupport { - - private final Debugger debugger; - private final CallFrame frame; - private Debugger.Listener closeableListener; - - public WebJSDebuggerTooltipSupport(Debugger debugger, CallFrame frame) { - this.debugger = debugger; - this.frame = frame; - } - - public Debugger getDebugger() { - return debugger; - } - - public CallFrame getFrame() { - return frame; - } - - @Override - public void addCloseable(final Closeable closeable) { - closeableListener = new CloseableDebuggerListener(closeable); - debugger.addListener(closeableListener); - } - - @Override - public void removeCloseable(Closeable closeable) { - debugger.removeListener(closeableListener); - } - - private static class CloseableDebuggerListener implements Debugger.Listener { - - private final Closeable closeable; - - public CloseableDebuggerListener(Closeable closeable) { - this.closeable = closeable; - } - - @Override - public void paused(List callStack, String reason) {} - - @Override - public void resumed() { - doClose(); - } - - @Override - public void reset() { - doClose(); - } - - @Override - public void enabled(boolean enabled) { - if (!enabled) { - doClose(); - } - } - - private void doClose() { - try { - closeable.close(); - } catch (IOException ex) {} - } - - } - -}