bpp-phyl3  3.0.0
TreeDrawingDisplayControler.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
6 #define BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
7 
8 
9 #include "TreeDrawingListener.h"
10 
11 // From the STL:
12 #include <string>
13 #include <vector>
14 #include <map>
15 #include <algorithm>
16 
17 namespace bpp
18 {
28 {
29 private:
30  std::map<std::string, TreeDrawingListener*> listeners_;
31  std::vector<TreeDrawing*> registeredTreeDrawings_;
32 
33 public:
36  {}
37 
38 private:
41  {
42  for (std::map<std::string, TreeDrawingListener*>::const_iterator it = tddc.listeners_.begin();
43  it != tddc.listeners_.end(); ++it)
44  {
45  listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
46  }
47  }
49  {
50  listeners_.clear();
52  for (std::map<std::string, TreeDrawingListener*>::const_iterator it = tddc.listeners_.begin();
53  it != tddc.listeners_.end(); ++it)
54  {
55  listeners_[it->first] = dynamic_cast<TreeDrawingListener*>(it->second->clone());
56  }
57  return *this;
58  }
59 
60 public:
62 
63 public:
68  void addListener(const std::string& propertyName, TreeDrawingListener* listener);
69 
70  bool hasListenerFor(const std::string& propertyName) const
71  {
72  return listeners_.find(propertyName) != listeners_.end();
73  }
74 
75  void enableListener(const std::string& propertyName, bool tf)
76  {
77  if (!hasListenerFor(propertyName))
78  throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
79  listeners_[propertyName]->enable(tf);
80  }
81 
82  bool isListenerEnabled(const std::string& propertyName) const
83  {
84  if (!hasListenerFor(propertyName))
85  throw Exception("TreeDrawingDisplayControler::enableListener. No listener is registered for property " + propertyName + ".");
86  return listeners_.find(propertyName)->second->isEnabled();
87  }
88 
90  {
91  if (std::find(registeredTreeDrawings_.begin(), registeredTreeDrawings_.end(), td) != registeredTreeDrawings_.end())
92  throw Exception("TreeDrawingDisplayControler::registerTreeDrawing. TreeDrawing is already associated to this controller.");
93  for (std::map<std::string, TreeDrawingListener*>::iterator it = listeners_.begin();
94  it != listeners_.end(); ++it)
95  {
96  td->addTreeDrawingListener(it->second);
97  }
98  registeredTreeDrawings_.push_back(td);
99  }
100 };
101 
102 
117 {
118 public:
119  static const std::string PROPERTY_NODE_IDS;
120  static const std::string PROPERTY_LEAF_NAMES;
121  static const std::string PROPERTY_BRANCH_LENGTHS;
122  static const std::string PROPERTY_BOOTSTRAP_VALUES;
123 
124 private:
126 
127 public:
129  settings_(settings)
130  {
131  if (!settings)
132  throw NullPointerException("BasicTreeDrawingDisplayControler::constructor. Trying to use NULL settings.");
137  }
138 
139 private:
142 };
143 } // end of namespace bpp.
144 #endif // BPP_PHYL_GRAPHICS_TREEDRAWINGDISPLAYCONTROLER_H
Easy tune of tree drawings display, a basic implementation:
BasicTreeDrawingDisplayControler(const BasicTreeDrawingDisplayControler &)
BasicTreeDrawingDisplayControler(const TreeDrawingSettings *settings)
BasicTreeDrawingDisplayControler & operator=(const BasicTreeDrawingDisplayControler &)
A TreeDrawingListener implementation that write the bootstrap values of inner nodes.
A TreeDrawingListener implementation that write the branch lengths of inner nodes.
A TreeDrawingListener implementation that write leaf names.
A TreeDrawingListener implementation that writes nodes id.
Easy tune of tree drawings display.
void enableListener(const std::string &propertyName, bool tf)
TreeDrawingDisplayControler(const TreeDrawingDisplayControler &tddc)
TreeDrawingDisplayControler & operator=(const TreeDrawingDisplayControler &tddc)
std::vector< TreeDrawing * > registeredTreeDrawings_
bool isListenerEnabled(const std::string &propertyName) const
std::map< std::string, TreeDrawingListener * > listeners_
bool hasListenerFor(const std::string &propertyName) const
void addListener(const std::string &propertyName, TreeDrawingListener *listener)
Add a listener to the controller. The controller then owns the object, and will copy or delete it whe...
Interface allowing to capture drawing events.
A set of options to tune the display of a TreeDrawing object.
Definition: TreeDrawing.h:27
Basal interface for tree drawing classes.
Definition: TreeDrawing.h:223
virtual void addTreeDrawingListener(TreeDrawingListener *listener)=0
Add a drawing listener to this instance.
Defines the basic types of data flow nodes.