001package jmri.web.server;
002
003/**
004 * @author Steve Todd Copyright (C) 2011
005 * @author Randall Wood Copyright (C) 2012
006 */
007import javax.swing.BoxLayout;
008import javax.swing.JComponent;
009import javax.swing.JFrame;
010import javax.swing.JLabel;
011import javax.swing.JPanel;
012import javax.swing.JTextField;
013import jmri.InstanceManager;
014import jmri.swing.JTitledSeparator;
015import jmri.swing.PreferencesPanel;
016import org.openide.util.lookup.ServiceProvider;
017
018@ServiceProvider(service = PreferencesPanel.class)
019public class RailroadNamePreferencesPanel extends JPanel implements PreferencesPanel {
020
021    private JTextField railroadName;
022    private WebServerPreferences preferences;
023    public RailroadNamePreferencesPanel() {
024        preferences = InstanceManager.getDefault(WebServerPreferences.class);
025        initGUI();
026        setGUI();
027    }
028
029    public RailroadNamePreferencesPanel(JFrame f) {
030        this();
031    }
032
033    private void initGUI() {
034        this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
035        add(new JTitledSeparator(Bundle.getMessage("TitleRailroadNamePreferences")));
036        add(rrNamePanel());
037    }
038
039    private void setGUI() {
040    }
041
042    private JPanel rrNamePanel() {
043        JPanel panel = new JPanel();
044        railroadName = new JTextField(preferences.getRailroadName());
045        railroadName.setToolTipText(Bundle.getMessage("ToolTipRailRoadName"));
046        railroadName.setColumns(30);
047        panel.add(new JLabel(Bundle.getMessage("LabelRailRoadName")));
048        panel.add(railroadName);
049        return panel;
050    }
051
052    @Override
053    public String getPreferencesItem() {
054        return Bundle.getMessage("RailroadNamePreferencesItem");
055    }
056
057    @Override
058    public String getPreferencesItemText() {
059        return Bundle.getMessage("RailroadNamePreferencesItemTitle");
060    }
061
062    @Override
063    public String getTabbedPreferencesTitle() {
064        return null;
065    }
066
067    @Override
068    public String getLabelKey() {
069        return null;
070    }
071
072    @Override
073    public JComponent getPreferencesComponent() {
074        return this;
075    }
076
077    @Override
078    public boolean isPersistant() {
079        return false;
080    }
081
082    @Override
083    public String getPreferencesTooltip() {
084        return null;
085    }
086
087    @Override
088    public void savePreferences() {
089        this.preferences.setRailroadName(railroadName.getText());
090        this.preferences.save();
091    }
092
093    @Override
094    public boolean isDirty() {
095        return this.preferences.isDirty();
096    }
097
098    @Override
099    public boolean isRestartRequired() {
100        return false;
101    }
102
103    @Override
104    public boolean isPreferencesValid() {
105        return true; // no validity checking performed
106    }
107}