source: source/class/pf/Application.js @ 148:73e43b1ec298

qx_legacy
Last change on this file since 148:73e43b1ec298 was 148:73e43b1ec298, checked in by fnevgeny, 15 years ago

Semicolumns missing...

File size: 86.8 KB
Line 
1/* ************************************************************************
2
3   Copyright: Weizmann Institute of Science
4
5   License: GPL
6
7   Authors: Evgeny Stambulchik
8
9************************************************************************ */
10
11/* ************************************************************************
12
13
14#asset(pf/image/*.png)
15#asset(pf/html/*.html)
16
17************************************************************************ */
18
19
20function changeN_e(ev)
21{
22    var e = ev.getTarget();
23    var N_e = e.getNumValue();
24   
25    if (isFinite(N_e) && this.plasma.e.setN(N_e)) {
26        this.updatePlasmaParameters();
27        this.updateGUI();
28    }
29}
30
31function changeT_e(ev)
32{
33    var e = ev.getTarget();
34    var T_e = e.getNumValue();
35   
36    if (isFinite(T_e)) {
37        this.plasma.e.setT(T_e);
38        this.plasma.i.setT(T_e);
39        this.plasma.r.setT(T_e);
40        this.updateGUI();
41    }
42}
43
44function changeZ_i(ev)
45{
46    var e = ev.getTarget();
47    var Z_i = parseInt(e.getValue());
48   
49    if (isFinite(Z_i)) {
50        this.plasma.i.setQ(Z_i);
51        this.updatePlasmaParameters();
52        this.updateGUI();
53    }
54}
55
56function changeT_i(ev)
57{
58    var e = ev.getTarget();
59    var T_i = e.getNumValue();
60   
61    if (isFinite(T_i)) {
62        this.plasma.i.setT(T_i);
63        this.plasma.r.setT(T_i);
64        this.updateGUI();
65    }
66}
67
68function changeZ_r(ev)
69{
70    var e = ev.getTarget();
71    var Z_r = parseInt(e.getValue());
72   
73    if (isFinite(Z_r)) {
74        this.plasma.r.setQ(Z_r);
75        this.updatePlasmaParameters();
76        this.updateGUI();
77    }
78}
79
80function changeP_r(ev)
81{
82    var e = ev.getTarget();
83    var P_r = parseInt(e.getValue())/100.0;
84   
85    if (isFinite(P_r)) {
86        this.plasma.P_r = P_r;
87        this.updatePlasmaParameters();
88        this.updateGUI();
89    }
90}
91
92function changeT_r(ev)
93{
94    var e = ev.getTarget();
95    var T_r = e.getNumValue();
96   
97    if (isFinite(T_r)) {
98        this.plasma.r.setT(T_r);
99        this.updateGUI();
100    }
101}
102
103function changeM_i(ev)
104{
105    var e = ev.getTarget();
106    var M_i = parseInt(e.getValue());
107   
108    if (isFinite(M_i)) {
109        this.plasma.i.setM(M_i);
110        this.updateGUI();
111    }
112}
113
114function changeM_r(ev)
115{
116    var e = ev.getTarget();
117    var M_r = parseInt(e.getValue());
118   
119    if (isFinite(M_r)) {
120        this.plasma.r.setM(M_r);
121        this.updateGUI();
122    }
123}
124
125function changeN_u(ev)
126{
127    var e = ev.getTarget();
128    var n_u = parseInt(e.getValue());
129   
130    this.plasma.n_u = n_u;
131    this.updateGUI();
132}
133
134function changeN_l(ev)
135{
136    var e = ev.getTarget();
137    var n_l = parseInt(e.getValue());
138   
139    this.plasma.n_l = n_l;
140    this.updateGUI();
141}
142
143function changeB(ev)
144{
145    var e = ev.getTarget();
146    var v = e.getNumValue();
147   
148    if (isFinite(v)) {
149        this.plasma.B = v;
150        this.updateGUI();
151    }
152}
153
154function viewMenuCB(ev)
155{
156    var explorer_is_seen;
157   
158    if (this.entity_tree.isSeeable()) {
159        explorer_is_seen = true;
160    } else {
161        explorer_is_seen = false;
162    }
163   
164    this.showSectionsButton.setEnabled(explorer_is_seen);
165    this.showSpeciesButton.setEnabled(explorer_is_seen);
166    this.redrawButton.setEnabled(this.canvas.isSeeable());
167
168    if (this.prefs.autoLoadWiki) {
169        this.loadWikiButton.setEnabled(false);
170    } else {
171        var tree = this.entity_tree;
172        var leaf = tree.getSelectedElement();
173        if (leaf && leaf.classname == "qx.legacy.ui.tree.TreeFile" && explorer_is_seen) {
174            this.loadWikiButton.setEnabled(true);
175        } else {
176            this.loadWikiButton.setEnabled(false);
177        }
178    }
179}
180
181function editMenuCB(ev)
182{
183    var explorer_is_seen;
184   
185    if (this.entity_tree.isSeeable()) {
186        explorer_is_seen = true;
187    } else {
188        explorer_is_seen = false;
189    }
190
191    var tree = this.entity_tree;
192    var leaf = tree.getSelectedElement();
193
194    if (leaf && leaf.classname == "qx.legacy.ui.tree.TreeFile" && explorer_is_seen) {
195        if (this.isFavorite(leaf)) {
196            this.editMenuButtonAddToFav.setEnabled(false);
197            this.editMenuButtonRemFromFav.setEnabled(true);
198        } else {
199            this.editMenuButtonAddToFav.setEnabled(true);
200            this.editMenuButtonRemFromFav.setEnabled(false);
201        }
202    } else {
203        this.editMenuButtonAddToFav.setEnabled(false);
204        this.editMenuButtonRemFromFav.setEnabled(false);
205    }
206}
207
208function treeMenuCB(ev)
209{
210    if (ev.getButton() == "right") {
211        var menu = this.treeMenu;
212
213        if (menu.isSeeable()) {
214            menu.hide();
215        } else {
216            var leaf = ev.getTarget();
217            var el = leaf.getElement();
218           
219            if (leaf.classname == "qx.legacy.ui.tree.TreeFile") {
220                if (this.isFavorite(leaf)) {
221                    this.treeMenuButtonAddToFav.setEnabled(false);
222                    this.treeMenuButtonRemFromFav.setEnabled(true);
223                } else {
224                    this.treeMenuButtonAddToFav.setEnabled(true);
225                    this.treeMenuButtonRemFromFav.setEnabled(false);
226                }
227            } else {
228                this.treeMenuButtonAddToFav.setEnabled(false);
229                this.treeMenuButtonRemFromFav.setEnabled(false);
230            }
231           
232            // position the menu
233            menu.setLeft(ev.getClientX());
234            menu.setTop(ev.getClientY());
235
236            menu.show();
237        };
238
239        ev.stopPropagation();
240    }
241}
242
243function showFundamentalCB(ev)
244{
245    this.showFundamental = !this.showFundamental;
246    this.rePopulateTree();
247}
248
249function showSpectroscopyCB(ev)
250{
251    this.showSpectroscopy = !this.showSpectroscopy;
252    this.rePopulateTree();
253}
254
255function showWavesCB(ev)
256{
257    this.showWaves = !this.showWaves;
258    this.rePopulateTree();
259}
260
261function showCollisionsCB(ev)
262{
263    this.showCollisions = !this.showCollisions;
264    this.rePopulateTree();
265}
266
267function showElectronsCB(ev)
268{
269    this.showElectrons = !this.showElectrons;
270    this.rePopulateTree();
271}
272
273function showIonsCB(ev)
274{
275    this.showIons = !this.showIons;
276    this.rePopulateTree();
277}
278
279function showRadiatorsCB(ev)
280{
281    this.showRadiators = !this.showRadiators;
282    this.rePopulateTree();
283}
284
285function addToFavCB(ev)
286{
287    var tree = this.entity_tree;
288    var leaf = tree.getSelectedElement();
289
290    if (!leaf) {
291        return;
292    }
293
294    leaf.setTextColor("red");
295
296    // Add to the list of favorites
297    var fav = new Array;
298    fav.entity  = leaf.getUserData("entity");
299    fav.species = leaf.getUserData("species");
300    fav.color   = this.nextColor();
301    this.favorites.push(fav);
302   
303    // Switch the dimension selector ...
304    this.gui_compare_dim.selectByValue(fav.entity.dimension);
305    // ... and update the list of favorites
306    this.updateFavoritesListView();
307    this.updateLegendListView();
308}
309
310function removeFromFavCB(ev)
311{
312    var tree = this.entity_tree;
313    var leaf = tree.getSelectedElement();
314
315    if (!leaf) {
316        return;
317    }
318    leaf.setTextColor("black");
319
320    var entity  = leaf.getUserData("entity");
321    var species = leaf.getUserData("species");
322
323    // Remove from the list of favorites
324    for (var k = 0; k < this.favorites.length; k++) {
325        var fav = this.favorites[k];
326        if (fav.entity  == entity && fav.species == species) {
327            this.favorites.splice(k, 1);
328            break;
329        }
330    }
331
332    // Switch the dimension selector ...
333    this.gui_compare_dim.selectByValue(entity.dimension);
334    // ... and update the list of favorites
335    this.updateFavoritesListView();
336    this.updateLegendListView();
337}
338
339function clickTreeCB(ev)
340{
341    var e = ev.getTarget();
342    if (e.isSelected()) {
343        var entity = e.getUserData("entity");
344
345        if (entity) {
346            this.gui_entity_units.update(entity.dimension,
347                this.prefs.units[entity.dimension]);
348        } else {
349            this.gui_entity_units.update(null, null);
350        }
351       
352        this.updateEntityValue();
353    }
354}
355
356function changeUnitsCB(ev)
357{
358    this.updateEntityValue();
359}
360
361/**
362 * The application
363 */
364qx.Class.define("pf.Application",
365{
366    extend : qx.application.Inline,
367    include : [qx.legacy.application.MGuiCompat],
368
369    /*
370    *****************************************************************************
371       MEMBERS
372    *****************************************************************************
373    */
374
375    members :
376    {
377        showFundamental  : true,
378        showSpectroscopy : true,
379        showWaves        : true,
380        showCollisions   : true,
381
382        showElectrons  : true,
383        showIons       : true,
384        showRadiators  : true,
385       
386        plasma : null,
387
388        updatePlasmaParameters : function()
389        {
390            return this.plasma.updateParameters();
391        },
392       
393        updateGUI : function()
394        {
395            if (this.prefs.currentConfigName) {
396                this.gui_configName.setLabel(this.prefs.currentConfigName);
397            }
398           
399            this.gui_N_e.setNumValue(this.plasma.e.getN());
400            this.gui_T_e.setNumValue(this.plasma.e.getT());
401           
402            this.gui_N_i.setNumValue(this.plasma.i.getN());
403            this.gui_T_i.setNumValue(this.plasma.i.getT());
404            this.gui_Z_i.setValue(this.plasma.i.getQ());
405            this.gui_M_i.setValue(this.plasma.i.getM());
406
407            this.gui_P_r.setValue(100*this.plasma.P_r);
408           
409            this.gui_N_r.setNumValue(this.plasma.r.getN());
410            this.gui_T_r.setNumValue(this.plasma.r.getT());
411            this.gui_Z_r.setValue(this.plasma.r.getQ());
412            this.gui_Zcore.setValue(this.plasma.r.getQ() + 1);
413            this.gui_M_r.setValue(this.plasma.r.getM());
414           
415            this.gui_B.setNumValue(this.plasma.B);
416           
417            this.gui_n_u.setValue(this.plasma.n_u);
418            this.gui_n_l.setValue(this.plasma.n_l);
419           
420            // Update the currently selected entity
421            this.updateEntityValue();
422           
423            // Update the list of favorites
424            this.updateFavoritesListView();
425            this.updateLegendListView();
426        },
427       
428
429        getEntityFullName : function (entity, species)
430        {
431            var name = entity.name;
432            if (entity.nspecies == 1) {
433                var prepos = entity.prepos;
434                if (!prepos) {
435                    prepos = "of";
436                }
437                name += " " + prepos + " ";
438                switch (species.id) {
439                case "e":
440                    name += "electrons";
441                    break;
442                case "i":
443                    name += "ions";
444                    break;
445                case "r":
446                    name += "radiators";
447                    break;
448                }
449            }
450           
451            return name;
452        },
453       
454        evaluateEntityValue : function(entity, species)
455        {
456            var formula;
457            if (entity.nspecies == 1) {
458                var species_str = "this.plasma." + species.id;
459                formula = entity.formula.replace(/\%s1/g, species_str);
460            } else {
461                formula = entity.formula;
462            }
463            var v = eval(formula);
464           
465            return v;
466        },
467       
468        updateEntityValue : function()
469        {
470            var tree = this.entity_tree;
471            var leaf = tree.getSelectedElement();
472           
473            if (!leaf) {
474                return;
475            }
476           
477            var entity  = leaf.getUserData("entity");
478            var species = leaf.getUserData("species");
479           
480            var name, section, value;
481            if (entity) {
482                var v     = this.evaluateEntityValue(entity, species);
483                var scale = this.gui_entity_units.getSelected().getValue();
484               
485                name    = this.getEntityFullName(entity, species);
486                section = entity.section;
487                value   = v*scale
488            } else {
489                name    = null;
490                section = null;
491                value   = 0;
492            }
493           
494            this.gui_entity_name.setValue(name);
495
496            this.gui_entity_section.setValue(section);
497
498            this.gui_entity_value.setNumValue(value);
499           
500            if (this.prefs.autoLoadWiki) {
501                this.showWikiPage(entity);
502            } else {
503                this.gui_wiki.setSource(null);
504            }
505        },
506
507        isFavorite : function(leaf)
508        {
509            var entity  = leaf.getUserData("entity");
510            var species = leaf.getUserData("species");
511
512            for (var k = 0; k < this.favorites.length; k++) {
513                var fav = this.favorites[k];
514                if (fav.entity  == entity && fav.species == species) {
515                    return true;
516                    break;
517                }
518            }
519           
520            return false;
521        },
522
523        populateTree : function()
524        {
525            var i, n = plasma_entities.length;
526            var sa = new Array;
527            if (this.showElectrons) {
528                sa.push(this.plasma.e)
529            }
530            if (this.showIons) {
531                sa.push(this.plasma.i)
532            }
533            if (this.showRadiators) {
534                sa.push(this.plasma.r)
535            }
536           
537            for (var i = 0; i < n; i++) {
538                var entity = plasma_entities[i];
539               
540                if (entity.section == "fundamental" &&
541                    this.showFundamental != true) {
542                    continue;
543                }
544                if (entity.section == "spectroscopy" &&
545                    this.showSpectroscopy != true) {
546                    continue;
547                }
548                if (entity.section == "waves" &&
549                    this.showWaves != true) {
550                    continue;
551                }
552                if (entity.section == "collisions" &&
553                    this.showCollisions != true) {
554                    continue;
555                }
556               
557                var folder;
558                switch (entity.dimension) {
559                case "frequency":
560                    folder = this.gui_folder_freq;
561                    break;
562                case "length":
563                    folder = this.gui_folder_length;
564                    break;
565                case "velocity":
566                    folder = this.gui_folder_vel;
567                    break;
568                case "energy":
569                    folder = this.gui_folder_energy;
570                    break;
571                case "pressure":
572                    folder = this.gui_folder_pressure;
573                    break;
574                case "area":
575                    folder = this.gui_folder_area;
576                    break;
577                case "power_density":
578                    folder = this.gui_folder_power_density;
579                    break;
580                case "spectral_power_density":
581                    folder = this.gui_folder_spectral_power_density;
582                    break;
583                case "none":
584                    folder = this.gui_folder_none;
585                    break;
586                default:
587                    folder = this.gui_folder_misc;
588                    break;
589                }
590               
591                var leaf;
592               
593                switch (entity.nspecies) {
594                case 1:
595                    for (var j = 0; j < sa.length; j++) {
596                        var s = sa[j];
597                        var icon = "pf/image/" + s.id + "_small.png";
598
599                        leaf = new qx.legacy.ui.tree.TreeFile(entity.name, icon);
600                        leaf.addListener("changeSelected", clickTreeCB, this);
601                        leaf.addListener("contextmenu", treeMenuCB, this);
602                        leaf.setUserData("entity", entity);
603                        leaf.setUserData("species", s);
604                       
605                        if (this.isFavorite(leaf)) {
606                            leaf.setTextColor("red");
607                        }
608
609                        folder.add(leaf);
610                    }
611                    break;
612                default:
613                    leaf = new qx.legacy.ui.tree.TreeFile(entity.name,
614                        "pf/image/all_small.png");
615                    leaf.addListener("changeSelected", clickTreeCB, this);
616                    leaf.addListener("contextmenu", treeMenuCB, this);
617                    leaf.setUserData("entity", entity);
618
619                    if (this.isFavorite(leaf)) {
620                        leaf.setTextColor("red");
621                    }
622                   
623                    folder.add(leaf);
624                    break;
625                }
626            }
627        }, 
628
629        cleanTree : function()
630        {
631            this.gui_folder_freq.removeAll();
632           
633            this.gui_folder_length.removeAll();
634           
635            this.gui_folder_vel.removeAll();
636           
637            this.gui_folder_none.removeAll();
638           
639            this.gui_folder_energy.removeAll();
640           
641            this.gui_folder_pressure.removeAll();
642           
643            this.gui_folder_area.removeAll();
644           
645            this.gui_folder_power_density.removeAll();
646
647            this.gui_folder_spectral_power_density.removeAll();
648           
649            this.gui_folder_misc.removeAll();
650        },
651
652        rePopulateTree : function()
653        {
654            this.cleanTree();
655           
656            this.populateTree();
657        },
658
659
660        updateFavoritesListView : function()
661        {
662            var lv = this.favoritesListView;
663            var rowData = lv.getData();
664            rowData.length = 0;
665           
666            var dimension = this.gui_compare_dim.getSelectedValue();
667           
668            var scale = this.gui_compare_units.getSelectedValue();
669           
670            for (var i = 0; i < this.favorites.length; i++) {
671                var fav = this.favorites[i];
672                var entity = fav.entity;
673               
674                if (entity.dimension != dimension) {
675                    continue;
676                }
677               
678                var species = fav.species;
679
680                var icon;
681                if (species) {
682                    icon = "pf/image/" + species.id + "_small.png";
683                } else {
684                    icon = "pf/image/all_small.png";
685                }
686                var name = this.getEntityFullName(entity, species);
687                var value = scale*this.evaluateEntityValue(entity, species);
688
689                rowData.push({ s_icon  : {icon       : icon,
690                                          iconWidth  : 16, 
691                                          iconHeight : 16             },
692                               name    : {text       : name           },
693                               section : {text       : entity.section },
694                               value   : {text       : pf.util.Format.numPrint(value)}
695                             });
696            }
697           
698            lv.updateSort();
699            lv.update();
700        },
701
702        updateLegendListView : function()
703        {
704            var lv = this.legendListView;
705            var rowData = lv.getData();
706            rowData.length = 0;
707           
708            var dimension = this.gui_compare_dim.getSelectedValue();
709           
710            for (var i = 0; i < this.favorites.length; i++) {
711                var fav = this.favorites[i];
712                var entity = fav.entity;
713               
714                if (entity.dimension != dimension) {
715                    continue;
716                }
717               
718                var species = fav.species;
719
720                var icon;
721                if (species) {
722                    icon = "pf/image/" + species.id + "_small.png";
723                } else {
724                    icon = "pf/image/all_small.png";
725                }
726                var name  = this.getEntityFullName(entity, species);
727                var color = fav.color;
728
729                rowData.push({ s_icon   : {icon       : icon,
730                                           iconWidth  : 16, 
731                                           iconHeight : 16    },
732                               name     : {text       : name  },
733                               color    : {text       : color,
734                                           textColor  : color },
735                               favorite : fav
736                             });
737            }
738            lv.update();
739        },
740
741
742        renderTabPage : function(label, icon, checked)
743        {
744            var tab_id, page_id;
745           
746            tab_id = new qx.legacy.ui.pageview.tabview.Button(label, icon);
747            this.tabbar.add(tab_id);
748            page_id = new qx.legacy.ui.pageview.tabview.Page(tab_id);
749            page_id.setHeight("100%");
750            page_id.setPadding(10, 10, 10, 10);
751            page_id.setBackgroundColor("white");
752            this.tabpane.add(page_id);
753
754            if (checked) {
755                tab_id.setChecked(true);
756            }
757           
758            return page_id;
759        },
760
761        renderParametersTab : function()
762        {
763            var page_id = this.renderTabPage("Parameters",
764                "pf/image/tab-parameters.png", true);
765
766            var fr, gl, rc0, rc, rc1, rc2;
767
768            rc0 = new qx.legacy.ui.layout.VerticalBoxLayout;
769            rc0.setWidth("100%");
770            rc0.setHeight("auto");
771            rc0.setSpacing(1);
772            page_id.add(rc0);
773
774            fr = new qx.legacy.ui.groupbox.GroupBox("Configuration name",
775                "pf/image/info.png");
776            fr.setDimension("100%", "auto");
777            fr.setBackgroundColor("#e1eeff");
778            fr.getLegendObject().setBackgroundColor("#e1eeff");
779            this.gui_configName =
780                new qx.legacy.ui.basic.Atom(this.prefs.currentConfigName);
781            fr.add(this.gui_configName);
782            rc0.add(fr);
783
784            rc = new qx.legacy.ui.layout.HorizontalBoxLayout;
785            rc.setWidth("100%");
786            rc.setHeight("auto");
787            rc.setSpacing(1);
788            rc0.add(rc);
789           
790            rc1 = new qx.legacy.ui.layout.VerticalBoxLayout;
791            rc1.setWidth("50%");
792            rc1.setHeight("auto");
793            rc1.setSpacing(2);
794            rc.add(rc1);
795           
796            rc2 = new qx.legacy.ui.layout.VerticalBoxLayout;
797            rc2.setWidth("50%");
798            rc2.setHeight("auto");
799            rc2.setSpacing(2);
800            rc.add(rc2);
801           
802            fr = new qx.legacy.ui.groupbox.GroupBox("Electrons",
803                "pf/image/e_small.png");
804            fr.setDimension("100%", "auto");
805            fr.setBackgroundColor("#eeeeff");
806            fr.getLegendObject().setBackgroundColor("#eeeeff");
807
808            rc1.add(fr);
809
810            gl = new qx.legacy.ui.layout.GridLayout;
811            gl.setWidth("100%");
812            gl.setVerticalSpacing(4);
813            gl.setHorizontalSpacing(6);
814            gl.setColumnCount(2);
815            gl.setColumnWidth(0, "25%");
816            gl.setColumnWidth(1, "75%");
817            gl.setRowCount(2);
818            gl.setRowHeight(0, 30);
819            gl.setRowHeight(1, 30);
820
821            fr.add(gl);
822
823            var l, e;
824
825            // N_e
826            l = new qx.legacy.ui.basic.Label("N<sub>e</sub> (cm<sup>-3</sup>):");
827            gl.add(l, 0, 0);
828            e = new pf.ui.TextField(this.plasma.e.getN());
829            gl.add(e, 1, 0);
830            e.addListener("changeValue", changeN_e, this);
831            this.gui_N_e = e;
832
833            // T_e
834            l = new qx.legacy.ui.basic.Label("T<sub>e</sub> (eV):");
835            gl.add(l, 0, 1);
836            e = new pf.ui.TextField(this.plasma.e.getT());
837            gl.add(e, 1, 1);
838            e.addListener("changeValue", changeT_e, this);
839            this.gui_T_e = e;
840
841
842            fr = new qx.legacy.ui.groupbox.GroupBox("Ions",
843                "pf/image/i_small.png");
844            fr.setDimension("100%", "auto");
845            fr.setBackgroundColor("#ffeeee");
846            fr.getLegendObject().setBackgroundColor("#ffeeee");
847
848            rc1.add(fr);
849
850            gl = new qx.legacy.ui.layout.GridLayout;
851            gl.setWidth("100%");
852            gl.setVerticalSpacing(4);
853            gl.setHorizontalSpacing(6);
854            gl.setColumnCount(2);
855            gl.setColumnWidth(0, "25%");
856            gl.setColumnWidth(1, "75%");
857            gl.setRowCount(4);
858            gl.setRowHeight(0, 30);
859            gl.setRowHeight(1, 30);
860            gl.setRowHeight(2, 30);
861            gl.setRowHeight(3, 30);
862
863            fr.add(gl);
864
865            // Z_i
866            l = new qx.legacy.ui.basic.Label("Z<sub>i</sub>:");
867            gl.add(l, 0, 0);
868            e = new pf.ui.Spinner(1, this.plasma.i.getQ(), 100);
869            gl.add(e, 1, 0);
870            e.addListener("change", changeZ_i, this);
871            this.gui_Z_i = e;
872           
873            // M_i
874            l = new qx.legacy.ui.basic.Label("M<sub>i</sub>:");
875            gl.add(l, 0, 1);
876            e = new pf.ui.Spinner(1, this.plasma.i.getM(), 200);
877            gl.add(e, 1, 1);
878            e.addListener("change", changeM_i, this);
879            this.gui_M_i = e;
880           
881            // T_i
882            l = new qx.legacy.ui.basic.Label("T<sub>i</sub> (eV):");
883            gl.add(l, 0, 2);
884            e = new pf.ui.TextField(this.plasma.i.getT());
885            gl.add(e, 1, 2);
886            e.addListener("changeValue", changeT_i, this);
887            this.gui_T_i = e;
888
889            // N_i
890            l = new qx.legacy.ui.basic.Label("N<sub>i</sub> (cm<sup>-3</sup>):");
891            gl.add(l, 0, 3);
892            e = new pf.ui.TextField(this.plasma.i.getN());
893            gl.add(e, 1, 3);
894            e.setReadOnly(true);
895            this.gui_N_i = e;
896           
897           
898            fr = new qx.legacy.ui.groupbox.GroupBox("Radiators",
899                "pf/image/r_small.png");
900            fr.setDimension("100%", "auto");
901            fr.setBackgroundColor("#eeffee");
902            fr.getLegendObject().setBackgroundColor("#eeffee");
903
904            rc2.add(fr);
905
906            gl = new qx.legacy.ui.layout.GridLayout;
907            gl.setWidth("100%");
908            gl.setVerticalSpacing(4);
909            gl.setHorizontalSpacing(6);
910            gl.setColumnCount(2);
911            gl.setColumnWidth(0, "25%");
912            gl.setColumnWidth(1, "75%");
913            gl.setRowCount(5);
914            gl.setRowHeight(0, 30);
915            gl.setRowHeight(1, 30);
916            gl.setRowHeight(2, 30);
917            gl.setRowHeight(3, 30);
918            gl.setRowHeight(4, 30);
919
920            fr.add(gl);
921
922
923            // Z_r
924            l = new qx.legacy.ui.basic.Label("Z<sub>r</sub>:");
925            gl.add(l, 0, 0);
926            e = new pf.ui.Spinner(0, this.plasma.r.getQ(), 100);
927            gl.add(e, 1, 0);
928            e.addListener("change", changeZ_r, this);
929            this.gui_Z_r = e;
930
931            // M_r
932            l = new qx.legacy.ui.basic.Label("M<sub>r</sub>:");
933            gl.add(l, 0, 1);
934            e = new pf.ui.Spinner(1, this.plasma.r.getM(), 200);
935            gl.add(e, 1, 1);
936            e.addListener("change", changeM_r, this);
937            this.gui_M_r = e;
938
939            // T_r
940            l = new qx.legacy.ui.basic.Label("T<sub>r</sub> (eV):");
941            gl.add(l, 0, 2);
942            e = new pf.ui.TextField(this.plasma.r.getT());
943            gl.add(e, 1, 2);
944            e.addListener("changeValue", changeT_r, this);
945            this.gui_T_r = e;
946
947            // P_r
948            l = new qx.legacy.ui.basic.Label("P<sub>r</sub> (%):");
949            gl.add(l, 0, 3);
950            e = new pf.ui.Spinner(0, 100*this.plasma.P_r, 100);
951            gl.add(e, 1, 3);
952            e.addListener("change", changeP_r, this);
953            this.gui_P_r = e;
954
955            // N_r
956            l = new qx.legacy.ui.basic.Label("N<sub>r</sub> (cm<sup>-3</sup>):");
957            gl.add(l, 0, 4);
958            e = new pf.ui.TextField(this.plasma.r.getN());
959            e.setReadOnly(true);
960            gl.add(e, 1, 4);
961            this.gui_N_r = e;
962
963
964            fr = new qx.legacy.ui.groupbox.GroupBox("Fields",
965                "pf/image/field_small.png");
966            fr.setDimension("100%", "auto");
967            fr.setBackgroundColor("#ffffdd");
968            fr.getLegendObject().setBackgroundColor("#ffffdd");
969
970            rc1.add(fr);
971
972            gl = new qx.legacy.ui.layout.GridLayout;
973            gl.setWidth("100%");
974            gl.setVerticalSpacing(4);
975            gl.setHorizontalSpacing(6);
976            gl.setColumnCount(2);
977            gl.setColumnWidth(0, "25%");
978            gl.setColumnWidth(1, "75%");
979            gl.setRowCount(1);
980            gl.setRowHeight(0, 30);
981
982            fr.add(gl);
983
984
985            l = new qx.legacy.ui.basic.Label("B (T):");
986            gl.add(l, 0, 0);
987            e = new pf.ui.TextField(this.plasma.B);
988            gl.add(e, 1, 0);
989            e.addListener("changeValue", changeB, this);
990            this.gui_B = e;
991
992            // Atomic system frame
993            fr = new qx.legacy.ui.groupbox.GroupBox("Atomic system",
994                "pf/image/all_small.png");
995            fr.setDimension("100%", "auto");
996            fr.setBackgroundColor("#ffffdd");
997            fr.getLegendObject().setBackgroundColor("#ffffdd");
998
999            rc2.add(fr);
1000
1001            gl = new qx.legacy.ui.layout.GridLayout;
1002            gl.setWidth("100%");
1003            gl.setVerticalSpacing(4);
1004            gl.setHorizontalSpacing(6);
1005            gl.setColumnCount(2);
1006            gl.setColumnWidth(0, "25%");
1007            gl.setColumnWidth(1, "75%");
1008            gl.setRowCount(3);
1009            gl.setRowHeight(0, 30);
1010            gl.setRowHeight(1, 30);
1011            gl.setRowHeight(2, 30);
1012
1013            fr.add(gl);
1014
1015            l = new qx.legacy.ui.basic.Label("Z<sub>core</sub>:");
1016            gl.add(l, 0, 0);
1017            e = new qx.legacy.ui.form.TextField(this.plasma.r.getQ() + 1);
1018            e.setReadOnly(true);
1019            gl.add(e, 1, 0);
1020            this.gui_Zcore = e;
1021
1022            l = new qx.legacy.ui.basic.Label("n<sub>u</sub>:");
1023            gl.add(l, 0, 1);
1024            e = new pf.ui.Spinner(2, this.plasma.n_u, 1000);
1025            gl.add(e, 1, 1);
1026            e.addListener("change", changeN_u, this);
1027            this.gui_n_u = e;
1028
1029            l = new qx.legacy.ui.basic.Label("n<sub>l</sub>:");
1030            gl.add(l, 0, 2);
1031            e = new pf.ui.Spinner(1, this.plasma.n_l, 1000);
1032            gl.add(e, 1, 2);
1033            e.addListener("change", changeN_l, this);
1034            this.gui_n_l = e;
1035        },
1036
1037        renderExplorerTab : function()
1038        {
1039            var page_id = this.renderTabPage("Explorer",
1040                "pf/image/tab-explorer.png", false);
1041           
1042            var sp = new qx.legacy.ui.splitpane.HorizontalSplitPane(300, "1*");
1043            sp.set(
1044            {
1045                left            : 1,
1046                right           : 1,
1047                top             : 1,
1048                bottom          : 1,
1049                border          : "inset-thin",
1050                showKnob        : true
1051            });
1052            page_id.add(sp);
1053                       
1054            var left_pane  = sp.getLeftArea();
1055            left_pane.setBackgroundColor("white");
1056            left_pane.setBorder("inset-thin");
1057            var right_pane = sp.getRightArea();
1058            right_pane.setBackgroundColor("white");
1059            right_pane.setBorder("inset-thin");
1060            var tree = new qx.legacy.ui.tree.Tree("Browser");
1061            tree.set(
1062            {
1063                overflow        : "scroll",
1064                height          : "100%",
1065                width           : "100%",
1066                paddingLeft     : 4,
1067                paddingTop      : 4
1068            });
1069            left_pane.add(tree);
1070           
1071            this.entity_tree = tree;
1072           
1073            var folder;
1074           
1075            folder = new qx.legacy.ui.tree.TreeFolder("Dimensionless");
1076            folder.setAlwaysShowPlusMinusSymbol(true);
1077            folder.addListener("changeSelected", clickTreeCB, this);
1078            tree.add(folder);
1079            this.gui_folder_none = folder;
1080
1081            folder = new qx.legacy.ui.tree.TreeFolder("Length");
1082            folder.setAlwaysShowPlusMinusSymbol(true);
1083            folder.addListener("changeSelected", clickTreeCB, this);
1084            tree.add(folder);
1085            this.gui_folder_length = folder;
1086           
1087            folder = new qx.legacy.ui.tree.TreeFolder("Frequency");
1088            folder.setAlwaysShowPlusMinusSymbol(true);
1089            folder.addListener("changeSelected", clickTreeCB, this);
1090            tree.add(folder);
1091            this.gui_folder_freq = folder;
1092
1093            folder = new qx.legacy.ui.tree.TreeFolder("Velocity");
1094            folder.setAlwaysShowPlusMinusSymbol(true);
1095            folder.addListener("changeSelected", clickTreeCB, this);
1096            tree.add(folder);
1097            this.gui_folder_vel = folder;
1098           
1099            folder = new qx.legacy.ui.tree.TreeFolder("Area");
1100            folder.setAlwaysShowPlusMinusSymbol(true);
1101            folder.addListener("changeSelected", clickTreeCB, this);
1102            tree.add(folder);
1103            this.gui_folder_area = folder;
1104
1105            folder = new qx.legacy.ui.tree.TreeFolder("Energy");
1106            folder.setAlwaysShowPlusMinusSymbol(true);
1107            folder.addListener("changeSelected", clickTreeCB, this);
1108            tree.add(folder);
1109            this.gui_folder_energy = folder;
1110
1111            folder = new qx.legacy.ui.tree.TreeFolder("Pressure");
1112            folder.setAlwaysShowPlusMinusSymbol(true);
1113            folder.addListener("changeSelected", clickTreeCB, this);
1114            tree.add(folder);
1115            this.gui_folder_pressure = folder;
1116
1117            folder = new qx.legacy.ui.tree.TreeFolder("Power density");
1118            folder.setAlwaysShowPlusMinusSymbol(true);
1119            folder.addListener("changeSelected", clickTreeCB, this);
1120            tree.add(folder);
1121            this.gui_folder_power_density = folder;
1122
1123            folder = new qx.legacy.ui.tree.TreeFolder("Power spectral density");
1124            folder.setAlwaysShowPlusMinusSymbol(true);
1125            folder.addListener("changeSelected", clickTreeCB, this);
1126            tree.add(folder);
1127            this.gui_folder_spectral_power_density = folder;
1128
1129            folder = new qx.legacy.ui.tree.TreeFolder("Miscellaneous");
1130            folder.setAlwaysShowPlusMinusSymbol(true);
1131            folder.addListener("changeSelected", clickTreeCB, this);
1132            tree.add(folder);
1133            this.gui_folder_misc = folder;
1134
1135            this.populateTree();
1136
1137            tree.setHideNode(true);
1138            tree.setRootOpenClose(true);
1139           
1140            // Build context-sensitive popup menu
1141            this.treeMenu = new qx.legacy.ui.menu.Menu;
1142            var button;
1143           
1144            button = new qx.legacy.ui.menu.Button("Add to Favorites",
1145                "pf/image/favorite-add.png");
1146            button.addListener("execute", addToFavCB, this);
1147            this.treeMenu.add(button);
1148            this.treeMenuButtonAddToFav = button;
1149            button = new qx.legacy.ui.menu.Button("Remove from Favorites",
1150                "pf/image/favorite-delete.png");
1151            button.addListener("execute", removeFromFavCB, this);
1152            this.treeMenu.add(button);
1153            this.treeMenuButtonRemFromFav = button;
1154           
1155            this.doc.add(this.treeMenu);
1156
1157
1158            var vbl = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
1159            vbl.set(
1160            {
1161                height          : "100%",
1162                width           : "100%",
1163                padding         : 4,
1164                spacing         : 10
1165            });
1166            right_pane.add(vbl);
1167
1168            var gl = new qx.legacy.ui.layout.GridLayout;
1169            gl.set(
1170            {
1171                height            : "auto",
1172                left              : 4,
1173                right             : 4,
1174                top               : 4,
1175                verticalSpacing   : 4,
1176                horizontalSpacing : 6
1177            });
1178           
1179            gl.setColumnCount(3);
1180            gl.setColumnWidth(0, "15%");
1181            gl.setColumnWidth(1, "60%");
1182            gl.setColumnWidth(2, "20%");
1183            gl.setRowCount(3);
1184            gl.setRowHeight(0, 30);
1185            gl.setRowHeight(1, 30);
1186            gl.setRowHeight(2, 30);
1187
1188            var l, e;
1189
1190            l = new qx.legacy.ui.basic.Label("Name:");
1191            gl.add(l, 0, 0);
1192            e = new qx.legacy.ui.form.TextField();
1193            e.setReadOnly(true);
1194            this.gui_entity_name = e;
1195            gl.add(e, 1, 0);
1196
1197            l = new qx.legacy.ui.basic.Label("Value:");
1198            gl.add(l, 0, 1);
1199            e = new pf.ui.TextField("");
1200            e.setReadOnly(true);
1201            gl.add(e, 1, 1);
1202            this.gui_entity_value = e;
1203
1204            e = new pf.UnitSelector();
1205            e.addListener("changeSelected", changeUnitsCB, this);
1206            gl.add(e, 2, 1);
1207            this.gui_entity_units = e;
1208
1209            l = new qx.legacy.ui.basic.Label("Section:");
1210            gl.add(l, 0, 2);
1211            e = new qx.legacy.ui.form.TextField();
1212            e.setReadOnly(true);
1213            this.gui_entity_section = e;
1214            gl.add(e, 1, 2);
1215
1216            vbl.add(gl);
1217           
1218            var frame = new qx.legacy.ui.embed.Iframe();
1219            frame.set({ width : '100%', height : '2*' });
1220           
1221            vbl.add(frame);
1222           
1223            this.gui_wiki = frame;
1224        },
1225       
1226        renderCompareTab : function()
1227        {
1228            var page_id = this.renderTabPage("Compare",
1229                "pf/image/tab-compare.png");
1230           
1231            var bl = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
1232            bl.setWidth("100%");
1233            bl.setHeight("100%");
1234            bl.setSpacing(10);
1235            page_id.add(bl);
1236           
1237            var rc = new qx.legacy.ui.layout.HorizontalBoxLayout;
1238            rc.setWidth("100%");
1239            rc.setHeight("auto");
1240            rc.setSpacing(10);
1241            bl.add(rc);
1242
1243            var l, e;
1244            l = new qx.legacy.ui.basic.Label("Dimension:");
1245            e = new pf.ui.ComboBox;
1246            e.add(new qx.legacy.ui.form.ListItem("Frequency", null, "frequency"));
1247            e.add(new qx.legacy.ui.form.ListItem("Length", null, "length"));
1248            e.add(new qx.legacy.ui.form.ListItem("Velocity", null, "velocity"));
1249            e.add(new qx.legacy.ui.form.ListItem("Energy", null, "energy"));
1250            e.add(new qx.legacy.ui.form.ListItem("Pressure", null, "pressure"));
1251            e.add(new qx.legacy.ui.form.ListItem("Area", null, "area"));
1252            e.add(new qx.legacy.ui.form.ListItem("Power density", null, "power_density"));
1253            e.add(new qx.legacy.ui.form.ListItem("Power spectral density",
1254                null, "spectral_power_density"));
1255            e.add(new qx.legacy.ui.form.ListItem("Electric field", null, "efield"));
1256            e.add(new qx.legacy.ui.form.ListItem("None", null, "none"));
1257            e.addListener("changeSelected", function(ev) {
1258                    var dimension = this.gui_compare_dim.getSelectedValue();
1259                    this.gui_compare_units.update(dimension,
1260                        this.prefs.units[dimension]);
1261                    this.updateFavoritesListView();
1262                    this.updateLegendListView();
1263                }, this);
1264            rc.add(l, e);
1265            this.gui_compare_dim = e;
1266
1267            l = new qx.legacy.ui.basic.Label("Units:");
1268            e = new pf.UnitSelector();
1269            e.addListener("changeSelected", function(ev) {
1270                    this.updateFavoritesListView();
1271                }, this);
1272            rc.add(l, e);
1273            this.gui_compare_units = e;
1274
1275            var lc =
1276            {
1277                s_icon   : { label      : "",
1278                             width      : 24,
1279                             type       : "iconHtml",
1280                             align      : "center",                   
1281                             sortable   : false                         },
1282                name     : { label      : "Name",
1283                             width      : 300,
1284                             type       : "text",
1285                             align      : "left",
1286                             sortable   : true,
1287                             sortProp   : "text"                        },
1288                section  : { label      : "Section",
1289                             width      : 120,
1290                             type       : "text",
1291                             align      : "left",
1292                             sortable   : true,
1293                             sortProp   : "text"                        },
1294                value    : { label      : "Value",
1295                             width      : 120,
1296                             type       : "text",
1297                             align      : "right",
1298                             sortable   : true,
1299                             sortProp   : "text",
1300                             sortMethod : qx.legacy.util.Compare.byFloatString }
1301            };
1302
1303            var lv = new qx.legacy.ui.listview.ListView(new Array, lc);
1304
1305            lv.setWidth("100%");
1306            lv.setHeight("2*");
1307            lv.setBackgroundColor("white");
1308            lv.setBorder("dark-shadow");
1309
1310            bl.add(lv);
1311           
1312            this.favoritesListView = lv;
1313        },
1314       
1315        drawAll : function(ev)
1316        {
1317            var canvas = this.canvas;
1318           
1319            canvas.setPrintable(true);
1320           
1321            var pname = this.guiParameter.getValue();
1322            var vmin = this.guiMinParam.getNumValue();
1323            var vmax = this.guiMaxParam.getNumValue();
1324            var npoints = this.guiParamPoints.getValue();
1325           
1326            if (npoints < 2 || !pname) {
1327                return;
1328            }
1329
1330            var dimension = this.gui_compare_dim.getSelectedValue();
1331            var scale = this.gui_compare_units.getSelectedValue();
1332
1333            var par0;
1334            var label;
1335            switch (pname) {
1336            case "N_e":
1337                par0 = this.plasma.e.getN();
1338                label = "N<sub>e</sub> (cm<sup>-3</sup>)"
1339                break;
1340            case "T":
1341                par0 = this.plasma.e.getT();
1342                label = "T (eV)"
1343                break;
1344            case "T_e":
1345                par0 = this.plasma.e.getT();
1346                label = "T<sub>e</sub> (eV)"
1347                break;
1348            case "T_i":
1349                par0 = this.plasma.i.getT();
1350                label = "T<sub>i</sub> (eV)"
1351                break;
1352            case "T_r":
1353                par0 = this.plasma.r.getT();
1354                label = "T<sub>r</sub> (eV)"
1355                break;
1356            case "T_i,r":
1357                par0 = this.plasma.i.getT();
1358                label = "T<sub>i,r</sub> (eV)"
1359                break;
1360            case "B":
1361                par0 = this.plasma.B;
1362                label = "B (T)"
1363                break;
1364            default:
1365                return;
1366            }
1367           
1368            var xdata = new Array;
1369            for (var j = 0; j < npoints; j++) {
1370                var x = par0*(vmin + (vmax - vmin)*j/(npoints - 1));
1371                xdata.push(x);
1372            }
1373                       
1374            var wxmin = xdata[0];
1375            var wxmax = xdata[xdata.length - 1];
1376
1377            var wymin = 0;
1378            var wymax = 0;
1379
1380            var sets = new Array;
1381            var first = true;
1382            for (var i = 0; i < this.favorites.length; i++) {
1383                var fav = this.favorites[i];
1384                var entity = fav.entity;
1385               
1386                if (entity.dimension != dimension) {
1387                    continue;
1388                }
1389               
1390                var species = fav.species;
1391                var vname = this.getEntityFullName(entity, species);
1392
1393                var set   = new Array;
1394                var ydata = new Array;
1395                for (var j = 0; j < npoints; j++) {
1396                    var par = xdata[j];
1397
1398                    switch (pname) {
1399                    case "N_e":
1400                        this.plasma.e.setN(par);
1401                        this.updatePlasmaParameters();
1402                        break;
1403                    case "T_e":
1404                        this.plasma.e.setT(par);
1405                        break;
1406                    case "T_i":
1407                        this.plasma.i.setT(par);
1408                        break;
1409                    case "T_r":
1410                        this.plasma.r.setT(par);
1411                        break;
1412                    case "T_i,r":
1413                        this.plasma.i.setT(par);
1414                        this.plasma.r.setT(par);
1415                        break;
1416                    case "T":
1417                        this.plasma.e.setT(par);
1418                        this.plasma.i.setT(par);
1419                        this.plasma.r.setT(par);
1420                        break;
1421                    case "B":
1422                        this.plasma.B = par;
1423                        break;
1424                    }
1425                   
1426                    var value = scale*this.evaluateEntityValue(entity, species);
1427                   
1428                    if (first) {
1429                        wymin = value;
1430                        wymax = value;
1431                        first = false;
1432                    } else {
1433                        if (value < wymin) {
1434                            wymin = value;
1435                        }
1436                        if (value > wymax) {
1437                            wymax = value;
1438                        }
1439                    }
1440                   
1441                    ydata.push(value);
1442                }
1443                set.x = xdata;
1444                set.y = ydata;
1445                set.legend = vname;
1446                set.color = fav.color;
1447                sets.push(set);
1448            }
1449           
1450            // Restore parameter
1451            switch (pname) {
1452            case "N_e":
1453                this.plasma.e.setN(par0);
1454                this.updatePlasmaParameters();
1455                break;
1456            case "T_e":
1457                this.plasma.e.setT(par0);
1458                break;
1459            case "T_i":
1460                this.plasma.i.setT(par0);
1461                break;
1462            case "T_r":
1463                this.plasma.r.setT(par0);
1464                break;
1465            case "T_i,r":
1466                this.plasma.i.setT(par0);
1467                this.plasma.r.setT(par0);
1468                break;
1469            case "T":
1470                this.plasma.e.setT(par0);
1471                this.plasma.i.setT(par0);
1472                this.plasma.r.setT(par0);
1473                break;
1474            case "B":
1475                this.plasma.B = par0;
1476                break;
1477            }
1478           
1479            canvas.clear();
1480           
1481            canvas.setViewportCoordinates(0.15, 0.1, 0.9, 0.9);
1482            dwx = Math.abs(wxmax - wxmin);
1483            if (dwx == 0) {
1484                dwx = wxmax;
1485            }
1486            dwy = Math.abs(wymax - wymin);
1487            if (dwy == 0) {
1488                wymin = 0.0;
1489                if (wymax == 0) {
1490                    wymax = 1.0;
1491                } else {
1492                    wymax *= 2;
1493                }
1494            }
1495            var wymin_r =
1496                wymin < 0 ? (wymin - 0.05*dwy) : Math.max(0, wymin - 0.05*dwy);
1497            var wxmin_r =
1498                wxmin < 0 ? (wxmin - 0.05*dwx) : Math.max(0, wxmin - 0.05*dwx);
1499            canvas.setWorldCoordinates(wxmin_r, wymin_r,
1500                wxmax + 0.05*dwx, wymax + 0.05*dwy);
1501           
1502            // Draw frame
1503            canvas.drawFrame("black");
1504
1505            // Mark initial value of the varied parameter
1506            canvas.setColor("#c0c0c0");
1507            canvas.drawPolyLineW(new Array(par0, par0),
1508                new Array(wymin, wymax));
1509           
1510            // Draw title
1511            canvas.drawTitle(this.prefs.currentConfigName, "black");
1512           
1513            // Draw axis ticks
1514            canvas.drawTicks("x", "blue");
1515            canvas.drawTicks("y", "blue");
1516
1517            // Draw axis labels
1518            canvas.drawLabel("x", label, "black");
1519           
1520            // Draw sets
1521            for (var i = 0; i < sets.length; i++) {
1522                var set = sets[i];
1523                canvas.setColor(set.color);
1524                canvas.drawPolyLineW(set.x, set.y);
1525               
1526                delete set;
1527            }
1528           
1529            delete sets;
1530           
1531            canvas.paint();
1532        },
1533
1534        showWikiPage : function(entity)
1535        {
1536            var url;
1537            if (entity && entity.wikiLink) {
1538                url = "http://en.wikipedia.org/w/index.php?title=" +
1539                      entity.wikiLink + "&printable=yes";
1540            } else {
1541                url = null;
1542            }
1543           
1544            this.gui_wiki.setSource(url);
1545        },
1546       
1547        loadWikiCB : function(ev)
1548        {
1549            var tree = this.entity_tree;
1550            var leaf = tree.getSelectedElement();
1551           
1552            if (!leaf) {
1553                return;
1554            }
1555           
1556            var entity = leaf.getUserData("entity");
1557           
1558            this.showWikiPage(entity);
1559        },
1560       
1561        drawCB : function(ev)
1562        {
1563            this.drawAll();
1564        },
1565       
1566        renderPlotTab : function()
1567        {
1568            var page_id = this.renderTabPage("Plot",
1569                "pf/image/tab-plot.png");
1570
1571            var sp = new qx.legacy.ui.splitpane.HorizontalSplitPane("1*", 300);
1572            sp.set(
1573            {
1574                height          : "100%",
1575                width           : "100%",
1576                left            : 1,
1577                right           : 1,
1578                top             : 1,
1579                bottom          : 1,
1580                border          : "inset-thin",
1581                showKnob        : true
1582            });
1583            page_id.add(sp);
1584                       
1585            var left_pane  = sp.getLeftArea();
1586            left_pane.setBackgroundColor("white");
1587            left_pane.setBorder("inset-thin");
1588            var right_pane = sp.getRightArea();
1589            right_pane.setBackgroundColor("white");
1590            right_pane.setBorder("inset-thin");
1591
1592            var canvas = new pf.ui.canvas.Plotter();
1593            canvas.set(
1594            {
1595                height          : "100%",
1596                width           : "100%"
1597            });
1598            left_pane.add(canvas);
1599            this.canvas = canvas;
1600
1601
1602            var vbl = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
1603            vbl.set(
1604            {
1605                height          : "100%",
1606                width           : "100%",
1607                padding         : 4,
1608                spacing         : 10
1609            });
1610            right_pane.add(vbl);
1611
1612            var gl = new qx.legacy.ui.layout.GridLayout;
1613            gl.set(
1614            {
1615                height            : "auto",
1616                width             : "100%",
1617                left              : 4,
1618                right             : 4,
1619                top               : 4,
1620                verticalSpacing   : 4,
1621                verticalSpacing   : 4,
1622                horizontalSpacing : 6
1623            });
1624           
1625            gl.setColumnCount(2);
1626            gl.setColumnWidth(0, 150);
1627            gl.setColumnWidth(1, 100);
1628            gl.setRowCount(5);
1629            gl.setRowHeight(0, 30);
1630            gl.setRowHeight(1, 30);
1631            gl.setRowHeight(2, 30);
1632            gl.setRowHeight(3, 30);
1633            gl.setRowHeight(4, 30);
1634            vbl.add(gl);
1635
1636            var l, e;
1637
1638            var btn = new qx.legacy.ui.form.Button("Redraw", "pf/image/tab-plot.png");
1639            btn.addListener("execute", this.drawCB, this);
1640            gl.add(btn, 0, 0);
1641
1642            l = new qx.legacy.ui.basic.Label("Parameter to vary:");
1643            e = new pf.ui.ComboBox;
1644            e.add(new qx.legacy.ui.form.ListItem("N_e",   null, "N_e"));
1645            e.add(new qx.legacy.ui.form.ListItem("T",     null, "T"));
1646            e.add(new qx.legacy.ui.form.ListItem("T_e",   null, "T_e"));
1647            e.add(new qx.legacy.ui.form.ListItem("T_i",   null, "T_i"));
1648            e.add(new qx.legacy.ui.form.ListItem("T_r",   null, "T_r"));
1649            e.add(new qx.legacy.ui.form.ListItem("T_i,r", null, "T_i,r"));
1650            e.add(new qx.legacy.ui.form.ListItem("B",     null, "B"));
1651            e.selectByValue("N_e");
1652            this.guiParameter = e;
1653            gl.add(l, 0, 1);
1654            gl.add(e, 1, 1);
1655
1656            l = new qx.legacy.ui.basic.Label("Minimum scale:");
1657            e = new pf.ui.TextField(0.5);
1658            this.guiMinParam = e;
1659            gl.add(l, 0, 2);
1660            gl.add(e, 1, 2);
1661
1662            l = new qx.legacy.ui.basic.Label("Maximum scale:");
1663            e = new pf.ui.TextField(2.0);
1664            this.guiMaxParam = e;
1665            gl.add(l, 0, 3);
1666            gl.add(e, 1, 3);
1667
1668            l = new qx.legacy.ui.basic.Label("Number of points:");
1669            e = new pf.ui.Spinner(2, 20, 100);
1670            this.guiParamPoints = e;
1671            gl.add(l, 0, 4);
1672            gl.add(e, 1, 4);
1673
1674
1675            var lc =
1676            {
1677                s_icon   : { label      : "",
1678                             width      : 24,
1679                             type       : "iconHtml",
1680                             align      : "center",                   
1681                             sortable   : false                         },
1682                name     : { label      : "Name",
1683                             width      : 185,
1684                             type       : "text",
1685                             align      : "left",
1686                             sortable   : true,
1687                             sortProp   : "text"                        },
1688                color    : { label      : "Color",
1689                             width      : 55,
1690                             type       : "text",
1691                             align      : "left",
1692                             sortable   : false                         }
1693            };
1694
1695            var lv = new qx.legacy.ui.listview.ListView(new Array, lc);
1696
1697            lv.setWidth("100%");
1698            lv.setHeight("2*");
1699            // lv.setBackgroundColor("white");
1700            lv.setBorder("dark-shadow");
1701           
1702            lv.addListener("dblclick", function(ev) {
1703                    ev.stopPropagation();
1704                    var pane = this.getPane();
1705                    var item = pane.getSelectedItem();
1706                    if (!item) {
1707                        return;
1708                    }
1709                    var favorite = item.favorite;
1710                    if (!favorite) {
1711                        return;
1712                    }
1713                    mypop.setUserData("favorite", null); // avoid loop call
1714                    mypop.setValue(favorite.color);
1715                    mypop.setUserData("favorite", favorite);
1716                    var el = this.getElement();
1717                    mypop.setTop(qx.legacy.html.Location.getPageBoxTop(el));
1718                    mypop.setLeft(qx.legacy.html.Location.getPageBoxLeft(el) -
1719                        this.getWidthValue());
1720                    mypop.show();
1721                });
1722
1723            vbl.add(lv);
1724            this.legendListView = lv;
1725           
1726            var mytables =
1727            {
1728              core : {
1729                label : "Basic Colors",
1730                values : this.colorMap
1731              },
1732
1733              recent : {
1734                label : "Recent Colors",
1735                values : [ ]
1736              }
1737            }
1738
1739            var mypop = new qx.legacy.ui.component.ColorPopup(mytables);
1740            // A hack
1741            mypop._layout.remove(mypop._automaticBtn);
1742
1743            mypop.addToDocument();
1744
1745            mypop.addListener("changeValue", function(ev) {
1746                var color = ev.getValue();
1747                var mypop = ev.getTarget();
1748                var favorite = mypop.getUserData("favorite");
1749                if (!favorite || !color) {
1750                    return;
1751                }
1752                favorite.color = color;
1753                this.updateLegendListView();
1754                this.drawAll();
1755            }, this);
1756   
1757        },
1758
1759
1760        aboutCB : function(ev)
1761        {
1762            this.aboutWindow.open();
1763        },
1764       
1765        prefsCB : function(ev)
1766        {
1767            this.prefsWindow.open();
1768        },
1769       
1770        updateSaveLoadList : function()
1771        {
1772            var lv = this.saveLoadConfigList;
1773            var configPtrs = this.prefs.configPtrs;
1774           
1775            var rowData = lv.getData();
1776            rowData.length = 0;
1777            lv.getPane().getManager().deselectAll();
1778
1779            var i;
1780            var d = new Date();
1781            var df = new qx.util.format.DateFormat("yyyy-MM-dd HH:mm:ss");
1782           
1783            for (i = 0; i < configPtrs.length; i++) {
1784                var configPtr = configPtrs[i];
1785
1786                d.setTime(configPtr.time);
1787
1788                rowData.push({ name : {text       : configPtr.name },
1789                               date : {text       : df.format(d)   }
1790                             });
1791            }
1792           
1793            lv.updateSort();
1794            lv.update();
1795        },
1796       
1797        saveAsCB : function(ev)
1798        {
1799            var w = this.saveLoadWindow;
1800           
1801            this.updateSaveLoadList();
1802            this.saveLoadTextField.setValue(null);
1803            this.saveLoadTextField.setReadOnly(false);
1804           
1805            w.setCaption("Save configuration")
1806            w.setIcon("pf/image/save.png");
1807            w.setUserData("type", "save");
1808           
1809            w.open();
1810        },
1811       
1812        saveConfigCB : function(ev)
1813        {
1814            if (this.prefs.currentConfigName &&
1815                this.prefs.currentConfigName != "Untitled") {
1816                if (this.saveConfig(this.prefs.currentConfigName) != true) {
1817                    alert("Save failed!");
1818                }
1819            } else {
1820                this.saveAsCB(ev);
1821            }
1822        },
1823       
1824        openCB : function(ev)
1825        {
1826            var w = this.saveLoadWindow;
1827           
1828            this.updateSaveLoadList();
1829            this.saveLoadTextField.setValue(null);
1830            this.saveLoadTextField.setReadOnly(true);
1831           
1832            w.setCaption("Open configuration")
1833            w.setIcon("pf/image/open.png");
1834            w.setUserData("type", "open");
1835           
1836            w.open();
1837        },
1838       
1839        buildMenu : function()
1840        {
1841            var menubar = this.menubar;
1842           
1843            var submenu, btn, q;
1844
1845            var theme = qx.legacy.theme.manager.Color.getInstance().getColorTheme();
1846            var bg = '#' +
1847                qx.util.ColorUtil.rgbToHexString(theme.colors['button']);
1848           
1849            submenu = new qx.legacy.ui.menu.Menu;
1850            submenu.setBackgroundColor(bg);
1851            this.doc.add(submenu);
1852            q = new qx.event.Command("Ctrl+O");
1853            q.addListener("execute", this.openCB, this);
1854            btn = new qx.legacy.ui.menu.Button("Open...", "pf/image/open.png", q);
1855            submenu.add(btn);
1856            q = new qx.event.Command("Ctrl+S");
1857            q.addListener("execute", this.saveConfigCB, this);
1858            btn = new qx.legacy.ui.menu.Button("Save", "pf/image/save.png", q);
1859            submenu.add(btn);
1860            btn = new qx.legacy.ui.menu.Button("Save as...", "pf/image/save.png");
1861            btn.addListener("execute", this.saveAsCB, this);
1862            submenu.add(btn);
1863            submenu.add(new qx.legacy.ui.menu.Separator);
1864            q = new qx.event.Command("Ctrl+P");
1865            q.addListener("execute", function(ev) {
1866                window.print();
1867            });
1868            btn = new qx.legacy.ui.menu.Button("Print...", "pf/image/print.png", q);
1869            submenu.add(btn);
1870            submenu.add(new qx.legacy.ui.menu.Separator);
1871            q = new qx.event.Command("Ctrl+R");
1872            q.addListener("execute", function(ev) {
1873                    if (!this.prefs.warnOnExit ||
1874                        confirm("Restart Plasma Formulary?")) {
1875                        this.intendedExit = true;
1876                        location.reload(true);
1877                    }
1878                }, this);
1879            btn = new qx.legacy.ui.menu.Button("Restart", "pf/image/reset.png", q);
1880            submenu.add(btn);
1881            submenu.add(new qx.legacy.ui.menu.Separator);
1882            q = new qx.event.Command("Ctrl+Q");
1883            q.addListener("execute", function(ev) {
1884                    if (!this.prefs.warnOnExit ||
1885                        confirm("Quit Plasma Formulary?")) {
1886                        this.intendedExit = true;
1887                        window.close();
1888                    }
1889                }, this);
1890            btn = new qx.legacy.ui.menu.Button("Quit", "pf/image/exit.png", q);
1891            submenu.add(btn);
1892               
1893            btn = new qx.legacy.ui.menubar.Button("File", submenu);
1894            btn.set({ paddingLeft : 7, paddingRight : 7 });
1895            menubar.add(btn);
1896
1897
1898            submenu = new qx.legacy.ui.menu.Menu;
1899            submenu.setBackgroundColor(bg);
1900            submenu.addListener("beforeAppear", editMenuCB, this);
1901            this.doc.add(submenu);
1902            btn = new qx.legacy.ui.menu.Button("Add to Favorites",
1903                "pf/image/favorite-add.png");
1904            btn.addListener("execute", addToFavCB, this);
1905            this.editMenuButtonAddToFav = btn;
1906            submenu.add(btn);
1907            btn = new qx.legacy.ui.menu.Button("Remove from Favorites",
1908                "pf/image/favorite-delete.png");
1909            btn.addListener("execute", removeFromFavCB, this);
1910            this.editMenuButtonRemFromFav = btn;
1911            submenu.add(btn);
1912            submenu.add(new qx.legacy.ui.menu.Separator);
1913            btn = new qx.legacy.ui.menu.Button("Preferences",
1914                "pf/image/preferences.png");
1915            btn.addListener("execute", this.prefsCB, this);
1916            submenu.add(btn);
1917
1918            btn = new qx.legacy.ui.menubar.Button("Edit", submenu);
1919            btn.set({ paddingLeft : 7, paddingRight : 7 });
1920            menubar.add(btn);
1921
1922
1923            submenu = new qx.legacy.ui.menu.Menu;
1924            submenu.setBackgroundColor(bg);
1925            submenu.addListener("beforeAppear", viewMenuCB, this);
1926
1927            var subMenu1 = new qx.legacy.ui.menu.Menu;
1928            subMenu1.setBackgroundColor(bg);
1929            button = new qx.legacy.ui.menu.CheckBox("Fundamental",
1930                null, this.showFundamental);
1931            button.addListener("execute", showFundamentalCB, this);
1932            subMenu1.add(button);
1933            button = new qx.legacy.ui.menu.CheckBox("Spectroscopy",
1934                null, this.showSpectroscopy);
1935            button.addListener("execute", showSpectroscopyCB, this);
1936            subMenu1.add(button);
1937            button = new qx.legacy.ui.menu.CheckBox("Waves",
1938                null, this.showWaves);
1939            button.addListener("execute", showWavesCB, this);
1940            subMenu1.add(button);
1941            button = new qx.legacy.ui.menu.CheckBox("Collisions",
1942                null, this.showCollisions);
1943            button.addListener("execute", showCollisionsCB, this);
1944            subMenu1.add(button);
1945            this.showSectionsButton = new qx.legacy.ui.menu.Button("Show Sections",
1946                null, null, subMenu1);
1947            submenu.add(this.showSectionsButton);
1948           
1949            submenu.add(new qx.legacy.ui.menu.Separator);
1950
1951            var subMenu2 = new qx.legacy.ui.menu.Menu;
1952            subMenu2.setBackgroundColor(bg);
1953            button = new qx.legacy.ui.menu.CheckBox("Electrons",
1954                null, this.showElectrons);
1955            button.addListener("execute", showElectronsCB, this);
1956            subMenu2.add(button);
1957            button = new qx.legacy.ui.menu.CheckBox("Ions",
1958                null, this.showIons);
1959            button.addListener("execute", showIonsCB, this);
1960            subMenu2.add(button);
1961            button = new qx.legacy.ui.menu.CheckBox("Radiators",
1962                null, this.showRadiators);
1963            button.addListener("execute", showRadiatorsCB, this);
1964            subMenu2.add(button);
1965            this.showSpeciesButton = new qx.legacy.ui.menu.Button("Show Species",
1966                null, null, subMenu2);
1967            submenu.add(this.showSpeciesButton);
1968           
1969            submenu.add(new qx.legacy.ui.menu.Separator);
1970            q = new qx.event.Command("Ctrl+W");
1971            q.addListener("execute", this.loadWikiCB, this);
1972            btn = new qx.legacy.ui.menu.Button("Load Wikipedia Article",
1973                "pf/image/wikipedia.png", q);
1974            submenu.add(btn);
1975            this.loadWikiButton = btn;
1976            this.doc.add(submenu, subMenu1, subMenu2);
1977
1978            submenu.add(new qx.legacy.ui.menu.Separator);
1979            q = new qx.event.Command("Ctrl+L");
1980            q.addListener("execute", this.drawCB, this);
1981            btn = new qx.legacy.ui.menu.Button("Redraw Plot",
1982                "pf/image/tab-plot.png", q);
1983            submenu.add(btn);
1984            this.redrawButton = btn;
1985           
1986            btn = new qx.legacy.ui.menubar.Button("View", submenu);
1987            btn.set({ paddingLeft : 7, paddingRight : 7 });
1988            menubar.add(btn);
1989
1990
1991            submenu = new qx.legacy.ui.menu.Menu;
1992            submenu.setBackgroundColor(bg);
1993            this.doc.add(submenu);
1994            q = new qx.event.Command("F1");
1995            q.addListener("execute", function(ev) {
1996                alert("Help system not implemented yet");
1997            });
1998            btn = new qx.legacy.ui.menu.Button("Help Contents",
1999                "pf/image/help.png", q);
2000            submenu.add(btn);
2001            btn = new qx.legacy.ui.menu.Button("NRL Plasma Formulary",
2002                "pf/image/nrl.png");
2003            btn.addListener("execute", function (ev) {
2004                    var w = new qx.legacy.util.NativeWindow("http://wwwppd.nrl.navy.mil/nrlformulary/");
2005                    w.setDimension(800, 600);
2006                    w.open();
2007                }, this);
2008            submenu.add(btn);
2009            btn = new qx.legacy.ui.menu.Button("Plasma at Wikipedia",
2010                "pf/image/wikipedia.png");
2011            btn.addListener("execute", function (ev) {
2012                    var w = new qx.legacy.util.NativeWindow("http://en.wikipedia.org/wiki/Plasma_%28physics%29");
2013                    w.setDimension(800, 600);
2014                    w.open();
2015                }, this);
2016            submenu.add(btn);
2017            submenu.add(new qx.legacy.ui.menu.Separator);
2018            btn = new qx.legacy.ui.menu.Button("License Terms",
2019                "pf/image/gnu.png");
2020            btn.addListener("execute", function (ev) {
2021                    var w = new qx.legacy.util.NativeWindow("resource/pf/html/GPL.html");
2022                    w.setDimension(800, 600);
2023                    w.open();
2024                }, this);
2025            submenu.add(btn);
2026            btn = new qx.legacy.ui.menu.Button("About...",
2027                "pf/image/about.png");
2028            btn.addListener("execute", this.aboutCB, this);
2029            submenu.add(btn);
2030
2031            btn = new qx.legacy.ui.menubar.Button("Help", submenu);
2032            btn.set({ paddingLeft : 7, paddingRight : 7 });
2033            menubar.add(btn);
2034        },
2035       
2036        nextColor : function()
2037        {
2038            var color = this.colorMap[this.ncolor];
2039            this.ncolor++;
2040            if (this.ncolor == this.colorMap.length) {
2041                this.ncolor = 0;
2042            }
2043           
2044            return color;
2045        },
2046
2047        getWindowDimensions : function()
2048        {
2049            var dims = new Object;
2050           
2051            dims.w = qx.legacy.html.Window.getInnerWidth(this.win);
2052            dims.h = qx.legacy.html.Window.getInnerHeight(this.win);
2053           
2054            return dims;
2055        },
2056
2057        savePreferences : function()
2058        {
2059            if (this.prefs) {
2060                var prefstr = qx.util.Json.stringify(this.prefs);
2061                qx.bom.Cookie.set("pf_prefs", prefstr, 3650);
2062            }
2063        },
2064       
2065        loadPreferences : function()
2066        {
2067            var prefstr = qx.bom.Cookie.get("pf_prefs");
2068           
2069            if (prefstr) {
2070                this.prefs = qx.util.Json.parseQx(prefstr);
2071            }
2072           
2073            if (!this.prefs) {
2074                this.prefs = new Object;
2075            }
2076 
2077            if (undefined === this.prefs.rememberWindowSize) {
2078                this.prefs.rememberWindowSize = false;
2079            }
2080
2081            if (undefined === this.prefs.autoLoadWiki) {
2082                this.prefs.autoLoadWiki = true;
2083            }
2084           
2085            if (undefined === this.prefs.warnOnExit) {
2086                this.prefs.warnOnExit = true;
2087            }
2088           
2089            if (!this.prefs.units) {
2090                this.prefs.units = new Object;
2091            }
2092           
2093            if (!this.prefs.currentConfigName) {
2094                this.prefs.currentConfigName = "Untitled";
2095            }
2096           
2097            if (!this.prefs.configPtrs) {
2098                this.prefs.configPtrs = new Array;
2099            }
2100        },
2101       
2102        getConfig : function(name)
2103        {
2104            if (!name) {
2105                return null;
2106            }
2107
2108            var configPtrs = this.prefs.configPtrs;
2109           
2110            var i, configPtr = null;
2111            for (i = 0; i < configPtrs.length; i++) {
2112                if (configPtrs[i].name == name) {
2113                    configPtr = configPtrs[i];
2114                    return configPtr;
2115                    break;
2116                }
2117            }
2118           
2119            return null;
2120        },
2121       
2122        saveConfig : function(name)
2123        {
2124            if (!name) {
2125                return false;
2126            }
2127
2128            var configPtr = this.getConfig(name);
2129           
2130            var d = new Date();
2131            var time = d.getTime();
2132           
2133            if (!configPtr) {
2134                configPtr = new Object;
2135                configPtr.name = name;
2136                configPtr.hash = time;
2137                this.prefs.configPtrs.push(configPtr);
2138            }
2139           
2140            configPtr.time = time;
2141           
2142            var cookie_name = "pf_config_" + configPtr.hash;
2143           
2144            var config = new Object;
2145           
2146            config.N_e = this.plasma.e.getN();
2147
2148            config.T_e = this.plasma.e.getT();
2149            config.T_i = this.plasma.i.getT();
2150            config.T_r = this.plasma.r.getT();
2151
2152            config.M_i = this.plasma.i.getM();
2153            config.M_r = this.plasma.r.getM();
2154           
2155            config.Q_i = this.plasma.i.getQ();
2156            config.Q_r = this.plasma.r.getQ();
2157
2158            config.P_r = this.plasma.P_r;
2159
2160            config.B   = this.plasma.B  ;
2161
2162            config.n_u = this.plasma.n_u;
2163            config.n_l = this.plasma.n_l;
2164           
2165            var configstr = qx.util.Json.stringify(config);
2166            qx.bom.Cookie.set(cookie_name, configstr, 3650);
2167           
2168            this.prefs.currentConfigName = name;
2169           
2170            return true;
2171        },
2172       
2173        loadConfig : function(name)
2174        {
2175            var configPtr = this.getConfig(name);
2176            if (!configPtr) {
2177                return false;
2178            }
2179
2180            var cookie_name = "pf_config_" + configPtr.hash;
2181
2182            var configstr = qx.bom.Cookie.get(cookie_name);
2183            if (!configstr) {
2184                // Cookie was deleted???
2185                qx.lang.Array.remove(this.prefs.configPtrs, configPtr);
2186                return false;
2187            }
2188
2189            var config = qx.util.Json.parseQx(configstr);
2190           
2191            if (config) {
2192                this.plasma.e.setN(config.N_e);
2193
2194                this.plasma.e.setT(config.T_e);
2195                this.plasma.i.setT(config.T_i);
2196                this.plasma.r.setT(config.T_r);
2197
2198                this.plasma.i.setM(config.M_i);
2199                this.plasma.r.setM(config.M_r);
2200
2201                this.plasma.i.setQ(config.Q_i);
2202                this.plasma.r.setQ(config.Q_r);
2203
2204                this.plasma.P_r = config.P_r;
2205
2206                this.plasma.B   = config.B  ;
2207
2208                this.plasma.n_u = config.n_u;
2209                this.plasma.n_l = config.n_l;
2210
2211                this.prefs.currentConfigName = name;
2212
2213                return true;
2214            } else {
2215                return false;
2216            }
2217        },
2218       
2219        removeConfig : function(name)
2220        {
2221            var configPtr = this.getConfig(name);
2222            if (configPtr) {
2223                qx.lang.Array.remove(this.prefs.configPtrs, configPtr);
2224                var cookie_name = "pf_config_" + configPtr.hash;
2225                qx.bom.Cookie.del(cookie_name);
2226            }
2227        },
2228       
2229        renameConfig : function(oldname, newname)
2230        {
2231            var configPtr = this.getConfig(oldname);
2232            if (configPtr) {
2233                configPtr.name = newname;
2234            }
2235        },
2236       
2237        createSaveLoadDialog : function()
2238        {
2239            var w, rc, rc1, e, btn;
2240            // "Save as..." dialog
2241            w = new qx.legacy.ui.window.Window();
2242            w.setSpace(200, "auto", 100, 300);
2243            w.setModal(true);
2244            w.setShowMinimize(false);
2245            w.setShowMaximize(false);
2246
2247            w.addListener("keypress", function(ev) {
2248                    if (ev.getKeyIdentifier() == "Escape") {
2249                        w.close()
2250                    }
2251                });
2252
2253            rc = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
2254            rc.set({width : "100%", height : "100%", spacing : 4});
2255            w.add(rc);
2256           
2257            var tb = new qx.legacy.ui.toolbar.ToolBar();
2258            var btn_delete = new qx.legacy.ui.toolbar.Button("Delete",
2259                "pf/image/delete.png");
2260            var btn_rename = new qx.legacy.ui.toolbar.Button("Rename",
2261                "pf/image/rename.png");
2262            btn_delete.setEnabled(false);
2263            btn_rename.setEnabled(false);
2264            var sep = new qx.legacy.ui.toolbar.Separator();
2265            tb.add(sep, btn_delete, btn_rename);
2266            rc.add(tb);
2267           
2268            var lc =
2269            {
2270                name     : { label      : "Configuration",
2271                             width      : 250,
2272                             type       : "text",
2273                             align      : "left",
2274                             sortable   : true,
2275                             sortProp   : "text"  },
2276                date     : { label      : "Last Modified",
2277                             width      : 180,
2278                             type       : "text",
2279                             align      : "right",
2280                             sortable   : true   }
2281            };
2282
2283            var lv = new qx.legacy.ui.listview.ListView(new Array, lc);
2284
2285            lv.setWidth("100%");
2286            lv.setBorder("dark-shadow");
2287            lv.setHeight("2*");
2288
2289            this.saveLoadConfigList = lv;
2290            rc.add(lv);
2291
2292            btn_delete.addListener("execute", function(ev) {
2293                    var pane = lv.getPane();
2294                    var item = pane.getSelectedItem();
2295                    if (item && confirm("Delete \"" + item.name.text + "\"?")) {
2296                        this.removeConfig(item.name.text);
2297                        this.updateSaveLoadList();
2298                    }
2299                }, this);
2300
2301            btn_rename.addListener("execute", function(ev) {
2302                    var pane = lv.getPane();
2303                    var item = pane.getSelectedItem();
2304                    if (item) {
2305                        var name = item.name.text;
2306                        var newname = prompt("Rename \"" + name + "\" to", name);
2307                        if (newname && newname != name) {
2308                            this.renameConfig(name, newname);
2309                            this.updateSaveLoadList();
2310                            if (name == this.prefs.currentConfigName) {
2311                                this.prefs.currentConfigName = newname;
2312                                this.gui_configName.setLabel(newname);
2313                            }
2314                        }
2315                    }
2316                }, this);
2317
2318            e = new pf.ui.TextField();
2319            e.setWidth("100%");
2320            rc.add(e);
2321           
2322            this.saveLoadTextField = e;
2323
2324            var sm = lv.getPane().getManager();
2325            sm.setMultiSelection(false);
2326            sm.addListener("changeSelection", function(ev) {
2327                    var item = this.getSelectedItem();
2328                    if (!item) {
2329                        e.setValue(null);
2330                        btn_delete.setEnabled(false);
2331                        btn_rename.setEnabled(false);
2332                    } else {
2333                        e.setValue(item.name.text);
2334                        btn_rename.setEnabled(true);
2335                        btn_delete.setEnabled(true);
2336                    }
2337                });
2338           
2339
2340            rc1 = new qx.legacy.ui.layout.HorizontalBoxLayout("horizontal");
2341            rc1.set({width                   : "100%",
2342                     height                  : "auto",
2343                     horizontalChildrenAlign : "right",
2344                     verticalChildrenAlign   : "bottom"});
2345            rc.add(rc1);
2346
2347            btn = new qx.legacy.ui.form.Button("Cancel",
2348                "pf/image/cancel.png");
2349            btn.addListener("execute", function(ev) {
2350                    this.saveLoadWindow.close();
2351                }, this);
2352            rc1.add(btn);
2353
2354            btn = new qx.legacy.ui.form.Button("OK",
2355                "pf/image/ok.png");
2356            btn.addListener("execute", function(ev) {
2357                    var cfgname = this.saveLoadTextField.getValue(); 
2358                    if (!cfgname) {
2359                        alert("Please enter a name!");
2360                    } else {
2361                        var type = w.getUserData("type");
2362                        if (type == "save") {
2363                            if (this.saveConfig(cfgname) == true) {
2364                                this.saveLoadWindow.close();
2365                                if (this.prefs.currentConfigName) {
2366                                    this.gui_configName.setLabel(this.prefs.currentConfigName);
2367                                }
2368                            } else {
2369                                alert("Save failed!");
2370                            }
2371                        } else {
2372                            if (this.loadConfig(cfgname) == true) {
2373                                this.updatePlasmaParameters();
2374                                this.updateGUI();
2375                                this.saveLoadWindow.close();
2376                            } else {
2377                                alert("Load failed!");
2378                            }
2379                        }
2380                    }
2381                }, this);
2382            rc1.add(btn);
2383
2384            e.setLiveUpdate(true);
2385            e.addListener("changeValue", function(ev) {
2386                    var name = this.getValue();
2387                    btn.setEnabled(null != name && name.length != 0);
2388                });
2389               
2390            this.doc.add(w);
2391            this.saveLoadWindow = w;
2392        },
2393
2394        createPrefsDialog : function()
2395        {
2396            var w;
2397            // "Preferences..." dialog
2398            w = new qx.legacy.ui.window.Window("Preferences",
2399                "pf/image/preferences.png");
2400            w.setSpace(200, "auto", 100, "auto");
2401            w.setModal(true);
2402            w.setShowMinimize(false);
2403            w.setShowMaximize(false);
2404
2405            var vbl = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
2406            vbl.setStretchChildrenOrthogonalAxis(false);
2407            w.add(vbl);
2408           
2409            var fr1, fr2, rc, l, e;
2410           
2411            fr1 = new qx.legacy.ui.groupbox.GroupBox("Default units");
2412            fr1.setDimension("auto", "auto");
2413            vbl.add(fr1);
2414           
2415            rc = new qx.legacy.ui.layout.HorizontalBoxLayout;
2416            rc.setWidth("100%");
2417            rc.setHeight("auto");
2418            rc.setSpacing(10);
2419            fr1.add(rc);
2420
2421            l = new qx.legacy.ui.basic.Label("Dimension:");
2422            e = new pf.ui.ComboBox;
2423            e.add(new qx.legacy.ui.form.ListItem("Frequency", null, "frequency"));
2424            e.add(new qx.legacy.ui.form.ListItem("Length", null, "length"));
2425            e.add(new qx.legacy.ui.form.ListItem("Velocity", null, "velocity"));
2426            e.add(new qx.legacy.ui.form.ListItem("Energy", null, "energy"));
2427            e.add(new qx.legacy.ui.form.ListItem("Pressure", null, "pressure"));
2428            e.add(new qx.legacy.ui.form.ListItem("Area", null, "area"));
2429            e.add(new qx.legacy.ui.form.ListItem("Power density", null, "power_density"));
2430            e.add(new qx.legacy.ui.form.ListItem("Power spectral density",
2431                null, "spectral_power_density"));
2432            e.add(new qx.legacy.ui.form.ListItem("Electric field", null, "efield"));
2433            e.addListener("changeSelected", function(ev) {
2434                    var dimension = ev.getTarget().getSelectedValue();
2435                    this.gui_prefs_units.update(dimension,
2436                        this.prefs.units[dimension]);
2437                }, this);
2438            rc.add(l, e);
2439            this.gui_prefs_dim = e;
2440
2441            l = new qx.legacy.ui.basic.Label("Units:");
2442            e = new pf.UnitSelector();
2443            e.addListener("changeSelected", function(ev) {
2444                    var dimension = this.gui_prefs_dim.getSelectedValue();
2445                    var units = ev.getTarget().getValue();
2446                    this.prefs.units[dimension] = units;
2447                }, this);
2448            rc.add(l, e);
2449            this.gui_prefs_units = e;
2450
2451            fr2 = new qx.legacy.ui.groupbox.GroupBox("Interface");
2452            fr2.setDimension("auto", "auto");
2453            vbl.add(fr2);
2454            // A hack...
2455            fr1.addListener("appear", function(ev) {
2456                    fr2.setWidth(this.getWidthValue());
2457                });
2458
2459            rc = new qx.legacy.ui.layout.VerticalBoxLayout;
2460            rc.setWidth("100%");
2461            rc.setHeight("auto");
2462            rc.setSpacing(10);
2463            fr2.add(rc);
2464
2465            e = new qx.legacy.ui.form.CheckBox("Load Wikipedia articles automatically");
2466            e.setChecked(this.prefs.autoLoadWiki);
2467            e.addListener("changeChecked", function(ev) {
2468                this.prefs.autoLoadWiki = ev.getTarget().getChecked();
2469            }, this);
2470            rc.add(e);
2471
2472            e = new qx.legacy.ui.form.CheckBox("Remember window dimensions on exit");
2473            e.setChecked(this.prefs.rememberWindowSize);
2474            e.addListener("changeChecked", function(ev) {
2475                this.prefs.rememberWindowSize = ev.getTarget().getChecked();
2476            }, this);
2477            rc.add(e);
2478
2479            e = new qx.legacy.ui.form.CheckBox("Warn on exit or restart");
2480            e.setChecked(this.prefs.warnOnExit);
2481            e.addListener("changeChecked", function(ev) {
2482                this.prefs.warnOnExit = ev.getTarget().getChecked();
2483            }, this);
2484            rc.add(e);
2485
2486            this.doc.add(w);
2487            this.prefsWindow = w;
2488        },
2489
2490        /**
2491         * TODOC
2492         *
2493         * @type member
2494         * @param e {Event} TODOC
2495         * @return {void}
2496         */
2497        main : function(e)
2498        {
2499            this.base(arguments);
2500            this.compat();
2501
2502            // Enable logging in debug variant
2503            if (qx.core.Variant.isSet("qx.debug", "on"))
2504            {
2505                // support native logging capabilities, e.g. Firebug
2506                qx.log.appender.Native;
2507                // support additional cross-browser console. (Press F7)
2508                qx.log.appender.Console;
2509            }
2510           
2511            this.doc = qx.legacy.ui.core.ClientDocument.getInstance();
2512            this.win = this.doc.getWindowElement();
2513           
2514            // Load prefs
2515            this.loadPreferences();
2516           
2517            this.plasma = new pf.Plasma();
2518           
2519            // Load config from the previous session
2520            if (this.prefs.currentConfigName) {
2521                this.loadConfig(this.prefs.currentConfigName);
2522            }
2523           
2524            if (this.updatePlasmaParameters() != true) {
2525                this.error("Error updating plasma parameters!");
2526            }
2527           
2528            // Favorites
2529            this.favorites = new Array;
2530           
2531            this.colorMap = new Array("red", "blue", "green", "orange",
2532                "brown", "olive", "teal", "magenta", "grey", "black");
2533            this.ncolor = 0;
2534
2535            // Top-level container
2536            this.bl_top = new qx.legacy.ui.layout.VerticalBoxLayout("vertical");
2537            this.bl_top.setWidth("100%");
2538            this.bl_top.setHeight("100%");
2539
2540            this.bl_top.addToDocument();
2541
2542            // The menubar
2543            this.menubar = new qx.legacy.ui.menubar.MenuBar;
2544            this.bl_top.add(this.menubar);
2545           
2546            // The menu items
2547            this.buildMenu();
2548           
2549            var tf1 = new qx.legacy.ui.pageview.tabview.TabView;
2550            tf1.set({ width : '100%', height : '2*' });
2551
2552            this.bl_top.add(tf1);
2553
2554            this.tabbar  = tf1.getBar();
2555            this.tabpane = tf1.getPane();
2556            this.tabpane.setHeight('3*');
2557            this.tabpane.setPadding(0, 0, 0, 0);
2558
2559            // The "Parameters" tab
2560            this.renderParametersTab();
2561           
2562            // The "Explorer" tab
2563            this.renderExplorerTab();
2564           
2565            // The "Compare" tab
2566            this.renderCompareTab();
2567           
2568            // The "Plot" tab
2569            this.renderPlotTab();
2570           
2571            // "Preferences" dialog
2572            this.createPrefsDialog();
2573
2574            // "Save as" dialog
2575            this.createSaveLoadDialog();
2576
2577            // "About..." dialog
2578            w = new qx.legacy.ui.window.Window("About Plasma Formulary",
2579                "pf/image/about.png");
2580            w.setSpace(200, "auto", 100, "auto");
2581            w.setModal(true);
2582            w.setShowMinimize(false);
2583            w.setShowMaximize(false);
2584           
2585            var version = qx.core.Version;
2586            if (!version) {
2587                version = '0.8.3';
2588            }
2589            str = 'Plasma Formulary Interactive.<br/>'    +
2590                  '$Revision$.'                    +
2591                  '<p>Written by Evgeny Stambulchik.</p>' +
2592                  '<p>GUI built with the Qooxdoo-'        + 
2593                  version + ' toolkit.<br/>'              + 
2594                  'Using Walter Zorn jsGraphics for drawing.</p>';
2595
2596            var a = new qx.legacy.ui.basic.Atom(str);
2597            a.set({ top: 4, left: 4 });
2598            w.add(a);
2599
2600            this.doc.add(w);
2601            this.aboutWindow = w;
2602           
2603            if (this.prefs.rememberWindowSize && this.prefs.dims) {
2604                self.resizeTo(this.prefs.dims.w,this.prefs.dims.h)
2605            }
2606
2607            // Handle resize events
2608            this.doc.addListener("windowresize", function(e) {
2609                if (this.prefs.rememberWindowSize) {
2610                    this.prefs.dims = this.getWindowDimensions();
2611                }
2612                this.drawAll();
2613            }, this);
2614        },
2615   
2616
2617        /**
2618         * TODOC
2619         *
2620         * @type member
2621         * @param e {Event} TODOC
2622         * @return {void}
2623         */
2624        close : function(e)
2625        {
2626            // Save preferences
2627            this.savePreferences();
2628
2629            this.base(arguments);
2630            this.compat();
2631           
2632            // Prompt user
2633            if (this.prefs.warnOnExit && !this.intendedExit) {
2634                return "This will end your Plasma Formulary session.";
2635            }
2636        }
2637    }
2638});
Note: See TracBrowser for help on using the repository browser.