void init(String prompt) {
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
JPanel g = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 0, 2, 2);
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0.0;
UIUtil.jGridBagAdd(g, new JLabel("Password: "), gbc,
GridBagConstraints.RELATIVE);
gbc.weightx = 1.0;
UIUtil.jGridBagAdd(g, password, gbc, GridBagConstraints.REMAINDER);
gbc.weightx = 0.0;
UIUtil.jGridBagAdd(g, new JLabel("Confirm: "), gbc,
GridBagConstraints.RELATIVE);
gbc.weightx = 1.0;
UIUtil.jGridBagAdd(g, confirm, gbc, GridBagConstraints.REMAINDER);
//
promptLabel.setHorizontalAlignment(JLabel.CENTER);
// Main panel
JPanel centerPanel = new JPanel(new BorderLayout());
centerPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
centerPanel.add(promptLabel, BorderLayout.NORTH);
centerPanel.add(g, BorderLayout.CENTER);
// Create the bottom button panel
JButton ok = new JButton("Ok");
ok.setMnemonic('o");
ok.setDefaultCapable(true);
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (!new String(password.getPassword()).equals(
new String(confirm.getPassword()))) {
JOptionPane.showMessageDialog(PasswordChangeDialog.this,
"Passwords do not match. Please try again.",
"Passwords do not match",
JOptionPane.ERROR_MESSAGE);
} else {
setVisible(false);
}
}
});
getRootPane().setDefaultButton(ok);
JButton cancel = new JButton("Cancel");
cancel.setMnemonic('c");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
cancelled = true;
setVisible(false);
}
});
JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
southPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
southPanel.add(cancel);
southPanel.add(ok);
// Create the center banner panel
IconWrapperPanel iconPanel = new IconWrapperPanel(new ResourceIcon(
SshToolsConnectionHostTab.AUTH_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(southPanel, BorderLayout.SOUTH);
// Build the main panel
getContentPane().setLayout(new GridLayout(1, 1));
getContentPane().add(mainPanel);
pack();
toFront();
UIUtil.positionComponent(SwingConstants.CENTER, this);
setVisible(true);
}
|