jimm.datavision.gui
Class FieldWidget

java.lang.Object
  extended by jimm.datavision.gui.FieldWidget
All Implemented Interfaces:
java.awt.dnd.DropTargetListener, java.awt.event.ActionListener, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, java.util.Observer, javax.swing.event.MouseInputListener
Direct Known Subclasses:
EditWinWidget, ImageFieldWidget, TextFieldWidget

public class FieldWidget
extends java.lang.Object
implements javax.swing.event.MouseInputListener, java.awt.dnd.DropTargetListener, java.awt.event.ActionListener, java.awt.event.KeyListener, java.util.Observer

A field widget is the visual representation of a text-based report field.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  int action
           
protected static int ACTION_INACTION
           
protected static int ACTION_MOVE
           
protected static int ACTION_POPPING_UP_MENU
           
protected static int ACTION_STRETCH_BOTTOM
           
protected static int ACTION_STRETCH_LEFT
           
protected static int ACTION_STRETCH_RIGHT
           
protected static int ACTION_STRETCH_TOP
           
protected  boolean actionStartedYet
           
protected  javax.swing.JMenuItem aggregatesMenuItem
           
protected  javax.swing.JMenu alignSubmenu
           
protected static java.util.HashMap componentMap
           
protected  javax.swing.JMenuItem formatMenuItem
           
protected static int GRAB_EDGE_WIDTH
           
protected static int MIN_SIZE
          Minimum field with and height.
protected  boolean mouseChangedSelectedState
           
protected  javax.swing.JMenuItem nameItem
           
protected  javax.swing.JPopupMenu popup
           
protected static java.awt.Font POPUP_FONT
           
protected  PreMoveInfo preMoveInfo
           
protected  PreStretchInfo preStretchInfo
           
protected  SectionWidget sectionWidget
           
protected  boolean selected
           
protected  javax.swing.JMenuItem showOrHide
           
protected  javax.swing.JMenu sizeSubmenu
           
protected  AbstractSwingField swingField
           
 
Constructor Summary
protected FieldWidget(SectionWidget sw, AbstractSwingField asf)
          Constructor.
  FieldWidget(SectionWidget sw, Field field)
          Constructor.
 
Method Summary
protected  int actionFromPosition(java.awt.event.MouseEvent e)
          Given a mouse event, returns the ACTION_* constant associated with the mouse position within the field.
 void actionPerformed(java.awt.event.ActionEvent e)
          Performs some action based on the action command string (the menu item text).
protected  void addCustomPopupItems()
          This hook lets subclasses customize the popup menu.
 void align(int which, Field prototype)
          Align this field in relation to prototype.
protected  void buildPopupMenu()
          Builds the popup menu.
protected  void cursorForPosition(java.awt.event.MouseEvent e)
          If this field is selected, sets the cursor based on the current mouse position in the widget.
protected  void delete()
          Asks the window delete this field and all selected fields.
 void doDelete()
          Deletes this field from its section.
(package private)  void doDrag(int action, java.awt.Point mouseScreenPos)
          Performs a drag or a stretch.
(package private)  void doSelect(boolean makeSelected)
          Performs whatever is necessary to select or deselct self.
 void doSetVisibility(boolean newVisibility)
          Sets the visiblity of this field.
 void dragEnter(java.awt.dnd.DropTargetDragEvent e)
           
 void dragExit(java.awt.dnd.DropTargetEvent e)
           
 void dragOver(java.awt.dnd.DropTargetDragEvent e)
           
 void drop(java.awt.dnd.DropTargetDropEvent e)
          Handles drop of a dragged field.
 void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
           
protected  void enableMenuItems()
          Enables or disables popup menu items based on field and window state.
protected  void finalize()
           
(package private) static FieldWidget findFieldWidgetOwning(java.lang.Object c)
          Returns the field widget that owns a particular visual component.
(package private)  java.awt.Color getColor()
           
 javax.swing.JComponent getComponent()
           
 Field getField()
           
