001package jmri.jmrit.consisttool;
002
003import jmri.InstanceManager;
004import jmri.swing.PreferencesPanel;
005import java.awt.event.ActionEvent;
006import javax.swing.BoxLayout;
007import javax.swing.JPanel;
008import javax.swing.JComponent;
009import javax.swing.JCheckBox;
010import org.openide.util.lookup.ServiceProvider;
011
012/**
013 * @author Paul Bender Copyright (C) 2019
014 */
015@ServiceProvider(service = PreferencesPanel.class)
016public class ConsistToolPrefsPanel extends JPanel implements PreferencesPanel {
017        
018    private JCheckBox writeCVOptionCheckBox;
019    private boolean dirty = false;
020
021    public ConsistToolPrefsPanel() {
022        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
023        JPanel p = new JPanel();
024        p.setLayout(new java.awt.FlowLayout());
025        writeCVOptionCheckBox = new JCheckBox(Bundle.getMessage("WriteCVToRosterOption"));
026        writeCVOptionCheckBox.addActionListener((ActionEvent e) -> {
027            ConsistPreferencesManager cpm = InstanceManager.getDefault(ConsistPreferencesManager.class);
028            if(cpm.isUpdateCV19() != writeCVOptionCheckBox.isSelected()) {
029               dirty = true;
030               cpm.setUpdateCV19(writeCVOptionCheckBox.isSelected());
031            }
032        });
033        writeCVOptionCheckBox.setSelected(InstanceManager.getDefault(ConsistPreferencesManager.class).isUpdateCV19());
034
035        p.add(writeCVOptionCheckBox);
036        writeCVOptionCheckBox.setToolTipText(Bundle.getMessage("WriteCVToRosterToolTip"));
037        add(p);
038    }
039
040    /**
041     * {@inheritDoc}
042     */
043    @Override
044    public String getPreferencesItem() {
045        return "CONSISTTOOL"; // NOI18N
046    }
047
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public String getPreferencesItemText() {
053        return Bundle.getMessage("ConsistToolTitle");
054    }
055
056    /**
057     * {@inheritDoc}
058     */
059    @Override
060    public String getTabbedPreferencesTitle() {
061        return getPreferencesItemText();
062    }
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public String getLabelKey() {
069        return null;
070    }
071
072    /**
073     * {@inheritDoc}
074     */
075    @Override
076    public JComponent getPreferencesComponent() {
077        return this;
078    }
079
080    /**
081     * {@inheritDoc}
082     */
083    @Override
084    public boolean isPersistant() {
085        return false;
086    }
087
088    /**
089     * {@inheritDoc}
090     */
091    @Override
092    public String getPreferencesTooltip() {
093        return null;
094    }
095
096    /**
097     * {@inheritDoc}
098     */
099    @Override
100    public void savePreferences() {
101       // saved through preferences, so just reset dirty
102       dirty = false;
103    }
104
105    /**
106     * {@inheritDoc}
107     */
108    @Override
109    public boolean isDirty() {
110        return dirty;
111    }
112
113    /**
114     * {@inheritDoc}
115     */
116    @Override
117    public boolean isRestartRequired() {
118        return false;
119    }
120
121    /**
122     * {@inheritDoc}
123     */
124    @Override
125    public boolean isPreferencesValid() {
126        return true; // no validity checking performed
127    }
128
129
130}