3 import javajs.awt.Component;
4 import javajs.awt.Dimension;
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.
11 * In JSmol it is Jmol.Swing (see JsmolCore.js)
13 * There should be one and only one SwingController on a page.
14 * It is called by its class name "SwingController" directly.
19 public interface SwingController {
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.
25 * SwingController should make the changes in the underlying
26 * "Java" object directly, then send notification of the event to the manager.
29 * var component = Jmol.Swing.htDialogs[element.id];
30 * var info = component.toString();
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);
41 void click(HTMLElement element, HTMLWindowEvent event);
45 * Remove this component's HTML5 equivalent and clear references to it.
49 void dispose(Component dialog);
52 * Return the width and height of the window in d.
55 * d.width = $(window).width();
56 * d.height = $(window).height();
60 void getScreenDimensions(Dimension d);
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.
70 void register(Component c, String type);
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.
79 void setDialog(Component dialog);
82 * Convey to the HTML object that this check box's selection
85 * $("#" + chk.id).prop('checked', !!chk.selected);
89 void setSelected(Component chk);
92 * Convey to the HTML object that this combo box's selected item
95 * $("#" + cmb.id).prop('selectedIndex', cmb.selectedIndex);
99 void setSelectedIndex(Component cmb);
102 * Convey to the HTML object that this component's text
105 * $("#" + btn.id).prop('value', btn.text);
109 void setText(String text);
112 * Convey to the HTML object that this component's text
116 * $("#" + c.id).show();
118 * $("#" + c.id).hide();
122 void setVisible(Component c);
125 * Called by clicking the [x] in the corner of the dialog;
126 * send a notification back to the manager via processWindowClosing(key)
128 * var id = $("div.JDialog:has(#" + element.id + ")")[0].id
129 * var dialog = Jmol.Swing.htDialogs[id];
130 * dialog.manager.processWindowClosing(dialog.registryKey);
134 void windowClosing(HTMLElement element);