PageRenderTime 39ms CodeModel.GetById 30ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/ui/panels/calendar/ScheduleCalendarButton.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 99 lines | 64 code | 13 blank | 22 comment | 6 complexity | b2b3531ac13447dccf8417d58c6ff4f4 MD5 | raw file
 1/*
 2 *  This file is part of YaBS.
 3 *
 4 *      YaBS is free software: you can redistribute it and/or modify
 5 *      it under the terms of the GNU General Public License as published by
 6 *      the Free Software Foundation, either version 3 of the License, or
 7 *      (at your option) any later version.
 8 *
 9 *      YaBS is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *      You should have received a copy of the GNU General Public License
15 *      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package mpv5.ui.panels.calendar;
18
19import java.awt.Color;
20import java.awt.Font;
21import java.awt.event.ActionEvent;
22import java.awt.event.ActionListener;
23import java.util.ArrayList;
24import java.util.Date;
25import javax.swing.JButton;
26import mpv5.db.objects.Schedule;
27import mpv5.globals.Messages;
28import mpv5.ui.panels.ScheduleDayEventsPanel;
29
30public class ScheduleCalendarButton extends JButton implements ActionListener {
31
32    private static final long serialVersionUID = 1L;
33    private Date date;
34    private ArrayList<Schedule> scheduledEvents = new ArrayList<Schedule>();
35
36    protected ScheduleCalendarButton(Date d) {
37        super("");
38        this.date = d;
39    }
40
41    /**
42     * @return the date
43     */
44    protected Date getDate() {
45        return date;
46    }
47
48    /**
49     * @param date the date to set
50     */
51    protected void setDate(Date date) {
52        this.date = date;
53    }
54
55    protected void addScheduledEvent(Schedule schedule) {
56        scheduledEvents.add(schedule);
57        this.setFont(this.getFont().deriveFont(Font.BOLD));
58        this.setBackground(Color.GREEN);
59
60        if (scheduledEvents.isEmpty() == false) {
61            this.setToolTipText(Messages.DAY_EVENTS.toString());
62        }
63    }
64
65    protected void removeScheduledEvent(Schedule schedule) {
66        scheduledEvents.remove(schedule);
67        if (scheduledEvents.isEmpty() == true) {
68            this.setFont(this.getFont().deriveFont(Font.PLAIN));
69            this.setBackground(Color.LIGHT_GRAY);
70            this.setToolTipText(Messages.DAY_EVENTS.toString());
71        }
72    }
73
74    protected void clearScheduledEvents() {
75        scheduledEvents.clear();
76        this.setFont(this.getFont().deriveFont(Font.PLAIN));
77        this.setBackground(Color.LIGHT_GRAY);
78    }
79
80    public void actionPerformed(ActionEvent e) {
81        JButton button = (JButton) e.getSource();
82        String buttonText = button.getText();
83        int dayInt = new Integer(buttonText).intValue();
84        ScheduleCalendarDayChooser.instanceOf().setDay(dayInt);
85        ScheduleDayEventsPanel.instanceOf().setDayEvents(scheduledEvents);
86    }
87
88    protected boolean hasEvents() {
89        if (scheduledEvents.isEmpty()) {
90            return false;
91        } else {
92            return true;
93        }
94    }
95
96    public ArrayList<Schedule> getScheduledEvents() {
97        return scheduledEvents;
98    }
99}