package edu.calpoly.cpe205.fetter; import javax.swing.*; import java.util.*; import java.io.*; import java.lang.reflect.*; import java.lang.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*; /** * This class manages all the GUI components used to display information * about a field. This class also responds to UI events triggered by * these GUI components. */ // Author: Wes Strickland // Version History // Nov 18, 2000 - comments/pseudocode // Nov 29, 2000 - (Phillip Hansen) added code to the constructor // Nov 30, 2000 - (Mike Hebron) changed class description // Feb 9, 2001 - (Phillip Hansen) performed code walkthrough public class FieldRow extends RowAbstract { /** * Constructs the FieldRow *

* Pre-conditions: none
* Post-conditions: FieldRow object is constructed * @param fieldData of type FieldDataInterface */ public FieldRow(FieldDataInterface data) { // SET fieldData to data fieldData = data; // CALL getName of fieldData returns X // CALL constructor of JButton // CALL setName with JButton name = new JButton(fieldData.getName()); // Name of the fieldData // CONSTRUCT FieldGetListener // ADD ActionListener to name using FieldGetListener FieldGetListener getListener = new FieldGetListener(); name.addActionListener(getListener); // CALL getModifiers of fieldData returns mod int mod = fieldData.getModifiers(); // modifiers of fieldData // CONSTRUCT JPanel // SET modifierPanel to JPanel modifierPanel = new JPanel(); // panel contaning modifiers of fieldData if(Modifier.isStatic(mod)) { modifierPanel.add(new JLabel(new ImageIcon(this.getClass(). getClassLoader().getResource("edu/calpoly/cpe205/fetter/images/static.gif")))); } if(Modifier.isFinal(mod)) { modifierPanel.add(new JLabel(new ImageIcon(this.getClass(). getClassLoader().getResource("edu/calpoly/cpe205/fetter/images/final.gif")))); } if(Modifier.isTransient(mod)) { modifierPanel.add(new JLabel(new ImageIcon(this.getClass(). getClassLoader().getResource("edu/calpoly/cpe205/fetter/images/transient.gif")))); } if(Modifier.isVolatile(mod)) { modifierPanel.add(new JLabel(new ImageIcon(this.getClass(). getClassLoader().getResource("edu/calpoly/cpe205/fetter/images/volatile.gif")))); } // CALL getType of fieldData return typestring // CONSTRUCT newlabel of JLabel with typestring type = new JLabel(fieldData.getType()); // JLabel containing the type of fieldData // CONSTRUCT ParameterObjectComboBox with string // SET selectors to NEW ParameterObjectComboBox[] with 1 // SET selectors to ParameterObjectComboBox selectors = new ParameterObjectComboBox[1]; selectors[0] = new ParameterObjectComboBox(fieldData.getType()); // CALL getEditor of selector returns edder // CONSTRUCT FieldCreateNewPrimitiveListener fieldCreateNewPrimitiveListener FieldCreateNewPrimitiveListener fieldCreateNewPrimitiveListener = new FieldCreateNewPrimitiveListener(); // ADD actionListener on edder with fieldCreateNewPrimitiveListener selectors[0].getEditor().addActionListener(fieldCreateNewPrimitiveListener); // CONSTRUCT FieldSetListener fieldSetListener // SET setListener to fieldSetListener // CALL addActionListener on selector with FieldSetListener setListener = new FieldSetListener(); selectors[0].addActionListener(setListener); } /** * Listens to field buttons in field panel, used in getting a field *

*/ protected class FieldGetListener implements ActionListener { /** * @param evt of type ActionEvent */ public void actionPerformed(ActionEvent evt) { // CALL updateValue of FieldDataInterface // INDEX selectors with index 0 returns combo // CALL removeActionListener of combo with setListener // CALL selectLast of combo // CALL addActionListener on combo with setListener fieldData.updateValue(); selectors[0].removeActionListener(setListener); selectors[0].selectLast(); selectors[0].addActionListener(setListener); } } /** * Creates a new actionListener for primitive types */ protected class FieldCreateNewPrimitiveListener implements ActionListener { /** * Listens for an ActionEvent from the ParameterObjectComboBox *

* Pre-conditions: none
* Post-conditions: appends primitive to end of ParameterObjectComboBox * @param evt of type ActionEvent */ public void actionPerformed(ActionEvent evt) { // CALL getSelectedItem of ParameterObjectComboBox // CALL createPrimitive of FieldDataInterface returns str // CALL setLast of ParameterObjectComboBox ETA.out.println("FieldRow.FieldCreateNewPrimitiveListener.actionPerformed(" + evt + ")"); } } /** * Sets a listener to listen to this FieldRow *

*/ protected class FieldSetListener implements ActionListener { /** * Sets a listener on the ParameterObjectComboBox *

* Pre-conditions: none
* Post-conditions: none * @param evt of type ActionEvent */ public void actionPerformed(ActionEvent evt) { // INDEX selectors with 0 retuns select // CALL getSelectedItem on select returns item // CALL setValue on fieldData with item if(selectors[0].getSelectedIndex() != 0) { fieldData.setValue((ParameterDataInterface) (selectors[0]. getSelectedItem())); } } } protected FieldDataInterface fieldData; // a FieldRow contains a FieldDataInterface protected ActionListener setListener; // the action listener listening on the ParameterObjectComboBox }