001package jmri.jmrit.logixng.expressions.swing; 002 003import java.util.List; 004 005import javax.annotation.CheckForNull; 006import javax.annotation.Nonnull; 007import javax.swing.JLabel; 008import javax.swing.JPanel; 009 010import jmri.*; 011import jmri.jmrit.logixng.Base; 012import jmri.jmrit.logixng.AnalogExpressionManager; 013import jmri.jmrit.logixng.MaleSocket; 014import jmri.jmrit.logixng.expressions.AnalogExpressionLocalVariable; 015import jmri.jmrit.logixng.util.swing.LogixNG_SelectStringSwing; 016 017/** 018 * Configures an AnalogExpressionLocalVariable object with a Swing JPanel. 019 * 020 * @author Daniel Bergqvist Copyright 2022 021 */ 022public class AnalogExpressionLocalVariableSwing extends AbstractAnalogExpressionSwing { 023 024 private LogixNG_SelectStringSwing _selectLocalVariableSwing; 025 026 027 @Override 028 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 029 AnalogExpressionLocalVariable action = (AnalogExpressionLocalVariable)object; 030 031 panel = new JPanel(); 032 033 _selectLocalVariableSwing = new LogixNG_SelectStringSwing(getJDialog(), this); 034 035 JPanel _tabbedPaneNamedBean; 036 if (action != null) { 037 _tabbedPaneNamedBean = _selectLocalVariableSwing.createPanel(action.getSelectNamedBean()); 038 } else { 039 _tabbedPaneNamedBean = _selectLocalVariableSwing.createPanel(null); 040 } 041 042 panel.add(new JLabel(Bundle.getMessage("AnalogExpressionLocalVariable_LocalVariable"))); 043 panel.add(_tabbedPaneNamedBean); 044 } 045 046 /** {@inheritDoc} */ 047 @Override 048 public boolean validate(@Nonnull List<String> errorMessages) { 049 AnalogExpressionLocalVariable expression = new AnalogExpressionLocalVariable("IQAE1", null); 050 _selectLocalVariableSwing.validate(expression.getSelectNamedBean(), errorMessages); 051 return errorMessages.isEmpty(); 052 } 053 054 /** {@inheritDoc} */ 055 @Override 056 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 057 AnalogExpressionLocalVariable expression = new AnalogExpressionLocalVariable(systemName, userName); 058 updateObject(expression); 059 return InstanceManager.getDefault(AnalogExpressionManager.class).registerExpression(expression); 060 } 061 062 /** {@inheritDoc} */ 063 @Override 064 public void updateObject(@Nonnull Base object) { 065 if (! (object instanceof AnalogExpressionLocalVariable)) { 066 throw new IllegalArgumentException("object must be an AnalogExpressionLocalVariable but is a: "+object.getClass().getName()); 067 } 068 AnalogExpressionLocalVariable expression = (AnalogExpressionLocalVariable)object; 069 _selectLocalVariableSwing.updateObject(expression.getSelectNamedBean()); 070 } 071 072 /** {@inheritDoc} */ 073 @Override 074 public String toString() { 075 return Bundle.getMessage("AnalogExpressionLocalVariable_Short"); 076 } 077 078 @Override 079 public void dispose() { 080 } 081 082 083// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AnalogExpressionLocalVariableSwing.class); 084 085}