protected  java.lang.String getPopupNameText()
          Returns string to use for popup menu's first item, the (disabled) name of this field.
 PreMoveInfo getPreMoveInfo()
          Returns the information we saved before starting to move this widget.
 SectionWidget getSectionWidget()
          Returns the section widget containing this field widget.
(package private)  boolean isSelected()
          Returns true if the field is selected.
 void keyPressed(java.awt.event.KeyEvent ke)
           
 void keyReleased(java.awt.event.KeyEvent ke)
           
 void keyTyped(java.awt.event.KeyEvent ke)
           
 void mouseClicked(java.awt.event.MouseEvent e)
          If the user is placing a new text field, pass it on to the section widget; else do nothing.
 void mouseDragged(java.awt.event.MouseEvent e)
          Asks section to drag (move, resize) all selected widgets together.
 void mouseEntered(java.awt.event.MouseEvent e)
          Changes cursor if this widget is selected.
 void mouseExited(java.awt.event.MouseEvent e)
          Changes cursor if this widget is selected.
 void mouseMoved(java.awt.event.MouseEvent e)
          Changes cursor if this widget is selected.
 void mousePressed(java.awt.event.MouseEvent e)
          When the mouse is pressed, do the Right Thing(tm).
protected  boolean mousePressReleaseCommon(java.awt.event.MouseEvent e)
          Performs checks and behaviors common to both mouse presses and mouse release events.
 void mouseReleased(java.awt.event.MouseEvent e)
          When the mouse is released and we have been dragging this field, drop this one and all others that are being dragged.
 void moveToSection(SectionWidget sw)
          Moves both field view and model to a new section.
 void pickUp(java.awt.Point mouseScreenPos)
          Prepares for movement by remembering where we are now and removing ourself from the section view widget (but not the section model).
 void putDown(SectionWidget sw)
          Place this field into a section widget.
protected  void resetCursor()
          Resets the cursor to its default.
(package private)  void select(boolean deselectOthers)
          Selects this field.
protected  void setVisibilityLook()
          Sets the look of the field based on the current visiblity flag value.
protected  void showPopupMenu(java.awt.event.MouseEvent e)
          Displays popup menu, after enabling/disabling the appropriate items.
 void size(int which, Field prototype)
          Resize this field in relation to prototype.
(package private)  void snapBack()
          Move back to original location in original section widget.
 void startStretching(java.awt.Point mouseScreenPos)
          Prepares for stretching by creating a PreStretchInfo.
 void stopStretching()
          Stop stretching.
(package private)  void toggleVisibility()
          Toggles the visiblity of this field and all selected fields.
 java.lang.String toString()
           
 void update(java.util.Observable obj, java.lang.Object arg)
           
 boolean usesFormat()
          Returns true if this field can be formatted.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GRAB_EDGE_WIDTH

protected static final int GRAB_EDGE_WIDTH
See Also:
Constant Field Values

ACTION_INACTION

protected static final int ACTION_INACTION
See Also:
Constant Field Values

ACTION_MOVE

protected static final int ACTION_MOVE
See Also:
Constant Field Values

ACTION_STRETCH_LEFT

protected static final int ACTION_STRETCH_LEFT
See Also:
Constant Field Values

ACTION_STRETCH_RIGHT

protected static final int ACTION_STRETCH_RIGHT
See Also:
Constant Field Values

ACTION_STRETCH_TOP

protected static final int ACTION_STRETCH_TOP
See Also:
Constant Field Values

ACTION_STRETCH_BOTTOM

protected static final int ACTION_STRETCH_BOTTOM
See Also:
Constant Field Values

ACTION_POPPING_UP_MENU

protected static final int ACTION_POPPING_UP_MENU
See Also:
Constant Field Values

MIN_SIZE

protected static final int MIN_SIZE
Minimum field with and height.

See Also:
Constant Field Values

POPUP_FONT

