KickJava   Java API By Example, From Geeks To Geeks.

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


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.Cursor JavaDoc;
23 import java.text.DateFormat JavaDoc;
24
25 import javax.swing.*;
26
27
28 /**
29  * A label displaying an event
30  */

31 public class EventLabel extends JLabel
32 {
33     private BasicEvent event;
34     
35     /**
36      * Constructor
37      *
38      * @param event the EventItem to display
39      */

40     public EventLabel(BasicEvent event)
41     {
42         super(event.getTitle());
43         this.event = event;
44         this.setBackground(event.getColor());
45         this.setOpaque(true);
46         this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
47         
48         this.setIcon(event.getIcon());
49                 
50         String JavaDoc start = event.getStartHour() + ":" + event.getStartMinute();
51         if(start.length() < 5)
52             start += "0";
53         String JavaDoc end = event.getEndHour() + ":" + event.getEndMinute();
54         if(end.length() < 5)
55             end += "0";
56
57         String JavaDoc tooltip = null;
58         if(event.isMultiDay())
59         {
60             DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.SHORT);
61             start = df.format(event.getStartDate()) + " (" + start + ")";
62             end = df.format(event.getEndDate()) + " (" + end + ")";
63             tooltip = "<b>" + start + " - " + end + "<br>" + event.getTitle() + "</b>";
64         }
65         else
66             tooltip = "<b>[" + start + "-" + end + "] " + event.getTitle() + "</b>";
67         
68         tooltip += event.getDescription();
69         this.setToolTipText("<html>" + tooltip + "</html>");
70                 
71         this.setHorizontalAlignment(SwingConstants.LEFT);
72         this.setVerticalAlignment(SwingConstants.TOP);
73     }
74
75     /**
76      * Get the displayed event
77      *
78      * @return the displayed event
79      */

80     public BasicEvent getEvent()
81     {
82         return this.event;
83     }
84 }
Popular Tags