AlertBox.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
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     //protected JLabel message_;
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         //caption_.setForeground(Color.black);
00051         //caption_.setBorder(new EmptyBorder(12, 12, 1, 0));
00052 
00053         message_ = new JTextArea();
00054         message_.setOpaque(false);
00055         message_.setEditable(false);
00056         message_.setForeground(caption_.getForeground());
00057         //message_ = new JLabel("");
00058         //message_.setBorder(new EmptyBorder(12, 12, 1, 0));
00059 
00060         inputArea_ = new JPanel();
00061         inputArea_.setLayout(new GridBagLayout());
00062         //inputArea_.setBorder(new EmptyBorder(0, 0, 0, 0));
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             //getRootPane().setDefaultButton(okButton);
00088             break;
00089         case OK_CANCEL_TYPE:
00090             okButton = new InnerButton(OK_BUTTON);
00091             options_ = new Object[] { okButton, new InnerButton(CANCEL_BUTTON) };
00092             //getRootPane().setDefaultButton(okButton);
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 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:52