jimm.datavision.gui
Class SectionWidget

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by jimm.datavision.gui.SectionWidget
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class SectionWidget
extends javax.swing.JPanel
implements java.awt.event.ActionListener

A section widget is the visual representation of a report section.

Author:
Jim Menard, jimm@io.com
See Also:
Serialized Form

Nested Class Summary
(package private)  class SectionWidget.PopupListener
          An inner class that handles display of the popup menu.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  javax.swing.JMenuItem addGroup
           
protected static java.awt.Font DEFAULT_POPUP_FONT
           
protected  javax.swing.JMenuItem deleteGroup
           
protected  javax.swing.JMenuItem deleteSection
           
protected  Designer designer
           
protected  javax.swing.JMenuItem editSuppress
           
protected  SectionFieldPanel fieldPanel
           
protected  javax.swing.JMenuItem insertSection
           
protected  SectionNameLabel label
           
static int LHS_WIDTH
           
protected  java.lang.String name
           
protected  javax.swing.JMenuItem nameItem
           
(package private) static java.awt.Color NORMAL_COLOR
           
protected  javax.swing.JPopupMenu popup
           
protected  java.lang.String popupName
           
protected  Section section
           
(package private) static java.awt.Color SUPPRESSED_COLOR
           
protected  javax.swing.JCheckBoxMenuItem togglePageBreak
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SectionWidget(Designer win, Section sect, java.lang.String name)
          Constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Performs some action based on the action command string (the menu item text).
 void addField(FieldWidget fw)
          Adds field widget to panel.
 FieldWidget addTitleField(int x, int width, java.lang.String title)
          Passes this request up to the design window.
protected  void buildDisplayName()
          Constructs the section name widget that is displayed to the left of the section.
protected  void buildPopupMenu()
          Builds the popup menu.
(package private)  void createNewTextField(java.awt.event.MouseEvent e)
          Asks design window to create and accepts a new text field.
(package private)  void deselectAll()
          Deselects all fields in all sections.
(package private)  void dragSelectedWidgets(int action, java.awt.Point mouseScreenPos)
          Tells the window to drag (move, resize) all selected fields.
(package private)  void editSuppression()
          Toggles the suppressed flag of the section.
protected  void enablePopupMenuItems()
          Modifies menu items based on the state of the section.
 Designer getDesigner()
          Returns the design window containing this section widget
 SectionFieldPanel getFieldPanel()
           
 int getHeight()
          Returns the height of the section, including the resizer bar.
 int getMinSectionHeight()
          Returns the minimum height the section needs to fit all of its fields.
 int getPaperWidth()
          Returns the width of the report paper (the white part upon which fields are placed).
 Report getReport()
          Returns the report we are representing.
 Section getSection()
          Returns the section we are representing.
 SectionArea getSectionArea()
          Returns the SectionArea of the Section (report header, page footer, etc.)
 int getSectionHeight()
          Returns the height of the report section.
 int getTotalWidth()
          Returns the width of the section, including the left-hand side name.
 void growBy(int dy)
          Resizes the section.
 void growToFit()
          Grows this section widget to the minimum height required.
(package private)  void paperSizeChanged()
          Resizes this widget.
 void performCommand(Command cmd)
          Passes a command up to the design window for execution.
(package private)  void pickUp(java.awt.Point mouseScreenPos)
          Passes on to the design window the request to pick up all selected fields for dragging (not just the specified field).
(package private)  void putDown(FieldWidget f, java.awt.Point origScreenPos, java.awt.Point mouseScreenPos)
          Passes on to the design window the request to put down all fields being dragged (not just the specified field).
 void removeField(FieldWidget fw)
          Removes field widget from panel, but do not change field model's relation with section model.
 void resizeBy(int dy, SectionResizeCommand cmd)
          Grows or shrinks the section widget and executes a command that allows this action to be undone/redone.
(package private)  void select(FieldWidget fieldWidget, boolean makeSelected, boolean deselectOthers)
          Selects or deselcts a field widget, possibly deselecting all others everywhere.
 void setDisplayName(java.lang.String name)
          Set the section display name.
(package private)  void setFieldVisibility(boolean newVisiblity, FieldWidget fw)
          Sets the visibility of all selected fields plus the one passed in.
 void setIgnoreKeys(boolean ignoreKeys)
          Passes responsiblity up to the design window.
 void setPopupName(java.lang.String popupName)
          Set the popup menu name, also displayed as first, disabled menu item.
(package private)  void showPopup(java.awt.event.MouseEvent e)
          Displays popup menu, after enabling and disabling menu items.
 void shrinkToFit()
          Shrinks this section widget to the minimum height required.
