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 javax.swing.border.*; /** * This class contains the GUI components used to display Returned Object * information in the rows of the Returned Objects tab in the Object Pool. * This class also responds to UI events triggered by the GUI components * it contains. */ // author: Phillip Hansen // version history: // Nov 20, 2000 - added psuedo code and description // Nov 30, 2000 - (Mike Hebron) updated class description // Jun 12, 2001 - Mike Power implemented constructor // Jun 13, 2001 - Mike Power removed inspect and primitiveValue // member data // Jun 13, 2001 - Mike Power added value member data // Jan 17, 2001 - Apel Yahinian stubbed all functions // Feb 27, 2001 - (Phillip Hansen) implemeted RemoveListener.actionPerformed // Mar 11, 2001 - (Phillip Hansen) added code to shade the name and value and make // them non-editable public class ReturnedRow { public ReturnedRow(ReturnedDataInterface retData) { // SET returnedData to retData // SET type to NEW JLabel with getTypeName of retData // SET descriptiveName to NEW JTextField with getOriginName of retData // CALL setBackground of descriptiveName with Color.lightGray // CALL setEditable of descriptiveName with false // SET remover to NEW RemoveListener // SET mover to NEW MoveListener returnedData = retData; type = new JLabel(retData.getTypeName()); descriptiveName = new JTextField(retData.getOriginName()); descriptiveName.setBackground(Color.lightGray); descriptiveName.setEditable(false); remover = new RemoveListener(); mover = new MoveListener(); // IF isPrimitive of retData THEN // SET value to NEW JTextField with getValue of retData // CALL setBackground of value with Color.lightGray // CALL setEditable of value with false // ELSE // SET value to NEW JButton with "Inspect" // CALL addActionListener of value with NEW InspectObjectValueListener // ENDIF if(retData.isPrimitive()) { value = new JTextField(retData.getValue()); value.setBackground(Color.lightGray); ((JTextField)value).setEditable(false); } else { value = new JButton("Inspect"); ((JButton) value).addActionListener(new InspectObjectValueListener()); } // CALL addMouseListener of type with NEW SelectedListener type.addMouseListener(new SelectedListener()); // CALL setBorder of type with raised // CALL setBorder of value with raised // CALL setBorder of descriptiveName with raised type.setBorder(raised); value.setBorder(raised); descriptiveName.setBorder(raised); } /** * determines whether or not the row is selected *
* Pre-conditions: none
* Post-conditions: none
*/
public boolean isSelected()
{
// RETURN true if the row is selected
return lowered == type.getBorder();
}
/**
* either selects or deselects the row
*
* Pre-conditions: none
* Post-conditions: none
* @param select boolean determining whether or not to select the row
*/
public void setSelected(boolean select)
{
Border borderType; // border to set on the row components depending on whether
// the row is to be selected or deselected
// IF select is equal to true
// SET borderType to lowered
// ELSE
// SET borderType to raised
// ENDIF
if (select)
borderType = lowered;
else
borderType = raised;
// CALL setBorder of type with borderType
// CALL setBorder of value with borderType
// CALL setBorder of descriptiveName with borderType
type.setBorder(borderType);
value.setBorder(borderType);
descriptiveName.setBorder(borderType);
}
/**
* gets the name of the parameter data
*
* Pre-conditions: none
* Post-conditions: none
* @return JTextField containing the name
*/
public JTextField getNameTextField()
{
// RETURN descriptiveName
return descriptiveName;
}
/**
* gets the type of the parameter data
*
* Pre-conditions: none
* Post-conditions: none
* @return JLabel containing the type
*/
public JLabel getTypeLabel()
{
// RETURN type
return type;
}
/**
* gets the value of the parameter
*
* Pre-conditions: none
* Post-conditions: none
* @return JComponent containing the value
*/
public JComponent getValueComponent()
{
// RETURN value
return value;
}
/**
* Returns the ActionListener that will reaspond to action events
* by removing the ReturnedRow
*/
public ActionListener getRemoveListener()
{
//RETURN remover
return remover;
}
/**
* Returns the ActionListener that will respond to action events by
* moving the ReturnedRow to the ParameterTab
*/
public ActionListener getMoveListener()
{
//RETURN mover
return mover;
}
/**
* the listener that will recieve events and reaspond by removing
* the ReturnedRow
*/
protected ActionListener remover;
/**
* the listener that will reaspond to event by moving the ReturnedRow
* to the ParameterRowTab
*/
protected ActionListener mover;
/**
* the returned data
*/
protected ReturnedDataInterface returnedData;
/**
* the type of the paramter
*/
protected JLabel type;
/**
* the name of the parameter
*/
protected JTextField descriptiveName;
/**
* hashcode of the value
*/
protected int valueHashcode;
/**
* This component will be reasponsible for displaying the
* value of the ReturnedData.
*/
protected JComponent value;
/**
* indicates selection on the components of the row
*/
protected static Border lowered = BorderFactory.createLoweredBevelBorder();
/**
* indicates non-selection on the components of the row
*/
protected static Border raised = BorderFactory.createRaisedBevelBorder();
/**
* This class listens for button clicks on the "Move to Test Data Items" button of the
* Returned Objects tab of the Object Pool.
*/
protected class MoveListener implements ActionListener
{
/**
* moves the returned data item to the test data item tab
*
* Pre-conditions: the MoveListener has been triggered
* Post-conditions: the returned object is gone; a new test data item is in the pool
* @param evt the ActionEvent
*/
public void actionPerformed(ActionEvent evt)
{
// CALL getBorder on the JLabel
// IF returned border equals lowered
// CALL move on ReturnedDataInterface
// ENDIF
if (type.getBorder() == lowered)
{
returnedData.move();
}
}
}
/**
* This class listens for button clicks on the remove button.
*/
protected class RemoveListener implements ActionListener
{
/**
* removes the parameter data from the object pool
*
* Pre-conditions: the RemoveListener has been triggered
* Post-conditions: none
* @param evt the ActionEvent
*/
public void actionPerformed(ActionEvent evt)
{
// CALL getBorder on the JLabel
// IF returned border equals lowered
// CALL remove on ReturnedDataInterface
// ENDIF
if (type.getBorder() == lowered)
{
returnedData.remove();
}
}
}
/**
* This class listens for button clicks on the inspect button.
*/
protected class InspectObjectValueListener implements ActionListener
{
/**
* inspects the object
*
* Pre-conditions: the InspectObjectValueListener has been triggered
* Post-conditions: none
* @param evt the ActionEvent
*/
public void actionPerformed(ActionEvent evt)
{
// CALL inspectObjectValue on returnedData
returnedData.inspectObjectValue();
}
}
/**
* This class listens for when the user clicks on any component of the row.
*/
protected class SelectedListener extends MouseAdapter
{
/**
* it toggles the selection of the components
*
* Pre-conditions: the SelectedListener has been triggered
* Post-conditions: none
* @param evt the MouseEvent
*/
public void mouseClicked(MouseEvent evt)
{
// CALL getBorder on type
// IF returned Border equals lowered
// SET returned Border on all components with raised
// ELSE
// SET returned Border on all components with lowered
// ENDIF
setSelected(type.getBorder() != lowered);
}
}
}