use of apps.StartupActionsManager 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 apps.StartupActionsManager in project JMRI by JMRI.
the class LnTcpPreferencesPanel method initComponents.
private void initComponents() {
bindingGroup = new BindingGroup();
port = new JSpinner();
portLabel = new JLabel();
startup = new JCheckBox();
port.setModel(new SpinnerNumberModel(1234, 1, 65535, 1));
port.setEditor(new JSpinner.NumberEditor(port, "#"));
// NOI18N
port.setToolTipText(Bundle.getMessage("ToolTipPort"));
Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${port}"), port, BeanProperty.create("value"));
bindingGroup.addBinding(binding);
// NOI18N
portLabel.setText(Bundle.getMessage("LabelPort"));
// NOI18N
portLabel.setToolTipText(Bundle.getMessage("ToolTipPort"));
startup.setSelected(this.isStartupAction());
// NOI18N
startup.setText(Bundle.getMessage("LabelStartup"));
this.startupItemListener = (ItemEvent e) -> {
this.startup.removeItemListener(this.startupItemListener);
StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
if (this.startup.isSelected()) {
PerformActionModel model = new PerformActionModel();
model.setClassName(LnTcpServerAction.class.getName());
if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
manager.addAction(model);
} else {
manager.setActions(this.startupActionPosition, model);
}
} else {
manager.getActions(PerformActionModel.class).stream().filter((model) -> (LnTcpServerAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
manager.removeAction(model);
});
}
this.startup.addItemListener(this.startupItemListener);
};
this.startup.addItemListener(this.startupItemListener);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(port, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(startup, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(port, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(portLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startup).addContainerGap(198, Short.MAX_VALUE)));
bindingGroup.bind();
}
use of apps.StartupActionsManager in project JMRI by JMRI.
the class WebServerPreferencesPanel method initComponents.
private void initComponents() {
bindingGroup = new BindingGroup();
port = new JSpinner();
portLabel = new JLabel();
readonlyPower = new JCheckBox();
startup = new JCheckBox();
port.setModel(new SpinnerNumberModel(12080, 1, 65535, 1));
port.setEditor(new JSpinner.NumberEditor(port, "#"));
// NOI18N
port.setToolTipText(Bundle.getMessage("ToolTipPort"));
Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${port}"), port, BeanProperty.create("value"));
bindingGroup.addBinding(binding);
// NOI18N
portLabel.setText(Bundle.getMessage("LabelPort"));
// NOI18N
portLabel.setToolTipText(Bundle.getMessage("ToolTipPort"));
// NOI18N
readonlyPower.setText(Bundle.getMessage("LabelReadonlyPower"));
readonlyPower.addActionListener((ActionEvent e) -> {
readonlyPower.setToolTipText(Bundle.getMessage(readonlyPower.isSelected() ? "ToolTipReadonlyPowerTrue" : "ToolTipReadonlyPowerFalse"));
});
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${readonlyPower}"), readonlyPower, BeanProperty.create("selected"));
bindingGroup.addBinding(binding);
startup.setSelected(this.isStartupAction());
// NOI18N
startup.setText(Bundle.getMessage("LabelStartup"));
this.startupItemListener = (ItemEvent e) -> {
this.startup.removeItemListener(this.startupItemListener);
StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
if (this.startup.isSelected()) {
PerformActionModel model = new PerformActionModel();
model.setClassName(WebServerAction.class.getName());
if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
manager.addAction(model);
} else {
manager.setActions(this.startupActionPosition, model);
}
} else {
manager.getActions(PerformActionModel.class).stream().filter((model) -> (WebServerAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
manager.removeAction(model);
});
}
this.startup.addItemListener(this.startupItemListener);
};
this.startup.addItemListener(this.startupItemListener);
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(port, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(startup, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE).addComponent(readonlyPower, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(port, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(portLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(readonlyPower).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startup).addContainerGap(198, Short.MAX_VALUE)));
bindingGroup.bind();
}
use of apps.StartupActionsManager in project JMRI by JMRI.
the class WiThrottlePrefsPanel method socketPortPanel.
private JPanel socketPortPanel() {
JPanel SPPanel = new JPanel();
port = new JSpinner(new SpinnerNumberModel(localPrefs.getPort(), 1, 65535, 1));
port.setToolTipText(Bundle.getMessage("PortToolTip"));
port.setEditor(new JSpinner.NumberEditor(port, "#"));
JLabel label = new JLabel(Bundle.getMessage("PortLabel"));
label.setToolTipText(port.getToolTipText());
SPPanel.add(port);
SPPanel.add(label);
startupCB = new JCheckBox(Bundle.getMessage("LabelStartup"), isStartUpAction());
startupItemListener = (ItemEvent e) -> {
this.startupCB.removeItemListener(this.startupItemListener);
StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
if (this.startupCB.isSelected()) {
PerformActionModel model = new PerformActionModel();
model.setClassName(WiThrottleCreationAction.class.getName());
if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
manager.addAction(model);
} else {
manager.setActions(this.startupActionPosition, model);
}
} else {
manager.getActions(PerformActionModel.class).stream().filter((model) -> (WiThrottleCreationAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
manager.removeAction(model);
});
}
this.startupCB.addItemListener(this.startupItemListener);
};
this.startupCB.addItemListener(this.startupItemListener);
SPPanel.add(startupCB);
return SPPanel;
}
Aggregations