ROOT logo
// @(#)root/graf:$Id$
// Author: Matthew.Adam.Dobbs   06/09/99

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include <stdio.h>

#include "TLegendEntry.h"
#include "TVirtualPad.h"
#include "TROOT.h"
#include "Riostream.h"


ClassImp(TLegendEntry)


//____________________________________________________________________________
// TLegendEntry   Matthew.Adam.Dobbs@Cern.CH, September 1999
// Storage class for one entry of a TLegend
//


//____________________________________________________________________________
TLegendEntry::TLegendEntry(): TAttText(), TAttLine(), TAttFill(), TAttMarker()
{
   // TLegendEntry do-nothing default constructor

   fObject = 0;
}


//____________________________________________________________________________
TLegendEntry::TLegendEntry(const TObject* obj, const char* label, Option_t* option )
             :TAttText(0,0,0,0,0), TAttLine(1,1,1), TAttFill(0,0), TAttMarker(1,21,1)
{
   // TLegendEntry normal constructor for one entry in a TLegend
   //   obj is the object this entry will represent. If obj has
   //   line/fill/marker attributes, then the TLegendEntry will display
   //   these attributes.
   //   label is the text that will describe the entry, it is displayed using
   //   TLatex, so may have a complex format.
   //   option may have values
   //    L draw line associated w/ TAttLine if obj inherits from TAttLine
   //    P draw polymarker assoc. w/ TAttMarker if obj inherits from TAttMarker
   //    F draw a box with fill associated w/ TAttFill if obj inherits TAttFill
   //   default is object = "LPF"

   fObject = 0;
   if ( !label && obj ) fLabel = obj->GetTitle();
   else                 fLabel = label;
   fOption = option;
   if (obj) SetObject((TObject*)obj);
}


//____________________________________________________________________________
TLegendEntry::TLegendEntry( const TLegendEntry &entry ) : TObject(entry), TAttText(entry), TAttLine(entry), TAttFill(entry), TAttMarker(entry)
{
   // TLegendEntry copy constructor

   ((TLegendEntry&)entry).Copy(*this);
}


//____________________________________________________________________________
TLegendEntry::~TLegendEntry()
{
   // TLegendEntry default destructor

   fObject = 0;
}


//____________________________________________________________________________
void TLegendEntry::Copy( TObject &obj ) const
{
   // copy this TLegendEntry into obj

   TObject::Copy(obj);
   TAttText::Copy((TLegendEntry&)obj);
   TAttLine::Copy((TLegendEntry&)obj);
   TAttFill::Copy((TLegendEntry&)obj);
   TAttMarker::Copy((TLegendEntry&)obj);
   ((TLegendEntry&)obj).fObject = fObject;
   ((TLegendEntry&)obj).fLabel = fLabel;
   ((TLegendEntry&)obj).fOption = fOption;
}


//____________________________________________________________________________
void TLegendEntry::Print( Option_t *) const
{
   // dump this TLegendEntry to cout

   TString output;
   cout << "TLegendEntry: Object ";
   if ( fObject ) output = fObject->GetName();
   else output = "NULL";
   cout << output << " Label ";
   if ( fLabel ) output = fLabel.Data();
   else output = "NULL";
   cout << output << " Option ";
   if (fOption ) output = fOption.Data();
   else output = "NULL";
   cout << output << endl;
}


//____________________________________________________________________________
void TLegendEntry::SaveEntry(ostream &out, const char* name )
{
   // Save this TLegendEntry as C++ statements on output stream out
   //  to be used with the SaveAs .C option

   char quote = '"';
   if ( gROOT->ClassSaved( TLegendEntry::Class() ) ) {
      out << "   entry=";
   } else {
      out << "   TLegendEntry *entry=";
   }
   TString objname = "NULL";
   if ( fObject ) objname = fObject->GetName();
   out << name << "->AddEntry("<<quote<<objname<<quote<<","<<quote<<
      fLabel.Data()<<quote<<","<<quote<<fOption.Data()<<quote<<");"<<endl;
   SaveFillAttributes(out,"entry",0,0);
   SaveLineAttributes(out,"entry",0,0,0);
   SaveMarkerAttributes(out,"entry",0,0,0);
   SaveTextAttributes(out,"entry",0,0,0,0,0);
}


//____________________________________________________________________________
void TLegendEntry::SetObject(TObject* obj )
{
   // (re)set the obj pointed to by this entry

   if ( ( fObject && fLabel == fObject->GetTitle() ) || !fLabel ) {
      if (obj) fLabel = obj->GetTitle();
   }
   fObject = obj;
}


