fi.helsinki.cs.gist.timeline
Class GCalendarScrollbar

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--fi.helsinki.cs.gist.timeline.GCalendarScrollbar

public class GCalendarScrollbar
extends javax.swing.JComponent
implements java.awt.event.ComponentListener, java.beans.PropertyChangeListener

GCalendarScrollbar shows a specified time range from calendar. It allows user to modify visible time range and select some part of visible calendar to more detailed views. It itself doesn't show this detailed view, but tells * through GVisibleDaysModel user's selection. In case of GTimeline, GTimeline listens this GVisibleDaysModel and updates it view accordingly.
GCalendarScrollbar offers several different ways to select visible days, and offer possibilities for developers to add extra functionality to it.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected static java.lang.String BUTTON_DOWN_ACTION
          Constant, which can be used to differentiate actions send by scrollbar buttons.
protected static java.lang.String BUTTON_UP_ACTION
          Constant, which can be used to differentiate actions send by scrollbar buttons.
protected  java.util.Calendar calendar
           
protected  int[] colsOfDaysOfWeek
           
protected  int columns
           
protected  int colW
           
protected  int colWRemainder
           
protected  javax.swing.JButton downButtonBottom
           
protected  javax.swing.JButton downButtonTop
           
protected  java.util.Date[][] grid
          Grid of calendar days.
protected  int headerH
           
protected  java.util.Vector monthChangeCells
           
protected  GMonthRange monthRange
           
protected static int NOT_VISIBLE
          Constant that indicates that some day or day of week is not visible.
protected  int rowH
           
protected  int rowHRemainder
           
protected  int rows
           
protected  javax.swing.JLayeredPane scrollArea
           
protected  java.util.Vector scrollAreaLayers
           
protected static int UNDEFINED
           
protected  javax.swing.JButton upButtonBottom
           
protected  javax.swing.JButton upButtonTop
           
 
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
 
Constructor Summary
GCalendarScrollbar(GCalendarModel calendarM, GVisibleDaysModel visibleDaysM, GCalendarEventSelectionModel selectionM)
          Constructs CalendarScrollbar with the given models.
GCalendarScrollbar(GCalendarModel calendarM, GVisibleDaysModel visibleDaysM, GCalendarEventSelectionModel selectionM, GDayNumberRenderer dayNumberRenderer, java.util.Date firstDay, java.util.Date lastDay, int firstVisibleWeekday, int lastVisibleWeekday)
          Constructs CalendarScrollbar with the given initial values.
 
Method Summary
protected  void calculateCellSizes()
          Calculates widths and heights for day cells.
protected  void commonConstructor(GCalendarModel calendarM, GVisibleDaysModel visibleDaysM, GCalendarEventSelectionModel selectionM, GDayNumberRenderer dayNumberRenderer, java.util.Date firstDay, java.util.Date lastDay, int firstVisibleWeekday, int lastVisibleWeekday)
          An implementation of constructor code common to all constructors.
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
          Kun ScrollAreaa muutetaan, niin lasketaan gridin solujen koot uusiksi
 void componentShown(java.awt.event.ComponentEvent e)
           
protected  int countWeeks(java.util.Date first, java.util.Date last)
          Counts weeks between and including given days.
