Initial checkin of Java Util classes and the Java Wrapper to WebShell

Util docs:  http://www.mozilla.org/projects/blackwood/java-util/
Java Wrapper to WebShell docs: http://www.mozilla.org/projects/blackwood/webclient/
This commit is contained in:
edburns%acm.org 1999-07-30 01:03:12 +00:00
Родитель 80c4f6d45d
Коммит a780fb92b5
34 изменённых файлов: 6782 добавлений и 0 удалений

36
java/Makefile.win Normal file
Просмотреть файл

@ -0,0 +1,36 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java enhancers to mozilla
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH = ..
DIRS = util \
webclient
include <$(DEPTH)\config\rules.mak>

40
java/README Normal file
Просмотреть файл

@ -0,0 +1,40 @@
Here lies the code that comprises the java enhancers to mozilla.
Authors: see the README files for each individual subdirectory
Requirements:
* JDK1.1.7 or greater (may work with lower versions, haven't checked).
* M8 or post M8 mozilla tree
* Perl 5 perl.exe must be in your path
How To Build:
* make it so the directory in which this file resides is a child of your
top level mozilla directory
* Copy the files .\webclient\config\buildpkg.bat and
.\webclient\config\outofdate.pl to mozilla\config. These file were
modified after M8 and the modifications are required to build java.
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie SET JDKHOME=C:\jdk1.1.8
* type "nmake /f makefile.win all" and hope for the best
* this should compile the clasess into %MOZ_SRC%\dist\classes
Problems:
* clobber_all doesn't remove the .class files from dist\classes. You
have to do this manually.
* post to netscape.public.mozilla.java newsgroup
General notes:
* Please update the ChangeLog (changelo) files in the subdiroctories when
you make changes.

37
java/util/Makefile.win Normal file
Просмотреть файл

@ -0,0 +1,37 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The original code is "The Lighthouse Foundation Classes (LFC)"
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java utility classes
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH = ..\..
DIRS = classes
include <$(DEPTH)\config\rules.mak>

41
java/util/README Normal file
Просмотреть файл

@ -0,0 +1,41 @@
Here lies the java classes that comprise the org.mozilla.util pagkage,
sometimes called MJUTIL for Mozilla Java Utils. This is not a complete
program, just a library.
Authors: Rob Davis, Paul Kim, Alan Chung, Ray Ryan, Ed Burns, Keith Bernstein, David-John Burrowes
Requirements:
* JDK1.1.7 or greater (may work with lower versions, haven't checked).
* M8 or post M8 mozilla tree
* Perl 5 perl.exe must be in your path
How To Build:
* make it so the directory in which this file resides is a child of your
top level mozilla\java directory
* Copy the files ..\webclient\config\buildpkg.bat and
..\webclient\config\outofdate.pl to mozilla\config. These file were
modified after M8 and the modifications are required to build java.
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie SET JDKHOME=C:\jdk1.1.8
* type "nmake /f makefile.win all" and hope for the best
* this should compile the clasess into %MOZ_SRC%\dist\classes
Problems:
* clobber_all doesn't remove the .class files from dist\classes. You
have to do this manually.
* post to netscape.public.mozilla.java newsgroup
General notes:
* Please update the ChangeLog (changelo) when you make changes.

4
java/util/changelo Normal file
Просмотреть файл

@ -0,0 +1,4 @@
Wed Jul 28 12:18:34 1999 <edburns@acm.org>
* Created initial distribution and README

Просмотреть файл

@ -0,0 +1,52 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The original code is "The Lighthouse Foundation Classes (LFC)"
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java util classes
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..
# PENDING(edburns): find out where this should really get defined
JAVA_OR_NSJVM=1
NO_CAFE=1
include <$(DEPTH)\config\config.mak>
JAR_MJUTIL_CLASSES = org\mozilla\util
!ifdef JAVA_OR_NSJVM
JDIRS = $(JAR_MJUTIL_CLASSES)
!endif
MJUTIL_JAR_NAME=mjutil$(VERSION_NUMBER).jar
JAVAC_PROG=$(JDKHOME)\bin\javac
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,126 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
/**
* The <B>Assert</B> class provides convenient means for condition testing.
* Class methods in the <B>Assert</B> class can be used to verify certain
* conditions and to raise exceptions if the conditions are not met.
* Assertions are particularly useful during the development of a
* project and may be turned off in production code. Turning off
* exceptions causes <B>Assert</B> not to raise exceptions when conditions
* are not met.<P>
*
* Typical usage:
* <BLOCKQUOTE><TT>
* Assert.assert(Assert.enabled && mytest(), "my test failed");
* </TT></BLOCKQUOTE><P>
*
* Such usage prevents <TT>mytest()</TT> from being executed if assertions
* are disabled. This techinique allows assertions to do time-consuming
* checks (such as <TT>myArray.containsObject(myObject)</TT>) without
* worrying about them impacting the performance of the final release.<P>
*
* If you know that the condition being tested is fast, you may omit the
* <I>enabled</I> flag:
* <BLOCKQUOTE><TT>
* Assert.assert(myValue != null);
* </TT></BLOCKQUOTE><P>
*
* Note that even in this second usage, if assertions are disabled,
* the <B>assert()</B> method will do nothing.<P>
*
* Another usage that is more efficient but bulkier:
* <BLOCKQUOTE><TT>
* if (Assert.enabled && Assert.assert(mytest(), "my test failed"));
* </TT></BLOCKQUOTE><P>
*
* Such usage prevents not only <TT>mytest()</TT> from being executed if
* assertions are disabled but also the assert method itself, and some
* compilers can remove the entire statement if assertions are disabled.<P>
*
* <B>Assert</B> is intended for general condition and invariant testing;
* for parameter testing, use <B>ParameterCheck</B>.
*
* @see ParameterCheck
*/
final public class Assert extends Object {
//
// Public Constants
//
/**
* True if failed assertions should raise exceptions, or false if they
* should do nothing.
*/
static public boolean enabled = true;
/**
* Private constructor prevents instances of this class from being created.
*/
private Assert() {}
/**
* Sets <I>enabled</I> to <I>newEnabled</I>.
*
* @param newEnabled true if and only if assertions should be
* enabled
*/
static public void setEnabled(boolean newEnabled) {
enabled = newEnabled;
}
/**
* Throws <B>AssertionFailureException</B> with a message of <I>message</I>
* if <I>enabled</I> is true and <I>test</I> is false; otherwise, does nothing.
*
* @param test value to verify
* @param message message of exception thrown if <I>test</I> is false
* @exception AssertionFailureException if <I>test</I> is false
* @return true
*/
static public boolean assert (boolean test, String message) {
if (enabled && !test) {
throw new AssertionFailureException (message);
}
return true;
}
/**
* Throws <B>AssertionFailureException</B> if <I>enabled</I> is true and
* <I>test</I> is false; otherwise, does nothing.
*
* @param test value to verify
* @exception AssertionFailureException if <I>test</I> is false
* @return true
*/
static public boolean assert (boolean test) {
if (enabled && !test) {
throw new AssertionFailureException ();
}
return true;
}
} // End of class Assert

Просмотреть файл

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
// CUAssertionFailureException.java
//
// $Id: AssertionFailureException.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $
//
package org.mozilla.util;
/**
* This exception is thrown when an <B>Assert.assert()</B> fails.
*
* @see Assert
*/
public class AssertionFailureException
extends RuntimeException {
public AssertionFailureException () { super(); }
public AssertionFailureException (String s) { super("\n" + s + "\n"); }
} // End of class AssertionFailureException

Просмотреть файл

@ -0,0 +1,515 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Date;
/**
* <P>
* <B>Debug</B> Vendor of debug "filter" strings set & queried by clients. This allows
* conditional code to only be executed if a certain filter is set.<BR>
*
* <I>Example of use from <B>JAG</B> days:<BR>
* JDApplication allows the setting of filters from the commandline at app startup time,
* and Log supports printing debug messages only when a specific filter string has
* been set.</I>
*
* <P>
*
* Alternatively, users can use the System Properties table to define
* filter strings at runtime: <P>
*
* <CODE>
* java -DDebug.filters=String ... <P>
* </CODE>
*
* where String is comma (,) separated list of constants <B>WITH NO
* WHITESPACE</B>. ie "AXISPANEL_PAINT,BODYPANEL_PAINT". <P>
*
*
* All filters are case-sensitive.
*
* This class also provides various timing routines.
*
* </P>
* @author Keith Bernstein
* @version $Id: Debug.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $ */
public class Debug extends Object {
static public final String HELP_FILTER_STRING = "HELP";
static public final String ALL_FILTER_STRING = "ALL";
static public final String TIMING_FILTER_STRING = "TIMING";
static public final String PROGRESS_FILTER_STRING = "PROGRESS";
/** the name in the properties table where we look for filter strings */
static final String PROPERTY_NAME = "Debug.filters";
static final String SEP = ",";
static boolean showedColumnTitleHelp = false;
// PENDING(kbern) When we start using JDK 1.2, we should change this filters Vector to a
// "Set" in the new collection API for increased access and verification times.
static Vector filters = null;
static long initializationTime = new Date().getTime();
static long lastTime = initializationTime;
static long startTime = 0L;
static long lapTime = 0L;
static {
/** This code adds to the filters Vector from the
* System.Properties variable named by PROPERTY_NAME
* The value of this variable must be a SEP separeted list
* and contain *NO WHITESPACE*!!
*/
String flags = System.getProperty(PROPERTY_NAME);
if (null != flags) {
Vector flagVector = Utilities.vectorFromString(flags, SEP);
int i, size = (null != flagVector) ? flagVector.size() : 0;
String curFlag;
for (i = 0; i < size; i++) {
curFlag = (String) flagVector.elementAt(i);
Debug.addFilter(curFlag);
}
}
}
/**
* Sets a debug filter, for future consumption by this class, as well as other
* utility classes, like Log, etc.
*
* Virtually all "filters" are simply developer-meaningful strings which will be
* tested within developer code, to conditionally execute code.
*
* There are some predefined filters, which this class actually does something with
* (besides simply handing it back when asked for).
*
* The predefined filters are:
* HELP
* ALL
* TIMING
*
* If the "HELP" filter is found, this class will print a message displaying the
* predefined filters and what they do.
*
* If the "ALL" filter is found, this class will return "true" when queried for the
* existence of <B>any</B> filter, effectively turning on all debugging tests.
* This is useful for both quick and easy tests, as well as to find forgotten debug
* filters (see Log class for more info on this).
*
* If the "TIMING" filter is specified, then the time routines will always print
* their info, regardless of what filter string is passed to them. This is useful
* for turning on all timing tests.
* */
static public synchronized void addFilter(String aFilter) {
if (aFilter != null) {
if (filters == null) {
Log.log("Debugging has been enabled.");
Log.log("os name: "+System.getProperty("os.name"));
Log.log("os version: "+System.getProperty("os.version"));
Log.log("Java version: "+System.getProperty("java.version"));
Log.log("Java home: "+System.getProperty("java.home"));
Log.log("User home: "+System.getProperty("user.home"));
filters = new Vector(1);
}
Log.log("Adding debug filter: "+aFilter);
if (!filters.contains(aFilter)) {
filters.addElement(aFilter);
}
if (aFilter.equalsIgnoreCase(Debug.HELP_FILTER_STRING)) {
Log.log("Set one or more debug filters (usually possible from the commandling), then simply wrap your debug code in a test for a particular debug filter, and only execute the code if that filter has been set.");
Log.log("Predifined debug filters:");
Log.log(" HELP [prints this info]");
Log.log(" ALL [causes all calls to \"containsFilter()\" to return \"true\", effectively enabling all filters]");
Log.log(" TIMING [causes all timing messages generated by this class to print]");
}
} else {
throw new IllegalArgumentException("null filter passed to addFilter()");
}
}
/**
* Removes the specified filter from the list of filters.
*/
static public synchronized void removeFilter(String aFilter) {
if (filters != null) {
filters.removeElement(aFilter);
}
}
/**
* Removes all filters from the list of filters.
*/
static public synchronized void removeAllFilters() {
if (filters != null) {
filters.removeAllElements();
}
}
/**
* Look for any "filter" with the specified prefix.
*
* "ALL" is not considered to be a match.
*
* This method works in (normally) O-n time (if no match).
*/
static public synchronized boolean containsFilterWithPrefix(String aFilterPrefix) {
boolean returnValue = false;
if (Debug.filters != null) {
Enumeration filterEnumeration = Debug.filters.elements();
while (!returnValue && filterEnumeration.hasMoreElements()) {
String aFilter = (String)filterEnumeration.nextElement();
if (aFilter.startsWith(aFilterPrefix)) {
returnValue = true;
}
}
}
return returnValue;
}
/**
* Funnel-point method, which takes a filter and an "allFiltersgMatchThisString" string.
* See the javadoc for "containsFilter(String aFilter)" for the rest of what this method
* does.
*
* This method works in (normally) O-1 time.
*
* NOTE: The "allFiltersgMatchThisString" parameter can be used to conditionally execute
* code while preventing the "ALL" filter from having any effect. So, the conditional code
* should use the test "if (Debug.containsFilter("SomeFilter", ""))" to see if a filter
* has been set, and not get a false positive from the "ALL" filter.
*/
static public synchronized boolean containsFilter(String aFilter, String allFiltersgMatchThisString) {
if (((aFilter != null) && ((filters != null) && filters.contains(aFilter)))
|| ((filters != null) && filters.contains(allFiltersgMatchThisString))
|| (aFilter != null) && aFilter.equals("")) {
return true;
} else {
return false;
}
}
/**
* Returns true if any of the following conditions are true:
* 1. The specified filter is contained in the current filter set.
* 2. The "ALL" filter is set (this is true even if the passed-in filter is "null").
* 3. The passed-in filter is ""... as that filter is considered
* to <B>always</B> be a match, regardless of the current filter set.
* 4. The passed in filter is "null" and the "ALL" filter is currently set.
* Otherwise returns false.
*
* NOTE: This method, and all filtering of this class is case-sensitive.
*/
static public synchronized boolean containsFilter(String aFilter) {
return Debug.containsFilter(aFilter, Debug.ALL_FILTER_STRING);
}
// Only used by the timing routines, since they ignore "ALL", but pay attention to
// "TIMING".
static private synchronized boolean containsTimingFilter(String aFilter) {
return Debug.containsFilter(aFilter, Debug.TIMING_FILTER_STRING);
}
static private synchronized void maybeShowColumnHelp() {
if (!showedColumnTitleHelp) {
Log.enableTimestampPrefix(false);
Log.logErrorMessage("************************:");
Log.logErrorMessage("Debugging time codes:");
Log.logErrorMessage(" etset=elapsed time since elapsed time (since the previous elapsedTime() call)");
Log.logErrorMessage(" etsst=elapsed time since start time (since the previous startTime() call)");
Log.logErrorMessage(" etsit=elapsed time since initialization time (typically since the program was launched)");
Log.logErrorMessage("************************:");
showedColumnTitleHelp = true;
Log.enableTimestampPrefix(false);
}
}
// We don't use Log's debugging logging methods for a few reasons:
// - They check for filters, but we've already had to check ourselves because of the
// "TIMING" filter, so we don't want to waste time checking again.
// - It doesn't know about "TIMING", so if the filter was null, it would assume that
// "ALL" was set, not "TIMING".
// - We need to add a suffix to the "baseName" of the filter that we deduce, and Log
// doesn't want to provide such a method ('cause it would be gross :-))
// - We don't want the time and day stamp on each message, and though we could disable
// that around each call to Log's debugMessage stuff, that's pretty gross.
static private synchronized void logTimingMessageString(String debugMessage, String debugFilter) {
String filterString;
if (debugFilter == null) {
if (Debug.containsFilter(Debug.TIMING_FILTER_STRING)) {
filterString = Debug.TIMING_FILTER_STRING;
} else {
// Quiets compiler... If we're here, we should always be able to set it below.
filterString = "UNMATCHED FILTER";
}
} else if (debugFilter.equals("")) {
filterString = "ANY";
} else {
filterString = debugFilter;
}
String baseStr = Log.getApplicationName();
if ( baseStr == null) {
System.err.println("["+filterString+"]: "+ debugMessage);
System.err.flush();
}
else {
System.err.println(baseStr + "["+filterString+"]: "+ debugMessage);
System.err.flush();
}
}
/**
* Starts a timer which can be stopped using one of the "stopTiming()" methods.
*
* This method does not check debug filters... it always does what it's told.
*
* Calling this method resets the elapsed time ("lap time").
*/
static public synchronized void startTiming() {
startTime = new Date().getTime();
lapTime = startTime;
}
/**
* Identical to the "startTiming(String logMessage, String aFilter)" method, except it
* will only show the message if the filter "TIMING" exists in Debug's filter list.
*/
static public synchronized void startTiming(String logMessage) {
Debug.startTiming(logMessage, Debug.TIMING_FILTER_STRING);
}
/**
* This method does absolutely nothing unless:
* 1. The specified filter is contained in the current filter set.
* 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null").
* 3. The passed-in filter is ""... as that filter is considered
* to <B>always</B> be a match, and so will cause this method to always work,
* regardless of the current filter set.
* NOTE: The "ALL" filter has no effect on timing methods.
*
* Otherwise, starts a timer which can be stopped using one of the "stopTiming()" methods
* and prints out a logMessage indicating that timing has begun.
*
* This method may be called with a "null" logMessage. A logMessage is sometimes
* unneccesary since the matched filter string is printed with the output anyway, and that
* is frequently enough information.
*
* Calling this method resets the elapsed time ("lap time").
*/
static public synchronized void startTiming(String logMessage, String aFilter) {
if (Debug.containsTimingFilter(aFilter)) {
if (logMessage == null) {
logMessage = "";
} else {
logMessage = " ["+logMessage+"]";;
}
Debug.maybeShowColumnHelp();
Debug.startTiming();
Debug.logTimingMessageString("Resetting start time at etsit of: "+Debug.formatTime(Debug.elapsedTimeSinceInitialization())+logMessage, aFilter);
}
}
static private synchronized long elapsedTime(long startTime) {
lapTime = new Date().getTime();
return lapTime - startTime; // "lapTime" happens to be currTime right now!
}
/**
* Returns the elapsed time since this class was initialized.
*
* This method does not check debug filters... it always does what it's told.
*
* Calling this method resets the elapsed time ("lap time").
*
* This method may be called repeatedly to get "lap" times.
*/
static public synchronized long elapsedTimeSinceInitialization() {
return Debug.elapsedTime(initializationTime);
}
/**
* Returns the elapsed time since the preceeding startTiming() call,
*
* This method does not check debug filters... it always does what it's told.
*
* Calling this method resets the elapsed time ("lap time").
*
* This method may be called repeatedly to get "lap" times.
*/
static public synchronized long elapsedTimeSinceStartTime() {
if (startTime == 0) {
return 0L; // "startTime()" was never called.
} else {
return Debug.elapsedTime(startTime);
}
}
/**
* Returns the elapsed time since this class was initialized.
*
* This method does not check debug filters... it always does what it's told.
*
* Calling this method resets the elapsed time ("lap time").
*
* This method may be called repeatedly to get "lap" times.
*/
static public synchronized long elapsedTimeSinceElapsedTime() {
if (lapTime == 0) {
return 0L; // "elapsedTimeXXX()" was never called.
} else {
return Debug.elapsedTime(lapTime);
}
}
/**
* Identical to the "elapsedTime(String logMessage, String aFilter)" method, except it
* will only show the message if the filter "TIMING" exists in Debug's filter list.
*/
static public synchronized void elapsedTime(String logMessage) {
Debug.elapsedTime(logMessage, Debug.TIMING_FILTER_STRING);
}
/**
* This method does absolutely nothing unless:
* 1. The specified filter is contained in the current filter set.
* 2. The "TIMING" filter is set (this is true even if the passed-in filter is "null").
* 3. The passed-in filter is ""... as that filter is considered
* to <B>always</B> be a match, and so will cause this method to always work,
* regardless of the current filter set.
* NOTE: The "ALL" filter has no effect on timing methods.
*
* Otherwise, prints the following information:
* 1. The elapsed time since initialization of this class.
* 2. The elapsed time since the preceeding startTiming() call.
* 3. The "lap" time, since the last time "elapsedTime()" was called.
* 4. A client-supplied message.
*
* When a filter matches, this method invokes the following methods:
* elapsedTime()
* elapsedTimeSinceInitialization()
* elapsedTimeSinceElapsedTime()
*
* When a filter matches, calling this method resets the elapsed time ("lap time").
*
*
* This method may be called with a "null" logMessage. A logMessage is sometimes
* unneccesary since the matched filter string is printed with the output anyway, and that
* is frequently enough information.
*
* This method may be called repeatedly to get "lap" times.
*/
static public synchronized void elapsedTime(String logMessage, String aFilter) {
if (Debug.containsTimingFilter(aFilter)) {
if (logMessage == null) {
logMessage = "";
} else {
logMessage = " ["+logMessage+"]";;
}
Debug.maybeShowColumnHelp();
Debug.logTimingMessageString("etset: "+Debug.formatTime(Debug.elapsedTimeSinceElapsedTime())+" etsst: "+Debug.formatTime(Debug.elapsedTimeSinceStartTime())+" etsit: "+Debug.formatTime(Debug.elapsedTimeSinceInitialization())+logMessage, aFilter);
}
}
/**
* format end - start to sec.millisec
*/
static private synchronized String formatTime(long milliseconds) {
String d1000sStr = String.valueOf( milliseconds % 1000);
int len = d1000sStr.length();
return String.valueOf(milliseconds / 1000)+"."+
"000".substring(len) + d1000sStr;
}
/**
* format time to %4u%03u so that the decimal points will align
*/
private static synchronized String formatTimeAligned(long milliseconds) {
long deltaSecs = milliseconds / 1000;
String dSecsStr = null;
if ( deltaSecs == 0)
dSecsStr = " ";
else {
dSecsStr = String.valueOf( deltaSecs);
int len = dSecsStr.length();
dSecsStr = " ".substring( len) + dSecsStr;
}
String d1000sStr = String.valueOf( milliseconds % 1000);
int len = d1000sStr.length();
return dSecsStr + "." + "000".substring(len) + d1000sStr;
}
/**
* Print time since start of app, and time since the last time this method
* was called.
* Call this with a msg you want printed, and a filter. Then
* run with -jsdebug filter and all these timing msgs will come out.
*/
static public synchronized void printTime( String msg, String aFilter) {
if ( filters != null && filters.contains( aFilter)) {
long curTime = System.currentTimeMillis();
System.out.println( formatTimeAligned( curTime -
initializationTime) + " " +
formatTimeAligned( curTime - lastTime) + " " +
msg);
System.out.flush();
lastTime = curTime;
}
}
/**
* Returns a String containing the hexadecimal hashCode of the passed in object,
* of the form: "0x0000"
*/
static public synchronized String getHashCode(Object anObject) {
String returnValue;
if (anObject == null) {
returnValue = "0x0000";
} else {
returnValue = "0x"+Integer.toHexString(anObject.hashCode());
}
return returnValue;
}
/**
* Returns a String containing the class name and hexadecimal hashCode of the
* passed in object, of the form: "fully.qualified.ClassName[0x0000]"
*/
static public synchronized String getNameAndHashCode(Object anObject) {
String returnValue;
if (anObject == null) {
returnValue = "<null>[0x0000]";
} else {
returnValue = anObject.getClass().getName()+"["+Debug.getHashCode(anObject)+"]";
}
return returnValue;
}
} // End of class Debug

Просмотреть файл

@ -0,0 +1,229 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
import java.util.Date;
/**
* <P>
* <B>Log</B>
* </P>
* @author Keith Bernstein
* @version $Id: Log.java,v 1.1 1999-07-30 01:02:57 edburns%acm.org Exp $
*/
public class Log extends Object {
static String applicationName = "APPLICATION NAME UNKNOWN [call setApplicationName() from main]";
static String applicationVersion = "APPLICATION VERSION UNKNOWN [call setApplicationVersion() from main]";
static String applicationVersionDate = "APPLICATION VERSION DATE UNKNOWN [call setApplicationVersionDate() from main]";
static int showTimestampPrefix = 1;
/**
* This string will be prepended to all output from this class.
*
* This string is usually the application name, e.g. "JavaPlan".
*
* It is useful because it includes a timestamp and the base string (usually the
* application name), so that if two apps are launched from the same commandline
* (for example), with "&", or one app invokes another, it is clear who the message
* is comming from. The time stamp can help see how long operations took, etc.
*
* If you don't want your messages prefixed with anything (no time stamp or name), you must
* pass "null" for "applicationName".
*
* If this method is never called, "applicationName" will default to:
* "APPLICATION NAME UNKNOWN [call setApplicationName from main]"
*
*/
static public synchronized void setApplicationName(String newApplicationName) {
// It's really unfortunate that we can't discover this dynamically.
applicationName = newApplicationName;
}
/**
* Returns the applicationName set by "setApplicationName()"
*
*/
static public synchronized String getApplicationName() {
// It's really unfortunate that we can't discover this dynamically.
return applicationName;
}
static public synchronized void setApplicationVersion(String newApplicationVersion) {
// It's really unfortunate that we can't discover this dynamically.
applicationVersion = newApplicationVersion;
}
/**
* Returns the applicationVersion set by "setApplicationVersion()"
*
*/
static public synchronized String getApplicationVersion() {
// It's really unfortunate that we can't discover this dynamically.
return applicationVersion;
}
static public synchronized void setApplicationVersionDate(String newApplicationVersionDate) {
// It's really unfortunate that we can't discover this dynamically.
applicationVersionDate = newApplicationVersionDate;
}
/**
* Returns the applicationVersion set by "setApplicationVersionDate()"
*
*/
static public synchronized String getApplicationVersionDate() {
// It's really unfortunate that we can't discover this dynamically.
return applicationVersionDate;
}
static protected synchronized Object applicationNameWithTimeStamp() {
String timestampPrefix;
if (showTimestampPrefix > 0) {
timestampPrefix = "["+new Date()+"] ";
} else {
timestampPrefix = "";
}
if (applicationName != null) {
return timestampPrefix+Log.getApplicationName();
} else {
return timestampPrefix;
}
}
/**
* Incrememnts or decrements whether or not to prefix logged messages with a timestamp.
* Two (or "n") calls with a value of "false" must be followed by two (or "n") calls
* with a value of "true" to reenable timestamp prefixes.
*/
static public synchronized void enableTimestampPrefix(boolean enable) {
if (enable) {
showTimestampPrefix++;
} else {
showTimestampPrefix--;
}
}
/**
* Writes "infoMessage" to stdout, prefixed by the string "ApplicationName: "
*/
static public synchronized void log(Object infoMessage) {
System.out.println(Log.applicationNameWithTimeStamp()+": "+infoMessage);
System.out.flush();
}
/**
* Writes "errorMessage" to stderr, prefixed by the string "ApplicationName error: "
*/
static public synchronized void logError(Object errorMessage) {
System.err.println(Log.applicationNameWithTimeStamp()+" error: "+errorMessage);
System.err.flush();
}
/**
* Writes "errorMessage" to stderr, prefixed by the string "ApplicationName: "
*/
static public synchronized void logErrorMessage(Object errorMessage) {
System.err.println(Log.applicationNameWithTimeStamp()+": "+errorMessage);
System.err.flush();
}
static private synchronized void logErrorMessage(String baseNameSuffixString, Object errorMessage) {
System.err.println(Log.applicationNameWithTimeStamp()+baseNameSuffixString+": "+errorMessage);
System.err.flush();
}
/**
* Funnel-point method for printing debug messages.
*
* Writes "debugMessage" to stderr, prefixed by the string "ApplicationName:"
*
* This method only works if the debugFilter string is found in Debug's list of
* filter strings (which you can normally set on the commandline, see JDApplication),
* or if the "ALL" filter has been set into Debug's list of filters, or if the passed
* in filter is "", which is considered to always be "set", and will print a line with
* "[DEBUG]" listed as the filter.
*
* This method may be called with a "null" debugMessage. A debugMessage is sometimes
* unneccesary since the matched filter string is printed with the output anyway, and that
* is frequently enough information.
*/
static public synchronized void logDebugMessage(Object debugMessage, String debugFilter) {
if (Debug.containsFilter(debugFilter)) {
String filterString;
if (debugFilter == null) {
if (Debug.containsFilter(Debug.ALL_FILTER_STRING)) {
filterString = Debug.ALL_FILTER_STRING;
} else {
// Quiets compiler... If we're here, we should always be able to set it below.
filterString = "UNMATCHED FILTER";
}
} else if (debugFilter.equals("")) {
filterString = "DEBUG";
} else {
filterString = debugFilter;
}
Log.logErrorMessage("["+filterString+"]", debugMessage);
}
}
/**
* Equivalent to calling "logDebugMessage(debugMessage, "ALL")".
*/
static public synchronized void logDebugMessage(Object debugMessage) {
logDebugMessage(debugMessage, "ALL");
}
/**
* Log a message when "aCondition" is true, otherwise be silent.
* Equivalent to calling "if (aCondition) logDebugMessage(debugMessage, "")".
*/
static public synchronized void logDebugMessage(Object debugMessage, boolean aCondition) {
if (aCondition) {
Log.logDebugMessage(debugMessage, "");
}
}
/**
* Log a message when "aCondition" is true, otherwise be silent.
*/
static public synchronized void logDebugMessage(Object anInstance, Object debugMessage, boolean aCondition) {
if (aCondition) {
Log.logDebugMessage(Debug.getNameAndHashCode(anInstance)+": "+debugMessage, "");
}
}
/**
* Equivalent to calling "logDebugMessage(anInstance, debugMessage, "ALL")".
*/
static public synchronized void logDebugMessage(Object anInstance, Object debugMessage) {
Log.logDebugMessage(anInstance, debugMessage, "ALL");
}
/**
* Writes "debugMessage" to stderr, prefixed by the string "ApplicationName: ClassName[0xhashCode]: " *
*/
static public synchronized void logDebugMessage(Object anInstance, Object debugMessage, String debugFilter) {
Log.logDebugMessage(Debug.getNameAndHashCode(anInstance)+": "+debugMessage, debugFilter);
}
} // End of class Log

Просмотреть файл

@ -0,0 +1,372 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
/**
* ParameterCheck provides convenient means for parameter
* checking. Class methods in the ParameterCheck class can be
* used to verify that method parameters meet certain conditions and to
* raise exceptions if the conditions are not met.<p>
*
* Typical usage:
* <BLOCKQUOTE><TT>
* ParameterCheck.nonNull(myParameter);
* </TT></BLOCKQUOTE><P>
*
* This verifies that <TT>myParameter</TT> is not null, throwing an
* IllegalArgumentException if it is.<P>
*
* ParameterCheck is intended specifically for checking parameters;
* for general condition and invariant testing, use Assert.
*
* @version $Id: ParameterCheck.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $
* @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc)
* @author David-John Burrowes (he moved it to the AU package)
* @see Assert
*/
final public class ParameterCheck extends Object {
/**
* The RCSID for this class.
*/
private static final String RCSID =
"$Id: ParameterCheck.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $";
/**
* Private constructor prevents instances of this class from being
* created.
*/
private ParameterCheck() {
}
/**
* Throws IllegalArgumentException if 'anObject' is null; otherwise, does
* nothing.
*
* @param anObject value to verify as non-null
* @exception IllegalArgumentException if 'anObject' is null
*/
static public void nonNull(Object anObject) {
if (anObject == null) {
throw new IllegalArgumentException("Object is null");
}
}
/**
* Throws IllegalArgumentException if 'aString' is null or if
* 'aString' is an empty string; otherwise, does nothing.
*
* @param aString string to verify as non-null and not empty
* @exception IllegalArgumentException if 'aString' is null or empty
*/
static public void notEmpty(String aString) {
if (aString == null) {
throw new IllegalArgumentException("String is null");
}
else if (aString.equals("")) {
throw new IllegalArgumentException("String is empty");
}
}
/**
* Throws RangeException if 'anInt' is less than 'minimum'; otherwise,
* does nothing.
*
* @param anInt value to verify as not less than 'minimum'
* @param minimum smallest acceptable value for 'anInt'
* @exception RangeException if 'anInt' is less than 'minimum'
*/
static public void noLessThan(int anInt, int minimum) {
if (anInt < minimum) {
throw new RangeException("Value " + anInt +
" is out of range. It is should be no less than " + minimum);
}
}
/**
* Throws RangeException if 'anInt' is not greater than 'minimum';
* otherwise, does nothing.
*
* @param anInt value to verify as greater than 'minimum'
* @param minimum largest unacceptable value for 'anInt'
* @exception RangeException if 'anInt' is not greater than 'minimum'
*/
static public void greaterThan(int anInt, int minimum) {
if (anInt <= minimum) {
throw new RangeException ("Value " + anInt +
" is out of range. It should be greater than " + minimum);
}
}
/**
* Throws RangeException if 'anInt' is greater than 'maximum'; otherwise,
* does nothing.
*
* @param anInt value to verify as not greater than 'maximum'
* @param maximum largest acceptable value for 'anInt'
* @exception RangeException if 'anInt' is greater than 'maximum'
*/
static public void noGreaterThan(int anInt, int maximum) {
if (anInt > maximum) {
throw new RangeException ("Value " + anInt + "is out of " +
"range. It should be no greater than " + maximum);
}
}
/**
* Throws RangeException if 'anInt' is not less than 'maximum';
* otherwise, does nothing.
*
* @param anInt value to verify as less than 'minimum'
* @param maximum smallest unacceptable value for 'anInt'
* @exception RangeException if 'anInt' is not less than 'maximum'
*/
static public void lessThan(int anInt, int maximum) {
if (anInt >= maximum) {
throw new RangeException ("Value " + anInt +
" is out of range. " +
"It should be less than " + maximum);
}
}
/**
* Throws RangeException if 'aDouble' is less than 'minimum'; otherwise,
* does nothing.
*
* @param aDouble value to verify as not less than 'minimum'
* @param minimum smallest acceptable value for 'aDouble'
* @exception RangeException if 'aDouble' is less than 'minimum'
*/
static public void noLessThan(double aDouble, double minimum) {
if (aDouble < minimum) {
throw new RangeException ("Value " + aDouble +
" is out of range. " +
"It should be no less than " + minimum);
}
}
/**
* Throws RangeException if 'aDouble' is not greater than 'minimum';
* otherwise, does nothing.
*
* @param aDouble value to verify as greater than 'minimum'
* @param minimum largest unacceptable value for 'aDouble'
* @exception RangeException if 'aDouble' is not greater than 'minimum'
*/
static public void greaterThan(double aDouble, double minimum) {
if (aDouble <= minimum) {
throw new RangeException ("Value " + aDouble +
" is out of range. " +
"It should be greater than " + minimum);
}
}
/**
* Throws RangeException if 'aDouble' is greater than
* 'maximum'; otherwise, does nothing.
*
* @param aDouble value to verify as not greater than 'maximum'
* @param maximum largest acceptable value for 'aDouble'
* @exception RangeException if 'aDouble' is greater than 'maximum'
*/
static public void noGreaterThan(double aDouble, double maximum) {
if (aDouble > maximum) {
throw new RangeException ("Value " + aDouble +
" is out of range. " +
"It should be no greater than " + maximum);
}
}
/**
* Throws RangeException if 'aDouble' is not less than 'maximum';
* otherwise, does nothing.
*
* @param aDouble value to verify as less than 'minimum'
* @param maximum smallest unacceptable value for 'aDouble'
* @exception RangeException if 'aDouble' is not less than 'maximum'
*/
static public void lessThan(double aDouble, double maximum) {
if (aDouble >= maximum) {
throw new RangeException ("Value " + aDouble +
" is out of range. It should be less than " + maximum);
}
}
/**
* Throws RangeException if 'anInt' is less than 'minimum' or greater
* than 'maximum'; otherwise, does nothing.
*
* @param anInt value to verify as not greater than 'maximum' and
* not less than 'minimum'
* @param minimum smallest acceptable value for 'anInt'
* @param maximum largest acceptable value for 'anInt'
* @exception RangeException if 'anInt' is less than 'minimum' or
* greater than 'maximum'
*/
static public void withinRange(int anInt, int minimum, int maximum) {
ParameterCheck.noLessThan(anInt, minimum);
ParameterCheck.noGreaterThan(anInt, maximum);
}
/**
* Throws RangeException if 'aDouble' is less than 'minimum' or greater
* than 'maximum'; otherwise, does nothing.
*
* @param aDouble value to verify as not greater than 'maximum' and
* not less than 'minimum'
* @param minimum smallest acceptable value for 'aDouble'
* @param maximum largest acceptable value for 'aDouble'
* @exception RangeException if 'aDouble' is less than 'minimum' or
* greater than 'maximum'
*/
static public void withinRange(double aDouble, double minimum,
double maximum) {
ParameterCheck.noLessThan(aDouble, minimum);
ParameterCheck.noGreaterThan(aDouble, maximum);
}
/**
* Throws RangeException if 'anInt' is not within 'aRange'; otherwise,
* does nothing.
*
* @param anInt value to verify as within 'aRange'
* @param aRange acceptable range for 'anInt'
* @exception RangeException if 'anInt' is not within 'aRange'
*/
static public void withinRange(int anInt, Range aRange) {
if (!aRange.containsIndex(anInt)) {
throw new RangeException ("Value " + anInt +
" should be in range " + aRange);
}
}
/**
* Throws RangeException if 'anInt' is not within a sequence that starts
* at 0 and has a length of 'count'; otherwise does nothing.
*
* (e.g. withinCount(myInt, array.length) will verify that 'myInt' is not
* less than 0 and not greater than 'array.length'-1)
*
* @param anInt value to verify as between 0 and 'count' - 1, inclusive
* @param count length of sequence
* @exception RangeException if 'anInt' is out of bounds
*/
static public void withinCount(int anInt, int count) {
ParameterCheck.withinRange(anInt, 0, count-1);
}
/**
* Throws RangeException if 'aRange' is not completely between 'minimum'
* and 'maximum', inclusive; otherwise, does nothing.
*
* @param aRange range to verify as between 'minimum' and 'maximum'
* @param minimum smallest acceptable index in 'aRange'
* @param maximum largest acceptable index in 'aRange'
* @exception RangeException if 'aRange' is out of bounds
*/
static public void rangeWithinBounds(Range aRange, int minimum,
int maximum) {
if (aRange.getStart() < minimum) {
throw new RangeException ("Range " + aRange +
" should not contain indices less than " +
minimum);
}
if (aRange.getEnd() > maximum) {
throw new RangeException ("Range " + aRange +
" should not contain indices greater than "
+ maximum);
}
}
/**
* Throws RangeException if 'aRange' is not completely within a sequence
* that starts at 0 and has a length of 'count'; otherwise does nothing.
*
* (e.g. rangeWithinCount(range, array.length) will verify that 'range'
* does not start before 0 and does not end after 'array.length'-1).
*
* @param aRange range to verify as between 0 and 'count' - 1, inclusive
* @param count length of sequence
* @exception RangeException if 'aRange' is out of bounds
*/
static public void rangeWithinCount(Range aRange, int count) {
ParameterCheck.rangeWithinBounds(aRange, 0, count-1);
}
/**
* Checks a string and a range which is intended to indicate a substring.
* Throws IllegalArgumentException if either argument is null. Throws
* RangeException if <I>aRange</I> does not indicate a valid substring of
* <I>aString</I>.
*
* @param aRange A range which must be contained within
* the string.
* @param aString A string to use for verifying the range.
* @exception IllegalArgumentException if either argument is null
* @exception RangeException if the range is not contained
* within the string
*/
static public void rangeWithinString(Range aRange, String aString) {
ParameterCheck.nonNull(aString);
ParameterCheck.nonNull(aRange);
if (aRange.getStart() < 0) {
throw new RangeException("Range has negative start");
}
if(aRange.getMax() > aString.length()) {
throw new RangeException("Range extends beyond end of String");
}
}
/**
* Throws IllegalArgumentException if 'generalTest' is false; otherwise,
* does nothing. 'message' will be the message of the exception. 'message'
* may be null, but use of a meaningful message is recommended.
*
* @param generalTest value to verify as true
* @param message message describing the failure
* @exception IllegalArgumentException if 'generalTest' is false
* @see #isFalse(boolean generalTest, String message)
*/
static public void isTrue(boolean generalTest, String message) {
if (!generalTest) {
throw new IllegalArgumentException(message);
}
}
/**
* Identical to isTrue, except the test is inverted.
*
* @param generalTest value to verify as false
* @param message message describing the failure
* @exception IllegalArgumentException if 'generalTest' is false
* @see #isTrue(boolean generalTest, String message)
*/
static public void isFalse(boolean generalTest, String message) {
if (generalTest) {
throw new IllegalArgumentException(message);
}
}
} // End of class ParameterCheck

Просмотреть файл

@ -0,0 +1,467 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
import java.io.Serializable;
import java.lang.Cloneable;
import java.lang.Math;
/**
* An Range is an object representing a range of integer values. A
* range has a start index and a count. The count must be greater than or
* equal to 0. Instances of this class are immutable, but subclasses may
* introduce mutability. A mutable range will return true from
* isMutable().
*
* @version $Id: Range.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $
* @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc)
* @author David-John Burrowes (he moved it to the AU package)
* @see Range#isMutable()
* <!-- see MutableRange -->
*/
public class Range extends Object implements Cloneable, Serializable {
//
// STATIC VARIABLES
//
/**
* The RCSID for this class.
*/
private static final String RCSID =
"$Id: Range.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $";
/**
* A zero range
*/
static public final Range ZeroRange = new Range(-1, 0);
//
// Instance Variables
//
/**
* The start index of the range
*/
protected int start;
/**
* The length of the range
*/
protected int count;
//
// Constructors
//
/**
* Creates an instance of Range from another Range object
* otherRange which must be non-null.
*
* @param range the reference range to create this range from
* @exception IllegalArgumentException if otherRange is null
*/
public Range(Range otherRange) {
//
// Do our own construction rather than calling Range(int,int)
// because we want to be able to do the parameter check. There is
// another way that allows us to use the other constructor, but
// this class is too simple to be worth the exta work.
//
super();
ParameterCheck.nonNull(otherRange);
this.start = otherRange.getStart();
this.count = otherRange.getCount();
}
/**
* Creates an instance of Range with a start index newStart and
* an extent newCount. newCount must be greater than or equal to
* 0.
*
* @param newStart the start index of the range
* @param newCount the number of elements in the range
* @exception RangeException if newCount is less than 0.
*/
public Range(int newStart, int newCount) {
super();
this.start = newStart;
this.count = newCount;
}
//
// PROPERTY ACCESS
//
/**
* Returns the start index of the range.
*
* @return the start index of this range
*/
public synchronized int getStart() {
return this.start;
}
/**
* Returns the number of elements in this range.
*
* @return the number of elements in this range
*/
public synchronized int getCount() {
return this.count;
}
/**
* Returns the the last index contained within the range.
*
* @return the end index of this range
*/
public synchronized int getEnd() {
return this.getStart() + this.getCount() - 1;
}
/**
* Returns the max index (the index at start + count).
*
* @return the max index.
*/
public synchronized int getMax() {
return this.getStart() + this.getCount();
}
/**
* Returns a number guaranteed to be within this range, including
* endpoints
*
* @return a number within the range, including endpoints.
*/
protected int getConstrainedInt(int number) {
int rc;
if (number < this.getStart()) {
rc = this.getStart();
}
else {
if (number > this.getEnd()) {
rc = this.getEnd();
} else {
rc = number;
}
}
return rc;
}
//
// METHODS
//
/**
* Returns true if and only if index lies within this range.
* Note that if the receiver is of zero length, then this method will return
* false.
*
* @return true if and only if and only if index lies within this
* range
*/
public synchronized boolean containsIndex(int index) {
if (this.getCount() == 0) {
return false;
} else {
return (index >= this.getStart()) && (index <= this.getEnd());
}
}
/**
* Returns true if and only if the start index of this range is
* greater than index.
*
* @return true if and only if the start index of this range is
* greater than index
*/
public synchronized boolean isAfterIndex(int index){
return (this.getStart() > index);
}
/**
* Return true if and only if the end index of this range is less than
* index.
*
* @return true if and only if the end index of this range is less than
* index
*/
public synchronized boolean isBeforeIndex(int index)
{
return (this.getEnd() < index);
}
/**
* Returns true if and only if every element in otherRange is contained
* in this range. If the receiver is a zero length range, then
* this method will return false. Note that containment can apply to
* zero length ranges; a non-zero-length range contains any zero-length
* range. Contrast with range intersection.
*
* @see #intersectsWithRange(Range otherRange)
* @return true if and only if every element in otherRange is
* contained in this range
* @exception IllegalArgumentException if otherRange is null
*
*/
public synchronized boolean containsRange (Range otherRange)
{
ParameterCheck.nonNull(otherRange);
if (this.getCount() == 0) {
return false;
} else if (otherRange.getCount() == 0) {
return true;
}
return ((this.getStart() <= otherRange.getStart()) &&
(this.getEnd() >= otherRange.getEnd()));
}
/**
* Returns true if and only if otherRange intersects with this range. A
* zero-length range intersects with no range.
*
* @return true if and only if otherRange intersects with this range
* @exception IllegalArgumentException if otherRange is null
*
*/
public synchronized boolean intersectsWithRange(Range otherRange) {
return this.overlapWithRange(otherRange) > 0;
}
/**
* Returns the number of elements that are in both this range and
* otherRange. A zero-length range has no overlapping elements
* with any range.
*
* @param a range to check overlaps with this range
* @exception IllegalArgumentException if otherRange is null
* @return number of elements in both this range and otherRange
*/
public synchronized int overlapWithRange(Range otherRange) {
if (this.getCount() == 0 || otherRange.getCount() == 0) {
return 0;
} else {
return Math.max(0, (Math.min(this.getEnd(), otherRange.getEnd()) -
Math.max(this.getStart(),
otherRange.getStart())) + 1);
}
}
/**
* Returns true if and only if otherRange is adjacent to this range;
* two ranges are adjacent if the max of one range is equal to the start of
* the other. A zero length range is adjacent to no range.
*
* @return true if and only if otherRange is adjacent to this range
* @exception IllegalArgumentException if otherRange is null
*/
public synchronized boolean isAdjacentToRange(Range otherRange) {
ParameterCheck.nonNull(otherRange);
if (this.getCount() == 0 || otherRange.getCount() == 0) {
return false;
}
return (Math.max(this.getStart(), otherRange.getStart()) ==
(Math.min(this.getEnd(), otherRange.getEnd()) + 1));
}
/**
*
* Returns true if and only if this range is before otherRange
* and the two ranges do not overlap.
*
* @return true if and only if this range is before otherRange
* and the two ranges do not overlap.
* @exception IllegalArgumentException if otherRange is null
*/
public synchronized boolean isBeforeRange(Range otherRange) {
ParameterCheck.nonNull(otherRange);
if (this.getEnd() < otherRange.getStart()) {
return true;
} else {
return false;
}
}
/**
*
* Returns true if this range is after otherRange and the two
* ranges do not overlap.
*
* @return true if this range is after otherRange and the two
* ranges do not overlap.
* @exception IllegalArgumentException if otherRange is null
*/
protected boolean isAfterRange(Range otherRange) {
ParameterCheck.nonNull(otherRange);
return otherRange.isBeforeRange(this);
}
/**
* Returns the intersection of this range and otherRange. If the
* ranges do not intersect then Range.ZeroRange is returned.
* Note that a zero length range has no intersection with a non-zero
* length range.
*
* @return the intersection of this range and otherRange
* @exception IllegalArgumentException if otherRange is null
*/
public synchronized Range rangeFromIntersection(Range otherRange) {
ParameterCheck.nonNull(otherRange);
if (this.intersectsWithRange(otherRange)) {
int newStart = Math.max(this.getStart(), otherRange.getStart());
int newEnd = Math.min(this.getEnd(), otherRange.getEnd());
return new Range(newStart, newEnd - newStart + 1);
}
return Range.ZeroRange;
}
/**
* Returns the union of this range and otherRange.
* Returns the other range if one of them are zero length range.
* Returns Range.ZeroRange if both are zero length range.Note that the
* union of a non-zero length range with a zero length range is merely the
* non-zero length range.
*
* @return the union of this range and otherRange if both are
* non-zero range
* @exception IllegalArgumentException if otherRange is null
*/
public synchronized Range rangeFromUnion(Range otherRange) {
ParameterCheck.nonNull(otherRange);
Range retRange;
int thisRangeCount = this.getCount();
int otherRangeCount = otherRange.getCount();
if (thisRangeCount == 0 && otherRangeCount == 0) {
retRange = ZeroRange;
} else if (thisRangeCount == 0) {
retRange = new Range(otherRange);
} else if (otherRangeCount == 0) {
retRange = new Range(this);
} else {
int newStart;
int newEnd;
newStart = Math.min(this.getStart(), otherRange.getStart());
newEnd = Math.max(this.getEnd(), otherRange.getEnd());
return new Range(newStart, newEnd - newStart + 1);
}
return retRange;
}
/**
* Returns this range, with its start shifted by offset.
*
* @return this range, with its start offset by offset.
*/
public synchronized Range rangeShiftedByOffset(int offset) {
return new Range(this.getStart() + offset, this.getCount());
}
/**
* Returns a String representation of this Range.
*
* @return string representation of this range
*/
public synchronized String toString() {
return "start = " + this.getStart() + ", count = " + this.getCount();
}
/**
* Returns true only if this instance can change after it is created.<P>
*
* The default implementation returns false because instances of this
* class can't change; subclasses that introduce mutability should
* override this method to return true.
*
* @return true if and only if the range may change
*/
public boolean isMutable() {
return false;
}
/**
* Creates and returns an Range that is identical to this one.
*
* @return a reference to the immutable instance or
* a copy of the mutable instance
*/
public synchronized Object clone() {
if (this.isMutable()) {
Range newRange;
try {
newRange = (Range)super.clone();
}
catch (CloneNotSupportedException e) {
// Won't happen because we implement Cloneable
throw new InternalError(e.toString());
}
return newRange;
}
else {
// No reason to clone an immutable object
return this;
}
}
/**
* Returns true if and only if otherRange is an Range
* with the same start and count as this range.
*
* @return true if and only if otherRange equals this range
*/
public synchronized boolean equals(Object otherRange) {
return ((otherRange == this) ||
((otherRange != null) &&
(otherRange instanceof Range) &&
(this.getStart() == ((Range)otherRange).getStart()) &&
(this.getEnd() == ((Range)otherRange).getEnd())));
}
/**
* Overridden because equals() is overridden. Returns a hash code
* that is based on the start and count of this range.
*
* @return a hash code based on the start index and count of this range
*/
public synchronized int hashCode() {
return Math.round(this.getStart()) ^ Math.round(this.getCount());
}
} // End of class Range

Просмотреть файл

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
import java.lang.RuntimeException;
/**
* An RangeException is an exception that is thrown when a value
* is outside of its acceptable range.
*
* @version $Id: RangeException.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $
* @author The LFC Team (Rob Davis, Paul Kim, Alan Chung, Ray Ryan, etc)
* @author David-John Burrowes (he moved it to the AU package)
*/
public class RangeException extends RuntimeException {
//
// STATIC VARIABLES
//
/**
* The RCSID for this class.
*/
private static final String RCSID =
"$Id: RangeException.java,v 1.1 1999-07-30 01:02:58 edburns%acm.org Exp $";
/**
* Constructs an exception with no error string.
*/
public RangeException() {
super();
}
/**
* Constructs an exception with an error string.
*
* @param message A message that will hopefully tell someone about the cause
* of this exception.
*/
public RangeException(String message) {
super(message);
}
}

Просмотреть файл

@ -0,0 +1,285 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is "The Lighthouse Foundation Classes (LFC)"
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.util;
import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;
import java.util.StringTokenizer;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import java.awt.Component;
import java.awt.Container;
public class Utilities extends Object {
// PENDING(kbern) NOTE: These Vector methods should eventually move into a file
// called "VectorUtilities", must like the already-existing "HashtableUtilities".
/**
* Take the given string and chop it up into a series
* of strings on "delimeter" boundries. This is useful
* for trying to get an array of strings out of the
* resource file.
*/
static public Vector vectorFromString(String input, String delimeter) {
Vector aVector = new Vector();
StringTokenizer aTokenizer = new StringTokenizer(input, delimeter);
while (aTokenizer.hasMoreTokens())
aVector.addElement(aTokenizer.nextToken());
return aVector;
}
/**
* Creates a String by combining the elements of aVector.
* after each element it will insert the String "delimeter".
* If no "delimeter" is desired, the "delimeter" parameter should be ""
*/
static public String stringFromVector(Vector aVector, String delimeter) {
String returnString = null;
if (aVector != null) {
Enumeration vectorEnumerator = aVector.elements();
if (delimeter == null) {
delimeter = ""; // Might as well be nice to sloppy caller!
}
while (vectorEnumerator.hasMoreElements()) {
if (returnString == null) {
returnString = "";
} else {
returnString += delimeter;
}
returnString += vectorEnumerator.nextElement();
}
}
return (returnString == null) ? "" : returnString;
}
/**
* Convert an Array into a Vector. Can you *believe* that there is no Vector constructor
* which takes an Array!!! &()*&$#(*&$
*/
static public Vector vectorFromArray(Object[] anArray) {
Vector returnVector;
if ((anArray != null) && (anArray.length > 0)) {
returnVector = new Vector(anArray.length);
for (int i = anArray.length - 1; i >= 0; i--) {
returnVector.addElement(anArray[i]);
}
} else {
returnVector = new Vector(0);
}
return returnVector;
}
/**
* Amazing that "Vector" does not override Object's "equals()" method to do this
* itself!
*/
static public boolean vectorsAreEqual(Vector vectorOne, Vector vectorTwo) {
boolean returnValue = vectorOne.equals(vectorTwo); // Give "Object" a chance.
if (!returnValue && (vectorOne != null) && (vectorTwo != null)) {
int vectorSize = vectorOne.size();
if (vectorSize == vectorTwo.size()) {
int index;
// "Object" says, "No", but maybe they really are... let's do the long check...
for (index = 0; index < vectorSize; index++) {
if (!(vectorOne.elementAt(index).equals(vectorTwo.elementAt(index)))) {
break;
}
}
if (index == vectorSize) {
// We made it to the end without "break"ing! They must be equal...
returnValue = true;
}
} // else, they're definately not equal!
}
return returnValue;
}
/**
* Returns "true" if the passed in array contains the passed in element.
* Checks for equality using ".equals()".
* Returns "false" if "anArray" is null.
*/
static public boolean arrayContainsElement(Object[] anArray, Object anElement) {
boolean returnValue = false;
if (anArray != null) {
for (int index = 0; (!returnValue && (index < anArray.length)); index++) {
if (anArray[index].equals(anElement)) {
returnValue = true;
}
}
}
return returnValue;
}
/**
* Removes leading, trailing, and internal whitespace from the passed-in
* string.
* Returns a new string without any whitespace.
*/
static public String removeAllWhitespace(String aString) {
String returnString = aString;
if (aString != null) {
returnString = aString.trim();
Vector stringComponents = Utilities.vectorFromString(aString, " ");
returnString = Utilities.stringFromVector(stringComponents, "");
}
return returnString;
}
/**
* Can return a string of the form "5:35:09pm", as opposed to "17:35:09"
* If "useTwentyFourHourTime" is "true", returns time in the form "17:35:09"
* If "showAMPMIndicator" is "true" it will include the "am" or "pm" text,
* otherwise it won't.
* Note that the "showAMPMIndicator" field is ignored if "useTwentyFourHourTime" is "true"
* since it provides redundant information in that case.
*/
static public String currentTimeString(boolean useTwentyFourHourTime, boolean showAMPMIndicator) {
// "ugly" is of the form, "17:35:09"
String returnString = new Date().toString().substring(11, 19);
if (!useTwentyFourHourTime) {
Vector dateComponents = Utilities.vectorFromString(returnString, ":");
try {
String ampmString;
int hourField = Integer.parseInt((String)(dateComponents.elementAt(0)));
// Make it on 12 hour clock, with am and pm...
if (hourField > 12) {
// More common than == 12
ampmString = "pm";
hourField -= 12;
dateComponents.setElementAt(Integer.toString(hourField), 0);
returnString = Utilities.stringFromVector(dateComponents, ":");
} else if (hourField == 12) {
ampmString = "pm";
} else {
ampmString = "am";
}
if (showAMPMIndicator) {
returnString += ampmString;
}
} catch (NumberFormatException anException) {
}
}
return returnString;
}
/**
* Uses "getParent()" to find this Component's top-level ancestor.
*
* If this Component has no ancestors, this method will return the Component itself.
*/
static public Component getTopLevelParent(Component aComponent) {
Component returnComponent = aComponent;
if (aComponent != null) {
Component testComponent = aComponent;
do {
if (testComponent instanceof Container) {
returnComponent = testComponent;
testComponent = ((Container)testComponent).getParent();
} else {
testComponent = null;
}
} while (testComponent != null);
}
return returnComponent;
}
/**
* @param aClass the class whose package name should be returned
*
* @return the fully qualified package name of the given class, null
* if not found
*/
static public String getPackageName(Class aClass) {
if (null == aClass) {
return null;
}
String baseName = aClass.getName();
int index = baseName.lastIndexOf('.');
return (index < 0 ? "" : baseName.substring(0, index+1));
}
/**
*
* This method is a simpler alternative to
* ResourceLoader.loadResourceBundle. Instead of returning an
* PropertyResourceBundle, as ResourceLoader.loadResourceBundle
* does, it must returns a java.util.ResourceBundle
*
* @param baseName the fully qualified name of the resource bundle,
* sans "<CODE>.properties</CODE>" suffix. For example, a
* valid value for baseName would be
* <CODE>com.sun.jag.apps.spex.util.SUResources</CODE> when the
* properties file <CODE>SUResources.properties</CODE> is in the
* classpath under the directory
* <CODE>com/sun/jag/apps/spex/util</CODE>.
*
* @return the actual ResourceBundle instance, or null if not found.
* <!-- see ResourceLoader#loadResourceBundle -->
*/
static public ResourceBundle getResourceBundle(String baseName) {
ResourceBundle resourceBundle = null;
try {
resourceBundle = ResourceBundle.getBundle(baseName);
}
catch (MissingResourceException e) {
Log.logError("Missing resource bundle: " + baseName);
}
return resourceBundle;
}
/**
Case insensitive String.endsWith()
*/
public static boolean endsWithIgnoringCase(String aString, String possibleEnding) {
int endingLength;
if (aString == null || possibleEnding == null)
return false;
endingLength = possibleEnding.length();
if (aString.length() < endingLength)
return false;
return aString.regionMatches(true, aString.length() - endingLength,
possibleEnding, 0, endingLength);
}
}

Просмотреть файл

@ -0,0 +1,38 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java wrapper to mozilla
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH = ..\..
DIRS = classes \
src
include <$(DEPTH)\config\rules.mak>

67
java/webclient/README Normal file
Просмотреть файл

@ -0,0 +1,67 @@
Here lies the MozWebShell java wrapper to mozilla M8.
Authors: Kirk Baker <kbaker@eb.com>
Ian Wilkinson <iw@ennoble.co>
Build hacking and packaging: Ed Burns <edburns@acm.org>
Requirements:
* built M8 mozilla tree for WinNT4.0
* JDK1.1.7 or greater
* built org.mozilla.util java classes (see NOTE_UTIL)
* Perl 5 perl.exe must be in your path
How To Build:
* make it so the directory in which this file resides is a child of your
top level mozilla\java directory
* Copy the files .\config\buildpkg.bat and .\config\outofdate.pl to
mozilla\config. These file were modified after M8 and the
modifications are required to build java.
* make sure the environment var JDKHOME is set to your jdk installation
directory, ie SET JDKHOME=C:\jdk1.1.8
* type "nmake /f makefile.win all" and hope for the best
* Due to bug 10561 (http://bugzilla.mozilla.org/show_bug.cgi?id=10561)
one must do a horrendous workaround:
In the directory mozilla/dist/WIN32_D.OBJ/bin, copy the components.reg
file and the components directory to the following places:
C:\WINNT\System32
%JDKHOME%\jre\bin
How to Run:
* once the build has successfully completed, run this batch file:
.\src\WIN32_D.OBJ\runem.bat <opt: YOUR_URL>
Note that YOUR_URL is probably necessary since firewall support wasn't
working in M8.
Problems:
* clobber_all doesn't remove the .class files from dist\classes. You
have to do this manually.
* post to netscape.public.mozilla.java newsgroup
General notes:
* Please update the ChangeLog (changelo) when you make changes.
NOTE_UTIL:
* this package depends on the org.mozilla.util classes, which can be
found in the mozilla tree under mozilla\java\util. They are a
separate checkout and build. Once you check out the org.mozilla.util
classes, see the README in the mozilla\java\util\README.

13
java/webclient/changelo Normal file
Просмотреть файл

@ -0,0 +1,13 @@
Wed Jul 28 12:17:30 1999 <edbuns@acm.org>
* Renamed MozWebShell to webclient.BrowserControl
* Moved util classes into separate package
* updated README accordingly
Mon Jul 26 21:32:18 1999 <edburns@acm.org>
* Prepared the initial checkin of MozWebShell. Need to rename to
org.mozilla.webclient.BrowserControl.

Просмотреть файл

@ -0,0 +1,56 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1999 Sun
# Microsystems, Inc. All Rights Reserved.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build the java portion of the java wrapper to mozilla
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..
# PENDING(edburns): find out where this should really get defined
JAVA_OR_NSJVM=1
NO_CAFE=1
include <$(DEPTH)\config\config.mak>
JAR_WEBCLIENT_CLASSES = org\mozilla\webclient \
org\mozilla\webclient\test
!ifdef JAVA_OR_NSJVM
JDIRS = $(JAR_WEBCLIENT_CLASSES)
!endif
WEBCLIENT_JAR_NAME=webclient(VERSION_NUMBER).jar
JAVAC_PROG=$(JDKHOME)\bin\javac
export::
@echo +++ Checking that org.mozilla.util classes have been built...
if not exist $(MOZ_SRC)\mozilla\dist\classes\org\mozilla\util\Assert.class \
stopbuild.exe
include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControl.java
/**
*
* <B>BrowserControl</B> simply declares the composition of the core and extended
* interfaces.
*
* @version $Id: BrowserControl.java,v 1.1 1999-07-30 01:03:03 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCore
* @see org.mozilla.webclient.BrowserControlExtended
*
*/
public interface BrowserControl extends BrowserControlCore, BrowserControlExtended
{
} // end of interface BrowserControl

Просмотреть файл

@ -0,0 +1,240 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlCanvas.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.*;
/**
*
* BrowserControlCanvas is the principal class for embedding
* the Mozilla WebShell into the Java framework.
* This component represents the proxy for the native
* WebShell class as provided by the nsIWebShell
* interface.
*
* @see org.mozilla.webclient.BrowserControl
*
* @author Kirk Baker
* @author Ian Wilkinson
* <P>
* <B>Lifetime And Scope</B> <P>
* See concrete subclasses for scope info.
* @version $Id: BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
* @see org.mozilla.webclient.Win32BrowserControlCanvas
*/
import java.awt.*;
import java.awt.Canvas;
import java.awt.event.*;
import sun.awt.*;
public abstract class BrowserControlCanvas extends Canvas
{
//
// Class Variables
//
private static int webShellCount = 0;
//
// Instance Variables
//
// Attribute Instance Variables
private boolean initializeOK;
private boolean boundsValid;
private boolean hasFocus;
// Relationship Instance Variables
private BrowserControl webShell;
private int nativeWindow;
private Rectangle windowRelativeBounds;
// PENDING(edburns): Is this needed: // private BrowserControlIdleThread idleThread;
//
// Constructors and Initializers
//
/**
* Initialize the BrowserControlMozillaShim. For now,
* this initializes the Mozilla registry.
*/
public BrowserControlCanvas ()
{
nativeWindow = 0;
webShell = null;
initializeOK = false;
boundsValid = false;
hasFocus = false;
try {
BrowserControlMozillaShim.initialize();
} catch (Exception e) {
System.out.println(e.toString());
}
} // BrowserControlCanvas() ctor
/**
* Obtain the native window handle for this component's
* peer.
*/
abstract protected int getWindow(DrawingSurfaceInfo dsi);
//
// Methods from Canvas
//
/**
* Instantiate the Mozilla WebShell container.
*/
public void addNotify ()
{
super.addNotify();
DrawingSurface ds = (DrawingSurface)this.getPeer();
DrawingSurfaceInfo dsi = ds.getDrawingSurfaceInfo();
windowRelativeBounds = new Rectangle();
// We must lock() the DrawingSurfaceInfo before
// accessing its native window handle.
dsi.lock();
nativeWindow = getWindow(dsi);
try {
Rectangle r = new Rectangle(getBoundsRelativeToWindow());
webShell = new BrowserControlImpl(nativeWindow, r);
} catch (Exception e) {
dsi.unlock();
System.out.println(e.toString());
return;
}
dsi.unlock();
initializeOK = true;
webShellCount++;
/*
requestFocus();
*/
} // addNotify()
public BrowserControl getWebShell ()
{
return webShell;
} // getWebShell()
protected Point getEventCoordsLocalToWindow(MouseEvent evt)
{
Rectangle localBounds = getBoundsRelativeToWindow();
int windowLocalX = evt.getX() + localBounds.x;
int windowLocalY = evt.getY() + localBounds.y;
return new Point(windowLocalX, windowLocalY);
} // getEventCoordsLocalToWindow()
protected Rectangle getWindowBounds ()
{// Throw an Exception?
Container parent = getParent();
if (parent != null) {
do {
// if the parent is a window, then return its bounds
if (parent instanceof Window == true) {
return parent.getBounds();
}
parent = parent.getParent();
} while (parent != null);
}
return new Rectangle();
} // getWindowBounds()
protected Rectangle getBoundsRelativeToWindow ()
{
if (boundsValid) {
return windowRelativeBounds;
}
Container parent = getParent();
Point ourLoc = getLocation();
Rectangle ourBounds = getBounds();
if (parent != null) {
do {
// if the parent is a window, then don't adjust to its offset
// and look no further
if (parent instanceof Window == true) {
break;
}
Point parentLoc = parent.getLocation();
ourLoc.translate(-parentLoc.x, -parentLoc.y);
parent = parent.getParent();
} while (parent != null);
}
windowRelativeBounds.setBounds(-ourLoc.x, -ourLoc.y, ourBounds.width, ourBounds.height);
boundsValid = true;
return windowRelativeBounds;
} // getBoundsRelativeToWindow()
public void setBounds(int x, int y, int w, int h)
{
super.setBounds(x, y, w, h);
if (webShell != null) {
System.out.println("in BrowserControlCanvas setBounds: x = " + x + " y = " + y + " w = " + w + " h = " + h);
try {
webShell.setBounds(new Rectangle(0, 0, w - 1, h - 1));
}
catch(Exception ex) {
}
}
}
public void setBounds(Rectangle rect)
{
super.setBounds(rect);
}
} // class BrowserControlCanvas
// EOF

Просмотреть файл

@ -0,0 +1,119 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are Copyright (C) 1997, 1998, 1999 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.mozilla.webclient;
// BrowserControlCanvasFactory.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
/**
*
* <B>BrowserControlCanvasFactory</B> creates concrete instances of BrowserControlCanvas
* <B>Lifetime And Scope</B> <P>
* This is a static class, it is neven instantiated.
*
* @version $Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.test.EmbeddedMozilla
*/
public class BrowserControlCanvasFactory extends Object
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public BrowserControlCanvasFactory()
{
Assert.assert(false, "This class shouldn't be constructed.");
}
//
// Class methods
//
public static BrowserControlCanvas newBrowserControlCanvas()
{
BrowserControlCanvas result = null;
// PENDING(edburns): do some magic to determine the right kind of
// BrowserControlCanvas to instantiate
Class browserControlCanvasClass = null;
String className = "org.mozilla.webclient.Win32BrowserControlCanvas";
try {
if (null != (browserControlCanvasClass = Class.forName(className))) {
result = (BrowserControlCanvas) browserControlCanvasClass.newInstance();
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return result;
}
//
// General Methods
//
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("BrowserControlCanvasFactory");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlCanvasFactory.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $");
BrowserControlCanvas canvas = BrowserControlCanvasFactory.newBrowserControlCanvas();
Assert.assert(null != canvas);
}
// ----UNIT_TEST_END
} // end of class BrowserControlCanvasFactory

Просмотреть файл

@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlCore.java
/**
*
* <B>BrowserControlCore</B> Defines the core methods for browsing
*
* @version $Id: BrowserControlCore.java,v 1.1 1999-07-30 01:03:04 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlExtended
* @see org.mozilla.webclient.BrowserControl
*
*/
public interface BrowserControlCore
{
public void loadURL(String urlString) throws Exception;
public void stop() throws Exception;
public boolean canBack() throws Exception;
public boolean canForward() throws Exception;
public boolean back() throws Exception;
public boolean forward() throws Exception;
public int getNativeWebShell();
} // end of interface BrowserControlCore

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlExtended.java
import java.awt.Rectangle;
/**
*
* <B>BrowserControlExtended</B> defines the interface for extended browser
* functionality
*
* @version $Id: BrowserControlExtended.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCore
* */
public interface BrowserControlExtended
{
public void show () throws Exception;
public void hide () throws Exception;
public void setBounds (Rectangle bounds) throws Exception;
public void moveTo (int x, int y) throws Exception;
public void setFocus () throws Exception;
public void removeFocus () throws Exception;
public void repaint (boolean forceRepaint) throws Exception;
public boolean goTo (int historyIndex) throws Exception;
public int getHistoryLength () throws Exception;
public int getHistoryIndex () throws Exception;
public String getURL (int historyIndex) throws Exception;
} // end of interface BrowserControlExtended

Просмотреть файл

@ -0,0 +1,245 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// BrowserControlImpl.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.Rectangle;
/**
*
* <B>BrowserControlImpl</B> provides the implementation for BrowserControl
*
* <B>Lifetime And Scope</B> <P>
*
* @version $Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControl
*
*/
public class BrowserControlImpl extends Object implements BrowserControl
{
//
// Protected Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
/**
* a handle to the actual mozilla webShell
*/
private int nativeWebShell;
//
// Constructors and Initializers
//
public BrowserControlImpl(int windowPtr, Rectangle bounds) throws Exception
{
nativeWebShell = BrowserControlMozillaShim.webShellCreate(windowPtr, bounds);
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from BrowserControl
//
public void loadURL(String urlString) throws Exception
{
BrowserControlMozillaShim.webShellLoadURL(nativeWebShell, urlString);
}
public void stop() throws Exception
{
BrowserControlMozillaShim.webShellStop(nativeWebShell);
}
public void show () throws Exception
{
BrowserControlMozillaShim.webShellShow(nativeWebShell);
}
public void hide () throws Exception
{
BrowserControlMozillaShim.webShellHide(nativeWebShell);
}
public void setBounds (Rectangle bounds) throws Exception
{
BrowserControlMozillaShim.webShellSetBounds(nativeWebShell, bounds);
}
public void moveTo (int x, int y) throws Exception
{
BrowserControlMozillaShim.webShellMoveTo(nativeWebShell, x, y);
}
/**
*
*/
public void setFocus () throws Exception
{
BrowserControlMozillaShim.webShellSetFocus(nativeWebShell);
}
/**
*
*/
public void removeFocus () throws Exception
{
BrowserControlMozillaShim.webShellRemoveFocus(nativeWebShell);
}
/**
*
*/
public void repaint (boolean forceRepaint) throws Exception
{
BrowserControlMozillaShim.webShellRepaint(nativeWebShell, forceRepaint);
}
/**
*
*/
public boolean canBack () throws Exception
{
return BrowserControlMozillaShim.webShellCanBack(nativeWebShell);
}
/**
*
*/
public boolean canForward () throws Exception
{
return BrowserControlMozillaShim.webShellCanForward(nativeWebShell);
}
/**
*
*/
public boolean back () throws Exception
{
return BrowserControlMozillaShim.webShellBack(nativeWebShell);
}
/**
*
*/
public boolean forward () throws Exception
{
return BrowserControlMozillaShim.webShellForward(nativeWebShell);
}
/**
*
*/
public boolean goTo (int historyIndex) throws Exception
{
return BrowserControlMozillaShim.webShellGoTo(nativeWebShell, historyIndex);
}
/**
*
*/
public int getHistoryLength () throws Exception
{
return BrowserControlMozillaShim.webShellGetHistoryLength(nativeWebShell);
}
/**
*
*/
public int getHistoryIndex () throws Exception
{
return BrowserControlMozillaShim.webShellGetHistoryIndex(nativeWebShell);
}
/**
*
*/
public String getURL (int historyIndex) throws Exception
{
return BrowserControlMozillaShim.webShellGetURL(nativeWebShell, historyIndex);
}
/**
*
*/
public int getNativeWebShell ()
{
return nativeWebShell;
}
/**
*
*/
public void finalize ()
{
try {
BrowserControlMozillaShim.webShellDelete(nativeWebShell);
}
catch (Exception ex) {
System.out.println(ex.toString());
}
nativeWebShell = 0;
}
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
// BrowserControlImpl me = new BrowserControlImpl();
Log.setApplicationName("BrowserControlImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlImpl.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $");
}
// ----UNIT_TEST_END
} // end of class BrowserControlImpl

Просмотреть файл

@ -0,0 +1,572 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// MWebShellMozillaShim.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import java.awt.*;
/**
*
* <B>MWebShellMozillaShim</B> is a class with native methods that
* provides the glue between MWebShell and nsIWebShell. <P>
* WAS: instance <P>
* <B>Lifetime And Scope</B> <P>
* There is one instance of this class and all of the exposed methods
* are static.
* @version $Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlImpl
*
*/
public class BrowserControlMozillaShim extends Object
{
//
// Protected Constants
//
//
// Class Variables
//
private static boolean initialized = false;
private static BrowserControlMozillaShim instance = null;
private static Object lock = null;
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
//
// Constructors and Initializers
//
public BrowserControlMozillaShim()
{
super();
lock = new Object();
}
//
// Class methods
//
public static void initialize () throws Exception
{
if (!initialized) {
instance = new BrowserControlMozillaShim();
try {
System.loadLibrary("webclient");
}
catch (java.lang.UnsatisfiedLinkError e) {
throw new Exception("Unable to open native webclient library");
}
instance.nativeInitialize();
initialized = true;
}
}
public static void terminate () throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeTerminate();
initialized = false;
}
}
}
public static void processEvents(int theWebShell)
{
synchronized(lock) {
if (initialized) {
instance.nativeProcessEvents(theWebShell);
}
}
}
//
// Window events
//
public static void sendKeyDownEvent (int widgetPtr,
char keyChar, int keyCode,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendKeyDownEvent(widgetPtr,
keyChar, keyCode, modifiers,
eventTime);
}
}
}
public static void sendKeyUpEvent (int widgetPtr,
char keyChar, int keyCode,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendKeyUpEvent(widgetPtr, keyChar,
keyCode, modifiers, eventTime);
}
}
}
public static void sendMouseEvent (int windowPtr, int widgetPtr,
int widgetX, int widgetY,
int windowX, int windowY,
int mouseMessage, int numClicks,
int modifiers, int eventTime)
{
synchronized(lock) {
if (initialized) {
instance.nativeSendMouseEvent(windowPtr, widgetPtr,
widgetX, widgetY,
windowX, windowY,
mouseMessage, numClicks,
modifiers, eventTime);
}
}
}
public static void idleEvent (int windowPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeIdleEvent(windowPtr, 0);
}
}
}
public static void updateEvent (int windowPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeUpdateEvent(windowPtr, 0);
}
}
}
//
// Widget methods
//
public static int widgetCreate (int windowPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
return(instance.nativeWidgetCreate(windowPtr,
bounds.x, bounds.y,
bounds.width + 1, bounds.height + 1));
} else {
return 0;
}
}
}
public static void widgetDelete (int widgetPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetDelete(widgetPtr);
}
}
}
public static void widgetResize (int widgetPtr, Rectangle bounds,
boolean repaint)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetResize(widgetPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1, repaint);
}
}
}
public static void widgetResize (int widgetPtr, int width,
int height, boolean repaint)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetResize(widgetPtr, 0, 0, width + 1, height + 1, repaint);
}
}
}
public static void widgetEnable (int widgetPtr, boolean enable)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetEnable(widgetPtr, enable);
}
}
}
public static void widgetShow (int widgetPtr, boolean show)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetShow(widgetPtr, show);
}
}
}
public static void widgetInvalidate (int widgetPtr, boolean isSynchronous)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetInvalidate(widgetPtr, isSynchronous);
}
}
}
public static void widgetUpdate (int widgetPtr)
{
synchronized(lock) {
if (initialized) {
instance.nativeWidgetUpdate(widgetPtr);
}
}
}
//
// WebShell methods
//
public static int webShellCreate (int windowPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
return(instance.nativeWebShellCreate(windowPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1));
}
else {
throw new Exception("Error: unable to create native nsIWebShell");
}
}
}
public static void webShellDelete (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellDelete(webShellPtr);
}
}
}
public static void webShellLoadURL (int webShellPtr,
String urlString) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellLoadURL(webShellPtr, urlString);
}
}
}
public static void webShellStop (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellStop(webShellPtr);
}
}
}
public static void webShellShow (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellShow(webShellPtr);
}
}
}
public static void webShellHide (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellHide(webShellPtr);
}
}
}
public static void webShellSetBounds (int webShellPtr,
Rectangle bounds) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellSetBounds(webShellPtr, bounds.x, bounds.y, bounds.width + 1, bounds.height + 1);
}
}
}
public static void webShellMoveTo (int webShellPtr,
int x, int y) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellMoveTo(webShellPtr, x, y);
}
}
}
public static void webShellSetFocus (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellSetFocus(webShellPtr);
}
}
}
public static void webShellRemoveFocus (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellRemoveFocus(webShellPtr);
}
}
}
public static void webShellRepaint (int webShellPtr,
boolean forceRepaint) throws Exception
{
synchronized(lock) {
if (initialized) {
instance.nativeWebShellRepaint(webShellPtr, forceRepaint);
}
}
}
public static boolean webShellCanBack (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellCanBack(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellCanForward (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellCanForward(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellBack (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellBack(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellForward (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellForward(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static boolean webShellGoTo (int webShellPtr,
int historyIndex) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGoTo(webShellPtr, historyIndex);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static int webShellGetHistoryLength (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetHistoryLength(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static int webShellGetHistoryIndex (int webShellPtr) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetHistoryIndex(webShellPtr);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
public static String webShellGetURL(int webShellPtr,
int historyIndex) throws Exception
{
synchronized(lock) {
if (initialized) {
return instance.nativeWebShellGetURL(webShellPtr, historyIndex);
}
else {
throw new Exception("instance is not initialized.");
}
}
}
//
// Native interfaces
//
private native void nativeInitialize () throws Exception;
private native void nativeTerminate () throws Exception;
//
// Event interfaces
//
private native void nativeSendKeyDownEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime);
private native void nativeSendKeyUpEvent(int widgetPtr, char keyChar, int keyCode, int modifiers, int eventTime);
private native void nativeSendMouseEvent(int windowPtr, int widgetPtr,
int widgetX, int widgetY,
int windowX, int windowY,
int mouseMessage, int numClicks,
int modifiers, int eventTime);
private native void nativeProcessEvents(int theWebShell);
private native void nativeIdleEvent (int windowPtr, int eventTime);
private native void nativeUpdateEvent (int windowPtr, int eventTime);
//
// Widget interfaces
//
private native int nativeWidgetCreate (int windowPtr, int x, int y, int width, int height) throws Exception;
private native void nativeWidgetDelete (int widgetPtr) throws Exception;
private native void nativeWidgetResize (int widgetPtr, int x, int y, int width, int height, boolean repaint);
/*
private native void nativeWidgetResize (int widgetPtr, int width, int height, boolean repaint);
*/
private native void nativeWidgetEnable (int widgetPtr, boolean enable);
private native void nativeWidgetShow (int widgetPtr, boolean show);
private native void nativeWidgetInvalidate (int widgetPtr, boolean isSynchronous);
private native void nativeWidgetUpdate (int widgetPtr);
//
// WebShell interface
//
private native int nativeWebShellCreate (int windowPtr,
int x, int y, int width, int height) throws Exception;
private native void nativeWebShellDelete (int webShellPtr) throws Exception;
private native void nativeWebShellLoadURL (int webShellPtr, String urlString) throws Exception;
private native void nativeWebShellStop (int webShellPtr) throws Exception;
private native void nativeWebShellShow (int webShellPtr) throws Exception;
private native void nativeWebShellHide (int webShellPtr) throws Exception;
private native void nativeWebShellSetBounds (int webShellPtr, int x, int y, int width, int height) throws Exception;
private native void nativeWebShellMoveTo (int webShellPtr, int x, int y) throws Exception;
private native void nativeWebShellSetFocus (int webShellPtr) throws Exception;
private native void nativeWebShellRemoveFocus (int webShellPtr) throws Exception;
private native void nativeWebShellRepaint (int webShellPtr, boolean forceRepaint) throws Exception;
private native boolean nativeWebShellCanBack (int webShellPtr) throws Exception;
private native boolean nativeWebShellCanForward (int webShellPtr) throws Exception;
private native boolean nativeWebShellBack (int webShellPtr) throws Exception;
private native boolean nativeWebShellForward (int webShellPtr) throws Exception;
private native boolean nativeWebShellGoTo (int webShellPtr, int aHistoryIndex) throws Exception;
private native int nativeWebShellGetHistoryLength (int webShellPtr) throws Exception;
private native int nativeWebShellGetHistoryIndex (int webShellPtr) throws Exception;
private native String nativeWebShellGetURL (int webShellPtr, int aHistoryIndex) throws Exception;
//
// General Methods
//
// ----UNIT_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
BrowserControlMozillaShim me = new BrowserControlMozillaShim();
Log.setApplicationName("BrowserControlMozillaShim");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: BrowserControlMozillaShim.java,v 1.1 1999-07-30 01:03:05 edburns%acm.org Exp $");
}
// ----UNIT_TEST_END
} // end of class BrowserControlMozillaShim

Просмотреть файл

@ -0,0 +1,60 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient;
// Win32BrowserControlCanvas.java
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
/**
* Win32RaptorCanvas provides a concrete realization
* of the RaptorCanvas.
* <B>Lifetime And Scope</B> <P>
* There is one instance of the BrowserControlCanvas per top level awt Frame.
* @version $Id: Win32BrowserControlCanvas.java,v 1.1 1999-07-30 01:03:06 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCanvasFactory
*
*/
import sun.awt.*;
import sun.awt.windows.*;
/**
* Win32BrowserControlCanvas provides a concrete realization
* of the RaptorCanvas.
*/
class Win32BrowserControlCanvas extends BrowserControlCanvas {
/**
* Obtain the native window handle for this
* component's peer.
*
* @returns The native window handle.
*/
protected int getWindow(DrawingSurfaceInfo dsi) {
WDrawingSurfaceInfo ds = (WDrawingSurfaceInfo)dsi;
return ds.getHWnd();
}
}

Просмотреть файл

@ -0,0 +1,186 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
package org.mozilla.webclient.test;
/*
* EmbeddedMozilla.java
*/
import java.awt.*;
import java.awt.event.*;
import org.mozilla.webclient.*;
/**
*
* This is a test application for using the BrowserControl.
*
* @version $Id: EmbeddedMozilla.java,v 1.1 1999-07-30 01:03:07 edburns%acm.org Exp $
*
* @see org.mozilla.webclient.BrowserControlCanvasFactory
*/
public class EmbeddedMozilla extends Frame implements ActionListener {
static final int defaultWidth = 640;
static final int defaultHeight = 480;
private TextField urlField;
private BrowserControl browserControl;
private Panel controlPanel;
private Panel buttonsPanel;
public static void main (String[] arg) {
String urlArg =(0 < arg.length) ? arg[0] : "http://www.mozilla.org/";
EmbeddedMozilla gecko =
new EmbeddedMozilla("Embedded Mozilla", urlArg);
} // main()
public EmbeddedMozilla (String title, String url) {
super(title);
System.out.println("constructed with " + url);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
// should close the BrowserControlCanvas
}
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
setSize(defaultWidth, defaultHeight);
// Create the URL field
urlField = new TextField("", 30);
urlField.addActionListener(this);
// Create the buttons sub panel
buttonsPanel = new Panel();
buttonsPanel.setLayout(new GridBagLayout());
// Add the buttons
makeItem(buttonsPanel, "Back", 0, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Forward", 1, 0, 1, 1, 0.0, 0.0);
makeItem(buttonsPanel, "Stop", 2, 0, 1, 1, 0.0, 0.0);
// Create the control panel
controlPanel = new Panel();
controlPanel.setLayout(new BorderLayout());
// Add the URL field, and the buttons panel
controlPanel.add(urlField, BorderLayout.CENTER);
controlPanel.add(buttonsPanel, BorderLayout.WEST);
// Create the browser
BrowserControlCanvas browser =
BrowserControlCanvasFactory.newBrowserControlCanvas();
browser.setSize(defaultWidth, defaultHeight);
// Add the control panel and the browser
add(controlPanel, BorderLayout.NORTH);
add(browser, BorderLayout.CENTER);
pack();
show();
toFront();
browserControl = browser.getWebShell();
try {
browserControl.loadURL(url);
urlField.setText(url);
}
catch (Exception e) {
System.out.println(e.toString());
}
} // EmbeddedMozilla() ctor
public void actionPerformed (ActionEvent evt) {
String command = evt.getActionCommand();
try {
if (command.equals("Back")) {
if (browserControl.canBack()) {
browserControl.back();
int index = browserControl.getHistoryIndex();
String newURL = browserControl.getURL(index);
System.out.println(newURL);
urlField.setText(newURL);
}
}
else if (command.equals("Forward")) {
if (browserControl.canForward()) {
browserControl.forward();
int index = browserControl.getHistoryIndex();
String newURL = browserControl.getURL(index);
System.out.println(newURL);
urlField.setText(newURL);
}
}
else if (command.equals("Stop")) {
browserControl.stop();
}
else {
browserControl.loadURL(urlField.getText());
}
}
catch (Exception e) {
System.out.println(e.toString());
}
} // 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()
}
// EOF

Просмотреть файл

Просмотреть файл

Просмотреть файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,81 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Initial Developer of the Original Code is Sun Microsystems,
# Inc. Portions created by Sun are Copyright (C) 1999 Sun
# Microsystems, Inc. All Rights Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
DLLNAME = webclient
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MODULE=webclient
OBJS = \
.\$(OBJDIR)\nsActions.obj \
.\$(OBJDIR)\BrowserControlMozillaShim.obj \
$(NULL)
LINCS = \
$(NULL)
LCFLAGS = \
$(NULL)
LLIBS = \
$(DIST)\lib\raptorweb.lib \
$(DIST)\lib\raptorbasewidget_s.lib \
$(DIST)\lib\raptorwidget.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\nsreg.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\nspr3.lib \
$(DIST)\lib\plds3.lib \
$(DEPTH)\xpfe\bootstrap\WIN32_D.OBJ\nsSetupRegistry.obj \
$(NULL)
# $(DIST)\lib\raptorbase.lib \
# $(DIST)\lib\xpcom32.lib\
# $(DIST)\lib\xpcomds_s.lib\
WIN_LIBS = \
version.lib
include <$(DEPTH)\config\rules.mak>
include <..\config\localdefs.mak>
!CMDSWITCHES -S
# generate the jni header
export:: BrowserControlMozillaShim.h
BrowserControlMozillaShim.h:
@echo Assuming class org.mozilla.webclient.BrowserControlMozillaShim is in $(JAVAH_FLAGS)
$(JAVAH) $(JAVAH_FLAGS) -o $@ org.mozilla.webclient.BrowserControlMozillaShim
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
@echo +++ Creating .\$(OBJDIR)\runem.bat. Use this to run the test browser.
@echo $(JAVA) -Djava.library.path=$(MOZ_SRC)\mozilla\dist\WIN32_D.OBJ\bin -classpath $(JAVAC_CLASSPATH) org.mozilla.webclient.test.EmbeddedMozilla %1% > .\$(OBJDIR)\runem.bat
clobber_all:: clobber
clobber::
rm -f $(DIST)\bin\$(DLLNAME).dll
rm -f BrowserControlMozillaShim.h
rm -f .\$(OBJDIR)\runem.bat

Просмотреть файл

@ -0,0 +1,589 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
/*
* nsActions.cpp
*/
#include "nsActions.h"
void * handleEvent (PLEvent * event);
void destroyEvent (PLEvent * event);
void *
handleEvent (PLEvent * event)
{
nsActionEvent * actionEvent = (nsActionEvent*) event->owner;
void * result = nsnull;
if (actionEvent != NULL) {
actionEvent->setResult(result = actionEvent->handleEvent());
actionEvent->setComplete(PR_TRUE);
}
return result;
} // handleEvent()
void
destroyEvent (PLEvent * event)
{
nsActionEvent * actionEvent = (nsActionEvent*) event->owner;
if (actionEvent != NULL) {
if (!actionEvent->isSynchronous()) {
// Only delete if non-synchronous. Synchronous events are deleted by the event poster.
actionEvent->destroyEvent();
}
}
} // destroyEvent()
/*
* nsActionEvent
*/
nsActionEvent::nsActionEvent (PRBool synchronous)
{
PL_InitEvent(&mEvent, this,
(PLHandleEventProc ) ::handleEvent,
(PLDestroyEventProc) ::destroyEvent);
mSynchronous = synchronous;
mComplete = PR_FALSE;
mResult = nsnull;
}
PRBool
nsActionEvent::isComplete (void)
{
if (mSynchronous) {
return mComplete;
}
else {
return PR_TRUE;
}
} // isComplete()
/*
* wsResizeEvent
*/
wsResizeEvent::wsResizeEvent(nsIWebShell* webShell, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) :
nsActionEvent(PR_FALSE),
mWebShell(webShell),
mLeft(x),
mBottom(y),
mWidth(w),
mHeight(h)
{
}
void *
wsResizeEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(resize) x = %d y = %d w = %d h = %d\n", mLeft, mBottom, mWidth, mHeight);
nsresult rv = mWebShell->SetBounds(mLeft, mBottom, mWidth, mHeight);
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsLoadURLEvent
*/
wsLoadURLEvent::wsLoadURLEvent(nsIWebShell* webShell, PRUnichar * urlString) :
nsActionEvent(PR_FALSE),
mWebShell(webShell),
mURL(nsnull)
{
mURL = new nsString1(urlString);
}
void *
wsLoadURLEvent::handleEvent ()
{
if (mWebShell && mURL) {
printf("handleEvent(loadURL)\n");
nsresult rv = mWebShell->LoadURL(mURL->GetUnicode());
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
wsLoadURLEvent::~wsLoadURLEvent ()
{
if (mURL != nsnull)
delete mURL;
}
/*
* wsStopEvent
*/
wsStopEvent::wsStopEvent(nsIWebShell* webShell) :
nsActionEvent(PR_FALSE),
mWebShell(webShell)
{
}
void *
wsStopEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Stop)\n");
nsresult rv = mWebShell->Stop();
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsShowEvent
*/
wsShowEvent::wsShowEvent(nsIWebShell* webShell) :
nsActionEvent(PR_FALSE),
mWebShell(webShell)
{
}
void *
wsShowEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Show)\n");
nsresult rv = mWebShell->Show();
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsHideEvent
*/
wsHideEvent::wsHideEvent(nsIWebShell* webShell) :
nsActionEvent(PR_FALSE),
mWebShell(webShell)
{
}
void *
wsHideEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Hide)\n");
nsresult rv = mWebShell->Hide();
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsMoveToEvent
*/
wsMoveToEvent::wsMoveToEvent(nsIWebShell* webShell, PRInt32 x, PRInt32 y) :
nsActionEvent(PR_FALSE),
mWebShell(webShell),
mX(x),
mY(y)
{
}
void *
wsMoveToEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(MoveTo(%ld, %ld)\n", mX, mY);
nsresult rv = mWebShell->MoveTo(mX, mY);
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsSetFocusEvent
*/
wsSetFocusEvent::wsSetFocusEvent(nsIWebShell* webShell) :
nsActionEvent(PR_FALSE),
mWebShell(webShell)
{
}
void *
wsSetFocusEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(SetFocus()\n");
nsresult rv = mWebShell->SetFocus();
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsRemoveFocusEvent
*/
wsRemoveFocusEvent::wsRemoveFocusEvent(nsIWebShell* webShell) :
nsActionEvent(PR_FALSE),
mWebShell(webShell)
{
}
void *
wsRemoveFocusEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(RemoveFocus()\n");
nsresult rv = mWebShell->RemoveFocus();
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsRepaintEvent
*/
wsRepaintEvent::wsRepaintEvent(nsIWebShell* webShell, PRBool forceRepaint) :
nsActionEvent(PR_FALSE),
mWebShell(webShell),
mForceRepaint(forceRepaint)
{
}
void *
wsRepaintEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Repaint(%d)\n", mForceRepaint);
nsresult rv = mWebShell->Repaint(mForceRepaint);
printf("result = %lx\n", rv);
}
return NULL;
} // handleEvent()
/*
* wsCanBackEvent
*/
wsCanBackEvent::wsCanBackEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsCanBackEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(CanBack()\n");
nsresult rv = mWebShell->CanBack();
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsCanForwardEvent
*/
wsCanForwardEvent::wsCanForwardEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsCanForwardEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(CanForward()\n");
nsresult rv = mWebShell->CanForward();
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsBackEvent
*/
wsBackEvent::wsBackEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsBackEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Back()\n");
nsresult rv = mWebShell->Back();
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsForwardEvent
*/
wsForwardEvent::wsForwardEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsForwardEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(Forward()\n");
nsresult rv = mWebShell->Forward();
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsGoToEvent
*/
wsGoToEvent::wsGoToEvent(nsIWebShell* webShell, PRInt32 historyIndex) :
nsActionEvent(PR_TRUE),
mWebShell(webShell),
mHistoryIndex(historyIndex)
{
}
void *
wsGoToEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(GoTo(%ld)\n", mHistoryIndex);
nsresult rv = mWebShell->GoTo(mHistoryIndex);
printf("result = %lx\n", rv);
return (void *) rv;
}
return NULL;
} // handleEvent()
/*
* wsGetHistoryLengthEvent
*/
wsGetHistoryLengthEvent::wsGetHistoryLengthEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsGetHistoryLengthEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(wsGetHistoryLengthEvent()\n");
PRInt32 historyLength = 0;
nsresult rv = mWebShell->GetHistoryLength(historyLength);
printf("result = %lx\n", rv);
return (void *) historyLength;
}
return NULL;
} // handleEvent()
/*
* wsGetHistoryIndexEvent
*/
wsGetHistoryIndexEvent::wsGetHistoryIndexEvent(nsIWebShell* webShell) :
nsActionEvent(PR_TRUE),
mWebShell(webShell)
{
}
void *
wsGetHistoryIndexEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(wsGetHistoryIndexEvent()\n");
PRInt32 historyIndex = 0;
nsresult rv = mWebShell->GetHistoryIndex(historyIndex);
printf("result = %lx\n", rv);
return (void *) historyIndex;
}
return NULL;
} // handleEvent()
/*
* wsGetURLEvent
*/
wsGetURLEvent::wsGetURLEvent(nsIWebShell* webShell, PRInt32 historyIndex) :
nsActionEvent(PR_TRUE),
mWebShell(webShell),
mHistoryIndex(historyIndex)
{
}
void *
wsGetURLEvent::handleEvent ()
{
if (mWebShell) {
printf("handleEvent(wsGetURLEvent(%ld)\n", mHistoryIndex);
const PRUnichar * url = nsnull;
// returns PRUninchar * URL in <url>. No need to delete. References internal buffer of an nsString
nsresult rv = mWebShell->GetURL(mHistoryIndex, &url);
printf("result = %lx, url = %lx\n", rv, url);
return (void *) url;
}
return NULL;
} // handleEvent()
// EOF

Просмотреть файл

@ -0,0 +1,251 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The original code is RaptorCanvas
*
* The Initial Developer of the Original Code is Kirk Baker <kbaker@eb.com> and * Ian Wilkinson <iw@ennoble.com
*/
/*
* nsActions.h
*/
#ifndef nsActions_h___
#define nsActions_h___
#include <windows.h>
#include "nsIWebShell.h"
#include "nsString.h"
#include "plevent.h"
class nsActionEvent {
public:
nsActionEvent (PRBool synchronous);
virtual ~nsActionEvent () {};
virtual void * handleEvent (void) { return NULL;};
void destroyEvent (void) { delete this; };
operator PLEvent* () { return &mEvent; };
PRBool isSynchronous (void) { return mSynchronous; };
PRBool isComplete (void);
void setComplete (PRBool complete) { mComplete = complete; };
void * getResult (void) { return mResult; };
void setResult (void * result) { mResult = result; };
protected:
PLEvent mEvent;
void * mResult;
PRBool mSynchronous;
PRBool mComplete;
};
class wsResizeEvent : public nsActionEvent {
public:
wsResizeEvent (nsIWebShell* webShell, PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
PRInt32 mLeft;
PRInt32 mBottom;
PRInt32 mWidth;
PRInt32 mHeight;
};
class wsLoadURLEvent : public nsActionEvent {
public:
wsLoadURLEvent (nsIWebShell* webShell, PRUnichar * urlString);
~wsLoadURLEvent ();
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
nsString1 * mURL;
};
class wsStopEvent : public nsActionEvent {
public:
wsStopEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsShowEvent : public nsActionEvent {
public:
wsShowEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsHideEvent : public nsActionEvent {
public:
wsHideEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsMoveToEvent : public nsActionEvent {
public:
wsMoveToEvent (nsIWebShell* webShell, PRInt32 x, PRInt32 y);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
PRInt32 mX;
PRInt32 mY;
};
class wsSetFocusEvent : public nsActionEvent {
public:
wsSetFocusEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsRemoveFocusEvent : public nsActionEvent {
public:
wsRemoveFocusEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsRepaintEvent : public nsActionEvent {
public:
wsRepaintEvent (nsIWebShell* webShell, PRBool forceRepaint);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
PRBool mForceRepaint;
};
class wsCanBackEvent : public nsActionEvent {
public:
wsCanBackEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsCanForwardEvent : public nsActionEvent {
public:
wsCanForwardEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsBackEvent : public nsActionEvent {
public:
wsBackEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsForwardEvent : public nsActionEvent {
public:
wsForwardEvent (nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsGoToEvent : public nsActionEvent {
public:
wsGoToEvent (nsIWebShell* webShell, PRInt32 historyIndex);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
PRInt32 mHistoryIndex;
};
class wsGetHistoryLengthEvent : public nsActionEvent {
public:
wsGetHistoryLengthEvent
(nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsGetHistoryIndexEvent : public nsActionEvent {
public:
wsGetHistoryIndexEvent
(nsIWebShell* webShell);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
};
class wsGetURLEvent : public nsActionEvent {
public:
wsGetURLEvent (nsIWebShell* webShell, PRInt32 historyIndex);
void * handleEvent (void);
protected:
nsIWebShell * mWebShell;
PRInt32 mHistoryIndex;
};
#endif /* nsActions_h___ */
// EOF