зеркало из https://github.com/mozilla/gecko-dev.git
Made changes in EMWIndow.java and EmbeddedMozilla.java to create a better
GUI with menus for creating and closing new windows and for Find features. Ashu a=ashuk r=edburns Bug=20659
This commit is contained in:
Родитель
2434be9490
Коммит
b10d328efa
|
@ -34,29 +34,34 @@ import java.awt.event.*;
|
|||
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreeNode;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
import org.mozilla.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
* This is a test application for using the BrowserControl.
|
||||
|
||||
*
|
||||
* @version $Id: EMWindow.java,v 1.1 2000/03/13 18:41:51 edburns%acm.org Exp $
|
||||
* @version $Id: EMWindow.java,v 1.2 2000/04/06 17:33:29 ashuk%eng.sun.com Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlFactory
|
||||
|
||||
*/
|
||||
|
||||
public class EMWindow extends Frame implements ActionListener, DocumentLoadListener {
|
||||
public class EMWindow extends Frame implements DialogClient, ActionListener, DocumentLoadListener {
|
||||
static final int defaultWidth = 640;
|
||||
static final int defaultHeight = 480;
|
||||
|
||||
private int winNum;
|
||||
|
||||
private TextField urlField;
|
||||
private BrowserControl browserControl;
|
||||
private BrowserControlCanvas browserCanvas;
|
||||
|
@ -67,18 +72,48 @@ public class EMWindow extends Frame implements ActionListener, DocumentLoadListe
|
|||
private TreeModel bookmarksTree;
|
||||
private Panel controlPanel;
|
||||
private Panel buttonsPanel;
|
||||
private FindDialog findDialog = null;
|
||||
private MenuBar menuBar;
|
||||
|
||||
public static void main (String[] arg) {
|
||||
} // main()
|
||||
|
||||
public EMWindow (String title, String binDir, String url)
|
||||
private EmbeddedMozilla creator;
|
||||
|
||||
|
||||
public static void main(String [] arg)
|
||||
{
|
||||
super(title);
|
||||
}
|
||||
|
||||
|
||||
public EMWindow (String title, String binDir, String url, int winnum, EmbeddedMozilla Creator)
|
||||
{
|
||||
super(title);
|
||||
creator = Creator;
|
||||
winNum = winnum;
|
||||
System.out.println("constructed with binDir: " + binDir + " url: " +
|
||||
url);
|
||||
setLocation(0, EmbeddedMozilla.height);
|
||||
setSize(defaultWidth, defaultHeight);
|
||||
|
||||
// Create the Menu Bar
|
||||
menuBar = new MenuBar();
|
||||
this.setMenuBar(menuBar);
|
||||
Menu fileMenu = new Menu("File");
|
||||
Menu viewMenu = new Menu("View");
|
||||
Menu searchMenu = new Menu("Search");
|
||||
MenuItem newItem = new MenuItem("New Window");
|
||||
MenuItem closeItem = new MenuItem("Close");
|
||||
MenuItem findItem = new MenuItem("Find");
|
||||
MenuItem findNextItem = new MenuItem("Find Next");
|
||||
menuBar.add(fileMenu);
|
||||
menuBar.add(viewMenu);
|
||||
menuBar.add(searchMenu);
|
||||
fileMenu.add(newItem);
|
||||
newItem.addActionListener(this);
|
||||
fileMenu.add(closeItem);
|
||||
closeItem.addActionListener(this);
|
||||
searchMenu.add(findItem);
|
||||
findItem.addActionListener(this);
|
||||
searchMenu.add(findNextItem);
|
||||
findNextItem.addActionListener(this);
|
||||
|
||||
// Create the URL field
|
||||
urlField = new TextField("", 30);
|
||||
urlField.addActionListener(this);
|
||||
|
@ -128,6 +163,7 @@ public class EMWindow extends Frame implements ActionListener, DocumentLoadListe
|
|||
System.out.println("destroying the BrowserControl");
|
||||
EMWindow.this.delete();
|
||||
// should close the BrowserControlCanvas
|
||||
creator.DestroyEMWindow(winNum);
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
|
@ -239,9 +275,9 @@ public void delete()
|
|||
}
|
||||
|
||||
|
||||
public void actionPerformed (ActionEvent evt) {
|
||||
public void actionPerformed (ActionEvent evt) {
|
||||
String command = evt.getActionCommand();
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Navigation navigation = (Navigation)
|
||||
|
@ -250,7 +286,35 @@ public void delete()
|
|||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
History history = (History)
|
||||
browserControl.queryInterface(BrowserControl.HISTORY_NAME);
|
||||
if (command.equals("Stop")) {
|
||||
if (evt.getSource() instanceof MenuItem) {
|
||||
if (command.equals("New Window")) {
|
||||
creator.CreateEMWindow();
|
||||
}
|
||||
else if (command.equals("Close")) {
|
||||
System.out.println("Got windowClosing");
|
||||
System.out.println("destroying the BrowserControl");
|
||||
EMWindow.this.delete();
|
||||
// should close the BrowserControlCanvas
|
||||
creator.DestroyEMWindow(winNum);
|
||||
}
|
||||
else if (command.equals("Find")) {
|
||||
if (null == findDialog) {
|
||||
Frame f = new Frame();
|
||||
f.setSize(350,150);
|
||||
findDialog = new FindDialog(f, this,
|
||||
"Find in Page", "Find ",
|
||||
"", 20, false);
|
||||
findDialog.setModal(false);
|
||||
}
|
||||
findDialog.setVisible(true);
|
||||
// currentPage.findInPage("Sun", true, true);
|
||||
}
|
||||
else if (command.equals("Find Next")) {
|
||||
currentPage.findNextInPage(false);
|
||||
}
|
||||
}
|
||||
|
||||
else if(command.equals("Stop")) {
|
||||
navigation.stop();
|
||||
}
|
||||
else if (command.equals("Refresh")) {
|
||||
|
@ -286,6 +350,57 @@ public void delete()
|
|||
} // actionPerformed()
|
||||
|
||||
|
||||
public void dialogDismissed(Dialog d) {
|
||||
if(findDialog.wasClosed()) {
|
||||
System.out.println("Find Dialog Closed");
|
||||
try {
|
||||
CurrentPage currentPage = (CurrentPage)
|
||||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
currentPage.resetFind();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
String searchString = findDialog.getTextField().getText();
|
||||
if(searchString == null) {
|
||||
System.out.println("Java ERROR - SearchString not received from Dialog Box" +
|
||||
searchString);
|
||||
}
|
||||
else if(searchString.equals("")) {
|
||||
System.out.println("Clear button selected");
|
||||
}
|
||||
else {
|
||||
System.out.println("Tring to Find String - " + searchString);
|
||||
System.out.println("Parameters are - Backwrads = " + findDialog.backwards + " and Matchcase = " + findDialog.matchcase);
|
||||
try {
|
||||
CurrentPage currentPage = (CurrentPage)
|
||||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
currentPage.findInPage(searchString, !findDialog.backwards, findDialog.matchcase);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dialogCancelled(Dialog d) {
|
||||
System.out.println("Find Dialog Closed");
|
||||
try {
|
||||
CurrentPage currentPage = (CurrentPage)
|
||||
browserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME);
|
||||
currentPage.resetFind();
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void makeItem (Panel p, Object arg, int x, int y, int w, int h, double weightx, double weighty) {
|
||||
GridBagLayout gbl = (GridBagLayout) p.getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
|
|
@ -29,9 +29,6 @@ package org.mozilla.webclient.test;
|
|||
* EmbeddedMozilla.java
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import org.mozilla.webclient.*;
|
||||
import org.mozilla.util.Assert;
|
||||
|
||||
|
@ -41,100 +38,48 @@ import org.mozilla.util.Assert;
|
|||
* This is a test application for using the BrowserControl.
|
||||
|
||||
*
|
||||
* @version $Id: EmbeddedMozilla.java,v 1.2 2000/03/13 18:42:02 edburns%acm.org Exp $
|
||||
* @version $Id: EmbeddedMozilla.java,v 1.3 2000/04/06 17:33:33 ashuk%eng.sun.com Exp $
|
||||
*
|
||||
* @see org.mozilla.webclient.BrowserControlFactory
|
||||
|
||||
*/
|
||||
|
||||
public class EmbeddedMozilla extends Frame implements ActionListener
|
||||
public class EmbeddedMozilla
|
||||
{
|
||||
|
||||
public static String binDir;
|
||||
public static String url;
|
||||
public static int winCount = 0;
|
||||
public static String NEW_BUTTON_LABEL = "New Window";
|
||||
|
||||
public static int width = 200;
|
||||
public static int height = 100;
|
||||
|
||||
private Panel buttonPanel;
|
||||
public static int count = 0;
|
||||
public EMWindow[] EMWindow_Arr;
|
||||
|
||||
public static void printUsage()
|
||||
{
|
||||
System.out.println("usage: java org.mozilla.webclient.test.EMWindow <path> [url]");
|
||||
System.out.println("usage: java org.mozilla.webclient.test.EmbeddedMozilla <path> [url]");
|
||||
System.out.println(" <path> is the absolute path to the native browser bin directory, ");
|
||||
System.out.println(" including the bin.");
|
||||
}
|
||||
|
||||
public EmbeddedMozilla()
|
||||
{
|
||||
super("EmbeddedMozilla Launcher");
|
||||
setSize(200, 100);
|
||||
buttonPanel = new Panel();
|
||||
buttonPanel.setLayout(new GridBagLayout());
|
||||
|
||||
// Add the buttons
|
||||
makeItem(buttonPanel, NEW_BUTTON_LABEL, 0, 0, 1, 1, 0.0, 0.0);
|
||||
add(buttonPanel, BorderLayout.CENTER);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.out.println("Got windowClosing");
|
||||
System.out.println("bye");
|
||||
System.exit(0);
|
||||
// should close the BrowserControlCanvas
|
||||
CreateEMWindow();
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.out.println("Got windowClosed");
|
||||
public void CreateEMWindow()
|
||||
{
|
||||
System.out.println("Creating new EmbeddedMozilla window");
|
||||
EMWindow aEMWindow ;
|
||||
aEMWindow = new EMWindow("EmbeddedMozila#" + count+1,
|
||||
binDir, url, count, this);
|
||||
count++;
|
||||
}
|
||||
|
||||
public void DestroyEMWindow(int winNumber) {
|
||||
count--;
|
||||
if (count == 0) {
|
||||
System.out.println("closing application");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
pack();
|
||||
show();
|
||||
toFront();
|
||||
}
|
||||
|
||||
public void actionPerformed (ActionEvent evt)
|
||||
{
|
||||
String command = evt.getActionCommand();
|
||||
EMWindow newWindow;
|
||||
|
||||
if (command.equals(NEW_BUTTON_LABEL)) {
|
||||
System.out.println("Creating new EmbeddedMozilla window");
|
||||
newWindow = new EMWindow("EmbeddedMozila#" + winCount++,
|
||||
binDir, url);
|
||||
}
|
||||
} // actionPerformed()
|
||||
|
||||
|
||||
private void makeItem (Panel p, Object arg, int x, int y, int w,
|
||||
int h, double weightx, double weighty)
|
||||
{
|
||||
GridBagLayout gbl = (GridBagLayout) p.getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
Component comp;
|
||||
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.gridx = x;
|
||||
c.gridy = y;
|
||||
c.gridwidth = w;
|
||||
c.gridheight = h;
|
||||
c.weightx = weightx;
|
||||
c.weighty = weighty;
|
||||
if (arg instanceof String) {
|
||||
Button b;
|
||||
|
||||
comp = b = new Button((String) arg);
|
||||
b.addActionListener(this);
|
||||
|
||||
p.add(comp);
|
||||
gbl.setConstraints(comp, c);
|
||||
}
|
||||
} // makeItem()
|
||||
|
||||
|
||||
public static void main(String [] arg)
|
||||
{
|
||||
|
@ -147,6 +92,7 @@ public static void main(String [] arg)
|
|||
// set class vars used in EmbeddedMozilla ctor
|
||||
binDir = arg[0];
|
||||
url = urlArg;
|
||||
|
||||
EmbeddedMozilla em = new EmbeddedMozilla();
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public void findInPage(String stringToFind, boolean forward, boolean matchCase)
|
|||
myFactory.throwExceptionIfNotInitialized();
|
||||
|
||||
synchronized(myBrowserControl) {
|
||||
nativeFindInPage(stringToFind, forward, matchCase);
|
||||
nativeFindInPage(nativeWebShell, stringToFind, forward, matchCase);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public void findNextInPage(boolean forward)
|
|||
myFactory.throwExceptionIfNotInitialized();
|
||||
|
||||
synchronized(myBrowserControl) {
|
||||
nativeFindNextInPage(forward);
|
||||
nativeFindNextInPage(nativeWebShell, forward);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ public void resetFind()
|
|||
myFactory.throwExceptionIfNotInitialized();
|
||||
|
||||
synchronized(myBrowserControl) {
|
||||
nativeResetFind();
|
||||
nativeResetFind(nativeWebShell);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,9 +160,9 @@ public void selectAll()
|
|||
|
||||
native public void nativeCopyCurrentSelectionToSystemClipboard(int webShellPtr);
|
||||
|
||||
native public void nativeFindInPage(String stringToFind, boolean forward, boolean matchCase);
|
||||
native public void nativeFindInPage(int webShellPtr, String stringToFind, boolean forward, boolean matchCase);
|
||||
|
||||
native public void nativeFindNextInPage(boolean forward);
|
||||
native public void nativeFindNextInPage(int webShellPtr, boolean forward);
|
||||
|
||||
native public String nativeGetCurrentURL(int webShellPtr);
|
||||
|
||||
|
@ -174,7 +174,7 @@ native public String nativeGetSource();
|
|||
|
||||
native public byte [] nativeGetSourceBytes();
|
||||
|
||||
native public void nativeResetFind();
|
||||
native public void nativeResetFind(int webShellPtr);
|
||||
|
||||
native public void nativeSelectAll();
|
||||
|
||||
|
@ -190,7 +190,7 @@ public static void main(String [] args)
|
|||
Assert.setEnabled(true);
|
||||
Log.setApplicationName("CurrentPageImpl");
|
||||
Log.setApplicationVersion("0.0");
|
||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.2 2000/03/09 23:22:50 edburns%acm.org Exp $");
|
||||
Log.setApplicationVersionDate("$Id: CurrentPageImpl.java,v 1.3 2000/04/06 17:33:47 ashuk%eng.sun.com Exp $");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public NativeEventThread(String threadName, BrowserControl yourBrowserControl)
|
|||
public void delete()
|
||||
{
|
||||
// setting this to null causes the run thread to exit
|
||||
synchronized(this.browserControlCanvas.getTreeLock()) {
|
||||
synchronized(this) {
|
||||
// this has to be inside the synchronized block!
|
||||
browserControlCanvas = null;
|
||||
}
|
||||
|
@ -191,12 +191,14 @@ public void run()
|
|||
}
|
||||
|
||||
while (true) {
|
||||
synchronized (this.browserControlCanvas.getTreeLock()) {
|
||||
synchronized (this) {
|
||||
// this has to be inside the synchronized block!
|
||||
if (null == this.browserControlCanvas) {
|
||||
return;
|
||||
}
|
||||
nativeProcessEvents(nativeWebShell);
|
||||
synchronized (this.browserControlCanvas.getTreeLock()) {
|
||||
nativeProcessEvents(nativeWebShell);
|
||||
}
|
||||
|
||||
if (null != listenersToAdd && !listenersToAdd.isEmpty()) {
|
||||
tempEnum = listenersToAdd.elements();
|
||||
|
@ -230,7 +232,7 @@ void addListener(WebclientEventListener newListener)
|
|||
Assert.assert(-1 != nativeWebShell);
|
||||
Assert.assert(null != windowControl);
|
||||
|
||||
synchronized (this.browserControlCanvas.getTreeLock()) {
|
||||
synchronized (this) {
|
||||
if (null == listenersToAdd) {
|
||||
listenersToAdd = new Vector();
|
||||
}
|
||||
|
@ -258,7 +260,6 @@ void nativeEventOccurred(WebclientEventListener target, long eventType)
|
|||
WebclientEvent event = null;
|
||||
|
||||
if (target instanceof DocumentLoadListener) {
|
||||
System.out.println("debug: edburns: creating DocumentLoadEvent");
|
||||
event = new DocumentLoadEvent(this, eventType);
|
||||
}
|
||||
// else...
|
||||
|
@ -266,7 +267,6 @@ void nativeEventOccurred(WebclientEventListener target, long eventType)
|
|||
// PENDING(edburns): maybe we need to put this in some sort of
|
||||
// event queue?
|
||||
|
||||
System.out.println("About to call eventDispatched on listener");
|
||||
target.eventDispatched(event);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче