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.ShutdownComputer; 014import jmri.jmrit.logixng.actions.ShutdownComputer.Operation; 015import jmri.jmrit.logixng.util.swing.LogixNG_SelectEnumSwing; 016 017/** 018 * Configures an ActionTurnout object with a Swing JPanel. 019 * 020 * @author Daniel Bergqvist Copyright 2021 021 */ 022public class ShutdownComputerSwing extends AbstractDigitalActionSwing { 023 024 private LogixNG_SelectEnumSwing<Operation> _selectOperationSwing; 025 026 027 public ShutdownComputerSwing() { 028 } 029 030 public ShutdownComputerSwing(JDialog dialog) { 031 super.setJDialog(dialog); 032 } 033 034 @Override 035 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 036 ShutdownComputer action = (ShutdownComputer)object; 037 038 _selectOperationSwing = new LogixNG_SelectEnumSwing<>(getJDialog(), this); 039 040 JPanel _tabbedPaneOperation; 041 if (action != null) { 042 _tabbedPaneOperation = _selectOperationSwing.createPanel(action.getSelectEnum(), Operation.values()); 043 } else { 044 _tabbedPaneOperation = _selectOperationSwing.createPanel(null, Operation.values(), Operation.ShutdownJMRI); 045 } 046 047 panel = new JPanel(); 048 panel.add(_tabbedPaneOperation); 049 } 050 051 /** {@inheritDoc} */ 052 @Override 053 public boolean validate(@Nonnull List<String> errorMessages) { 054 // Create a temporary action to test formula 055 ShutdownComputer action = new ShutdownComputer("IQDA1", null); 056 _selectOperationSwing.validate(action.getSelectEnum(), errorMessages); 057 return errorMessages.isEmpty(); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 063 ShutdownComputer action = new ShutdownComputer(systemName, userName); 064 updateObject(action); 065 return InstanceManager.getDefault(DigitalActionManager.class).registerAction(action); 066 } 067 068 /** {@inheritDoc} */ 069 @Override 070 public void updateObject(@Nonnull Base object) { 071 if (! (object instanceof ShutdownComputer)) { 072 throw new IllegalArgumentException("object must be an ShutdownComputer but is a: "+object.getClass().getName()); 073 } 074 ShutdownComputer action = (ShutdownComputer)object; 075 _selectOperationSwing.updateObject(action.getSelectEnum()); 076 } 077 078 /** {@inheritDoc} */ 079 @Override 080 public String toString() { 081 return Bundle.getMessage("ShutdownComputer_Short"); 082 } 083 084 @Override 085 public void dispose() { 086 _selectOperationSwing.dispose(); 087 } 088 089}