| 1 |
/* |
| 2 |
Copyright (C) 2012 Red Hat, Inc. |
| 3 |
|
| 4 |
This file is part of IcedTea. |
| 5 |
|
| 6 |
IcedTea is free software; you can redistribute it and/or |
| 7 |
modify it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, version 2. |
| 9 |
|
| 10 |
IcedTea is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with IcedTea; see the file COPYING. If not, write to |
| 17 |
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 |
02110-1301 USA. |
| 19 |
|
| 20 |
Linking this library statically or dynamically with other modules is |
| 21 |
making a combined work based on this library. Thus, the terms and |
| 22 |
conditions of the GNU General Public License cover the whole |
| 23 |
combination. |
| 24 |
|
| 25 |
As a special exception, the copyright holders of this library give you |
| 26 |
permission to link this library with independent modules to produce an |
| 27 |
executable, regardless of the license terms of these independent |
| 28 |
modules, and to copy and distribute the resulting executable under |
| 29 |
terms of your choice, provided that you also meet, for each linked |
| 30 |
independent module, the terms and conditions of the license of that |
| 31 |
module. An independent module is a module which is not derived from |
| 32 |
or based on this library. If you modify this library, you may extend |
| 33 |
this exception to your version of the library, but you are not |
| 34 |
obligated to do so. If you do not wish to do so, delete this |
| 35 |
exception statement from your version. |
| 36 |
*/ |
| 37 |
package net.sourceforge.jnlp.runtime.html.browser; |
| 38 |
|
| 39 |
import java.net.Authenticator; |
| 40 |
import java.net.ProxySelector; |
| 41 |
import java.net.URL; |
| 42 |
import javax.swing.JFrame; |
| 43 |
import javax.swing.JScrollPane; |
| 44 |
import javax.swing.JTabbedPane; |
| 45 |
import net.sourceforge.jnlp.browser.BrowserAwareProxySelector; |
| 46 |
import static net.sourceforge.jnlp.runtime.JNLPRuntime.getConfiguration; |
| 47 |
import net.sourceforge.jnlp.security.JNLPAuthenticator; |
| 48 |
import net.sourceforge.jnlp.util.logging.JavaConsole; |
| 49 |
|
| 50 |
public class LinkingBrowser extends JTabbedPane { |
| 51 |
|
| 52 |
private final HtmlBrowserPanel browser; |
| 53 |
private final LinksPanel linksPanel = new LinksPanel(); |
| 54 |
|
| 55 |
public LinkingBrowser(final URL url) { |
| 56 |
this(url, false); |
| 57 |
} |
| 58 |
|
| 59 |
public LinkingBrowser(final String url) { |
| 60 |
this(url, false); |
| 61 |
} |
| 62 |
|
| 63 |
public LinkingBrowser(final URL url, boolean socket) { |
| 64 |
super(); |
| 65 |
browser = new HtmlBrowserPanel(url, socket); |
| 66 |
createGui(browser); |
| 67 |
} |
| 68 |
|
| 69 |
public LinkingBrowser(final String url, boolean socket) { |
| 70 |
super(); |
| 71 |
browser = new HtmlBrowserPanel(url, socket); |
| 72 |
createGui(browser); |
| 73 |
} |
| 74 |
|
| 75 |
private void createGui(HtmlBrowserPanel lBrowser) { |
| 76 |
linksPanel.addressChangeded(lBrowser.getUrl()); |
| 77 |
linksPanel.parseAndAdd(lBrowser.getCurrentSource()); |
| 78 |
linksPanel.setInternalBrowser(lBrowser); |
| 79 |
lBrowser.addDocumentChangedListener(linksPanel); |
| 80 |
this.addTab("html", lBrowser); //jeditropane |
| 81 |
this.addTab("links", new JScrollPane(linksPanel)); // set of found links - copyToClipboard, execute in browser, show... |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
public static void showStandAloneWindow(String url, boolean socket) { |
| 86 |
if (JavaConsole.canShowOnStartup(true)) { |
| 87 |
JavaConsole.getConsole().showConsoleLater(); |
| 88 |
} |
| 89 |
// plug in a custom authenticator and proxy selector |
| 90 |
Authenticator.setDefault(new JNLPAuthenticator()); |
| 91 |
BrowserAwareProxySelector proxySelector = new BrowserAwareProxySelector(getConfiguration()); |
| 92 |
proxySelector.initialize(); |
| 93 |
ProxySelector.setDefault(proxySelector); |
| 94 |
createFrame(url, socket, JFrame.EXIT_ON_CLOSE); |
| 95 |
} |
| 96 |
|
| 97 |
public static void createFrame(String url, boolean socket, int action) { |
| 98 |
HtmlBrowserPanel.warn(); |
| 99 |
JFrame f = new JFrame(); |
| 100 |
f.add(new LinkingBrowser(url, socket)); |
| 101 |
f.pack(); |
| 102 |
f.setDefaultCloseOperation(action); |
| 103 |
f.setVisible(true); |
| 104 |
} |
| 105 |
|
| 106 |
public HtmlBrowserPanel getBrowser() { |
| 107 |
return browser; |
| 108 |
} |
| 109 |
|
| 110 |
public LinksPanel getLinksPanel() { |
| 111 |
return linksPanel; |
| 112 |
} |
| 113 |
|
| 114 |
} |