00001 #ifndef VideoExcel_TableColumn_h
00002 #define VideoExcel_TableColumn_h
00003
00004 #include "TableDataSource.h"
00005 #include "TableCell.h"
00006
00007 #include "OglGui/DirectionButton.h"
00008 #include "OglGui/TextField.h"
00009 #include "OglGui/StaticText.h"
00010 #include "OglGui/MenuOnButton.h"
00011
00012 namespace Impala {
00013 namespace Application {
00014 namespace VideoExcel {
00015
00016
00017
00018 class TableColumn : public OglGui::Window,
00019 OglGui::TextFieldListener,
00020 OglGui::ButtonListener,
00021 OglGui::MenuListener,
00022 TableUpdateListener
00023 {
00024 public:
00025 typedef OglGui::Window Window;
00026 typedef OglGui::Button Button;
00027 typedef OglGui::DirectionButton DirectionButton;
00028 typedef OglGui::TextField TextField;
00029 typedef OglGui::MenuOnButton MenuOnButton;
00030 typedef OglGui::MenuTopPane MenuTopPane;
00031 typedef OglGui::Menu Menu;
00032
00033 TableColumn(Window *parent, TableDataSource *source,
00034 CString name, int width=120) :
00035 Window(parent, width, parent->H())
00036 {
00037 ConnectTo(parent, OglGui::T2T | OglGui::B2B);
00038 Init(name, parent, source, width, parent->H());
00039 }
00040
00041 void SetDisplayMode(int mode, int attr=TableCell::NONE)
00042 {
00043 mDisplayMode = mode;
00044 mDisplayAttr = attr;
00045 switch (mode)
00046 {
00047 case TableCell::DISPLAY_TEXT:
00048 mFilterTextField->SetVisible(true);
00049 mFilterValueButton->SetVisible(false);
00050 break;
00051 case TableCell::DISPLAY_IMAGE:
00052 if (!mCache)
00053 mCache = new TableViewCache(this, mSource);
00054 mFilterTextField->SetVisible(false);
00055 mFilterValueButton->SetVisible(false);
00056 mSortButton->SetVisible(false);
00057 break;
00058 case TableCell::DISPLAY_DOT:
00059 case TableCell::DISPLAY_FILLED:
00060 mFilterTextField->SetVisible(false);
00061 mFilterValueButton->SetVisible(true);
00062 break;
00063 }
00064 UpdateRows();
00065 }
00066
00067 void SetSortType(int type) {
00068 mSortType = type;
00069 }
00070
00071 void UpdateRows()
00072 {
00073 if (mDisplayMode == TableCell::DISPLAY_IMAGE)
00074 mCache->HideViews();
00075
00076 int cindex = 0;
00077 int yoffset = sHeaderHeight;
00078 int startR = mSource->GetStartRow();
00079 for (int i=startR; i<startR+mSource->GetNumberOfRows(); i++)
00080 {
00081 TableCell *c = GetCell(cindex++);
00082 int yheight = mSource->GetRowHeight(i);
00083 yoffset += yheight;
00084 c->UpdateRow(yoffset, i, mDisplayMode, mDisplayAttr);
00085 }
00086
00087
00088 for (int i=cindex; i<mCellCache.size(); i++)
00089 mCellCache[i]->SetVisible(false);
00090 UpdateScene();
00091 }
00092
00093 TableViewCache* GetViewCache()
00094 {
00095 return mCache;
00096 }
00097
00098 virtual void DisplayFunc()
00099 {
00100 if (mCache && mCache->ProcessDelayLoad())
00101 UpdateRows();
00102 Window::DisplayFunc();
00103 }
00104
00105 virtual void ButtonSelectionEvent(Button *src, void* userData)
00106 {
00107 int t = 0;
00108 if (mDisplayMode == TableCell::DISPLAY_TEXT)
00109 t = TableDataSource::TYPE_TEXT;
00110 if (mDisplayMode == TableCell::DISPLAY_DOT ||
00111 mDisplayMode == TableCell::DISPLAY_FILLED)
00112 t = TableDataSource::TYPE_NORMALIZEDVALUE;
00113 if (mSortType > 0)
00114 t = mSortType;
00115 if (t == 0) return;
00116
00117 if (mSource->GetSortColumn() == mColumnName)
00118 mSource->SetSortColumn(mColumnName,t,!mSource->GetSortAscending());
00119 else
00120 mSource->SetSortColumn(mColumnName,t);
00121 }
00122
00123 static int GetHeaderHeight()
00124 {
00125 return sHeaderHeight;
00126 }
00127
00128 int GetColumnWidth()
00129 {
00130 return mColWidth;
00131 }
00132
00133 void SetColumnWidthDynamic(bool value)
00134 {
00135 mColWidthDynamic = value;
00136 }
00137
00138 bool GetColumnWidthDynamic()
00139 {
00140 return mColWidthDynamic;
00141 }
00142
00143 void ResetFilter(bool callEvents=true)
00144 {
00145 switch (mDisplayMode)
00146 {
00147 case TableCell::DISPLAY_TEXT:
00148 mFilterTextField->SetText("");
00149 mFilter->Disable(callEvents);
00150 break;
00151 case TableCell::DISPLAY_DOT:
00152 case TableCell::DISPLAY_FILLED:
00153 mFilterValueButton->SetText("Filter");
00154 mFilter->Disable(callEvents);
00155 break;
00156 }
00157 }
00158
00159 private:
00160
00161 virtual void UpdateRowsEvent()
00162 {
00163 UpdateRows();
00164 }
00165
00166 virtual void UpdateSortEvent(String col, bool ascending)
00167 {
00168
00169 if (mColumnName == col)
00170 {
00171 mSortButton->SetFilled(true);
00172 mColumnHeader->SetPressed(true);
00173 mSortButton->SetDirection(ascending ? 3 : 1);
00174 }
00175 else
00176 {
00177 mSortButton->SetFilled(false);
00178 mColumnHeader->SetPressed(false);
00179 mSortButton->SetDirection(3);
00180 }
00181 }
00182
00183
00184
00185 virtual void
00186 TextFieldChangedEvent(TextField *src, void* userData)
00187 {
00188 if (mDisplayMode == TableCell::DISPLAY_TEXT)
00189 mFilter->SetTextFilter(src->GetText());
00190 }
00191
00192
00193 virtual void OnMenuItem(Menu *src, int menuIdx, String itemName,
00194 int itemIdx, void *userData)
00195 {
00196 ILOG_DEBUG("Selected option " << itemIdx << " menuIdx " << menuIdx <<
00197 " itemName " << itemName);
00198
00199 switch (itemIdx)
00200 {
00201 case 1:
00202 mFilter->SetValueFilter(0.95, false);
00203 mFilterValueButton->SetText("<5%%");
00204 break;
00205 case 2:
00206 mFilter->SetValueFilter(0.90, false);
00207 mFilterValueButton->SetText("<10%%");
00208 break;
00209 case 3:
00210 mFilter->SetValueFilter(0.80, false);
00211 mFilterValueButton->SetText("<20%%");
00212 break;
00213 case 4:
00214 mFilter->SetValueFilter(0.70, false);
00215 mFilterValueButton->SetText("<30%%");
00216 break;
00217 case 5:
00218 mFilter->SetValueFilter(0.50, false);
00219 mFilterValueButton->SetText("<50%%");
00220 break;
00221 case 6:
00222 mFilter->SetValueFilter(0.50, true);
00223 mFilterValueButton->SetText(">50%%");
00224 break;
00225 case 7:
00226 mFilter->SetValueFilter(0.20, false);
00227 mFilterValueButton->SetText(">20%%");
00228 break;
00229 case 8:
00230 mFilter->SetValueFilter(0.10, false);
00231 mFilterValueButton->SetText(">10%%");
00232 break;
00233 case 9:
00234 mFilter->Disable();
00235 mFilterValueButton->SetText("Filter");
00236 break;
00237 }
00238 }
00239
00240 TableCell *GetCell(int index)
00241 {
00242 if (index >= mCellCache.size())
00243 {
00244 TableCell *c = new TableCell(this, mSource, mCache, mColumnName);
00245 oglSys.SetNoMouseInput(c->GetOGLWND(),1);
00246 mCellCache.push_back(c);
00247 return c;
00248 }
00249 return mCellCache[index];
00250 }
00251
00252 void
00253 Init(String name, Window *parent, TableDataSource *source, int w, int h)
00254 {
00255 mSource = source;
00256 mColumnName = name;
00257 mCache = 0;
00258 mDisplayMode = TableCell::DISPLAY_TEXT;
00259 mDisplayAttr = TableCell::NONE;
00260
00261
00262 mSource->AddTableUpdateListener(this);
00263
00264
00265 oglSys.SetNoMouseInput(GetOGLWND(),1);
00266
00267 mColumnHeader = new Button(this,0,h-20,w,20,name,4,true);
00268 mColumnHeader->SetAlign(oglLeftAlign);
00269 mColumnHeader->SetAlignOffsets(4,0);
00270
00271 mColumnHeader->ConnectTo(this, OglGui::TOTOP| OglGui::TOLEFTRIGHT);
00272 mColumnHeader->SetButtonListener(this, 0);
00273 mColumnHeader->SetBackground(0xffffddee);
00274
00275 mSortButton = new DirectionButton(mColumnHeader,w-16,2,16,16,3,-1);
00276 mSortButton->SetBackground(0xffffddee);
00277 mSortButton->ConnectTo(mColumnHeader,OglGui::TORIGHT);
00278 mSortButton->SetButtonListener(this, 0);
00279
00280 mFilterTextField = new TextField(this, 0, h-40, w, 20, "");
00281 mFilterTextField->SetTextFieldListener(this, 0);
00282
00283 mFilterTextField->ConnectTo(this, OglGui::TOTOP | OglGui::TOLEFTRIGHT);
00284
00285 MenuTopPane* top = new MenuTopPane(this);
00286 Menu *filterMenu = new Menu(top, 1, 120);
00287 filterMenu->AddItem("filter " + mColumnName, 0);
00288 filterMenu->SetOptions(0, Menu::SEPARATOR, true);
00289 filterMenu->AddItem("strong match", 2);
00290 filterMenu->AddItem("less strong", 3);
00291 filterMenu->AddItem("weak match", 4);
00292 filterMenu->AddItem("very weak match", 5);
00293
00294
00295
00296
00297 filterMenu->AddItem("everything", 9);
00298
00299 filterMenu->SetMenuListener(this, 0);
00300
00301 mFilterValueButton =
00302 new MenuOnButton(this, 0, h-40, w, 20, "Filter", filterMenu);
00303
00304 mFilterValueButton->ConnectTo(this, OglGui::TOTOP|OglGui::TOLEFTRIGHT);
00305
00306 mFilter = new TableFilter(mSource, mColumnName);
00307 mSource->RegisterFilter(mFilter);
00308
00309 mColWidth = w;
00310 mColWidthDynamic = false;
00311
00312 }
00313
00314 static int sHeaderHeight;
00315
00316 bool mColWidthDynamic;
00317 int mDisplayMode;
00318 int mDisplayAttr;
00319 int mSortType;
00320 int mColWidth;
00321
00322 String mColumnName;
00323
00324 TableDataSource* mSource;
00325 TableViewCache* mCache;
00326 TableFilter* mFilter;
00327 std::vector<TableCell*> mCellCache;
00328
00329 Button* mColumnHeader;
00330 DirectionButton* mSortButton;
00331 TextField* mFilterTextField;
00332 MenuOnButton* mFilterValueButton;
00333
00334 ILOG_VAR_DEC;
00335 };
00336
00337 ILOG_VAR_INIT(TableColumn, Application.VideoExcel);
00338
00339 int TableColumn::sHeaderHeight = 40;
00340
00341 }
00342 }
00343 }
00344
00345 #endif // TableColumn_h