protected  void fillGrid(java.util.Date first, java.util.Date last)
          Maps dates to grid, stores grid points for months changes.
 java.util.Calendar getCalendar()
          Returns the calendar, that CalendarScrollbar uses.
 java.awt.Point getCellAtPoint(java.awt.Point p)
          Returns cell of given graphical point in day grid.
 java.awt.Point getCellOfDay(java.util.Date day)
          Returns cell of given day in day grid.
 int getColumnCount()
          Returns number of columns in day grid.
 int getColumnOfDayOfWeek(int DOW)
          Returns column number for given day of week.
 java.util.Date getDayAtCell(int col, int row)
          Returns day at given cell of day grid.
 java.util.Date getDayAtCell(java.awt.Point cell)
          Returns day at given cell of day grid.
 java.util.Date getDayAtPoint(java.awt.Point p)
          Returns day at given graphical point in day grid.
 int getDayOfWeekOfColumn(int col)
          Returns constant of day of week , which given column represents.
 javax.swing.JComponent getLayerBelow(javax.swing.JComponent layer)
          Returns layer below given layer.
 java.util.Vector getMonthChangeCells()
          Returns those cells of day grid, which represents 1st days of month.
 int getMonthCount()
          Returns number of months visible currently in CalendarScrollbar.
 java.util.Vector getMonthLinePointsOnLeft(javax.swing.JComponent c)
          Returns month lines (on left edge of scrollArea) in given component's coordinates.
 java.util.Vector getMonths()
          Returns months a calendar scrollbar is currently showing.
 java.awt.Rectangle getRectOfCell(int col, int row)
          Returns graphical area of certain cell in day grid.
 java.awt.Rectangle getRectOfCell(java.awt.Point cell)
          Returns graphical area of certain cell in day grid.
 java.awt.Rectangle getRectOfColumnHeader(int col)
           
 java.awt.Rectangle getRectOfDay(java.util.Date day)
          Returns graphical area of certain day in day grid.
 int getRowCount()
          Returns number of rows in day grid.
 java.util.Vector getScrollAreaLayers()
          Returns currently used scroll area layers.
 java.util.Vector getScrollDownButtons()
          Returns referernces to all buttons that acts as scroll down -buttons.
 java.util.Vector getScrollUpButtons()
          Returns referernces to all buttons that acts as scroll up -buttons.
 javax.swing.JComponent getTopMostLayer()
          Returns top layer in scroll area.
protected  void initColumns(int firstWeekday, int lastWeekday)
          Counts columns between and including first and last visible weekday
protected  void initScrollArea(GVisibleDaysModel visibleDaysM, GDayNumberRenderer dayNumberRenderer, GCalendarEventSelectionModel selectionM)
          Sets initial layout and creates layers for scrollarea.
 boolean isFirstMonthFull()
          Returns true, if first day of first visible month of day grid is in grid also.
 boolean isLastMonthFull()
          Returns true, if last day of last visible month of day grid is in grid also.
static void main(java.lang.String[] args)
           
 void propertyChange(java.beans.PropertyChangeEvent e)
           
 void setScrollAreaLayers(java.util.Vector layers)
          Sets and layouts new layers for scroll area.
 void setVisibleRange(java.util.Date firstDay, java.util.Date lastDay, boolean fillWeeks)
          Sets CalendarLayerl to show days between given range.
 java.lang.String toString()
          Returns internal state of CalendarScrollbar as text output.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_VISIBLE

protected static final int NOT_VISIBLE
Constant that indicates that some day or day of week is not visible.

UNDEFINED

protected static final int UNDEFINED

BUTTON_UP_ACTION

protected static final java.lang.String BUTTON_UP_ACTION
Constant, which can be used to differentiate actions send by scrollbar buttons.

BUTTON_DOWN_ACTION

protected static final java.lang.String BUTTON_DOWN_ACTION
Constant, which can be used to differentiate actions send by scrollbar buttons.

monthRange

protected GMonthRange monthRange

upButtonTop

protected javax.swing.JButton upButtonTop

downButtonTop

protected javax.swing.JButton downButtonTop

upButtonBottom

protected javax.swing.JButton upButtonBottom

downButtonBottom

protected javax.swing.JButton downButtonBottom

scrollArea

protected javax.swing.JLayeredPane scrollArea

scrollAreaLayers

protected java.util.Vector scrollAreaLayers

calendar

protected java.util.Calendar calendar

columns

protected int columns

rows

protected int rows

grid

protected java.util.Date[][] grid
Grid of calendar days. Ordering in grid is grid[rows][columns] Each cell in grid contains Date, that it represents java.awt.Point is usually used to point to certain cell. x coordinate refers to grid columns, and y coordinate to rows.

monthChangeCells

protected java.util.Vector monthChangeCells

colW

protected int colW

colWRemainder

protected int colWRemainder

rowH

protected int rowH

rowHRemainder

protected int rowHRemainder

headerH

protected int headerH

colsOfDaysOfWeek

protected int[] colsOfDaysOfWeek
Constructor Detail

GCalendarScrollbar

public GCalendarScrollbar(GCalendarModel calendarM,
                          GVisibleDaysModel visibleDaysM,
                          GCalendarEventSelectionModel selectionM)
Constructs CalendarScrollbar with the given models. Uses default DayNumberRenderer and sets initial visible range to six months period starting from current day.
Parameters:
calendarM - the calendar model
visibleDaysM - the visible days model
selectionM - the calendar event selection model

GCalendarScrollbar

public GCalendarScrollbar(GCalendarModel calendarM,
                          GVisibleDaysModel visibleDaysM,
                          GCalendarEventSelectionModel selectionM,
                          GDayNumberRenderer dayNumberRenderer,
                          java.util.Date firstDay,
                          java.util.Date lastDay,
                          int firstVisibleWeekday,
                          int lastVisibleWeekday)
Constructs CalendarScrollbar with the given initial values.
Parameters:
calendarM - the calendar model
visibleDaysM - the visible days model
selectionM - the calendar event selection model
dayNumberRenderer - the DayNumberRenderer to draw day numbers
firstDay - first visible day in scrollbar
lastDay - last visible day in scrollbar
firstVisibleWeekday - the first weekday shown
lastVisibleWeekday - the last weekday shown
Method Detail

commonConstructor

protected void commonConstructor(GCalendarModel calendarM,
                                 GVisibleDaysModel visibleDaysM,
                                 GCalendarEventSelectionModel selectionM,
                                 GDayNumberRenderer dayNumberRenderer,
                                 java.util.Date firstDay,
                                 java.util.Date lastDay,
                                 int firstVisibleWeekday,
                                 int lastVisibleWeekday)
An implementation of constructor code common to all constructors. Java allows calling of another constructor method only as first statement of constructor code, so this has to be used, if some initialization and default value creation has to be done.

initScrollArea

protected void initScrollArea(GVisibleDaysModel visibleDaysM,
                              GDayNumberRenderer dayNumberRenderer,
                              GCalendarEventSelectionModel selectionM)
Sets initial layout and creates layers for scrollarea.

getScrollUpButtons

public java.util.Vector getScrollUpButtons()
Returns referernces to all buttons that acts as scroll up -buttons. In basic GCalendarScrollbar there's two buttons, above and below the scroll area, for scrolling up.

getScrollDownButtons

public java.util.Vector getScrollDownButtons()
Returns referernces to all buttons that acts as scroll down -buttons. In basic GCalendarScrollbar there's two buttons, above and below the scroll area, for scrolling down.

getColumnCount

public int getColumnCount()
Returns number of columns in day grid.

getRowCount

public int getRowCount()
Returns number of rows in day grid.

getRectOfDay

public java.awt.Rectangle getRectOfDay(java.util.Date day)
Returns graphical area of certain day in day grid. This is the area of cell, which this day belongs.

getRectOfCell

public java.awt.Rectangle getRectOfCell(java.awt.Point cell)
Returns graphical area of certain cell in day grid. Cell is given as java.awt.Point, where x is a column of cell, and y is a row of cell.

getRectOfCell

public java.awt.Rectangle getRectOfCell(int col,
                                        int row)
Returns graphical area of certain cell in day grid.

getRectOfColumnHeader

public java.awt.Rectangle getRectOfColumnHeader(int col)

getCellOfDay

public java.awt.Point getCellOfDay(java.util.Date day)
Returns cell of given day in day grid. Cell is returned as a java.awt.Point where x is for columns, and y for rows.

getCellAtPoint

public java.awt.Point getCellAtPoint(java.awt.Point p)
Returns cell of given graphical point in day grid. Cell is returned as a java.awt.Point where x is for columns, and y for rows.

