Public Methods | |
| SaMethodDialog (SaMethodDescription desc, Object user, String funcName) | |
| Constructor. More... | |
| void | actionPerformed (ActionEvent e) |
| Implementation of ActionListener. More... | |
The SaMethodDescription determines hich method is to be called. The result of the operation (always a string) is passed to the user by calling its member function 'funcName' with the string as argument. 'funcName' must also have a second parameter: a String for the 'type' of the result.
|
||||||||||||||||
|
00037 {
00038 super(new JFrame(), "SaMethodDialog", true);
00039 _desc = desc;
00040 _user = user;
00041 _funcName = funcName;
00042 _mediator = new HxMediatorPeer();
00043 _nArgs = _desc.nArgs();
00044 _argObjChoice = new SaObjectChoice[_nArgs];
00045
00046 Container contentPane = getContentPane();
00047
00048 GridBagLayout gridbag = new GridBagLayout();
00049 GridBagConstraints c = new GridBagConstraints();
00050 contentPane.setLayout(gridbag);
00051
00052 c.fill = GridBagConstraints.HORIZONTAL;
00053 c.weightx = 1.0;
00054 c.weighty = 1.0;
00055 c.insets = new Insets(3, 3, 3, 3);
00056
00057 if (_desc.returnType().compareTo("void") != 0) {
00058 c.gridwidth = 1; // next row
00059 JLabel label1 = new JLabel("Name result (" + _desc.returnType() + ")");
00060 gridbag.setConstraints(label1, c);
00061 contentPane.add(label1);
00062
00063 c.gridwidth = GridBagConstraints.REMAINDER; // end of row
00064 _objChoice1 = new SaObjectChoice(_desc.returnType());
00065 _objChoice1.setSelectedItem("");
00066 gridbag.setConstraints(_objChoice1, c);
00067 contentPane.add(_objChoice1);
00068
00069 c.gridwidth = GridBagConstraints.REMAINDER; // next row
00070 JLabel l = new JLabel("=");
00071 gridbag.setConstraints(l, c);
00072 contentPane.add(l);
00073 }
00074
00075 if (_desc.isStatic() == 0) {
00076 c.gridwidth = 1; // next row
00077 JLabel label2 = new JLabel("Name object (" + _desc.className() + ")");
00078 gridbag.setConstraints(label2, c);
00079 contentPane.add(label2);
00080
00081 c.gridwidth = GridBagConstraints.REMAINDER; // end of row
00082 _objChoice2 = new SaObjectChoice(_desc.className());
00083 gridbag.setConstraints(_objChoice2, c);
00084 contentPane.add(_objChoice2);
00085
00086 c.gridwidth = GridBagConstraints.REMAINDER; // next row, end of row
00087 JLabel l2 = new JLabel(".");
00088 gridbag.setConstraints(l2, c);
00089 contentPane.add(l2);
00090 }
00091
00092 c.gridwidth = GridBagConstraints.REMAINDER; // next row, end of row
00093 JLabel label3 = new JLabel(_desc.name());
00094 gridbag.setConstraints(label3, c);
00095 contentPane.add(label3);
00096
00097 c.gridwidth = GridBagConstraints.REMAINDER; // next row, end of row
00098 JLabel l3 = new JLabel("(");
00099 gridbag.setConstraints(l3, c);
00100 contentPane.add(l3);
00101
00102 String[] argNames = _desc.argNames();
00103 String[] argTypes = _desc.argTypes();
00104 int i;
00105 for (i=0 ; i<_nArgs ; i++) {
00106 c.gridwidth = 1; // next row
00107 JLabel l4 = new JLabel(argTypes[i] + " " + argNames[i] + ",");
00108 gridbag.setConstraints(l4, c);
00109 contentPane.add(l4);
00110
00111 c.gridwidth = GridBagConstraints.REMAINDER; // end of row
00112 _argObjChoice[i] = new SaObjectChoice(argTypes[i]);
00113 gridbag.setConstraints(_argObjChoice[i], c);
00114 contentPane.add(_argObjChoice[i]);
00115 }
00116
00117 c.gridwidth = GridBagConstraints.REMAINDER; // next row, end of row
00118 JLabel l5 = new JLabel(")");
00119 gridbag.setConstraints(l5, c);
00120 contentPane.add(l5);
00121
00122 c.fill = GridBagConstraints.NONE;
00123 c.gridwidth = 1; // next row
00124 c.anchor = GridBagConstraints.WEST;
00125 _okButton = new JButton("OK");
00126 _okButton.addActionListener(this);
00127 gridbag.setConstraints(_okButton, c);
00128 contentPane.add(_okButton);
00129
00130 c.gridwidth = GridBagConstraints.REMAINDER; // end of row
00131 c.anchor = GridBagConstraints.EAST;
00132 _cancelButton = new JButton("Cancel");
00133 _cancelButton.addActionListener(this);
00134 gridbag.setConstraints(_cancelButton, c);
00135 contentPane.add(_cancelButton);
00136
00137
00138 // Add listener for window-closing
00139
00140 this.addWindowListener(new WindowAdapter() {
00141 public void windowClosing(WindowEvent e) {
00142 setVisible(false);
00143 }
00144 });
00145
00146 pack();
00147 setVisible(true);
00148 }
|
|
|
Implementation of ActionListener.
00154 {
00155 if (e.getSource() != _cancelButton) {
00156 String resultName;
00157 if (_desc.returnType().compareTo("void") != 0)
00158 resultName = (String) _objChoice1.getSelectedItem();
00159 else
00160 resultName = "";
00161 String[] args = new String[_nArgs];
00162 String[] argTypes = _desc.argTypes();
00163 int i;
00164 for (i=0 ; i<_nArgs ; i++) {
00165 String argName;
00166 argName = (String) _argObjChoice[i].getSelectedItem();
00167 args[i] = argTypes[i].concat(" ").concat(argName);
00168 }
00169 String r;
00170 Cursor oldCursor = getCursor();
00171 setCursor(new Cursor(java.awt.Cursor.WAIT_CURSOR));
00172 if (_desc.isStatic() == 0) {
00173 String objectName = (String) _objChoice2.getSelectedItem();
00174 if (objectName.length() == 0) {
00175 ErrorStreamArea.println("No value for object");
00176 setCursor(oldCursor);
00177 return;
00178 }
00179 r = _mediator.callMethod(_desc.className(), objectName,
00180 _desc.name(), resultName, args);
00181 }
00182 else
00183 r = _mediator.callStaticMethod(_desc.className(), _desc.name(),
00184 resultName, args);
00185 try {
00186 Class[] argClass = new Class[2];
00187 argClass[0] = Class.forName("java.lang.String");
00188 argClass[1] = Class.forName("java.lang.String");
00189 Object[] objs = new Object[2];
00190 objs[0] = r;
00191 objs[1] = _desc.returnType();
00192 Method method = _user.getClass().getMethod(_funcName, argClass);
00193 method.invoke(_user, objs);
00194 } catch (Exception ex) {
00195 ErrorStreamArea.println(ex.toString());
00196 }
00197 setCursor(oldCursor);
00198 }
00199 setVisible(false);
00200 }
|
1.2.12 written by Dimitri van Heesch,
© 1997-2001