📄 positionlistener.java
字号:
package ergo.ui;
// $Id: PositionListener.java,v 1.2 1999/08/13 01:20:10 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import java.awt.event.*;
import java.awt.*;
// Utility class of miraculous device. Simply create it, and it
// listens...!
public class PositionListener extends ComponentAdapter {
private String posKey;
private Window targetWin;
private Optionizer opser;
public PositionListener (String posKey1, Window targetWin1, Point pos, Optionizer opser) {
posKey = posKey1; targetWin = targetWin1; this.opser = opser;
targetWin.addComponentListener(this);
opser.expressOwnership(posKey1, Optionizer.TYPE_POSITION, null, pos);
targetWin.setLocation(opser.getPointOption(posKey));
}
// We seem to be shafted by the AWT again. This is called not only
// when the component is moved, but (in the case of a Window) also
// when it gets iconified. At least under Windows that seems to be
// implemented by setting the Window's position to (3000,3000). I would
// hardly consider iconifying a component equal to moving it. Anyway,
// this means we have to add special case code here to make sure not to
// let the component move completely off the screen. (To make matters
// worse, when the Window is iconified, isShowing(), isVisible(), and
// isEnabled() all return true.) -sigue at JDK 1.1.4
public void componentMoved (ComponentEvent e) {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Point loc = targetWin.getLocation();
int slop = 10;
// It's ok if the user wants part of the window offscreen. Just
// don't update the option if it's completely off the screen.
if (loc.x < (size.width - slop)
&& loc.y < (size.height - slop)
&& loc.x >= -slop
&& loc.y >= -slop)
opser.updateOption(posKey, targetWin.getLocation());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -