001 /*
002 * $Id: DateSelectionEvent.java 3272 2009-02-25 11:06:37Z kleopatra $
003 *
004 * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021 package org.jdesktop.swingx.event;
022
023 import java.util.Date;
024 import java.util.EventObject;
025 import java.util.SortedSet;
026
027 import org.jdesktop.swingx.calendar.DateSelectionModel;
028
029 /**
030 * @author Joshua Outwater
031 */
032 public class DateSelectionEvent extends EventObject {
033 public static enum EventType {
034 DATES_ADDED,
035 DATES_REMOVED,
036 DATES_SET,
037 SELECTION_CLEARED,
038 SELECTABLE_DATES_CHANGED,
039 SELECTABLE_RANGE_CHANGED,
040 UNSELECTED_DATES_CHANGED,
041 LOWER_BOUND_CHANGED,
042 UPPER_BOUND_CHANGED,
043 ADJUSTING_STARTED, ADJUSTING_STOPPED,
044 CALENDAR_CHANGED,
045 }
046
047 private EventType eventType;
048 private boolean adjusting;
049
050 /**
051 * Constructs a prototypical Event.
052 *
053 * @param source The object on which the Event initially occurred.
054 * @param eventType the type of the event
055 * @param adjusting the adjusting property of the source
056 * @throws IllegalArgumentException if source is null.
057 */
058 public DateSelectionEvent(Object source, EventType eventType, boolean adjusting) {
059 super(source);
060 this.eventType = eventType;
061 this.adjusting = adjusting;
062 }
063
064 /**
065 * Returns the selection of the source dateSelectionModel.<p>
066 *
067 * PENDING JW: that's the "live" selection, that is the source is re-queried on every call
068 * to this method. Bug or feature?
069 *
070 * @return the selection of the source.
071 */
072 public SortedSet<Date> getSelection() {
073 return ((DateSelectionModel)source).getSelection();
074 }
075
076 /**
077 * Returns the type of this event.
078 *
079 * @return the type of event.
080 */
081 public final EventType getEventType() {
082 return eventType;
083 }
084
085 /**
086 * Returns a boolean indicating whether the event source is in adjusting state.
087 *
088 * @return true if the event is fired while the model is in adjusting state.
089 */
090 public boolean isAdjusting() {
091 return adjusting;
092 }
093
094 @Override
095 public String toString() {
096 return "[" + String.valueOf(getSource()) + " type: " + getEventType() + " isAdjusting: " + isAdjusting();
097 }
098
099
100 }