# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\hg\core-main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: o.n.core/test/unit/src/org/netbeans/core/HtmlBrowserComponentTest.java --- o.n.core/test/unit/src/org/netbeans/core/HtmlBrowserComponentTest.java Base (BASE) +++ o.n.core/test/unit/src/org/netbeans/core/HtmlBrowserComponentTest.java Locally New @@ -0,0 +1,188 @@ +/* + * 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.core; + +import java.awt.Component; +import java.awt.Image; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.ObjectInput; +import java.net.URL; +import javax.swing.JComponent; +import javax.swing.JPanel; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import org.openide.awt.HtmlBrowser; +import org.openide.awt.HtmlBrowser.Factory; +import org.openide.awt.HtmlBrowser.Impl; +import org.openide.util.HelpCtx; +import org.openide.util.Lookup; +import org.openide.util.lookup.Lookups; +import org.openide.windows.CloneableTopComponent; + +/** + * + * @author stan + */ +public class HtmlBrowserComponentTest { + + public HtmlBrowserComponentTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void testLookup() { + System.out.println( "getLookup" ); + //The content of HtmlBrowser.Impl lookup must appear in browser TopComponent lookup + HtmlBrowser.Factory factory = new HtmlBrowser.Factory() { + @Override + public Impl createHtmlBrowserImpl() { + return new TestBrowserImpl(); + } + }; + HtmlBrowserComponent browser = new HtmlBrowserComponent( factory, false, false); + browser.open(); + assertSame( TestBrowserImpl.lookupContent, browser.getLookup().lookup( TestLookupContent.class ) ); + } + + private static class TestLookupContent { + + } + + private static class TestBrowserImpl extends HtmlBrowser.Impl { + + private final JComponent theComponent = new JPanel(); + private final static TestLookupContent lookupContent = new TestLookupContent(); + private final Lookup lookup = Lookups.singleton( lookupContent ); + + @Override + public Component getComponent() { + return theComponent; + } + + @Override + public void reloadDocument() { + } + + @Override + public void stopLoading() { + } + + @Override + public void setURL( URL url ) { + } + + @Override + public URL getURL() { + return null; + } + + @Override + public String getStatusMessage() { + return null; + } + + @Override + public String getTitle() { + return null; + } + + @Override + public boolean isForward() { + return false; + } + + @Override + public void forward() { + } + + @Override + public boolean isBackward() { + return false; + } + + @Override + public void backward() { + } + + @Override + public boolean isHistory() { + return false; + } + + @Override + public void showHistory() { + } + + @Override + public void addPropertyChangeListener( PropertyChangeListener l ) { + } + + @Override + public void removePropertyChangeListener( PropertyChangeListener l ) { + } + + @Override + public Lookup getLookup() { + return lookup; + } + }; +} Index: openide.awt/apichanges.xml --- openide.awt/apichanges.xml Base (BASE) +++ openide.awt/apichanges.xml Locally Modified (Based On LOCAL) @@ -50,6 +50,20 @@ AWT API + + + Minor API extensions to allow better integration of embedded browsers. + + + + + + Internal web browser can now contain an additional toolbar component: HtmlBrowser(Factory, boolean, boolean, Component) + Browser implementation can pass arbitrary data to Web browser window's Lookup: HtmlBrowser.Impl.getLookup() + + + + ToolbarWithOverflow class that adds an overflow button when the toolbar becomes too small to show all the available actions. Index: openide.awt/manifest.mf --- openide.awt/manifest.mf Base (BASE) +++ openide.awt/manifest.mf Locally Modified (Based On LOCAL) @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.awt OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 7.51 +OpenIDE-Module-Specification-Version: 7.52 Index: openide.awt/src/org/openide/awt/HtmlBrowser.java --- openide.awt/src/org/openide/awt/HtmlBrowser.java Base (BASE) +++ openide.awt/src/org/openide/awt/HtmlBrowser.java Locally Modified (Based On LOCAL) @@ -44,12 +44,7 @@ package org.openide.awt; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Desktop; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -62,21 +57,8 @@ import java.util.logging.Logger; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; -import javax.swing.WindowConstants; -import org.openide.util.Exceptions; -import org.openide.util.ImageUtilities; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.RequestProcessor; +import javax.swing.*; +import org.openide.util.*; /** * Object that provides viewer for HTML pages. @@ -113,8 +95,8 @@ /** currently used implementation of browser */ final Impl browserImpl; - /** true = do not listen on changes of URL on cbLocation */ - private boolean everythinkIListenInCheckBoxIsUnimportant = false; + /** true = ignore changes in location field */ + private boolean ignoreChangeInLocationField = false; /** toolbar visible property */ private boolean toolbarVisible = false; @@ -144,6 +126,7 @@ final Component browserComponent; private JPanel head; private RequestProcessor rp = new RequestProcessor(); + private final Component extraToolbar; // init ...................................................................... @@ -173,6 +156,21 @@ * @param statusLine visibility of statusLine */ public HtmlBrowser(Factory fact, boolean toolbar, boolean statusLine) { + this( fact, toolbar, statusLine, null ); + } + + /** + * Creates new html browser. + * + * @param fact Factory that is used for creation. If null is passed it searches for + * a factory providing displayable component. + * @param toolbar visibility of toolbar + * @param statusLine visibility of statusLine + * @param extraToolbar Additional toolbar to be displayed under the default + * toolbar with location field and back/forward buttons. + * @since 7.52 + */ + public HtmlBrowser(Factory fact, boolean toolbar, boolean statusLine, Component extraToolbar) { Impl impl = null; Component comp = null; @@ -201,6 +199,7 @@ browserImpl = impl; browserComponent = comp; + this.extraToolbar = extraToolbar; setLayout(new BorderLayout(0, 2)); @@ -373,8 +372,11 @@ head.add(txtLocation, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,4), 0, 0)); head.add(bReload, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,0,0,4), 0, 0)); head.add(bStop, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0,0,0,0), 0, 0)); + if( null != extraToolbar ) { + head.add(extraToolbar, new GridBagConstraints(0, 1, 5, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3,0,0,0), 0, 0)); + } - head.setBorder( BorderFactory.createEmptyBorder(8, 10, 8, 10)); + head.setBorder( BorderFactory.createEmptyBorder(8, 10, null == extraToolbar ? 8 : 3, 10)); if (browserImpl != null) { bBack.setEnabled(browserImpl.isBackward()); @@ -461,6 +463,7 @@ class URLSetter implements Runnable { private boolean sameHosts = false; + @Override public void run() { if (!SwingUtilities.isEventDispatchThread()) { if ("nbfs".equals(url.getProtocol())) { // NOI18N @@ -592,13 +595,13 @@ */ private void updateLocationBar() { if (toolbarVisible) { - everythinkIListenInCheckBoxIsUnimportant = true; + ignoreChangeInLocationField = true; String url = browserImpl.getLocation(); txtLocation.setText(url); - everythinkIListenInCheckBoxIsUnimportant = false; + ignoreChangeInLocationField = false; } } @@ -673,6 +676,7 @@ /** * Listens on changes in HtmlBrowser.Impl. */ + @Override public void propertyChange(PropertyChangeEvent evt) { String property = evt.getPropertyName(); @@ -700,16 +704,19 @@ bForward.setEnabled(browserImpl.isForward()); } else if (property.equals(Impl.PROP_BACKWARD) && (bBack != null)) { bBack.setEnabled(browserImpl.isBackward()); + } else if (property.equals(Impl.PROP_LOADING) && (bStop != null)) { + bStop.setEnabled(((Boolean)evt.getNewValue()).booleanValue()); } } /** * Listens on changes in HtmlBrowser visual components. */ + @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == txtLocation) { // URL manually changed - if (everythinkIListenInCheckBoxIsUnimportant) { + if (ignoreChangeInLocationField) { return; } @@ -764,7 +771,17 @@ /** history property name */ public static final String PROP_HISTORY = "history"; // NOI18N + public static final String PROP_BROWSER_WAS_CLOSED = "browser.was.closed"; // NOI18N + /** + * Name of boolean property which is fired when the browser is busy loading + * its content. + * + * @since 7.52 + */ + public static final String PROP_LOADING = "loading"; //NOI18N + + /** * Returns visual component of html browser. * * @return visual component of html browser. @@ -895,7 +912,16 @@ */ public void dispose() { } + + /** + * The content of this Lookup will be merged into browser's TopComponent Lookup. + * @return Browser's Lookup + * @since 7.52 + */ + public Lookup getLookup() { + return Lookup.EMPTY; } + } /** A manager class which can display URLs in the proper way. * Might open a selected HTML browser, knows about embedded vs. external @@ -954,6 +980,7 @@ public TrivialURLDisplayer() { } + @Override public void showURL(URL u) { if (Desktop.isDesktopSupported()) { Desktop d = Desktop.getDesktop();