📄 xjswindow.java
字号:
/****************************************************************
* XBrowser - eXtended web Browser *
* *
* Copyright (c) 2000-2001 Armond Avanes *
* Refer to ReadMe & License files for more information *
* *
* *
* By: Uladzimir V. Kavalchuk *
* Uladzimir_Kavalchuk@ep.minsk.by *
* http://xbrowser.sourceforge.net/ *
*****************************************************************/
package xbrowser.renderer.custom.js;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import org.mozilla.javascript.*;
import xbrowser.*;
import xbrowser.doc.*;
import xbrowser.renderer.*;
import xbrowser.renderer.custom.*;
public class XJSWindow extends ScriptableObject {
public XJSWindow() { // prototype
}
public void defineSelf() {
try {
defineFunctionProperties( props, getClass(), DONTENUM);
defineProperty( "window", getClass(), READONLY);
defineProperty( "document", getClass(), READONLY);
defineProperty( "navigator", getClass(), READONLY);
defineProperty( "screen", getClass(), READONLY);
defineProperty( "screenLeft", getClass(), DONTENUM);
defineProperty( "screenTop", getClass(), DONTENUM);
defineProperty( "opener", getClass(), DONTENUM);
defineProperty( "name", getClass(), READONLY);
defineProperty( "closed", getClass(), READONLY);
defineProperty( "parent", getClass(), READONLY);
defineProperty( "top", getClass(), READONLY);
defineProperty( "history", getClass(), READONLY);
defineProperty( "location", getClass(), DONTENUM);
defineProperty( "status", getClass(), DONTENUM);
defineProperty( "defaultStatus", getClass(), DONTENUM);
/** @todo Implement this props, Maybe stubs. */
// defineProperty( "event", getClass(), DONTENUM);
// defineProperty( "length", getClass(), DONTENUM);
} catch( Exception ex) {
XRendererSupport.getContext().getLogger().error( this, "Window definition failed: " + ex);
}
}
public XJSWindow( XHTMLDocument doc, XRenderer window) {
this.doc = doc;
htmlWindow = window;
}
public String getClassName() {
return "XJSWindow";
}
public void setDocument( XJSDocument xjsDocument) {
document = xjsDocument;
}
// JavaScript-visible
public void alert( String text) {
Component c = htmlWindow.getComponent().getParent();
JOptionPane.showMessageDialog( c, text, "JavaScript alert", JOptionPane.INFORMATION_MESSAGE);
}
public Object getDocument() {
return document;
}
public Object getWindow() {
return this;
}
public synchronized Object getNavigator() {
if( navigator == null) {
try {
navigator = new XJSNavigator();
} catch( Exception ex) {
XRendererSupport.getContext().getLogger().error( this, "Error getting navigator!" + ex);
return XJSDocument.UNDEFINED;
}
}
return navigator;
}
public Object getScreen() {
ScriptableObject o = new ScriptableObject() {
public String getClassName() { return "SCREEN"; }
};
o.defineProperty( "colorDepth", new Integer(32), READONLY);
o.defineProperty( "pixelDepth", new Integer(32), READONLY);
return o;
}
private static class TimeoutListener implements ActionListener {
public TimeoutListener( XJSWindow owner, String expr, boolean repeat, Integer timerKey) {
this.expr = expr;
this.owner = owner;
this.repeat = repeat;
this.key = timerKey;
}
public void actionPerformed( ActionEvent e) {
owner.doc.addScript( expr, null);
if( ! repeat) {
Timer timer = (Timer)e.getSource();
timer.removeActionListener( this);
timers.remove( key);
}
}
// Attributes:
private String expr;
private XJSWindow owner;
private boolean repeat;
private Integer key;
} // class TimeoutListener
public int setTimeout( String expr, int msec) {
Integer timerKey = new Integer( timerId++);
Timer timer = new Timer( msec, new TimeoutListener( this, expr, false, timerKey));
timer.setRepeats( false);
timer.start();
timers.put( timerKey, timer);
return timerKey.intValue();
}
public void clearTimeout( int timerID) {
Integer timerKey = new Integer( timerID);
Timer timer = (Timer)timers.get( timerKey);
if( timer != null) {
timer.stop();
timers.remove( timer);
}
}
/** @todo: setInterval(), clearInterval() */
public static Object open( Context cx, Scriptable thisObj, Object[] args, Function funObj)
throws JavaScriptException {
if( ! ( thisObj instanceof XJSWindow))
throw new JavaScriptException( "this is not window???");
if( args.length < 1 || !( args[0] instanceof String))
throw new JavaScriptException( "Invalid arguments to window.open()!");
XJSWindow _this = (XJSWindow) thisObj;
String url = (String)args[0];
try {
URL fullURL = new URL( _this.doc.getBase(), url);
url = fullURL.toString();
} catch( MalformedURLException mfe) {/* Cant combine -- do not try to. */}
if( args.length > 1) {
String newWinName = (String)args[1];
XJSWindow win = _this.getExistingWindow( newWinName);
XRendererSupport.getContext().getLogger().message(XJSWindow.class, "Existing win is: " + win);
if( win == null)
win = _this.getNewWindow( url);
XRendererSupport.getContext().getLogger().message(XJSWindow.class, "New win is: " + win);
if( win != null) {
String options = args.length > 2 ? (String)args[2] : null;
win.setOptions( _this, (String)args[1], options);
}
return win;
} else { //
XRendererSupport.getContext().getLogger().message(XJSWindow.class, "Opened in the same window!");
XRenderer r = _this.htmlWindow;
r.showURL( url);
return thisObj;
}
}
private void setOptions( XJSWindow parent, String name, String options) {
this.parent = parent;
this.name = name;
/** @todo: Make options! */
}
/** Given window name, returns existing XJSWindow or null if new must be opened. */
private XJSWindow getExistingWindow( String winName) {
if( winName == null)
return null;
if( winName.equals( "_blank"))
return null; // Load the linked document into a new blank window. This window is not named.
if( winName.equals( "_parent"))
return parent; // Load the linked document into the immediate parent of the document the link is in.
if( winName.equals( "_search")) /** @todo: When search pane will be done, use this. */
return null; // Load the linked document into the browser search pane. Available in Microsoft
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -