hysun.util
Class MonthlyCalendar

java.lang.Object
  - java.awt.Component
      - java.awt.Container
          - javax.swing.JComponent
              - hysun.util.MonthlyCalendar

public class MonthlyCalendar
extends javax.swing.JComponent
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Monthly Calendar organized in weeks.

Bean Patterns:

The calendar object is a MouseListener and a MouseMotionListener for itself.

User program shall not install this MouseListener or MouseMotionListener to any other components; otherwise, runtime exception will be thrown.

All implementation of the MouseListener or MouseMotionListener methods are finalized to prevent overriding by subclasses.

User program specify "event handling code" for "date selected event" by overriding the protected void dateSelected() method which is empty implemented in this class.

Field Detail

DEFAULT_HEADER_SYMBOLS

public static final java.lang.String[] DEFAULT_HEADER_SYMBOLS
Default symbols to be displayed for the header

DEFAULT_FONT

public static final java.awt.Font DEFAULT_FONT
Default font to be used

DEFAULT_HEADER_BG

public static final java.awt.Color DEFAULT_HEADER_BG
Default background color of the header

DEFAULT_HEADER_FG

public static final java.awt.Color DEFAULT_HEADER_FG
Default foreground color of the header

DEFAULT_DATE_BG

public static final java.awt.Color DEFAULT_DATE_BG
Default background color of the date

DEFAULT_DATE_FG

public static final java.awt.Color DEFAULT_DATE_FG
Default foreground color of the date

DEFAULT_HIGHLIGHT_BG

public static final java.awt.Color DEFAULT_HIGHLIGHT_BG
Default background color of highlighted date

DEFAULT_HIGHLIGHT_FG

public static final java.awt.Color DEFAULT_HIGHLIGHT_FG
Default foreground color of highlighted date

DEFAULT_CELL_WIDTH

public static final int DEFAULT_CELL_WIDTH
Default cell width. (= 24)

DEFAULT_CELL_HEIGHT

public static final int DEFAULT_CELL_HEIGHT
Default cell height. (=18)
Constructor Detail

MonthlyCalendar

public MonthlyCalendar()
Default constructor
Method Detail

setMouseListeningEnabled

public void setMouseListeningEnabled(boolean b)
Bean method. Once disabled, there will be no highlighting effect and no "date selection event".


getMouseListeningEnabled

public boolean getMouseListeningEnabled()
Bean method.

setYear

public void setYear(int year)
Bean method

getYear

public int getYear()
Bean method

setMonth

public void setMonth(int month)
Bean method

getMonth

public int getMonth()
Bean method

setYearMonth

public void setYearMonth(int year,
                         int month)
Convinent method to set year and month

setYearMonth

public void setYearMonth(java.util.Calendar calendar)
Convinent method to set year and month

setWeekStartOnSunday

public void setWeekStartOnSunday(boolean b)
Bean method

getWeekStartOnSunday

public boolean getWeekStartOnSunday()
Bean method

setHeaderFont

public void setHeaderFont(java.awt.Font font)
Bean method

getHeaderFont

public java.awt.Font getHeaderFont()
Bean method

setDateFont

public void setDateFont(java.awt.Font font)
Bean method

getDateFont

public java.awt.Font getDateFont()
Bean method

setHeaderBackground

public void setHeaderBackground(java.awt.Color c)
Bean method

getHeaderBackground

public java.awt.Color getHeaderBackground()
Bean method

setHeaderForeground

public void setHeaderForeground(java.awt.Color c)
Bean method

getHeaderForeground

public java.awt.Color getHeaderForeground()
Bean method

setDateBackground

public void setDateBackground(java.awt.Color c)
Bean method

getDateBackground

public java.awt.Color getDateBackground()
Bean method

setDateForeground

public void setDateForeground(java.awt.Color c)
Bean method

getDateForeground

public java.awt.Color getDateForeground()
Bean method

setHighlightBackground

public void setHighlightBackground(java.awt.Color c)
Bean method

getHighlightBackground

public java.awt.Color getHighlightBackground()
Bean method

setHighlightForeground

public void setHighlightForeground(java.awt.Color c)
Bean method

getHighlightForeground

public java.awt.Color getHighlightForeground()
Bean method

setCellDimension

public void setCellDimension(java.awt.Dimension d)
Bean method. Note: if headerComponent is set, calling this method will have no effect.

getCellDimension

public java.awt.Dimension getCellDimension()
Bean method

setBorder

public void setBorder(javax.swing.border.Border border)
Override parent class setBorder method to make sure border insets is included.
Overrides:
setBorder in class javax.swing.JComponent

setHeaderComponent

public void setHeaderComponent(javax.swing.JComponent comp)
Bean method. If header component is set, the default header will not display anymore.

getHeaderComponent

public javax.swing.JComponent getHeaderComponent()
Bean method

setPreferredSize

public final void setPreferredSize(java.awt.Dimension d)
This method is blank implemented to disable it. The size of the component is controlled by the cell dimension. Method is finalized to prevent subclass overriding.
Overrides:
setPreferredSize in class javax.swing.JComponent

paintComponent

protected final void paintComponent(java.awt.Graphics g)
Draw the graphics. Method is finalized to prevent subclass overriding.
Overrides:
paintComponent in class javax.swing.JComponent

paintSymbol

public static void paintSymbol(java.awt.Graphics g,
                               java.awt.Font f,
                               java.awt.Color bg,
                               java.awt.Color fg,
                               java.lang.String s,
                               int x,
                               int y,
                               int w,
                               int h)
This will fill a rectangle area specified by x, y, w, h using bg color. If String s is not null, it will also paint the specified String s at the center of the rectangle using the specified font and fg color.

resetHighlight

public void resetHighlight()
Reset highlighted date. Use in combination with repaint().

getSelectedDay

public int getSelectedDay()
Returns only the DAY_OF_MONTH date value

getSelectedDate

public java.util.Calendar getSelectedDate()
Return YEAR+MONTH+DAY_OF_MONTH as a Calendar object

mouseEntered

public final void mouseEntered(java.awt.event.MouseEvent e)
Implementation of MouseListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public final void mouseExited(java.awt.event.MouseEvent e)
Implementation of MouseListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public final void mouseClicked(java.awt.event.MouseEvent e)
Implementation of MouseListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public final void mousePressed(java.awt.event.MouseEvent e)
Implementation of MouseListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public final void mouseReleased(java.awt.event.MouseEvent e)
Implementation of MouseListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseMoved

public final void mouseMoved(java.awt.event.MouseEvent e)
Implementation of MouseMotionListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public final void mouseDragged(java.awt.event.MouseEvent e)
Implementation of MouseMotionListener interface method. User program should ignore this method. Method is finalized to prevent subclass overriding.
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

dateSelected

protected void dateSelected()
This method will be called when the "date selection event" occurs. The implementation of the method is left empty. Subclasses should override this method to specify "event handling code".