AlertBox.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.util;
18 
19 import java.awt.*;
20 import java.awt.event.*;
21 import javax.swing.*;
22 
23 
24 public abstract class AlertBox extends ModalDialog {
25  //--------------------------------------------------------------------
26  protected Object[] options_;
27  protected JLabel caption_;
28  //protected JLabel message_;
29  JTextArea message_;
30  protected String title_;
31 
32  private int messageType_;
33  private JDialog dialog_;
34 
35  //--------------------------------------------------------------------
36  public AlertBox(Frame owner, String title, int messageType, int buttonType) {
37  owner_ = owner;
38  _init(title, messageType, buttonType);
39  }
40  public AlertBox(Dialog owner, String title, int messageType, int buttonType) {
41  owner_ = owner;
42  _init(title, messageType, buttonType);
43  }
44 
45  private void _init(String title, int messageType, int buttonType) {
46  title_ = title;
47  messageType_ = messageType;
48 
49  caption_ = new JLabel("");
50  //caption_.setForeground(Color.black);
51  //caption_.setBorder(new EmptyBorder(12, 12, 1, 0));
52 
53  message_ = new JTextArea();
54  message_.setOpaque(false);
55  message_.setEditable(false);
56  message_.setForeground(caption_.getForeground());
57  //message_ = new JLabel("");
58  //message_.setBorder(new EmptyBorder(12, 12, 1, 0));
59 
60  inputArea_ = new JPanel();
61  inputArea_.setLayout(new GridBagLayout());
62  //inputArea_.setBorder(new EmptyBorder(0, 0, 0, 0));
63  gbc_ = new GridBagConstraints();
64 
65  listener_ = new ActionListener() {
66  public void actionPerformed(ActionEvent evt) {
67  InnerButton button = (InnerButton)evt.getSource();
68  buttonType_ = button.getButtonType();
69  buttonCommand_ = evt.getActionCommand();
70  SwingUtilities.invokeLater(
71  new Runnable() {
72  public void run() {
73  dispose();
74  }
75  }
76  );
77  }
78  };
79 
80  InnerButton okButton;
81  switch (buttonType) {
82  case NONE_TYPE:
83  break;
84  case OK_TYPE:
85  okButton = new InnerButton(OK_BUTTON);
86  options_ = new Object[] { okButton };
87  //getRootPane().setDefaultButton(okButton);
88  break;
89  case OK_CANCEL_TYPE:
90  okButton = new InnerButton(OK_BUTTON);
91  options_ = new Object[] { okButton, new InnerButton(CANCEL_BUTTON) };
92  //getRootPane().setDefaultButton(okButton);
93  break;
94  case YES_NO_TYPE:
95  options_ = new Object[] {
98  };
99  break;
100  case YES_NO_CANCEL_TYPE:
101  options_ = new Object[] {
102  new InnerButton(YES_BUTTON),
103  new InnerButton(NO_BUTTON),
105  };
106  break;
107  }
108 
109  mainPanel_ = new JPanel();
110  mainPanel_.setLayout(new BorderLayout());
111  mainPanel_.add(caption_, BorderLayout.NORTH);
112  mainPanel_.add(message_, BorderLayout.CENTER);
113  mainPanel_.add(inputArea_, BorderLayout.SOUTH);
114  }
115 
116  public void show() {
117  JOptionPane optionPane = new JOptionPane(
118  mainPanel_,
119  messageType_,
120  JOptionPane.DEFAULT_OPTION,
121  null,
122  options_,
123  options_[0]
124  );
125 
126  dialog_ = optionPane.createDialog(owner_, title_);
127  dialog_.setVisible(true);
128  }
129 
130  public void dispose() {
131  dialog_.dispose();
132  }
133  public void setCaption(String caption) {
134  caption_.setText(caption);
135  }
136  public void setTitle(String title) {
137  title_ = title;
138  }
139  public void setMessage(String message) {
140  message_.setText(message);
141  }
142 
143 }
void setMessage(String message)
Definition: AlertBox.java:139
#define null
our own NULL pointer
Definition: IceTypes.h:57
void setCaption(String caption)
Definition: AlertBox.java:133
AlertBox(Dialog owner, String title, int messageType, int buttonType)
Definition: AlertBox.java:40
AlertBox(Frame owner, String title, int messageType, int buttonType)
Definition: AlertBox.java:36
def run(tree, args)
void _init(String title, int messageType, int buttonType)
Definition: AlertBox.java:45


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:18