17 package com.generalrobotix.ui.util;
19 import java.awt.AWTEventMulticaster;
20 import java.awt.BorderLayout;
21 import java.awt.Component;
22 import java.awt.Dialog;
23 import java.awt.Frame;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Window;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.WindowEvent;
31 import javax.swing.Box;
32 import javax.swing.BoxLayout;
33 import javax.swing.JButton;
34 import javax.swing.JDialog;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.SwingUtilities;
38 import javax.swing.border.EmptyBorder;
44 @SuppressWarnings(
"serial")
50 public static final int NONE_TYPE = 0;
51 public static final int OK_TYPE = 1;
52 public static final int OK_CANCEL_TYPE = 2;
53 public static final int YES_NO_TYPE = 3;
54 public static final int YES_NO_CANCEL_TYPE = 4;
57 public static final int INLINE_CAPTION = 1;
58 public static final int MULTILINE_CAPTION = 2;
61 public static final int CUSTOM_BUTTON = 0;
62 public static final int OK_BUTTON = 1;
63 public static final int CANCEL_BUTTON = 2;
64 public static final int YES_BUTTON = 3;
65 public static final int NO_BUTTON = 4;
66 public static final int CLOSE_BUTTON = 5;
69 private static final int BUTTON_GAP = 5;
70 private static final int CAPTION_GAP = 11;
78 protected boolean closeButtonEnabled_ =
true;
85 protected GridBagConstraints
gbc_;
97 super(owner, title,
true);
99 _init(title, message, buttonType);
108 super(owner, title,
true);
110 _init(title, message, buttonType);
113 private void _init(String title, String message,
int buttonType) {
114 JLabel messageLabel =
new JLabel(message);
117 inputArea_ =
new JPanel();
118 inputArea_.setLayout(
new GridBagLayout());
119 inputArea_.setBorder(
new EmptyBorder(6, 12, 0, 0));
120 gbc_ =
new GridBagConstraints();
122 listener_ =
new ActionListener() {
123 public void actionPerformed(ActionEvent evt) {
126 buttonCommand_ = evt.getActionCommand();
127 SwingUtilities.invokeLater(
137 buttonArea_ =
new JPanel();
138 buttonArea_.setBorder(
new EmptyBorder(0, 0, 11, 11));
139 buttonArea_.setLayout(
new BoxLayout(buttonArea_, BoxLayout.X_AXIS));
140 buttonArea_.setAlignmentX(Component.LEFT_ALIGNMENT);
141 buttonArea_.add(Box.createHorizontalGlue());
144 switch (buttonType) {
149 getRootPane().setDefaultButton(okButton);
150 buttonArea_.add(okButton);
154 getRootPane().setDefaultButton(okButton);
155 buttonArea_.add(okButton);
156 buttonArea_.add(Box.createHorizontalStrut(BUTTON_GAP));
161 buttonArea_.add(Box.createHorizontalStrut(BUTTON_GAP));
164 case YES_NO_CANCEL_TYPE:
166 buttonArea_.add(Box.createHorizontalStrut(BUTTON_GAP));
168 buttonArea_.add(Box.createHorizontalStrut(BUTTON_GAP));
173 mainPanel_ =
new JPanel();
174 mainPanel_.setLayout(
new BorderLayout());
175 mainPanel_.setBorder(
new EmptyBorder(12, 12, 17, 11));
176 mainPanel_.add(messageLabel, BorderLayout.NORTH);
177 mainPanel_.add(inputArea_, BorderLayout.CENTER);
179 getContentPane().add(mainPanel_, BorderLayout.CENTER);
180 getContentPane().add(buttonArea_, BorderLayout.SOUTH);
188 gbc_.gridwidth = GridBagConstraints.REMAINDER;
189 gbc_.fill = GridBagConstraints.HORIZONTAL;
190 inputArea_.add(Box.createHorizontalStrut(width_), gbc_);
205 gbc_.gridwidth = GridBagConstraints.REMAINDER;
206 gbc_.fill = GridBagConstraints.HORIZONTAL;
207 inputArea_.add(Box.createVerticalStrut(11), gbc_);
209 gbc_.anchor = GridBagConstraints.NORTHWEST;
210 gbc_.fill = GridBagConstraints.NONE;
214 if (caption ==
null || caption.equals(
"")) {
215 label =
new JLabel(
"");
217 label =
new JLabel(caption +
" :");
223 inputArea_.add(label, gbc_);
225 inputArea_.add(Box.createHorizontalStrut(CAPTION_GAP));
227 case MULTILINE_CAPTION:
228 gbc_.gridwidth = GridBagConstraints.REMAINDER;
229 inputArea_.add(label, gbc_);
231 gbc_.gridwidth = GridBagConstraints.REMAINDER;
232 gbc_.fill = GridBagConstraints.HORIZONTAL;
233 inputArea_.add(Box.createVerticalStrut(6), gbc_);
236 inputArea_.add(Box.createHorizontalStrut(12));
242 gbc_.anchor = GridBagConstraints.NORTHWEST;
243 gbc_.gridwidth = GridBagConstraints.REMAINDER;
245 gbc_.fill = GridBagConstraints.HORIZONTAL;
247 gbc_.fill = GridBagConstraints.NONE;
250 inputArea_.add(component, gbc_);
254 buttonArea_.add(Box.createHorizontalStrut(BUTTON_GAP));
256 button.setCaption(caption);
257 buttonArea_.add(button);
264 setLocationRelativeTo(owner_);
271 owner_.setEnabled(
false);
273 setLocationRelativeTo(owner_);
279 owner_.setEnabled(
true);
283 listener_ = AWTEventMulticaster.add(listener_, listener);
287 listener_ = AWTEventMulticaster.remove(listener_, listener);
291 closeButtonEnabled_ = enabled;
295 if (closeButtonEnabled_) {
296 super.processWindowEvent(evt);
327 void setCaption(String caption) {
329 setActionCommand(caption);
static final String get(String key)
png_infop png_charp png_int_32 png_int_32 int * type
void _init(String title, String message, int buttonType)
#define null
our own NULL pointer
void addInputComponent(String caption, Component component, int location, boolean fill)
void setInputAreaWidth(int width)
png_infop png_uint_32 * width
ModalDialog(Frame owner, String title, String message, int buttonType)
void addButton(String caption)
png_infop int int location
void setCloseButtonEnabled(boolean enabled)
void addActionListener(ActionListener listener)
ModalDialog(Dialog owner, String title, String message, int buttonType)
void processWindowEvent(WindowEvent evt)
void removeActionListener(ActionListener listener)