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.*; import java.sql.Time; /** * This class displays the GUI representing all the Field-related information * of an ETAMainModel. It's primary purpose is to serve as the GUI for the * the Object Inspector dialog. * * @see ObjectInspector */ // Author: Michael Hebron // Version History // Nov 18, 2000 - comments, pseudocode added // Nov 19, 2000 - added field and listener for OK button // Nov 28, 2000 - implemented addFieldRow // - implemented constructor // Feb 12, 2001 - (Jonathon Lee) - removed ETA.out calls // Feb 13, 2001 - (Jonathon Lee) - updated pseudocode for setEditable public class ETAInspectorView extends ETAViewAbstract { /** * Creates a new instance of an ETAInspectorView *

* Pre-conditions: none
* Post-conditions: ETAMainView's fields become initialized * @param parent The JDialog that the Object Inspector will be modal upon */ public ETAInspectorView(JDialog parent) { // CALLS super class's constructor with parent super(parent); // SET closeButton to NEW JButton with "Close" // SET fieldRows to NEW Vector // SET fieldVisibility to NEW HashMap // SET fieldClassLevel to NEW JTabbedPane // SET description to NEW String closeButton = new JButton("Close"); fieldRows = new Vector(); fieldVisibility = new HashMap(); fieldClassLevel = new JTabbedPane(); } /** * Sets the description and type labels of the object being inspected in the Object * Inspector dialog * Pre-conditions: none
* Post-conditions: the Description label of the Object Inspector will be set * @param description description of the object being inspected */ public void setInspectDescription(String description) { // CALL setText of descLabel with CONCAT of "Description: " and description // CALL setText of typeLabel with CONCAT of "Object Type: " and // toString of getMainTestClass of model descLabel.setText("Description: " + description); typeLabel.setText("Object Type: " + model.getMainTestClass().toString()); } /** * Lays out the GUI components of the view *

* This method is meant to be called only once, right after construction * of the view *

* Pre-conditions: The view hasn't had layoutGUI called on it before
* Post-conditions: All of the view's GUI components become layed out in * an orderly fashion */ public void layoutGUI() { /* gui layout */ GridBagConstraints cns = new GridBagConstraints(); // cns used for the GridBagLayout // CALL setLayout of getContentPane with NEW BorderLayout getContentPane().setLayout(new GridBagLayout()); // CALL add of getContentPane with typeLabel cns.gridx = 0; cns.gridy = GridBagConstraints.RELATIVE; cns.anchor = GridBagConstraints.WEST; typeLabel = new JLabel("Object Type:"); getContentPane().add(typeLabel, cns); // CALL add of getContentPane with descLabel cns.gridx = 0; cns.gridy = GridBagConstraints.RELATIVE; cns.anchor = GridBagConstraints.WEST; descLabel = new JLabel("Description:"); getContentPane().add(descLabel, cns); // CALL setPreferredSize of fieldClassLevel with NEW 400x400 Dimension // CALL add of getContentPane with fieldClassLevel fieldClassLevel.setPreferredSize(new Dimension(400, 400)); cns.gridx = 0; cns.gridy = GridBagConstraints.RELATIVE; cns.anchor = GridBagConstraints.CENTER; cns.fill = GridBagConstraints.BOTH; getContentPane().add(fieldClassLevel, cns); // CALL add of getContentPane with closeButton cns.gridx = 0; cns.gridy = GridBagConstraints.RELATIVE; cns.anchor = GridBagConstraints.EAST; cns.fill = GridBagConstraints.NONE; getContentPane().add(closeButton, cns); // CALL pack of this pack(); /* window closing listeners */ closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { dispose(); } }); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { dispose(); } public void windowClosed(WindowEvent evt) { ETA.log.print("["); ETA.log.print((new Time(System.currentTimeMillis())).toString().substring(0, 5)); ETA.log.println("] End Inspect"); } }); // CALL setTitle of this with "Object Inspector" setTitle("Object Inspector"); } /** * Sets the model that this class is a view for *

* Pre-condition: none * Post-condition: The view becomes responsible for displaying * model's data * @param model The ETAMainModel whose data the view becomes responsible for * displaying */ public void setModel(ETAMainModel model) { // SET model of this to model this.model = model; } /** * Creates a new FieldRow and adds it to the * collection of FieldRows the view is responsible for displaying. *

* This function also registers the ParameterObjectComboBoxes of the new * FieldRow as a ParameterDataListener of the ETAMainModel.

* Pre-conditions: none
* Post-conditions: The view has a new FieldRow that it's responsible for * displaying. The combo boxes in the new FieldRow become ParameterDataListeners * of the ETAMainModel * @param fieldData a FieldDataInterface for the FieldRow that * is being added for the View to display */ public void addFieldRow(FieldDataInterface fieldData) { // CONSTRUCT fr as FieldRow with fieldData // CALL add of fieldRows with fr // CALL getDeclaringClass of fieldData returns className // CALL get of fieldVisibility with className returns vtp FieldRow fr = new FieldRow(fieldData); fieldRows.add(fr); String className = fieldData.getDeclaringClass(); VisibilityTabbedPane vtp = (VisibilityTabbedPane) fieldVisibility.get(className); // IF vtp = null THEN // CONSTRUCT newVT as VisibilityTabbedPane // CALL put of fieldVisibility with className and newVT // SET vtp to newVT // ENDIF if (vtp == null) { VisibilityTabbedPane newVT = new VisibilityTabbedPane(); fieldVisibility.put(className, newVT); vtp = newVT; fieldClassLevel.add(className, vtp); } // CALL addRow of vtp with visibility and fr // CALL getComboBoxes of fr returns arrayOfCB // CALL addParameterDataListener of model with arrayOfCB[0] //todo: code for bitflagchecking int visibility = 0; if (Modifier.isPublic(fieldData.getModifiers())) { visibility = Modifier.PUBLIC; } else if (Modifier.isProtected(fieldData.getModifiers())) { visibility = Modifier.PROTECTED; } else if (Modifier.isPrivate(fieldData.getModifiers())) { visibility = Modifier.PRIVATE; } vtp.addRow(visibility, fr); ParameterObjectComboBox[] arrayOfCB = fr.getComboBoxes(); model.addParameterDataListener(arrayOfCB[0]); } /** * Enables/disables the view's GUI components to allow/disallow the user * to change the values stored in the main test object's fields *

* Pre-conditions: none
* Post-conditions: The view's GUI components for displaying/editing fields * become enabled/disabled */ public void setEditable(boolean editable) { // CALL iterator of fieldrows returns itr // WHILE hasNext of itr // CALL next of itr returns fieldRow // CALL getComboBoxes of fieldRow returns methodComboBoxArray // FOR all of methodComboBoxArray // CALL setEnabled of methodComboBoxArray[x] with editable // ENDFOR // ENDWHILE Iterator itr = fieldRows.iterator(); while (itr.hasNext()) { // current FieldRow that is having it's row's disabled FieldRow tempFieldRow = (FieldRow) (itr.next()); // comboboxes associated with the current fieldrow ParameterObjectComboBox[] methodComboBoxArray = tempFieldRow.getComboBoxes(); // loop to setEnabled for all the comboboxes in methodComboBoxArray for (int index = 0; index < methodComboBoxArray.length; index++) { methodComboBoxArray[index].setEnabled(editable); } } } /** * Clears the view of its FieldRows *

* Pre-conditions: none
* Post-conditions: The view is no longer displaying FieldRows. The combo boxes * in the removed MethodRow are unregistered from the ETAMainModel as * ParameterDataListeners */ public void clearFields() { // CALL iterator of fieldRows returns itr // WHILE hasNext of itr // CALL next of itr returns removeRow // CALL getComboBoxes of removeRow returns arrayOfCB // CALL removeParameterDataListener of model with arrayOfCB[0] // ENDWHILE Iterator itr = fieldRows.iterator(); while(itr.hasNext()) { model.removeParameterDataListener( ((RowAbstract)itr.next()).getComboBoxes()[0]); } // CALL values of fieldVisibility returns tabs // CALL iterator of tabs returns itr // WHILE hasNext of itr // CALL next of itr returns visTab // CALL remove of fieldClassLevel with visTab // ENDWHILE itr = fieldVisibility.values().iterator(); while(itr.hasNext()) { fieldClassLevel.remove((Component)itr.next()); } // CALL clear of fieldVisibility // CALL clear of fieldRows fieldVisibility.clear(); fieldRows.clear(); } /** * JTabbedPane containing tabs for each class in the class hiearchy of the main * test object. Each of these tabs displays FieldRows for * each field of a class */ protected JTabbedPane fieldClassLevel; /** *@link aggregation * @associates <{VisibilityTabbedPane}> */ /** * Map of Strings (representing the name of a a class in the class hierarchy * of the main test object) to VisibilityTabbedPanes */ protected java.util.Map fieldVisibility; /** * Collection of FieldRows that this view is responsible for displaying */ protected Collection fieldRows; /** * The "OK" button for the ObjectInspector dialog */ protected JButton closeButton; /** * Label displaying the description of the object being inspected */ protected JLabel descLabel; /** * Label displaying the type of the object being inspected */ protected JLabel typeLabel; }