GUI.class.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <?php
  2. /*
  3. * DON'T REMOVE THE FOLLOWING LICENSE
  4. * INFORMATION!
  5. * ----------------------------------
  6. * Copyright by
  7. * Dennis Ritz
  8. * Author: Dennis Ritz
  9. * dennis.ritz@gmx.net
  10. * 2007-2008
  11. * ----------------------------------
  12. */
  13. /*
  14. * CLASS Label
  15. */
  16. class Label {
  17. private $active = false;
  18. private $_childs = array();
  19. private $_eventListeners = array();
  20. public function __construct($p_first,$p_second = null) {
  21. if(is_string($p_first)) {
  22. $this->_childs[1] = $p_first;
  23. if(is_subclass_of($p_second,"Icon") || is_a($p_second,"Icon")
  24. || is_subclass_of($p_second,"Input") || is_a($p_second,"Input")) $this->_childs[0]=$p_second;
  25. } else if(is_subclass_of($p_first,"Icon") || is_a($p_first,"Icon")
  26. || is_subclass_of($p_first,"Input") || is_a($p_first,"Input")) {
  27. $this->_childs[0] = $p_first;
  28. if(is_string($p_second)) $this->_childs[1] = $p_second;
  29. }
  30. }
  31. public function setIcon($p_icon) {
  32. if(is_subclass_of($p_icon,"Icon") || is_a($p_icon,"Icon")) {
  33. $this->_childs[0] = $p_icon;
  34. }
  35. }
  36. public function setText($p_text) {
  37. if(is_string($p_text)) {
  38. $this->_childs[1] = $p_text;
  39. }
  40. }
  41. public function active($p_on=false) {
  42. $this->active = $p_on;
  43. }
  44. public function __toString() {
  45. $ret = '<table class="';
  46. if($this->active) $ret .= 'label_active';
  47. else $ret.= 'label';
  48. $ret.= '"><tr>';
  49. if(array_key_exists(0,$this->_childs)) {
  50. $ret.= '<td class="icon">'.$this->_childs[0]->__toString().'</td>';
  51. }
  52. if(array_key_exists(1,$this->_childs)) {
  53. $ret.= '<td class="text" ';
  54. foreach($this->_eventListeners as $eventListener) {
  55. $ret.= $eventListener->__toString();
  56. }
  57. $ret.= '>'.$this->_childs[1].'</td>';
  58. }
  59. $ret.= '</tr></table>';
  60. return str_replace("\n", "", $ret);
  61. }
  62. public function addEventListener($p_listener) {
  63. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  64. $this->_eventListeners[$p_listener->event()] = $p_listener;
  65. }
  66. }
  67. }
  68. /*
  69. * CLASS Icon
  70. */
  71. class Icon {
  72. private $_src = null;
  73. private $_eventListeners = array();
  74. public function __construct($p_src) {
  75. if(is_string($p_src)) {
  76. $this->_src = $p_src;
  77. }
  78. }
  79. public function __toString() {
  80. $ret = '<img ';
  81. foreach($this->_eventListeners as $eventListener) {
  82. $ret .= $eventListener->__toString();
  83. }
  84. $ret .= ' src="'.$this->_src.'">';
  85. return $ret;
  86. }
  87. public function addEventListener($p_listener) {
  88. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  89. array_push($this->_eventListeners,$p_listener);
  90. }
  91. }
  92. }
  93. /*
  94. * CLASS Input
  95. */
  96. class Input {
  97. private $_ID = null;
  98. private $_name = null;
  99. private $_class= null;
  100. private $_type;
  101. private $_value;
  102. private $_eventListeners = array();
  103. private $_selected = false;
  104. public function __construct($p_id,$p_name,$p_class,$p_type,$p_value = null,$p_selected = false) {
  105. $this->_ID = $p_id;
  106. $this->_name = $p_name;
  107. $this->_class = $p_class;
  108. $this->_type = $p_type;
  109. $this->_value = $p_value;
  110. $this->_selected = $p_selected;
  111. }
  112. public function addEventListener($p_listener) {
  113. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  114. $this->_eventListeners[$p_listener->event()] = $p_listener;
  115. }
  116. }
  117. public function getEventListeners() {
  118. return $this->_eventListeners;
  119. }
  120. public function __toString() {
  121. $ret = "<input";
  122. if(!empty($this->_ID))$ret.= " id='".$this->_ID."'";
  123. if(!empty($this->_name))$ret.= " name='".$this->_name."'";
  124. if(!empty($this->_class))$ret.= " class='".$this->_class."'";
  125. if(!empty($this->_type))$ret.= " type='".$this->_type."'";
  126. if(!empty($this->_value))$ret.= " value='".$this->_value."'";
  127. if($this->_selected && $this->_type == "radio") $ret.= " checked='checked'";
  128. foreach($this->_eventListeners as $event => $eventListener) {
  129. $ret.= ' '.$eventListener->__toString();
  130. }
  131. $ret.= ">";
  132. return $ret;
  133. }
  134. }
  135. /*
  136. * CLASS Tree
  137. */
  138. class Tree {
  139. private $_ID = null;
  140. private $_renderer = null;
  141. private $_childs = null;
  142. private $_eventListeners = null;
  143. public function __construct($p_id) {
  144. $this->_ID = $p_id;
  145. $this->_childs = array();
  146. $this->_renderer = new TreeRenderer();
  147. }
  148. public function getID() {
  149. return $this->_ID;
  150. }
  151. public function appendChild($p_node) {
  152. if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
  153. array_push($this->_childs, $p_node);
  154. }
  155. }
  156. public function __toString() {
  157. return $this->_renderer->_toString($this);
  158. }
  159. public function hasChildNodes() {
  160. if(count($this->_childs) > 0)
  161. return true;
  162. else
  163. return false;
  164. }
  165. public function getChildNodes() {
  166. return $this->_childs;
  167. }
  168. public function addEventListener($p_listener) {
  169. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  170. array_push($this->_eventListeners,$p_listener);
  171. }
  172. }
  173. public function getEventListeners() {
  174. return $this->_eventListeners;
  175. }
  176. }
  177. class TreeRenderer {
  178. public function __construct() {}
  179. public function _toString($p_tree) {
  180. $ret = '<div id="'.$p_tree->getID().'" class="tree">';
  181. $ret.= '<div class="treeDivider">&nbsp;</div>';
  182. if($p_tree->hasChildNodes()) {
  183. $childNodes = $p_tree->getChildNodes();
  184. foreach($childNodes as $childNode) {
  185. $ret.= $childNode->__toString();
  186. $ret.= '<div class="treeDivider">&nbsp;</div>';
  187. }
  188. }
  189. $ret.= '</div>';
  190. return $ret;
  191. }
  192. }
  193. class TreeNode {
  194. private $_renderer = null;
  195. private $_ID = null;
  196. private $_value = null;
  197. private $_childs = null;
  198. private $_eventListeners = null;
  199. private $_contextMenu=null;
  200. public function __construct() {
  201. $this->_renderer = new TreeNodeRenderer();
  202. $this->_childs = array();
  203. $this->_eventListeners = array();
  204. $argsArr = func_get_args();
  205. if(count($argsArr)>0) {
  206. foreach($argsArr as $arg) {
  207. if(is_string($arg))
  208. $this->_ID = $arg;
  209. else
  210. $this->_value[] = $arg;
  211. }
  212. } else {
  213. $this->_value[] = new Label("no value");
  214. }
  215. }
  216. public function appendChild($p_node) {
  217. if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
  218. array_push($this->_childs, $p_node);
  219. }
  220. }
  221. public function __toString() {
  222. $ret = $this->_renderer->_toString($this);
  223. return $ret;
  224. }
  225. public function setRenderer($p_renderer) {
  226. if(is_subclass_of($p_renderer,"TreeNodeRenderer") || is_a($p_renderer,"TreeNodeRenderer")) {
  227. $this->_renderer = $p_renderer;
  228. }
  229. }
  230. public function hasChildNodes() {
  231. if(count($this->_childs) > 0)
  232. return true;
  233. else
  234. return false;
  235. }
  236. public function getID() {
  237. return $this->_ID;
  238. }
  239. public function getValue() {
  240. return $this->_value;
  241. }
  242. public function getChildNodes() {
  243. return $this->_childs;
  244. }
  245. public function addEventListener($p_listener) {
  246. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  247. $this->_eventListeners[$p_listener->event()] = $p_listener;
  248. }
  249. }
  250. public function getEventListeners() {
  251. return $this->_eventListeners;
  252. }
  253. public function addContextMenu($p_menu) {
  254. if(is_subclass_of($p_menu,"ContextMenu") || is_a($p_menu,"ContextMenu")) {
  255. $this->_contextMenu = $p_menu;
  256. }
  257. }
  258. public function getContextMenu() {
  259. return $this->_contextMenu;
  260. }
  261. }
  262. class TreeNodeRenderer {
  263. public function __constructor() {}
  264. public function _toString($p_node) {
  265. $value = $p_node->getValue();
  266. $eventListeners = $p_node->getEventListeners();
  267. $contextMenu = $p_node->getContextMenu();
  268. if($p_node->hasChildNodes())
  269. $ret = '<div class="treeNode" id="';
  270. else
  271. $ret = '<div class="treeNodeLeaf" id="';
  272. if($p_node->getID() != null) $ret.= $p_node->getID();
  273. $ret.= '">';
  274. $ret.= '<div class="treeNodeValue">';
  275. $ret.='<div class="treeNodeListener"';
  276. $onmousedown = "true";
  277. $ronmousedown = "true";
  278. foreach($eventListeners as $event => $eventListener) {
  279. if($event == "onmousedown") {
  280. $onmousedown = $eventListener->action();
  281. } elseif($event == "ronmousedown") {
  282. $ronmousedown = $eventListener->action();
  283. } else {
  284. $ret.= ' '.$eventListener->__toString();
  285. }
  286. }
  287. if($contextMenu != null) {
  288. $ret.=" onmousedown='Tree.select(event,this);(Mouse.checkRClick(event)) ? ".$ronmousedown." : false; return (Mouse.checkRClick(event)) ? ContextMenu.show(this,event) : ".$onmousedown.";'";
  289. } else {
  290. $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown."'";
  291. }
  292. $ret.='>&nbsp;</div>';
  293. if($p_node->hasChildNodes()) {
  294. $ret.= "<img class='expander' src='img/GUI/Tree/expand.png' onclick='Tree.expand(this.parentNode.parentNode);'>";
  295. } else {
  296. $ret.= "<img class='expander' src='img/GUI/Tree/transparent.png'>";
  297. }
  298. $ret.= '<a';
  299. foreach($eventListeners as $event => $eventListener) {
  300. if($event == "onclick") {
  301. $ret.= " href='javascript:' ".$eventListener->__toString();
  302. }elseif($event != "onmousedown" && $event != "ronmousedown"){
  303. $ret.= ' '.$eventListener->__toString();
  304. }
  305. }
  306. if($contextMenu != null) {
  307. $ret.=" onmousedown='Tree.select(event,this);(Mouse.checkRClick(event)) ? ".$ronmousedown." : false; return (Mouse.checkRClick(event)) ? ContextMenu.show(this,event) : ".$onmousedown.";'";
  308. } else {
  309. $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown.";'";
  310. }
  311. $ret.= '>';
  312. foreach($value as $valueItem) {
  313. $ret.= $valueItem->__toString();
  314. }
  315. $ret.='</a>';
  316. $ret.='</div>';
  317. $ret.='<div class="treeNodeSub">';
  318. if($p_node->hasChildNodes()) {
  319. $ret.= '<div class="treeDivider">&nbsp;</div>';
  320. $childs = $p_node->getChildNodes();
  321. foreach($childs as $child) {
  322. $ret.= $child->__toString();
  323. $ret.= '<div class="treeDivider">&nbsp;</div>';
  324. }
  325. }
  326. $ret.='</div>';
  327. $ret.='<div class="contextContainer">';
  328. if($contextMenu != null) {
  329. $ret.= $contextMenu->__toString();
  330. }
  331. $ret.= '</div>';
  332. $ret.= '</div>';
  333. return $ret;
  334. }
  335. }
  336. class EventListener {
  337. private $_event;
  338. private $_action;
  339. public function __construct($p_event,$p_action) {
  340. $this->_event = $p_event;
  341. $this->_action = $p_action;
  342. }
  343. public function __toString() {
  344. return $this->_event."='".$this->_action."'";
  345. }
  346. public function event($p_eventType=null) {
  347. return $this->_event;
  348. }
  349. public function action($p_action=null) {
  350. return $this->_action;
  351. }
  352. }
  353. class ContextMenu {
  354. private $_renderer = null;
  355. private $_childs = null;
  356. private $_eventListeners = null;
  357. public function __construct() {
  358. $this->_childs = array();
  359. $this->_renderer = new ContextMenuRenderer();
  360. }
  361. public function appendChild($p_node) {
  362. if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
  363. array_push($this->_childs, $p_node);
  364. }
  365. }
  366. public function __toString() {
  367. return $this->_renderer->_toString($this);
  368. }
  369. public function hasChildNodes() {
  370. if(count($this->_childs) > 0)
  371. return true;
  372. else
  373. return false;
  374. }
  375. public function getChildNodes() {
  376. return $this->_childs;
  377. }
  378. public function addEventListener($p_listener) {
  379. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  380. array_push($this->_eventListeners,$p_listener);
  381. }
  382. }
  383. public function getEventListeners() {
  384. return $this->_eventListeners;
  385. }
  386. }
  387. class ContextMenuRenderer {
  388. public function __construct() {}
  389. public function _toString($p_menu) {
  390. $ret = '<div class="contextMenu">';
  391. $ret.= '<div class="contextMenuDivider">&nbsp;</div>';
  392. if($p_menu->hasChildNodes()) {
  393. $childNodes = $p_menu->getChildNodes();
  394. foreach($childNodes as $childNode) {
  395. $ret.= $childNode->__toString();
  396. $ret.= '<div class="contextMenuDivider">&nbsp;</div>';
  397. }
  398. }
  399. $ret.= '</div>';
  400. return $ret;
  401. }
  402. }
  403. class ContextMenuNode {
  404. private $_renderer = null;
  405. private $_value = null;
  406. private $_childs = null;
  407. private $_eventListeners = null;
  408. public function __construct($p_value = null) {
  409. $this->_renderer = new ContextMenuNodeRenderer();
  410. $this->_childs = array();
  411. $this->_eventListeners = array();
  412. if(!empty($p_value)) {
  413. $this->_value = $p_value;
  414. } else {
  415. $this->_value = new Label("undefined value");
  416. }
  417. }
  418. public function appendChild($p_node) {
  419. if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
  420. array_push($this->_childs, $p_node);
  421. }
  422. }
  423. public function __toString() {
  424. $ret = $this->_renderer->_toString($this);
  425. return $ret;
  426. }
  427. public function setRenderer($p_renderer) {
  428. if(is_subclass_of($p_renderer,"ContextMenuNodeRenderer") || is_a($p_renderer,"ContextMenuNodeRenderer")) {
  429. $this->_renderer = $p_renderer;
  430. }
  431. }
  432. public function hasChildNodes() {
  433. if(count($this->_childs) > 0)
  434. return true;
  435. else
  436. return false;
  437. }
  438. public function getValue() {
  439. return $this->_value;
  440. }
  441. public function getChildNodes() {
  442. return $this->_childs;
  443. }
  444. public function addEventListener($p_listener) {
  445. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  446. array_push($this->_eventListeners,$p_listener);
  447. }
  448. }
  449. public function getEventListeners() {
  450. return $this->_eventListeners;
  451. }
  452. }
  453. class ContextMenuNodeRenderer {
  454. public function __constructor() {}
  455. public function _toString($p_node) {
  456. $value = $p_node->getValue();
  457. $eventListeners = $p_node->getEventListeners();
  458. $ret = '<div class="contextMenuNode">';
  459. $ret.= '<div class="contextMenuNodeValue">';
  460. $ret.= '<div class="contextMenuNodeListener"';
  461. foreach($eventListeners as $eventListener) {
  462. $ret.= ' '.$eventListener->__toString();
  463. }
  464. $ret.= '>&nbsp;</div>';
  465. $ret.= '<a';
  466. foreach($eventListeners as $eventListener) {
  467. if($eventListener->event() == "onclick") {
  468. $ret.= " href='javascript:' onclick='".$eventListener->action()."'";
  469. }else{
  470. $ret.= ' '.$eventListener->__toString();
  471. }
  472. }
  473. $ret.= '>';
  474. $ret.= $value->__toString();
  475. $ret.='</a>';
  476. $ret.='</div>';
  477. $ret.='<div class="contextMenuNodeSub">';
  478. if($p_node->hasChildNodes()) {
  479. $childs = $p_node->getChildNodes();
  480. foreach($childs as $child) {
  481. $ret.= $child->__toString();
  482. }
  483. }
  484. $ret.='</div>';
  485. $ret.= '</div>';
  486. return $ret;
  487. }
  488. }
  489. ?>