From d8b465e26599268b8eded0732e8f29062556997e Mon Sep 17 00:00:00 2001 From: Tobi Oetiker Date: Thu, 6 Nov 2008 14:40:55 +0000 Subject: initial commit --- qx08/source/class/tr/Application.js | 140 +++++++------- qx08/source/class/tr/Server.js | 98 +++++----- qx08/source/class/tr/Theme.js | 11 ++ qx08/source/class/tr/test/DemoTest.js | 67 +++---- qx08/source/class/tr/ui/ActionButton.js | 271 +++++++++++++++------------ qx08/source/class/tr/ui/Cellrenderer.js | 43 +++-- qx08/source/class/tr/ui/Config.js | 196 +++++++++++++++++++ qx08/source/class/tr/ui/Footer.js | 45 ++--- qx08/source/class/tr/ui/Link.js | 54 ++++++ qx08/source/class/tr/ui/TraceTable.js | 321 ++++++++++++++++++++------------ 10 files changed, 814 insertions(+), 432 deletions(-) create mode 100644 qx08/source/class/tr/Theme.js create mode 100644 qx08/source/class/tr/ui/Config.js create mode 100644 qx08/source/class/tr/ui/Link.js (limited to 'qx08/source/class/tr') diff --git a/qx08/source/class/tr/Application.js b/qx08/source/class/tr/Application.js index 7113b14..fe7df8f 100644 --- a/qx08/source/class/tr/Application.js +++ b/qx08/source/class/tr/Application.js @@ -17,68 +17,78 @@ /** * This is the main application class of your custom application "qx08" */ -qx.Class.define("tr.Application", -{ - extend : qx.application.Standalone, - - /* - ***************************************************************************** - MEMBERS - ***************************************************************************** - */ - - members : - { - /** - * This method contains the initial application code and gets called - * during startup of the application - */ - main : function() - { - var self=this; - // Call super class - this.base(arguments); - - // Enable logging in debug variant - if (qx.core.Variant.isSet("qx.debug", "on")) - { - // support native logging capabilities, e.g. Firebug for Firefox - qx.log.appender.Native; - // support additional cross-browser console. Press F7 to toggle visibility - qx.log.appender.Console; - } - - /* - ------------------------------------------------------------------------- - Below is your actual application code... - ------------------------------------------------------------------------- - */ - - - // if we run with a file:// url make sure - // the app finds the Tr service (Tr.cgi) - Tr.Server.getInstance().setLocalUrl( - 'http://johan.oetiker.ch/~oetiker/tr/' - ); - var root=this.getRoot(); - // Document is the application root - var root = new qx.ui.container.Composite(new qx.ui.layout.VBox()); - this.getRoot().add(root, { left : 0, top: 0}); - - - - var top = new qx.ui.container.Composite(new qx.ui.layout.HBox()); - var title = new qx.ui.basic.Atom('SmokeTrace 2.4.2'); - with(title){ - setTextColor('#b0b0b0'); - setFont(qx.bom.Font.fromString('20px bold sans-serif')); - } - top.add(title); - top.add(new qx.ui.basic.HorizontalSpacer()); - top.add(new Tr.ui.ActionButton()); - root.add(top); - var trace = new Tr.ui.TraceTable(); - root.add(trace); - root.add(new Tr.ui.Footer(this.tr("SmokeTrace is part of the of the SmokePing suite created by Tobi Oetiker, Copyright 2008."),'http://oss.oetiker.ch/smokeping')); - } -}); +qx.Class.define("tr.Application", { + extend : qx.application.Standalone, + + members : { + /** + * This method contains the initial application code and gets called + * during startup of the application + * + * @type member + * @return {void} + */ + main : function() { + // Call super class + this.base(arguments); + + // Enable logging in debug variant + if (qx.core.Variant.isSet("qx.debug", "on")) { + // support native logging capabilities, e.g. Firebug for Firefox + qx.log.appender.Native; + + // support additional cross-browser console. Press F7 to toggle visibility + qx.log.appender.Console; + } + + // if we run with a file:// url make sure + // the app finds the Tr service (tr.cgi) + tr.Server.getInstance().setLocalUrl('http://localhosth/~oetiker/tr/'); + + // Document is the application root + var root = new qx.ui.container.Composite(new qx.ui.layout.VBox()); + + this.getRoot().add(root, { + left : 0, + top : 0, + right : 0, + bottom : 0 + }); + + root.set({ margin : 10 }); + var top = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({ alignY : 'top' })); + var title = new tr.ui.Link('SmokeTrace 2.4.2', 'http://oss.oetiker.ch/smokeping/', '#b0b0b0', '20px bold sans-serif'); + + top.add(title); + top.add(new qx.ui.core.Spacer(), { flex : 1 }); + top.add(new tr.ui.ActionButton()); + root.add(top); + + var trace = new tr.ui.TraceTable(); + root.add(trace, { flex : 1 }); + + root.add(new tr.ui.Footer(this.tr("SmokeTrace is part of the of the SmokePing suite created by Tobi Oetiker, Copyright 2008."), 'http://oss.oetiker.ch/smokeping/')); + + var cfgwin = new tr.ui.Config(); + + this.getRoot().add(cfgwin, { + left : 30, + top : 30 + }); + + qx.event.message.Bus.subscribe('tr.config', function(e) { + switch(e.getData()) + { + case 'open': + cfgwin.open(); + break; + + case 'cancel': + case 'ok': + cfgwin.close(); + break; + } + }); + } + } + }); \ No newline at end of file diff --git a/qx08/source/class/tr/Server.js b/qx08/source/class/tr/Server.js index 89496f1..c58ee53 100644 --- a/qx08/source/class/tr/Server.js +++ b/qx08/source/class/tr/Server.js @@ -3,70 +3,76 @@ ************************************************************************ */ /** - * A Tr specific rpc call which works + * A Tr specific rpc call which works */ +qx.Class.define('tr.Server', { + extend : qx.io.remote.Rpc, + type : "singleton", + + -qx.Class.define('Tr.Server', { - extend: qx.io.remote.Rpc, - type: "singleton", /* - ***************************************************************************** - CONSTRUCTOR - ***************************************************************************** - */ + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ /** - * @param local_url {String} When running the application in file:// mode. - * where will we find our RPC server. - */ - construct: function (local_url) { + * @param local_url {String} When running the application in file:// mode. + * where will we find our RPC server. + */ + construct : function(local_url) { this.base(arguments); + this.set({ - timeout: 7000000, - url: 'tr.cgi', - serviceName: 'Tr', - crossDomain: true - }); - return this; + timeout : 60000, + url : 'tr.cgi', + serviceName : 'Tr', + crossDomain : true + }); + + return this; }, - /* - ***************************************************************************** - MEMBERS - ***************************************************************************** - */ - members : - { - /* - --------------------------------------------------------------------------- - CORE METHODS - --------------------------------------------------------------------------- - */ + + /* + ***************************************************************************** + MEMBERS + ***************************************************************************** + */ + + members : { + /* + --------------------------------------------------------------------------- + CORE METHODS + --------------------------------------------------------------------------- + */ /** * Tell about the BaseUrl we found. * * @type member - * - * @param {void} - * - * @return BaseUrl {Strings} - */ - - getBaseUrl: function(){ - return this.__base_url; + * @return {var} BaseUrl {Strings} + */ + getBaseUrl : function() { + return this.__base_url; }, - setLocalUrl: function(local_url){ - if ( document.location.host === '' ) { - with(this){ - setUrl(local_url+'tr.cgi'); - } - } - } + /** + * TODOC + * + * @type member + * @param local_url {var} TODOC + * @return {void} + */ + setLocalUrl : function(local_url) { + if (document.location.host === '') { + this.setUrl(local_url + 'tr.cgi'); + } + } } -}); +}); \ No newline at end of file diff --git a/qx08/source/class/tr/Theme.js b/qx08/source/class/tr/Theme.js new file mode 100644 index 0000000..6008e3a --- /dev/null +++ b/qx08/source/class/tr/Theme.js @@ -0,0 +1,11 @@ +qx.Theme.define("tr.Theme", { + title : "Tr Light Colors", + + meta : { + color : tr.theme.Color, + decoration : qx.theme.modern.Decoration, + font : qx.theme.modern.Font, + icon : qx.theme.icon.Tango, + appearance : qx.theme.modern.Appearance + } +}); \ No newline at end of file diff --git a/qx08/source/class/tr/test/DemoTest.js b/qx08/source/class/tr/test/DemoTest.js index 76ce685..0f6a04f 100644 --- a/qx08/source/class/tr/test/DemoTest.js +++ b/qx08/source/class/tr/test/DemoTest.js @@ -20,36 +20,39 @@ * i.e. using deeper namespaces and a corresponding file structure within the * test folder. */ -qx.Class.define("tr.test.DemoTest", -{ - extend : qx.dev.unit.TestCase, - - members : - { - /* - --------------------------------------------------------------------------- - TESTS - --------------------------------------------------------------------------- - */ - - /** - * Here are some simple tests - */ - testSimple : function() - { - this.assertEquals(4, 3+1, "This should never fail!"); - this.assertFalse(false, "Can false be true?!"); - }, - - /** - * Here are some more advanced tests - */ - testAdvanced: function () - { - var a = 3; - var b = a; - this.assertIdentical(a, b, "A rose by any other name is still a rose"); - this.assertInRange(3, 1, 10, "You must be kidding, 3 can never be outside [1,10]!"); +qx.Class.define("tr.test.DemoTest", { + extend : qx.dev.unit.TestCase, + + members : { + /* + --------------------------------------------------------------------------- + TESTS + --------------------------------------------------------------------------- + */ + + /** + * Here are some simple tests + * + * @type member + * @return {void} + */ + testSimple : function() { + this.assertEquals(4, 3 + 1, "This should never fail!"); + this.assertFalse(false, "Can false be true?!"); + }, + + + /** + * Here are some more advanced tests + * + * @type member + * @return {void} + */ + testAdvanced : function() { + var a = 3; + var b = a; + this.assertIdentical(a, b, "A rose by any other name is still a rose"); + this.assertInRange(3, 1, 10, "You must be kidding, 3 can never be outside [1,10]!"); + } } - } -}); +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/ActionButton.js b/qx08/source/class/tr/ui/ActionButton.js index 5d6eb5d..6b91e5d 100644 --- a/qx08/source/class/tr/ui/ActionButton.js +++ b/qx08/source/class/tr/ui/ActionButton.js @@ -5,192 +5,235 @@ /** * a widget showing the Tr graph overview */ +qx.Class.define('tr.ui.ActionButton', { + extend : qx.ui.container.Composite, + + -qx.Class.define('Tr.ui.ActionButton', -{ - extend: qx.ui.Containter. /* - ***************************************************************************** - CONSTRUCTOR - ***************************************************************************** - */ - - construct: function () { - this.base(arguments); - - this.set({ - height: 'auto', - width: 'auto', - horizontalChildrenAlign: 'left' - }); - var hbox = new qx.ui.layout.HorizontalBoxLayout; - hbox.set({ - height: 'auto', - width: 'auto', - verticalChildrenAlign: 'middle' - }); + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ + + construct : function() { + this.base(arguments, new qx.ui.layout.VBox); + + // this.set({ alignX : 'left' }); + // return this; + var hbox = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({ + alignY : 'middle', + spacing : 5 + })); + var lab1 = new qx.ui.basic.Label(this.tr("Host")); - lab1.set({ - paddingRight: 6 - }); + lab1.set({ paddingRight : 6 }); hbox.add(lab1); var host = new qx.ui.form.TextField(); + host.set({ - width: 200, - height: 'auto', - border: 'dark-shadow', - padding: 1 + width : 200, + padding : 1 }); + hbox.add(host); this.__host = host; var lab2 = new qx.ui.basic.Label(this.tr("Delay")); + lab2.set({ - paddingRight: 6, - paddingLeft: 12 + paddingRight : 6, + paddingLeft : 12 }); + hbox.add(lab2); - var delay = new qx.ui.form.Spinner(1,2,60); - delay.set({ - border: 'dark-shadow', - width: 45 - }); + + var delay = new qx.ui.form.Spinner(0, 2, 60); + + delay.set({ width : 45 }); hbox.add(delay); this.__delay = delay; var lab3 = new qx.ui.basic.Label(this.tr("Rounds")); + lab3.set({ - paddingRight: 6, - paddingLeft: 12 + paddingRight : 6, + paddingLeft : 12 }); + hbox.add(lab3); - var rounds = new qx.ui.form.Spinner(1,20,200); - rounds.set({ - border: 'dark-shadow', - width: 45 - }); + var rounds = new qx.ui.form.Spinner(0, 20, 200); + + rounds.set({ width : 45 }); + hbox.add(rounds); this.__rounds = rounds; var button = new qx.ui.form.Button(''); this.__button = button; - button.set({ - marginLeft: 10, - width: 60, - height: 'auto', - border: 'dark-shadow', - padding: 2 + + button.set({ + marginLeft : 10, + width : 60, + padding : 2, + center : true }); + hbox.add(button); + + var config = new qx.ui.form.Button(this.tr("Config ...")); + hbox.add(config); + + config.addListener('execute', function(e) { + qx.event.message.Bus.dispatch('tr.config', 'open'); + }); + this.add(hbox); + var info = new qx.ui.basic.Atom(); + info.set({ - marginTop: 3, - padding: 3, - textColor: 'red', - width: '100%', - height: 'auto', - backgroundColor: '#f0f0f0', - visibility: false - }); - qx.event.message.Bus.subscribe('tr.info',this.__set_info,this); + marginTop : 3, + padding : 3, + textColor : 'red', + backgroundColor : '#f0f0f0', + visibility : 'hidden' + }); + + qx.event.message.Bus.subscribe('tr.info', this.__set_info, this); this.add(info); this.__info = info; - qx.event.message.Bus.subscribe('tr.status',this.__set_status,this); - qx.event.message.Bus.dispatch('tr.status','stopped'); - - var start_trace = function(event) { - qx.event.message.Bus.dispatch('tr.cmd',{ - action: button.getUserData('action'), - host: host.getValue(), - delay: delay.getValue(), - rounds: rounds.getValue() + qx.event.message.Bus.subscribe('tr.status', this.__set_status, this); + qx.event.message.Bus.dispatch('tr.status', 'stopped'); + + var start_trace = function(event) { + qx.event.message.Bus.dispatch('tr.cmd', { + action : button.getUserData('action'), + host : host.getValue(), + delay : delay.getValue(), + rounds : rounds.getValue() }); - }; + }; + + host.addListener('keydown', function(e) { + if (e.getKeyIdentifier() == 'Enter') { + start_trace(); + } + }); -// var self=this; -// host.addEventListener('keyup',function(e){if(e.getKeyIdentifier() == 'Enter'){start_trace()}}); - host.addEventListener('execute',start_trace); - button.addEventListener('execute', start_trace ); + // host.addListener('execute', start_trace); + button.addListener('execute', start_trace); - var history = qx.client.History.getInstance(); - var history_action = function(event){ + var history = qx.bom.History.getInstance(); + + var history_action = function(event) { var targ = event.getData(); host.setValue(targ); - history.addToHistory(targ,'SmokeTrace to '+targ); - start_trace(); - } - history.addEventListener('request', history_action); + history.addToHistory(targ, 'SmokeTrace to ' + targ); + start_trace(); + }; + + history.addListener('request', history_action); // if we got called with a host on the commandline - var initial_host = qx.client.History.getInstance().getState(); - if (initial_host){ + var initial_host = qx.bom.History.getInstance().getState(); + + if (initial_host) { host.setValue(initial_host); - history.addToHistory(initial_host,'SmokeTrace to '+initial_host); + history.addToHistory(initial_host, 'SmokeTrace to ' + initial_host); + // dispatch this task once all the initializations are done - qx.client.Timer.once(start_trace,this,0); - } + qx.event.Timer.once(start_trace, this, 0); + } }, - members: { - __set_info: function(e){ + members : { + __host : null, + __delay : null, + __rounds : null, + __button : null, + __info : null, + + + /** + * TODOC + * + * @type member + * @param e {Event} TODOC + * @return {void} + */ + __set_info : function(e) { this.__info.set({ - label: e.getData(), - visibility: true + label : e.getData(), + visibility : 'visible' }); }, - __set_status: function(m){ + + + /** + * TODOC + * + * @type member + * @param m {var} TODOC + * @return {void} + */ + __set_status : function(m) { var host = this.__host; var rounds = this.__rounds; var delay = this.__delay; - with(this.__button){ - // this.debug(m.getData()); - switch(m.getData()){ + var button = this.__button; + var action = button.getUserData('action'); + + // this.debug(m.getData()); + switch(m.getData()) + { case 'starting': - if (getUserData('action') == 'go') { - setLabel(this.tr("Starting")); - this.__info.setVisibility(false); - border: 'dark-shadow' - setEnabled(false); + if (action == 'go') { + button.setLabel(this.tr("Starting")); + this.__info.setVisibility('hidden'); + + // border:'dark-shadow', + button.setEnabled(false); host.setEnabled(false); rounds.setEnabled(false); delay.setEnabled(false); } + break; + case 'stopping': - if (getUserData('action') == 'stop') { - setLabel(this.tr("Stopping")); - setEnabled(false); + if (action == 'stop') { + button.setLabel(this.tr("Stopping")); + button.setEnabled(false); host.setEnabled(false); rounds.setEnabled(false); delay.setEnabled(false); } + break; + case 'stopped': - setUserData('action','go'); - setLabel(this.tr("Go")); - setEnabled(true); + button.setUserData('action', 'go'); + button.setLabel(this.tr("Go")); + button.setEnabled(true); host.setEnabled(true); rounds.setEnabled(true); delay.setEnabled(true); break; + case 'started': - setUserData('action','stop'); - setLabel(this.tr("Stop")); - setEnabled(true); + button.setUserData('action', 'stop'); + button.setLabel(this.tr("Stop")); + button.setEnabled(true); host.setEnabled(false); rounds.setEnabled(false); delay.setEnabled(false); break; + default: - alert('Unknown Status Message: '+m.getData()); - } + this.error('Unknown Status Message: ' + m.getData()); } - } - } - - -}); - - + } + } +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/Cellrenderer.js b/qx08/source/class/tr/ui/Cellrenderer.js index f18672d..6a89da9 100644 --- a/qx08/source/class/tr/ui/Cellrenderer.js +++ b/qx08/source/class/tr/ui/Cellrenderer.js @@ -6,6 +6,7 @@ * Tobias Oetiker ************************************************************************ */ + /* ************************************************************************ #module(Tr) ************************************************************************ */ @@ -13,34 +14,38 @@ /** * A configurable cell renderre */ +qx.Class.define('tr.ui.Cellrenderer', { + extend : qx.ui.table.cellrenderer.Number, + -qx.Class.define('Tr.ui.Cellrenderer', -{ - extend: qx.ui.table.cellrenderer.Number, /** - * Format a number with a configurable number of fraction digits - * and add optional pre and postfix. - * @param digits {Integer} how many digits should there be. Default is 0. - * @param prefix {String} optional prefix. - * @param postfix {String} optional postfix. - */ - - construct: function (digits,postfix,prefix) { - if (digits == undefined){ + * Format a number with a configurable number of fraction digits + * and add optional pre and postfix. + * @param digits {Integer} how many digits should there be. Default is 0. + * @param prefix {String} optional prefix. + * @param postfix {String} optional postfix. + */ + construct : function(digits, postfix, prefix) { + if (digits == undefined) { digits = 0; } - this.base(arguments) + + this.base(arguments); var format = new qx.util.format.NumberFormat(); + format.set({ - maximumFractionDigits: digits, - minimumFractionDigits: digits + maximumFractionDigits : digits, + minimumFractionDigits : digits }); - if (postfix != undefined){ + + if (postfix != undefined) { format.setPostfix(postfix); } - if (prefix != undefined){ + + if (prefix != undefined) { format.setPrefix(prefix); - } + } + this.setNumberFormat(format); } -}); +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/Config.js b/qx08/source/class/tr/ui/Config.js new file mode 100644 index 0000000..5d264d2 --- /dev/null +++ b/qx08/source/class/tr/ui/Config.js @@ -0,0 +1,196 @@ +/* ************************************************************************ +#module(Tr) +#asset(qx/icon/${qx.icontheme}/22/actions/dialog-apply.png) +#asset(qx/icon/${qx.icontheme}/22/actions/dialog-close.png) + +************************************************************************ */ + +/** + * show the config options for traceroute as defined by the server + */ +qx.Class.define('tr.ui.Config', { + extend : qx.ui.window.Window, + + + + + /* + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ + + construct : function() { + this.base(arguments, this.tr("Traceroute Configuration")); + var layout = new qx.ui.layout.Grid(3, 5); + layout.setColumnAlign(0, 'right', 'middle'); + layout.setColumnAlign(1, 'left', 'middle'); + layout.setColumnWidth(0, 140); + layout.setColumnWidth(1, 140); + + this.setLayout(layout); + + this.set({ + allowMaximize : false, + allowMinimize : false, + modal : true, + resizable : false, + showMaximize : false, + showMinimize : false + }); + + var self = this; + + var create_config = function(retval, exc, id) { + if (exc == null) { + self.__create_config(retval); + } else { + self.error(exc); + } + }; + + tr.Server.getInstance().callAsync(create_config, 'get_config'); + }, + + members : { + /** + * TODOC + * + * @type member + * @param data {var} TODOC + * @return {void} + */ + __create_config : function(data) { + var entries = data.length; + var status = {}; + var setdef = {}; + var r = 0; + var self = this; + + for (var k=0; k 0); + }; + + break; + } + + self.add(widget, { + row : r, + column : 1 + }); + + r++; + })(); + + }* // this is the rest of the scoping trick + + for (var key in setdef) { + setdef[key](); + } + + var ok = new qx.ui.form.Button(this.tr("Apply")).set({ + marginTop : 10, + marginLeft : 20 + }); + + ok.addListener('execute', function(e) { + var config = {}; + + for (var key in status) { + config[key] = status[key](); + } + + self.close(); + qx.event.message.Bus.dispatch('tr.setup', config); + }); + + this.add(ok, { + row : r, + column : 0 + }); + + var cancel = new qx.ui.form.Button(this.tr("Reset")).set({ + marginTop : 10, + marginRight : 20 + }); + + cancel.addListener('execute', function(e) { + for (var key in setdef) { + setdef[key](); + } + }); + + this.add(cancel, { + row : r, + column : 1 + }); + } + } +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/Footer.js b/qx08/source/class/tr/ui/Footer.js index 1882043..6b77aa3 100644 --- a/qx08/source/class/tr/ui/Footer.js +++ b/qx08/source/class/tr/ui/Footer.js @@ -5,41 +5,20 @@ /** * a widget showing the footer */ +qx.Class.define('tr.ui.Footer', { + extend : qx.ui.container.Composite, + + -qx.Class.define('Tr.ui.Footer', -{ - extend: qx.ui.layout.HorizontalBoxLayout, /* - ***************************************************************************** - CONSTRUCTOR - ***************************************************************************** - */ + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ - construct: function (text,url) { - this.base(arguments); - this.set({ - horizontalChildrenAlign: 'right', - height: 'auto' - }); - var logo = new qx.ui.form.Button(text); - logo.set({ - textColor: '#b0b0b0', - backgroundColor: null, - font: qx.ui.core.Font.fromString('10px sans-serif'), - border: null - }); - - logo.addEventListener('execute', function(e){ - var w = new qx.client.NativeWindow(url); - w.set({ - width: 1000, - height: 800 - }); - w.open() - }); - this.add(logo); + construct : function(text, url) { + this.base(arguments, new qx.ui.layout.HBox().set({ alignX : 'right' })); + this.add(new tr.ui.Link(text, url, '#888', '10px sans-serif')); } -}); - - +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/Link.js b/qx08/source/class/tr/ui/Link.js new file mode 100644 index 0000000..dd7f33e --- /dev/null +++ b/qx08/source/class/tr/ui/Link.js @@ -0,0 +1,54 @@ +/* ************************************************************************ +#module(Tr) +************************************************************************ */ + +/** + * A label with the ability to link out. Based on Label. + */ +qx.Class.define('tr.ui.Link', { + extend : qx.ui.basic.Label, + + + + + /* + ***************************************************************************** + CONSTRUCTOR + ***************************************************************************** + */ + + /** + * @param text {String} Initial label + * @param url {String} Where to link to + * @param color {String} Hex Color for the text + * @param font {String} Font from string representation + */ + construct : function(text, url, color, font) { + this.base(arguments, text); + + if (color) { + this.setTextColor(color); + } + + if (font) { + this.setFont(qx.bom.Font.fromString(font)); + } + + this.set({ + cursor : 'pointer', + opacity : 0.9 + }); + + this.addListener('click', function(e) { + window.open(url, '__new'); + }); + + this.addListener('mouseover', function(e) { + this.setOpacity(1); + }, this); + + this.addListener('mouseout', function(e) { + this.setOpacity(0.7); + }, this); + } +}); \ No newline at end of file diff --git a/qx08/source/class/tr/ui/TraceTable.js b/qx08/source/class/tr/ui/TraceTable.js index 446cbad..2291c2c 100644 --- a/qx08/source/class/tr/ui/TraceTable.js +++ b/qx08/source/class/tr/ui/TraceTable.js @@ -5,210 +5,285 @@ /** * a widget showing the Tr target tree */ +qx.Class.define('tr.ui.TraceTable', { + extend : qx.ui.table.Table, + + -qx.Class.define('Tr.ui.TraceTable', -{ - extend: qx.ui.table.Table, /* - ***************************************************************************** + ***************************************************************************** CONSTRUCTOR - ***************************************************************************** - */ + ***************************************************************************** + */ - - construct: function () { - + construct : function() { var tableModel = new qx.ui.table.model.Simple(); this.__tableModel = tableModel; - tableModel.setColumns([ this.tr("Hop"), this.tr("Host"),this.tr("Ip"), - this.tr("Loss [%]"), this.tr("Sent"), this.tr("Last [ms]"), //"; help syntax highliter - this.tr("Avg [ms]"), this.tr("Best [ms]"), this.tr("Worst [ms]"), this.tr("StDev [ms]") ]); + + tableModel.setColumns([ this.tr("Hop"), this.tr("Host"), this.tr("Ip"), this.tr("Loss [%]"), this.tr("Sent"), this.tr("Last [ms]"), * // "; help syntax highliter + this.tr("Avg [ms]"), this.tr("Best [ms]"), this.tr("Worst [ms]"), this.tr("StDev [ms]") ]); + var custom = { - tableColumnModel: function(obj) { + tableColumnModel : function(obj) { return new qx.ui.table.columnmodel.Resize(obj); } }; - with(this){ - base(arguments,tableModel,custom); - set({ - width: '100%', - height: '1*', - border: 'dark-shadow', - showCellFocusIndicator: false, - statusBarVisible: false - }); - }; - var tcm = this.getTableColumnModel(); + + this.base(arguments, tableModel, custom); + + this.set({ + decorator : 'main', + showCellFocusIndicator : false, + statusBarVisible : false + }); + + var tcm = this.getTableColumnModel(); this.__tcm = tcm; - tcm.setDataCellRenderer(0, new Tr.ui.Cellrenderer(1)); - tcm.setDataCellRenderer(3, new Tr.ui.Cellrenderer(0,' %')); - tcm.setDataCellRenderer(4, new Tr.ui.Cellrenderer(0)); - - var render_ms = new Tr.ui.Cellrenderer(1); + tcm.setDataCellRenderer(0, new tr.ui.Cellrenderer(1)); + tcm.setDataCellRenderer(3, new tr.ui.Cellrenderer(0, ' %')); + tcm.setDataCellRenderer(4, new tr.ui.Cellrenderer(0)); + + var render_ms = new tr.ui.Cellrenderer(1); - for (var i=5;i<10;i++){ + for (var i=5; i<10; i++) { tcm.setDataCellRenderer(i, render_ms); } - // Obtain the behavior object to manipulate var resizeBehavior = tcm.getBehavior(); + // This uses the set() method to set all attriutes at once; uses flex - resizeBehavior.set(0, { width:"2*"}); - resizeBehavior.set(1, { width:"9*"}); - resizeBehavior.set(2, { width:"5*"}); + resizeBehavior.set(0, { width : '2*' }); + resizeBehavior.set(1, { width : '9*' }); + resizeBehavior.set(2, { width : '5*' }); - for (var i=3;i<10;i++){ - resizeBehavior.set(i, { width:"3*"}); + for (var i=3; i<10; i++) { + resizeBehavior.set(i, { width : '3*' }); } - qx.event.message.Bus.subscribe('tr.cmd',this.__handle_tr,this); + + qx.event.message.Bus.subscribe('tr.cmd', this.__handle_tr, this); }, + + + /* - ***************************************************************************** - Statics - ***************************************************************************** - */ - members: { - __make_empty_row: function (){ - return ([undefined,undefined,undefined,0,0,undefined,undefined,undefined,undefined,undefined,0,0,0]); + ***************************************************************************** + Statics + ***************************************************************************** + */ + + members : { + __handle : null, + __data : null, + __delay : null, + __tableModel : null, + __tcm : null, + + + /** + * TODOC + * + * @type member + * @return {var} TODOC + */ + __make_empty_row : function() { + return ([ undefined, undefined, undefined, 0, 0, undefined, undefined, undefined, undefined, undefined, 0, 0, 0 ]); }, - __stop_table: function (){ + + + /** + * TODOC + * + * @type member + * @return {void} + */ + __stop_table : function() { var tableModel = this.__tableModel; - for (var i=0;i<10;i++){ - tableModel.setColumnSortable(i,true); + + for (var i=0; i<10; i++) { + tableModel.setColumnSortable(i, true); } - qx.event.message.Bus.dispatch('tr.status','stopped'); + + qx.event.message.Bus.dispatch('tr.status', 'stopped'); this.__handle = undefined; }, - __handle_tr: function(m){ + + + /** + * TODOC + * + * @type member + * @param m {var} TODOC + * @return {void} + */ + __handle_tr : function(m) { var self = this; - var f_hop = 0,f_host=1,f_ip=2,f_loss=3,f_snt=4,f_last=5,f_avg=6,f_best=7,f_worst=8,f_stdev=9,f_cnt=10,f_sum=11,f_sqsum=12; + var f_host = 1, f_ip = 2, f_loss = 3, f_snt = 4, f_last = 5, f_avg = 6, f_best = 7, f_worst = 8, f_stdev = 9, f_cnt = 10, f_sum = 11, f_sqsum = 12; var fill_table; - fill_table = function(retval,exc,id){ - if (exc == null){ - if ( self.__handle == undefined ) { - qx.event.message.Bus.dispatch('tr.status','started'); + + fill_table = function(retval, exc, id) { + if (exc == null) { + if (self.__handle == undefined) { + qx.event.message.Bus.dispatch('tr.status', 'started'); } + self.__handle = retval['handle']; var tableModel = self.__tableModel; var lines = retval['output'].length; var data = self.__data; var sleep = 0; - for(var i=0;i hop) break; - if ( Math.floor(data[ii][0]) == hop ){ - if ( ip == undefined ) break; - if ( ip == data[ii][2] ) break; + + while (true) { + if (ii == max) { + break; + } + + if (Math.floor(data[ii][0]) > hop) { + break; } + + if (Math.floor(data[ii][0]) == hop) { + if (ip == undefined) { + break; + } + + if (ip == data[ii][2]) { + break; + } + } + ii++; } - if (ii == max || Math.floor(data[ii][0]) > hop ){ - if (ii > 0 && Math.floor(data[ii-1][0]) == hop ){ - hop = data[ii-1][0] + 0.1; + + if (ii == max || Math.floor(data[ii][0]) > hop) { + if (ii > 0 && Math.floor(data[ii - 1][0]) == hop) { + hop = data[ii - 1][0] + 0.1; } - data.splice(ii,0,self.__make_empty_row()); + + data.splice(ii, 0, self.__make_empty_row()); data[ii][0] = hop; } var drow = data[ii]; - if (drow[f_host] == undefined && host != undefined){ + + if (drow[f_host] == undefined && host != undefined) { drow[f_host] = host; } - if (drow[f_ip] == undefined && ip != undefined){ + + if (drow[f_ip] == undefined && ip != undefined) { drow[f_ip] = ip; } + drow[f_snt]++; drow[f_last] = value; - - if (value != undefined){ + if (value != undefined) { var best = drow[f_best]; - if (best == undefined || best > value){ - drow[f_best] = value; - } - var worst = drow[f_worst]; - if (worst == undefined || worst < value){ - drow[f_worst] = value; + + if (best == undefined || best > value) { + drow[f_best] = value; } - drow[f_sum] += value; + + var worst = drow[f_worst]; + + if (worst == undefined || worst < value) { + drow[f_worst] = value; + } + + drow[f_sum] += value; var sum = drow[f_sum]; - drow[f_cnt] ++; + drow[f_cnt]++; var cnt = drow[f_cnt]; - var sqsum = drow[f_sqsum]+value*value; - drow[f_sqsum] = sqsum; - drow[f_avg] = drow[f_sum]/drow[f_cnt]; - drow[f_stdev] = Math.sqrt((cnt*sqsum-sum*sum)/(cnt*(cnt-1))) + var sqsum = drow[f_sqsum] + value * value; + drow[f_sqsum] = sqsum; + drow[f_avg] = drow[f_sum] / drow[f_cnt]; + drow[f_stdev] = Math.sqrt((cnt * sqsum - sum * sum) / (cnt * (cnt - 1))); } - drow[f_loss] = ((drow[f_snt]-drow[f_cnt])/drow[f_snt])*100; - } + + drow[f_loss] = ((drow[f_snt] - drow[f_cnt]) / drow[f_snt]) * 100; + } tableModel.setData(data); - if (retval['again']){ - var next_round = function (){Tr.Server.getInstance().callAsync( - fill_table,'run_tr',{ handle: retval['handle'], - point: retval['point']})}; - qx.client.Timer.once(next_round,self,sleep*1000); + + if (retval['again']) { + var next_round = function() { + tr.Server.getInstance().callAsync(fill_table, 'run_tr', { + handle : retval['handle'], + point : retval['point'] + }); + }; + + qx.event.Timer.once(next_round, self, sleep * 1000); } else { self.__stop_table(); } } else { - alert(exc); self.__stop_table(); - } + } }; - var stop_handler = function (data,exc,id){ - if (exc == null){ - qx.event.message.Bus.dispatch('tr.status','stopped'); + var stop_handler = function(data, exc, id) { + if (exc == null) { + qx.event.message.Bus.dispatch('tr.status', 'stopped'); + } else { + this.error(exc); } - else { - alert(exc); - } }; var cmd = m.getData(); - switch(cmd['action']){ - case 'stop': - qx.event.message.Bus.dispatch('tr.status','stopping'); - Tr.Server.getInstance().callAsync(stop_handler,'stop_tr',this.__handle); - break; - case 'go': - this.__data = []; - this.__tableModel.setData(this.__data); - this.__delay = cmd['delay']; - for (var i=0;i<10;i++){ - this.__tableModel.setColumnSortable(i,false); - } - qx.event.message.Bus.dispatch('tr.status','starting'); - Tr.Server.getInstance().callAsync(fill_table,'run_tr',{host: cmd['host'], rounds: cmd['rounds'], delay: cmd['delay']}); - break; - default: - alert('Unknown Command '+cmd['action']); + + switch(cmd['action']) + { + case 'stop': + qx.event.message.Bus.dispatch('tr.status', 'stopping'); + tr.Server.getInstance().callAsync(stop_handler, 'stop_tr', this.__handle); + break; + + case 'go': + this.__data = []; + this.__tableModel.setData(this.__data); + this.__delay = cmd['delay']; + + for (var i=0; i<10; i++) { + this.__tableModel.setColumnSortable(i, false); + } + + qx.event.message.Bus.dispatch('tr.status', 'starting'); + tr.Server.getInstance().callAsync(fill_table, 'run_tr', { + host : cmd['host'], + rounds : cmd['rounds'], + delay : cmd['delay'] + }); + + break; + + default: + this.error('Unknown Command ' + cmd['action']); } } - } -}); - - + } +}); \ No newline at end of file -- cgit v1.2.3-24-g4f1b