window.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 444 行 · 第 1/2 页
JAVA
444 行
else if (evt_ instanceof ScrollEvent) {
((Scrollable) source).processScrollEvent((ScrollEvent) evt_);
requestFocus();
super.requestSync();
}
else if (evt_ instanceof PaintEvent) {
/*
* Unless the affected component is totally obscured by windows
* that are stacked above it, we must redraw its window and all the
* windows above it.
*/
if (!((Component) source).isTotallyObscured()) {
Vector windowlist = _term.getWindowList();
synchronized (windowlist) {
/*
* We have to draw the window rather than just the affected
* component, because setVisible(false) may have been set
* on the component.
*/
Window ancestor = ((Component) source).getAncestorWindow();
ancestor.draw();
/*
* Ignore windows that are underneath the window that
* contains the component that generated the PaintEvent.
*/
Window w = null;
int i;
for (i = 0; i < windowlist.size(); i++) {
w = (Window) windowlist.elementAt(i);
if (w == ancestor) break;
}
/*
* Redraw all the windows _above_ the one that generated
* the PaintEvent.
*/
for (; i < windowlist.size(); i++) {
w = (Window) windowlist.elementAt(i);
w.draw();
}
}
super.requestSync();
}
}
else if (evt_ instanceof SyncEvent) {
_term.sync();
}
else if (evt_ instanceof WindowEvent) {
WindowEvent we = (WindowEvent) evt_;
we.getWindow().processWindowEvent(we);
/*
* Now, having given the WindowListener objects a chance to process
* the WindowEvent, we must check if it was a WINDOW_CLOSING event
* sent to this window.
*/
if (we.getID() == AWTEvent.WINDOW_CLOSING) {
we.getWindow()._windowClosed = true;
/*
* Remove this window from the list of those displayed, and
* blank out the screen area where the window was displayed.
*/
_term.removeWindow(we.getWindow());
_term.blankBox(_origin, _size);
/*
* Now redraw all of the windows, from the bottom to the top.
*/
Vector winlist = _term.getWindowList();
Window window = null;
synchronized (winlist) {
for (int i = 0; i < winlist.size(); i++) {
window = (Window) winlist.elementAt(i);
window.draw();
}
if (window != null) // (there may be no windows left)
window.requestFocus();
}
/*
* Put a SyncEvent onto the SyncQueue. The SyncThread will
* sleep for 50 msec before putting it onto the EventQueue,
* from which it will be picked up by the active Window (i.e.
* an instance of this class), which will then call
* Toolkit.sync() directly. This is done to avoid calling
* sync() after the close of a window and again after the
* display of a new window which might be displayed immediately
* afterwards.
*/
if(window != null)
SyncQueue.getInstance().postEvent(new SyncEvent(window));
}
} // end if WindowEvent
else if (evt_ instanceof GarbageCollectionEvent) {
SyncQueue.getInstance().postEvent(evt_);
}
else if (evt_ instanceof InvocationEvent) {
((InvocationEvent) evt_).dispatch();
}
else {
/*
* It is a KeyEvent, MouseEvent, ActionEvent, ItemEvent, FocusEvent
* or a custom type of event.
*/
//System.err.println(evt_);
((Component) source).processEvent(evt_);
}
}
/**
* Hide this window and all of its contained components. This is done by
* putting a WINDOW_CLOSING event onto the queue.
*/
public void hide() {
if (!_visible) {
System.err.println("Trying to hide window " + this
+ " that is already hidden!");
return; // This window is already hidden.
}
_visible = false;
WindowEvent we = new WindowEvent(this, AWTEvent.WINDOW_CLOSING);
_term.getSystemEventQueue().postEvent(we);
}
/**
* Draw all the components in this window, and request the keyboard focus.
*/
public void draw() {
super.draw();
requestFocus();
}
/**
* Overrides the method in the Component superclass, because a Window has
* no parent container. Note that we return a COPY of the origin, not a
* reference to it, so that the caller cannot modify our location via the
* returned value.
*/
public Point getLocationOnScreen() {
return new Point(_origin);
}
/**
* A Window component will not receive input focus during keyboard focus
* traversal using Tab and Shift-Tab.
*/
public boolean isFocusTraversable() {
return false;
}
/**
* Adjust the position of the window so that it fits inside the screen.
*/
public void adjustLocation() {
int bottom = _origin.y + getHeight();
if (bottom > _term.getScreenRows())
_origin.y -= bottom - _term.getScreenRows();
if (_origin.y < 0) _origin.y = 0;
int right = _origin.x + getWidth();
if (right > _term.getScreenColumns())
_origin.x -= right - _term.getScreenColumns();
if (_origin.x < 0) _origin.x = 0;
}
public void debug(int level_) {
System.err.println("Window origin=" + _origin + " size=" + _size);
super.debug(1);
}
private void startPlayback() {
String scriptfilename = null;
BufferedReader scriptReader = null;
if ((scriptfilename = System.getProperty("charva.script.playback")) == null)
return;
try {
scriptReader = new BufferedReader(new FileReader(scriptfilename));
} catch (FileNotFoundException ef) {
System.err.println("Cannot open script file \"" + scriptfilename
+ "\" for reading");
return;
}
PlaybackThread thr = new PlaybackThread(scriptReader);
thr.setDaemon(true);
thr.setName("playback thread");
thr.start();
}
//====================================================================
// INSTANCE VARIABLES
private Window _owner;
protected Toolkit _term;
private boolean _windowClosed = false;
private Vector _windowListeners = null;
private static boolean _dispatchThreadRunning = false;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?