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

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

(-)o.n.core/test/unit/src/org/netbeans/core/HtmlBrowserComponentTest.java (+188 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core;
43
44
import java.awt.Component;
45
import java.awt.Image;
46
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
48
import java.io.ObjectInput;
49
import java.net.URL;
50
import javax.swing.JComponent;
51
import javax.swing.JPanel;
52
import org.junit.After;
53
import org.junit.AfterClass;
54
import org.junit.Before;
55
import org.junit.BeforeClass;
56
import org.junit.Test;
57
import static org.junit.Assert.*;
58
import org.openide.awt.HtmlBrowser;
59
import org.openide.awt.HtmlBrowser.Factory;
60
import org.openide.awt.HtmlBrowser.Impl;
61
import org.openide.util.HelpCtx;
62
import org.openide.util.Lookup;
63
import org.openide.util.lookup.Lookups;
64
import org.openide.windows.CloneableTopComponent;
65
66
/**
67
 *
68
 * @author stan
69
 */
70
public class HtmlBrowserComponentTest {
71
72
    public HtmlBrowserComponentTest() {
73
    }
74
75
    @BeforeClass
76
    public static void setUpClass() {
77
    }
78
79
    @AfterClass
80
    public static void tearDownClass() {
81
    }
82
83
    @Before
84
    public void setUp() {
85
    }
86
87
    @After
88
    public void tearDown() {
89
    }
90
91
    @Test
92
    public void testLookup() {
93
        System.out.println( "getLookup" );
94
        //The content of HtmlBrowser.Impl lookup must appear in browser TopComponent lookup
95
        HtmlBrowser.Factory factory = new HtmlBrowser.Factory() {
96
            @Override
97
            public Impl createHtmlBrowserImpl() {
98
                return new TestBrowserImpl();
99
            }
100
        };
101
        HtmlBrowserComponent browser = new HtmlBrowserComponent( factory, false, false);
102
        browser.open();
103
        assertSame( TestBrowserImpl.lookupContent, browser.getLookup().lookup( TestLookupContent.class ) );
104
    }
105
106
    private static class TestLookupContent {
107
108
    }
109
110
    private static class TestBrowserImpl extends HtmlBrowser.Impl {
111
112
        private final JComponent theComponent = new JPanel();
113
        private final static TestLookupContent lookupContent = new TestLookupContent();
114
        private final Lookup lookup = Lookups.singleton( lookupContent );
115
116
        @Override
117
        public Component getComponent() {
118
            return theComponent;
119
        }
120
121
        @Override
122
        public void reloadDocument() {
123
        }
124
125
        @Override
126
        public void stopLoading() {
127
        }
128
129
        @Override
130
        public void setURL( URL url ) {
131
        }
132
133
        @Override
134
        public URL getURL() {
135
            return null;
136
        }
137
138
        @Override
139
        public String getStatusMessage() {
140
            return null;
141
        }
142
143
        @Override
144
        public String getTitle() {
145
            return null;
146
        }
147
148
        @Override
149
        public boolean isForward() {
150
            return false;
151
        }
152
153
        @Override
154
        public void forward() {
155
        }
156
157
        @Override
158
        public boolean isBackward() {
159
            return false;
160
        }
161
162
        @Override
163
        public void backward() {
164
        }
165
166
        @Override
167
        public boolean isHistory() {
168
            return false;
169
        }
170
171
        @Override
172
        public void showHistory() {
173
        }
174
175
        @Override
176
        public void addPropertyChangeListener( PropertyChangeListener l ) {
177
        }
178
179
        @Override
180
        public void removePropertyChangeListener( PropertyChangeListener l ) {
181
        }
182
183
        @Override
184
        public Lookup getLookup() {
185
            return lookup;
186
        }
187
    };
188
}
(-)openide.awt/apichanges.xml (+14 lines)
Lines 50-55 Link Here
50
<apidef name="awt">AWT API</apidef>
50
<apidef name="awt">AWT API</apidef>
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
    <change id="BrowserExtensions">
54
      <api name="awt"/>
55
      <summary>Minor API extensions to allow better integration of embedded browsers.</summary>
56
      <version major="7" minor="52"/>
57
      <date day="21" month="8" year="2012"/>
58
      <author login="saubrecht"/>
59
      <compatibility addition="yes" binary="compatible" source="compatible" deprecation="no" semantic="compatible" modification="no" deletion="no"/>
60
      <description>
61
          Internal web browser can now contain an additional toolbar component: HtmlBrowser(Factory, boolean, boolean, Component)
62
          Browser implementation can pass arbitrary data to Web browser window's Lookup: HtmlBrowser.Impl.getLookup()
63
      </description>
64
      <class package="org.openide.awt" name="HtmlBrowser"/>
65
      <issue number="217171"/>
66
    </change>
53
    <change id="ToolbarWithOverflow">
67
    <change id="ToolbarWithOverflow">
54
      <api name="awt"/>
68
      <api name="awt"/>
55
      <summary>ToolbarWithOverflow class that adds an overflow button when the toolbar becomes too small to show all the available actions.</summary>
69
      <summary>ToolbarWithOverflow class that adds an overflow button when the toolbar becomes too small to show all the available actions.</summary>
(-)openide.awt/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.awt
2
OpenIDE-Module: org.openide.awt
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/awt/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.51
5
OpenIDE-Module-Specification-Version: 7.52
6
6
(-)openide.awt/src/org/openide/awt/HtmlBrowser.java (-27 / +54 lines)
Lines 44-55 Link Here
44
44
45
package org.openide.awt;
45
package org.openide.awt;
46
46
47
import java.awt.BorderLayout;
47
import java.awt.*;
48
import java.awt.Component;
49
import java.awt.Desktop;
50
import java.awt.GridBagConstraints;
51
import java.awt.GridBagLayout;
52
import java.awt.Insets;
53
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
49
import java.awt.event.ActionListener;
55
import java.awt.event.MouseAdapter;
50
import java.awt.event.MouseAdapter;
Lines 62-82 Link Here
62
import java.util.logging.Logger;
57
import java.util.logging.Logger;
63
import javax.accessibility.Accessible;
58
import javax.accessibility.Accessible;
64
import javax.accessibility.AccessibleContext;
59
import javax.accessibility.AccessibleContext;
65
import javax.swing.BorderFactory;
60
import javax.swing.*;
66
import javax.swing.JButton;
61
import org.openide.util.*;
67
import javax.swing.JComponent;
68
import javax.swing.JFrame;
69
import javax.swing.JLabel;
70
import javax.swing.JPanel;
71
import javax.swing.JScrollPane;
72
import javax.swing.JTextField;
73
import javax.swing.SwingUtilities;
74
import javax.swing.WindowConstants;
75
import org.openide.util.Exceptions;
76
import org.openide.util.ImageUtilities;
77
import org.openide.util.Lookup;
78
import org.openide.util.NbBundle;
79
import org.openide.util.RequestProcessor;
80
62
81
/**
63
/**
82
* Object that provides viewer for HTML pages.
64
* Object that provides viewer for HTML pages.
Lines 113-120 Link Here
113
    /** currently used implementation of browser */
95
    /** currently used implementation of browser */
114
    final Impl browserImpl;
96
    final Impl browserImpl;
115
97
116
    /** true = do not listen on changes of URL on cbLocation */
98
    /** true = ignore changes in location field */
117
    private boolean everythinkIListenInCheckBoxIsUnimportant = false;
99
    private boolean ignoreChangeInLocationField = false;
118
100
119
    /** toolbar visible property */
101
    /** toolbar visible property */
120
    private boolean toolbarVisible = false;
102
    private boolean toolbarVisible = false;
Lines 144-149 Link Here
144
    final Component browserComponent;
126
    final Component browserComponent;
145
    private JPanel head;
127
    private JPanel head;
146
    private RequestProcessor rp = new RequestProcessor();
128
    private RequestProcessor rp = new RequestProcessor();
129
    private final Component extraToolbar;
147
130
148
    // init ......................................................................
131
    // init ......................................................................
149
132
Lines 173-178 Link Here
173
     * @param statusLine visibility of statusLine
156
     * @param statusLine visibility of statusLine
174
    */
157
    */
175
    public HtmlBrowser(Factory fact, boolean toolbar, boolean statusLine) {
158
    public HtmlBrowser(Factory fact, boolean toolbar, boolean statusLine) {
159
        this( fact, toolbar, statusLine, null );
160
    }
161
162
    /**
163
    * Creates new html browser.
164
     *
165
     * @param fact Factory that is used for creation. If null is passed it searches for
166
     *             a factory providing displayable component.
167
     * @param toolbar visibility of toolbar
168
     * @param statusLine visibility of statusLine
169
     * @param extraToolbar Additional toolbar to be displayed under the default
170
     * toolbar with location field and back/forward buttons.
171
     * @since 7.52
172
    */
173
    public HtmlBrowser(Factory fact, boolean toolbar, boolean statusLine, Component extraToolbar) {
176
        Impl impl = null;
174
        Impl impl = null;
177
        Component comp = null;
175
        Component comp = null;
178
176
Lines 201-206 Link Here
201
199
202
        browserImpl = impl;
200
        browserImpl = impl;
203
        browserComponent = comp;
201
        browserComponent = comp;
202
        this.extraToolbar = extraToolbar;
204
203
205
        setLayout(new BorderLayout(0, 2));
204
        setLayout(new BorderLayout(0, 2));
206
205
Lines 373-380 Link Here
373
        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));
372
        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));
