You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.3 KiB
109 lines
2.3 KiB
package de.memtext.dlg; |
|
|
|
import java.awt.BorderLayout; |
|
import java.awt.Container; |
|
import java.awt.Dialog; |
|
import java.awt.Frame; |
|
import java.awt.HeadlessException; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
|
|
import javax.swing.JButton; |
|
import javax.swing.JComponent; |
|
import javax.swing.JPanel; |
|
|
|
/** |
|
* Dialog which can only be closed by clicking OK. |
|
* |
|
* setCenter for convenienance. |
|
* |
|
* @author MB |
|
* |
|
*/ |
|
|
|
public class OkDlg extends DialogWithExit { |
|
private JPanel psouth = new JPanel(); |
|
|
|
protected JButton ok = new JButton("OK"); |
|
|
|
/** |
|
* Constructor for OkDlg. |
|
* @param arg0 |
|
* @throws HeadlessException |
|
*/ |
|
public OkDlg(Frame owner) throws HeadlessException { |
|
super(owner, true); |
|
initSouth(); |
|
} |
|
|
|
public OkDlg(Frame owner, String title, boolean isModal) { |
|
super(owner, title, isModal); |
|
initSouth(); |
|
} |
|
|
|
|
|
public OkDlg(Frame owner, String title) throws HeadlessException { |
|
super(owner, title, true); |
|
initSouth(); |
|
} |
|
|
|
|
|
public JButton getOkBtn() { |
|
return ok; |
|
} |
|
|
|
|
|
/** |
|
* Constructor for OkDlg. |
|
* @param arg0 |
|
* @throws HeadlessException |
|
*/ |
|
public OkDlg(Dialog arg0) throws HeadlessException { |
|
super(arg0, true); |
|
initSouth(); |
|
} |
|
|
|
|
|
private void initSouth() { |
|
|
|
ok.addActionListener(new ActionListener() { |
|
|
|
@Override |
|
public void actionPerformed(ActionEvent ae) { |
|
performOk(); |
|
} |
|
}); |
|
psouth.add(ok); |
|
|
|
Container cp = this.getContentPane(); |
|
cp.add(psouth, BorderLayout.SOUTH); |
|
this.getRootPane().setDefaultButton(ok); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void addBeforeOK(JComponent comp) { |
|
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
|
psouth.add(comp, pos); |
|
} |
|
|
|
public void addAfterOK(JComponent comp) { |
|
int pos = de.memtext.util.ComponentUtils.getPositionOnComponent(ok, psouth); |
|
psouth.add(comp, pos + 1); |
|
} |
|
|
|
/** |
|
* subclasses can override this method and specify commands |
|
* to be executed when OK was clicked |
|
*/ |
|
protected void performOk() { |
|
this.hide(); |
|
} |
|
|
|
public static void main(String args[]) { |
|
OkDlg d = new OkDlg(new javax.swing.JFrame()); |
|
d.show(); |
|
} |
|
}
|
|
|