From 39792012990627a5af298429783c3af6aff26658 Mon Sep 17 00:00:00 2001
From: Ananya Bahadur <ananya95@gmail.com>
Date: Sun, 10 Jul 2016 01:07:26 +0530
Subject: [PATCH] Helpers to override `buttonClicked` added.

These changes were made to primarily to accommodate for the cyclops-stimulator. Since buttonClicked manipulates the DataViewport via AccessClass, a sub-class of VisualizerEditor cannot functionally override the method.
Hence:

* Added protected methods which manipulate DataViewport (via AccessClass)
* moved the SelectorButtons into protected area, essential!
* All of the additions are essential to the cyclops-stimulator.
* There is NO change in the public interface.

Now, my buttonClicked method can access the SelectorButtons, manipulate (anything about!!) DataViewport.
Please remove the (new) comments from VisualizerEditor::buttonClicked (.cpp), they are not needed anymore.
---
 .../Processors/Editors/VisualizerEditor.cpp   | 49 +++++++++++----
 Source/Processors/Editors/VisualizerEditor.h  | 61 ++++++++++++++++---
 2 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/Source/Processors/Editors/VisualizerEditor.cpp b/Source/Processors/Editors/VisualizerEditor.cpp
index ccabfae1d..eaf6ae558 100755
--- a/Source/Processors/Editors/VisualizerEditor.cpp
+++ b/Source/Processors/Editors/VisualizerEditor.cpp
@@ -114,7 +114,7 @@ VisualizerEditor::~VisualizerEditor()
 
     if (tabIndex > -1)
     {
-		AccessClass::getDataViewport()->destroyTab(tabIndex);
+        AccessClass::getDataViewport()->destroyTab(tabIndex);
     }
 
     deleteAllChildren();
@@ -155,7 +155,7 @@ void VisualizerEditor::editorWasClicked()
     if (tabIndex > -1)
     {
         std::cout << "Setting tab index to " << tabIndex << std::endl;
-		AccessClass::getDataViewport()->selectTab(tabIndex);
+        AccessClass::getDataViewport()->selectTab(tabIndex);
     }
 
 }
@@ -184,14 +184,15 @@ void VisualizerEditor::buttonClicked(Button* button)
         if (tabSelector->getToggleState() && windowSelector->getToggleState())
         {
             tabSelector->setToggleState(false, dontSendNotification);
-			AccessClass::getDataViewport()->destroyTab(tabIndex);
-            tabIndex = -1;
+            // AccessClass::getDataViewport()->destroyTab(tabIndex);
+            // tabIndex = -1;
+            removeTab(tabIndex);
         }
 
         if (dataWindow == nullptr) // have we created a window already?
         {
-
-            dataWindow = new DataWindow(windowSelector, tabText);
+            // dataWindow = new DataWindow(windowSelector, tabText);
+            makeNewWindow();
             dataWindow->setContentNonOwned(canvas, false);
             dataWindow->setVisible(true);
             //canvas->refreshState();
@@ -228,15 +229,15 @@ void VisualizerEditor::buttonClicked(Button* button)
                 dataWindow->setVisible(false);
             }
 
-			tabIndex = AccessClass::getDataViewport()->addTabToDataViewport(tabText, canvas, this);
-
+            // tabIndex = AccessClass::getDataViewport()->addTabToDataViewport(tabText, canvas, this);
+            addTab(tabText, canvas);
 
         }
         else if (!tabSelector->getToggleState() && tabIndex > -1)
         {
-			AccessClass::getDataViewport()->destroyTab(tabIndex);
-            tabIndex = -1;
-
+            // AccessClass::getDataViewport()->destroyTab(tabIndex);
+            // tabIndex = -1;
+            removeTab(tabIndex);
         }
     }
 
@@ -313,6 +314,32 @@ void VisualizerEditor::loadCustomParameters(XmlElement* xml)
     }
 }
 
