Search in sources :

Example 1 with PerformActionModel

use of apps.PerformActionModel in project JMRI by JMRI.

the class PerformActionModelXml method load.

@Override
public boolean load(Element shared, Element perNode) throws Exception {
    boolean result = true;
    String className = shared.getAttribute("name").getValue();
    PerformActionModel model = new PerformActionModel();
    Exception exception = null;
    model.setClassName(className);
    for (Element child : shared.getChildren("property")) {
        // NOI18N
        if (// NOI18N
        child.getAttributeValue("name").equals("systemPrefix") && child.getAttributeValue("value") != null) {
            // NOI18N
            // NOI18N
            model.setSystemPrefix(child.getAttributeValue("value"));
        }
    }
    InstanceManager.getDefault(StartupActionsManager.class).addAction(model);
    if (exception != null) {
        throw exception;
    }
    return result;
}
Also used : PerformActionModel(apps.PerformActionModel) Element(org.jdom2.Element) StartupActionsManager(apps.StartupActionsManager)

Example 2 with PerformActionModel

use of apps.PerformActionModel 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();
}
Also used : AutoBinding(org.jdesktop.beansbinding.AutoBinding) Binding(org.jdesktop.beansbinding.Binding) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) BeanProperty(org.jdesktop.beansbinding.BeanProperty) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Bindings(org.jdesktop.beansbinding.Bindings) ItemListener(java.awt.event.ItemListener) StartupActionsManager(apps.StartupActionsManager) AutoBinding(org.jdesktop.beansbinding.AutoBinding) LayoutStyle(javax.swing.LayoutStyle) PerformActionModel(apps.PerformActionModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) ELProperty(org.jdesktop.beansbinding.ELProperty) Binding(org.jdesktop.beansbinding.Binding) JPanel(javax.swing.JPanel) PreferencesPanel(jmri.swing.PreferencesPanel) ItemEvent(java.awt.event.ItemEvent) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager) JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) GroupLayout(javax.swing.GroupLayout) JSpinner(javax.swing.JSpinner)

Example 3 with PerformActionModel

use of apps.PerformActionModel in project JMRI by JMRI.

the class PerformActionModelXml method store.

/**
     * Default implementation for storing the model contents
     *
     * @param o Object to store, of type PerformActonModel
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element element = new Element("perform");
    PerformActionModel g = (PerformActionModel) o;
    element.setAttribute("name", g.getClassName());
    element.setAttribute("type", "Action");
    element.setAttribute("class", this.getClass().getName());
    // NOI18N
    Element property = new Element("property");
    // NOI18N
    property.setAttribute("name", "systemPrefix");
    property.setAttribute("value", g.getSystemPrefix());
    element.addContent(property);
    return element;
}
Also used : PerformActionModel(apps.PerformActionModel) Element(org.jdom2.Element)

Example 4 with PerformActionModel

use of apps.PerformActionModel 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();
}
Also used : AutoBinding(org.jdesktop.beansbinding.AutoBinding) Binding(org.jdesktop.beansbinding.Binding) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) BeanProperty(org.jdesktop.beansbinding.BeanProperty) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Bindings(org.jdesktop.beansbinding.Bindings) ItemListener(java.awt.event.ItemListener) StartupActionsManager(apps.StartupActionsManager) ActionEvent(java.awt.event.ActionEvent) AutoBinding(org.jdesktop.beansbinding.AutoBinding) LayoutStyle(javax.swing.LayoutStyle) PerformActionModel(apps.PerformActionModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) ELProperty(org.jdesktop.beansbinding.ELProperty) Binding(org.jdesktop.beansbinding.Binding) JPanel(javax.swing.JPanel) PreferencesPanel(jmri.swing.PreferencesPanel) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager) JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) GroupLayout(javax.swing.GroupLayout) JSpinner(javax.swing.JSpinner)

Example 5 with PerformActionModel

use of apps.PerformActionModel 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;
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) JCheckBox(javax.swing.JCheckBox) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) ButtonGroup(javax.swing.ButtonGroup) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JTitledSeparator(jmri.swing.JTitledSeparator) ItemListener(java.awt.event.ItemListener) JOptionPane(javax.swing.JOptionPane) StartupActionsManager(apps.StartupActionsManager) File(java.io.File) JRadioButton(javax.swing.JRadioButton) ResourceBundle(java.util.ResourceBundle) FileUtil(jmri.util.FileUtil) PerformActionModel(apps.PerformActionModel) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) JFrame(javax.swing.JFrame) PropertyChangeEvent(java.beans.PropertyChangeEvent) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) PreferencesPanel(jmri.swing.PreferencesPanel) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) JSpinner(javax.swing.JSpinner) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager)

Aggregations

PerformActionModel (apps.PerformActionModel)5 StartupActionsManager (apps.StartupActionsManager)4 ItemEvent (java.awt.event.ItemEvent)3 ItemListener (java.awt.event.ItemListener)3 Arrays (java.util.Arrays)3 JCheckBox (javax.swing.JCheckBox)3 JComponent (javax.swing.JComponent)3 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 JSpinner (javax.swing.JSpinner)3 SpinnerNumberModel (javax.swing.SpinnerNumberModel)3 InstanceManager (jmri.InstanceManager)3 PreferencesPanel (jmri.swing.PreferencesPanel)3 GroupLayout (javax.swing.GroupLayout)2 LayoutStyle (javax.swing.LayoutStyle)2 AutoBinding (org.jdesktop.beansbinding.AutoBinding)2 BeanProperty (org.jdesktop.beansbinding.BeanProperty)2 Binding (org.jdesktop.beansbinding.Binding)2 BindingGroup (org.jdesktop.beansbinding.BindingGroup)2 Bindings (org.jdesktop.beansbinding.Bindings)2