bpp-phyl  2.2.0
TreeDrawingDisplayControler.h
Go to the documentation of this file.
1 //
2 // File: TreeDrawingDisplayControler.h
3 // Created by: Julien Dutheil
4 // Created on: Tue May 18 12:37 2010
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Development Team, (2010)
9 
10 This software is a computer program whose purpose is to provide
11 graphic components to develop bioinformatics applications.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _TREEDRAWINGDISPLAYCONTROLER_H_
41 #define _TREEDRAWINGDISPLAYCONTROLER_H_
42 
43 #include "TreeDrawingListener.h"
44 
45 //From the STL:
46 #include <string>
47 #include <vector>
48 #include <map>
49 #include <algorithm>
50 
51 namespace bpp {
52 
62 {
63  private:
64  std::map<std::string, TreeDrawingListener*> listeners_;
65  std::vector<TreeDrawing*> registeredTreeDrawings_;
66 
67  public:
70  {}
71 
72  private:
75  {
76  for (std::map<std::string, TreeDrawingListener*>::const_iterator it = tddc.listeners_.begin();
77  it != tddc.listeners_.end(); ++it)
78  {
79  listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
80  }
81  }
83  {
84  listeners_.clear();
86  for (std::map<std::string, TreeDrawingListener*>::const_iterator it = tddc.listeners_.begin();
87  it != tddc.listeners_.end(); ++it)
88  {
89  listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
90  }
91  return *this;
92  }
93 
94  public:
96 
97  public:
102  void addListener(const std::string& propertyName, TreeDrawingListener* listener) throw (Exception);
103 
104  bool hasListenerFor(const std::string& propertyName) const
105  {
106  return listeners_.find(propertyName) != listeners_.end();
107  }
108 
109  void enableListener(const std::string& propertyName, bool tf) throw (Exception)
110  {
111  if (!hasListenerFor(propertyName))
112  throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
113  listeners_[propertyName]->enable(tf);
114  }
115 
116  bool isListenerEnabled(const std::string& propertyName) const throw (Exception)
117  {
118  if (!hasListenerFor(propertyName))
119  throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
120  return listeners_.find(propertyName)->second->isEnabled();
121  }
122 
123  void registerTreeDrawing(TreeDrawing* td) throw (Exception)
124  {
125  if (std::find(registeredTreeDrawings_.begin(), registeredTreeDrawings_.end(), td) != registeredTreeDrawings_.end())
126  throw Exception("TreeDrawingDisplayControler::registerTreeDrawing. TreeDrawing is already associated to this controler.");
127  for (std::map<std::string, TreeDrawingListener*>::iterator it = listeners_.begin();
128  it != listeners_.end(); ++it)
129  td->addTreeDrawingListener(it->second);
130  registeredTreeDrawings_.push_back(td);
131  }
132 
133 };
134 
135 
136 
151 {
152  public:
153  static const std::string PROPERTY_NODE_IDS;
154  static const std::string PROPERTY_LEAF_NAMES;
155  static const std::string PROPERTY_BRANCH_LENGTHS;
156  static const std::string PROPERTY_BOOTSTRAP_VALUES;
157 
158  private:
160 
161  public:
162  BasicTreeDrawingDisplayControler(const TreeDrawingSettings* settings) throw (NullPointerException) :
163  settings_(settings)
164  {
165  if (!settings)
166  throw NullPointerException("BasicTreeDrawingDisplayControler::constructor. Trying to use NULL settings.");
171  }
172 
173  private:
176 
177 };
178 
179 } //end of namespace bpp.
180 
181 #endif //_TREEDRAWINGDISPLAYCONTROLER_H_
182 
Basal interface for tree drawing classes.
Definition: TreeDrawing.h:264
bool isListenerEnabled(const std::string &propertyName) const
A TreeDrawingListener implementation that write the bootstrap values of inner nodes.
Easy tune of tree drawings display, a basic implementation:
BasicTreeDrawingDisplayControler(const BasicTreeDrawingDisplayControler &)
std::vector< TreeDrawing * > registeredTreeDrawings_
BasicTreeDrawingDisplayControler & operator=(const BasicTreeDrawingDisplayControler &)
BasicTreeDrawingDisplayControler(const TreeDrawingSettings *settings)
Easy tune of tree drawings display.
A set of options to tune the display of a TreeDrawing object.
Definition: TreeDrawing.h:61
A TreeDrawingListener implementation that write the branch lengths of inner nodes.
Interface allowing to capture drawing events.
void enableListener(const std::string &propertyName, bool tf)
void addListener(const std::string &propertyName, TreeDrawingListener *listener)
Add a listener to the controler. The controler then owns the object, and will copy or delete it when ...
A TreeDrawingListener implementation that write leaf names.
std::map< std::string, TreeDrawingListener * > listeners_
TreeDrawingDisplayControler(const TreeDrawingDisplayControler &tddc)
A TreeDrawingListener implementation that writes nodes id.
bool hasListenerFor(const std::string &propertyName) const
TreeDrawingDisplayControler & operator=(const TreeDrawingDisplayControler &tddc)