(package private)  void snapToGrid(Rectangle r)
          Asks the design window to snap the rectangle to it's grid.
(package private)  void startStretching(java.awt.Point mouseScreenPos)
          Passes on to the design window the request to start stretching all selected fields (not just the specified field).
(package private)  void stopStretching(FieldWidget f, Rectangle origBounds)
          Passes on to the design window the request to stop stretching all fields being stretched (not just the specified field).
(package private)  void togglePageBreak()
          Toggles the page break flag of the section.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LHS_WIDTH

public static final int LHS_WIDTH
See Also:
Constant Field Values

DEFAULT_POPUP_FONT

protected static final java.awt.Font DEFAULT_POPUP_FONT

NORMAL_COLOR

static final java.awt.Color NORMAL_COLOR

SUPPRESSED_COLOR

static final java.awt.Color SUPPRESSED_COLOR

name

protected java.lang.String name

popupName

protected java.lang.String popupName

designer

protected Designer designer

section

protected Section section

label

protected SectionNameLabel label

fieldPanel

protected SectionFieldPanel fieldPanel

popup

protected javax.swing.JPopupMenu popup

nameItem

protected javax.swing.JMenuItem nameItem

editSuppress

protected javax.swing.JMenuItem editSuppress

togglePageBreak

protected javax.swing.JCheckBoxMenuItem togglePageBreak

deleteGroup

protected javax.swing.JMenuItem deleteGroup

addGroup

protected javax.swing.JMenuItem addGroup

deleteSection

protected javax.swing.JMenuItem deleteSection

insertSection

protected javax.swing.JMenuItem insertSection
Constructor Detail

SectionWidget

public SectionWidget(Designer win,
                     Section sect,
                     java.lang.String name)
Constructor.

Parameters:
win - parent design window
sect - the report section
name - a name such as "Report Header (a)"
Method Detail

buildPopupMenu

protected void buildPopupMenu()
Builds the popup menu.


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

enablePopupMenuItems

protected void enablePopupMenuItems()
Modifies menu items based on the state of the section.


buildDisplayName

protected void buildDisplayName()
Constructs the section name widget that is displayed to the left of the section.


setDisplayName

public void setDisplayName(java.lang.String name)
Set the section display name.

Parameters:
name - the new name

setPopupName

public void setPopupName(java.lang.String popupName)
Set the popup menu name, also displayed as first, disabled menu item.

Parameters:
popupName - the new name

getReport

public Report getReport()
Returns the report we are representing.

Returns:
a report

getSection

public Section getSection()
Returns the section we are representing.

Returns:
a report section

getSectionArea

public SectionArea getSectionArea()
Returns the SectionArea of the Section (report header, page footer, etc.)

Returns:
the section's SectionArea

getDesigner

public Designer getDesigner()
Returns the design window containing this section widget

Returns:
a design window

getPaperWidth

public int getPaperWidth()
Returns the width of the report paper (the white part upon which fields are placed).

Returns:
the paper width

getTotalWidth

public int getTotalWidth()
Returns the width of the section, including the left-hand side name.

Returns:
the total width

getHeight

public int getHeight()
Returns the height of the section, including the resizer bar.

Overrides:
getHeight in class javax.swing.JComponent
Returns:
the total height

getSectionHeight

public int getSectionHeight()
Returns the height of the report section.

Returns:
report section height

getMinSectionHeight

public int getMinSectionHeight()
Returns the minimum height the section needs to fit all of its fields.

Returns:
minimum height

paperSizeChanged

void paperSizeChanged()
Resizes this widget. Called by the design window whenever the user selects a new paper size.


editSuppression

void editSuppression()
Toggles the suppressed flag of the section.


togglePageBreak

void togglePageBreak()
Toggles the page break flag of the section.


shrinkToFit

public void shrinkToFit()
Shrinks this section widget to the minimum height required. This method is only called from the popup menu. It should not be called as part of a larger operation because it creates a command that allows undo/redo.


growToFit

public void growToFit()
Grows this section widget to the minimum height required. This method, unlike shrinkToFit, is always called as part of some other operation.


growBy

public void growBy(int dy)
Resizes the section. Called by resizer bar and by commands that grow sections as a side effect.

Parameters:
dy - delta y

resizeBy

public void resizeBy(int dy,
                     SectionResizeCommand cmd)
Grows or shrinks the section widget and executes a command that allows this action to be undone/redone. Calls growBy(int) to grow or shrink, then lets our window execute the command that remembers the size change for later undo/redo.

The command does not change our height. It remembers the old and new heights for later undo/redo.

Parameters:
dy - delta height
cmd - a section resize command
See Also:
performCommand(jimm.datavision.gui.cmd.Command)

performCommand

