01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas, Bettina Lademann |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla.gui.toolkit;
14:
15: import javax.swing.JComboBox;
16: import javax.swing.DefaultComboBoxModel;
17:
18: import java.util.Locale;
19:
20: import org.rapla.components.calendarview.WeekdayMapper;
21:
22: /** ComboBox that displays the weekdays in long format
23: @see WeekdayMapper
24: */
25: public final class WeekdayChooser extends JComboBox {
26: private static final long serialVersionUID = 1L;
27:
28: WeekdayMapper mapper;
29:
30: public WeekdayChooser() {
31: this (Locale.getDefault());
32: }
33:
34: public WeekdayChooser(Locale locale) {
35: setLocale(locale);
36: }
37:
38: public void setLocale(Locale locale) {
39: super .setLocale(locale);
40: if (locale == null)
41: return;
42: mapper = new WeekdayMapper(locale);
43: setModel(new DefaultComboBoxModel(mapper.getNames()));
44: }
45:
46: public void selectWeekday(int weekday) {
47: setSelectedIndex(mapper.indexForDay(weekday));
48: }
49:
50: /** returns the selected day or -1 if no day is selected.
51: @see java.util.Calendar
52: */
53: public int getSelectedWeekday() {
54: if (getSelectedIndex() == -1)
55: return -1;
56: else
57: return mapper.dayForIndex(getSelectedIndex());
58: }
59:
60: }
|