00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00025
00026
00027
00028
00029
00030 TLegendEntry::TLegendEntry(): TAttText(), TAttLine(), TAttFill(), TAttMarker()
00031 {
00032
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
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
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
00066
00067 ((TLegendEntry&)entry).Copy(*this);
00068 }
00069
00070
00071
00072 TLegendEntry::~TLegendEntry()
00073 {
00074
00075
00076 fObject = 0;
00077 }
00078
00079
00080
00081 void TLegendEntry::Copy( TObject &obj ) const
00082 {
00083
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
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
00119
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
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
00154
00155 TObject* obj = 0;
00156 TList* padprimitives = gPad->GetListOfPrimitives();
00157 if (padprimitives) obj = padprimitives->FindObject( objectName );
00158 if (obj) SetObject( obj );
00159 }