//____________________________________________________________________________
void TLegendEntry::SetObject( const char* objectName)
{
   // (re)set the obj pointed to by this entry

   TObject* obj = 0;
   TList* padprimitives = gPad->GetListOfPrimitives();
   if (padprimitives) obj = padprimitives->FindObject( objectName );
   if (obj) SetObject( obj );
}
 TLegendEntry.cxx:1
 TLegendEntry.cxx:2
 TLegendEntry.cxx:3
 TLegendEntry.cxx:4
 TLegendEntry.cxx:5
 TLegendEntry.cxx:6
 TLegendEntry.cxx:7
 TLegendEntry.cxx:8
 TLegendEntry.cxx:9
 TLegendEntry.cxx:10
 TLegendEntry.cxx:11
 TLegendEntry.cxx:12
 TLegendEntry.cxx:13
 TLegendEntry.cxx:14
 TLegendEntry.cxx:15
 TLegendEntry.cxx:16
 TLegendEntry.cxx:17
 TLegendEntry.cxx:18
 TLegendEntry.cxx:19
 TLegendEntry.cxx:20
 TLegendEntry.cxx:21
 TLegendEntry.cxx:22
 TLegendEntry.cxx:23
 TLegendEntry.cxx:24
 TLegendEntry.cxx:25
 TLegendEntry.cxx:26
 TLegendEntry.cxx:27
 TLegendEntry.cxx:28
 TLegendEntry.cxx:29
 TLegendEntry.cxx:30
 TLegendEntry.cxx:31
 TLegendEntry.cxx:32
 TLegendEntry.cxx:33
 TLegendEntry.cxx:34
 TLegendEntry.cxx:35
 TLegendEntry.cxx:36
 TLegendEntry.cxx:37
 TLegendEntry.cxx:38
 TLegendEntry.cxx:39
 TLegendEntry.cxx:40
 TLegendEntry.cxx:41
 TLegendEntry.cxx:42
 TLegendEntry.cxx:43
 TLegendEntry.cxx:44
 TLegendEntry.cxx:45
 TLegendEntry.cxx:46
 TLegendEntry.cxx:47
 TLegendEntry.cxx:48
 TLegendEntry.cxx:49
 TLegendEntry.cxx:50
 TLegendEntry.cxx:51
 TLegendEntry.cxx:52
 TLegendEntry.cxx:53
 TLegendEntry.cxx:54
 TLegendEntry.cxx:55
 TLegendEntry.cxx:56
 TLegendEntry.cxx:57
 TLegendEntry.cxx:58
 TLegendEntry.cxx:59
 TLegendEntry.cxx:60
 TLegendEntry.cxx:61
 TLegendEntry.cxx:62
 TLegendEntry.cxx:63
 TLegendEntry.cxx:64
 TLegendEntry.cxx:65
 TLegendEntry.cxx:66
 TLegendEntry.cxx:67
 TLegendEntry.cxx:68
 TLegendEntry.cxx:69
 TLegendEntry.cxx:70
 TLegendEntry.cxx:71
 TLegendEntry.cxx:72
 TLegendEntry.cxx:73
 TLegendEntry.cxx:74
 TLegendEntry.cxx:75
 TLegendEntry.cxx:76
 TLegendEntry.cxx:77
 TLegendEntry.cxx:78
 TLegendEntry.cxx:79
 TLegendEntry.cxx:80
 TLegendEntry.cxx:81
 TLegendEntry.cxx:82
 TLegendEntry.cxx:83
 TLegendEntry.cxx:84
 TLegendEntry.cxx:85
 TLegendEntry.cxx:86
 TLegendEntry.cxx:87
 TLegendEntry.cxx:88
 TLegendEntry.cxx:89
 TLegendEntry.cxx:90
 TLegendEntry.cxx:91
 TLegendEntry.cxx:92
 TLegendEntry.cxx:93
 TLegendEntry.cxx:94
 TLegendEntry.cxx:95
 TLegendEntry.cxx:96
 TLegendEntry.cxx:97
 TLegendEntry.cxx:98
 TLegendEntry.cxx:99
 TLegendEntry.cxx:100
 TLegendEntry.cxx:101
 TLegendEntry.cxx:102
 TLegendEntry.cxx:103
 TLegendEntry.cxx:104
 TLegendEntry.cxx:105
 TLegendEntry.cxx:106
 TLegendEntry.cxx:107
 TLegendEntry.cxx:108
 TLegendEntry.cxx:109
 TLegendEntry.cxx:110
 TLegendEntry.cxx:111
 TLegendEntry.cxx:112
 TLegendEntry.cxx:113
 TLegendEntry.cxx:114
 TLegendEntry.cxx:115
 TLegendEntry.cxx:116
 TLegendEntry.cxx:117
 TLegendEntry.cxx:118
 TLegendEntry.cxx:119
 TLegendEntry.cxx:120
 TLegendEntry.cxx:121
 TLegendEntry.cxx:122
 TLegendEntry.cxx:123
 TLegendEntry.cxx:124
 TLegendEntry.cxx:125
 TLegendEntry.cxx:126
 TLegendEntry.cxx:127
 TLegendEntry.cxx:128
 TLegendEntry.cxx:129
 TLegendEntry.cxx:130
 TLegendEntry.cxx:131
 TLegendEntry.cxx:132
 TLegendEntry.cxx:133
 TLegendEntry.cxx:134
 TLegendEntry.cxx:135
 TLegendEntry.cxx:136
 TLegendEntry.cxx:137
 TLegendEntry.cxx:138
 TLegendEntry.cxx:139
 TLegendEntry.cxx:140
 TLegendEntry.cxx:141
 TLegendEntry.cxx:142
 TLegendEntry.cxx:143
 TLegendEntry.cxx:144
 TLegendEntry.cxx:145
 TLegendEntry.cxx:146
 TLegendEntry.cxx:147
 TLegendEntry.cxx:148
 TLegendEntry.cxx:149
 TLegendEntry.cxx:150
 TLegendEntry.cxx:151
 TLegendEntry.cxx:152
 TLegendEntry.cxx:153
 TLegendEntry.cxx:154
 TLegendEntry.cxx:155
 TLegendEntry.cxx:156
 TLegendEntry.cxx:157
 TLegendEntry.cxx:158
 TLegendEntry.cxx:159