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.Color; 026import java.awt.Paint; 027import java.util.HashMap; 028import java.util.Map; 029 030import org.biojava.bio.BioError; 031import org.biojava.bio.seq.DNATools; 032import org.biojava.bio.symbol.IllegalSymbolException; 033import org.biojava.bio.symbol.Symbol; 034 035/** 036 * A simple implementation of SymbolStyle optimized for DNA. 037 * 038 * @author Matthew Pocock 039 */ 040public class DNAStyle implements SymbolStyle { 041 private Map outlinePaint; 042 private Map fillPaint; 043 044 { 045 outlinePaint = new HashMap(); 046 fillPaint = new HashMap(); 047 } 048 049 public Paint outlinePaint(Symbol s) throws IllegalSymbolException { 050 DNATools.getDNA().validate(s); 051 return (Paint) outlinePaint.get(s); 052 } 053 054 public Paint fillPaint(Symbol s) throws IllegalSymbolException { 055 DNATools.getDNA().validate(s); 056 return (Paint) fillPaint.get(s); 057 } 058 059 public void setOutlinePaint(Symbol s, Paint paint) 060 throws IllegalSymbolException { 061 DNATools.getDNA().validate(s); 062 outlinePaint.put(s, paint); 063 } 064 065 public void setFillPaint(Symbol s, Paint paint) 066 throws IllegalSymbolException { 067 DNATools.getDNA().validate(s); 068 fillPaint.put(s, paint); 069 } 070 071 public DNAStyle() { 072 try { 073 setOutlinePaint(DNATools.t(), Color.black); 074 setFillPaint(DNATools.t(), Color.red); 075 setOutlinePaint(DNATools.a(), Color.black); 076 setFillPaint(DNATools.a(), Color.green); 077 setOutlinePaint(DNATools.g(), Color.black); 078 setFillPaint(DNATools.g(), Color.blue); 079 setOutlinePaint(DNATools.c(), Color.black); 080 setFillPaint(DNATools.c(), Color.yellow); 081 } catch (IllegalSymbolException ire) { 082 throw new BioError("DNA symbols dissapeared from DNA alphabet", ire); 083 } 084 } 085}