bpp-phyl3  3.0.0
TreeDrawingDisplayControler.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 using namespace bpp;
8 using namespace std;
9 
11 {
12  for (std::map<std::string, TreeDrawingListener*>::iterator it = listeners_.begin();
13  it != listeners_.end(); ++it)
14  {
15  for (unsigned int j = 0; j < registeredTreeDrawings_.size(); ++j)
16  {
17  registeredTreeDrawings_[j]->removeTreeDrawingListener(it->second);
18  }
19  delete it->second;
20  }
21 }
22 
23 void TreeDrawingDisplayControler::addListener(const std::string& propertyName, TreeDrawingListener* listener)
24 {
25  if (listeners_.find(propertyName) != listeners_.end())
26  throw Exception("TreeDrawingDisplayControler::addListener. A listener is already added with this name: " + propertyName + ".");
27  if (!listener)
28  throw Exception("TreeDrawingDisplayControler::addListener. Trying to add a NULL listener!");
29  if (!listener->isAutonomous())
30  throw Exception("TreeDrawingDisplayControler::addListener. Trying to add a non-autonomous listener!");
31  listeners_[propertyName] = listener;
32  // Add listener to already registered tree drawings:
33  for (unsigned int i = 0; i < registeredTreeDrawings_.size(); ++i)
34  {
35  registeredTreeDrawings_[i]->addTreeDrawingListener(listener);
36  }
37 }
38 
41 const string BasicTreeDrawingDisplayControler::PROPERTY_BRANCH_LENGTHS = "Branch lengths";
42 const string BasicTreeDrawingDisplayControler::PROPERTY_BOOTSTRAP_VALUES = "Bootstrap values";
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.
virtual bool isAutonomous() const =0
Tells if the listener is autonomous. If so, it will never be hard-copied or deleted.
Defines the basic types of data flow nodes.