<commit_before>package org.helioviewer.jhv.gui.dialogs;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.helioviewer.jhv.Settings;
import org.helioviewer.jhv.gui.JHVFrame;
import org.helioviewer.jhv.gui.interfaces.ShowableDialog;
import org.helioviewer.jhv.io.DataSources;
import org.helioviewer.jhv.view.j2k.io.jpip.JPIPCacheManager;

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.dialog.StandardDialog;

@SuppressWarnings("serial")
public class PreferencesDialog extends StandardDialog implements ShowableDialog {

    private final JLabel labelCache = new JLabel("The image cache currently uses 0.0GB on disk.", JLabel.RIGHT);

    private void setLabelCache() {
        labelCache.setText(String.format("The image cache currently uses %.1fGB on disk.", JPIPCacheManager.getSize() / (1024 * 1024 * 1024.)));
    }

    private JCheckBox defaultMovie;
    private JCheckBox sampHub;
    private JCheckBox normalizeRadius;
    private JCheckBox normalizeAIA;
    private DefaultsSelectionPanel defaultsPanel;

    public PreferencesDialog() {
        super(JHVFrame.getFrame(), "Preferences", true);
        setResizable(false);
    }

    @Override
    public ButtonPanel createButtonPanel() {
        AbstractAction close = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        };
        setDefaultCancelAction(close);

        JButton cancelBtn = new JButton(close);
        cancelBtn.setText("Cancel");

