Search in sources :

Example 66 with JComboBox

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

the class SensorTableDataModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    if (row >= sysNameList.size()) {
        log.debug("row is greater than name list");
        return "";
    }
    String name = sysNameList.get(row);
    Sensor s = senManager.getBySystemName(name);
    if (s == null) {
        log.debug("error null sensor!");
        return "error";
    }
    if (col == INVERTCOL) {
        boolean val = s.getInverted();
        return Boolean.valueOf(val);
    } else if (col == USEGLOBALDELAY) {
        boolean val = s.useDefaultTimerSettings();
        return Boolean.valueOf(val);
    } else if (col == ACTIVEDELAY) {
        return s.getSensorDebounceGoingActiveTimer();
    } else if (col == INACTIVEDELAY) {
        return s.getSensorDebounceGoingInActiveTimer();
    } else if (col == EDITCOL) {
        return Bundle.getMessage("ButtonEdit");
    } else if (col == PULLUPCOL) {
        JComboBox<Sensor.PullResistance> c = new JComboBox<Sensor.PullResistance>(Sensor.PullResistance.values());
        c.setSelectedItem(s.getPullResistance());
        c.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                comboBoxAction(e);
            }
        });
        return c;
    } else {
        return super.getValueAt(row, col);
    }
}
Also used : JComboBox(javax.swing.JComboBox) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Sensor(jmri.Sensor)

Example 67 with JComboBox

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

the class WarrantRoute method makeTextBoxPanel.

/**
     * Puts label message to the Right
     *
     * @param comp    Component to put into JPanel
     * @param label   Bundle keyword for label message
     * @param tooltip Bundle keyword for tooltip message
     * @return Panel containing Component
     */
protected static JPanel makeTextBoxPanel(JComponent comp, String label, String tooltip) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.add(Box.createHorizontalStrut(STRUT_SIZE));
    comp.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    comp.setMaximumSize(new Dimension(300, comp.getPreferredSize().height));
    comp.setMinimumSize(new Dimension(30, comp.getPreferredSize().height));
    panel.add(comp);
    if (comp instanceof JTextField || comp instanceof JComboBox) {
        comp.setBackground(Color.white);
        JLabel l = new JLabel(Bundle.getMessage(label));
        l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
        l.setToolTipText(Bundle.getMessage(tooltip));
        panel.add(l);
    } else if (comp instanceof AbstractButton) {
        ((AbstractButton) comp).setText(Bundle.getMessage(label));
    }
    panel.add(Box.createHorizontalStrut(STRUT_SIZE));
    if (tooltip != null) {
        panel.setToolTipText(tooltip);
        comp.setToolTipText(Bundle.getMessage(tooltip));
    }
    panel.setMaximumSize(new Dimension(350, comp.getPreferredSize().height));
    panel.setMinimumSize(new Dimension(80, comp.getPreferredSize().height));
    return panel;
}
Also used : JPanel(javax.swing.JPanel) AbstractButton(javax.swing.AbstractButton) JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField)

Example 68 with JComboBox

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

the class AbstractActionModelFactory method editModel.

