src/org/gel/mauve/gui/sequence/MultiGenomeRectangularBeadRenderer.java

Go to the documentation of this file.
00001 package org.gel.mauve.gui.sequence;
00002 
00003 import java.awt.Graphics2D;
00004 import java.awt.Paint;
00005 import java.awt.Stroke;
00006 import java.util.HashSet;
00007 import java.util.Hashtable;
00008 import java.util.Vector;
00009 
00010 import org.biojava.bio.gui.sequence.RectangularBeadRenderer;
00011 import org.biojava.bio.gui.sequence.SequenceRenderContext;
00012 import org.biojava.bio.seq.Feature;
00013 import org.biojava.bio.seq.Sequence;
00014 import org.biojava.utils.ChangeVetoException;
00015 import org.gel.mauve.BaseViewerModel;
00016 import org.gel.mauve.Genome;
00017 
00018 public class MultiGenomeRectangularBeadRenderer extends RectangularBeadRenderer
00019                 implements FlatFileFeatureConstants {
00020         
00021         protected Hashtable seq_to_offset;
00022         
00023         protected HashSet painted;
00024 
00025         protected BaseViewerModel model;
00026         
00027         public double last_offset = -1;
00028         
00029         private boolean listeners = true;
00030         
00031         public MultiGenomeRectangularBeadRenderer (double beadDepth, double beadDisplacement, Paint beadOutline,
00032                                 Paint beadFill, Stroke beadStroke, BaseViewerModel mod) {
00033                 super (beadDepth, beadDisplacement, beadOutline, beadFill, beadStroke);
00034                 model = mod;
00035                 painted = new HashSet (model.getSequenceCount ());
00036                 seq_to_offset = new Hashtable (model.getSequenceCount ());
00037         }
00038 
00039         public synchronized void renderBead (Graphics2D g, Feature feature, SequenceRenderContext context) {
00040                 try {
00041                         double offset = ((Double) seq_to_offset.get (feature.getSequence ())).doubleValue ();
00042                         if  (offset != last_offset) {
00043                                 /*if (painted.contains (feature.getSequence ())) {
00044                                         listeners = false;
00045                                         painted.clear ();
00046                                 }
00047                                 else
00048                                         painted.add (feature.getSequence ());*/
00049                                 listeners = false;
00050                                 if (last_offset != -1)
00051                                         setBeadDisplacement (beadDisplacement - last_offset);
00052                                 //new Exception ().printStackTrace ();
00053                                 System.out.println ("last: " + last_offset + "\ndisp: " + beadDisplacement);
00054                                 last_offset = offset;
00055                                 System.out.println ("offset: "  + offset + "\ndisp: " + beadDisplacement);
00056                                 //Snew Exception ().printStackTrace ();
00057                                 setBeadDisplacement (beadDisplacement + offset);
00058                                 listeners = true;
00059                         }
00060                         super.renderBead (g, feature, context);
00061                 } catch (ChangeVetoException e) {
00062                         // TODO Auto-generated catch block
00063                         e.printStackTrace();
00064                 }
00065         }
00066         
00067         public void setOffset (Genome genome, double offset) {
00068                 seq_to_offset.put (genome.getAnnotationSequence (), new Double (offset));
00069         }
00070         
00071         public double getOffset (Genome genome) {
00072                 Object ret = seq_to_offset.get (genome.getAnnotationSequence ());
00073                 if (ret == null)
00074                         return NO_OFFSET;
00075                 return ((Double) ret).doubleValue ();
00076         }
00077         
00078         public boolean hasListeners () {
00079                 System.out.println ("list: " + listeners);
00080                 if (listeners)
00081                         return super.hasListeners ();
00082                 else
00083                         return false;
00084         }
00085 
00086 }

Generated on Mon Aug 19 06:03:43 2013 for Mauve by doxygen 1.3.6