Search in sources :

Example 26 with YBoxPanel

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);
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) JCheckBox(javax.swing.JCheckBox) Container(java.awt.Container) YBoxPanel(com.mucommander.commons.util.ui.layout.YBoxPanel) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent)

Aggregations

YBoxPanel (com.mucommander.commons.util.ui.layout.YBoxPanel)26 JPanel (javax.swing.JPanel)11 JButton (javax.swing.JButton)8 JLabel (javax.swing.JLabel)7 FlowLayout (java.awt.FlowLayout)6 ButtonChoicePanel (com.mucommander.commons.util.ui.button.ButtonChoicePanel)4 ProportionalGridPanel (com.mucommander.commons.util.ui.layout.ProportionalGridPanel)4 FontChooser (com.mucommander.ui.chooser.FontChooser)4 BorderLayout (java.awt.BorderLayout)4 ActionEvent (java.awt.event.ActionEvent)3 JCheckBox (javax.swing.JCheckBox)3 JScrollPane (javax.swing.JScrollPane)3 XAlignedComponentPanel (com.mucommander.commons.util.ui.layout.XAlignedComponentPanel)2 CollapseExpandButton (com.mucommander.ui.button.CollapseExpandButton)2 SpinningDial (com.mucommander.ui.icon.SpinningDial)2 InformationPane (com.mucommander.ui.layout.InformationPane)2 Container (java.awt.Container)2 Dimension (java.awt.Dimension)2 ActionListener (java.awt.event.ActionListener)2 WindowAdapter (java.awt.event.WindowAdapter)2