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.*;
/**
* ParameterObjectComboBoxes hold references to Test Data Items of a
* particular type. Users use the ParameterObjectComboBox to select one
* of these references so he/she can:
*
* Pre-conditions: none
* Post-conditions: Creates a new instance of ParameterObjectComboBox
* @param tn string containing the name of the type
*/
public ParameterObjectComboBox(String tn)
{
// CALL addItem of this with tn
// SET typeName to tn
addItem(tn);
typeName = tn;
/*
setEditable(tn.equals("java.lang.String") || tn.equals("java.lang.Byte") ||
tn.equals("java.lang.Boolean") || tn.equals("java.lang.Character") ||
tn.equals("java.lang.Double") || tn.equals("java.lang.Float") ||
tn.equals("java.lang.Integer") || tn.equals("java.lang.Long") ||
tn.equals("java.lang.Short"));
*/
getEditor().getEditorComponent().addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent evt)
{
if (isEditable() && isEnabled()) getEditor().setItem("");
}
});
}
/**
* Returns the currently selected test data item
*
* Pre-conditions: none
* Post Conditions: none
*/
public Object getSelectedItem()
{
return dataModel.getElementAt(getSelectedIndex());
}
/**
* selects the default 'no parameter object' value (aka 'the typename' string)
*
* Pre-conditions: none
* Post-conditions: none
*/
public void unselect()
{
// CALL setSelectedIndex of JComboBox with 0 as parameter
setSelectedIndex(0);
}
/**
* returns the name of the type
*
* Pre-conditions: none
* Post-conditions: returned value will be a string containing the name of the type
* @returned String containing the name of the type
*/
public String getTypeName()
{
// RETURN typeName
return typeName;
}
/**
* selects last item in combo box
*
* Pre-conditions: none
* Post-conditions: none
*/
public void selectLast()
{
// CALL getItemCount of JComboBox
// CALL setSelectedIndex with value that was returned from getItemCount
/* if empty, select 0; otherwise select (count - 1) */
if (getItemCount() == 0)
{
setSelectedIndex(getItemCount());
}
else
{
setSelectedIndex(getItemCount() - 1);
}
}
/**
* informs the appropriate listeners when a parameter data item is changed
*
* Pre-conditions: none
* Post-conditions: none
* @param changed the ParameterDataInterface that was changed
*/
public void parameterDataChanged(ParameterDataInterface changed)
{
// CALL repaint of JComboBox
}
/**
* informs the appropriate listeners when a parameter data item is added
*
* Pre-conditions: none
* Post-conditions: none
* @param added the ParameterDataInterface that was added
*/
public void parameterDataAdded(ParameterDataInterface added)
{
// CALL addElement of validSelections with added
// CALL addItem of JComboBox with added
addItem(added);
}
/**
* informs the appropriate listeners when a parameter data item is removed
*
* Pre-conditions: none
* Post-conditions: none
* @param removed the ParameterDataInterface that was removed
*/
public void parameterDataRemoved(ParameterDataInterface removed)
{
// CALL removeElement of validSelections with removed
// CALL removeItem of JComboBox with removed
removeItem(removed);
}
/**
* String containing the name of the types of data listed in the ComboBox
*/
protected String typeName;
}