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.LogLocalVariables; 014 015/** 016 * Configures an LogLocalVariables object with a Swing JPanel. 017 * 018 * @author Daniel Bergqvist Copyright 2021 019 */ 020public class LogLocalVariablesSwing extends AbstractDigitalActionSwing { 021 022 private JCheckBox _includeGlobalVariables; 023 private JCheckBox _expandArraysAndMaps; 024 private JCheckBox _showClassName; 025 026 @Override 027 protected void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) { 028 LogLocalVariables action = (LogLocalVariables)object; 029 030 panel = new JPanel(); 031 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 032 033 _includeGlobalVariables = new JCheckBox(Bundle.getMessage("LogLocalVariablesSwing_IncludeGlobalVariables")); 034 panel.add(_includeGlobalVariables); 035 036 _expandArraysAndMaps = new JCheckBox(Bundle.getMessage("LogLocalVariablesSwing_ExpandArraysAndMaps")); 037 panel.add(_expandArraysAndMaps); 038 039 _showClassName = new JCheckBox(Bundle.getMessage("LogLocalVariablesSwing_ShowClassName")); 040 panel.add(_showClassName); 041 042 if (action != null) { 043 _includeGlobalVariables.setSelected(action.isIncludeGlobalVariables()); 044 _expandArraysAndMaps.setSelected(action.isExpandArraysAndMaps()); 045 _showClassName.setSelected(action.isShowClassName()); 046 } else { 047 _includeGlobalVariables.setSelected(true); 048 _expandArraysAndMaps.setSelected(false); 049 _showClassName.setSelected(false); 050 } 051 } 052 053 /** {@inheritDoc} */ 054 @Override 055 public boolean validate(@Nonnull List<String> errorMessages) { 056 return true; 057 } 058 059 /** {@inheritDoc} */ 060 @Override 061 public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) { 062 LogLocalVariables action = new LogLocalVariables(systemName, userName); 063 updateObject(action); 064 return InstanceManager.getDefault(DigitalActionManager.class).registerAction(action); 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 public void updateObject(@Nonnull Base object) { 070 if (!(object instanceof LogLocalVariables)) { 071 throw new IllegalArgumentException("object must be an LogLocalVariables but is a: "+object.getClass().getName()); 072 } 073 074 LogLocalVariables action = (LogLocalVariables)object; 075 076 action.setIncludeGlobalVariables(_includeGlobalVariables.isSelected()); 077 action.setExpandArraysAndMaps(_expandArraysAndMaps.isSelected()); 078 action.setShowClassName(_showClassName.isSelected()); 079 } 080 081 /** {@inheritDoc} */ 082 @Override 083 public String toString() { 084 return Bundle.getMessage("LogLocalVariables_Short"); 085 } 086 087 @Override 088 public void dispose() { 089 } 090 091}