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