Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

SelectionCollectionItem.h

Go to the documentation of this file.
00001 #ifndef MediaTable_SelectionCollectionItem_h
00002 #define MediaTable_SelectionCollectionItem_h
00003 
00004 #include "OglGui/Window.h"
00005 #include "SelectionCollectionListener.h"
00006 #include "OglGui/Menu.h"
00007 
00008 namespace Impala {
00009 namespace Application {
00010 namespace MediaTable {
00011 
00012 class SelectionCollectionItem : public OglGui::Window,
00013                                 OglGui::MenuListener
00014 {
00015 public:
00016     typedef OglGui::Window                  Window;
00017     typedef OglGui::StaticText              StaticText;
00018     typedef OglGui::MenuTopPane             MenuTopPane;
00019     typedef OglGui::Menu                    Menu;
00020 
00021     SelectionCollectionItem(Window* parent, int id, unsigned long bgColor) :
00022         Window(parent, 80, 80)
00023     {
00024         Init(id, bgColor);
00025     }
00026 
00027     void SetItemName(String text)
00028     {
00029         mItemText->SetText(text);
00030     }
00031 
00032     void SetItemCounts(int total, int visible)
00033     {
00034         std::ostringstream stotal;
00035         stotal << total;
00036         mItemCount->SetText(stotal.str());
00037         std::ostringstream svisible;
00038         svisible << visible;
00039         mItemVisCount->SetText(svisible.str());
00040     }
00041 
00042     virtual void MouseFunc(int msg, int but, int state, int x, int y)
00043     {
00044         if (mListener && msg == oglMouseUp && but == oglLeftButton)
00045         {
00046             ILOG_USER("Select Collection " << mId);
00047             mListener->SelectCollectionEvent(mId);
00048                 }
00049         if (msg == oglMouseDown && but == oglRightButton)
00050         {
00051             int rx=0, ry=0;
00052             ToTopWindow(this, rx, ry);
00053             mContextMenu->Open(rx+x,ry+y);
00054         }
00055     }
00056 
00057     void SetListener(SelectionCollectionListener *target)
00058     {
00059         mListener = target;
00060     }
00061 
00062     void SetHighlighted(bool highLight)
00063     {
00064         SetBorderFillShaded(highLight ? DEEP_SHADE_UP : DEEP_SHADE_DOWN);
00065         SetBorderType(highLight ? BEV_LINE : BEV_INVISIBLE);
00066     }
00067 
00068     virtual void OnMenuItem(Menu *src, int menuIdx, String itemName,
00069                             int itemIdx, void *userData)
00070     {
00071         ILOG_USER("bin " << mId << " selected option " << itemIdx << " menuIdx " << menuIdx <<
00072                    " itemName " << itemName);
00073 
00074          // As all calls will use the listener, stop here if we don't have one
00075         if (!mListener)
00076             return;
00077 
00078         if (itemIdx == 1)
00079             mListener->SelectCollectionEvent(mId);
00080         if (itemIdx == 2)
00081             mListener->SelectCollectionInvertedEvent(mId);
00082         if (itemIdx == 3)
00083             mListener->AddCollectionToSelectionEvent(mId);
00084         if (itemIdx == 4)
00085             mListener->RemoveCollectionFromSelectionEvent(mId);
00086         if (itemIdx == 5)
00087             mListener->EmptyCollectionEvent(mId);
00088 
00089         if (itemIdx == 8)
00090                 mListener->SaveCollectionEvent(mId);
00091         if (itemIdx == 9)
00092                 mListener->LoadCollectionEvent(mId);
00093     }
00094 
00095 private :
00096 
00097     void Init(int id, unsigned long bgColor)
00098     {
00099         mId       = id;
00100         mBgcolor  = bgColor;
00101         mListener = 0;
00102 
00103         SetBorderBackground(bgColor);
00104         SetRoundness(16, 16, 16, 16);
00105         SetBorderFillShaded(-2);
00106         SetBorderType(-1);
00107 
00108         mItemText       = new StaticText(this, 0, 0,  W(), 20, "");
00109         mItemCount      = new StaticText(this, 0, 20, W(), 20, "");
00110         mItemVisCount   = new StaticText(this, 0, 44, W(), 20, "");
00111         mItemVisCount->SetTextShadowed(true);
00112         mItemCount->SetForeground(0xff555555);
00113 
00114         oglSys.SetNoMouseInput(mItemText->GetOGLWND(),1);
00115         oglSys.SetNoMouseInput(mItemCount->GetOGLWND(),1);
00116         oglSys.SetNoMouseInput(mItemVisCount->GetOGLWND(),1);
00117 
00118         RepositionViewports();
00119         ScaleChildren();
00120         SetAllowChildScaling(false); // Since we scale ourselves
00121 
00122         SetItemName("unknown");
00123         SetItemCounts(0, 0);
00124 
00125         MenuTopPane* top = new MenuTopPane(this);
00126         mContextMenu = new Menu(top, 1, 180);
00127         mContextMenu->AddItem("Show only these", 1);
00128         mContextMenu->AddItem("Show everything but these", 2);
00129         if (id > 1)
00130         {
00131             mContextMenu->AddItem("Add these to view", 3);
00132             mContextMenu->AddItem("Remove these from view", 4);
00133             mContextMenu->AddItem("Empty this bucket", 5);
00134         }
00135         if (id == -1)
00136         {
00137             mContextMenu->SetOptions(2, Menu::DISABLED, true);
00138             mContextMenu->SetOptions(3, Menu::DISABLED, true);
00139             mContextMenu->SetOptions(4, Menu::DISABLED, true);
00140             mContextMenu->SetOptions(5, Menu::DISABLED, true);
00141         }
00142         else
00143         {
00144             mContextMenu->AddItem("Save selection to marks.csv", 8);
00145             mContextMenu->AddItem("Load selection from marks.csv", 9);
00146         }
00147         mContextMenu->SetMenuListener(this, 0);
00148     }
00149 
00150     int                             mId;
00151     unsigned long                   mBgcolor;
00152 
00153     StaticText*                     mItemText;
00154     StaticText*                     mItemCount;
00155     StaticText*                     mItemVisCount;
00156     Menu*                           mContextMenu;
00157 
00158     SelectionCollectionListener*    mListener;
00159 
00160     ILOG_VAR_DEC;
00161 };
00162 
00163 ILOG_VAR_INIT(SelectionCollectionItem, Application.MediaTable);
00164 
00165 } // namespace MediaTable
00166 } // namespace Application
00167 } // namespace Impala
00168 
00169 #endif // SelectionCollectionItem_h

Generated on Fri Mar 19 09:30:33 2010 for ImpalaSrc by  doxygen 1.5.1