public void performCommand(Command cmd)
Passes a command up to the design window for execution.

Parameters:
cmd - a command
See Also:
Designer.performCommand(jimm.datavision.gui.cmd.Command)

setIgnoreKeys

public void setIgnoreKeys(boolean ignoreKeys)
Passes responsiblity up to the design window.

See Also:
Designer.setIgnoreKeys(boolean)

addTitleField

public FieldWidget addTitleField(int x,
                                 int width,
                                 java.lang.String title)
Passes this request up to the design window.

Parameters:
x - where to place the title
width - how wide it should be
title - the string to display
Returns:
the newly-created widget
See Also:
Designer.addTitleField(int, int, java.lang.String)

pickUp

void pickUp(java.awt.Point mouseScreenPos)
Passes on to the design window the request to pick up all selected fields for dragging (not just the specified field). Called from FieldWidget.mousePressed(java.awt.event.MouseEvent).

Parameters:
mouseScreenPos - the location of the mouse in screen coordinates
See Also:
Designer.pickUp(java.awt.Point)

putDown

void putDown(FieldWidget f,
             java.awt.Point origScreenPos,
             java.awt.Point mouseScreenPos)
Passes on to the design window the request to put down all fields being dragged (not just the specified field). Called from FieldWidget.mouseReleased(java.awt.event.MouseEvent).

Parameters:
f - the field in which the mouse has been clicked
origScreenPos - the original location of the field in screen coordinates
mouseScreenPos - the location of the mouse in screen coordinates
See Also:
Designer.putDown(jimm.datavision.gui.FieldWidget, java.awt.Point, java.awt.Point)

startStretching

void startStretching(java.awt.Point mouseScreenPos)
Passes on to the design window the request to start stretching all selected fields (not just the specified field). Called from FieldWidget.mousePressed(java.awt.event.MouseEvent).

Parameters:
mouseScreenPos - the location of the mouse in screen coordinates
See Also:
Designer.startStretching(java.awt.Point)

stopStretching

void stopStretching(FieldWidget f,
                    Rectangle origBounds)
Passes on to the design window the request to stop stretching all fields being stretched (not just the specified field). Called from FieldWidget.mouseReleased(java.awt.event.MouseEvent).

Parameters:
f - the field in which the mouse has been clicked
origBounds - the field's original bounds
See Also:
Designer.putDown(jimm.datavision.gui.FieldWidget, java.awt.Point, java.awt.Point)

dragSelectedWidgets

void dragSelectedWidgets(int action,
                         java.awt.Point mouseScreenPos)
Tells the window to drag (move, resize) all selected fields. Called from one field widget when it's being manipulated with the mouse.

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

select

void select(FieldWidget fieldWidget,
            boolean makeSelected,
            boolean deselectOthers)
Selects or deselcts a field widget, possibly deselecting all others everywhere. Called from field widget itself, this passes the request on to the design window.

Parameters:
fieldWidget - a field widget
makeSelected - if true, select this field; else deselect it
deselectOthers - if true, all other fields in all sections are deselected first
See Also:
Designer.select(jimm.datavision.gui.FieldWidget, boolean, boolean)

deselectAll

void deselectAll()
Deselects all fields in all sections. Tells the design window to do so.

See Also:
Designer.deselectAll()

addField

public void addField(FieldWidget fw)
Adds field widget to panel. Does not affect models. Field retains its selection state.

Parameters:
fw - field widget to add

removeField

public void removeField(FieldWidget fw)
Removes field widget from panel, but do not change field model's relation with section model. Field retains its selection state.

To delete a field widget completely, see Designer.deleteSelectedFields().

Parameters:
fw - field widget to remove
See Also:
addField(jimm.datavision.gui.FieldWidget)

getFieldPanel

public SectionFieldPanel getFieldPanel()

snapToGrid

void snapToGrid(Rectangle r)
Asks the design window to snap the rectangle to it's grid.

Parameters:
r - a rectangle

setFieldVisibility

void setFieldVisibility(boolean newVisiblity,
                        FieldWidget fw)
Sets the visibility of all selected fields plus the one passed in. Passes the buck to the design window.

See Also:
FieldWidget.toggleVisibility(), Designer.setFieldVisibility(boolean, jimm.datavision.gui.FieldWidget)

createNewTextField

void createNewTextField(java.awt.event.MouseEvent e)
Asks design window to create and accepts a new text field.

See Also:
Designer.createNewTextField(jimm.datavision.gui.SectionWidget, java.awt.event.MouseEvent)

showPopup

void showPopup(java.awt.event.MouseEvent e)
Displays popup menu, after enabling and disabling menu items.

Parameters:
e - mouse event that caused popup to do its thing