JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / javajs / api / SwingController.java
1 package javajs.api;\r
2 \r
3 import javajs.awt.Component;\r
4 import javajs.awt.Dimension;\r
5 \r
6 /**\r
7  * SwingController is an interface that javajs.swing classes will need.\r
8  * It must be implemented as a JavaScript object PRIOR to \r
9  * any calls to create any components.\r
10  * \r
11  * In JSmol it is Jmol.Swing (see JsmolCore.js)\r
12  * \r
13  * There should be one and only one SwingController on a page. \r
14  * It is called by its class name "SwingController" directly. \r
15  * \r
16  * @author hansonr\r
17  * \r
18  */\r
19 public interface SwingController {\r
20   \r
21   /**\r
22    * Fired from clicking an element such as a button or \r
23    * check box or table entry, or from entering text in a text box.\r
24    * \r
25    * SwingController should make the changes in the underlying \r
26    * "Java" object directly, then send notification of the event to the manager.\r
27    * For instance:\r
28    * \r
29    *   var component = Jmol.Swing.htDialogs[element.id];\r
30    *   var info = component.toString();\r
31    *   \r
32    * if (info.indexOf("JCheck") >= 0)\r
33    *     component.selected = element.checked;\r
34    * var id = $("div.JDialog:has(#" + element.id + ")")[0].id\r
35    * var dialog = Jmol.Swing.htDialogs[id];\r
36    * dialog.manager.actionPerformed(component ? component.name :  dialog.registryKey + "/" + element.id);\r
37    * \r
38    * @param element\r
39    * @param event \r
40    */\r
41   void click(HTMLElement element, HTMLWindowEvent event);\r
42   \r
43 \r
44   /**\r
45    * Remove this component's HTML5 equivalent and clear references to it.\r
46    * \r
47    * @param dialog\r
48    */\r
49   void dispose(Component dialog);\r
50   \r
51   /**\r
52    * Return the width and height of the window in d.\r
53    * For example:\r
54    * \r
55    * d.width = $(window).width();\r
56    * d.height = $(window).height();\r
57    *\r
58    * @param d\r
59    */\r
60   void getScreenDimensions(Dimension d);\r
61   \r
62   /**\r
63    * Set c's id to a unique identifier\r
64    * and add it to an associative array that will\r
65    * associate that id with c.\r
66    * \r
67    * @param c\r
68    * @param type\r
69    */\r
70   void register(Component c, String type);\r
71   \r
72   /**\r
73    * The HTML for this dialog has been generated.\r
74    * Now create the HTML on the page for this dialog\r
75    * based on dialog.html and wrap it appropriately.\r
76    * \r
77    * @param dialog\r
78    */\r
79   void setDialog(Component dialog);\r
80   \r
81   /**\r
82    * Convey to the HTML object that this check box's selection\r
83    * has been changed.\r
84    * \r
85    *  $("#" + chk.id).prop('checked', !!chk.selected);\r
86    *  \r
87    * @param chk\r
88    */\r
89   void setSelected(Component chk);\r
90   \r
91   /**\r
92    * Convey to the HTML object that this combo box's selected item\r
93    * has been changed.\r
94    * \r
95    *  $("#" + cmb.id).prop('selectedIndex', cmb.selectedIndex);\r
96    *  \r
97    * @param cmb\r
98    */\r
99   void setSelectedIndex(Component cmb);\r
100   \r
101   /**\r
102    * Convey to the HTML object that this component's text\r
103    * has been changed.\r
104    * \r
105    *  $("#" + btn.id).prop('value', btn.text);\r
106    *  \r
107    * @param text\r
108    */\r
109   void setText(String text);\r
110   \r
111   /**\r
112    * Convey to the HTML object that this component's text\r
113    * has been changed.\r
114    * \r
115    *   if (c.visible)\r
116    *     $("#" + c.id).show();\r
117    *   else\r
118    *     $("#" + c.id).hide();  \r
119    *\r
120    * @param c\r
121    */  \r
122   void setVisible(Component c);\r
123   \r
124   /**\r
125    * Called by clicking the [x] in the corner of the dialog;\r
126    * send a notification back to the manager via processWindowClosing(key)\r
127    * \r
128    *   var id = $("div.JDialog:has(#" + element.id + ")")[0].id\r
129    *   var dialog = Jmol.Swing.htDialogs[id];\r
130    *   dialog.manager.processWindowClosing(dialog.registryKey);\r
131    * \r
132    * @param element\r
133    */\r
134   void windowClosing(HTMLElement element);\r
135  \r
136 }\r