//*CMZ :  2.23/03 27/09/99  10.05.28  by  Rene Brun
//*CMZ :  2.23/02 07/09/99  09.13.12  by  Rene Brun
//*-- Author :    Matthew.Adam.Dobbs   06/09/99

//*KEEP,CopyRight,T=C.
/*************************************************************************
 * Copyright(c) 1995-1999, The ROOT System, All rights reserved.         *
 * Authors: Rene Brun and Fons Rademakers.                               *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/AA_LICENSE.                      *
 * For the list of contributors see $ROOTSYS/AA_CREDITS.                 *
 *************************************************************************/
//*KEND.

//*KEEP,TLegendEntry,T=C++.
#include "TLegendEntry.h"
//*KEEP,TVirtualPad.
#include "TVirtualPad.h"
//*KEEP,TROOT.
#include "TROOT.h"
//*KEND.

#include <fstream.h>
#include <stdio.h>
#include <iostream.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;
  fLabel = 0;
  fOption = 0;
}

//____________________________________________________________________________
 TLegendEntry::TLegendEntry(TObject* obj, const Text_t* label, Option_t* option )
             :TAttText(0,0,0,0,0), TAttLine(0,0,0), TAttFill(0,0), TAttMarker(0,0,0)
{
  //___________________________________
  // 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 = obj;
  if ( !label && obj ) fLabel = obj->GetTitle();
  else {
    fLabel = label;
  }
  fOption = option;
}

//____________________________________________________________________________
 TLegendEntry::TLegendEntry( const TLegendEntry &entry )
{
  // TLegendEntry copy constructor
  ((TLegendEntry&)entry).Copy(*this);
}

//____________________________________________________________________________
 TLegendEntry::~TLegendEntry()
{
  // TLegendEntry default destructor
  fObject = 0;
  fLabel = 0;
  fOption = 0;
}

//____________________________________________________________________________
 void TLegendEntry::Copy( TObject &obj )
{
  // 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 *)
{
  // 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;
  else output = "NULL";
  cout << output << " Option ";
  if (fOption ) output = fOption;
  else output = "NULL";
  cout << output << endl;
}

//____________________________________________________________________________
 void TLegendEntry::SaveEntry( ofstream &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 << "   ";
  } else {
    out << "   TLegendEntry *";
  }
  TString objname = "NULL";
  TString label = fLabel;
  if ( fObject ) objname = fObject->GetName();
  out << "entry = " << name << "->AddEntry("<<objname<<","<<quote<<
    label<<quote<<","<<quote<<fOption<<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 ) {
    fLabel = obj->GetTitle();
  }
  fObject = obj;
}

//____________________________________________________________________________
 void TLegendEntry::SetObject( const Text_t* objectName)
{
  // (re)set the obj pointed to by this entry
  TObject* obj = 0;
  TList* padprimitives = gPad->GetListOfPrimitives();
  if ( padprimitives ) obj = padprimitives->FindObject( objectName );
  SetObject( obj );
}



ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.