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