#include "View.h"
#include <iostream>
#include <FL/fl_ask.H>
+#include <FL/Fl_PNG_Image.H>
+
+#ifdef _WIN32
+#include <FL/x.H>
+#include <windows.h>
+#endif /*_WIN32*/
View::View(ControllerIF::SPtr contr, ModelIF::SPtr model)
{
subscribeSubject(mModel.get());
}
+void View::showErrorMsg(const std::string& message)
+{
+ std::cerr << message << std::endl;
+ std::string printMsg = message;
+ fl_message_title("Error!");
+ printMsg.append("\n\nExit application?");
+ switch ( fl_choice(printMsg.c_str(), "Yes", "No", 0) ) {
+ case 0: exit(EXIT_FAILURE); break;
+ }
+}
+
View::~View()
{
win_exmpl->hide();
void View::updatedBySubject(Subject* s)
{
- if(s == nullptr)
+ if(s == nullptr) {
throw std::string("Nullpointer given as Subject!");
+ }
try
{
win_exmpl->redraw();
}
// ----------- Exception Handling ------------
- catch(std::string& e)
+ catch(const std::string &e)
{
- std::cerr << e << std::endl;
- fl_alert(e.c_str()); //Textbox mit fehlermeldung
+ showErrorMsg(e);
}
-}
+ catch(...)
+ {
+ showErrorMsg("Unknown error occured!");
+ }
+}
void View::show()
{
// Setze fenster style global
Fl::scheme("gtk+");
+ //Setze Fenster Icon
+#ifdef _WIN32
+ win_exmpl->icon((char*)LoadIcon(fl_display, MAKEINTRESOURCE(101)));
+#else
+ Fl_PNG_Image win_icon("Icon.png");
+ win_exmpl->icon(&win_icon);
+#endif /*_WIN32*/
+
+ //Tabelle mit Beispieldaten füllen
+ tbl_example->row_header(true);
+ tbl_example->col_header(true);
+ for(int i = 0; i <= 10; i++)
+ for(int ii = 0; ii <= 10; ii++)
+ tbl_example->SetTableData(std::to_string(i) + " " + std::to_string(ii), i, ii, i + ii);
+
// definiere callback funktionen
btn_exception->callback((Fl_Callback*)btn_exception_cb, (void*)(this) );
// ----------- Exception Handling ------------
catch(const std::string &e)
{
- std::cerr << e << std::endl;
- fl_alert(e.c_str()); //Textbox mit fehlermeldung
+ showErrorMsg(e);
}
catch(...)
{
- fl_alert("Unknown error occured!");
- std::cerr << "Unknown error occured!" << std::endl;
+ showErrorMsg("Unknown error occured!");
}
}