GUI.class.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. public function __construct($p_id,$p_name,$p_class,$p_type,$p_value = null,$p_selected = false) {
  104. $this->_ID = $p_id;
  105. $this->_name = $p_name;
  106. $this->_class = $p_class;
  107. $this->_type = $p_type;
  108. $this->_value = $p_value;
  109. $this->_selected = $p_selected;
  110. }
  111. public function addEventListener($p_listener) {
  112. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  113. $this->_eventListeners[$p_listener->event()] = $p_listener;
  114. }
  115. }
  116. public function getEventListeners() {
  117. return $this->_eventListeners;
  118. }
  119. public function __toString() {
  120. $ret = "<input";
  121. if(!empty($this->_ID))$ret.= " id='".$this->_ID."'";
  122. if(!empty($this->_name))$ret.= " name='".$this->_name."'";
  123. if(!empty($this->_class))$ret.= " class='".$this->_class."'";
  124. if(!empty($this->_type))$ret.= " type='".$this->_type."'";
  125. if(!empty($this->_value))$ret.= " value='".$this->_value."'";
  126. if($this->_selected && $this->_type == "radio") $ret.= " checked='checked'";
  127. foreach($this->_eventListeners as $event => $eventListener) {
  128. $ret.= ' '.$eventListener->__toString();
  129. }
  130. $ret.= ">";
  131. return $ret;
  132. }
  133. }
  134. /*
  135. * CLASS Tree
  136. */
  137. class Tree {
  138. private $_ID = null;
  139. private $_renderer = null;
  140. private $_childs = null;
  141. private $_eventListeners = null;
  142. public function __construct($p_id) {
  143. $this->_ID = $p_id;
  144. $this->_childs = array();
  145. $this->_renderer = new TreeRenderer();
  146. }
  147. public function getID() {
  148. return $this->_ID;
  149. }
  150. public function appendChild($p_node) {
  151. if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
  152. array_push($this->_childs, $p_node);
  153. }
  154. }
  155. public function __toString() {
  156. return $this->_renderer->_toString($this);
  157. }
  158. public function hasChildNodes() {
  159. if(count($this->_childs) > 0)
  160. return true;
  161. else
  162. return false;
  163. }
  164. public function getChildNodes() {
  165. return $this->_childs;
  166. }
  167. public function addEventListener($p_listener) {
  168. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  169. array_push($this->_eventListeners,$p_listener);
  170. }
  171. }
  172. public function getEventListeners() {
  173. return $this->_eventListeners;
  174. }
  175. }
  176. class TreeRenderer {
  177. public function __construct() {}
  178. public function _toString($p_tree) {
  179. $ret = '<div id="'.$p_tree->getID().'" class="tree">';
  180. $ret.= '<div class="treeDivider">&nbsp;</div>';
  181. if($p_tree->hasChildNodes()) {
  182. $childNodes = $p_tree->getChildNodes();
  183. foreach($childNodes as $childNode) {
  184. $ret.= $childNode->__toString();
  185. $ret.= '<div class="treeDivider">&nbsp;</div>';
  186. }
  187. }
  188. $ret.= '</div>';
  189. return $ret;
  190. }
  191. }
  192. class TreeNode {
  193. private $_renderer = null;
  194. private $_ID = null;
  195. private $_value = null;
  196. private $_childs = null;
  197. private $_eventListeners = null;
  198. private $_contextMenu=null;
  199. public function __construct() {
  200. $this->_renderer = new TreeNodeRenderer();
  201. $this->_childs = array();
  202. $this->_eventListeners = array();
  203. $argsArr = func_get_args();
  204. if(count($argsArr)>0) {
  205. foreach($argsArr as $arg) {
  206. if(is_string($arg))
  207. $this->_ID = $arg;
  208. else
  209. $this->_value[] = $arg;
  210. }
  211. } else {
  212. $this->_value[] = new Label("no value");
  213. }
  214. }
  215. public function appendChild($p_node) {
  216. if(is_subclass_of($p_node,"TreeNode") || is_a($p_node,"TreeNode")) {
  217. array_push($this->_childs, $p_node);
  218. }
  219. }
  220. public function __toString() {
  221. $ret = $this->_renderer->_toString($this);
  222. return $ret;
  223. }
  224. public function setRenderer($p_renderer) {
  225. if(is_subclass_of($p_listener,"TreeNodeRenderer") || is_a($p_listener,"TreeNodeRenderer")) {
  226. $this->_renderer = $p_renderer;
  227. }
  228. }
  229. public function hasChildNodes() {
  230. if(count($this->_childs) > 0)
  231. return true;
  232. else
  233. return false;
  234. }
  235. public function getID() {
  236. return $this->_ID;
  237. }
  238. public function getValue() {
  239. return $this->_value;
  240. }
  241. public function getChildNodes() {
  242. return $this->_childs;
  243. }
  244. public function addEventListener($p_listener) {
  245. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  246. $this->_eventListeners[$p_listener->event()] = $p_listener;
  247. }
  248. }
  249. public function getEventListeners() {
  250. return $this->_eventListeners;
  251. }
  252. public function addContextMenu($p_menu) {
  253. if(is_subclass_of($p_menu,"ContextMenu") || is_a($p_menu,"ContextMenu")) {
  254. $this->_contextMenu = $p_menu;
  255. }
  256. }
  257. public function getContextMenu() {
  258. return $this->_contextMenu;
  259. }
  260. }
  261. class TreeNodeRenderer {
  262. public function __constructor() {}
  263. public function _toString($p_node) {
  264. $value = $p_node->getValue();
  265. $eventListeners = $p_node->getEventListeners();
  266. $contextMenu = $p_node->getContextMenu();
  267. if($p_node->hasChildNodes())
  268. $ret = '<div class="treeNode" id="';
  269. else
  270. $ret = '<div class="treeNodeLeaf" id="';
  271. if($p_node->getID() != null) $ret.= $p_node->getID();
  272. $ret.= '">';
  273. $ret.= '<div class="treeNodeValue">';
  274. $ret.='<div class="treeNodeListener"';
  275. $onmousedown = "true";
  276. $ronmousedown = "true";
  277. foreach($eventListeners as $event => $eventListener) {
  278. if($event == "onmousedown") {
  279. $onmousedown = $eventListener->action();
  280. } elseif($event == "ronmousedown") {
  281. $ronmousedown = $eventListener->action();
  282. } else {
  283. $ret.= ' '.$eventListener->__toString();
  284. }
  285. }
  286. if($contextMenu != null) {
  287. $ret.=" onmousedown='Tree.select(event,this);if(Mouse.checkRClick(event)) { ContextMenu.show(this,event);".$ronmousedown." } else { ".$onmousedown.";};'";
  288. } else {
  289. $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown."'";
  290. }
  291. $ret.='>&nbsp;</div>';
  292. if($p_node->hasChildNodes()) {
  293. $ret.= "<img class='expander' src='img/GUI/Tree/expand.png' onclick='Tree.expand(this.parentNode.parentNode);'>";
  294. } else {
  295. $ret.= "<img class='expander' src='img/GUI/Tree/transparent.png'>";
  296. }
  297. $ret.= '<a';
  298. foreach($eventListeners as $event => $eventListener) {
  299. if($event == "onclick") {
  300. $ret.= " href='javascript:' ".$eventListener->__toString();
  301. }elseif($event != "onmousedown" && $event != "ronmousedown"){
  302. $ret.= ' '.$eventListener->__toString();
  303. }
  304. }
  305. if($contextMenu != null) {
  306. $ret.=" onmousedown='Tree.select(event,this);(Mouse.checkRClick(event)) ? ".$ronmousedown." : false; return (Mouse.checkRClick(event)) ? ContextMenu.show(this,event) : ".$onmousedown.";'";
  307. } else {
  308. $ret.=" onmousedown='Tree.select(event,this);return ".$onmousedown.";'";
  309. }
  310. $ret.= '>';
  311. foreach($value as $valueItem) {
  312. $ret.= $valueItem->__toString();
  313. }
  314. $ret.='</a>';
  315. $ret.='</div>';
  316. $ret.='<div class="treeNodeSub">';
  317. if($p_node->hasChildNodes()) {
  318. $ret.= '<div class="treeDivider">&nbsp;</div>';
  319. $childs = $p_node->getChildNodes();
  320. foreach($childs as $child) {
  321. $ret.= $child->__toString();
  322. $ret.= '<div class="treeDivider">&nbsp;</div>';
  323. }
  324. }
  325. $ret.='</div>';
  326. $ret.='<div class="contextContainer">';
  327. if($contextMenu != null) {
  328. $ret.= $contextMenu->__toString();
  329. }
  330. $ret.= '</div>';
  331. $ret.= '</div>';
  332. return $ret;
  333. }
  334. }
  335. class EventListener {
  336. private $_event;
  337. private $_action;
  338. public function __construct($p_event,$p_action) {
  339. $this->_event = $p_event;
  340. $this->_action = $p_action;
  341. }
  342. public function __toString() {
  343. return $this->_event."='".$this->_action."'";
  344. }
  345. public function event($p_eventType=null) {
  346. return $this->_event;
  347. }
  348. public function action($p_action=null) {
  349. return $this->_action;
  350. }
  351. }
  352. class ContextMenu {
  353. private $_renderer = null;
  354. private $_childs = null;
  355. private $_eventListeners = null;
  356. public function __construct() {
  357. $this->_childs = array();
  358. $this->_renderer = new ContextMenuRenderer();
  359. }
  360. public function appendChild($p_node) {
  361. if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
  362. array_push($this->_childs, $p_node);
  363. }
  364. }
  365. public function __toString() {
  366. return $this->_renderer->_toString($this);
  367. }
  368. public function hasChildNodes() {
  369. if(count($this->_childs) > 0)
  370. return true;
  371. else
  372. return false;
  373. }
  374. public function getChildNodes() {
  375. return $this->_childs;
  376. }
  377. public function addEventListener($p_listener) {
  378. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  379. array_push($this->_eventListeners,$p_listener);
  380. }
  381. }
  382. public function getEventListeners() {
  383. return $this->_eventListeners;
  384. }
  385. }
  386. class ContextMenuRenderer {
  387. public function __construct() {}
  388. public function _toString($p_menu) {
  389. $ret = '<div class="contextMenu">';
  390. $ret.= '<div class="contextMenuDivider">&nbsp;</div>';
  391. if($p_menu->hasChildNodes()) {
  392. $childNodes = $p_menu->getChildNodes();
  393. foreach($childNodes as $childNode) {
  394. $ret.= $childNode->__toString();
  395. $ret.= '<div class="contextMenuDivider">&nbsp;</div>';
  396. }
  397. }
  398. $ret.= '</div>';
  399. return $ret;
  400. }
  401. }
  402. class ContextMenuNode {
  403. private $_renderer = null;
  404. private $_value = null;
  405. private $_childs = null;
  406. private $_eventListeners = null;
  407. public function __construct($p_value = null) {
  408. $this->_renderer = new ContextMenuNodeRenderer();
  409. $this->_childs = array();
  410. $this->_eventListeners = array();
  411. if(!empty($p_value)) {
  412. $this->_value = $p_value;
  413. } else {
  414. $this->_value = new Label("undefined value");
  415. }
  416. }
  417. public function appendChild($p_node) {
  418. if(is_subclass_of($p_node,"ContextMenuNode") || is_a($p_node,"ContextMenuNode")) {
  419. array_push($this->_childs, $p_node);
  420. }
  421. }
  422. public function __toString() {
  423. $ret = $this->_renderer->_toString($this);
  424. return $ret;
  425. }
  426. public function setRenderer($p_renderer) {
  427. if(is_subclass_of($p_listener,"ContextMenuNodeRenderer") || is_a($p_listener,"ContextMenuNodeRenderer")) {
  428. $this->_renderer = $p_renderer;
  429. }
  430. }
  431. public function hasChildNodes() {
  432. if(count($this->_childs) > 0)
  433. return true;
  434. else
  435. return false;
  436. }
  437. public function getValue() {
  438. return $this->_value;
  439. }
  440. public function getChildNodes() {
  441. return $this->_childs;
  442. }
  443. public function addEventListener($p_listener) {
  444. if(is_subclass_of($p_listener,"EventListener") || is_a($p_listener,"EventListener")) {
  445. array_push($this->_eventListeners,$p_listener);
  446. }
  447. }
  448. public function getEventListeners() {
  449. return $this->_eventListeners;
  450. }
  451. }
  452. class ContextMenuNodeRenderer {
  453. public function __constructor() {}
  454. public function _toString($p_node) {
  455. $value = $p_node->getValue();
  456. $eventListeners = $p_node->getEventListeners();
  457. $ret = '<div class="contextMenuNode">';
  458. $ret.= '<div class="contextMenuNodeValue">';
  459. $ret.= '<div class="contextMenuNodeListener"';
  460. foreach($eventListeners as $eventListener) {
  461. $ret.= ' '.$eventListener->__toString();
  462. }
  463. $ret.= '>&nbsp;</div>';
  464. $ret.= '<a';
  465. foreach($eventListeners as $eventListener) {
  466. if($eventListener->event() == "onclick") {
  467. $ret.= " href='javascript:' onclick='".$eventListener->action()."'";
  468. }else{
  469. $ret.= ' '.$eventListener->__toString();
  470. }
  471. }
  472. $ret.= '>';
  473. $ret.= $value->__toString();
  474. $ret.='</a>';
  475. $ret.='</div>';
  476. $ret.='<div class="contextMenuNodeSub">';
  477. if($p_node->hasChildNodes()) {
  478. $childs = $p_node->getChildNodes();
  479. foreach($childs as $child) {
  480. $ret.= $child->__toString();
  481. }
  482. }
  483. $ret.='</div>';
  484. $ret.= '</div>';
  485. return $ret;
  486. }
  487. }
  488. ?>