public CalculateChecksumDialog(MainFrame mainFrame, FileSet files) {
super(mainFrame, ActionProperties.getActionLabel(CalculateChecksumAction.Descriptor.ACTION_ID), files);
YBoxPanel mainPanel = new YBoxPanel();
// Retrieve all MessageDigest instances and sort them by alphabetical order of their algorithm
// Create a TreeSet with a custom Comparator
SortedSet<MessageDigest> algorithmSortedSet = new TreeSet<MessageDigest>(new Comparator<MessageDigest>() {
public int compare(MessageDigest md1, MessageDigest md2) {
return md1.getAlgorithm().compareTo(md2.getAlgorithm());
}
});
// Add all MessageDigest to the TreeSet
for(String algo : Security.getAlgorithms("MessageDigest")) {
try {
algorithmSortedSet.add(MessageDigest.getInstance(algo));
}
catch(NoSuchAlgorithmException e) {
// Should never happen and if it ever does, the digest will simply be discarded
}
}
// Convert the sorted set into an array
messageDigests = new MessageDigest[algorithmSortedSet.size()];
algorithmSortedSet.toArray(messageDigests);
// Add the sorted list of algorithms to a combo box to let the user choose one
algorithmComboBox = new JComboBox();
for (MessageDigest messageDigest : messageDigests)
algorithmComboBox.addItem(messageDigest.getAlgorithm());
// Select the last used algorithm (if any), or the default algorithm
algorithmComboBox.setSelectedItem(lastUsedAlgorithm);
algorithmComboBox.addItemListener(this);
FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, 0, 0);
JPanel tempPanel = new JPanel(flowLayout);
tempPanel.add(new JLabel(Translator.get("calculate_checksum_dialog.checksum_algorithm")+" : "));
tempPanel.add(algorithmComboBox);
mainPanel.add(tempPanel);
mainPanel.addSpace(10);
// Create the components that allow to choose where the checksum file should be created
mainPanel.add(new JLabel(Translator.get("destination")+" :"));
mainPanel.addSpace(5);
JRadioButton tempLocationRadioButton = new JRadioButton(Translator.get("calculate_checksum_dialog.temporary_file"), true);
mainPanel.add(tempLocationRadioButton);
specificLocationRadioButton = new JRadioButton("", false);
tempPanel = new JPanel(new BorderLayout());
tempPanel.add(specificLocationRadioButton, BorderLayout.WEST);
specificLocationRadioButton.addItemListener(this);
// Create a path field with auto-completion capabilities
specificLocationTextField = new FilePathField(getChecksumFilename(lastUsedAlgorithm));
specificLocationTextField.setEnabled(false);
tempPanel.add(specificLocationTextField, BorderLayout.CENTER);
JPanel tempPanel2 = new JPanel(new BorderLayout());
tempPanel2.add(tempPanel, BorderLayout.NORTH);
mainPanel.add(tempPanel2);
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(tempLocationRadioButton);
buttonGroup.add(specificLocationRadioButton);
// Create file details button and OK/cancel buttons and lay them out a single row
JPanel fileDetailsPanel = createFileDetailsPanel();
okButton = new JButton(Translator.get("ok"));
JButton cancelButton = new JButton(Translator.get("cancel"));
mainPanel.add(createButtonsPanel(createFileDetailsButton(fileDetailsPanel),
DialogToolkit.createOKCancelPanel(okButton, cancelButton, getRootPane(), this)));
mainPanel.add(fileDetailsPanel);
// mainPanel.add(new HelpButtonPanel(new HelpButton(mainFrame, "CalculateChecksum")));
getContentPane().add(mainPanel);