root/trunk/FRII/cartwheel-interface/LoadFileWindow.cc

Revision 10, 3.5 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Implementation file for the LoadFileWindow class, which allows the
17 // loading of sister XML files.
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>               // cartwheel-clients/sister.c++
26 #include <sister.hh>            // cartwheel-clients/sister.c++
27 #include "load_sister.hh"
28
29 //
30 // load button callback
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 // choose_select callback
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   // If it's a good value, stuff it in a holder & make it the input field
55   // value, too.
56   l->filename_holder = w->value();
57   l->filename->value(l->filename_holder.c_str());
58
59 #if 0                           // causes crashes on Windows...
60   l->load_file();
61 #endif // 0
62 }
63
64 //
65 // choose button callback
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 // cancel button callback
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 // LoadFileWindow constructor
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   // load file button
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   // cancel button
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   // notification widget, initially zippo
129   notify = new gui::TextLabel(text_x + 40, box_y + 70, 200, 30, "");
130   notify->bold(true);
131   add(notify);;
132 }
133
134 //
135 // load the given file
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 }
Note: See TracBrowser for help on using the browser.