| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#include <string> |
|---|
| 20 |
|
|---|
| 21 |
#include <FL/Fl.H> |
|---|
| 22 |
#include <FL/Fl_Return_Button.H> |
|---|
| 23 |
|
|---|
| 24 |
#include "LoadFileWindow.hh" |
|---|
| 25 |
#include <iff.hh> |
|---|
| 26 |
#include <sister.hh> |
|---|
| 27 |
#include "load_sister.hh" |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
static void load_cb(Fl_Widget * w, void * p) |
|---|
| 34 |
{ |
|---|
| 35 |
LoadFileWindow * l = (LoadFileWindow*) p; |
|---|
| 36 |
|
|---|
| 37 |
l->load_file(); |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
static void choose_select_cb(Fl_File_Chooser * w, void * p) |
|---|
| 45 |
{ |
|---|
| 46 |
LoadFileWindow * l = (LoadFileWindow*) p; |
|---|
| 47 |
|
|---|
| 48 |
l->notify->label(""); |
|---|
| 49 |
|
|---|
| 50 |
if (!w->value()) { |
|---|
| 51 |
return; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
l->filename_holder = w->value(); |
|---|
| 57 |
l->filename->value(l->filename_holder.c_str()); |
|---|
| 58 |
|
|---|
| 59 |
#if 0 |
|---|
| 60 |
l->load_file(); |
|---|
| 61 |
#endif |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
static void choose_cb(Fl_Widget * w, void * p) |
|---|
| 69 |
{ |
|---|
| 70 |
LoadFileWindow * l = (LoadFileWindow*) p; |
|---|
| 71 |
|
|---|
| 72 |
l->notify->label(""); |
|---|
| 73 |
l->chooser->show(); |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
static void cancel_cb(Fl_Widget * w, void * p) |
|---|
| 81 |
{ |
|---|
| 82 |
LoadFileWindow * l = (LoadFileWindow*) p; |
|---|
| 83 |
l->window()->hide(); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
LoadFileWindow::LoadFileWindow(int x, int y, int w, int h) |
|---|
| 91 |
: Fl_Group(x, y, w, h, "Open file") |
|---|
| 92 |
{ |
|---|
| 93 |
color(FL_WHITE); |
|---|
| 94 |
|
|---|
| 95 |
int text_x = 50; |
|---|
| 96 |
int box_x = 200; |
|---|
| 97 |
int box_y = 90; |
|---|
| 98 |
|
|---|
| 99 |
gui::TextLabel* b; |
|---|
| 100 |
b = new gui::TextLabel(text_x, box_y, 100, 24, "File to open:"); |
|---|
| 101 |
add(b); |
|---|
| 102 |
|
|---|
| 103 |
filename = new Fl_Input(box_x, box_y, 200, 24); |
|---|
| 104 |
box_y += 24 + 16; |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
Fl_Button* load_button = new Fl_Return_Button(130, box_y + 30, |
|---|
| 108 |
80, 24, "Open"); |
|---|
| 109 |
add(load_button); |
|---|
| 110 |
load_button->callback(load_cb, (void *) this); |
|---|
| 111 |
|
|---|
| 112 |
Fl_Button* choose_button = new Fl_Button(220, box_y + 30, |
|---|
| 113 |
80, 24, "Choose"); |
|---|
| 114 |
add(choose_button); |
|---|
| 115 |
choose_button->callback(choose_cb, (void *) this); |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
Fl_Button* cancel_button = new Fl_Button(310, box_y + 30, |
|---|
| 119 |
80, 24, "Cancel"); |
|---|
| 120 |
add(cancel_button); |
|---|
| 121 |
cancel_button->callback(cancel_cb, (void *) this); |
|---|
| 122 |
|
|---|
| 123 |
chooser = new Fl_File_Chooser(".", NULL, |
|---|
| 124 |
Fl_File_Chooser::SINGLE, |
|---|
| 125 |
"Choose a data file to load:"); |
|---|
| 126 |
chooser->callback(choose_select_cb, (void *) this); |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
notify = new gui::TextLabel(text_x + 40, box_y + 70, 200, 30, ""); |
|---|
| 130 |
notify->bold(true); |
|---|
| 131 |
add(notify);; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
void LoadFileWindow::load_file() |
|---|
| 139 |
{ |
|---|
| 140 |
const char * v = filename->value(); |
|---|
| 141 |
if (!v || strlen(v) == 0) { |
|---|
| 142 |
return; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
iff::AnalysisGroup * g = NULL; |
|---|
| 146 |
try { |
|---|
| 147 |
g = sister::parse_file(v); |
|---|
| 148 |
} catch (sister::exception& e) { |
|---|
| 149 |
notify->label("Error opening file; try again!"); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
if (g != NULL) { |
|---|
| 153 |
window()->hide(); |
|---|
| 154 |
|
|---|
| 155 |
if (g->n_sequences() == 1) { |
|---|
| 156 |
load_single((iff::SingleAnalysisGroup*) g); |
|---|
| 157 |
} else { |
|---|
| 158 |
load_pair((iff::PairAnalysisGroup*) g); |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
} |
|---|