+void VisualizerEditor::makeNewWindow()
+{
+    dataWindow = new DataWindow(windowSelector, tabText);
+}
+
+Component* VisualizerEditor::getActiveTabContentComponent() const
+{
+    return AccessClass::getDataViewport()->getCurrentContentComponent();
+}
+
+void VisualizerEditor::setActiveTabId(int tindex)
+{
+    AccessClass::getDataViewport()->selectTab(tindex);
+}
+
+void VisualizerEditor::removeTab(int tindex)
+{
+    AccessClass::getDataViewport()->destroyTab(tindex);
+    tabIndex = -1;
+}
+
+int VisualizerEditor::addTab(String tab_text, Visualizer* vis_canvas)
+{
+    tabIndex = AccessClass::getDataViewport()->addTabToDataViewport(tab_text, vis_canvas, this);
+    return tabIndex;
+}
 
 void VisualizerEditor::saveVisualizerParameters(XmlElement* xml)
 {
diff --git a/Source/Processors/Editors/VisualizerEditor.h b/Source/Processors/Editors/VisualizerEditor.h
index dbf876746..52f166a3c 100755
--- a/Source/Processors/Editors/VisualizerEditor.h
+++ b/Source/Processors/Editors/VisualizerEditor.h
@@ -84,17 +84,17 @@ public:
     VisualizerEditor(GenericProcessor* processor, bool useDefaultParameterEditors);
     ~VisualizerEditor();
 
-	/**
+    /**
      * @brief      This method handles the button evnets which open visualizer in a tab or window.
      * @warning    Do not override this function unless you call ``VisualizerEditor::buttonClicked``
      *             somewhere!
      */
     void buttonClicked(Button* button);
-	
-	/**
+    
+    /**
      * @brief      All additional buttons that you create _for the editor_ should be handled here.
      */
-	virtual void buttonEvent(Button* button);
+    virtual void buttonEvent(Button* button);
 
     /**
      * @brief      Creates a new canvas. This is like a factory method and must be defined in your sub-class.
@@ -120,18 +120,61 @@ public:
 
     String tabText;
 
-private:
+protected: // these should be available to sub-classes if needed.
+    
+    /**
+     * @brief      Creates a new DataWindow using the windowSelector (button)
+     *             and ``tabText``. The new object is stored in (and owned by)
+     *             VisualizerEditor::dataWindow.
+     * @details    Use this to make a new DataWindow. If needed, you can
+     *             transfer ownership of the new object from
+     *             VisualizerEditor::dataWindow to _your_ own ScopedPointer.
+     */
+    void makeNewWindow();
 
-    void initializeSelectors();
-    bool isPlaying;
+    /**
+     * @brief      Use this to efficiently compare or find what is on the
+     *             currently active tab.
+     *
+     * @return     The active tab content Component.
+     */
+    Component* getActiveTabContentComponent() const;
 
+    /**
+     * @brief      Selects the specified _tab_ in the DataViewport.
+     *
+     * @param[in]  tindex  The index which was returned by VisualizerEditor::addTab
+     */
+    void setActiveTabId(int tindex);
+
+    /**
+     * @brief      Remove the specified tab from DataViewport.
+     *
+     * @param[in]  tindex  The index which was returned by VisualizerEditor::addTab
+     */
+    void removeTab(int tindex);
+
+    /**
+     * @brief      Adds a new tab to the DataViewport.
+     *
+     * @param[in]  tab_text    The tab text
+     * @param      vis_canvas  The content Visualizer (Canvas) Component for this tab.
+     *
+     * @return     The identifier token for this tab. You must provide this
+     *             identifier to access/remove this tab.
+     */
+    int addTab(String tab_text, Visualizer* vis_canvas);
+
+    bool isPlaying; /**< Acquisition status flag */
+
+    // So that we can override buttonClick. That's not possible if these are private.
     SelectorButton* windowSelector;
     SelectorButton* tabSelector;
 
+private:
+    void initializeSelectors();
     int tabIndex;
 
-
-
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VisualizerEditor);
 
 };
-- 
GitLab