001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.tagging.ac;
003
004import java.awt.AWTEvent;
005
006/**
007 * This event is generated by an AutoCompTextField when an autocomplete occured.
008 *
009 * @see AutoCompTextField
010 * @see AutoCompListener
011 * @since 18221
012 */
013public class AutoCompEvent extends AWTEvent {
014
015    /**
016     * The first number in the range of ids used for autoComp events.
017     */
018    public static final int AUTOCOMP_FIRST = 5900;
019
020    /**
021     * The last number in the range of ids used for autoComp events.
022     */
023    public static final int AUTOCOMP_LAST = 5901;
024
025    /**
026     * This event id indicates that an autocomp is about to start.
027     */
028    public static final int AUTOCOMP_BEFORE = AUTOCOMP_FIRST;
029
030    /**
031     * This event id indicates that an autocomp completed.
032     */
033    public static final int AUTOCOMP_DONE = AUTOCOMP_FIRST + 1;
034
035    /*
036     * JDK 1.1 serialVersionUID
037     */
038    private static final long serialVersionUID = 3745384758753475838L;
039
040    /** the selected autocomplete item */
041    private Object item;
042
043    /**
044     * Constructs a <code>AutoCompEvent</code> object.
045     * <p> This method throws an
046     * <code>IllegalArgumentException</code> if <code>source</code>
047     * is <code>null</code>.
048     *
049     * @param source The (<code>AutoCompTextField</code>) object that
050     *               originated the event
051     * @param id     An integer that identifies the event type.
052     *               For information on allowable values, see
053     *               the class description for {@link AutoCompEvent}
054     * @param item   The item selected for autocompletion.
055     * @throws IllegalArgumentException if <code>source</code> is null
056     * @see #getSource()
057     * @see #getID()
058     */
059    public AutoCompEvent(Object source, int id, Object item) {
060        super(source, id);
061        this.item = item;
062    }
063
064    /**
065     * Returns the item selected for autocompletion.
066     *
067     * @return the item selected for autocompletion
068     */
069    public Object getItem() {
070        return item;
071    }
072
073    /**
074     * Returns a parameter string identifying this text event.
075     * This method is useful for event-logging and for debugging.
076     *
077     * @return a string identifying the event and its attributes
078     */
079    @Override
080    public String paramString() {
081        String typeStr;
082        switch(id) {
083            case AUTOCOMP_BEFORE:
084                typeStr = "AUTOCOMP_BEFORE";
085                break;
086            case AUTOCOMP_DONE:
087                typeStr = "AUTOCOMP_DONE";
088                break;
089          default:
090                typeStr = "unknown type";
091        }
092        return typeStr;
093    }
094}