001package jmri.jmrix.bidib.simulator; 002 003import java.awt.event.ActionEvent; 004import java.awt.event.ActionListener; 005import java.awt.event.FocusEvent; 006import java.awt.event.FocusListener; 007import javax.swing.JLabel; 008import javax.swing.JPanel; 009import javax.swing.JTextField; 010 011 012import org.slf4j.Logger; 013import org.slf4j.LoggerFactory; 014 015/** 016 * Handle configuring a BiDiB layout connection via a BiDiBSimulator 017 * adapter. 018 * <p> 019 * This uses the {@link BiDiBSimulatorAdapter} class to do the actual connection. 020 * 021 * @author Bob Jacobsen Copyright (C) 2001, 2003 022 * @author Eckart Meyer Copyright (C) 2019 023 * 024 * @see BiDiBSimulatorAdapter 025 */ 026public class ConnectionConfig extends jmri.jmrix.AbstractSimulatorConnectionConfig { 027 028 protected JLabel simulationFileLabel = new JLabel("Simulation File:"); 029 protected JTextField simulationFileField = new JTextField(10); 030 031 /** 032 * Ctor for an object being created during load process; Swing init is 033 * deferred. 034 * @param p PortAdapter to present port 035 */ 036 public ConnectionConfig(jmri.jmrix.SerialPortAdapter p) { 037 super(p); 038 log.debug("ConnectionConfig, p: {}", p); 039 } 040 041 /** 042 * Ctor for a functional Swing object with no preexisting adapter 043 */ 044 public ConnectionConfig() { 045 super(); 046 log.debug("ConnectionConfig"); 047 } 048 049 @Override 050 public String name() { 051 log.debug("get name"); 052 return "BiDiB Simulator"; 053 } 054 055 String manufacturerName = jmri.jmrix.bidib.BiDiBConnectionTypeList.BIDIB; 056 057 @Override 058 public String getManufacturer() { 059 //log.debug("get manufacturer: {}", manufacturerName); 060 return manufacturerName; 061 } 062 063 @Override 064 public void setManufacturer(String manu) { 065 log.debug("set manufacturer: {}", manu); 066 manufacturerName = manu; 067 } 068 069 @Override 070 protected void setInstance() { 071 log.debug("BiDiB Simulator ConnectionConfig.setInstance: {}", adapter); 072 if (adapter == null) { 073 adapter = new BiDiBSimulatorAdapter(); 074 log.debug("-- adapter created: {}", adapter); 075 } 076 } 077 078// @Override 079// public boolean isDirty() { 080// log.debug("isDirty"); 081// if (super.isDirty()) { 082// return true; 083// } 084// return ( (()) ) 085// } 086 087// @Override 088// public boolean isRestartRequired() { 089// log.debug("isRestartRequired"); 090// return super.isRestartRequired(); 091// } 092 093 /** 094 * {@inheritDoc} 095 */ 096 @Override 097 public void loadDetails(JPanel details) { 098 log.debug("loadDetails"); 099 super.loadDetails(details); 100 } 101 102 /** 103 * {@inheritDoc} 104 */ 105 @Override 106 protected void checkInitDone() { 107 super.checkInitDone(); 108 log.debug("checkInitDone"); 109 if (adapter.getSystemConnectionMemo() != null) { 110 simulationFileField.setText(((BiDiBSimulatorAdapter)adapter).getSimulationFile()); 111 simulationFileField.addActionListener(new ActionListener() { 112 @Override 113 public void actionPerformed(ActionEvent e) { 114 ((BiDiBSimulatorAdapter)adapter).setSimulationFile(simulationFileField.getText()); 115 simulationFileField.setText(((BiDiBSimulatorAdapter)adapter).getSimulationFile()); 116 } 117 }); 118 simulationFileField.addFocusListener(new FocusListener() { 119 @Override 120 public void focusLost(FocusEvent e) { 121 ((BiDiBSimulatorAdapter)adapter).setSimulationFile(simulationFileField.getText()); 122 simulationFileField.setText(((BiDiBSimulatorAdapter)adapter).getSimulationFile()); 123 } 124 125 @Override 126 public void focusGained(FocusEvent e) { 127 } 128 }); 129 } 130 } 131 132 @Override 133 protected void showAdvancedItems() { 134 super.showAdvancedItems(); // we're adding to the normal advanced items. 135 log.debug("showAdvancedItems"); 136 if (adapter.getSystemConnectionMemo() != null) { 137 cR.gridy += 2; 138 cL.gridy += 2; 139 gbLayout.setConstraints(simulationFileLabel, cL); 140 gbLayout.setConstraints(simulationFileField, cR); 141 _details.add(simulationFileLabel); 142 _details.add(simulationFileField); 143 } 144 if (_details.getParent() != null) { 145 _details.getParent().revalidate(); 146 _details.getParent().repaint(); 147 } 148 } 149 150 @Override 151 public void updateAdapter() { 152 super.updateAdapter(); // we're adding more details to the connection. 153 log.debug("updateAdapter"); 154 if (adapter.getSystemConnectionMemo() != null) { 155 ((BiDiBSimulatorAdapter)adapter).setSimulationFile(simulationFileField.getText()); 156 } 157 } 158 159// @Override 160// public boolean isHostNameAdvanced() { 161// return showAutoConfig.isSelected(); 162// } 163// 164// @Override 165// public boolean isAutoConfigPossible() { 166// return true; 167// } 168 169 170 171 private final static Logger log = LoggerFactory.getLogger(ConnectionConfig.class); 172}