root/trunk/FRII/gui/MappingContainer.hh

Revision 10, 3.6 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 things that contain features between two sequences. All
17 // subclasses must support:
18 //   * change notification;
19 //   * a basic (very simple) drawing function.
20 //
21 // See SeqcompMappingContainer.hh for a specific subclass.
22
23 #ifndef MAPPING_CONTAINER_HH
24 #define MAPPING_CONTAINER_HH
25
26 #include <vector>
27 #include <FL/Fl_Widget.H>
28 #include "_Canvas.hh"
29 #include "ColorPatch.hh"
30 #include "FeaturesContainer.hh"
31
32 namespace gui {
33   //
34   // A virtual base class for things that listen to MappingContainer changes.
35   //
36
37   class MappingContainerChanged_ {
38     friend class MappingContainer;
39   protected:
40     virtual void notify() = 0;
41     virtual ~MappingContainerChanged_() { }
42   };
43
44   //
45   // A container for sequence-to-sequence mappings.
46   //
47
48   class _FeaturesToMapChangeNotify;
49   class MappingContainer {
50     friend class _FeaturesToMapChangeNotify;
51   protected:
52     Fl_Color _color;
53     bool _visible;
54
55     std::vector<MappingContainerChanged_*> _to_notify_list;
56
57     // Responsible for notifying change listeners of a change.
58     void notify_changed() {
59       for (unsigned int i = 0; i < _to_notify_list.size(); i++) {
60         _to_notify_list[i]->notify();
61       }
62     }
63
64     MappingContainer() : _color(FL_BLACK), _visible(true) { };
65   public:
66     // Adds a change listener to the list.
67     void add_change_listener(MappingContainerChanged_* l) {
68       _to_notify_list.push_back(l);
69     }
70
71     bool visible() { return _visible; }
72     void visible(bool t) { _visible = t; notify_changed(); }
73
74     Fl_Color color() const { return _color; }
75     void color(Fl_Color c) { _color = c; notify_changed(); }
76
77     //
78     // Override in subclasses.
79     //
80
81     virtual void draw_on_canvas(_Canvas * canvas, bool is_closeup = false) = 0;
82     virtual ~MappingContainer() {
83       for (unsigned int i = 0; i < _to_notify_list.size(); i++) {
84         delete _to_notify_list[i];
85       }
86     }
87   };
88
89   //
90   // A specific subclass that redraws Fl_Widgets.
91   //
92
93   class MappingContainerChanged_Redrawer : public MappingContainerChanged_ {
94   private:
95     Fl_Widget * to_redraw;
96   public:
97     MappingContainerChanged_Redrawer(Fl_Widget * r) : to_redraw(r) { }
98     void notify() { to_redraw->redraw(); }
99     ~MappingContainerChanged_Redrawer() { }
100   };
101
102   //
103   // A specific class that links colors to mappings.
104   //
105
106   class ColorChangeListener_MappingContainer : public ColorChangeListener_ {
107   protected:
108     MappingContainer * _map;
109   public:
110     ColorChangeListener_MappingContainer(MappingContainer * m) {
111       _map = m;
112     }
113
114     void notify(Fl_Color c) { _map->color(c); }
115   };
116
117   //
118   // _FeaturesToMapChangeNotify -- take change notifications from the
119   // PercentFeaturesContainer and pass them to the MappingContainer class.
120   //
121
122   class _FeaturesToMapChangeNotify : public FeaturesContainerChanged_ {
123   private:
124     MappingContainer * map; // the map to be notified
125   public:
126     // constructor -- store the map
127     _FeaturesToMapChangeNotify(MappingContainer* m) { map = m; }
128
129     // notify() -- notify the map of the change.
130     void notify() { map->notify_changed(); }
131   };
132 }
133
134 #endif // MAPPING_CONTAINER_HH
135
Note: See TracBrowser for help on using the browser.