use of com.mucommander.commons.util.ui.layout.YBoxPanel in project mucommander by mucommander.
the class PreferredEncodingsDialog method init.
protected void init() {
// Mac OS X: small window borders
if (OsFamily.MAC_OS.isCurrent())
getRootPane().putClientProperty("Window.style", "small");
Container contentPane = getContentPane();
// Label
JLabel label = new JLabel(Translator.get("preferred_encodings") + ":");
// Mac OS X: small component size
if (OsFamily.MAC_OS.isCurrent())
label.putClientProperty("JComponent.sizeVariant", "small");
contentPane.add(label, BorderLayout.NORTH);
// Checkboxes
YBoxPanel yPanel = new YBoxPanel();
checkboxes = new Vector<JCheckBox>();
JCheckBox checkbox;
for (String enc : Charset.availableCharsets().keySet()) {
checkbox = new JCheckBox(enc);
// Mac OS X: component size
if (OsFamily.MAC_OS.isCurrent())
checkbox.putClientProperty("JComponent.sizeVariant", "small");
checkboxes.add(checkbox);
yPanel.add(checkbox);
}
selectCheckboxes(EncodingPreferences.getPreferredEncodings());
JScrollPane scrollPane = new JScrollPane(yPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
contentPane.add(scrollPane, BorderLayout.CENTER);
// 'Revert to defaults' button
JButton defaultsButton = new JButton(Translator.get("reset"));
// Mac OS X: component size
if (OsFamily.MAC_OS.isCurrent())
defaultsButton.putClientProperty("JComponent.sizeVariant", "small");
defaultsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
selectCheckboxes(EncodingPreferences.getDefaultPreferredEncodings());
}
});
JPanel flowPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
flowPanel.add(defaultsButton);
contentPane.add(flowPanel, BorderLayout.SOUTH);
setMinimumSize(MINIMUM_DIALOG_DIMENSION);
setMaximumSize(MAXIMUM_DIALOG_DIMENSION);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JCheckBox checkbox;
int nbCheckboxes = checkboxes.size();
java.util.List<String> preferredEncodings = new Vector<String>();
for (int i = 0; i < nbCheckboxes; i++) {
checkbox = checkboxes.get(i);
if (checkbox.isSelected())
preferredEncodings.add(checkbox.getText());
}
EncodingPreferences.setPreferredEncodings(preferredEncodings);
}
});
}
Aggregations