001package jmri.jmrit.logixng.actions.swing; 002 003import java.util.List; 004 005import javax.annotation.CheckForNull; 006import javax.annotation.Nonnull; 007import javax.swing.*; 008 009import jmri.InstanceManager; 010import jmri.jmrit.logixng.Base; 011import jmri.jmrit.logixng.DigitalActionManager; 012import jmri.jmrit.logixng.MaleSocket; 013import jmri.jmrit.logixng.actions.Sequence; 014 015/** 016 * Configures an ActionTurnout object with a Swing JPanel. 017 * 018 * @author Daniel Bergqvist Copyright 2021 019 */ 020public class SequenceSwing extends AbstractDigitalActionSwing { 021 022 private JCheckBox _startImmediately; 023 private JCheckBox _runContinuously; 024 025 @Override 026 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 027 if ((object != null) && !(object instanceof Sequence)) { 028 throw new IllegalArgumentException("object must be an Sequence but is a: "+object.getClass().getName()); 029 } 030 031 Sequence action = (Sequence)object; 032 033 panel = new JPanel(); 034 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 035 _startImmediately = new JCheckBox(Bundle.getMessage("SequenceSwing_StartImmediately")); 036 _runContinuously = new JCheckBox(Bundle.getMessage("SequenceSwing_RunContinuously")); 037 if (action != null) { 038 _startImmediately.setSelected(action.getStartImmediately()); 039 _runContinuously.setSelected(action.getRunContinuously()); 040 } 041 panel.add(_startImmediately); 042 panel.add(_runContinuously); 043 } 044 045 /** {@inheritDoc} */ 046 @Override 047 public boolean validate(@Nonnull List<String> errorMessages) { 048 return true; 049 } 050 051 /** {@inheritDoc} */ 052 @Override 053 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 054 Sequence action = new Sequence(systemName, userName); 055 updateObject(action); 056 return InstanceManager.getDefault(DigitalActionManager.class).registerAction(action); 057 } 058 059 /** {@inheritDoc} */ 060 @Override 061 public void updateObject(@Nonnull Base object) { 062 if (!(object instanceof Sequence)) { 063 throw new IllegalArgumentException("object must be an Sequence but is a: "+object.getClass().getName()); 064 } 065 066 Sequence action = (Sequence)object; 067 action.setStartImmediately(_startImmediately.isSelected()); 068 action.setRunContinuously(_runContinuously.isSelected()); 069 } 070 071 /** {@inheritDoc} */ 072 @Override 073 public String toString() { 074 return Bundle.getMessage("Sequence_Short"); 075 } 076 077 @Override 078 public void dispose() { 079 } 080 081}