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 represents a Test Data Item. It provides * methods that give information on the Test Data Item's type, name, * and value. It also provides methods to set the value and name of the Test * Data Item. */ // Author: Phillip Hansen // Version History // Nov 19, 2000 - wrote psuedo code and description // Nov 19, 2000 - (Brian Laird) added constructor and getTypeName // Nov 30, 2000 - (Mike Hebron) updated class description // Jan 12, 2001 - Mike Power implemented accessor methods // Jan 12, 2001 - Mike Power implemented constructor // Jan 27, 2001 - Phillip Hansen implemented isPrimitive // Feb 3, 2001 - Wes Strickland implemented changePrimitiveValue() method // Feb 6, 2001 - Phillip Hansen fixed a problem with isPrimitive (Teamatic // defect number 504828). // Feb 07, 2001 - (Apel Yahinian) Updated constructor, created model protected value // Changed inspectObjectValue to use model.inspect // Feb 11, 2001 - (Phillip Hansen) Added session log code for the remove method // in accordance with Teamatic defect 505170 public class ParameterData implements ParameterDataInterface { /** * Creates an instance of ParameterData *

* Pre-conditions: none * Post-conditions: ParameterData is constructed * @param newValueObject an object that contains the test data item's value * @param userCreatedName a string of test data item's name */ public ParameterData(Object newValueObject, String userCreatedName, ETAMainModel newmodel) { // SET valueObject to newValueObject // SET userDefinedName to userCreatedName valueObject = newValueObject; userDefinedName = userCreatedName; model = newmodel; } /** * Returns the type name of the test data item *

* Pre-conditions: none * Post-conditions: none * @return a String of the test data item type's name */ public String getTypeName() { // CALL getClass of valueObject returns cla // CALL classToName of ETAMainModel with cla returns str // RETURN str return ETAMainModel.classToName(valueObject.getClass()); } /** *returns the user defined name of the ParameterData *

*Pre-conditions: none
*Post-conditions: none
*/ public String getDescriptiveName() { // RETURN userDefinedName return userDefinedName; } /** * Redefines toString to return the user defined name of the * ParameterData object *

*Pre-conditions: none
*Post-conditions: none
*/ public String toString() { String retString; // string returned by method // IF isPrimitive THEN // SET retString to CONCAT of userDefinedName, " (", valueObject, ")" // ELSE // SET retString to userDefinedName // ENDIF if (isPrimitive()) { retString = userDefinedName + " (" + valueObject + ")"; } else { retString = userDefinedName; } // RETURN retString return retString; } /** * sets the name of the object *

* Pre-conditions: none
* Post-conditions: none * @param newName the new name of the object */ public void changeName(String newName) { // CONSTRUCT oldName as NEW String with userDefinedName // SET userDefinedName to newName String oldName = new String(userDefinedName); userDefinedName = newName; ETA.log.print("["); ETA.log.print((new Time(System.currentTimeMillis())).toString().substring(0, 5)); ETA.log.println("] Rename '" + oldName + "' to '" + newName + "'"); } /** * displays an object inspector dialog for the object *

* Pre-conditions: none
* Post-conditions: object inspector is displayed to the user */ public void inspectObjectValue() { // CALL inspect of inspect (in ETAMainModel) with valueObject, true // CALL setVisible of inspect with true model.inspect(valueObject, userDefinedName, true); // CONSTRUCT sessionLog as NEW String String sessionLog = new String(); // session log entry /* assemble session log entry */ sessionLog = "[" + (new Time( System.currentTimeMillis())).toString().substring(0, 5) + "] Inspect '" + userDefinedName + "'"; // CALL println of log of ETA with sessionLog ETA.log.println(sessionLog); } /** * sets the value of the object *

* Pre-conditions: none
* Post-conditions: valueObject will be set to a new object * of the appropriate type * @param value new value for the object */ public void changePrimitiveValue(String value) { Calendar rightNow; // used for logging the time the value was changed int minute; // the minute value of the time right now String twoDigitMinute; // string representation of minute, with leading 0s // CALL getValue of PrimitiveValueFactory with value // SET valueObject to the returned object valueObject = PrimitiveValueFactory.getAPrimitiveValueFactory(ETAMainModel.classToName( valueObject.getClass())).getValue(value); // SET rightNow to NEW GregorianCalendar with Locale.US // CALL get of rightNow with CALENDAR.MINUTE returns minute // IF minute < 10 // SET twoDigitMinute to CONCAT of "0" and minute; // ELSE // CALL toString of Integer with minute returns twoDigitMinute // ENDIF rightNow = new GregorianCalendar(Locale.US); minute = rightNow.get(Calendar.MINUTE); if (minute < 10) { twoDigitMinute = "0" + minute; } else { twoDigitMinute = Integer.toString(minute); } // LOG the change value event ([hh:mm] Change 'name' value to 34) ETA.log.println("[" + (new Time( System.currentTimeMillis())).toString().substring(0, 5) + "] Change '" + userDefinedName + "' value to " + valueObject); } /** * removes the object from ETAMainModel *

* Pre-conditions: none
* Post-conditions: object is no longer stored in the model */ public void remove() { Calendar rightNow; // used for logging the time the value was removed int minute; // the minute value of the time right now String twoDigitMinute; // string representation of minute, with leading 0s // CALL removeParameterData on model with this model.removeParameterData(this); // SET rightNow to NEW GregorianCalendar with Locale.US // CALL get of rightNow with CALENDAR.MINUTE returns minute // IF minute < 10 // SET twoDigitMinute to CONCAT of "0" and minute; // ELSE // CALL toString of Integer with minute returns twoDigitMinute // ENDIF rightNow = new GregorianCalendar(Locale.US); minute = rightNow.get(Calendar.MINUTE); if (minute < 10) { twoDigitMinute = "0" + minute; } else { twoDigitMinute = Integer.toString(minute); } // LOG the remove event ([hh:mm] Delete 'name') ETA.log.println("[" + rightNow.get(Calendar.HOUR_OF_DAY) + ":" + twoDigitMinute + "] " + "Delete '" + userDefinedName + "'"); } /** * gets the value of the object for display as a string *

* Pre-conditions: none
* Post-conditions: none * @return the value of the object as a string */ public String getValue() { // CALL toString on valurObject returns ret // RETURN ret return valueObject.toString(); } /** * gets the object *

* Pre-conditions: none
* Post-conditions: none * @return the parameter data object */ public Object getValueObject() { // RETURN valueObject return valueObject; } /** * Determines if the data is primitive *

* Pre-conditions: none
* Post-conditions: none * @return true if the data is primitive */ public boolean isPrimitive() { // CALL getClass on valueObject // CALL classToName of ETAMainModel with returned class // check the returned name against the primitive names // return true if the names match String name = ETAMainModel.classToName(valueObject.getClass()); if (name.equals("java.lang.Float") || name.equals("java.lang.String") || name.equals("java.lang.Integer") || name.equals("java.lang.Byte") || name.equals("java.lang.Short") || name.equals("java.lang.Long") || name.equals("java.lang.Double") || name.equals("java.lang.Character") || name.equals("java.lang.Boolean")) return true; return false; } /** * name of the object */ protected String userDefinedName; /** * The test data item that this class represents */ protected Object valueObject; /** * reference to the ETAMainModel */ protected ETAMainModel model; }