public OptionDialog(int type, Object text, Option choices[], OptionCallback callback, Component buttonBarAccessory) {
super(new BorderLayout());
lock_ = new Object();
dismissed = false;
this.callback = callback;
Panel titlePanel = new Panel(new FlowLayout(0));
Image icon = null;
switch (type) {
case 0:
// '\0'
icon = UIUtil.loadImage(getClass(), INFORMATION_ICON);
break;
case 2:
// '\002'
icon = UIUtil.loadImage(getClass(), WARNING_ICON);
break;
case 1:
// '\001'
icon = UIUtil.loadImage(getClass(), QUESTION_ICON);
break;
case 99:
break;
default:
icon = UIUtil.loadImage(getClass(), ERROR_ICON);
break;
}
if (icon != null) {
UIUtil.waitFor(icon, this);
}
Panel textPanel = new Panel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.NONE;
if (text instanceof Component) {
UIUtil.gridBagAdd(textPanel, (Component) text, gbc, 0);
} else {
StringTokenizer st = new StringTokenizer(String.valueOf(text), "\n"); //$NON-NLS-1$
while (st.hasMoreTokens()) {
String n = st.nextToken().trim();
if (n.length() > 0) {
UIUtil.gridBagAdd(textPanel, new Label(n), gbc, 0);
}
}
}
add(textPanel, "Center"); //$NON-NLS-1$
Panel choicePanel = new Panel(new FlowLayout(buttonBarAccessory == null ? FlowLayout.CENTER : FlowLayout.RIGHT));
OptionWrapper choice = new OptionWrapper();
choice.idx = -1;
for (int i = 0; choices != null && i < choices.length; i++) {
// ImageButton b = new ImageButton(choices[i].getIcon(), choices[i]
// .getText(), choices[i].getText());
Button b = new Button(choices[i].getText()) {
public Dimension getMinimumSize() {
return new Dimension(60, super.getMinimumSize().height);
}
public Dimension getPreferredSize() {
return getMinimumSize();
}
};
choicePanel.add(b);
b.addActionListener(new BlockingActionListener(choices[i]));
}
if (icon != null) {
add(new ImageCanvas(icon), "West"); //$NON-NLS-1$
}
if(buttonBarAccessory != null) {
Panel p= new Panel(new GridBagLayout());
GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.anchor = GridBagConstraints.WEST;
gbc2.fill = GridBagConstraints.HORIZONTAL;
gbc2.insets = new Insets(2, 4, 2, 2);
UIUtil.gridBagAdd(p, buttonBarAccessory, gbc2, GridBagConstraints.RELATIVE);