/**
* Represents a XUL panel in JSFL. The object can be set up and then used to invoke a XUL panel without writing an actual XUL file.
* The XML can be generated purely in JSFL and passed in, or you can use convenience methods to add various controls without having
* to writing XML strings in JSFL.
*
*
*
**/
/**
* Constructor
* @param title The title of the window. This is only used if you own XML string is not passed in to the create
* method.
* @param buttons The remaining arguments are Strings of types of buttons to include. For convenience, use the static
* constants XULWindow.ACCEPT and XULWindow.CANCEL. This is only used if you own XML string is not passed in to
* the create method.
**/
function XULWindow(title) {
//fl.trace("Creating new XULWindow");
var that = this;
this._title = title || "Options";
var buttons = [];
var iLen = arguments.length;
for (var i = 1; i < iLen; i++) {
buttons.push(arguments[i]);
}
this._xml = '";
//fl.trace(xul);
FLfile.write(xulFilePath, xul);
var options = fl.getDocumentDOM().xmlPanel(xulFilePath);
FLfile.remove(xulFilePath);
return options//.dismiss;
}
/**
* Creates a check box control with a label.
* @param label String for the label next to the check box.
* @param id String for the id of the checkbox. This is the name of the property on the returned object with data in it
* @param checked Whether initially checked or not.
**/
this.addCheckbox = function(label, id, checked) {
this._xml += '';
}
/**
* Opens an <hbox> nodes so that all controls added after this method call are contained within the hbox. Should
* be ultimately terminated with closeHBox
*
* @see #closeHBox
**/
this.openHBox = function() {
this._xml += "";
}
/**
* Closes a previously open <hbox>, enclosing all intermediate controls within an hbox node.
*
* @see #openHBox
**/
this.closeHBox = function() {
this._xml += "";
}
/**
* Opens an <vbox> nodes so that all controls added after this method call are contained within the vbox. Should
* be ultimately terminated with closeVBox
*
* @see #closeVBox
**/
this.openVBox = function() {
this._xml += "";
}
/**
* Closes a previously open <vbox>, enclosing all intermediate controls within an vbox node.
*
* @see #openVBox
**/
this.closeVBox = function() {
this._xml += "";
}
/**
* @private
* Adds a button to the panel, but I assume there might be more involved in getting one to do something than we can realistically
* accomplish here.
**/
this.addButton = function(label, id, accessKey, autocheck) {
this._xml += '';
}
/**
* Creates a List Box.
* @param id The name of the property on the returned object with data in it.
* @param items Array of Objects specifying the items to display. The Objects should take on the following form:
* {label:"Text to display", value:"valueOfThisItem", selected:true}
* label is required. If value is omitted, the label is returned
* as the selected value.
* @param width The width in pixels. Defaults to 200.
* @param rows The number of rows to display in the viewable area. If the rows is less than the number of
* items in the list, scrollbars will appear. If this parameter is omitted, the length of the Array passed
* in to items is used.
**/
this.addListBox = function(id, items, width, rows) {
var signature = "addListBox(id:String, items:Array, width:Number=NaN, rows:Number=NaN)"
if (!id) {
alert("XULWindow::addListBox() requires an id parameter.\n\t" + signature);
return;
}
if (!items) {
alert("XULWindow::addListBox() requires an items parameter.\n\t" + signature);
return;
}
if (isNaN(width)) { width = 200; }
if (isNaN(rows)) { rows = items.length; }
this._xml += '\n';
var iLen = items.length;
var item;
var selected;
var value;
for (var i = 0; i < iLen; i++) {
item = items[i];
if (!item.label) {
alert("The items parameter of XULWindow::addListBox() needs to be an Array of Objects, each Object consisting of"
+ " at least a label property, and optionally a value and a selected property.")
return;
}
value = item.value ? 'value="'+item.value+'" ' : '';
selected = item.selected ? 'selected="'+item.selected+'" ' : '';
this._xml += '\t\n';
}
this._xml += "\n";
}
/**
* Adds a basic text label.
* @param label The text to display in the label.
* @param control The id of the associated control. If the user clicks on the label, focus is moved to the control. (Doesn't work?)
**/
this.addLabel = function(label, control) {
this._xml += '\n';
}
/**
* Adds a text box in which the user can type.
* @param id The name of the property on the returned data object.
* @param value The default value contained within the text box.
**/
this.addTextBox = function(id, value) {
this._xml += ''
}
/**
* Creates a vertically-oriented group of radio buttons.
* @param id The name of the property on the returned object with data in it.
* @param items Array of Objects specifying the buttons to display. The Objects should take on the following form:
* {label:"Text to display", value:"valueOfThisButton", selected:true}
* label is required. If value is omitted, the label is returned
* as the selected value.
**/
this.addRadioGroup = function(id, items) {
var signature = "addRadioGroup(id:String, items:Array)"
if (!id) {
alert("XULWindow::addRadioGroup() requires an id parameter.\n\t" + signature);
return;
}
if (!items) {
alert("XULWindow::addRadioGroup() requires an items parameter.\n\t" + signature);
return;
}
this._xml += '\n';
var iLen = items.length;
var item;
var selected;
var value;
for (var i = 0; i < iLen; i++) {
item = items[i];
if (!item.label) {
alert("The items parameter of XULWindow::addRadioGroup() needs to be an Array of Objects, each Object consisting of"
+ " at least a label property, and optionally a value and a selected property.")
return;
}
value = item.value ? 'value="'+item.value+'" ' : '';
selected = item.selected ? 'selected="'+item.selected+'" ' : '';
this._xml += '\t\n';
}
this._xml += "\n";
}
}
/**
* Static constant alias for the name of the "accept" button.
**/
XULWindow.__defineGetter__("ACCEPT", function(){ return "accept"; });
/**
* Static constant alias for the name of the "cancel" button.
**/
XULWindow.__defineGetter__("CANCEL", function(){ return "cancel"; });