root/trunk/FRII/gui/FeaturesContainer.hh

Revision 10, 3.2 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Base class for features on a single-sequence.  All subclasses must support:
17 //   * export of features;
18 //   * change notification.
19 //
20 // See SimpleFeaturesContainer.hh and BlastFeaturesContainer.* for specific
21 // implementations.
22
23 #ifndef FEATURES_CONTAINER_HH
24 #define FEATURES_CONTAINER_HH
25
26 #include "FeatureList.hh"
27 #include "ColorPatch.hh"
28
29 namespace gui {
30   //
31   // A virtual base class for things that listen to FeaturesContainer changes.
32   //
33
34   class FeaturesContainerChanged_ {
35     friend class FeaturesContainer;
36   protected:
37     virtual void notify() = 0;
38     virtual ~FeaturesContainerChanged_() { }
39   };
40
41   //
42   // A container for features on a single sequence.
43   //
44  
45   class FeaturesContainer {
46   protected:
47     std::vector<FeaturesContainerChanged_*> _to_notify_list;
48     Fl_Color _color;
49     bool _visible;
50
51     // Notify change listeners of a change.
52     void notify_changed() {
53       for (unsigned int i = 0; i < _to_notify_list.size(); i++) {
54         _to_notify_list[i]->notify();
55       }
56     }
57
58     FeaturesContainer() { _color = FL_BLACK; _visible = true; }
59   public:
60     // Add change listener.
61     void add_change_listener(FeaturesContainerChanged_* l) {
62       _to_notify_list.push_back(l);
63     }
64
65     // color management
66     Fl_Color color() { return _color; }
67     void color(Fl_Color c) { _color = c; notify_changed(); }
68
69     // visibility management
70     bool visible() { return _visible; }
71     void visible(bool v) { _visible = v; notify_changed(); }
72
73     // do any of these features contain alignments?
74     virtual bool contains_alignments() const {
75       return getFeatureList()->contains_alignments();
76     }
77
78     //
79     // Override in subclasses.
80     //
81     virtual const FeatureList* getFeatureList() const = 0;
82     virtual FeaturesContainer * copy_me() const = 0;
83
84     virtual ~FeaturesContainer() {
85       for (unsigned int i = 0; i < _to_notify_list.size(); i++) {
86         delete _to_notify_list[i];
87       }
88     }
89   };
90
91   //
92   // A specific subclass that redraws Fl_Widgets.
93   //
94
95   class FeaturesContainerChanged_Redrawer : public FeaturesContainerChanged_ {
96   private:
97     Fl_Widget * to_redraw;
98   public:
99     FeaturesContainerChanged_Redrawer(Fl_Widget * r) : to_redraw(r) { }
100     void notify() { to_redraw->redraw(); }
101     ~FeaturesContainerChanged_Redrawer() { }
102   };
103
104   //
105   // A specific class that links colors to mappings.
106   //
107
108   class ColorChangeListener_FeaturesContainer : public ColorChangeListener_ {
109   protected:
110     FeaturesContainer * _cont;
111   public:
112     ColorChangeListener_FeaturesContainer(FeaturesContainer * c) {
113       _cont = c;
114     }
115     virtual ~ColorChangeListener_FeaturesContainer() { };
116
117     void notify(Fl_Color c) { _cont->color(c); }
118   };
119
120 }
121
122 #endif // FEATURES_CONTAINER_HH
123
Note: See TracBrowser for help on using the browser.