123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- <?php
- /*
- * DON'T REMOVE THE FOLLOWING LICENSE
- * INFORMATION!
- * ----------------------------------
- * Copyright by
- * Dennis Ritz
- * Author: Dennis Ritz
- * dennis.ritz@gmx.net
- * 2007-2008
- * ----------------------------------
- */
- /*
- * CLASS Label
- */
- class Label {
- private $active = false;
- private $_childs = array();
- private $_eventListeners = array();
-
- public function __construct($p_first,$p_second = null) {
- if(is_string($p_first)) {
- $this->_childs[1] = $p_first;
- if(is_subclass_of($p_second,"Icon") || is_a($p_second,"Icon")
- || is_subclass_of($p_second,"Input") || is_a($p_second,"Input")) $this->_childs[0]=$p_second;
- } else if(is_subclass_of($p_first,"Icon") || is_a($p_first,"Icon")
- || is_subclass_of($p_first,"Input") || is_a($p_first,"Input")) {
- $this->_childs[0] = $p_first;
- if(is_string($p_second)) $this->_childs[1] = $p_second;
- }
- }
-
- public function setIcon($p_icon) {
- if(is_subclass_of($p_icon,"Icon") || is_a($p_icon,"Icon")) {
- $this->_childs[0] = $p_icon;
- }
- }
-
- public function setText($p_text) {
- if(is_string($p_text)) {
- $this->_childs[1] = $p_text;
- }
- }
-
- public function active($p_on=false) {
- $this->active = $p_on;
- }
-
- public function __toString() {
- $ret = '<table class="';
- if($this->active) $ret .= 'label_active';
- else $ret.= 'label';
- $ret.= '"><tr>';
- if(array_key_exists(0,$this->_childs)) {
- $ret.= '<td class="icon">'.$this->_childs[0]->__toString().'</td>';
- }
- if(array_key_exists(1,$this->_childs)) {
- $ret.= '<td class="text" ';
- foreach($this->_eventListeners as $eventListener) {
- $ret.= $eventListener->__toString();
- }
- $ret.= '>'.$this->_childs[1].'</td>';
- }
- $ret.= '</tr></table>';
- return str_replace("\n", "", $ret);
- }
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- $this->_eventListeners[$p_listener->event()] = $p_listener;
- }
- }
- }
- /*
- * CLASS Icon
- */
- class Icon {
- private $_src = null;
- private $_eventListeners = array();
-
- public function __construct($p_src) {
- if(is_string($p_src)) {
- $this->_src = $p_src;
- }
- }
-
- public function __toString() {
- $ret = '<img ';
- foreach($this->_eventListeners as $eventListener) {
- $ret .= $eventListener->__toString();
- }
- $ret .= ' src="'.$this->_src.'">';
- return $ret;
- }
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- array_push($this->_eventListeners,$p_listener);
- }
- }
- }
- /*
- * CLASS Input
- */
- class Input {
- private $_ID = null;
- private $_name = null;
- private $_class= null;
- private $_type;
- private $_value;
- private $_eventListeners = array();
-
- public function __construct($p_id,$p_name,$p_class,$p_type,$p_value = null,$p_selected = false) {
- $this->_ID = $p_id;
- $this->_name = $p_name;
- $this->_class = $p_class;
- $this->_type = $p_type;
- $this->_value = $p_value;
- $this->_selected = $p_selected;
- }
-
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- $this->_eventListeners[$p_listener->event()] = $p_listener;
- }
- }
- public function getEventListeners() {
- return $this->_eventListeners;
- }
-
- public function __toString() {
- $ret = "<input";
- if(!empty($this->_ID))$ret.= " id='".$this->_ID."'";
- if(!empty($this->_name))$ret.= " name='".$this->_name."'";
- if(!empty($this->_class))$ret.= " class='".$this->_class."'";
- if(!empty($this->_type))$ret.= " type='".$this->_type."'";
- if(!empty($this->_value))$ret.= " value='".$this->_value."'";
- if($this->_selected && $this->_type == "radio") $ret.= " checked='checked'";
- foreach($this->_eventListeners as $event => $eventListener) {
- $ret.= ' '.$eventListener->__toString();
- }
- $ret.= ">";
- return $ret;
- }
- }
- /*
- * CLASS Tree
- */
- class Tree {
- private $_ID = null;
- private $_renderer = null;
- private $_childs = null;
- private $_eventListeners = null;
-
- public function __construct($p_id) {
- $this->_ID = $p_id;
- $this->_childs = array();
- $this->_renderer = new TreeRenderer();
- }
-
- public function getID() {
- return $this->_ID;
- }
-
- public function appendChild($p_node) {
- if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
- array_push($this->_childs, $p_node);
- }
- }
-
- public function __toString() {
- return $this->_renderer->_toString($this);
- }
-
- public function hasChildNodes() {
- if(count($this->_childs) > 0)
- return true;
- else
- return false;
- }
- public function getChildNodes() {
- return $this->_childs;
- }
-
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- array_push($this->_eventListeners,$p_listener);
- }
- }
- public function getEventListeners() {
- return $this->_eventListeners;
- }
- }
- class TreeRenderer {
- public function __construct() {}
-
- public function _toString($p_tree) {
- $ret = '<div id="'.$p_tree->getID().'" class="tree">';
- $ret.= '<div class="treeDivider"> </div>';
- if($p_tree->hasChildNodes()) {
- $childNodes = $p_tree->getChildNodes();
- foreach($childNodes as $childNode) {
- $ret.= $childNode->__toString();
- $ret.= '<div class="treeDivider"> </div>';
- }
- }
- $ret.= '</div>';
- return $ret;
- }
- }
- class TreeNode {
- private $_renderer = null;
- private $_ID = null;
- private $_value = null;
- private $_childs = null;
- private $_eventListeners = null;
- private $_contextMenu=null;
-
- public function __construct() {
- $this->_renderer = new TreeNodeRenderer();
- $this->_childs = array();
- $this->_eventListeners = array();
-
- $argsArr = func_get_args();
- if(count($argsArr)>0) {
- foreach($argsArr as $arg) {
- if(is_string($arg))
- $this->_ID = $arg;
- else
- $this->_value[] = $arg;
- }
- } else {
- $this->_value[] = new Label("no value");
- }
- }
-
- public function appendChild($p_node) {
- if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
- array_push($this->_childs, $p_node);
- }
- }
-
- public function __toString() {
- $ret = $this->_renderer->_toString($this);
- return $ret;
- }
-
- public function setRenderer($p_renderer) {
- if(is_subclass_of($p_listener,"TreeNodeRenderer") || is_a($p_listener,"TreeNodeRenderer")) {
- $this->_renderer = $p_renderer;
- }
- }
-
- public function hasChildNodes() {
- if(count($this->_childs) > 0)
- return true;
- else
- return false;
- }
-
- public function getID() {
- return $this->_ID;
- }
-
- public function getValue() {
- return $this->_value;
- }
-
- public function getChildNodes() {
- return $this->_childs;
- }
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- $this->_eventListeners[$p_listener->event()] = $p_listener;
- }
- }
- public function getEventListeners() {
- return $this->_eventListeners;
- }
-
- public function addContextMenu($p_menu) {
- if(is_subclass_of($p_menu,"ContextMenu") || is_a($p_menu,"ContextMenu")) {
- $this->_contextMenu = $p_menu;
- }
- }
-
- public function getContextMenu() {
- return $this->_contextMenu;
- }
- }
- class TreeNodeRenderer {
- public function __constructor() {}
-
- public function _toString($p_node) {
- $value = $p_node->getValue();
- $eventListeners = $p_node->getEventListeners();
- $contextMenu = $p_node->getContextMenu();
-
- if($p_node->hasChildNodes())
- $ret = '<div class="treeNode" id="';
- else
- $ret = '<div class="treeNodeLeaf" id="';
- if($p_node->getID() != null) $ret.= $p_node->getID();
- $ret.= '">';
- $ret.= '<div class="treeNodeValue">';
- $ret.='<div class="treeNodeListener"';
- $onmousedown = "true";
- $ronmousedown = "true";
- foreach($eventListeners as $event => $eventListener) {
- if($event == "onmousedown") {
- $onmousedown = $eventListener->action();
- } elseif($event == "ronmousedown") {
- $ronmousedown = $eventListener->action();
- } else {
- $ret.= ' '.$eventListener->__toString();
- }
- }
- if($contextMenu != null) {
- $ret.=" onmousedown='Tree.select(event,this);if(Mouse.checkRClick(event)) { ContextMenu.show(this,event);".$ronmousedown." } else { ".$onmousedown.";};'";
- } else {
- $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown."'";
- }
- $ret.='> </div>';
- if($p_node->hasChildNodes()) {
- $ret.= "<img class='expander' src='img/GUI/Tree/expand.png' onclick='Tree.expand(this.parentNode.parentNode);'>";
- } else {
- $ret.= "<img class='expander' src='img/GUI/Tree/transparent.png'>";
- }
- $ret.= '<a';
-
- foreach($eventListeners as $event => $eventListener) {
- if($event == "onclick") {
- $ret.= " href='javascript:' ".$eventListener->__toString();
- }elseif($event != "onmousedown" && $event != "ronmousedown"){
- $ret.= ' '.$eventListener->__toString();
- }
- }
- if($contextMenu != null) {
- $ret.=" onmousedown='Tree.select(event,this);(Mouse.checkRClick(event)) ? ".$ronmousedown." : false; return (Mouse.checkRClick(event)) ? ContextMenu.show(this,event) : ".$onmousedown.";'";
- } else {
- $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown.";'";
- }
- $ret.= '>';
- foreach($value as $valueItem) {
- $ret.= $valueItem->__toString();
- }
- $ret.='</a>';
- $ret.='</div>';
- $ret.='<div class="treeNodeSub">';
- if($p_node->hasChildNodes()) {
- $ret.= '<div class="treeDivider"> </div>';
- $childs = $p_node->getChildNodes();
- foreach($childs as $child) {
- $ret.= $child->__toString();
- $ret.= '<div class="treeDivider"> </div>';
- }
- }
- $ret.='</div>';
- $ret.='<div class="contextContainer">';
- if($contextMenu != null) {
- $ret.= $contextMenu->__toString();
- }
- $ret.= '</div>';
- $ret.= '</div>';
- return $ret;
- }
- }
- class EventListener {
- private $_event;
- private $_action;
-
- public function __construct($p_event,$p_action) {
- $this->_event = $p_event;
- $this->_action = $p_action;
- }
-
- public function __toString() {
- return $this->_event."='".$this->_action."'";
- }
-
- public function event($p_eventType=null) {
- return $this->_event;
- }
-
- public function action($p_action=null) {
- return $this->_action;
- }
- }
- class ContextMenu {
- private $_renderer = null;
- private $_childs = null;
- private $_eventListeners = null;
-
- public function __construct() {
- $this->_childs = array();
- $this->_renderer = new ContextMenuRenderer();
- }
-
- public function appendChild($p_node) {
- if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
- array_push($this->_childs, $p_node);
- }
- }
-
- public function __toString() {
- return $this->_renderer->_toString($this);
- }
-
- public function hasChildNodes() {
- if(count($this->_childs) > 0)
- return true;
- else
- return false;
- }
- public function getChildNodes() {
- return $this->_childs;
- }
-
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- array_push($this->_eventListeners,$p_listener);
- }
- }
- public function getEventListeners() {
- return $this->_eventListeners;
- }
- }
- class ContextMenuRenderer {
- public function __construct() {}
-
- public function _toString($p_menu) {
- $ret = '<div class="contextMenu">';
- $ret.= '<div class="contextMenuDivider"> </div>';
- if($p_menu->hasChildNodes()) {
- $childNodes = $p_menu->getChildNodes();
- foreach($childNodes as $childNode) {
- $ret.= $childNode->__toString();
- $ret.= '<div class="contextMenuDivider"> </div>';
- }
- }
- $ret.= '</div>';
- return $ret;
- }
- }
- class ContextMenuNode {
- private $_renderer = null;
- private $_value = null;
- private $_childs = null;
- private $_eventListeners = null;
-
- public function __construct($p_value = null) {
- $this->_renderer = new ContextMenuNodeRenderer();
- $this->_childs = array();
- $this->_eventListeners = array();
-
- if(!empty($p_value)) {
- $this->_value = $p_value;
- } else {
- $this->_value = new Label("undefined value");
- }
- }
-
- public function appendChild($p_node) {
- if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
- array_push($this->_childs, $p_node);
- }
- }
-
- public function __toString() {
- $ret = $this->_renderer->_toString($this);
- return $ret;
- }
-
- public function setRenderer($p_renderer) {
- if(is_subclass_of($p_listener,"ContextMenuNodeRenderer") || is_a($p_listener,"ContextMenuNodeRenderer")) {
- $this->_renderer = $p_renderer;
- }
- }
-
- public function hasChildNodes() {
- if(count($this->_childs) > 0)
- return true;
- else
- return false;
- }
-
- public function getValue() {
- return $this->_value;
- }
-
- public function getChildNodes() {
- return $this->_childs;
- }
- public function addEventListener($p_listener) {
- if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
- array_push($this->_eventListeners,$p_listener);
- }
- }
- public function getEventListeners() {
- return $this->_eventListeners;
- }
- }
- class ContextMenuNodeRenderer {
- public function __constructor() {}
-
- public function _toString($p_node) {
- $value = $p_node->getValue();
- $eventListeners = $p_node->getEventListeners();
-
- $ret = '<div class="contextMenuNode">';
- $ret.= '<div class="contextMenuNodeValue">';
- $ret.= '<div class="contextMenuNodeListener"';
- foreach($eventListeners as $eventListener) {
- $ret.= ' '.$eventListener->__toString();
- }
- $ret.= '> </div>';
- $ret.= '<a';
- foreach($eventListeners as $eventListener) {
- if($eventListener->event() == "onclick") {
- $ret.= " href='javascript:' onclick='".$eventListener->action()."'";
- }else{
- $ret.= ' '.$eventListener->__toString();
- }
- }
- $ret.= '>';
- $ret.= $value->__toString();
- $ret.='</a>';
- $ret.='</div>';
- $ret.='<div class="contextMenuNodeSub">';
- if($p_node->hasChildNodes()) {
- $childs = $p_node->getChildNodes();
- foreach($childs as $child) {
- $ret.= $child->__toString();
- }
- }
- $ret.='</div>';
- $ret.= '</div>';
- return $ret;
- }
- }
- ?>
|