001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.bio.gui.sequence;
022
023import java.awt.event.MouseEvent;
024import java.util.EventObject;
025import java.util.List;
026
027/**
028 * An event indicating that a mouse gesture was recognised within a widget that
029 * renders sequences.
030 *
031 * @author Matthew Pocock
032 * @since 1.2
033 */
034public class SequenceViewerEvent extends EventObject {
035  private final List path;
036  private final Object target;
037  private final MouseEvent mouseEvent;
038  private final int pos;
039  
040  /**
041   * Construct a SequenceViewerEvent with the given source, target, mouseEvent
042   * and path.
043   *
044   * @param source  the event source, presumably a GUI component
045   * @param target  an Object that is the target of the gesture - a feature, or
046   *                {alignment, label, index} or some other structure, or null
047   *                if there is no obvious target
048   * @param pos the position (offset) within the sequence
049   * @param mouseEvent the MouseEvent that caused this event to be produced
050   * @param path  a List of SequenceRenderer instances passed through to reach
051   *              this event source
052   */
053  public SequenceViewerEvent(
054    Object source,
055    Object target,
056    int pos,
057    MouseEvent mouseEvent,
058    List path
059  ) {
060    super(source);
061    this.target = target;
062    this.pos = pos;
063    this.mouseEvent = mouseEvent;
064    this.path = path;
065  }
066  
067  /**
068   * Get the list of SequenceRenderer instances that were passed through to
069   * produce this event
070   *
071   * @return a List of SequenceRenderer instances
072   */
073  public List getPath() {
074    return path;
075  }
076  
077  /**
078   * Get the Object that was the target of the mouse gesture or null if the
079   * mouse is not gesturing over any recognizable rendered object.
080   *
081   * @return the Object gestured at by the mouse event
082   */
083  public Object getTarget() {
084    return target;
085  }
086  
087  /**
088   * Get the offset within the sequence - the symbol index. This is not
089   * guaranteed to be within the legal range of symbol indices.
090   *
091   * @return the position of the gesture in sequence coordinates
092   */
093  public int getPos() {
094    return pos;
095  }
096  
097  /**
098   * Get the mouse event that caused this.
099   *
100   * @return the MouseEvent that caused this gesture to be noticed
101   */
102  public MouseEvent getMouseEvent() {
103    return mouseEvent;
104  }
105  
106  public String toString() {
107    return "[" +
108        super.toString() + "]" +
109        "target: "+ target +
110        "pos: " + pos +
111        "mosuseEvent: " + mouseEvent;
112  }
113}