        AbstractAction save = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveSettings();
                setVisible(false);
            }
        };
        setDefaultAction(save);

        JButton okBtn = new JButton(save);
        okBtn.setText("Save");
        setInitFocusedComponent(okBtn);

        ButtonPanel panel = new ButtonPanel();
        panel.add(okBtn, ButtonPanel.AFFIRMATIVE_BUTTON);
        panel.add(cancelBtn, ButtonPanel.CANCEL_BUTTON);

        return panel;
    }

    @Override
    public JComponent createContentPanel() {
        defaultsPanel = new DefaultsSelectionPanel();
        defaultsPanel.setBorder(BorderFactory.createEmptyBorder(3, 9, 3, 9));
        return defaultsPanel;
    }

    @Override
    public JComponent createBannerPanel() {
        JPanel panel = createParametersPanel();
        panel.setBorder(BorderFactory.createEmptyBorder(3, 9, 3, 9));
        return panel;
    }

    @Override
    public void showDialog() {
        setLabelCache();
        pack();
        setLocationRelativeTo(JHVFrame.getFrame());
        setVisible(true);
    }

    private void saveSettings() {
        Settings.setProperty("startup.loadmovie", Boolean.toString(defaultMovie.isSelected()));
        Settings.setProperty("startup.sampHub", Boolean.toString(sampHub.isSelected()));
        Settings.setProperty("display.normalize", Boolean.toString(normalizeRadius.isSelected()));
        Settings.setProperty("display.normalizeAIA", Boolean.toString(normalizeAIA.isSelected()));
        defaultsPanel.setSettings();
    }

    private JPanel createParametersPanel() {
        JPanel row1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        row1.add(new JLabel("Preferred server", JLabel.RIGHT));

        JComboBox<String> combo = new JComboBox<>(DataSources.getServers().toArray(new String[0]));
        combo.setSelectedItem(Settings.getProperty("default.server"));
        combo.addActionListener(e -> Settings.setProperty("default.server", (String) Objects.requireNonNull(combo.getSelectedItem())));
        row1.add(combo);

        JPanel row2 = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.anchor = GridBagConstraints.BASELINE_LEADING;

        c.gridx = 0;
        c.gridy = 0;
        row2.add(new JLabel("At startup", JLabel.RIGHT), c);

        c.gridx = 1;
        defaultMovie = new JCheckBox("Load default movie", Boolean.parseBoolean(Settings.getProperty("startup.loadmovie")));
        row2.add(defaultMovie, c);

        c.gridx = 2;
        sampHub = new JCheckBox("Load SAMP hub", Boolean.parseBoolean(Settings.getProperty("startup.sampHub")));
        row2.add(sampHub, c);

        c.gridx = 0;
        c.gridy = 1;
        row2.add(new JLabel("Normalize", JLabel.RIGHT), c);

        c.gridx = 1;
        normalizeRadius = new JCheckBox("Solar radius (needs restart)", Boolean.parseBoolean(Settings.getProperty("display.normalize")));
        row2.add(normalizeRadius, c);

        c.gridx = 2;
        normalizeAIA = new JCheckBox("SDO/AIA brightness (needs restart)", Boolean.parseBoolean(Settings.getProperty("display.normalizeAIA")));
        row2.add(normalizeAIA, c);<commit_msg>More alignment<commit_after>package org.helioviewer.jhv.gui.dialogs;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Objects;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.helioviewer.jhv.Settings;
import org.helioviewer.jhv.gui.JHVFrame;
import org.helioviewer.jhv.gui.interfaces.ShowableDialog;
import org.helioviewer.jhv.io.DataSources;
import org.helioviewer.jhv.view.j2k.io.jpip.JPIPCacheManager;

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.dialog.StandardDialog;

@SuppressWarnings("serial")
public class PreferencesDialog extends StandardDialog implements ShowableDialog {

    private final JLabel labelCache = new JLabel("The image cache currently uses 0.0GB on disk.", JLabel.RIGHT);

    private void setLabelCache() {
        labelCache.setText(String.format("The image cache currently uses %.1fGB on disk.", JPIPCacheManager.getSize() / (1024 * 1024 * 1024.)));
    }

    private JCheckBox defaultMovie;
    private JCheckBox sampHub;
    private JCheckBox normalizeRadius;
    private JCheckBox normalizeAIA;
    private DefaultsSelectionPanel defaultsPanel;

    public PreferencesDialog() {
        super(JHVFrame.getFrame(), "Preferences", true);
        setResizable(false);
    }

    @Override
    public ButtonPanel createButtonPanel() {
        AbstractAction close = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        };
        setDefaultCancelAction(close);

        JButton cancelBtn = new JButton(close);
        cancelBtn.setText("Cancel");

        AbstractAction save = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveSettings();
                setVisible(false);
            }
        };
        setDefaultAction(save);

        JButton okBtn = new JButton(save);
        okBtn.setText("Save");
        setInitFocusedComponent(okBtn);

        ButtonPanel panel = new ButtonPanel();
        panel.add(okBtn, ButtonPanel.AFFIRMATIVE_BUTTON);
        panel.add(cancelBtn, ButtonPanel.CANCEL_BUTTON);

        return panel;
    }

    @Override
    public JComponent createContentPanel() {
        defaultsPanel = new DefaultsSelectionPanel();
        defaultsPanel.setBorder(BorderFactory.createEmptyBorder(3, 9, 3, 9));
        return defaultsPanel;
    }

    @Override
    public JComponent createBannerPanel() {
        JPanel panel = createParametersPanel();
        panel.setBorder(BorderFactory.createEmptyBorder(3, 9, 3, 9));
        return panel;
    }

    @Override
    public void showDialog() {
        setLabelCache();
        pack();
        setLocationRelativeTo(JHVFrame.getFrame());
        setVisible(true);
    }

    private void saveSettings() {
        Settings.setProperty("startup.loadmovie", Boolean.toString(defaultMovie.isSelected()));
        Settings.setProperty("startup.sampHub", Boolean.toString(sampHub.isSelected()));
        Settings.setProperty("display.normalize", Boolean.toString(normalizeRadius.isSelected()));
        Settings.setProperty("display.normalizeAIA", Boolean.toString(normalizeAIA.isSelected()));
        defaultsPanel.setSettings();
    }

    private JPanel createParametersPanel() {
        JPanel row1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
        row1.add(new JLabel("Preferred server", JLabel.RIGHT));

        JComboBox<String> combo = new JComboBox<>(DataSources.getServers().toArray(new String[0]));
        combo.setSelectedItem(Settings.getProperty("default.server"));
        combo.addActionListener(e -> Settings.setProperty("default.server", (String) Objects.requireNonNull(combo.getSelectedItem())));
        row1.add(combo);

        JPanel row2 = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();

        c.anchor = GridBagConstraints.BASELINE_TRAILING;
        c.gridx = 0;
        c.gridy = 0;
        row2.add(new JLabel("At startup", JLabel.RIGHT), c);

        c.anchor = GridBagConstraints.BASELINE_LEADING;
        c.gridx = 1;
        defaultMovie = new JCheckBox("Load default movie", Boolean.parseBoolean(Settings.getProperty("startup.loadmovie")));
        row2.add(defaultMovie, c);

        c.gridx = 2;
        sampHub = new JCheckBox("Load SAMP hub", Boolean.parseBoolean(Settings.getProperty("startup.sampHub")));
        row2.add(sampHub, c);

        c.anchor = GridBagConstraints.BASELINE_TRAILING;
        c.gridx = 0;
        c.gridy = 1;
        row2.add(new JLabel("Normalize (after restart)", JLabel.RIGHT), c);

        c.anchor = GridBagConstraints.BASELINE_LEADING;
        c.gridx = 1;
        normalizeRadius = new JCheckBox("Solar radius", Boolean.parseBoolean(Settings.getProperty("display.normalize")));
        row2.add(normalizeRadius, c);

        c.gridx = 2;
        normalizeAIA = new JCheckBox("SDO/AIA brightness", Boolean.parseBoolean(Settings.getProperty("display.normalizeAIA")));
        row2.add(normalizeAIA, c);
{'fraction_non_alphanumeric': 0.10903453621565756, 'fraction_numerical': 0.007751270347084661, 'mean_word_length': 3.4610065309258546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789442', 'n_tokens_mistral': 3446, 'n_tokens_neox': 3324, 'n_words': 642}