summaryrefslogtreecommitdiffstats
path: root/qooxdoo/source/class/Smokeping/ui/Graph.js
blob: 8a55a4f2ea039e5275fe8f2ae73bc8acdcfcaad1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* ************************************************************************
#module(Smokeping)
************************************************************************ */

/**
 * a widget showing the smokeping graph overview
 */

var  Smokeping_ui_Graph_default_width = null;
var  Smokeping_ui_Graph_default_height = null;

qx.Class.define('Smokeping.ui.Graph', 
{
    extend: qx.ui.layout.BoxLayout,        

    /*
    *****************************************************************************
       CONSTRUCTOR
    *****************************************************************************
    */

    /**
     * @param base_url   {String}   Path to the location of the image generator
     *
     */

    construct: function (src,width,height) {
		this.base(arguments);
		this._src=src;
		this._width=width;
		this._height=height;
		if ( Smokeping_ui_Graph_default_width){
			this.setWidth( Smokeping_ui_Graph_default_width)
 			this.setHeight( Smokeping_ui_Graph_default_height);
		} 
		else {
            this.setWidth('auto');
			this.setHeight('auto');
		};
		this.set({
			border : new qx.ui.core.Border(1,'dotted','#ffffff'),
		    horizontalChildrenAlign: 'center',
	        verticalChildrenAlign: 'middle'
		});
		this._highlight();
		var loader = new Smokeping.ui.LoadingAnimation();
    	this.add(loader);
		this._preloader = qx.io.image.PreloaderManager.getInstance().create(this._src+';w='+this._width+';h='+this._height);
		if (this._preloader.isLoaded()){
			qx.client.Timer.once(this._image_loader,this,0);
		} else {
			this._preloader.addEventListener('load', this._image_loader, this);
		}
		this.addEventListener('mouseover',this._highlight,this);
		this.addEventListener('mouseout',this._unhighlight,this);
	},

	members: {
		_image_loader: function(e) {					
			 Smokeping_ui_Graph_default_width = this._preloader.getWidth();
			 Smokeping_ui_Graph_default_height = this._preloader.getHeight();
			var image = new qx.ui.basic.Image();
			image.setPreloader(this._preloader);
            qx.io.image.PreloaderManager.getInstance().remove(this._preloader);
			with(this){
				removeAll();
				add(image);
				addEventListener('click',this._open_navigator,this);
				_unhighlight();
			}
		},
		_open_navigator: function(e){
			with(this){
				setEnabled(false);
				_unhighlight();
				this._window = new Smokeping.ui.Navigator(this._src,this._width,this._height);
				_window.addToDocument();
				_window.positionRelativeTo(getElement(),2,-4);
				addEventListener('beforeDisappear',_kill_window,this);
				_window.open();
				_window.addEventListener('beforeDisappear',_close_window,this);
			}
		},
		_close_window: function(e){
			this.setEnabled(true);
		},
		_kill_window: function(e){
			this._window.close();
			this._window.dispose();
		},
		_highlight: function(e){	
			this.setBackgroundColor('#f8f8f8');
			this.getBorder().set({
				color: '#808080'
			});
		},
		_unhighlight: function(e){
			this.setBackgroundColor('transparent');
			this.getBorder().set({
				color: '#ffffff'
			});
		}
	}
	

});