01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: MessageBox.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
08:
09: package org.ozoneDB.tools;
10:
11: import java.awt.*;
12: import java.awt.event.*;
13:
14: public class MessageBox extends Dialog {
15: public static int YES = 1;
16: public static int NO = 2;
17: public static int CANCEL = 4;
18: public static int OK = 8;
19: public static int CONFIRM = 16;
20: static int choice;
21:
22: class MBButton extends Button implements ActionListener {
23: int kind;
24:
25: public MBButton(String title, int _kind) {
26: super (title);
27: kind = _kind;
28: addActionListener(this );
29: }
30:
31: public void actionPerformed(ActionEvent e) {
32: ((MessageBox) getParent()).choice = kind;
33: ((MessageBox) getParent()).close();
34: }
35: }
36:
37: MessageBox(Frame parent, String msg, int buttons) {
38: super (parent, true);
39: setLayout(new GridBagLayout());
40: GridBagConstraints c = new GridBagConstraints();
41: c.weightx = 1.0;
42: c.weighty = 1.0;
43: c.fill = GridBagConstraints.NONE;
44: c.anchor = GridBagConstraints.CENTER;
45: c.gridwidth = GridBagConstraints.REMAINDER;
46: add(new Label(msg), c);
47: c.fill = GridBagConstraints.BOTH;
48: c.gridwidth = GridBagConstraints.RELATIVE;
49: if ((buttons & YES) != 0) {
50: add(new MBButton("YES", YES), c);
51: }
52: if ((buttons & NO) != 0) {
53: add(new MBButton("NO", NO), c);
54: }
55: if ((buttons & CANCEL) != 0) {
56: add(new MBButton("CANCEL", CANCEL), c);
57: }
58: if ((buttons & OK) != 0) {
59: add(new MBButton("OK", OK), c);
60: }
61: if ((buttons & CONFIRM) != 0) {
62: add(new MBButton("CONFIRM", CONFIRM), c);
63: }
64: setSize(20 + msg.length() * 7, 80);
65: setLocation(200, 200);
66: show();
67: }
68:
69: public void close() {
70: setVisible(false);
71: }
72:
73: public static int YesNoBox(Frame parent, String msg) {
74: new MessageBox(parent, msg, YES | NO);
75: return choice;
76: }
77:
78: public static int OkCancelBox(Frame parent, String msg) {
79: new MessageBox(parent, msg, OK | CANCEL);
80: return choice;
81: }
82:
83: public static int ConfirmBox(Frame parent, String msg) {
84: new MessageBox(parent, msg, CONFIRM);
85: return choice;
86: }
87: }
|