casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotPanel.h
Go to the documentation of this file.
00001 //# PlotPanel.h: Custom plot panels and buttons.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef PLOTPANEL_H_
00028 #define PLOTPANEL_H_
00029 
00030 #include <graphics/GenericPlotter/PlotEventHandler.h>
00031 
00032 #include <casa/namespace.h>
00033 
00034 namespace casa {
00035 
00036 // Abstract superclass for any widget that goes on a PlotPanel.
00037 class PlotWidget {
00038 public:
00039     // Constructor.
00040     PlotWidget() { }
00041     
00042     // Destructor.
00043     virtual ~PlotWidget() { }
00044     
00045     // Returns true if the widget is currently enabled, false otherwise.
00046     // A widget button should be grayed out or not interact-able.
00047     virtual bool isEnabled() const = 0;
00048     
00049     // Enables/disables the widget.
00050     virtual void setEnabled(bool enabled = true) = 0;
00051     
00052     // Returns true if the widget is currently visible.
00053     virtual bool isVisible() const = 0;
00054     
00055     // Show/hide the widget.
00056     virtual void setVisible(bool visible = true) = 0;
00057     
00058     // Returns the tooltip for this widget.
00059     virtual String tooltip() const = 0;
00060     
00061     // Sets the tooltip for this widget.
00062     virtual void setTooltip(const String& text) = 0;
00063 };
00064 typedef CountedPtr<PlotWidget> PlotWidgetPtr;
00065 
00066 
00067 // Generic class for a button that goes on a PlotPanel.  A button has
00068 // properties that can be set, as well as registration for event
00069 // handlers.  A button can only be seen/interacted with on a PlotPanel.
00070 class PlotButton : public virtual PlotWidget {
00071 public:
00072     // Constructor.
00073     PlotButton() { }
00074     
00075     // Destructor.
00076     virtual ~PlotButton() { }
00077     
00078     // Returns true if text is being shown on the button, false otherwise.
00079     virtual bool textShown() const = 0;
00080     
00081     // Show/hide the set text on the button.
00082     virtual void showText(bool show = true) = 0;
00083     
00084     // Currently set button text.  (May not be displayed.)
00085     virtual String text() const = 0;
00086     
00087     // Sets the button text.
00088     virtual void setText(const String& text) = 0;
00089     
00090     // Returns true if an image is being shown on the button, false otherwise.
00091     virtual bool imageShown() const = 0;
00092     
00093     // Show/hide the set image on the button.
00094     virtual void showImage(bool show = true) = 0;
00095     
00096     // Set the image path to be shown on the button.
00097     virtual void setImagePath(const String& imgPath) = 0;
00098     
00099     // Returns true if the button is "toggleable", false otherwise.  A button
00100     // that is toggleable sticks down when pushed, then comes back up when
00101     // pushed again.  The state can be determined with isToggled().
00102     virtual bool isToggleable() const = 0;
00103     
00104     // Sets whether this button is "toggleable" or not.
00105     virtual void setToggleable(bool toggleable = true) = 0;
00106     
00107     // Returns whether this button is in a toggled state or not.
00108     virtual bool isToggled() const = 0;
00109     
00110     // Sets whether this button is in a toggled state or not.  (Does not
00111     // affect buttons that are not toggleable.)
00112     virtual void setToggled(bool toggled = true) = 0;
00113     
00114     // Register the given event handler for this button.
00115     virtual void registerHandler(PlotButtonEventHandlerPtr handler) = 0;
00116     
00117     // Returns all event handlers currently registered on this button.
00118     virtual vector<PlotButtonEventHandlerPtr> allHandlers() const = 0;
00119     
00120     // Unregisters the given event handler.
00121     virtual void unregisterHandler(PlotButtonEventHandlerPtr handler) = 0;
00122 };
00123 
00124 
00125 // Generic class for a checkbox that goes on a PlotPanel.  A checkbox has
00126 // properties that can be set, as well as registration for event
00127 // handlers.  A checkbox can only be seen/interacted with on a PlotPanel.
00128 class PlotCheckbox : public virtual PlotWidget {
00129 public:
00130     // Constructor.
00131     PlotCheckbox() { }
00132     
00133     // Destructor.
00134     virtual ~PlotCheckbox() { }
00135     
00136     // Returns the text for this checkbox.
00137     virtual String text() const = 0;
00138     
00139     // Sets the text for this checkbox.
00140     virtual void setText(const String& text) = 0;
00141     
00142     // Returns true if the checkbox is currently checked, false otherwise.
00143     virtual bool isChecked() const = 0;
00144     
00145     // Sets whether the checkbox is checked or not.
00146     virtual void setChecked(bool checked = true) = 0;
00147     
00148     // Register the given event handler for this checkbox.
00149     virtual void registerHandler(PlotCheckboxEventHandlerPtr handler) = 0;
00150     
00151     // Returns all event handlers currently registered on this button.
00152     virtual vector<PlotCheckboxEventHandlerPtr> allHandlers() const = 0;
00153     
00154     // Unregisters the given event handler.
00155     virtual void unregisterHandler(PlotCheckboxEventHandlerPtr handler) = 0;
00156 };
00157 
00158 
00159 // A PlotPanel is a panel that goes on the bottom of the plot window.  A
00160 // single panel can contain multiple widgets.
00161 class PlotPanel {
00162 public:
00163     PlotPanel() { }
00164     
00165     virtual ~PlotPanel() { }
00166     
00167     // Returns all PlotWidgets currently on the panel.
00168     virtual vector<PlotWidgetPtr> widgets() const = 0;
00169     
00170     // Adds the given widget to this panel.
00171     virtual int addWidget(PlotWidgetPtr widget) = 0;
00172     
00173     // Clears all widgets on the panel.
00174     virtual void clearWidgets() = 0;
00175     
00176     // Removes the given widget from this panel.
00177     virtual void removeWidget(PlotWidgetPtr widget) = 0;
00178     
00179     // Removes the widget at the given index from this panel.
00180     virtual void removeWidget(int index) = 0;
00181 };
00182 
00183 
00185 // SMART POINTER DEFINITIONS //
00187 
00188 INHERITANCE_POINTER2(PlotButton, PlotButtonPtr, PlotWidget, PlotWidgetPtr)
00189 INHERITANCE_POINTER2(PlotCheckbox, PlotCheckboxPtr, PlotWidget, PlotWidgetPtr)
00190 typedef CountedPtr<PlotPanel> PlotPanelPtr;
00191 
00192 }
00193 
00194 #endif /*PLOTPANEL_H_*/