📄 ergodialog.java
字号:
package ergo.ui;
// $Id: ErgoDialog.java,v 1.2 1999/08/13 01:20:07 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.*;
import java.awt.event.*;
/*
* To do:
* - Really need to come up with a coherent interface and class structure
* for all these dialogs...
*/
/**
* Handles the WINDOW_DESTROY event and provides default methods.
* All other dialogs in Ergo should use this as a superclass.
*/
public class ErgoDialog extends Dialog implements FocusListener {
private boolean disposeOnExit = true;
ErgoDialog (Frame f, String title, boolean modal, boolean disposep) {
super(f, title, modal);
disposeOnExit = disposep;
// Deal with the user clicking the dialog's close box.
addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent e) { close(); }});
}
ErgoDialog (Frame f, String title, boolean modal) {
this(f, title, modal, true);
}
public void focusGained (FocusEvent e) {
if (e.getComponent() instanceof TextField) {
TextField field = (TextField) e.getComponent();
if (field.isEditable())
field.selectAll();
}
}
public void focusLost (FocusEvent e) {
if (e.getComponent() instanceof TextField) {
TextField field = (TextField) e.getComponent();
if (field.isEditable())
field.select(0, 0);
}
}
private void addTextFieldListeners (Component[] comps) {
if (comps != null) {
// Add this dialog as a FocusListener for each TextField it contains
// so that we can highlight the text when it gains focus.
for (int i = 0; i < comps.length; i++)
if (comps[i] instanceof TextField) {
TextField field = (TextField) comps[i];
if (field.isEditable())
field.addFocusListener(this);
}
else if (comps[i] instanceof Container) {
addTextFieldListeners(((Container) comps[i]).getComponents());
}
}
}
public Component getInitialFocus () { // default method
return null;
}
public void open () {
pack();
addTextFieldListeners(getComponents());
Rectangle pr = getParent().getBounds();
Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
int w = getSize().width;
int h = getSize().height;
int x = Math.min(ss.width - w, Math.max(0, pr.x + (pr.width - w) / 2));
int y = Math.min(ss.height - h, Math.max(0, pr.y + (pr.height - h) / 2));
setBounds(x, y, getSize().width, getSize().height);
//setVisible(true);
show(); // show() for dialogs. setVisible() for Components. go figure.
Component comp = getInitialFocus();
if (comp != null)
comp.requestFocus();
}
public void close () {
if (disposeOnExit)
dispose();
else
setVisible(false);
//getParent().enable();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -