001package jmri.jmrit.logixng.tools.debugger.swing;
002
003// import jmri.jmrit.logixng.tools.swing.LocalVariableTableModel;
004
005// import java.awt.BorderLayout;
006// import java.awt.Dimension;
007// import java.awt.event.ActionEvent;
008
009import java.util.List;
010
011import javax.annotation.CheckForNull;
012import javax.annotation.Nonnull;
013import javax.swing.*;
014
015import jmri.*;
016import jmri.jmrit.logixng.*;
017// import jmri.jmrit.logixng.SymbolTable.InitialValueType;
018// import jmri.jmrit.logixng.SymbolTable.VariableData;
019import jmri.jmrit.logixng.swing.AbstractSwingConfigurator;
020
021/**
022 * Abstract class for SwingConfiguratorInterface
023 */
024public abstract class AbstractDebuggerMaleSocketSwing extends AbstractSwingConfigurator {
025
026    private JPanel panel;
027//    private JPanel tablePanel;
028//    private JTable table;
029//    private LocalVariableTableModel tableModel;
030    
031    /** {@inheritDoc} */
032    @Override
033    public BaseManager<? extends NamedBean> getManager() {
034        throw new UnsupportedOperationException("Not supported");
035    }
036    
037    /** {@inheritDoc} */
038    @Override
039    public final JPanel getConfigPanel(@Nonnull JPanel buttonPanel) throws IllegalArgumentException {
040        createPanel(null, buttonPanel);
041        return panel;
042    }
043    
044    /** {@inheritDoc} */
045    @Override
046    public final JPanel getConfigPanel(@Nonnull Base object, @Nonnull JPanel buttonPanel) throws IllegalArgumentException {
047        createPanel(object, buttonPanel);
048        return panel;
049    }
050    
051    protected final void createPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) {
052        if ((object != null) && (! (object instanceof MaleSocket))) {
053            throw new IllegalArgumentException("object is not a MaleSocket: " + object.getClass().getName());
054        }
055        panel = new JPanel();
056/*        
057        MaleSocket maleSocket = (MaleSocket)object;
058        int row = 0;
059        panel.setLayout(new java.awt.GridBagLayout());
060        java.awt.GridBagConstraints c = new java.awt.GridBagConstraints();
061        c.gridwidth = 1;
062        c.gridheight = 1;
063        c.gridx = 0;
064        c.anchor = java.awt.GridBagConstraints.EAST;
065        JPanel subPanel = createSubPanel(object, buttonPanel);
066        if (subPanel != null) {
067            c.gridy = row++;
068            panel.add(subPanel, c);
069        }
070        createTablePanel(maleSocket, buttonPanel);
071        c.gridy = row;
072        panel.add(tablePanel, c);
073*/        
074    }
075/*    
076    private void createTablePanel(MaleSocket maleSocket, @Nonnull JPanel buttonPanel) {
077        tablePanel = new JPanel();
078        table = new JTable();
079        tableModel = new LocalVariableTableModel(maleSocket);
080        table.setModel(tableModel);
081        table.setDefaultRenderer(InitialValueType.class,
082                new LocalVariableTableModel.TypeCellRenderer());
083        table.setDefaultEditor(InitialValueType.class,
084                new LocalVariableTableModel.TypeCellEditor());
085        table.setDefaultRenderer(LocalVariableTableModel.Menu.class,
086                new LocalVariableTableModel.MenuCellRenderer());
087        table.setDefaultEditor(LocalVariableTableModel.Menu.class,
088                new LocalVariableTableModel.MenuCellEditor(table, tableModel));
089        tableModel.setColumnForMenu(table);
090        JScrollPane scrollpane = new JScrollPane(table);
091        scrollpane.setPreferredSize(new Dimension(400, 200));
092        tablePanel.add(scrollpane, BorderLayout.CENTER);
093        JButton add = new JButton(Bundle.getMessage("TableAddVariable"));
094        buttonPanel.add(add);
095        add.addActionListener((ActionEvent e) -> {
096            tableModel.add();
097        });
098    }
099*/    
100    /** {@inheritDoc} */
101    @Override
102    public final boolean validate(@Nonnull List<String> errorMessages) {
103        return true;
104    }
105    
106    /**
107     * The sub class may override this method to add more detail to the panel.
108     * @param object the object for which to return a configuration panel
109     * @param buttonPanel panel with the buttons
110     * @return a panel that configures this object
111     */
112    protected JPanel createSubPanel(@CheckForNull Base object, @Nonnull JPanel buttonPanel) {
113        return null;
114    }
115    
116    /**
117     * If the sub class overrides createSubPanel(), it may use this method to
118     * validate the sub panel.
119     * <P>
120     * The parameter errorMessage is used to give the error message in case of
121     * an error. If there are errors, the error messages is added to the list
122     * errorMessage.
123     * 
124     * @param errorMessages the error messages in case of an error
125     * @return true if data in the form is valid, false otherwise
126     */
127    public boolean validateSubPanel(@Nonnull List<String> errorMessages) {
128        return true;
129    }
130    
131    /** {@inheritDoc} */
132    @Override
133    public MaleSocket createNewObject(@Nonnull String systemName, @CheckForNull String userName) {
134        throw new UnsupportedOperationException("Not supported");
135    }
136    
137    /** {@inheritDoc} */
138    @Override
139    public final void updateObject(@Nonnull Base object) {
140        if (! (object instanceof MaleSocket)) {
141            throw new IllegalArgumentException("object is not a MaleSocket: " + object.getClass().getName());
142        }
143/*        
144        MaleSocket maleSocket = (MaleSocket)object;
145        maleSocket.clearLocalVariables();
146        for (VariableData variableData : tableModel.getVariables()) {
147            maleSocket.addLocalVariable(variableData);
148        }
149*/        
150    }
151    
152    /** {@inheritDoc} */
153    @Override
154    public String getExampleSystemName() {
155        throw new UnsupportedOperationException("Not supported");
156    }
157    
158    /** {@inheritDoc} */
159    @Override
160    public String getAutoSystemName() {
161        throw new UnsupportedOperationException("Not supported");
162    }
163    
164    /** {@inheritDoc} */
165    @Override
166    public String toString() {
167        throw new UnsupportedOperationException("Not supported");
168    }
169    
170    @Override
171    public final void dispose() {
172    }
173    
174    /*.*
175     * Dispose the sub panel and remove all the listeners that this class may
176     * have registered.
177     *./
178    public void disposeSubPanel() {
179    }
180*/    
181}