7 package org.libcsdbg.jtracer;
9 import java.awt.event.KeyEvent;
10 import java.awt.event.ActionEvent;
11 import java.awt.event.ActionListener;
13 import java.awt.Color;
14 import java.awt.Insets;
15 import java.awt.BorderLayout;
16 import java.awt.GridBagLayout;
17 import java.awt.GridBagConstraints;
19 import javax.swing.JDialog;
20 import javax.swing.JFrame;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.ImageIcon;
24 import javax.swing.WindowConstants;
29 public class Alert extends JDialog implements ActionListener
56 Alert(JFrame owner, String msg,
short desc)
61 ok.setMnemonic(KeyEvent.VK_O);
64 cancel.setMnemonic(KeyEvent.VK_C);
66 GridBagLayout lm =
new GridBagLayout();
67 JPanel center =
new JPanel(lm);
68 JPanel south =
new JPanel(lm);
69 ImageIcon icon = null;
71 Registry conf = Registry.getCurrent();
72 GridBagConstraints c =
new GridBagConstraints();
73 c.gridy = c.gridx = 0;
74 c.insets =
new Insets(12, 4, 4, 4);
80 icon = conf.loadIcon(
"prompt32.png");
82 lm.setConstraints(ok, c);
86 lm.setConstraints(cancel, c);
92 icon = conf.loadIcon(
"error32.png");
93 lm.setConstraints(ok, c);
98 setTitle(
"Information");
99 icon = conf.loadIcon(
"info32.png");
100 lm.setConstraints(ok, c);
105 String lines[] = msg.split(
"\\n");
107 JLabel l =
new JLabel(icon);
109 c.insets =
new Insets(12, 12, 0, 12);
110 c.anchor = GridBagConstraints.NORTH;
111 c.gridheight = lines.length;
112 lm.setConstraints(l, c);
115 c.gridx = c.gridheight = 1;
116 c.insets =
new Insets(8, 0, 0, 8);
117 c.anchor = GridBagConstraints.WEST;
119 Font fnt = (Font) conf.
get(
"message",
"font");
120 Color fg = (Color) conf.
get(
"message",
"fgcolor");
121 for (
int i = 0, cnt = lines.length; i < cnt; i++) {
122 l =
new JLabel(lines[i]);
127 lm.setConstraints(l, c);
132 add(center, BorderLayout.CENTER);
133 add(south, BorderLayout.SOUTH);
135 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
138 setLocationRelativeTo(owner);
165 public static void error(JFrame owner, String msg,
boolean fatal)
180 public static void info(JFrame owner, String msg)
195 public static boolean prompt(JFrame owner, String msg)
210 String cmd = event.getActionCommand();
211 if (cmd.equals(
"Ok"))
217 catch (Throwable t) {
Object get(String section, String key)
Get an entry.
static boolean prompt(JFrame owner, String msg)
Show an alert prompting the user to make a choice.
static void info(JFrame owner, String msg)
Show a generic alert.
boolean getReply()
Get the user reply.
void actionPerformed(ActionEvent event)
Handler for action events fired by the alert buttons.
static void error(JFrame owner, String msg, boolean fatal)
Show an error alert and exit if the error is marked as fatal.
static final long serialVersionUID
Class version.
User alert or simple prompt dialog with configurable styles.
static final short ERROR_MSG
Alert type for error messages.
boolean reply
The user reply.
static final short QUESTION_MSG
Alert type for prompt messages.
static final short INFORMATION_MSG
Alert type for plain, information messages.