simpleTableTest.C

Go to the documentation of this file.
00001 // This TableTest class is a simple example of how to use a TGSimpleTable 
00002 // that creates and owns it's own TGSimpleTableInterface. 
00003 // TableTest inherits from TGMainFrame to
00004 // create a top level frame to embed the TGTable in. First the data
00005 // needed is created. Then the TGSimpleTable is created using this
00006 // data. In the end, the table is added to the TGMainFrame that is the
00007 // TableTest and the necessary calls to correctly draw the window are
00008 // made. For more information about the use of TGSimpleTable see it's
00009 // documentation.
00010 
00011 // author: Roel Aaij 13/07/2007
00012 
00013 #include <iostream>
00014 #include <TApplication.h>
00015 #include <TGClient.h>
00016 #include <TGButton.h>
00017 #include <TGFrame.h>
00018 #include <TGLayout.h>
00019 #include <TGWindow.h>
00020 #include <TGLabel.h>
00021 #include <TGNumberEntry.h>
00022 #include <TString.h>
00023 #include <TGButtonGroup.h>
00024 #include <TGMenu.h>
00025 #include <TGSimpleTable.h>
00026 
00027 // A little class to automatically handle the generation of unique
00028 // widget ids.
00029 class IDList {
00030 private:
00031    Int_t nID ;               // Generates unique widget IDs.
00032 public:
00033    IDList() : nID(0) {}
00034    ~IDList() {}
00035    Int_t GetUnID(void) { return ++nID ; }
00036 } ;
00037 
00038 class TableTest : public TGMainFrame {
00039 
00040 private:
00041    IDList         IDs ;      // Generator for unique widget IDs.
00042    Double_t     **fData;
00043    UInt_t         fNDataRows;
00044    UInt_t         fNDataColumns;
00045    UInt_t         fNTableRows;
00046    UInt_t         fNTableColumns;
00047    TGSimpleTable *fSimpleTable;
00048    
00049 public:
00050    TableTest(const TGWindow *p, UInt_t ndrows, UInt_t ndcols, 
00051              UInt_t ntrows, UInt_t ntcols, UInt_t w = 100, UInt_t h = 100) ;
00052    virtual ~TableTest() ;
00053 
00054    void DoExit() ;
00055 
00056    TGSimpleTable *GetTable() { return fSimpleTable; }
00057 
00058    ClassDef(TableTest, 0)
00059 };
00060                           
00061 TableTest::TableTest(const TGWindow *p,  UInt_t ndrows, UInt_t ndcols, 
00062                      UInt_t ntrows, UInt_t ntcols, UInt_t w, UInt_t h) 
00063    : TGMainFrame(p, w, h), fData(0), fNDataRows(ndrows), fNDataColumns(ndcols),
00064      fNTableRows(ntrows), fNTableColumns(ntcols), fSimpleTable(0)
00065 {
00066    SetCleanup(kDeepCleanup) ;   
00067    Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
00068    DontCallClose() ;
00069       
00070    // Create the needed data.
00071    Int_t i = 0, j = 0; 
00072    fData = new Double_t*[fNDataRows];
00073    for (i = 0; i < (Int_t)fNDataRows; i++) {
00074       fData[i] = new Double_t[fNDataColumns];
00075       for (j = 0; j < (Int_t)fNDataColumns; j++) {
00076          fData[i][j] = 10 * i + j;
00077       }
00078    }
00079    
00080    // Create the table and add it to the TableTest that is a TGMainFrame.
00081    fSimpleTable = new TGSimpleTable(this, IDs.GetUnID(), fData, fNTableRows, 
00082                                     fNTableColumns);
00083    AddFrame(fSimpleTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00084    
00085    // Calls to layout and draw the TableTest that is a TGMainFrame.
00086    SetWindowName("TGSimpleTable Test") ;
00087    MapSubwindows() ;
00088    Layout();
00089    Resize(GetDefaultWidth()+20, 600) ;
00090    MapWindow() ;
00091    
00092 } ;
00093 
00094 TableTest::~TableTest()
00095 {
00096    // Destructor
00097    UInt_t i = 0; 
00098    for (i = 0; i < fNDataRows; i++) {
00099       delete[] fData[i];
00100    }
00101    delete[] fData;
00102    Cleanup() ;
00103  }
00104  
00105  void TableTest::DoExit()
00106 {
00107    // Exit this application via the Exit button or Window Manager.
00108    // Use one of the both lines according to your needs.
00109    // Please note to re-run this macro in the same ROOT session,
00110    // you have to compile it to get signals/slots 'on place'.
00111    
00112    DeleteWindow();            // to stay in the ROOT session
00113    //   gApplication->Terminate();   // to exit and close the ROOT session   
00114 }
00115 
00116 TGSimpleTable *simpleTableTest(UInt_t ndrows = 500, UInt_t ndcols = 20, 
00117                    UInt_t ntrows = 50, UInt_t ntcols = 10) {
00118    TableTest *test = new TableTest(0, ndrows, ndcols, ntrows, ntcols, 500, 200);
00119    return test->GetTable();
00120 }

Generated on Tue Jul 5 15:44:26 2011 for ROOT_528-00b_version by  doxygen 1.5.1