edu.cmu.hcii.calo.view.EditableLabelListener Class Reference

List of all members.

Detailed Description

A listener class that synchronizes a clickable label "viewer" with a text field "editor".

This allows the creation of a control that appears as a simple label until clicked, at which point it becomes editable. This class also provides a mouseover and cursor affordance when the user hovers over the label.

To use this class, first ensure that the "viewer" (label) is visible and that the "editor" (text field) is not. Then create an EditableLabelListener for the viewer and editor. It is not necessary to attach this class as a listener to either the viewer or the editor, as this is done automatically in the constructor.

Warning:
To restate the above: it is NOT necessary to explicitly attach instances of this class as a listener to any control. Where by "it is not necessary", we mean "it will make strange things happen, so don't do it". This class only derives from listener classes and interfaces because it needs to attach itself, and Java doesn't believe in private inheritance.
Author:
Brian Ellis


Public Member Functions

 EditableLabelListener (Component parent, JLabel viewer, JTextField editor)
 Constructs an EditableLabelListener with the given parent, viewer, and editor components.
void actionPerformed (ActionEvent e)
 Called when the user hits the return key inside the text field.
void focusGained (FocusEvent e)
 Does nothing when the focus is gained.
void focusLost (FocusEvent e)
 Replaces the editor with the viewer when the focus of the editor is lost.
void mouseClicked (MouseEvent e)
 Replaces the viewer with the editor when the mouse is clicked in the viewer.
void mouseEntered (MouseEvent e)
 Displays a mouseover border on the viewer when the mouse is moved into it.
void mouseExited (MouseEvent e)
 Removes the mouseover border from the viewer when the mouse is moved off of it.

Static Public Attributes

Borders
Border styles for the label.

static final EmptyBorder NORMAL_LABEL_BORDER = new EmptyBorder(3, 3, 3, 3)
 The normal label border, which is just empty with the same insets as the text field.
static final CompoundBorder MOUSEOVER_LABEL_BORDER
 The mouseover label border, which draws a translucent black line around the edge of the label.

Protected Member Functions

String fieldTransform (String fieldText)
 Returns the string that should be transferred to the viewer component when the editor component is done being edited.
String labelTransform (String labelText)
 Returns the string that should be transferred from the viewer component to the editor component when the editor component is shown.

Private Attributes

Component parent
 The component that contains the viewer and editor.
JLabel viewer
 The viewer component.
JTextField editor
 The editor component.


Constructor & Destructor Documentation

edu.cmu.hcii.calo.view.EditableLabelListener.EditableLabelListener ( Component  parent,
JLabel  viewer,
JTextField  editor 
)

Constructs an EditableLabelListener with the given parent, viewer, and editor components.

The viewer must be a JLabel, and the editor must be a JTextField. The parent is only necessary to determine whether the interaction should be enabled.

Parameters:
parent the parent component of the editor and viewer
viewer the viewer component
editor the editor component


Member Function Documentation

void edu.cmu.hcii.calo.view.EditableLabelListener.actionPerformed ( ActionEvent  e  ) 

Called when the user hits the return key inside the text field.

Parameters:
e the action event

String edu.cmu.hcii.calo.view.EditableLabelListener.fieldTransform ( String  fieldText  )  [protected]

Returns the string that should be transferred to the viewer component when the editor component is done being edited.

This is implemented simply to return the contents of the editor, but subclasses can override it to define custom behavior (like changing the empty string into a placeholder for the label).

Parameters:
fieldText the text that was placed into the editor
Returns:
the text that should be shown in the viewer

void edu.cmu.hcii.calo.view.EditableLabelListener.focusGained ( FocusEvent  e  ) 

Does nothing when the focus is gained.

Parameters:
e the focus event
See also:
java.awt.event.FocusListener.focusGained(java.awt.event.FocusEvent)

void edu.cmu.hcii.calo.view.EditableLabelListener.focusLost ( FocusEvent  e  ) 

Replaces the editor with the viewer when the focus of the editor is lost.

Parameters:
e the focus event

String edu.cmu.hcii.calo.view.EditableLabelListener.labelTransform ( String  labelText  )  [protected]

Returns the string that should be transferred from the viewer component to the editor component when the editor component is shown.

This is implemented simply to return the contents of the viewer, but subclasses can override it to define custom behavior (like changing some placeholder into the empty string for the purposes of editing).

Parameters:
labelText the text that is being shown in the viewer
Returns:
the text that should be placed into the editor

void edu.cmu.hcii.calo.view.EditableLabelListener.mouseClicked ( MouseEvent  e  ) 

Replaces the viewer with the editor when the mouse is clicked in the viewer.

Parameters:
e the mouse event

void edu.cmu.hcii.calo.view.EditableLabelListener.mouseEntered ( MouseEvent  e  ) 

Displays a mouseover border on the viewer when the mouse is moved into it.

Parameters:
e the mouse event

void edu.cmu.hcii.calo.view.EditableLabelListener.mouseExited ( MouseEvent  e  ) 

Removes the mouseover border from the viewer when the mouse is moved off of it.

Parameters:
e the mouse event


Member Data Documentation

final EmptyBorder edu.cmu.hcii.calo.view.EditableLabelListener.NORMAL_LABEL_BORDER = new EmptyBorder(3, 3, 3, 3) [static]

The normal label border, which is just empty with the same insets as the text field.

final CompoundBorder edu.cmu.hcii.calo.view.EditableLabelListener.MOUSEOVER_LABEL_BORDER [static]

Initial value:

        new CompoundBorder(new LineBorder(new Color(0f, 0f, 0f, 0.5f)), new EmptyBorder(2, 2, 2, 2))
The mouseover label border, which draws a translucent black line around the edge of the label.

Component edu.cmu.hcii.calo.view.EditableLabelListener.parent [private]

The component that contains the viewer and editor.

JLabel edu.cmu.hcii.calo.view.EditableLabelListener.viewer [private]

The viewer component.

JTextField edu.cmu.hcii.calo.view.EditableLabelListener.editor [private]

The editor component.


The documentation for this class was generated from the following file:
Generated on Mon Aug 13 15:06:22 2007 for CALO by  doxygen 1.5.2