@Override
public void editModel(StartupModel model, Component parent) {
    if (this.getModelClass().isInstance(model)) {
        JList<String> actions = new JList<>(StartupActionModelUtil.getDefault().getNames());
        JComboBox<String> connections = new JComboBox<>();
        JPanel message = this.getDialogMessage(actions, connections);
        actions.setSelectedValue(model.getName(), true);
        String userName = ConnectionNameFromSystemName.getConnectionName(((AbstractActionModel) model).getSystemPrefix());
        if (userName == null) {
            // make not null to simplify following conditionals
            userName = "";
        }
        if (!userName.isEmpty()) {
            connections.setSelectedItem(userName);
        }
        int result = JOptionPane.showOptionDialog(parent, message, this.getDescription(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
        if (result == JOptionPane.OK_OPTION) {
            String name = actions.getSelectedValue();
            Optional<StartupActionsManager> manager = InstanceManager.getOptionalDefault(StartupActionsManager.class);
            if (!name.equals(model.getName())) {
                model.setName(name);
                manager.ifPresent(sam -> {
                    sam.setRestartRequired();
                });
            }
            if (((userName.isEmpty() && connections.getSelectedItem() != null)) || !userName.equals(connections.getSelectedItem())) {
                ((AbstractActionModel) model).setSystemPrefix(ConnectionNameFromSystemName.getPrefixFromName((String) connections.getSelectedItem()));
                manager.ifPresent(sam -> {
                    sam.setRestartRequired();
                });
            }
        }
    }
}
Also used : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) StartupActionsManager(apps.StartupActionsManager) JList(javax.swing.JList)

Example 69 with JComboBox

use of javax.swing.JComboBox in project n2a by frothga.

the class Lay method cb.

public static JComboBox cb(Object... args) {
    // TODO: Can add special hint for this method so
    // that subsequent strings can be interpreted as
    // elements for the combo box array model.
    HintList hints = new HintList();
    List aModel = new ArrayList();
    ComboBoxModel cModel = null;
    boolean strElems = false;
    for (Object arg : args) {
        if (arg instanceof String) {
            if (((String) arg).equalsIgnoreCase("!strelems")) {
                strElems = true;
            }
            if (strElems) {
                aModel.add(arg);
            } else {
                hints.addHints(parseHints((String) arg));
            }
        } else if (arg != null) {
            if (arg.getClass().isArray()) {
                for (int a = 0; a < Array.getLength(arg); a++) {
                    aModel.add(Array.get(arg, a));
                }
            } else {
                aModel.add(arg);
            }
        }
        if (arg instanceof ComboBoxModel) {
            cModel = (ComboBoxModel) arg;
        }
    }
    JComboBox cbo;
    if (cModel != null)
        cbo = new JComboBox(cModel);
    else
        cbo = new JComboBox(aModel.toArray());
    if (hints.contains("white"))
        cbo.setBackground(Color.white);
    setHints(cbo, hints);
    return cbo;
}
Also used : JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ComboBoxModel(javax.swing.ComboBoxModel)

Example 70 with JComboBox

use of javax.swing.JComboBox in project n2a by frothga.

the class ParameterSpecEditDialog method init.

private void init(ParameterSpecification spec) {
    setIconImage(ImageUtil.getImage("edit.gif").getImage());
    MButton btnChange = new MButton("Ch&ange", ImageUtil.getImage("run.gif"));
    btnChange.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String validationMsg = pnlSpecDef.getValidationMsg();
            if (validationMsg != null) {
                Dialogs.showError(ParameterSpecEditDialog.this, validationMsg);
                return;
            }
            result = CHANGE;
            closeDialog();
        }
    });
    MButton btnCancel = new MButton("&Cancel", ImageUtil.getImage("cancel.gif"));
    btnCancel.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            closeDialog();
        }
    });
    try {
        ParamSpecGlob selected = null;
        List<ParamSpecGlob> specChoices = new ArrayList<ParamSpecGlob>();
        for (Class<? extends ParameterSpecification> clazz : specPanels.keySet()) {
            ParamSpecGlob glob = new ParamSpecGlob(clazz);
            specChoices.add(glob);
            if (clazz.equals(spec.getClass())) {
                selected = glob;
            }
        }
        cboSpecs = new JComboBox(specChoices.toArray());
        cboSpecs.setSelectedItem(selected);
        cboSpecs.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ParamSpecGlob glob = (ParamSpecGlob) cboSpecs.getSelectedItem();
                change(glob.paramSpecClass);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
    Lay.BLtg(this, "N", Lay.FL("L", Lay.lb("Specification Type:", "fg=white"), cboSpecs, "mb=[1b,black],bg=5B8FFF"), "C", pnlContainer = Lay.p("eb=10"), "S", Lay.FL("R", btnChange, btnCancel), "size=[400,300],center");
    setDefaultButton(btnChange);
    origSpec = spec;
    change(spec.getClass());
}
Also used : ActionListener(java.awt.event.ActionListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) MButton(replete.gui.controls.mnemonics.MButton)

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