00001 #ifndef Impala_Visualization_GUI_ConceptTreeBrowser_h
00002 #define Impala_Visualization_GUI_ConceptTreeBrowser_h
00003
00004 #include "OglGui/Window.h"
00005 #include "OglGui/DropDownWindow.h"
00006 #include "OglGui/ScrollBar.h"
00007 #include "OglGui/ScrollWnd.h"
00008 #include "OglGui/TextField.h"
00009
00010 #include "ConceptPreviewBar.h"
00011 #include "PreviewBarSelectionListener.h"
00012
00013 namespace Impala {
00014 namespace Visualization {
00015 namespace GUI {
00016
00017
00018
00019 class ConceptTreeBrowser: public OglGui::Window,
00020 public OglGui::TextFieldListener,
00021 public PreviewBarSelectionListener
00022 {
00023 public:
00024 typedef Core::Trec::ThreadSet ThreadSet;
00025 typedef OglGui::ScrollBar ScrollBar;
00026 typedef OglGui::ScrollWnd ScrollWnd;
00027 typedef OglGui::StaticText StaticText;
00028 typedef OglGui::TextField TextField;
00029 typedef OglGui::DropDownWindow DropDownWindow;
00030
00031 ConceptTreeBrowser(OglGui::Window *parent, int w, int h, int thumbW,
00032 int thumbH, double viewscale, ThreadSet* threadset,
00033 String title = "Concept tree browser") :
00034 OglGui::Window(parent, w, h)
00035 {
00036 Init(thumbW, thumbH, viewscale, threadset, title);
00037 this->ConnectTo(parent);
00038 }
00039
00040 DropDownWindow*
00041 CatFilledDropDown(DropDownWindow *parent, char *title, char *folder)
00042 {
00043 DropDownWindow* dropDownWnd =
00044 new DropDownWindow(parent, parent->WndWidth(), 20, title);
00045 return dropDownWnd;
00046 }
00047
00048 DropDownWindow *DropWnd()
00049 {
00050 return mDropWnd;
00051 }
00052
00053 void Reset()
00054 {
00055 mKeyWordSearch->SetText("");
00056 SetFilter("");
00057 std::map<String, ConceptPreviewBar*>::iterator f;
00058
00059
00060
00061
00062
00063
00064
00065 }
00066
00067 void AddConcept(String name, String parent, double quality, int type)
00068 {
00069 DropDownWindow *target = mDropWnd;
00070 if (parent != "root")
00071 {
00072 if (mRootWnds.find(parent) == mRootWnds.end())
00073 {
00074 mRootWnds[parent] =
00075 new DropDownWindow(mDropWnd, mDropWnd->W(), 20, parent);
00076 mRootWndCounts[parent] = 0;
00077 mDropWnd->AddWindow(mRootWnds[parent]);
00078 }
00079 target = mRootWnds[parent];
00080 mRootWndCounts[parent] = mRootWndCounts[parent] + 1;
00081 mChildToParent[name] = parent;
00082 }
00083 else
00084 {
00085 mChildToParent[name] = "root";
00086 mRootWndCounts["root"] = mRootWndCounts["root"] + 1;
00087 }
00088
00089 ConceptPreviewBar* bar =
00090 new ConceptPreviewBar(target, mDropWnd->W(), 60, name, mThreadSet,
00091 quality, false, mThumbWidth, mThumbHeight,
00092 mViewScale);
00093 bar->SetPreviewBarSelectionListener(this, 0);
00094 bar->SetType(type);
00095 mChildWnds[name] = bar;
00096 target->AddWindow(bar);
00097 }
00098
00099 void SetPreviewBarSelectionListener(PreviewBarSelectionListener *l,
00100 void* userData)
00101 {
00102 mListener = l;
00103 mListenerData = userData;
00104 }
00105
00106 private:
00107 virtual void TextFieldChangedEvent(TextField *src, void* userData)
00108 {
00109 SetFilter(src->GetText());
00110 }
00111
00112 virtual void PreviewBarSelectionEvent(OglGui::Window *src, String concept,
00113 bool selected, void* userData)
00114 {
00115 if (mListener)
00116 mListener->PreviewBarSelectionEvent(this, concept, selected,
00117 mListenerData);
00118 }
00119
00120 virtual void PreviewBarImageClickEvent(OglGui::Window* src, String concept,
00121 int keyframeID, void* userData)
00122 {
00123 if (mListener)
00124 mListener->PreviewBarImageClickEvent(this, concept, keyframeID,
00125 mListenerData);
00126 }
00127
00128 void SetFilter(String filtertext)
00129 {
00130 std::map<String, ConceptPreviewBar*>::iterator f;
00131 if (filtertext.empty())
00132 {
00133 for (f = mChildWnds.begin(); f != mChildWnds.end(); f++)
00134 {
00135 f->second->SetHighlight(false);
00136 f->second->SetSmall(false);
00137 }
00138 return;
00139 }
00140
00141 mBar->SetNewPos(0);
00142
00143 std::map<String, DropDownWindow*>::iterator d;
00144 for (d = mRootWnds.begin(); d != mRootWnds.end(); d++)
00145 d->second->DropDown(false);
00146
00147 for (f = mChildWnds.begin(); f != mChildWnds.end(); f++)
00148 {
00149 String item = f->first;
00150 if (item.find(filtertext) == String::npos)
00151 {
00152 f->second->SetHighlight(false);
00153 f->second->SetSmall(true);
00154 }
00155 else
00156 {
00157 if (mChildToParent[f->first] != "root")
00158 mRootWnds[mChildToParent[f->first]]->DropDown(true);
00159 f->second->SetHighlight(true);
00160 f->second->SetSmall(false);
00161 }
00162 }
00163
00164 }
00165
00166 void Init(int thumbW, int thumbH, double viewscale, ThreadSet *threadset,
00167 String title)
00168 {
00169 int W = WndWidth();
00170 int H = WndHeight();
00171
00172 mThumbWidth = thumbW;
00173 mThumbHeight = thumbH;
00174 mViewScale = viewscale;
00175 mThreadSet = threadset;
00176 mListener = NULL;
00177
00178 StaticText *keyWordSearchLabel =
00179 new StaticText(this, W-300, H-22, 120, 20, "concept filter:");
00180 mKeyWordSearch = new TextField(this, W-190, H-22, 180, 20, "");
00181 mKeyWordSearch->SetTextFieldListener(this, 0);
00182
00183 ScrollWnd* dropScrollWnd = new ScrollWnd(this,0,0,W-4,H-28,true,0,-1);
00184 dropScrollWnd->SetBorderType(0);
00185 mBar = dropScrollWnd->VerticalScrollBar();
00186
00187 OglGui::Window* contentHolder = dropScrollWnd->ContentHolder();
00188 mDropWnd = new DropDownWindow(contentHolder, 0, W-20, W-60, 20, title);
00189 mDropWnd->DropDown(true);
00190 dropScrollWnd->ReplaceContentPane(mDropWnd);
00191 }
00192
00193 int mThumbWidth;
00194 int mThumbHeight;
00195 double mViewScale;
00196
00197
00198 DropDownWindow* mDropWnd;
00199 ScrollBar* mBar;
00200 TextField* mKeyWordSearch;
00201 ThreadSet* mThreadSet;
00202
00203 std::map<String, DropDownWindow*> mRootWnds;
00204 std::map<String, int> mRootWndCounts;
00205 std::map<String, String> mChildToParent;
00206 std::map<String, ConceptPreviewBar*> mChildWnds;
00207
00208 PreviewBarSelectionListener* mListener;
00209 void* mListenerData;
00210
00211 ILOG_VAR_DEC;
00212 };
00213
00214 ILOG_VAR_INIT(ConceptTreeBrowser, Visulization.GUI);
00215
00216 }
00217 }
00218 }
00219 #endif
00220
00221