1 ///////////////////////////////////////////////////////////////////////////
3 // Author: Daniel Giritzer <daniel@giritzer.eu>
5 // Description: Diese Klasse stellt eine platformunabhängige Visualisierung
6 // des Models zur verfügung.
8 ///////////////////////////////////////////////////////////////////////////
11 #include <FL/fl_ask.H>
12 #include <FL/Fl_PNG_Image.H>
19 View::View(ControllerIF::SPtr contr, ModelIF::SPtr model)
23 subscribeSubject(mModel.get());
26 void View::showErrorMsg(const std::string& message)
28 std::cerr << message << std::endl;
29 std::string printMsg = message;
30 fl_message_title("Error!");
31 printMsg.append("\n\nExit application?");
32 switch ( fl_choice(printMsg.c_str(), "Yes", "No", 0) ) {
33 case 0: exit(EXIT_FAILURE); break;
41 // Ressourcen freigeben
42 Fl::delete_widget(win_exmpl);
43 unsubscribeSubject(mModel.get());
46 void View::updatedBySubject(Subject* s)
49 throw std::string("Nullpointer given as Subject!");
55 // Lade Daten von Model hier implementieren
59 // ----------- Exception Handling ------------
60 catch(const std::string &e)
66 showErrorMsg("Unknown error occured!");
72 // Setze fenster style global
77 win_exmpl->icon((char*)LoadIcon(fl_display, MAKEINTRESOURCE(101)));
79 Fl_PNG_Image win_icon("Icon.png");
80 win_exmpl->icon(&win_icon);
83 //Tabelle mit Beispieldaten füllen
84 tbl_example->row_header(true);
85 tbl_example->col_header(true);
86 for(int i = 0; i <= 10; i++)
87 for(int ii = 0; ii <= 10; ii++)
88 tbl_example->SetTableData(std::to_string(i) + " " + std::to_string(ii), i, ii, i + ii);
90 // definiere callback funktionen
91 btn_exception->callback((Fl_Callback*)btn_exception_cb, (void*)(this) );
97 void View::btn_exception_cb(Fl_Button* btn, void* view)
101 View* thisView = static_cast<View*>(view);
102 thisView->mController->throwException();
104 // ----------- Exception Handling ------------
105 catch(const std::string &e)
111 showErrorMsg("Unknown error occured!");