00001
00002 #ifndef Impala_Visualization_DataDocumentGui_h
00003 #define Impala_Visualization_DataDocumentGui_h
00004
00005
00006 #include "Visualization/AppControlDoc.h"
00007 #include "Visualization/Window.h"
00008 #include "OglGui/StringSelector.h"
00009 #include "OglGui/StringListener.h"
00010 #include "OglGui/TextArea.h"
00011 #include "OglGui/TextField.h"
00012 #include "OglGui/Strut.h"
00013 #include "OglGui/Button.h"
00014 #include "OglGui/MenuOnButton.h"
00015
00016 namespace Impala {
00017 namespace Visualization {
00018
00019 template <class DataDocT>
00020 class DataDocumentGui : public Window, public AppControlDoc,
00021 public Core::Database::DataDocumentListener,
00022 public OglGui::StringListener,
00023 public OglGui::ButtonListener
00024 {
00025 public:
00026
00027 static const int STRING_DIR = 1;
00028 static const int STRING_FILE = 2;
00029 static const int STRING_BOOK = 3;
00030
00031 static const int BUT_CONCEPT = 1;
00032 static const int BUT_ADD_CONCEPT = 2;
00033 static const int BUT_LOAD_CONCEPTS = 3;
00034 static const int BUT_SAVE_CONCEPTS = 4;
00035 static const int BUT_BOOKMARK = 5;
00036 static const int BUT_UNBOOKMARK = 6;
00037 static const int BUT_CLEAR_BOOKMARKED = 7;
00038 static const int BUT_LOAD_BOOKMARKED = 8;
00039 static const int BUT_SAVE_BOOKMARKED = 9;
00040
00041 DataDocumentGui(OglGui::Window* parent, int wndWidth, int wndHeight,
00042 DataDocT* dataDoc, int controlId,
00043 bool showFiles = true, bool showBookList = true,
00044 bool infoOnly = false, int nrOnRow = 3, int nrLines = 12,
00045 bool showAnno = true, bool showBookBut = true) :
00046 Window(parent, wndWidth, wndHeight, true),
00047 AppControlDoc(controlId, dataDoc)
00048 {
00049 mDataDoc = dataDoc;
00050 AddDocListener(this);
00051
00052 int width = (wndWidth - 15) / nrOnRow;
00053 int line = 20;
00054 mInfoText1 = mInfoText2 = mInfoText3 = 0;
00055 mStringSelector1 = mStringSelector2 = mStringSelector3 = 0;
00056
00057 if (showFiles)
00058 {
00059 mInfoText1 = new OglGui::TextArea(this, width, 1*line, "set info",
00060 false);
00061 if (nrOnRow >= 2)
00062 mInfoText2 = new OglGui::TextArea(this, width, 1*line,
00063 "file info", false);
00064 }
00065 if ((showBookList) && (nrOnRow >= 3))
00066 mInfoText3 = new OglGui::TextArea(this, width, 1*line,
00067 "bookmark info", false);
00068
00069 if (showFiles)
00070 {
00071 if (!infoOnly)
00072 {
00073 int nDir = mDataDoc->GetDataSet()->NrDirs();
00074 int sH = line * ((nrOnRow<2&&nDir<nrLines) ? nDir+1 : nrLines);
00075 mStringSelector1 = new OglGui::StringSelector(this, width, sH);
00076 mStringSelector1->SetStringListener(this, STRING_DIR);
00077 mStringSelector1->GuiName("dataDirSelector");
00078
00079 }
00080 if (nrOnRow < 2)
00081 {
00082 new OglGui::Strut(this, 4000, 1);
00083 mInfoText2 = new OglGui::TextArea(this,width,line,"file info",
00084 false);
00085 }
00086 mStringSelector2 = new OglGui::StringSelector(this, width,
00087 nrLines*line);
00088 mStringSelector2->SetStringListener(this, STRING_FILE);
00089 mStringSelector2->GuiName("dataFileSelector");
00090
00091 }
00092
00093 if (showBookList)
00094 {
00095 if (nrOnRow < 3)
00096 {
00097 new OglGui::Strut(this, 4000, 1);
00098 mInfoText3 = new OglGui::TextArea(this, wndWidth, 1*line,
00099 "bookmark info");
00100 mInfoText3->SetBorderType(0);
00101 }
00102 if (!infoOnly)
00103 {
00104 mStringSelector3 = new OglGui::StringSelector(this, width,
00105 nrLines*line);
00106 mStringSelector3->SetStringListener(this, STRING_BOOK);
00107 mStringSelector3->GuiName("dataBookmarkSelector");
00108
00109 }
00110 }
00111
00112 OglGui::Button* but;
00113 OglGui::TextArea* tArea;
00114 mConceptField = 0;
00115
00116 if (showAnno)
00117 {
00118
00119 but = new OglGui::MenuOnButton(this, 100, 22, "Concept");
00120 but->SetButtonListener(this, BUT_CONCEPT);
00121 mConceptField = new OglGui::TextField(this, 160, 22, "");
00122 but = new OglGui::Button(this, 80, 22, "Add",4,true);
00123 but->SetButtonListener(this, BUT_ADD_CONCEPT);
00124 new OglGui::Strut(this, 50, 1);
00125 tArea = new OglGui::TextArea(this, 80, 1*line, "Concepts",false);
00126
00127 but = new OglGui::Button(this, 60, 22, "Load",4,true);
00128 but->SetButtonListener(this, BUT_LOAD_CONCEPTS);
00129 but = new OglGui::Button(this, 60, 22, "Save",4,true);
00130 but->SetButtonListener(this, BUT_SAVE_CONCEPTS);
00131 mConceptFileField = new OglGui::TextField(this, 190, 22,
00132 "concept.txt");
00133 }
00134
00135 if (showBookBut)
00136 {
00137 new OglGui::Strut(this, 4000, 1);
00138
00139 tArea = new OglGui::TextArea(this, 65, line, "Cursor");
00140 tArea->SetBorderType(0);
00141 but = new OglGui::Button(this, 105, 22, "Bookmark (b)");
00142 but->SetButtonListener(this, BUT_BOOKMARK);
00143 but = new OglGui::Button(this, 115, 22, "Unbookmark (B)");
00144 but->SetButtonListener(this, BUT_UNBOOKMARK);
00145 new OglGui::Strut(this, 50, 1);
00146 tArea = new OglGui::TextArea(this, 80, 1*line, "Bookmarks");
00147 tArea->SetBorderType(0);
00148 but = new OglGui::Button(this, 60, 22, "Clear");
00149 but->SetButtonListener(this, BUT_CLEAR_BOOKMARKED);
00150 but = new OglGui::Button(this, 60, 22, "Load");
00151 but->SetButtonListener(this, BUT_LOAD_BOOKMARKED);
00152 but = new OglGui::Button(this, 60, 22, "Save");
00153 but->SetButtonListener(this, BUT_SAVE_BOOKMARKED);
00154 mBookmarkedField = new OglGui::TextField(this, 190, 20,
00155 "filename.ixs");
00156 }
00157
00158 Core::Database::RawDataSet* dataSet = mDataDoc->GetDataSet();
00159 std::string info = std::string("Set ") + dataSet->GetSetName() +
00160 " has " + MakeString(dataSet->NrDirs()) + " dirs";
00161 if (mInfoText1)
00162 mInfoText1->SetText(info);
00163 if (mStringSelector1)
00164 for (int i=0 ; i<dataSet->NrDirs() ; i++)
00165 mStringSelector1->AddString(dataSet->GetSection(i) + "/" +
00166 dataSet->GetDir(i));
00167 }
00168
00169 virtual void
00170 HandleNewFile()
00171 {
00172 int curD = mDataDoc->CurDirId();
00173 if (mStringSelector1)
00174 mStringSelector1->SetCurrentString(curD, true);
00175 Core::Database::RawDataSet* dataSet = mDataDoc->GetDataSet();
00176 int nrFiles = (curD != -1) ? dataSet->GetNrFiles(curD) : 0;
00177 std::string info("no dir selected");
00178 if (curD != -1)
00179 info = dataSet->GetDir(curD) + " has " + MakeString(nrFiles)
00180 + " files";
00181 if (mInfoText2)
00182 mInfoText2->SetText(info);
00183 int firstVis;
00184 if (mStringSelector2)
00185 {
00186 firstVis = mStringSelector2->GetFirstVis();
00187 mStringSelector2->RemoveStrings();
00188 }
00189 if (mStringSelector2 && (curD != -1))
00190 {
00191 int start = dataSet->GetFirstFileId(curD);
00192 int end = start + dataSet->GetNrFiles(curD);
00193 for (int i=start ; i<end ; i++)
00194 mStringSelector2->AddString(dataSet->GetFile(i));
00195 int idx = mDataDoc->CurFileId() - dataSet->GetFirstFileId(curD);
00196 mStringSelector2->SetFirstVis(firstVis, true);
00197 mStringSelector2->SetCurrentString(idx, true);
00198 }
00199 }
00200
00201 virtual void
00202 HandleNewBookmarked()
00203 {
00204 typedef typename DataDocT::BookmarkedType BookmarkedT;
00205 BookmarkedT* bookm = mDataDoc->GetBookmarked();
00206 if (mInfoText3)
00207 mInfoText3->SetText(MakeString(bookm->Size()) + " bookmarks");
00208 int firstVis;
00209 if (mStringSelector3)
00210 {
00211 firstVis = mStringSelector3->GetFirstVis();
00212 mStringSelector3->RemoveStrings();
00213 }
00214 Core::Database::RawDataSet* dataSet = mDataDoc->GetDataSet();
00215 int curB = mDataDoc->CurBookmark();
00216 if (mStringSelector3 && mDataDoc->HasBookmarks())
00217 {
00218 for (int i=0 ; i<bookm->Size() ; i++)
00219 mStringSelector3->AddString(mDataDoc->DescribeBookmark(i));
00220 mStringSelector3->SetFirstVis(firstVis, true);
00221 mStringSelector3->SetCurrentString(curB, true);
00222 }
00223 }
00224
00225 virtual void
00226 HandleCursorBookmarked()
00227 {
00228 if (mStringSelector3)
00229 mStringSelector3->SetCurrentString(mDataDoc->CurBookmark(), true);
00230 if (mConceptField)
00231 {
00232 mConceptField->SetText(mDataDoc->CurBookmarkAnno());
00233 mConceptField->ResetCaret();
00234 }
00235 }
00236
00237 virtual void
00238 AddCursorToBookmarked()
00239 {
00240 if (mConceptField)
00241 mDataDoc->SetConcept(mConceptField->GetText());
00242 if (! mDataDoc->AddCursorToBookmarked())
00243 return;
00244 AllHandleAddedBookmark();
00245 }
00246
00247 virtual void
00248 RemoveCursorFromBookmarked()
00249 {
00250 if (! mDataDoc->RemoveCursorFromBookmarked())
00251 return;
00252 AllHandleRemovedBookmark();
00253 AllHandleNewCursor(Core::Database::LEVEL_FILE, true);
00254 }
00255
00256 void
00257 ClearBookmarked()
00258 {
00259 mDataDoc->ClearBookmarked();
00260 AppControlDoc::HandleActivate();
00261 }
00262
00263 void
00264 LoadBookmarked()
00265 {
00266 mDataDoc->Clear();
00267 std::string fileName = mBookmarkedField->GetText();
00268 mDataDoc->LoadBookmarked(fileName);
00269 mDataDoc->LoadConceptsFromBookmarks();
00270 AppControlDoc::HandleActivate();
00271 }
00272
00273 void
00274 SaveBookmarked()
00275 {
00276 std::string fileName = mBookmarkedField->GetText();
00277 std::string conceptName = FileNameBase(fileName);
00278 mDataDoc->SaveBookmarked(fileName, conceptName);
00279 }
00280
00281 virtual void
00282 StringSelectionEvent(OglGui::StringSelector* src, int strIndex,
00283 void* listenerData)
00284 {
00285 typedef Core::Database::DocLevel DocLevel;
00286 if (listenerData == (void*)STRING_DIR)
00287 {
00288 DocLevel level = mDataDoc->CursorToDir(strIndex);
00289 AllHandleNewCursor(level, false);
00290 }
00291 if (listenerData == (void*)STRING_FILE)
00292 {
00293 int fileIdx = mDataDoc->GetFileOfDir(strIndex, -1);
00294 mDataDoc->CursorToFile(fileIdx);
00295 AllHandleNewCursor(Core::Database::LEVEL_FILE, false);
00296 }
00297 if (listenerData == (void*)STRING_BOOK)
00298 {
00299 mDataDoc->CursorToBookmark(strIndex);
00300 AllHandleNewCursor(Core::Database::LEVEL_FILE, true);
00301 }
00302 }
00303
00304 virtual void
00305 ButtonSelectionEvent(OglGui::Button* src, void *vData)
00306 {
00307 int listenerData = (int)((long long) vData);
00308 switch (listenerData)
00309 {
00310 case BUT_CONCEPT: {
00311 if (!mDataDoc->HasConcepts())
00312 break;
00313 OGLMENU menu = oglSys.MenuCreate();
00314 for (int i=0 ; i<mDataDoc->NrConcepts() ; i++)
00315 oglSys.MenuAdd(menu, (char*) mDataDoc->GetConcept(i).c_str(),
00316 0, 100 + i);
00317 int choice = oglSys.MenuPopUp(mOglWnd, menu);
00318 if (choice >= 100)
00319 {
00320 mDataDoc->SetConcept(choice - 100);
00321 mConceptField->SetText(mDataDoc->GetConcept());
00322 mConceptField->ResetCaret();
00323 HandleNewConcept();
00324 }
00325 oglSys.MenuDestroy(menu);
00326 break;
00327 }
00328 case BUT_ADD_CONCEPT:
00329 mDataDoc->SetConcept(mConceptField->GetText());
00330 HandleNewConcept();
00331 break;
00332 case BUT_LOAD_CONCEPTS:
00333 HandleLoadConcepts(mConceptFileField->GetText());
00334 break;
00335 case BUT_SAVE_CONCEPTS:
00336 HandleSaveConcepts(mConceptFileField->GetText());
00337 break;
00338 case BUT_BOOKMARK:
00339 AddCursorToBookmarked();
00340 break;
00341 case BUT_UNBOOKMARK:
00342 RemoveCursorFromBookmarked();
00343 break;
00344 case BUT_CLEAR_BOOKMARKED:
00345 ClearBookmarked();
00346 break;
00347 case BUT_LOAD_BOOKMARKED:
00348 LoadBookmarked();
00349 break;
00350 case BUT_SAVE_BOOKMARKED:
00351 SaveBookmarked();
00352 break;
00353 }
00354 }
00355
00356 virtual void
00357 HandleNewConcept()
00358 {
00359 }
00360
00361 virtual void
00362 HandleLoadConcepts(std::string fileName)
00363 {
00364 mDataDoc->LoadConcepts(fileName);
00365 }
00366
00367 virtual void
00368 HandleSaveConcepts(std::string fileName)
00369 {
00370 mDataDoc->SaveConcepts(fileName);
00371 }
00372
00373 protected:
00374
00375 OglGui::TextField* mConceptField;
00376 OglGui::TextField* mConceptFileField;
00377 OglGui::TextField* mBookmarkedField;
00378
00379 DataDocT* mDataDoc;
00380 private:
00381
00382 OglGui::TextArea* mInfoText1;
00383 OglGui::TextArea* mInfoText2;
00384 OglGui::TextArea* mInfoText3;
00385 OglGui::StringSelector* mStringSelector1;
00386 OglGui::StringSelector* mStringSelector2;
00387 OglGui::StringSelector* mStringSelector3;
00388
00389 };
00390
00391 }
00392 }
00393
00394 #endif