protected static final java.awt.Font POPUP_FONT

componentMap

protected static java.util.HashMap componentMap

swingField

protected AbstractSwingField swingField

sectionWidget

protected SectionWidget sectionWidget

action

protected int action

actionStartedYet

protected boolean actionStartedYet

selected

protected boolean selected

mouseChangedSelectedState

protected boolean mouseChangedSelectedState

preMoveInfo

protected PreMoveInfo preMoveInfo

preStretchInfo

protected PreStretchInfo preStretchInfo

popup

protected javax.swing.JPopupMenu popup

alignSubmenu

protected javax.swing.JMenu alignSubmenu

sizeSubmenu

protected javax.swing.JMenu sizeSubmenu

nameItem

protected javax.swing.JMenuItem nameItem

showOrHide

protected javax.swing.JMenuItem showOrHide

formatMenuItem

protected javax.swing.JMenuItem formatMenuItem

aggregatesMenuItem

protected javax.swing.JMenuItem aggregatesMenuItem
Constructor Detail

FieldWidget

public FieldWidget(SectionWidget sw,
                   Field field)
Constructor.

Parameters:
sw - section widget in which the field's new widget will reside
field - a report field

FieldWidget

protected FieldWidget(SectionWidget sw,
                      AbstractSwingField asf)
Constructor.

Parameters:
sw - section widget in which the field's new widget will reside
asf - an abstract swing field
Method Detail

findFieldWidgetOwning

static FieldWidget findFieldWidgetOwning(java.lang.Object c)
Returns the field widget that owns a particular visual component.

Returns:
a field widget or null

buildPopupMenu

protected void buildPopupMenu()
Builds the popup menu.


addCustomPopupItems

protected void addCustomPopupItems()
This hook lets subclasses customize the popup menu. By default, nothing happens.


finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

update