getDayAtPoint

public java.util.Date getDayAtPoint(java.awt.Point p)
Returns day at given graphical point in day grid. Cell is returned as a java.awt.Point where x is for columns, and y for rows.

getDayAtCell

public java.util.Date getDayAtCell(java.awt.Point cell)
Returns day at given cell of day grid.

getDayAtCell

public java.util.Date getDayAtCell(int col,
                                   int row)
Returns day at given cell of day grid.

getColumnOfDayOfWeek

public int getColumnOfDayOfWeek(int DOW)
Returns column number for given day of week. Day of week should be given as a constant of Calendar object that this GCalendarScrollbar uses. For example calendarScrollbar.getColumnOfDayOfWeek( calendarScrollbar.getCalendar().SUNDAY);

getDayOfWeekOfColumn

public int getDayOfWeekOfColumn(int col)
Returns constant of day of week , which given column represents.

getMonthChangeCells

public java.util.Vector getMonthChangeCells()
Returns those cells of day grid, which represents 1st days of month. Cells are returned as Vector of java.awt.Point s

isFirstMonthFull

public boolean isFirstMonthFull()
Returns true, if first day of first visible month of day grid is in grid also.

isLastMonthFull

public boolean isLastMonthFull()
Returns true, if last day of last visible month of day grid is in grid also.

getMonths

public java.util.Vector getMonths()
Returns months a calendar scrollbar is currently showing. Months are returned as Dates representing first day of month.

getMonthCount

public int getMonthCount()
Returns number of months visible currently in CalendarScrollbar. Also partially shown months are calculated.

getMonthLinePointsOnLeft

public java.util.Vector getMonthLinePointsOnLeft(javax.swing.JComponent c)
Returns month lines (on left edge of scrollArea) in given component's coordinates. x coordinates are always 0, just y matters.
See Also:
GMonthRange

setScrollAreaLayers

public void setScrollAreaLayers(java.util.Vector layers)
Sets and layouts new layers for scroll area. Old layers are removed. If you want to add layer between old layers, use getScrollAreaLayers, insert your layer to returned Vector, and set layers with this method. Layers has to be subcomponents of JComponent.

getScrollAreaLayers

public java.util.Vector getScrollAreaLayers()
Returns currently used scroll area layers. Layers are in same order that they are piled, bottom most layer being the first in Vector.

getCalendar

public java.util.Calendar getCalendar()
Returns the calendar, that CalendarScrollbar uses.

setVisibleRange

public void setVisibleRange(java.util.Date firstDay,
                            java.util.Date lastDay,
                            boolean fillWeeks)
Sets CalendarLayerl to show days between given range.
Parameters:
firstDay - the first day of range to be shown.
lastDay - the last day of range to be shown.
fillWeeks - true, if days outside of given range, but in same weeks with firstDay or lastDay, has to be shown. false, otherwise.

getLayerBelow

public javax.swing.JComponent getLayerBelow(javax.swing.JComponent layer)
Returns layer below given layer. If given component is not layer, or layer is bottom most layer, null is returned.

getTopMostLayer

public javax.swing.JComponent getTopMostLayer()
Returns top layer in scroll area.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Kun ScrollAreaa muutetaan, niin lasketaan gridin solujen koot uusiksi
Specified by:
componentResized in interface java.awt.event.ComponentListener

initColumns

protected void initColumns(int firstWeekday,
                           int lastWeekday)
Counts columns between and including first and last visible weekday

countWeeks

protected int countWeeks(java.util.Date first,
                         java.util.Date last)
Counts weeks between and including given days.

fillGrid

protected void fillGrid(java.util.Date first,
                        java.util.Date last)
Maps dates to grid, stores grid points for months changes.

calculateCellSizes

protected void calculateCellSizes()
Calculates widths and heights for day cells.

toString

public java.lang.String toString()
Returns internal state of CalendarScrollbar as text output. Useful for testing;
Overrides:
toString in class java.awt.Component

main

public static void main(java.lang.String[] args)