PageRenderTime 36954ms CodeModel.GetById 48ms RepoModel.GetById 16ms app.codeStats 1ms

/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
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  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. */
  17. package mpv5.ui.panels.calendar;
  18. import java.awt.Color;
  19. import java.awt.Font;
  20. import java.awt.event.ActionEvent;
  21. import java.awt.event.ActionListener;
  22. import java.util.ArrayList;
  23. import java.util.Date;
  24. import javax.swing.JButton;
  25. import mpv5.db.objects.Schedule;
  26. import mpv5.globals.Messages;
  27. import mpv5.ui.panels.ScheduleDayEventsPanel;
  28. public class ScheduleCalendarButton extends JButton implements ActionListener {
  29. private static final long serialVersionUID = 1L;
  30. private Date date;
  31. private ArrayList<Schedule> scheduledEvents = new ArrayList<Schedule>();
  32. protected ScheduleCalendarButton(Date d) {
  33. super("");
  34. this.date = d;
  35. }
  36. /**
  37. * @return the date
  38. */
  39. protected Date getDate() {
  40. return date;
  41. }
  42. /**
  43. * @param date the date to set
  44. */
  45. protected void setDate(Date date) {
  46. this.date = date;
  47. }
  48. protected void addScheduledEvent(Schedule schedule) {
  49. scheduledEvents.add(schedule);
  50. this.setFont(this.getFont().deriveFont(Font.BOLD));
  51. this.setBackground(Color.GREEN);
  52. if (scheduledEvents.isEmpty() == false) {
  53. this.setToolTipText(Messages.DAY_EVENTS.toString());
  54. }
  55. }
  56. protected void removeScheduledEvent(Schedule schedule) {
  57. scheduledEvents.remove(schedule);
  58. if (scheduledEvents.isEmpty() == true) {
  59. this.setFont(this.getFont().deriveFont(Font.PLAIN));
  60. this.setBackground(Color.LIGHT_GRAY);
  61. this.setToolTipText(Messages.DAY_EVENTS.toString());
  62. }
  63. }
  64. protected void clearScheduledEvents() {
  65. scheduledEvents.clear();
  66. this.setFont(this.getFont().deriveFont(Font.PLAIN));
  67. this.setBackground(Color.LIGHT_GRAY);
  68. }
  69. public void actionPerformed(ActionEvent e) {
  70. JButton button = (JButton) e.getSource();
  71. String buttonText = button.getText();
  72. int dayInt = new Integer(buttonText).intValue();
  73. ScheduleCalendarDayChooser.instanceOf().setDay(dayInt);
  74. ScheduleDayEventsPanel.instanceOf().setDayEvents(scheduledEvents);
  75. }
  76. protected boolean hasEvents() {
  77. if (scheduledEvents.isEmpty()) {
  78. return false;
  79. } else {
  80. return true;
  81. }
  82. }
  83. public ArrayList<Schedule> getScheduledEvents() {
  84. return scheduledEvents;
  85. }
  86. }