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.util.HashMap; 024import java.util.Iterator; 025import java.util.Map; 026 027/** 028 * Encapsulates the rendering info for a single line of the display. 029 * <p> 030 * The single line of info may be divided into multiple regions, each rendered 031 * by their own SequenceRenderer. It is the job of this class to cache the 032 * information about how much space each one wants, and how much space they want 033 * in total. A SequenceRenderer or SequencePanel that delegates rendering to 034 * multiple child SequenceRenderer instances may want to use these objects 035 * for storing this information about each row they are responsible for. 036 * 037 * @author Matthew Pocock 038 */ 039public class LineInfo { 040 private Map rendererToDepth = new HashMap(); 041 private double totalDepth = 0.0; 042 043 public double getDepth(SequenceRenderer r) { 044 Double depth = (Double) rendererToDepth.get(r); 045 return depth.doubleValue(); 046 } 047 048 public void setDepth(SequenceRenderer r, double depth) { 049 totalDepth = Double.NaN; 050 051 rendererToDepth.put(r, new Double(depth)); 052 } 053 054 public double getTotalDepth() { 055 if(Double.isNaN(totalDepth)) { 056 totalDepth = 0.0; 057 058 for(Iterator i = rendererToDepth.values().iterator(); i.hasNext(); ) { 059 Double d = (Double) i.next(); // should never be null 060 totalDepth += d.doubleValue(); 061 } 062 } 063 064 return totalDepth; 065 } 066}