Skip to content

Commit

Permalink
Regrouped generic gui function in the generic file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jan 30, 2014
1 parent 9e3faa4 commit bc6e91c
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 116 deletions.
71 changes: 0 additions & 71 deletions src/gui/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,6 @@ dwv.gui.base = dwv.gui.base || {};
dwv.gui.filter = dwv.gui.filter || {};
dwv.gui.filter.base = dwv.gui.filter.base || {};

/**
* Append the slider HTML.
* @method appendSliderHtml
* @static
*/
dwv.gui.base.appendSliderHtml = function()
{
// default values
var min = 0;
var max = 1;

// jquery-mobile range slider
// minimum input
var inputMin = document.createElement("input");
inputMin.id = "threshold-min";
inputMin.type = "range";
inputMin.max = max;
inputMin.min = min;
inputMin.value = min;
// maximum input
var inputMax = document.createElement("input");
inputMax.id = "threshold-max";
inputMax.type = "range";
inputMax.max = max;
inputMax.min = min;
inputMax.value = max;
// slicer div
var div = document.createElement("div");
div.id = "threshold-div";
div.setAttribute("data-role", "rangeslider");
div.appendChild(inputMin);
div.appendChild(inputMax);
div.setAttribute("data-mini", "true");
// append to document
document.getElementById("thresholdLi").appendChild(div);
// bind change
$("#threshold-div").on("change",
function( event ) {
dwv.gui.onChangeMinMax(
{ "min":$("#threshold-min").val(),
"max":$("#threshold-max").val() } );
}
);
// trigger creation
$("#toolList").trigger("create");
};

/**
* Initialise the slider HTML.
* @method initSliderHtml
* @static
*/
dwv.gui.base.initSliderHtml = function()
{
var min = app.getImage().getDataRange().min;
var max = app.getImage().getDataRange().max;

// minimum input
var inputMin = document.getElementById("threshold-min");
inputMin.max = max;
inputMin.min = min;
inputMin.value = min;
// maximum input
var inputMax = document.getElementById("threshold-max");
inputMax.max = max;
inputMax.min = min;
inputMax.value = max;
// trigger creation
$("#toolList").trigger("create");
};

/**
* Append the filter HTML to the page.
* @method appendFilterHtml
Expand Down
141 changes: 141 additions & 0 deletions src/gui/generic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/**
* GUI module.
* @module gui
*/
var dwv = dwv || {};
/**
* Namespace for GUI functions.
* @class gui
* @namespace dwv
* @static
*/
dwv.gui = dwv.gui || {};
dwv.gui.base = dwv.gui.base || {};

/**
* Get the size of the image display window.
* @method getWindowSize
* @static
*/
dwv.gui.base.getWindowSize = function()
{
return { 'width': ($(window).width()), 'height': ($(window).height() - 147) };
};

/**
* Update the progress bar.
* @method updateProgress
* @static
* @param {Object} event A ProgressEvent.
*/
dwv.gui.updateProgress = function(event)
{
// event is an ProgressEvent.
if( event.lengthComputable )
{
var percent = Math.round((event.loaded / event.total) * 100);
dwv.gui.displayProgress(percent);
}
};

/**
* Display a progress value.
* @method displayProgress
* @static
* @param {Number} percent The progress percentage.
*/
dwv.gui.base.displayProgress = function(percent)
{
// jquery-mobile specific
if( percent < 100 ) {
$.mobile.loading("show", {text: percent+"%", textVisible: true, theme: "b"} );
}
else if( percent === 100 ) {
$.mobile.loading("hide");
}
};

/**
* Refresh a HTML select.
* @method refreshSelect
* @static
* @param {String} selectName The name of the HTML select to refresh.
*/
dwv.gui.refreshSelect = function(selectName)
{
// jquery-mobile
if( $(selectName).selectmenu ) $(selectName).selectmenu('refresh');
};

/**
* Append the slider HTML.
* @method appendSliderHtml
* @static
*/
dwv.gui.base.appendSliderHtml = function()
{
// default values
var min = 0;
var max = 1;

// jquery-mobile range slider
// minimum input
var inputMin = document.createElement("input");
inputMin.id = "threshold-min";
inputMin.type = "range";
inputMin.max = max;
inputMin.min = min;
inputMin.value = min;
// maximum input
var inputMax = document.createElement("input");
inputMax.id = "threshold-max";
inputMax.type = "range";
inputMax.max = max;
inputMax.min = min;
inputMax.value = max;
// slicer div
var div = document.createElement("div");
div.id = "threshold-div";
div.setAttribute("data-role", "rangeslider");
div.appendChild(inputMin);
div.appendChild(inputMax);
div.setAttribute("data-mini", "true");
// append to document
document.getElementById("thresholdLi").appendChild(div);
// bind change
$("#threshold-div").on("change",
function( event ) {
dwv.gui.onChangeMinMax(
{ "min":$("#threshold-min").val(),
"max":$("#threshold-max").val() } );
}
);
// trigger creation
$("#toolList").trigger("create");
};

