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;
025
026/**
027 * The interface for things that can render labels for a line of information
028 * about a sequence.
029 * <p>
030 * Renderers are always activated within the context of a particular
031 * SequenceRenderContext.
032 * A single LabelRenderer can be shared among many sequence panels, or added
033 * multiple times to the same panel. The renderer is required to request how
034 * much leading and trailing space it requires, as well as the depth (space
035 * orthogonal to the direction that the sequence is rendered).
036 *
037 * @author Matthew Pocock
038 */
039public interface LabelRenderer {
040  
041  /**
042   * Render a label for the information for sp to g.
043   *
044   * @param g the Graphics2D to render to
045   * @param sp the SequencePanel that encapsulates the information to render
046   * @param min the minimum symbol to render (inclusive)
047   * @param max the maximum symbol to render (inclusive)
048   */
049  void paint(
050    Graphics2D g, SequenceRenderContext sp,
051    int min, int max, SequenceRenderContext.Border border
052  );
053
054  /**
055   * Retrieve the minimum space required to render the label.
056   *
057   * @param sp the SequencePanel to return info for
058   * @return the leading distance of the renderer for that sequence panel
059   */
060  double getMinimumWidth(SequenceRenderContext sp);
061    
062  public static LabelRenderer RENDER_NOTHING = new RenderNothing();
063  
064  static class RenderNothing implements LabelRenderer {
065    public void paint(
066         Graphics2D g, SequenceRenderContext sp,
067         int min, int max, SequenceRenderContext.Border border
068    ) {}
069    
070    public double getMinimumWidth(SequenceRenderContext src) {
071      return 0.0;
072    }
073  };
074}