- /**
- * Classe com.wikimb.TreeDoc
- *
- * Auteur: SuperDevy ( www.tibulle.com )
- * Version: alpha 1.0
- * Date: 29 mai 2005
- * Flash MX 2004 pro requis
- *
- * Classe applicative crée pour le wiki media-box.
- * Trois composants doivent être déposés : Tree, TextInput, CheckBox.
- *
- **/
-
- import mx.controls.Tree
- import mx.controls.TextInput
- import mx.controls.CheckBox
-
- class com.wikimb.TreeDoc
- {
- public var datasXML:XML;
- public var searchXML:XML;
-
- public var tree:Tree;
- public var input:TextInput;
- public var checkbox:CheckBox;
-
- public var onSelect:Function;
-
-
- //---o Constructeur
-
- public function TreeDoc (tree:Tree, input:TextInput, checkbox:CheckBox)
- {
- //---< Enregistrement des composants
- this.tree = tree;
- this.input = input;
- this.checkbox = checkbox;
-
- //---< Accessibilité
- input.tabIndex = 0;
- checkbox.tabIndex = 1;
- tree.tabIndex = 2;
-
- input._accProps.name = "Recherche";
-
- //---< Alignement
- resize();
- Stage.align = "TL";
- Stage.scaleMode = "noScale";
- }
-
-
- //---o Initialisation une fois le chargement effectué
-
- public function initialize (Void) :Void
- {
- trace("Initialisation");
- var local = this;
-
- //---< Tree (Liste)
- tree.dataProvider = datasXML.cloneNode(true);
- var event_tree:Object = new Object();
- event_tree.change = function () {
- var item:XMLNode = local.tree.selectedNode;
- if (!item.hasChildNodes()) {
- local.onSelect(item);
- }
- }
- tree.addEventListener("change", event_tree);
-
- //---< TextInbox (Recherche)
- var event_input:Object = new Object();
- event_input.enter = function () {
- local.search(local.input.text);
- }
- event_input.change = function () {
- if (local.checkbox.selected) {
- local.search(local.input.text);
- }
- }
- input.addEventListener("enter", event_input);
- input.addEventListener("change", event_input);
-
- //---< Stage (Redimentionnement)
- var event_stage:Object = new Object();
- event_stage.onResize = function () {
- local.resize();
- }
- Stage.addListener(event_stage);
- }
-
-
- //---o Chargement des données XML
-
- function load (url:String) :Void
- {
- var local = this;
- datasXML = new XML();
- datasXML.ignoreWhite = true;
- datasXML.onLoad = function() {
- trace("Chargement terminé");
- local.initialize();
- }
- datasXML.load(url);
- }
-
-
- //---o Recherche (initialisation)
-
- public function search (text:String) :Void
- {
- trace("Recherche pour le mot " + text);
- var t = getTimer();
- var local = this;
-
- if (text!="") {
- local.searchXML = new XML();
-
- var addNode = function (child) {
- local.searchXML.appendChild(child.cloneNode(false));
- };
- rec_search(datasXML, text, addNode);
- tree.dataProvider = local.searchXML;
- } else {
- local.searchXML = null;
- tree.dataProvider = local.datasXML.cloneNode(true);
- }
-
- trace("Temps de la recherche " + (getTimer()-t) + " ms");
- }
-
-
- //---o Recherche (exploration récursive)
-
- private function rec_search (node:XMLNode, text:String, action:Function) :Void
- {
- var childs = node.childNodes;
- var i:Number = 0;
- while (childs[i]!=undefined) {
- if (childs[i].hasChildNodes()) {
- rec_search(childs[i], text, action);
- } else {
- if (containText(childs[i].attributes.label, text)) {
- action(childs[i]);
- }
- }
- i++;
- }
- }
-
-
- //---o Regarde si un mot est présent dans une phrase.
-
- public function containText (sentence:String, word:String) :Boolean
- {
- return (sentence.toLowerCase().split(word.toLowerCase(), 2).length > 1);
- }
-
-
- //---o Redimentionnement pour coller aux bords
-
- public function resize (Void) :Void
- {
- trace("Redimentionnement");
- this.tree.setSize(Stage.width, Stage.height-24);
- this.input.setSize(Stage.width-22, 22);
- }
-
- }
-
- // ---> by SuperDevy <---
/**
* Classe com.wikimb.TreeDoc
*
* Auteur: SuperDevy ( www.tibulle.com )
* Version: alpha 1.0
* Date: 29 mai 2005
* Flash MX 2004 pro requis
*
* Classe applicative crée pour le wiki media-box.
* Trois composants doivent être déposés : Tree, TextInput, CheckBox.
*
**/
import mx.controls.Tree
import mx.controls.TextInput
import mx.controls.CheckBox
class com.wikimb.TreeDoc
{
public var datasXML:XML;
public var searchXML:XML;
public var tree:Tree;
public var input:TextInput;
public var checkbox:CheckBox;
public var onSelect:Function;
//---o Constructeur
public function TreeDoc (tree:Tree, input:TextInput, checkbox:CheckBox)
{
//---< Enregistrement des composants
this.tree = tree;
this.input = input;
this.checkbox = checkbox;
//---< Accessibilité
input.tabIndex = 0;
checkbox.tabIndex = 1;
tree.tabIndex = 2;
input._accProps.name = "Recherche";
//---< Alignement
resize();
Stage.align = "TL";
Stage.scaleMode = "noScale";
}
//---o Initialisation une fois le chargement effectué
public function initialize (Void) :Void
{
trace("Initialisation");
var local = this;
//---< Tree (Liste)
tree.dataProvider = datasXML.cloneNode(true);
var event_tree:Object = new Object();
event_tree.change = function () {
var item:XMLNode = local.tree.selectedNode;
if (!item.hasChildNodes()) {
local.onSelect(item);
}
}
tree.addEventListener("change", event_tree);
//---< TextInbox (Recherche)
var event_input:Object = new Object();
event_input.enter = function () {
local.search(local.input.text);
}
event_input.change = function () {
if (local.checkbox.selected) {
local.search(local.input.text);
}
}
input.addEventListener("enter", event_input);
input.addEventListener("change", event_input);
//---< Stage (Redimentionnement)
var event_stage:Object = new Object();
event_stage.onResize = function () {
local.resize();
}
Stage.addListener(event_stage);
}
//---o Chargement des données XML
function load (url:String) :Void
{
var local = this;
datasXML = new XML();
datasXML.ignoreWhite = true;
datasXML.onLoad = function() {
trace("Chargement terminé");
local.initialize();
}
datasXML.load(url);
}
//---o Recherche (initialisation)
public function search (text:String) :Void
{
trace("Recherche pour le mot " + text);
var t = getTimer();
var local = this;
if (text!="") {
local.searchXML = new XML();
var addNode = function (child) {
local.searchXML.appendChild(child.cloneNode(false));
};
rec_search(datasXML, text, addNode);
tree.dataProvider = local.searchXML;
} else {
local.searchXML = null;
tree.dataProvider = local.datasXML.cloneNode(true);
}
trace("Temps de la recherche " + (getTimer()-t) + " ms");
}
//---o Recherche (exploration récursive)
private function rec_search (node:XMLNode, text:String, action:Function) :Void
{
var childs = node.childNodes;
var i:Number = 0;
while (childs[i]!=undefined) {
if (childs[i].hasChildNodes()) {
rec_search(childs[i], text, action);
} else {
if (containText(childs[i].attributes.label, text)) {
action(childs[i]);
}
}
i++;
}
}
//---o Regarde si un mot est présent dans une phrase.
public function containText (sentence:String, word:String) :Boolean
{
return (sentence.toLowerCase().split(word.toLowerCase(), 2).length > 1);
}
//---o Redimentionnement pour coller aux bords
public function resize (Void) :Void
{
trace("Redimentionnement");
this.tree.setSize(Stage.width, Stage.height-24);
this.input.setSize(Stage.width-22, 22);
}
}
// ---> by SuperDevy <---