374
        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));
373
        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));
375
        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));
374
        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));
375
        if( null != extraToolbar ) {
376
            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));
377
        }
376
378
377
        head.setBorder( BorderFactory.createEmptyBorder(8, 10, 8, 10));
379
        head.setBorder( BorderFactory.createEmptyBorder(8, 10, null == extraToolbar ? 8 : 3, 10));
378
380
379
        if (browserImpl != null) {
381
        if (browserImpl != null) {
380
            bBack.setEnabled(browserImpl.isBackward());
382
            bBack.setEnabled(browserImpl.isBackward());
Lines 461-466 Link Here
461
        class URLSetter implements Runnable {
463
        class URLSetter implements Runnable {
462
            private boolean sameHosts = false;
464
            private boolean sameHosts = false;
463
465
466
            @Override
464
            public void run() {
467
            public void run() {
465
                if (!SwingUtilities.isEventDispatchThread()) {
468
                if (!SwingUtilities.isEventDispatchThread()) {
466
                    if ("nbfs".equals(url.getProtocol())) { // NOI18N
469
                    if ("nbfs".equals(url.getProtocol())) { // NOI18N
Lines 592-604 Link Here
592
     */
595
     */
593
    private void updateLocationBar() {
596
    private void updateLocationBar() {
594
        if (toolbarVisible) {
597
        if (toolbarVisible) {
595
            everythinkIListenInCheckBoxIsUnimportant = true;
598
            ignoreChangeInLocationField = true;
596
599
597
            String url = browserImpl.getLocation();
600
            String url = browserImpl.getLocation();
598
601
599
            txtLocation.setText(url);
602
            txtLocation.setText(url);
600
603
601
            everythinkIListenInCheckBoxIsUnimportant = false;
604
            ignoreChangeInLocationField = false;
602
        }
605
        }
603
    }
606
    }
604
607
Lines 673-678 Link Here
673
        /**
676
        /**
674
        * Listens on changes in HtmlBrowser.Impl.
677
        * Listens on changes in HtmlBrowser.Impl.
675
        */
678
        */
679
        @Override
676
        public void propertyChange(PropertyChangeEvent evt) {
680
        public void propertyChange(PropertyChangeEvent evt) {
677
            String property = evt.getPropertyName();
681
            String property = evt.getPropertyName();
678
682
Lines 700-715 Link Here
700
                bForward.setEnabled(browserImpl.isForward());
704
                bForward.setEnabled(browserImpl.isForward());
701
            } else if (property.equals(Impl.PROP_BACKWARD) && (bBack != null)) {
705
            } else if (property.equals(Impl.PROP_BACKWARD) && (bBack != null)) {
702
                bBack.setEnabled(browserImpl.isBackward());
706
                bBack.setEnabled(browserImpl.isBackward());
707
            } else if (property.equals(Impl.PROP_LOADING) && (bStop != null)) {
708
                bStop.setEnabled(((Boolean)evt.getNewValue()).booleanValue());
703
            }
709
            }
704
        }
710
        }
705
711
706
        /**
712
        /**
707
        * Listens on changes in HtmlBrowser visual components.
713
        * Listens on changes in HtmlBrowser visual components.
708
        */
714
        */
715
        @Override
709
        public void actionPerformed(ActionEvent e) {
716
        public void actionPerformed(ActionEvent e) {
710
            if (e.getSource() == txtLocation) {
717
            if (e.getSource() == txtLocation) {
711
                // URL manually changed
718
                // URL manually changed
712
                if (everythinkIListenInCheckBoxIsUnimportant) {
719
                if (ignoreChangeInLocationField) {
713
                    return;
720
                    return;
714
                }
721
                }
715
722
Lines 764-770 Link Here
764
        /** history property name */
771
        /** history property name */
765
        public static final String PROP_HISTORY = "history"; // NOI18N
772
        public static final String PROP_HISTORY = "history"; // NOI18N
766
773
774
        public static final String PROP_BROWSER_WAS_CLOSED = "browser.was.closed"; // NOI18N
775
767
        /**
776
        /**
777
         * Name of boolean property which is fired when the browser is busy loading
778
         * its content.
779
         * 
780
         * @since 7.52
781
         */
782
        public static final String PROP_LOADING = "loading"; //NOI18N
783
784
        /**
768
        * Returns visual component of html browser.
785
        * Returns visual component of html browser.
769
        *
786
        *
770
        * @return visual component of html browser.
787
        * @return visual component of html browser.
Lines 895-901 Link Here
895
         */
912
         */
896
        public void dispose() {
913
        public void dispose() {
897
        }
914
        }
915
916
        /**
917
         * The content of this Lookup will be merged into browser's TopComponent Lookup.
918
         * @return Browser's Lookup
919
         * @since 7.52
920
         */
921
        public Lookup getLookup() {
922
            return Lookup.EMPTY;
898
    }
923
    }
924
    }
899
925
900
    /** A manager class which can display URLs in the proper way.
926
    /** A manager class which can display URLs in the proper way.
901
     * Might open a selected HTML browser, knows about embedded vs. external
927
     * Might open a selected HTML browser, knows about embedded vs. external
Lines 954-959 Link Here
954
        public TrivialURLDisplayer() {
980
        public TrivialURLDisplayer() {
955
        }
981
        }
956
982
983
        @Override
957
        public void showURL(URL u) {
984
        public void showURL(URL u) {
958
            if (Desktop.isDesktopSupported()) {
985
            if (Desktop.isDesktopSupported()) {
959
                Desktop d = Desktop.getDesktop();
986
                Desktop d = Desktop.getDesktop();

Return to bug 217171