TLegendEntry.cxx

Go to the documentation of this file.
00001 // @(#)root/graf:$Id: TLegendEntry.cxx 35839 2010-09-28 13:17:21Z brun $
00002 // Author: Matthew.Adam.Dobbs   06/09/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include <stdio.h>
00013 
00014 #include "TLegendEntry.h"
00015 #include "TVirtualPad.h"
00016 #include "TROOT.h"
00017 #include "Riostream.h"
00018 
00019 
00020 ClassImp(TLegendEntry)
00021 
00022 
00023 //____________________________________________________________________________
00024 // TLegendEntry   Matthew.Adam.Dobbs@Cern.CH, September 1999
00025 // Storage class for one entry of a TLegend
00026 //
00027 
00028 
00029 //____________________________________________________________________________
00030 TLegendEntry::TLegendEntry(): TAttText(), TAttLine(), TAttFill(), TAttMarker()
00031 {
00032    // TLegendEntry do-nothing default constructor
00033 
00034    fObject = 0;
00035 }
00036 
00037 
00038 //____________________________________________________________________________
00039 TLegendEntry::TLegendEntry(const TObject* obj, const char* label, Option_t* option )
00040              :TAttText(0,0,0,0,0), TAttLine(1,1,1), TAttFill(0,0), TAttMarker(1,21,1)
00041 {
00042    // TLegendEntry normal constructor for one entry in a TLegend
00043    //   obj is the object this entry will represent. If obj has
00044    //   line/fill/marker attributes, then the TLegendEntry will display
00045    //   these attributes.
00046    //   label is the text that will describe the entry, it is displayed using
00047    //   TLatex, so may have a complex format.
00048    //   option may have values
00049    //    L draw line associated w/ TAttLine if obj inherits from TAttLine
00050    //    P draw polymarker assoc. w/ TAttMarker if obj inherits from TAttMarker
00051    //    F draw a box with fill associated w/ TAttFill if obj inherits TAttFill
00052    //   default is object = "LPF"
00053 
00054    fObject = 0;
00055    if ( !label && obj ) fLabel = obj->GetTitle();
00056    else                 fLabel = label;
00057    fOption = option;
00058    if (obj) SetObject((TObject*)obj);
00059 }
00060 
00061 
00062 //____________________________________________________________________________
00063 TLegendEntry::TLegendEntry( const TLegendEntry &entry ) : TObject(entry), TAttText(entry), TAttLine(entry), TAttFill(entry), TAttMarker(entry)
00064 {
00065    // TLegendEntry copy constructor
00066 
00067    ((TLegendEntry&)entry).Copy(*this);
00068 }
00069 
00070 
00071 //____________________________________________________________________________
00072 TLegendEntry::~TLegendEntry()
00073 {
00074    // TLegendEntry default destructor
00075 
00076    fObject = 0;
00077 }
00078 
00079 
00080 //____________________________________________________________________________
00081 void TLegendEntry::Copy( TObject &obj ) const
00082 {
00083    // copy this TLegendEntry into obj
00084 
00085    TObject::Copy(obj);
00086    TAttText::Copy((TLegendEntry&)obj);
00087    TAttLine::Copy((TLegendEntry&)obj);
00088    TAttFill::Copy((TLegendEntry&)obj);
00089    TAttMarker::Copy((TLegendEntry&)obj);
00090    ((TLegendEntry&)obj).fObject = fObject;
00091    ((TLegendEntry&)obj).fLabel = fLabel;
00092    ((TLegendEntry&)obj).fOption = fOption;
00093 }
00094 
00095 
00096 //____________________________________________________________________________
00097 void TLegendEntry::Print( Option_t *) const
00098 {
00099    // dump this TLegendEntry to cout
00100 
00101    TString output;
00102    cout << "TLegendEntry: Object ";
00103    if ( fObject ) output = fObject->GetName();
00104    else output = "NULL";
00105    cout << output << " Label ";
00106    if ( fLabel ) output = fLabel.Data();
00107    else output = "NULL";
00108    cout << output << " Option ";
00109    if (fOption ) output = fOption.Data();
00110    else output = "NULL";
00111    cout << output << endl;
00112 }
00113 
00114 
00115 //____________________________________________________________________________
00116 void TLegendEntry::SaveEntry(ostream &out, const char* name )
00117 {
00118    // Save this TLegendEntry as C++ statements on output stream out
00119    //  to be used with the SaveAs .C option
00120 
00121    char quote = '"';
00122    if ( gROOT->ClassSaved( TLegendEntry::Class() ) ) {
00123       out << "   entry=";
00124    } else {
00125       out << "   TLegendEntry *entry=";
00126    }
00127    TString objname = "NULL";
00128    if ( fObject ) objname = fObject->GetName();
00129    out << name << "->AddEntry("<<quote<<objname<<quote<<","<<quote<<
00130       fLabel.Data()<<quote<<","<<quote<<fOption.Data()<<quote<<");"<<endl;
00131    SaveFillAttributes(out,"entry",0,0);
00132    SaveLineAttributes(out,"entry",0,0,0);
00133    SaveMarkerAttributes(out,"entry",0,0,0);
00134    SaveTextAttributes(out,"entry",0,0,0,0,0);
00135 }
00136 
00137 
00138 //____________________________________________________________________________
00139 void TLegendEntry::SetObject(TObject* obj )
00140 {
00141    // (re)set the obj pointed to by this entry
00142 
00143    if ( ( fObject && fLabel == fObject->GetTitle() ) || !fLabel ) {
00144       if (obj) fLabel = obj->GetTitle();
00145    }
00146    fObject = obj;
00147 }
00148 
00149 
00150 //____________________________________________________________________________
00151 void TLegendEntry::SetObject( const char* objectName)
00152 {
00153    // (re)set the obj pointed to by this entry
00154 
00155    TObject* obj = 0;
00156    TList* padprimitives = gPad->GetListOfPrimitives();
00157    if (padprimitives) obj = padprimitives->FindObject( objectName );
00158    if (obj) SetObject( obj );
00159 }

Generated on Tue Jul 5 14:14:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1