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);
}
}
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;
}
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();
});
}
}
}
}
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;
}
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());
}
Aggregations