KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > calendar > widget > DayItem


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19  
20 package org.lucane.applications.calendar.widget;
21
22 import java.awt.*;
23 import java.awt.event.MouseListener JavaDoc;
24
25 import javax.swing.*;
26
27
28 /**
29  * A day item for the MonthView
30  */

31 public class DayItem extends JPanel
32 {
33     //-- colors constants
34
public static Color EVENT_COLOR = new Color(200, 100, 50);
35
36     private String JavaDoc dayOfMonth;
37     
38     /**
39      * Constructor
40      *
41      * @param dayOfMonth the day of month for this day item
42      */

43     public DayItem(String JavaDoc dayOfMonth)
44     {
45         super(new GridLayout(0, 1));
46         this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
47         this.setBackground(Color.WHITE);
48         this.setOpaque(true);
49         this.dayOfMonth = dayOfMonth;
50         
51         JLabel label = new JLabel(dayOfMonth);
52         label.setHorizontalAlignment(SwingConstants.RIGHT);
53         label.setVerticalAlignment(SwingConstants.TOP);
54         this.add(label);
55     }
56     
57     /**
58      * Reinit the DayItem.
59      * remove all events and reset the day of month
60      *
61      * @param dayOfMonth the day of month for this day item
62      */

63     public void reset(String JavaDoc dayOfMonth)
64     {
65         this.removeAll();
66         this.dayOfMonth = dayOfMonth;
67         
68         JLabel label = new JLabel(dayOfMonth);
69         label.setHorizontalAlignment(SwingConstants.RIGHT);
70         label.setVerticalAlignment(SwingConstants.TOP);
71         this.add(label);
72     }
73     
74     /**
75      * Add an event to this DayItem
76      *
77      * @param event the event to add
78      * @param listener the mouse listener to add on the event label
79      */

80     public void addEvent(BasicEvent event, MouseListener JavaDoc listener)
81     {
82         EventLabel label = new EventLabel(event);
83         label.addMouseListener(listener);
84         this.add(label);
85     }
86
87     /**
88      * Sets the current day
89      *
90      * @param current true if this item is the current day
91      */

92     public void setCurrentDay(boolean current)
93     {
94         if(current)
95             setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
96         else
97             setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
98     }
99     
100     public int getDayOfMonth()
101     {
102         if(dayOfMonth.length() > 0)
103             return Integer.parseInt(dayOfMonth);
104         return -1;
105     }
106 }
Popular Tags