public void update(java.util.Observable obj,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

usesFormat

public boolean usesFormat()
Returns true if this field can be formatted.

Returns:
true if this field can be formatted

getPopupNameText

protected java.lang.String getPopupNameText()
Returns string to use for popup menu's first item, the (disabled) name of this field.


getSectionWidget

public SectionWidget getSectionWidget()
Returns the section widget containing this field widget.

Returns:
the section widget containing this field widget

isSelected

boolean isSelected()
Returns true if the field is selected.

Returns:
true if the field is selected

align

public void align(int which,
                  Field prototype)
Align this field in relation to prototype.

Parameters:
which - one of the Designer.ALIGN_* constants
prototype - the field to which this one should be aligned

size

public void size(int which,
                 Field prototype)
Resize this field in relation to prototype.

Parameters:
which - one of the Designer.SIZE_SAME_* constants
prototype - the field from which this one should take sizes

select

void select(boolean deselectOthers)
Selects this field. If the shift key is down (we don't want to deselect other fields), toggles the selection state instead. If deselectOthers is true, do so. Eventually doSelect(boolean) will be called.

Parameters:
deselectOthers - if true, do so

doSelect

void doSelect(boolean makeSelected)
Performs whatever is necessary to select or deselct self. Called by Designer.select(jimm.datavision.gui.FieldWidget, boolean, boolean).

Parameters:
makeSelected - new selection state

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
If the user is placing a new text field, pass it on to the section widget; else do nothing.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - mousevent

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Asks section to drag (move, resize) all selected widgets together. (The section, in turn, asks the window to do the same.)

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Changes cursor if this widget is selected.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Changes cursor if this widget is selected.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Changes cursor if this widget is selected.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - mouse event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
When the mouse is pressed, do the Right Thing(tm). Handles popup menu, selecting, shift-selecting, and prepping for movement.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
When the mouse is released and we have been dragging this field, drop this one and all others that are being dragged.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mousePressReleaseCommon

protected boolean mousePressReleaseCommon(java.awt.event.MouseEvent e)
Performs checks and behaviors common to both mouse presses and mouse release events. Returns true if the event was handled by this method and should be ignored by the caller.

Parameters:
e - the mouse event
Returns:
true if the event was handled by this method and should be ignored by the caller

getPreMoveInfo

public PreMoveInfo getPreMoveInfo()
Returns the information we saved before starting to move this widget.

Returns:
an object containing the information we saved before starting to move this widget

pickUp

public void pickUp(java.awt.Point mouseScreenPos)
Prepares for movement by remembering where we are now and removing ourself from the section view widget (but not the section model).


putDown

public void putDown(SectionWidget sw)
Place this field into a section widget. Our bounds rectangle is in window coordinates; translate to section coordinates.


snapBack

void snapBack()
Move back to original location in original section widget.


startStretching

public void startStretching(java.awt.Point mouseScreenPos)
Prepares for stretching by creating a PreStretchInfo.

Parameters:
mouseScreenPos - the location of the mouse in screen coordinates

stopStretching

public void stopStretching()
Stop stretching.


showPopupMenu

protected void showPopupMenu(java.awt.event.MouseEvent e)
Displays popup menu, after enabling/disabling the appropriate items.


enableMenuItems

protected void enableMenuItems()
Enables or disables popup menu items based on field and window state.


actionFromPosition

protected int actionFromPosition(java.awt.event.MouseEvent e)
Given a mouse event, returns the ACTION_* constant associated with the mouse position within the field.


cursorForPosition

protected void cursorForPosition(java.awt.event.MouseEvent e)
If this field is selected, sets the cursor based on the current mouse position in the widget. If the field is unselected, resets the cursor.

Parameters:
e - a mouse event

resetCursor

protected void resetCursor()
Resets the cursor to its default.


doDrag

void doDrag(int action,
            java.awt.Point mouseScreenPos)
Performs a drag or a stretch. Called from Designer.dragSelectedWidgets(int, java.awt.Point).

Parameters:
action - a ACTION_* constant
mouseScreenPos - the location of the mouse in screen coordinates
See Also:
Designer.dragSelectedWidgets(int, java.awt.Point)

delete

protected void delete()
Asks the window delete this field and all selected fields.


doDelete

public void doDelete()
Deletes this field from its section. Deletes the report field from the report section (the model) and the field widget from the parent widget (the view/controller).


moveToSection

public void moveToSection(SectionWidget sw)
Moves both field view and model to a new section. Technically, moves model to a new section and adds view to section widget.

Parameters:
sw - a section widget

drop

public void drop(java.awt.dnd.DropTargetDropEvent e)
Handles drop of a dragged field. Passes request on to parent view.

Specified by:
drop in interface java.awt.dnd.DropTargetListener
Parameters:
e - drop event
See Also:
SectionFieldPanel.drop(java.awt.dnd.DropTargetDropEvent)

dragEnter

public void dragEnter(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dragEnter in interface java.awt.dnd.DropTargetListener

dragExit

public void dragExit(java.awt.dnd.DropTargetEvent e)
Specified by:
dragExit in interface java.awt.dnd.DropTargetListener

dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dragOver in interface java.awt.dnd.DropTargetListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dropActionChanged in interface java.awt.dnd.DropTargetListener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Performs some action based on the action command string (the menu item text).

Specified by:
actionPerformed in interface java.awt.event.ActionListener

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toggleVisibility

void toggleVisibility()
Toggles the visiblity of this field and all selected fields.


doSetVisibility

public void doSetVisibility(boolean newVisibility)
Sets the visiblity of this field. Called directly and/or indirectly from toggleVisibility.


setVisibilityLook

protected void setVisibilityLook()
Sets the look of the field based on the current visiblity flag value. The AbstractSwingField does all the work. We just ask our swingField to re-format itself.


getColor

java.awt.Color getColor()

getField

public Field getField()

getComponent

public javax.swing.JComponent getComponent()

keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent ke)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent ke)
Specified by:
keyReleased in interface java.awt.event.KeyListener