Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00017 package com.generalrobotix.ui.util;
00018
00019 import java.awt.*;
00020 import java.awt.event.*;
00021 import javax.swing.*;
00022
00023
00024 public abstract class AlertBox extends ModalDialog {
00025
00026 protected Object[] options_;
00027 protected JLabel caption_;
00028
00029 JTextArea message_;
00030 protected String title_;
00031
00032 private int messageType_;
00033 private JDialog dialog_;
00034
00035
00036 public AlertBox(Frame owner, String title, int messageType, int buttonType) {
00037 owner_ = owner;
00038 _init(title, messageType, buttonType);
00039 }
00040 public AlertBox(Dialog owner, String title, int messageType, int buttonType) {
00041 owner_ = owner;
00042 _init(title, messageType, buttonType);
00043 }
00044
00045 private void _init(String title, int messageType, int buttonType) {
00046 title_ = title;
00047 messageType_ = messageType;
00048
00049 caption_ = new JLabel("");
00050
00051
00052
00053 message_ = new JTextArea();
00054 message_.setOpaque(false);
00055 message_.setEditable(false);
00056 message_.setForeground(caption_.getForeground());
00057
00058
00059
00060 inputArea_ = new JPanel();
00061 inputArea_.setLayout(new GridBagLayout());
00062
00063 gbc_ = new GridBagConstraints();
00064
00065 listener_ = new ActionListener() {
00066 public void actionPerformed(ActionEvent evt) {
00067 InnerButton button = (InnerButton)evt.getSource();
00068 buttonType_ = button.getButtonType();
00069 buttonCommand_ = evt.getActionCommand();
00070 SwingUtilities.invokeLater(
00071 new Runnable() {
00072 public void run() {
00073 dispose();
00074 }
00075 }
00076 );
00077 }
00078 };
00079
00080 InnerButton okButton;
00081 switch (buttonType) {
00082 case NONE_TYPE:
00083 break;
00084 case OK_TYPE:
00085 okButton = new InnerButton(OK_BUTTON);
00086 options_ = new Object[] { okButton };
00087
00088 break;
00089 case OK_CANCEL_TYPE:
00090 okButton = new InnerButton(OK_BUTTON);
00091 options_ = new Object[] { okButton, new InnerButton(CANCEL_BUTTON) };
00092
00093 break;
00094 case YES_NO_TYPE:
00095 options_ = new Object[] {
00096 new InnerButton(YES_BUTTON),
00097 new InnerButton(NO_BUTTON)
00098 };
00099 break;
00100 case YES_NO_CANCEL_TYPE:
00101 options_ = new Object[] {
00102 new InnerButton(YES_BUTTON),
00103 new InnerButton(NO_BUTTON),
00104 new InnerButton(CANCEL_BUTTON)
00105 };
00106 break;
00107 }
00108
00109 mainPanel_ = new JPanel();
00110 mainPanel_.setLayout(new BorderLayout());
00111 mainPanel_.add(caption_, BorderLayout.NORTH);
00112 mainPanel_.add(message_, BorderLayout.CENTER);
00113 mainPanel_.add(inputArea_, BorderLayout.SOUTH);
00114 }
00115
00116 public void show() {
00117 JOptionPane optionPane = new JOptionPane(
00118 mainPanel_,
00119 messageType_,
00120 JOptionPane.DEFAULT_OPTION,
00121 null,
00122 options_,
00123 options_[0]
00124 );
00125
00126 dialog_ = optionPane.createDialog(owner_, title_);
00127 dialog_.setVisible(true);
00128 }
00129
00130 public void dispose() {
00131 dialog_.dispose();
00132 }
00133 public void setCaption(String caption) {
00134 caption_.setText(caption);
00135 }
00136 public void setTitle(String title) {
00137 title_ = title;
00138 }
00139 public void setMessage(String message) {
00140 message_.setText(message);
00141 }
00142
00143 }