/** * Defines the color for the buttons representing the current month. * * @param chosenMonthButtonColor the color for the current month. */ public void setChosenMonthButtonColor(final Color chosenMonthButtonColor) { if (chosenMonthButtonColor == null) { throw new NullPointerException("UIColor must not be null."); } final Color oldValue = this.chosenMonthButtonColor; this.chosenMonthButtonColor = chosenMonthButtonColor; refreshButtons(); firePropertyChange("chosenMonthButtonColor", oldValue, chosenMonthButtonColor); }
/** * Update the button labels and colors to reflect date selection. */ private void refreshButtons() { final Calendar c = getFirstVisibleDate(); for (int i = 0; i < 42; i++) { final JButton b = this.buttons[i]; b.setText(Integer.toString(c.get(Calendar.DATE))); b.setBackground(getButtonColor(c)); c.add(Calendar.DATE, 1); } }
/** * Sets the range of years available for selection. * * @param yearSelectionRange the range. */ public void setYearSelectionRange(final int yearSelectionRange) { final int oldYearSelectionRange = this.yearSelectionRange; this.yearSelectionRange = yearSelectionRange; refreshYearSelector(); firePropertyChange("yearSelectionRange", oldYearSelectionRange, yearSelectionRange); } }
/** * Constructs a new date chooser panel. * * @param calendar the calendar controlling the date. * @param controlPanel a flag that indicates whether or not the 'today' * button should appear on the panel. */ public DateChooserPanel(final Calendar calendar, final boolean controlPanel) { super(new BorderLayout()); this.chosenDateButtonColor = UIManager.getColor("textHighlight"); this.chosenMonthButtonColor = UIManager.getColor("control"); this.chosenOtherButtonColor = UIManager.getColor("controlShadow"); // the default date is today... this.chosenDate = calendar; this.firstDayOfWeek = calendar.getFirstDayOfWeek(); this.WEEK_DAYS = new int[7]; for (int i = 0; i < 7; i++) { this.WEEK_DAYS[i] = ((this.firstDayOfWeek + i - 1) % 7) + 1; } add(constructSelectionPanel(), BorderLayout.NORTH); add(getCalendarPanel(), BorderLayout.CENTER); if (controlPanel) { add(constructControlPanel(), BorderLayout.SOUTH); } setDate(calendar.getTime()); }
this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshButtons(); this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshYearSelector(); refreshButtons(); setDate(new Date()); final Calendar cal = getFirstVisibleDate(); cal.add(Calendar.DATE, i); setDate(cal.getTime());
/** * Changes the contents of the year selection JComboBox to reflect the * chosen date and the year range. */ private void refreshYearSelector() { if (!this.refreshing) { this.refreshing = true; this.yearSelector.removeAllItems(); final Integer[] years = getYears(this.chosenDate.get( Calendar.YEAR)); for (int i = 0; i < years.length; i++) { this.yearSelector.addItem(years[i]); } this.yearSelector.setSelectedItem(new Integer(this.chosenDate.get( Calendar.YEAR))); this.refreshing = false; } }
/** * Returns the first date that is visible in the grid. This should always * be in the month preceding the month of the selected date. * * @return the date. */ private Calendar getFirstVisibleDate() { final Calendar c = Calendar.getInstance(); c.set(this.chosenDate.get(Calendar.YEAR), this.chosenDate.get( Calendar.MONTH), 1); c.add(Calendar.DATE, -1); while (c.get(Calendar.DAY_OF_WEEK) != getFirstDayOfWeek()) { c.add(Calendar.DATE, -1); } return c; }
/** * Returns the button color according to the specified date. * * @param theDate the date. * @return the color. */ private Color getButtonColor(final Calendar theDate) { if (equalDates(theDate, this.chosenDate)) { return this.chosenDateButtonColor; } else if (theDate.get(Calendar.MONTH) == this.chosenDate.get( Calendar.MONTH)) { return this.chosenMonthButtonColor; } else { return this.chosenOtherButtonColor; } }
/** * Constructs a new date chooser panel. * * @param calendar the calendar controlling the date. * @param controlPanel a flag that indicates whether or not the 'today' * button should appear on the panel. */ public DateChooserPanel(final Calendar calendar, final boolean controlPanel) { super(new BorderLayout()); this.chosenDateButtonColor = UIManager.getColor("textHighlight"); this.chosenMonthButtonColor = UIManager.getColor("control"); this.chosenOtherButtonColor = UIManager.getColor("controlShadow"); // the default date is today... this.chosenDate = calendar; this.firstDayOfWeek = calendar.getFirstDayOfWeek(); this.WEEK_DAYS = new int[7]; for (int i = 0; i < 7; i++) { this.WEEK_DAYS[i] = ((this.firstDayOfWeek + i - 1) % 7) + 1; } add(constructSelectionPanel(), BorderLayout.NORTH); add(getCalendarPanel(), BorderLayout.CENTER); if (controlPanel) { add(constructControlPanel(), BorderLayout.SOUTH); } setDate(calendar.getTime()); }
this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshButtons(); this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshYearSelector(); refreshButtons(); setDate(new Date()); final Calendar cal = getFirstVisibleDate(); cal.add(Calendar.DATE, i); setDate(cal.getTime());
/** * Sets the range of years available for selection. * * @param yearSelectionRange the range. */ public void setYearSelectionRange(final int yearSelectionRange) { final int oldYearSelectionRange = this.yearSelectionRange; this.yearSelectionRange = yearSelectionRange; refreshYearSelector(); firePropertyChange("yearSelectionRange", oldYearSelectionRange, yearSelectionRange); } }
/** * Changes the contents of the year selection JComboBox to reflect the * chosen date and the year range. */ private void refreshYearSelector() { if (!this.refreshing) { this.refreshing = true; this.yearSelector.removeAllItems(); final Integer[] years = getYears(this.chosenDate.get( Calendar.YEAR)); for (int i = 0; i < years.length; i++) { this.yearSelector.addItem(years[i]); } this.yearSelector.setSelectedItem(new Integer(this.chosenDate.get( Calendar.YEAR))); this.refreshing = false; } }
/** * Returns the first date that is visible in the grid. This should always * be in the month preceding the month of the selected date. * * @return the date. */ private Calendar getFirstVisibleDate() { final Calendar c = Calendar.getInstance(); c.set(this.chosenDate.get(Calendar.YEAR), this.chosenDate.get( Calendar.MONTH), 1); c.add(Calendar.DATE, -1); while (c.get(Calendar.DAY_OF_WEEK) != getFirstDayOfWeek()) { c.add(Calendar.DATE, -1); } return c; }
/** * Returns the button color according to the specified date. * * @param theDate the date. * @return the color. */ private Color getButtonColor(final Calendar theDate) { if (equalDates(theDate, this.chosenDate)) { return this.chosenDateButtonColor; } else if (theDate.get(Calendar.MONTH) == this.chosenDate.get( Calendar.MONTH)) { return this.chosenMonthButtonColor; } else { return this.chosenOtherButtonColor; } }
/** * Constructs a new date chooser panel. * * @param calendar the calendar controlling the date. * @param controlPanel a flag that indicates whether or not the 'today' * button should appear on the panel. */ public DateChooserPanel(final Calendar calendar, final boolean controlPanel) { super(new BorderLayout()); this.chosenDateButtonColor = UIManager.getColor("textHighlight"); this.chosenMonthButtonColor = UIManager.getColor("control"); this.chosenOtherButtonColor = UIManager.getColor("controlShadow"); // the default date is today... this.chosenDate = calendar; this.firstDayOfWeek = calendar.getFirstDayOfWeek(); this.WEEK_DAYS = new int[7]; for (int i = 0; i < 7; i++) { this.WEEK_DAYS[i] = ((this.firstDayOfWeek + i - 1) % 7) + 1; } add(constructSelectionPanel(), BorderLayout.NORTH); add(getCalendarPanel(), BorderLayout.CENTER); if (controlPanel) { add(constructControlPanel(), BorderLayout.SOUTH); } setDate(calendar.getTime()); }
this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshButtons(); this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth)); refreshYearSelector(); refreshButtons(); setDate(new Date()); final Calendar cal = getFirstVisibleDate(); cal.add(Calendar.DATE, i); setDate(cal.getTime());
/** * Redefines the color for the buttons representing the other months. * * @param chosenOtherButtonColor a color. */ public void setChosenOtherButtonColor(final Color chosenOtherButtonColor) { if (chosenOtherButtonColor == null) { throw new NullPointerException("UIColor must not be null."); } final Color oldValue = this.chosenOtherButtonColor; this.chosenOtherButtonColor = chosenOtherButtonColor; refreshButtons(); firePropertyChange("chosenOtherButtonColor", oldValue, chosenOtherButtonColor); }
/** * Update the button labels and colors to reflect date selection. */ private void refreshButtons() { final Calendar c = getFirstVisibleDate(); for (int i = 0; i < 42; i++) { final JButton b = this.buttons[i]; b.setText(Integer.toString(c.get(Calendar.DATE))); b.setBackground(getButtonColor(c)); c.add(Calendar.DATE, 1); } }
/** * Sets the range of years available for selection. * * @param yearSelectionRange the range. */ public void setYearSelectionRange(final int yearSelectionRange) { final int oldYearSelectionRange = this.yearSelectionRange; this.yearSelectionRange = yearSelectionRange; refreshYearSelector(); firePropertyChange("yearSelectionRange", oldYearSelectionRange, yearSelectionRange); } }
/** * Changes the contents of the year selection JComboBox to reflect the * chosen date and the year range. */ private void refreshYearSelector() { if (!this.refreshing) { this.refreshing = true; this.yearSelector.removeAllItems(); final Integer[] years = getYears(this.chosenDate.get( Calendar.YEAR)); for (int i = 0; i < years.length; i++) { this.yearSelector.addItem(years[i]); } this.yearSelector.setSelectedItem(new Integer(this.chosenDate.get( Calendar.YEAR))); this.refreshing = false; } }