SWT

    SWT is an Eclipse project used for writing desktop programs.

1. Agreement

  • Object create()
    SWT models have a create() method, which is used to create corresponding Java objects. After creation, they need to be saved in the global variable stack. The variable name is the name of the model.
     
  • Variable declaration
    The SWT model needs to have a variable declaration, used for code assistance, to tell the type of Java object being saved.

2. Index model

     There are multiple index models under SWT, among which the index model of the control is xworker.swt.Widgets. In addition to control model indexes, SWT also has layout model indexes, event type model indexes, and so on.

3. Main model

    Take the control model as an example. The control model is generally used by container class controls, so container class controls will inherit xworker.swt.Widgets.

4.create method

    The code for the create() method of a typical SWT model is as follows, taking the create method of BlueButton in the video below as an example:

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
 
import xworker.swt.widgets.ControlCreator;
 
//Create button object, parent is putted by parent model
def button = new Button(parent, SWT.NONE);
button.setBackground(button.getDisplay().getSystemColor(SWT.COLOR_BLUE));
 
//Apply control common features
ControlCreator.init(button, self, actionContext);
 
//Set button attributes with model
button.setText(self.getMetadata().getLabel());
 
//Invoke children's create method, put button as parent
actionContext.peek().put("parent", button);
for(child : self.getChilds()){
     child.doAction("create", actionContext);
}
 
//Put button to global context
actionContext.g().put(self.getMetadata().getName(), button);
 
//Return
return button;

5. Video example

  • BlueButton is a custom control model, registered under the control index xworker.swt.Widgets.
  • The Shell model inherits xworker.swt.Widgets and can use BlueButton through Shell.

 

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号