source: source/class/pf/Application.js @ 106:f3e4c488c583

Last change on this file since 106:f3e4c488c583 was 106:f3e4c488c583, checked in by fnevgeny, 16 years ago

Made cookies persistent for 10 years ;-)

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