casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotAnnotation.h
Go to the documentation of this file.
00001 //# PlotAnnotation.h: Annotation class that can be drawn on a canvas.
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 PLOTANNOTATION_H_
00028 #define PLOTANNOTATION_H_
00029 
00030 #include <graphics/GenericPlotter/PlotItem.h>
00031 
00032 #include <casa/BasicSL/String.h>
00033 
00034 #include <casa/namespace.h>
00035 
00036 namespace casa {
00037 
00038 // PlotAnnotation is an abstraction of text written directly on the canvas.  An
00039 // annotation has text, font, orientation, outline, and background properties.
00040 class PlotAnnotation : public virtual PlotItem {
00041 public:
00042     // Constructor.
00043     PlotAnnotation() { }
00044     
00045     // Destructor.
00046     virtual ~PlotAnnotation() { }
00047     
00048     
00049     // Implements PlotItem::drawCount().  Provides default implementation that
00050     // returns 1.
00051     virtual unsigned int drawCount() const { return 1; }
00052     
00053     // ABSTRACT METHODS //
00054     
00055     // Returns the text of the annotation.
00056     virtual String text() const = 0;
00057     
00058     // Sets the text of the annotation.
00059     virtual void setText(const String& newText) = 0;
00060     
00061     // Returns a copy of the font used in the annotation.
00062     virtual PlotFontPtr font() const = 0;
00063     
00064     // Sets the annotation font to the given.
00065     virtual void setFont(const PlotFont& font) = 0;
00066     
00067     // Returns orientation in counterclockwise degrees (between 0 and 360).
00068     virtual int orientation() const = 0;
00069     
00070     // Sets the orientation in counterclockwise degrees (between 0 and 360).
00071     virtual void setOrientation(int orientation) = 0;
00072     
00073     // Returns the coordinate where the annotation is located on the canvas it
00074     // is attached to.
00075     virtual PlotCoordinate coordinate() const = 0;
00076     
00077     // Sets the location of the annotation to the given.
00078     virtual void setCoordinate(const PlotCoordinate& coord) = 0;
00079     
00080     // Returns true if an outline is shown around the annotation, false
00081     // otherwise.
00082     virtual bool outlineShown() const = 0;
00083     
00084     // Sets whether an outline is shown around the annotation.
00085     virtual void setOutlineShown(bool show = true) = 0;
00086     
00087     // Returns a copy of the line used to draw the outline for this annotation.
00088     virtual PlotLinePtr outline() const = 0;
00089     
00090     // Sets the outline to the given line.
00091     virtual void setOutline(const PlotLine& line) = 0;
00092     
00093     // Returns a copy of the area fill used for the annotation's background.
00094     virtual PlotAreaFillPtr background() const = 0;
00095     
00096     // Sets the annotation's background to the given.
00097     virtual void setBackground(const PlotAreaFill& area) = 0;
00098     
00099     
00100     // IMPLEMENTED METHODS //
00101     
00102     // Convenience methods for setting font.
00103     // <group>
00104     virtual void setFont(const PlotFontPtr font) {
00105         if(!font.null()) setFont(*font); }
00106     virtual void setFontColor(const String& color) {
00107         PlotFontPtr f = font();
00108         f->setColor(color);
00109         setFont(*f);
00110     }
00111     // </group>
00112     
00113     // Convenience methods for setting the outline.
00114     // <group>
00115     virtual void setOutline(const PlotLinePtr line) {
00116         if(!line.null()) setOutline(*line);
00117         else             setOutlineShown(false);
00118     }
00119     virtual void setOutline(const String& color,
00120             PlotLine::Style style = PlotLine::SOLID, double width = 1.0) {
00121         PlotLinePtr line = outline();
00122         line->setColor(color);
00123         line->setStyle(style);
00124         line->setWidth(width);
00125         setOutline(*line);
00126     }
00127     // </group>
00128     
00129     // Convenience methods for setting the background.
00130     // <group>
00131     virtual void setBackground(const PlotAreaFillPtr area) {
00132         if(!area.null()) setBackground(*area); }
00133     virtual void setBackground(const String& color,
00134             PlotAreaFill::Pattern pattern = PlotAreaFill::FILL) {
00135         PlotAreaFillPtr bg = background();
00136         bg->setColor(color);
00137         bg->setPattern(pattern);
00138         setBackground(*bg);
00139     }
00140     // </group>
00141 };
00142 INHERITANCE_POINTER2(PlotAnnotation, PlotAnnotationPtr, PlotItem, PlotItemPtr)
00143 
00144 }
00145 
00146 #endif /*PLOTANNOTATION_H_*/