public void showPrompts(String name,
String instruction,
KBIPrompt[] prompts) {
setTitle(name);
getContentPane().invalidate();
getContentPane().removeAll();
instructionLabel.setText(instruction);
JPanel promptPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 4, 4);
gbc.fill = GridBagConstraints.CENTER;
gbc.anchor = GridBagConstraints.WEST;
promptReply = new JTextComponent[prompts.length];
for (int i = 0; i < prompts.length; i++) {
if (prompts[i].echo()) {
promptReply[i] = new XTextField(prompts[i].getResponse(), 15);
} else {
promptReply[i] = new JPasswordField(prompts[i].getResponse(), 15);
}
System.out.println("Creating prompt " + prompts[i].getPrompt() +
" and setting to " + prompts[i].getResponse());
gbc.weightx = 0.0;
UIUtil.jGridBagAdd(promptPanel,
new JLabel(prompts[i].getPrompt() + " "), gbc,
GridBagConstraints.RELATIVE);
gbc.weightx = 1.0;
UIUtil.jGridBagAdd(promptPanel, promptReply[i], gbc,
GridBagConstraints.REMAINDER);
}
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
centerPanel.add(instructionLabel, BorderLayout.NORTH);
centerPanel.add(promptPanel, BorderLayout.CENTER);
// Create the center banner panel
IconWrapperPanel iconPanel = new IconWrapperPanel(new ResourceIcon(
KBIRequestHandlerDialog.class, KBI_ICON), centerPanel);
iconPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
// The main panel contains everything and is surrounded by a border
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
mainPanel.add(iconPanel, BorderLayout.CENTER);
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
// Build the main panel
getContentPane().setLayout(new GridLayout(1, 1));
getContentPane().add(mainPanel);
getContentPane().validate();
pack();
UIUtil.positionComponent(SwingConstants.CENTER, this);
setVisible(true);
if (!cancelled) {
for (int i = 0; i < promptReply.length; i++) {
System.out.println("Setting reply " + i + " to " +
promptReply[i].getText());
prompts[i].setResponse(promptReply[i].getText());
}
}
}
|