00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef TABLEDATAVIEWCONTROLLER_H
00010 #define TABLEDATAVIEWCONTROLLER_H
00011
00012 #include "TableDataView.h"
00013 #include "TableDataViewListener.h"
00014
00015 #include "OglGui/Menu.h"
00016
00017 #include "Application/videolympics/VideolympicsClient.h"
00018
00019 namespace Impala { namespace Application { namespace MediaTable {
00020
00021 class TableDataViewController :
00022 public TableDataViewListener,
00023 OglGui::MenuListener
00024 {
00025 public:
00026 typedef OglGui::MenuTopPane MenuTopPane;
00027 typedef OglGui::Menu Menu;
00028
00029 TableDataViewController(TableDataView *view)
00030 {
00031 SetTableDataView(view);
00032 mContext = 0;
00033 }
00034
00035 TableDataView* GetTableDataView()
00036 {
00037 return mView;
00038 }
00039
00040 #ifndef MEDIATABLE_VIDEOLYMPICS
00041 virtual inline void
00042 TransformMarkedTo(int sourcemask, int targetmask)
00043 {
00044 GetTableDataView()->TransformMarkedTo(sourcemask, targetmask);
00045 GetTableDataView()->DoUpdateSelectionEvent();
00046 }
00047
00048 #else
00049 virtual void TransformMarkedTo(int sourcemask, int targetmask)
00050 {
00051 for (int id=0; id < GetTableDataView()->GetTotalRows(); id++)
00052 {
00053 int mark = GetTableDataView()->GetMarkById(id);
00054 if((mark & sourcemask) == sourcemask)
00055 {
00056 mark &= ~sourcemask;
00057 mark |= targetmask;
00058 SetMarkById(id, mark);
00059 }
00060 }
00061 GetTableDataView()->DoUpdateSelectionEvent();
00062 }
00063 #endif
00064
00065 virtual inline void SetMarkById(int id, int mark)
00066 {
00067 GetTableDataView()->SetMarkById(id, mark);
00068 ILOG_USER("Set mark for id " << id << " to " << mark);
00069 #ifdef MEDIATABLE_VIDEOLYMPICS
00070 if(mark & 128)
00071 {
00072 std::string shotname =
00073 GetTableDataView()->GetTextDataByID("shotname", id);
00074 Application::Videolympics::VideolympicsClient *voc;
00075 voc = TableDataStore::GetInstance()->GetVideOlympicsClient();
00076 if(voc)
00077 voc->SendShot(shotname);
00078
00079 }
00080 #endif
00081 }
00082
00083 virtual inline void
00084 MarkAllRows(int mark, bool state)
00085 {
00086 GetTableDataView()->MarkAllRows(mark, state);
00087 GetTableDataView()->DoUpdateSelectionEvent();
00088 }
00089
00090 virtual inline void
00091 MarkAllFilteredRows(int mark, bool state)
00092 {
00093 GetTableDataView()->MarkAllFilteredRows(mark, state);
00094 GetTableDataView()->DoUpdateSelectionEvent();
00095 }
00096
00097 virtual inline void
00098 ScrollRelative(int nr)
00099 {
00100 GetTableDataView()->SetStartRow(GetTableDataView()->GetStartRow() + nr);
00101 }
00102
00103 virtual void KeyboardFunc(int c, int state)
00104 {
00105 switch (c)
00106 {
00107 case oglPAGEUP:
00108 ScrollRelative(-GetTableDataView()->GetNumberOfRows());
00109 break;
00110 case oglPAGEDOWN:
00111 ScrollRelative(GetTableDataView()->GetNumberOfRows());
00112 break;
00113
00114 case oglUP:
00115 ScrollRelative(-1);
00116 break;
00117 case oglDOWN:
00118 ScrollRelative(1);
00119 break;
00120
00121
00122 case '1': TransformMarkedTo(1, 4); break;
00123 case '2': TransformMarkedTo(1, 8); break;
00124 case '3': TransformMarkedTo(1, 16); break;
00125 case '4': TransformMarkedTo(1, 32); break;
00126 case '5': TransformMarkedTo(1, 64); break;
00127 case '6': TransformMarkedTo(1, 128); break;
00128
00129
00130 case '!': TransformMarkedTo( 4|1, 1); break;
00131 case '@': TransformMarkedTo( 8|1, 1); break;
00132 case '#': TransformMarkedTo( 16|1, 1); break;
00133 case '$': TransformMarkedTo( 32|1, 1); break;
00134 case '%': TransformMarkedTo( 64|1, 1); break;
00135 #ifndef MEDIATABLE_VIDEOLYMPICS
00136
00137 case '^': TransformMarkedTo(128|1, 1); break;
00138 #endif
00139 case 138:
00140 MarkAllRows(1, false);
00141 break;
00142
00143 case oglCTRL('a'):
00144 if(state == oglControl)
00145 MarkAllFilteredRows(1, true);
00146 break;
00147
00148
00149
00150
00151
00152
00153
00154 }
00155 }
00156
00157 void GetColumnMinMax(std::string column, double &min, double &max)
00158 {
00159 if (GetTableDataView()->GetFilteredRows()) {
00160 double value;
00161 if(GetTableDataView()->GetColumn(column)->GetType() == TableDataSource::TYPE_INT)
00162 value = GetTableDataView()->GetSortedIntData(column, 0);
00163 else
00164 value = GetTableDataView()->GetSortedDoubleData(column, 0);
00165 min = max = value;
00166 }
00167 for (int i=0; i<GetTableDataView()->GetFilteredRows(); i++)
00168 {
00169 double value;
00170 if(GetTableDataView()->GetColumn(column)->GetType() == TableDataSource::TYPE_INT)
00171 value = GetTableDataView()->GetSortedIntData(column, i);
00172 else
00173 value = GetTableDataView()->GetSortedDoubleData(column, i);
00174 if(value < min)
00175 min = value;
00176 if(value > max)
00177 max = value;
00178 }
00179 }
00180
00181 static int MarkToColor(int m)
00182 {
00183 int r=127,g=127,b=127;
00184 if (m == -1)
00185 return ARGB2COLOR(255, 200, 200, 200);
00186 if (m & 1)
00187 r = g = b = 255;
00188
00189
00190 if (m & 4)
00191 r += 64;
00192 if (m & 8)
00193 g += 64;
00194 if (m & 16)
00195 b += 64;
00196 if (m & 32)
00197 { r += 64; g += 64; }
00198 if (m & 64)
00199 { g += 64; b += 64; }
00200 if (m & 128)
00201 { r += 64; b += 64; }
00202 if (r>255) r = 255;
00203 if (g>255) g = 255;
00204 if (b>255) b = 255;
00205 return ARGB2COLOR(255, r,g,b);
00206 }
00207
00208 protected:
00209 virtual void InitContextMenu(OglGui::Window* window)
00210 {
00211 MenuTopPane* top = new MenuTopPane(window);
00212 mContext = new Menu(top, 1, 180);
00213
00214 mContext->AddItem("Add selection to bucket:", 2);
00215 mContext->AddItem("red", 3);
00216 mContext->AddItem("green", 4);
00217 mContext->AddItem("blue", 5);
00218 mContext->AddItem("yellow", 6);
00219 mContext->AddItem("cyan", 7);
00220 #ifndef MEDIATABLE_VIDEOLYMPICS
00221 mContext->AddItem("other", 8);
00222 #else
00223 mContext->AddItem("VideOlympics", 8);
00224 #endif
00225 mContext->SetOptions(2, Menu::SEPARATOR, true);
00226 mContext->SetMenuListener(this, 0);
00227 }
00228
00229 virtual void OpenContextMenu(int x, int y)
00230 {
00231 if(mContext)
00232 mContext->Open(x, y);
00233 }
00234
00235
00236 virtual void OnMenuItem(Menu *src, int menuIdx, String itemName,
00237 int itemIdx, void *userData)
00238 {
00239 switch (itemIdx)
00240 {
00241 case 3: TransformMarkedTo(1, 4); break;
00242 case 4: TransformMarkedTo(1, 8); break;
00243 case 5: TransformMarkedTo(1, 16); break;
00244 case 6: TransformMarkedTo(1, 32); break;
00245 case 7: TransformMarkedTo(1, 64); break;
00246 case 8: TransformMarkedTo(1, 128); break;
00247 default:
00248 break;
00249 }
00250 }
00251
00252 private:
00253 void SetTableDataView(TableDataView* view)
00254 {
00255 mView = view;
00256 mView->AddTableDataViewListener(this);
00257 }
00258
00259 TableDataView* mView;
00260
00261 Menu* mContext;
00262
00263
00264 ILOG_VAR_DECL;
00265 };
00266
00267 ILOG_VAR_INIT(TableDataViewController, Application.MediaTable);
00268
00269 } } }
00270 #endif