private void initGui() {
this.setResizable(false);
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
String introductionText = "<html><center>Configure Cockpit's preferences</center></html>";
JHtmlLabel introductionLabel = new JHtmlLabel(introductionText, hyperlinkListener);
introductionLabel.setHorizontalAlignment(JLabel.CENTER);
cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
cancelButton.addActionListener(this);
okButton = new JButton("Apply preferences");
okButton.setActionCommand("ApplyPreferences");
okButton.addActionListener(this);
// Set default ENTER and ESCAPE buttons.
this.getRootPane().setDefaultButton(okButton);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke("ESCAPE"), "ESCAPE");
this.getRootPane().getActionMap().put("ESCAPE", new AbstractAction() {
private static final long serialVersionUID = 1478626539912658292L;
public void actionPerformed(ActionEvent actionEvent) {
setVisible(false);
}
});
JPanel buttonsPanel = new JPanel(new GridBagLayout());
buttonsPanel.add(cancelButton, new GridBagConstraints(0, 0,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
buttonsPanel.add(okButton, new GridBagConstraints(1, 0,
1, 1, 1, 0, GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
// Uploads preferences pane.
JPanel uploadPrefsPanel = new JPanel(new GridBagLayout());
int row = 0;
JHtmlLabel aclPrefsLabel = new JHtmlLabel(
"ACL Permissions", hyperlinkListener);
uploadPrefsPanel.add(aclPrefsLabel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
aclButtonGroup = new ButtonGroup();
JRadioButton aclPrivateButton = new JRadioButton("Private", true);
aclPrivateButton.setActionCommand(CockpitPreferences.UPLOAD_ACL_PERMISSION_PRIVATE);
JRadioButton aclPublicReadButton = new JRadioButton("Public read");
aclPublicReadButton.setActionCommand(CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ);
JRadioButton aclPublicReadWriteButton = new JRadioButton("Public read and write");
aclPublicReadWriteButton.setActionCommand(CockpitPreferences.UPLOAD_ACL_PERMISSION_PUBLIC_READ_WRITE);
aclButtonGroup.add(aclPrivateButton);
aclButtonGroup.add(aclPublicReadButton);
aclButtonGroup.add(aclPublicReadWriteButton);
JPanel aclPrefsRadioPanel = new JPanel(new GridBagLayout());
aclPrefsRadioPanel.add(aclPrivateButton, new GridBagConstraints(0, 0,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
aclPrefsRadioPanel.add(aclPublicReadButton, new GridBagConstraints(1, 0,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
aclPrefsRadioPanel.add(aclPublicReadWriteButton, new GridBagConstraints(2, 0,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
uploadPrefsPanel.add(aclPrefsRadioPanel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
JHtmlLabel compressionPrefsLabel = new JHtmlLabel(
"Compress files with GZip?", hyperlinkListener);
uploadPrefsPanel.add(compressionPrefsLabel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
compressButtonGroup = new ButtonGroup();
JRadioButton compressNoButton = new JRadioButton("Don't compress", true);
compressNoButton.setActionCommand("INACTIVE");
JRadioButton compressYesButton = new JRadioButton("Compress");
compressYesButton.setActionCommand("ACTIVE");
compressButtonGroup.add(compressNoButton);
compressButtonGroup.add(compressYesButton);
JPanel compressPrefsRadioPanel = new JPanel(new GridBagLayout());
compressPrefsRadioPanel.add(compressNoButton, new GridBagConstraints(0, 0,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
compressPrefsRadioPanel.add(compressYesButton, new GridBagConstraints(1, 0,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
uploadPrefsPanel.add(compressPrefsRadioPanel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
JHtmlLabel encryptionPrefsLabel = new JHtmlLabel(
"<html>Encrypt Uploaded Files?<br><font size=\"-2\">If encryption is turned on you must " +
"also set the Encryption password</html>", hyperlinkListener);
uploadPrefsPanel.add(encryptionPrefsLabel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
encryptButtonGroup = new ButtonGroup();
JRadioButton encryptNoButton = new JRadioButton("Don't encrypt", true);
encryptNoButton.setActionCommand("INACTIVE");
JRadioButton encryptYesButton = new JRadioButton("Encrypt");
encryptYesButton.setActionCommand("ACTIVE");
encryptButtonGroup.add(encryptNoButton);
encryptButtonGroup.add(encryptYesButton);
encryptPasswordField = new JPasswordField();
JPanel encryptPrefsRadioPanel = new JPanel(new GridBagLayout());
encryptPrefsRadioPanel.add(encryptNoButton, new GridBagConstraints(0, 0,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
encryptPrefsRadioPanel.add(encryptYesButton, new GridBagConstraints(1, 0,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
uploadPrefsPanel.add(encryptPrefsRadioPanel, new GridBagConstraints(0, row++,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
// Determine the default crypto algorithm from jets3t.properties.
String encryptAlgorithm = Jets3tProperties.getInstance(Constants.JETS3T_PROPERTIES_FILENAME)
.getStringProperty("crypto.algorithm", "PBEWithMD5AndDES");
// Determine the available PBE algorithms.
String[] algorithms = EncryptionUtil.listAvailablePbeCiphers(true);
JPanel encryptionPrefsPanel = new JPanel(new GridBagLayout());
encryptionPrefsPanel.add(new JHtmlLabel("Password", hyperlinkListener), new GridBagConstraints(0, 0,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
encryptionPrefsPanel.add(encryptPasswordField, new GridBagConstraints(0, 1,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
encryptionPrefsPanel.add(new JHtmlLabel("Algorithm for Encrypting Uploads", hyperlinkListener), new GridBagConstraints(0, 2,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
encryptAlgorithmComboBox = new JComboBox(algorithms);
encryptAlgorithmComboBox.addActionListener(this);
encryptAlgorithmComboBox.setSelectedItem(encryptAlgorithm.toUpperCase());
encryptionPrefsPanel.add(encryptAlgorithmComboBox, new GridBagConstraints(0, 3,
1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
String algorithmExplanation =
"<html>This algorithm need not be set correctly to download<br>" +
"encrypted objects, as Cockpit will detect and apply the<br>" +
"appropriate algorithm.<br><br>" +
"<font size=\"-2\">" +
"The algorithm list only includes the Password-Based (PBE) algorithms<br>" +
"available to Java programs on your system.</font></html>";
encryptionPrefsPanel.add(new JHtmlLabel(algorithmExplanation, hyperlinkListener), new GridBagConstraints(0, 4,
1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
// Padding
encryptionPrefsPanel.add(new JLabel(), new GridBagConstraints(0, 5,
1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0));