Search in sources :

Example 46 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class AbstractNetworkConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        //Build up list of options
        //Hashtable<String, AbstractPortController.Option> adapterOptions = ((AbstractPortController)adapter).getOptionList();
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (hostNameField.getActionListeners().length > 0) {
        hostNameField.removeActionListener(hostNameField.getActionListeners()[0]);
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
        NUMOPTIONS = NUMOPTIONS + 2;
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    hostNameField.setText(adapter.getHostName());
    hostNameFieldLabel = new JLabel(rb.getString("HostFieldLabel"));
    hostNameField.setToolTipText(rb.getString("HostFieldToolTip"));
    if (adapter.getHostName() == null || adapter.getHostName().equals("")) {
        hostNameField.setText(p.getComboBoxLastSelection(adapter.getClass().getName() + ".hostname"));
        adapter.setHostName(hostNameField.getText());
    }
    portField.setToolTipText(rb.getString("PortFieldToolTip"));
    portField.setEnabled(true);
    portField.setText("" + adapter.getPort());
    portFieldLabel = new JLabel(rb.getString("PortFieldLabel"));
    adNameField.setToolTipText(rb.getString("AdNameFieldToolTip"));
    adNameField.setEnabled(false);
    adNameField.setText("" + adapter.getAdvertisementName());
    adNameFieldLabel = new JLabel(rb.getString("AdNameFieldLabel"));
    adNameFieldLabel.setEnabled(false);
    serviceTypeField.setToolTipText(rb.getString("ServiceTypeFieldToolTip"));
    serviceTypeField.setEnabled(false);
    serviceTypeField.setText("" + adapter.getServiceType());
    serviceTypeFieldLabel = new JLabel(rb.getString("ServiceTypeFieldLabel"));
    serviceTypeFieldLabel.setEnabled(false);
    showAutoConfig.setFont(showAutoConfig.getFont().deriveFont(9f));
    showAutoConfig.setForeground(Color.blue);
    showAutoConfig.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setAutoNetworkConfig();
        }
    });
    showAutoConfig.setSelected(adapter.getMdnsConfigure());
    setAutoNetworkConfig();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) ItemListener(java.awt.event.ItemListener)

Example 47 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class AbstractSimulatorConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) ItemListener(java.awt.event.ItemListener)

Example 48 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class AbstractStreamConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) ItemListener(java.awt.event.ItemListener)

Example 49 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class AbstractStreamConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }
        });
        systemPrefixField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setSystemPrefix(systemPrefixField.getText())) {
                    JOptionPane.showMessageDialog(null, "System Prefix " + systemPrefixField.getText() + " is already assigned");
                    systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
        connectionNameField.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }
        });
        connectionNameField.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent e) {
                if (!adapter.getSystemConnectionMemo().setUserName(connectionNameField.getText())) {
                    JOptionPane.showMessageDialog(null, "Connection Name " + connectionNameField.getText() + " is already assigned");
                    connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
                }
            }

            @Override
            public void focusGained(FocusEvent e) {
            }
        });
        for (String i : options.keySet()) {
            final String item = i;
            if (options.get(i).getComponent() instanceof JComboBox) {
                ((JComboBox<?>) options.get(i).getComponent()).addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        adapter.setOptionState(item, options.get(item).getItem());
                    }
                });
            }
        }
    }
    init = true;
}
Also used : ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent)

Example 50 with JComboBox

use of javax.swing.JComboBox in project JMRI by JMRI.

the class ConnectionConfig method checkInitDone.

@SuppressWarnings("unchecked")
@Override
protected void checkInitDone() {
    if (log.isDebugEnabled()) {
        log.debug("init called for " + name());
    }
    if (init) {
        return;
    }
    super.checkInitDone();
    updateUserNameField();
    ((JComboBox<Option>) options.get("Protocol").getComponent()).addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateUserNameField();
        }
    });
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Aggregations

JComboBox (javax.swing.JComboBox)226 JLabel (javax.swing.JLabel)97 JPanel (javax.swing.JPanel)88 ActionEvent (java.awt.event.ActionEvent)69 ActionListener (java.awt.event.ActionListener)66 JButton (javax.swing.JButton)55 GridBagLayout (java.awt.GridBagLayout)42 GridBagConstraints (java.awt.GridBagConstraints)41 Insets (java.awt.Insets)40 Dimension (java.awt.Dimension)39 JScrollPane (javax.swing.JScrollPane)37 JTextField (javax.swing.JTextField)36 BoxLayout (javax.swing.BoxLayout)34 JCheckBox (javax.swing.JCheckBox)33 DefaultCellEditor (javax.swing.DefaultCellEditor)27 JTable (javax.swing.JTable)26 BorderLayout (java.awt.BorderLayout)25 Component (java.awt.Component)25 TableColumn (javax.swing.table.TableColumn)23 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)22