/**
* Initialise the slider HTML.
* @method initSliderHtml
* @static
*/
dwv.gui.base.initSliderHtml = function()
{
var min = app.getImage().getDataRange().min;
var max = app.getImage().getDataRange().max;

// minimum input
var inputMin = document.getElementById("threshold-min");
inputMin.max = max;
inputMin.min = min;
inputMin.value = min;
// maximum input
var inputMax = document.getElementById("threshold-max");
inputMax.max = max;
inputMax.min = min;
inputMax.value = max;
// trigger creation
$("#toolList").trigger("create");
};


33 changes: 0 additions & 33 deletions src/gui/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,6 @@ var dwv = dwv || {};
dwv.gui = dwv.gui || {};
dwv.gui.base = dwv.gui.base || {};

/**
* Update the progress bar.
* @method updateProgress
* @static
* @param {Object} event A ProgressEvent.
*/
dwv.gui.updateProgress = function(event)
{
// event is an ProgressEvent.
if( event.lengthComputable )
{
var percent = Math.round((event.loaded / event.total) * 100);
dwv.gui.displayProgress(percent);
}
};

/**
* Display a progress value.
* @method displayProgress
* @static
* @param {Number} percent The progress percentage.
*/
dwv.gui.base.displayProgress = function(percent)
{
// jquery-mobile loading
if( percent < 100 ) {
$.mobile.loading("show", {text: percent+"%", textVisible: true, theme: "b"} );
}
else if( percent === 100 ) {
$.mobile.loading("hide");
}
};

/**
* Append the loadbox HTML to the page.
* @method appendLoadboxHtml
Expand Down
12 changes: 0 additions & 12 deletions src/gui/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ var dwv = dwv || {};
dwv.gui = dwv.gui || {};
dwv.gui.base = dwv.gui.base || {};

/**
* Refresh a HTML select.
* @method refreshSelect
* @static
* @param {String} selectName The name of the HTML select to refresh.
*/
dwv.gui.refreshSelect = function(selectName)
{
// jquery-mobile
if( $(selectName).selectmenu ) $(selectName).selectmenu('refresh');
};

/**
* Append the toolbox HTML to the page.
* @method appendToolboxHtml
Expand Down
1 change: 1 addition & 0 deletions viewers/mobile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<script type="text/javascript" src="../../src/dicom/dicomParser.js"></script>
<script type="text/javascript" src="../../src/dicom/dictionary.js"></script>
<script type="text/javascript" src="../../src/gui/filter.js"></script>
<script type="text/javascript" src="../../src/gui/generic.js"></script>
<script type="text/javascript" src="../../src/gui/handlers.js"></script>
<script type="text/javascript" src="../../src/gui/help.js"></script>
<script type="text/javascript" src="../../src/gui/html.js"></script>
Expand Down
1 change: 1 addition & 0 deletions viewers/simple/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<script type="text/javascript" src="../../src/dicom/dicomParser.js"></script>
<script type="text/javascript" src="../../src/dicom/dictionary.js"></script>
<script type="text/javascript" src="../../src/gui/filter.js"></script>
<script type="text/javascript" src="../../src/gui/generic.js"></script>
<script type="text/javascript" src="../../src/gui/handlers.js"></script>
<script type="text/javascript" src="../../src/gui/help.js"></script>
<script type="text/javascript" src="../../src/gui/html.js"></script>
Expand Down
1 change: 1 addition & 0 deletions viewers/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<script type="text/javascript" src="../../src/dicom/dicomParser.js"></script>
<script type="text/javascript" src="../../src/dicom/dictionary.js"></script>
<script type="text/javascript" src="../../src/gui/filter.js"></script>
<script type="text/javascript" src="../../src/gui/generic.js"></script>
<script type="text/javascript" src="../../src/gui/handlers.js"></script>
<script type="text/javascript" src="../../src/gui/help.js"></script>
<script type="text/javascript" src="../../src/gui/html.js"></script>
Expand Down

0 comments on commit bc6e91c

Please sign in to comment.