org.jbudget.gui.month
Class MonthSelectorPanel

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 org.jbudget.gui.templ.MonthSelectorTemplate
                      extended by org.jbudget.gui.month.MonthSelectorPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class MonthSelectorPanel
extends org.jbudget.gui.templ.MonthSelectorTemplate

A GUI widget for choosing months.

Author:
petrov
See Also:
Serialized Form

Nested Class Summary
static interface MonthSelectorPanel.SelectionListener
           
 
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
private  boolean activateValidMonths
          If true, only valid months can be selected.
private  java.util.Map<javax.swing.JToggleButton,java.lang.Integer> buttonToMonthMap
          A Map of Buttons to month indices
(package private)  java.util.Calendar calendar
           
(package private)  int cMonth
           
(package private)  int cYear
           
private  boolean exclusive
          If true, only one month can be selected.
(package private)  java.util.List<MonthSelectorPanel.SelectionListener> listeners
          A list of components listening for month selections
private  java.util.Map<java.lang.Integer,javax.swing.JToggleButton> monthToButtonMap
          A Map of month indices to buttons
private  java.util.Map<java.lang.Integer,java.util.Set<java.lang.Integer>> selectedMonthsMap
          A Map of selected months.
 
Fields inherited from class org.jbudget.gui.templ.MonthSelectorTemplate
aprilButton, augustButton, decemberButton, februaryButton, januaryButton, julyButton, juneButton, marchButton, mayButton, nextYearButton, novemberButton, octoberButton, prevYearButton, septemberButton, yearButtonsPanel, yearLabel, yearTextField
 
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
MonthSelectorPanel(boolean activateValidMonths)
          Creates a new instance of MonthSelectorPanel
 
Method Summary
 void addSelectionListener(MonthSelectorPanel.SelectionListener listener)
          Adds a Listener
 void clearAllSelections()
          Deselect all months.
 void deselectYear()
          Deselects all months in the year.
 java.util.Map<java.lang.Integer,java.util.Set<java.lang.Integer>> getSelectedMonths()
          Retruns a map that provides a set of selected months for every year.
private  void initializeActions()
          Initializes actions associated with buttons.
 boolean isExclusive()
          Returns true if the the month selector is in the 'exclusive' mode.
 boolean isYearSelected()
          Returns true if all valid months in a current year are selected.
private  void notifyListenersDeselected()
          Notifies all listeners that a month was deselected
private  void notifyListenersSelected()
          Notifies all listeners that a month was selected
private  void notifyYearChanged()
          Notifies all listeners that the selected year has changed.
 void removeSelectionListener(MonthSelectorPanel.SelectionListener listener)
          Removes a Listener
 void selectYear()
          Selects all available months in the currently selected year.
 void setEnabled(boolean enabled)
          Enable/Disable this component.
 void setExclusive(boolean exclusive)
          Changes the value of the 'exclusive' flag.
private  void updateGui()
          synchronizes the widget with the internal state.
protected  void updateSizes()
          sets the preferred component sizes.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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, getHeight, 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, 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, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

activateValidMonths

private final boolean activateValidMonths
If true, only valid months can be selected. Otherwise, only inactive months can be selected.


calendar

java.util.Calendar calendar

cYear

int cYear

cMonth

int cMonth

listeners

java.util.List<MonthSelectorPanel.SelectionListener> listeners
A list of components listening for month selections


monthToButtonMap

private final java.util.Map<java.lang.Integer,javax.swing.JToggleButton> monthToButtonMap
A Map of month indices to buttons


buttonToMonthMap

private final java.util.Map<javax.swing.JToggleButton,java.lang.Integer> buttonToMonthMap
A Map of Buttons to month indices


selectedMonthsMap

private final java.util.Map<java.lang.Integer,java.util.Set<java.lang.Integer>> selectedMonthsMap
A Map of selected months.


exclusive

private boolean exclusive
If true, only one month can be selected.

Constructor Detail

MonthSelectorPanel

public MonthSelectorPanel(boolean activateValidMonths)
Creates a new instance of MonthSelectorPanel

Method Detail

updateGui

private void updateGui()
synchronizes the widget with the internal state. Called whenever the value of cYear is changed.


initializeActions

private void initializeActions()
Initializes actions associated with buttons. Called once from the constructor.


updateSizes

protected void updateSizes()
sets the preferred component sizes.


updateUI

public void updateUI()
Overrides:
updateUI in class javax.swing.JPanel

getSelectedMonths

public java.util.Map<java.lang.Integer,java.util.Set<java.lang.Integer>> getSelectedMonths()
Retruns a map that provides a set of selected months for every year.


setEnabled

public void setEnabled(boolean enabled)
Enable/Disable this component.

Overrides:
setEnabled in class javax.swing.JComponent

setExclusive

public void setExclusive(boolean exclusive)
Changes the value of the 'exclusive' flag. If it is set to True, only one month can be selected.


isExclusive

public boolean isExclusive()
Returns true if the the month selector is in the 'exclusive' mode.


clearAllSelections

public void clearAllSelections()
Deselect all months. Does not notify any listeners that the moths are being deselected.


isYearSelected

public boolean isYearSelected()
Returns true if all valid months in a current year are selected.


selectYear

public void selectYear()
Selects all available months in the currently selected year.


deselectYear

public void deselectYear()
Deselects all months in the year.


notifyListenersSelected

private void notifyListenersSelected()
Notifies all listeners that a month was selected


notifyListenersDeselected

private void notifyListenersDeselected()
Notifies all listeners that a month was deselected


notifyYearChanged

private void notifyYearChanged()
Notifies all listeners that the selected year has changed.


addSelectionListener

public void addSelectionListener(MonthSelectorPanel.SelectionListener listener)
Adds a Listener


removeSelectionListener

public void removeSelectionListener(MonthSelectorPanel.SelectionListener listener)
Removes a Listener