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 */
021
022package org.biojava.bio.gui.sequence;
023
024import java.awt.Graphics2D;
025import java.awt.event.MouseEvent;
026import java.util.List;
027
028import org.biojava.utils.ChangeEvent;
029import org.biojava.utils.ChangeForwarder;
030import org.biojava.utils.ChangeSupport;
031import org.biojava.utils.ChangeType;
032
033/**
034 * <code>PairwiseSequenceRenderer</code>s render information about the
035 * relationship between two sequences. Its function is analagous to
036 * <code>SequenceRenderer</code> for single sequences and is
037 * extensively based on that code.
038 *
039 * @author Keith James
040 * @since 1.2
041 */
042public interface PairwiseSequenceRenderer
043{
044    /**
045     * <code>paint</code>s some or all of the information about the
046     * sequence pair.
047     *
048     * @param g2 a <code>Graphics2D</code>.
049     * @param prc a <code>PairwiseRenderContext</code> encapsulating
050     * the information to be displayed.
051     */
052    public void paint(Graphics2D g2, PairwiseRenderContext prc);
053
054    /**
055     * <code>processMouseEvent</code> produces a
056     * <code>SequenceViewerEvent</code> in response to a mouse
057     * gesture.
058     *
059     * @param prc a <code>PairwiseRenderContext</code>.
060     * @param me a <code>MouseEvent</code> that caused the request.
061     * @param path a <code>List</code> of
062     * <code>PairwiseSequenceRenderer</code> instances passed through
063     * so far.
064     *
065     * @return a <code>SequenceViewerEvent</code> encapsulating the
066     * mouse gesture.
067     */
068    public SequenceViewerEvent processMouseEvent(PairwiseRenderContext prc,
069                                                 MouseEvent            me,
070                                                 List                  path);
071
072    /**
073     * <code>PairwiseRendererForwarder</code> forward events to other
074     * renderers. This is closely based on the regular
075     * <code>RendererForwarder</code>.
076     */
077    public static class PairwiseRendererForwarder extends ChangeForwarder
078    {
079        /**
080         * Creates a new <code>PairwiseRendererForwarder</code>.
081         *
082         * @param source a <code>PairwiseSequenceRenderer</code>.
083         * @param cs a <code>ChangeSupport</code>.
084         */
085        public PairwiseRendererForwarder(PairwiseSequenceRenderer source,
086                                         ChangeSupport            cs)
087        {
088            super(source, cs);
089        }
090    
091        /**
092         * <code>generateEvent</code> generates events in response to
093         * layout change and repaint requests.
094         *
095         * @param ce a <code>ChangeEvent</code>.
096         *
097         * @return a <code>ChangeEvent</code>. 
098         */
099        public ChangeEvent generateEvent(ChangeEvent ce)
100        {
101            ChangeType type = ce.getType();
102
103            ChangeType newType;
104
105            if (type.isMatchingType(SequenceRenderContext.LAYOUT))
106                newType = SequenceRenderContext.LAYOUT;
107            else if (type.isMatchingType(SequenceRenderContext.REPAINT))
108                newType = SequenceRenderContext.REPAINT;
109            else
110                return null;
111
112            return new ChangeEvent(getSource(), newType, null, null, ce);
113        }
114    }
115}