PageRenderTime 29ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 149 lines | 56 code | 17 blank | 76 comment | 2 complexity | 5631915e27d23209a2a61e5f3f4b190b 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. * JYearChooser.java - A bean for choosing a year
  3. * Copyright (C) 2004 Kai Toedter
  4. * kai@toedter.com
  5. * www.toedter.com
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. package mpv5.ui.panels.calendar;
  22. import com.toedter.components.JSpinField;
  23. import java.util.Calendar;
  24. import javax.swing.JFrame;
  25. /**
  26. * JYearChooser is a bean for choosing a year.
  27. *
  28. * @version $LastChangedRevision: 85 $
  29. * @version $LastChangedDate: 2006-04-28 13:50:52 +0200 (Fr, 28 Apr 2006) $
  30. */
  31. public class ScheduleYearChooser extends JSpinField {
  32. private static final long serialVersionUID = 2648810220491090064L;
  33. protected ScheduleCalendarDayChooser dayChooser;
  34. protected int oldYear;
  35. protected int startYear;
  36. protected int endYear;
  37. /**
  38. * Default JCalendar constructor.
  39. */
  40. public ScheduleYearChooser() {
  41. setName("JYearChooser");
  42. Calendar calendar = Calendar.getInstance();
  43. dayChooser = null;
  44. setMinimum(calendar.getMinimum(Calendar.YEAR));
  45. setMaximum(calendar.getMaximum(Calendar.YEAR));
  46. setValue(calendar.get(Calendar.YEAR));
  47. }
  48. /**
  49. * Sets the year. This is a bound property.
  50. *
  51. * @param y the new year
  52. *
  53. * @see #getYear
  54. */
  55. public void setYear(int y) {
  56. super.setValue(y, true, false);
  57. if (dayChooser != null) {
  58. dayChooser.setYear(value);
  59. }
  60. spinner.setValue(new Integer(value));
  61. firePropertyChange("year", oldYear, value);
  62. oldYear = value;
  63. }
  64. /**
  65. * Sets the year value.
  66. *
  67. * @param value the year value
  68. */
  69. @Override
  70. public final void setValue(int value) {
  71. setYear(value);
  72. }
  73. /**
  74. * Returns the year.
  75. *
  76. * @return the year
  77. */
  78. public int getYear() {
  79. return super.getValue();
  80. }
  81. /**
  82. * Convenience method set a day chooser that might be updated directly.
  83. *
  84. * @param dayChooser the day chooser
  85. */
  86. public void setDayChooser(ScheduleCalendarDayChooser dayChooser) {
  87. this.dayChooser = dayChooser;
  88. }
  89. /**
  90. * Returns the endy ear.
  91. *
  92. * @return the end year
  93. */
  94. public int getEndYear() {
  95. return getMaximum();
  96. }
  97. /**
  98. * Sets the end ear.
  99. *
  100. * @param endYear the end year
  101. */
  102. public void setEndYear(int endYear) {
  103. setMaximum(endYear);
  104. }
  105. /**
  106. * Returns the start year.
  107. *
  108. * @return the start year.
  109. */
  110. public int getStartYear() {
  111. return getMinimum();
  112. }
  113. /**
  114. * Sets the start year.
  115. *
  116. * @param startYear the start year
  117. */
  118. public void setStartYear(int startYear) {
  119. setMinimum(startYear);
  120. }
  121. /**
  122. * Creates a JFrame with a JYearChooser inside and can be used for testing.
  123. *
  124. * @param s command line arguments
  125. */
  126. static public void main(String[] s) {
  127. JFrame frame = new JFrame("JYearChooser");
  128. frame.getContentPane().add(new ScheduleYearChooser());
  129. frame.pack();
  130. frame.setVisible(true);
  131. }
  132. }