зеркало из https://github.com/mozilla/gecko-dev.git
Ok after this checkin we now have all the functionality of Sun's JDIC
WebBrowser <https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/browser/WebBrowser.html>, with the following exceptions: - we're based on mozilla 1.6 - it only works on windows - we don't have mouse event support - we only support mozilla, not IE So, webclient still has a ways to go until we reach its former glory, but reach it we will. I'm going to assemble a 2.0 alpha 1 source code only release, including build instructions, from what we have now. I'd love it if someone could get the unit tests working on GNU/Linux again. I think the problem has to do with our old friend GDKSUPERWIN. Next step is to assemble the 2.0 alpha 1 source code release! Ed M webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java M webclient/src_moz/NavigationImpl.cpp - re-enable POST M webclient/src_moz/EmbedWindow.cpp M webclient/src_moz/EmbedWindow.h - expose DocShell post method. M webclient/test/automated/src/classes/org/mozilla/util/THTTPD.java M webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java - test code for POST
This commit is contained in:
Родитель
d3abbd41dc
Коммит
8539e82952
|
@ -65,6 +65,7 @@
|
||||||
|
|
||||||
<!-- Source directory for tests -->
|
<!-- Source directory for tests -->
|
||||||
<property name="src.test.dir" value="${basedir}/test/automated/src/classes"/>
|
<property name="src.test.dir" value="${basedir}/test/automated/src/classes"/>
|
||||||
|
<property name="src.manual.test.dir" value="${basedir}/test/manual/src/classes"/>
|
||||||
|
|
||||||
<!-- Output directory for tests -->
|
<!-- Output directory for tests -->
|
||||||
<property name="out.test.dir" value="${build.home}/test"/>
|
<property name="out.test.dir" value="${build.home}/test"/>
|
||||||
|
@ -86,7 +87,7 @@
|
||||||
<!--
|
<!--
|
||||||
Compile unit tests
|
Compile unit tests
|
||||||
-->
|
-->
|
||||||
<target name="compile.test">
|
<target name="compile.test" depends="copy-test-data-files">
|
||||||
|
|
||||||
<echo message="${build.home}"/>
|
<echo message="${build.home}"/>
|
||||||
|
|
||||||
|
@ -100,6 +101,7 @@
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
|
||||||
<src path="${src.test.dir}"/>
|
<src path="${src.test.dir}"/>
|
||||||
|
<src path="${src.manual.test.dir}"/>
|
||||||
<patternset>
|
<patternset>
|
||||||
<exclude name="**/*Win32*.java" if="build.unix.classes"/>
|
<exclude name="**/*Win32*.java" if="build.unix.classes"/>
|
||||||
</patternset>
|
</patternset>
|
||||||
|
@ -120,6 +122,13 @@
|
||||||
<copy todir="${build.test}">
|
<copy todir="${build.test}">
|
||||||
<fileset dir="${basedir}/test/automated/src/test"/>
|
<fileset dir="${basedir}/test/automated/src/test"/>
|
||||||
</copy>
|
</copy>
|
||||||
|
|
||||||
|
<copy todir="${out.test.dir}/classes">
|
||||||
|
<fileset dir="${src.manual.test.dir}">
|
||||||
|
<include name="**/*.gif" />
|
||||||
|
<include name="**/*.png" />
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +139,7 @@
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="run.test" depends="compile.test,copy-test-data-files">
|
<target name="run.test" depends="compile.test">
|
||||||
|
|
||||||
<junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
|
<junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
|
||||||
<jvmarg value="-Djava.library.path=${myenv.MOZILLA_FIVE_HOME}${PATH_SEP}${myenv.MOZILLA_FIVE_HOME}/components"/>
|
<jvmarg value="-Djava.library.path=${myenv.MOZILLA_FIVE_HOME}${PATH_SEP}${myenv.MOZILLA_FIVE_HOME}/components"/>
|
||||||
|
@ -160,6 +169,23 @@
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="run.test.browser" depends="compile.test">
|
||||||
|
|
||||||
|
<java classname="org.mozilla.webclient.test.TestBrowser" fork="true">
|
||||||
|
<jvmarg value="-Djava.library.path=${myenv.MOZILLA_FIVE_HOME}${PATH_SEP}${myenv.MOZILLA_FIVE_HOME}/components"/>
|
||||||
|
<jvmarg value="-DNSPR_LOG_MODULES=${myenv.NSPR_LOG_MODULES}"/>
|
||||||
|
<jvmarg value="-DNSPR_LOG_FILE=${myenv.NSPR_LOG_FILE}"/>
|
||||||
|
<jvmarg value="-DBROWSER_BIN_DIR=${myenv.MOZILLA_FIVE_HOME}"/>
|
||||||
|
<sysproperty key="native.waitForDebugger"
|
||||||
|
value="${native.waitForDebugger}"/>
|
||||||
|
<jvmarg line="${debug.jvm.args}"/>
|
||||||
|
|
||||||
|
<classpath refid="test.classpath"/>
|
||||||
|
</java>
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -304,6 +304,12 @@ ${myenv.MOZ_JDKHOME}/bin/java ${debug.options} org.mozilla.webclient.test.Embedd
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="run.test.browser" description="Run the test browser">
|
||||||
|
|
||||||
|
<ant antfile="build-tests.xml" target="run.test.browser"/>
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="compile.test" description="compile unit tests">
|
<target name="compile.test" description="compile unit tests">
|
||||||
|
|
||||||
<ant antfile="build-tests.xml" target="compile.test"/>
|
<ant antfile="build-tests.xml" target="compile.test"/>
|
||||||
|
|
|
@ -94,9 +94,12 @@ public void copyCurrentSelectionToSystemClipboard()
|
||||||
getWrapperFactory().verifyInitialized();
|
getWrapperFactory().verifyInitialized();
|
||||||
Assert.assert_it(-1 != getNativeBrowserControl());
|
Assert.assert_it(-1 != getNativeBrowserControl());
|
||||||
|
|
||||||
synchronized(getBrowserControl()) {
|
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
|
||||||
nativeCopyCurrentSelectionToSystemClipboard(getNativeBrowserControl());
|
public Object run() {
|
||||||
}
|
nativeCopyCurrentSelectionToSystemClipboard(CurrentPageImpl.this.getNativeBrowserControl());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Selection getSelection() {
|
public Selection getSelection() {
|
||||||
|
@ -336,7 +339,7 @@ public static void main(String [] args)
|
||||||
Assert.setEnabled(true);
|
Assert.setEnabled(true);
|
||||||
Log.setApplicationName("CurrentPageImpl");
|
Log.setApplicationName("CurrentPageImpl");
|
||||||
Log.setApplicationVersion("0.0");
|
Log.setApplicationVersion("0.0");
|
||||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.4 2004/04/28 14:39:54 edburns%acm.org Exp $");
|
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.5 2004/06/25 13:59:53 edburns%acm.org Exp $");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,16 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa
|
||||||
(JNIEnv *env, jobject obj, jint nativeBCPtr)
|
(JNIEnv *env, jobject obj, jint nativeBCPtr)
|
||||||
{
|
{
|
||||||
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
|
NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr;
|
||||||
|
|
||||||
if (nativeBrowserControl->initComplete) {
|
if (nativeBrowserControl == nsnull) {
|
||||||
wsCopySelectionEvent * actionEvent = new wsCopySelectionEvent(nativeBrowserControl);
|
::util_ThrowExceptionToJava(env, "Exception: null nativeBCPtr passed nativeGetSelection");
|
||||||
PLEvent * event = (PLEvent*) *actionEvent;
|
return;
|
||||||
::util_PostEvent(nativeBrowserControl, event);
|
}
|
||||||
|
|
||||||
|
nsresult rv = nativeBrowserControl->mWindow->CopySelection();
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
::util_ThrowExceptionToJava(env, "Exception: Can't get Selection from browser");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <nsCWebBrowser.h>
|
#include <nsCWebBrowser.h>
|
||||||
#include <nsIComponentManager.h>
|
#include <nsIComponentManager.h>
|
||||||
#include <nsIDocShellTreeItem.h>
|
#include <nsIDocShellTreeItem.h>
|
||||||
|
#include "nsIContentViewer.h"
|
||||||
|
#include "nsIContentViewerEdit.h"
|
||||||
#include "nsIDOMWindowInternal.h"
|
#include "nsIDOMWindowInternal.h"
|
||||||
#include "nsIDOMWindow.h"
|
#include "nsIDOMWindow.h"
|
||||||
#include "nsISelection.h"
|
#include "nsISelection.h"
|
||||||
|
@ -270,6 +272,33 @@ EmbedWindow::GetSelection(JNIEnv *env, jobject mSelection)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
EmbedWindow::CopySelection()
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebBrowser);
|
||||||
|
nsCOMPtr<nsIContentViewer> contentViewer = nsnull;
|
||||||
|
nsCOMPtr<nsIContentViewerEdit> contentViewerEdit = nsnull;
|
||||||
|
nsresult rv = NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
if (!docShell) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
||||||
|
if (!contentViewer || NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
contentViewerEdit = do_QueryInterface(contentViewer, &rv);
|
||||||
|
|
||||||
|
if (!contentViewerEdit || NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = contentViewerEdit->CopySelection();
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
EmbedWindow::LoadStream(nsIInputStream *aStream, nsIURI * aURI,
|
EmbedWindow::LoadStream(nsIInputStream *aStream, nsIURI * aURI,
|
||||||
const nsACString &aContentType,
|
const nsACString &aContentType,
|
||||||
|
|
|
@ -67,6 +67,7 @@ public:
|
||||||
|
|
||||||
nsresult SelectAll ();
|
nsresult SelectAll ();
|
||||||
nsresult GetSelection (JNIEnv *env, jobject selection);
|
nsresult GetSelection (JNIEnv *env, jobject selection);
|
||||||
|
nsresult CopySelection ();
|
||||||
|
|
||||||
nsresult LoadStream (nsIInputStream *aStream, nsIURI * aURI,
|
nsresult LoadStream (nsIInputStream *aStream, nsIURI * aURI,
|
||||||
const nsACString &aContentType,
|
const nsACString &aContentType,
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
|
||||||
|
* subject to license terms.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the Lesser GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.webclient.test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JDIC API demo class.
|
||||||
|
* <p>
|
||||||
|
* The class represents a status bar.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class MyStatusBar extends Box {
|
||||||
|
public JLabel lblStatus, lblDesc;
|
||||||
|
|
||||||
|
public MyStatusBar() {
|
||||||
|
super(BoxLayout.X_AXIS);
|
||||||
|
|
||||||
|
Toolkit kit = Toolkit.getDefaultToolkit();
|
||||||
|
Dimension screenSize = kit.getScreenSize();
|
||||||
|
|
||||||
|
// Add the JLabel displaying the selected object numbers.
|
||||||
|
lblStatus = new JLabel("Status:", SwingConstants.LEADING);
|
||||||
|
lblStatus.setPreferredSize(new Dimension((int) (0.7 * screenSize.width),
|
||||||
|
22));
|
||||||
|
lblStatus.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
|
this.add(lblStatus, null);
|
||||||
|
|
||||||
|
// Add the JLabel displaying the selected object size.
|
||||||
|
// lblSize = new JLabel("Size:", SwingConstants.LEADING);
|
||||||
|
// lblSize.setPreferredSize(new Dimension((int)(0.2*screenSize.width), 22));
|
||||||
|
// lblSize.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
|
// this.add(lblSize, null);
|
||||||
|
|
||||||
|
// Add the JLabel displaying the description.
|
||||||
|
lblDesc = new JLabel("Description:", SwingConstants.LEADING);
|
||||||
|
lblDesc.setPreferredSize(new Dimension((int) (0.3 * screenSize.width),
|
||||||
|
22));
|
||||||
|
lblDesc.setBorder(BorderFactory.createLoweredBevelBorder());
|
||||||
|
this.add(lblDesc, null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,430 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
|
||||||
|
* subject to license terms.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the Lesser GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||||
|
* USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.webclient.test;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.*;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
|
import org.mozilla.webclient.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>webclient API demo main class.</p>
|
||||||
|
|
||||||
|
* <p><code>TestBrowser</code> is a GUI application demonstrating the
|
||||||
|
* usage of the package <code>org.mozilla.webclient</code> </p>
|
||||||
|
|
||||||
|
* <p>This is based on the TestBrowser class in the <a
|
||||||
|
* href="https://jdic.dev.java.net/">JDIC project</a>. </p>
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TestBrowser extends JPanel {
|
||||||
|
|
||||||
|
public void addNotify() {
|
||||||
|
super.addNotify();
|
||||||
|
browserControlCanvas.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImageIcon browseIcon = new ImageIcon(
|
||||||
|
TestBrowser.class.getResource("images/Right.gif"));
|
||||||
|
|
||||||
|
BorderLayout borderLayout1 = new BorderLayout();
|
||||||
|
|
||||||
|
JToolBar jBrowserToolBar = new JToolBar();
|
||||||
|
JButton jStopButton = new JButton("Stop",
|
||||||
|
new ImageIcon(getClass().getResource("images/Stop.png")));
|
||||||
|
|
||||||
|
JButton jRefreshButton = new JButton("Refresh",
|
||||||
|
new ImageIcon(getClass().getResource("images/Reload.png")));
|
||||||
|
JButton jForwardButton = new JButton("Forward",
|
||||||
|
new ImageIcon(getClass().getResource("images/Forward.png")));
|
||||||
|
JButton jBackButton = new JButton("Back",
|
||||||
|
new ImageIcon(getClass().getResource("images/Back.png")));
|
||||||
|
JButton jCopyButton = new JButton("Copy");
|
||||||
|
|
||||||
|
JPanel jAddressPanel = new JPanel();
|
||||||
|
JLabel jAddressLabel = new JLabel();
|
||||||
|
JTextField jAddressTextField = new JTextField();
|
||||||
|
JButton jGoButton = new JButton();
|
||||||
|
JPanel jAddrToolBarPanel = new JPanel();
|
||||||
|
MyStatusBar statusBar = new MyStatusBar();
|
||||||
|
JPanel jBrowserPanel = new JPanel();
|
||||||
|
|
||||||
|
BrowserControl webBrowser;
|
||||||
|
Navigation navigation;
|
||||||
|
History history;
|
||||||
|
EventRegistration eventRegistration;
|
||||||
|
CurrentPage currentPage;
|
||||||
|
Canvas browserControlCanvas;
|
||||||
|
|
||||||
|
public TestBrowser() {
|
||||||
|
try {
|
||||||
|
jbInit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
BrowserControlFactory.setAppData(System.getProperty("BROWSER_BIN_DIR"));
|
||||||
|
} catch (Exception e) {}
|
||||||
|
|
||||||
|
JFrame frame = new JFrame("JDIC API Demo - Browser");
|
||||||
|
|
||||||
|
Container contentPane = frame.getContentPane();
|
||||||
|
|
||||||
|
contentPane.setLayout(new GridLayout(1, 1));
|
||||||
|
contentPane.add(new TestBrowser());
|
||||||
|
|
||||||
|
frame.addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void jbInit() throws Exception {
|
||||||
|
this.setLayout(borderLayout1);
|
||||||
|
|
||||||
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
|
|
||||||
|
this.setPreferredSize(new Dimension(screenSize.width * 9 / 10,
|
||||||
|
screenSize.height * 8 / 10));
|
||||||
|
|
||||||
|
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
|
||||||
|
|
||||||
|
jAddressLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
|
||||||
|
jAddressLabel.setToolTipText("");
|
||||||
|
jAddressLabel.setText(" URL: ");
|
||||||
|
|
||||||
|
jGoButton.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(0,
|
||||||
|
2, 0, 2),
|
||||||
|
new EtchedBorder()));
|
||||||
|
jGoButton.setMaximumSize(new Dimension(60, 25));
|
||||||
|
jGoButton.setMinimumSize(new Dimension(60, 25));
|
||||||
|
jGoButton.setPreferredSize(new Dimension(60, 25));
|
||||||
|
jGoButton.setToolTipText("Load the given URL");
|
||||||
|
jGoButton.setIcon(browseIcon);
|
||||||
|
jGoButton.setText("GO");
|
||||||
|
jGoButton.addActionListener(new TestBrowser_jGoButton_actionAdapter(this));
|
||||||
|
jAddressPanel.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
jAddressTextField.addActionListener(new TestBrowser_jAddressTextField_actionAdapter(this));
|
||||||
|
jBackButton.setToolTipText("Go back one page");
|
||||||
|
jBackButton.setHorizontalTextPosition(SwingConstants.TRAILING);
|
||||||
|
jBackButton.setEnabled(false);
|
||||||
|
jBackButton.setMaximumSize(new Dimension(75, 27));
|
||||||
|
jBackButton.setPreferredSize(new Dimension(75, 27));
|
||||||
|
jBackButton.addActionListener(new TestBrowser_jBackButton_actionAdapter(this));
|
||||||
|
|
||||||
|
jCopyButton.setToolTipText("Copy current selection");
|
||||||
|
jCopyButton.setHorizontalTextPosition(SwingConstants.TRAILING);
|
||||||
|
jCopyButton.setMaximumSize(new Dimension(75, 27));
|
||||||
|
jCopyButton.setPreferredSize(new Dimension(75, 27));
|
||||||
|
jCopyButton.addActionListener(new TestBrowser_jCopyButton_actionAdapter(this));
|
||||||
|
|
||||||
|
jForwardButton.setToolTipText("Go forward one page");
|
||||||
|
jForwardButton.setEnabled(false);
|
||||||
|
jForwardButton.addActionListener(new TestBrowser_jForwardButton_actionAdapter(this));
|
||||||
|
jRefreshButton.setToolTipText("Reload current page");
|
||||||
|
jRefreshButton.setEnabled(true);
|
||||||
|
jRefreshButton.setMaximumSize(new Dimension(75, 27));
|
||||||
|
jRefreshButton.setMinimumSize(new Dimension(75, 27));
|
||||||
|
jRefreshButton.setPreferredSize(new Dimension(75, 27));
|
||||||
|
jRefreshButton.addActionListener(new TestBrowser_jRefreshButton_actionAdapter(this));
|
||||||
|
jStopButton.setToolTipText("Stop loading this page");
|
||||||
|
jStopButton.setVerifyInputWhenFocusTarget(true);
|
||||||
|
jStopButton.setText("Stop");
|
||||||
|
jStopButton.setEnabled(true);
|
||||||
|
jStopButton.setMaximumSize(new Dimension(75, 27));
|
||||||
|
jStopButton.setMinimumSize(new Dimension(75, 27));
|
||||||
|
jStopButton.setPreferredSize(new Dimension(75, 27));
|
||||||
|
jStopButton.addActionListener(new TestBrowser_jStopButton_actionAdapter(this));
|
||||||
|
jAddressPanel.add(jAddressLabel, BorderLayout.WEST);
|
||||||
|
jAddressPanel.add(jAddressTextField, BorderLayout.CENTER);
|
||||||
|
jAddressPanel.add(jGoButton, BorderLayout.EAST);
|
||||||
|
jAddressPanel.setBorder(BorderFactory.createCompoundBorder(
|
||||||
|
BorderFactory.createEtchedBorder(),
|
||||||
|
BorderFactory.createEmptyBorder(2, 0, 2, 0)));
|
||||||
|
|
||||||
|
jBrowserToolBar.setFloatable(false);
|
||||||
|
jBrowserToolBar.add(jBackButton, null);
|
||||||
|
jBrowserToolBar.add(jForwardButton, null);
|
||||||
|
jBrowserToolBar.addSeparator();
|
||||||
|
jBrowserToolBar.add(jRefreshButton, null);
|
||||||
|
jBrowserToolBar.add(jStopButton, null);
|
||||||
|
// jBrowserToolBar.add(jCopyButton, null);
|
||||||
|
jBrowserToolBar.setBorder(BorderFactory.createCompoundBorder(
|
||||||
|
BorderFactory.createEtchedBorder(),
|
||||||
|
BorderFactory.createEmptyBorder(2, 2, 2, 0)));
|
||||||
|
|
||||||
|
jAddrToolBarPanel.setLayout(new BorderLayout());
|
||||||
|
jAddrToolBarPanel.add(jAddressPanel, BorderLayout.CENTER);
|
||||||
|
jAddrToolBarPanel.add(jBrowserToolBar, BorderLayout.WEST);
|
||||||
|
jAddrToolBarPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
|
||||||
|
|
||||||
|
statusBar.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
||||||
|
statusBar.lblDesc.setText("JDIC API Demo - Browser");
|
||||||
|
|
||||||
|
try {
|
||||||
|
webBrowser = BrowserControlFactory.newBrowserControl();
|
||||||
|
navigation = (Navigation)
|
||||||
|
webBrowser.queryInterface(BrowserControl.NAVIGATION_NAME);
|
||||||
|
history = (History)
|
||||||
|
webBrowser.queryInterface(BrowserControl.HISTORY_NAME);
|
||||||
|
eventRegistration = (EventRegistration)
|
||||||
|
webBrowser.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME);
|
||||||
|
currentPage = (CurrentPage)
|
||||||
|
webBrowser.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||||
|
browserControlCanvas = (Canvas)
|
||||||
|
webBrowser.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME);
|
||||||
|
// Print out debug messages in the command line.
|
||||||
|
//myWebBrowser.setDebug(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
eventRegistration.addDocumentLoadListener(new DocumentLoadListener() {
|
||||||
|
public void eventDispatched(WebclientEvent event) {
|
||||||
|
if (event instanceof DocumentLoadEvent) {
|
||||||
|
switch ((int) event.getType()) {
|
||||||
|
case ((int) DocumentLoadEvent.START_DOCUMENT_LOAD_EVENT_MASK):
|
||||||
|
updateStatusInfo("Loading started.");
|
||||||
|
break;
|
||||||
|
case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK):
|
||||||
|
jBackButton.setEnabled(history.canBack());
|
||||||
|
jForwardButton.setEnabled(history.canForward());
|
||||||
|
updateStatusInfo("Loading completed.");
|
||||||
|
|
||||||
|
if (event.getEventData() != null) {
|
||||||
|
jAddressTextField.setText(event.getEventData().toString());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ((int) DocumentLoadEvent.PROGRESS_URL_LOAD_EVENT_MASK):
|
||||||
|
// updateStatusInfo("Loading in progress...");
|
||||||
|
break;
|
||||||
|
case ((int) DocumentLoadEvent.FETCH_INTERRUPT_EVENT_MASK):
|
||||||
|
updateStatusInfo("Loading error.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
jBrowserPanel.setLayout(new BorderLayout());
|
||||||
|
jBrowserPanel.add(browserControlCanvas, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
this.add(jAddrToolBarPanel, BorderLayout.NORTH);
|
||||||
|
this.add(statusBar, BorderLayout.SOUTH);
|
||||||
|
this.add(jBrowserPanel, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateStatusInfo(String statusMessage) {
|
||||||
|
statusBar.lblStatus.setText(statusMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the current input URL string in the address text field, load it,
|
||||||
|
* and update the status info and toolbar info.
|
||||||
|
*/
|
||||||
|
void loadURL() {
|
||||||
|
String inputValue = jAddressTextField.getText();
|
||||||
|
|
||||||
|
if (inputValue == null) {
|
||||||
|
JOptionPane.showMessageDialog(this, "The given URL is NULL:",
|
||||||
|
"Warning", JOptionPane.WARNING_MESSAGE);
|
||||||
|
} else {
|
||||||
|
// Check if the text value is a URL string.
|
||||||
|
URL curUrl = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Check if the input string is a local path by checking if it starts
|
||||||
|
// with a driver name(on Windows) or root path(on Unix).
|
||||||
|
File[] roots = File.listRoots();
|
||||||
|
|
||||||
|
for (int i = 0; i < roots.length; i++) {
|
||||||
|
if (inputValue.toLowerCase().startsWith(roots[i].toString().toLowerCase())) {
|
||||||
|
File curLocalFile = new File(inputValue);
|
||||||
|
|
||||||
|
curUrl = curLocalFile.toURL();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curUrl == null) {
|
||||||
|
// Check if the text value starts with known protocols.
|
||||||
|
if (inputValue.toLowerCase().startsWith("http://")
|
||||||
|
|| inputValue.toLowerCase().startsWith("ftp://")
|
||||||
|
|| inputValue.toLowerCase().startsWith("gopher://")) {
|
||||||
|
curUrl = new URL(inputValue);
|
||||||
|
} else {
|
||||||
|
if (inputValue.toLowerCase().startsWith("ftp.")) {
|
||||||
|
curUrl = new URL("ftp://" + inputValue);
|
||||||
|
} else if (inputValue.toLowerCase().startsWith("gopher.")) {
|
||||||
|
curUrl = new URL("gopher://" + inputValue);
|
||||||
|
} else {
|
||||||
|
curUrl = new URL("http://" + inputValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
navigation.loadURL(curUrl.toString());
|
||||||
|
|
||||||
|
// Update the address text field, statusbar, and toolbar info.
|
||||||
|
updateStatusInfo("Loading " + curUrl.toString() + " ......");
|
||||||
|
} catch (MalformedURLException mue) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"The given URL is not valid:" + inputValue, "Warning",
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void jGoButton_actionPerformed(ActionEvent e) {
|
||||||
|
loadURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jAddressTextField_actionPerformed(ActionEvent e) {
|
||||||
|
loadURL();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jBackButton_actionPerformed(ActionEvent e) {
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jCopyButton_actionPerformed(ActionEvent e) {
|
||||||
|
currentPage.copyCurrentSelectionToSystemClipboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void jForwardButton_actionPerformed(ActionEvent e) {
|
||||||
|
history.forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
void jRefreshButton_actionPerformed(ActionEvent e) {
|
||||||
|
navigation.refresh(Navigation.LOAD_FORCE_RELOAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void jStopButton_actionPerformed(ActionEvent e) {
|
||||||
|
navigation.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jAddressTextField_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jAddressTextField_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jAddressTextField_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jBackButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jBackButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jBackButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestBrowser_jCopyButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jCopyButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jCopyButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jForwardButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jForwardButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jForwardButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jRefreshButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jRefreshButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jRefreshButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jStopButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jStopButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jStopButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestBrowser_jGoButton_actionAdapter implements java.awt.event.ActionListener {
|
||||||
|
TestBrowser adaptee;
|
||||||
|
|
||||||
|
TestBrowser_jGoButton_actionAdapter(TestBrowser adaptee) {
|
||||||
|
this.adaptee = adaptee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
adaptee.jGoButton_actionPerformed(e);
|
||||||
|
}
|
||||||
|
}
|
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Back.png
Normal file
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Back.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 407 B |
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Forward.png
Normal file
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Forward.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 390 B |
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Reload.png
Normal file
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Reload.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 555 B |
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Right.gif
Normal file
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Right.gif
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 82 B |
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Stop.png
Normal file
Двоичные данные
java/webclient/test/manual/src/classes/org/mozilla/webclient/test/images/Stop.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 765 B |
Загрузка…
Ссылка в новой задаче