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 022 023package org.biojava.bio.gui; 024 025import java.awt.Rectangle; 026import java.awt.geom.Rectangle2D; 027import java.util.Iterator; 028 029import org.biojava.bio.BioError; 030import org.biojava.bio.dist.Distribution; 031import org.biojava.bio.symbol.AtomicSymbol; 032import org.biojava.bio.symbol.FiniteAlphabet; 033import org.biojava.bio.symbol.IllegalSymbolException; 034 035/** 036 * A logo painter that paints in bars. The total height of the bars is 037 * proportional to the total informaton in the state. 038 * 039 * @author Matthew Pocock 040 */ 041public class BarLogoPainter implements LogoPainter { 042 public void paintLogo(LogoContext lCtxt) { 043 Distribution dis = lCtxt.getDistribution(); 044 BlockPainter blockPainter = lCtxt.getBlockPainter(); 045 046 Rectangle bounds = lCtxt.getBounds(); 047 double width = bounds.getWidth(); 048 double stepWidth = width / (double) ((FiniteAlphabet) dis.getAlphabet()).size(); 049 double height = bounds.getHeight(); 050 051 double w = 0.0; 052 for( 053 Iterator i = ((FiniteAlphabet) dis.getAlphabet()).iterator(); 054 i.hasNext(); 055 ) { 056 AtomicSymbol s = (AtomicSymbol) i.next(); 057 double rh = 0.0; 058 059 try { 060 rh = dis.getWeight(s) * height; 061 } catch (IllegalSymbolException ire) { 062 throw new BioError("State alphabet has changed while painting", ire); 063 } 064 065 Rectangle2D outline = new Rectangle2D.Double( 066 bounds.getX() + w, 067 bounds.getY() + height - rh, 068 stepWidth, 069 rh 070 ); 071 072 blockPainter.paintBlock(lCtxt, outline, s); 073 074 w += stepWidth; 075 } 076 } 077 078 public BarLogoPainter() {} 079}