Difference between revisions of "How to define play-in-able Swing GUI application"
(→Binding expression for dynamic instances) |
|||
Line 4: | Line 4: | ||
===Write your Swing code=== | ===Write your Swing code=== | ||
− | ====Using WindowBuilder plugin==== | + | ====Using the WindowBuilder plugin==== |
− | One possible option for creating the Swing GUI application is | + | One possible option for creating the Swing GUI application is to use the WindowBuilder plugin. |
− | Follow | + | Follow these instructions: |
# Install the WindowBuilder plugin from: [http://www.eclipse.org/windowbuilder/] | # Install the WindowBuilder plugin from: [http://www.eclipse.org/windowbuilder/] | ||
− | # Use the System Model view to define the classes and | + | # Use the System Model view to define the classes and objects that participate in your application. |
− | ## Classes that | + | ## Classes that have a GUI representation should extend one of the Swing available classes (JButton, JTextField, etc...). |
− | ## Classes that | + | ## Classes that have a GUI representation should be marked as such (check the 'GUI' radio button, by clicking the corresponding radio button when creating a class). |
# Create the application window using the WindowBuilder plugin. | # Create the application window using the WindowBuilder plugin. | ||
− | ## Use the "Choose Component" option to choose the classes defined using the System Model | + | ## Use the "Choose Component" option to choose the classes defined using the System Model. |
− | ##In the application window->design tab, | + | ## In the application window->design tab, under the constructor->name field, write the name of the object as was given to it in the System Model (since the System Model object and the GUI component are the exact same object in the application). |
====Manually writing Java Swing code==== | ====Manually writing Java Swing code==== | ||
− | # | + | #You can choose to write the GUI in pure Java Swing code. |
#Once the code is complete, use the '''import''' button from the System Model view to create a System Model from the Java Code. | #Once the code is complete, use the '''import''' button from the System Model view to create a System Model from the Java Code. | ||
− | ===Make your GUI | + | ===Make your GUI play-in-able=== |
− | Right click your LSC project-->Properties--> | + | Right-click your LSC project-->Properties-->PlayGo-->Play-In. Check the "Make GUI Play-in-able" check box: |
− | + | [[Image:play-in-able.jpg]] | |
− | + | ===Right-click menu=== | |
− | + | All public methods that are defined in your component's class will appear in the component's right-click menu during play-in. | |
− | ===Right click menu=== | + | |
− | All public methods | + | |
If you wish to omit one of the methods, do the following: | If you wish to omit one of the methods, do the following: | ||
Line 34: | Line 32: | ||
2. Add the '''@NonPlayInable''' annotation before the method you'd like to omit | 2. Add the '''@NonPlayInable''' annotation before the method you'd like to omit | ||
− | + | ===Supported Swing components and component's default action=== | |
− | + | All Swing components that are made play-in-able once clicking the "Make GUI play-in-able" check box, are defined in the '''swingComponents''' hash table under '''il.ac.wis.cs.automateplayin.GUIComponents.java''' in the '''guitoolkit''' project. | |
− | + | ||
− | + | ||
The components are added along with their event listeners and their default action. | The components are added along with their event listeners and their default action. | ||
− | + | For example, JButton is added to the hash table as follows:<br> | |
− | + | ||
'''swingComponents.put(Constants.JBUTTON, new String[]{Constants.ACTION_LISTENER,Constants.CLICK_ACTION});''' | '''swingComponents.put(Constants.JBUTTON, new String[]{Constants.ACTION_LISTENER,Constants.CLICK_ACTION});''' | ||
− | Components | + | Components that have no default action are added with no listener and default action; e.g., JLable is added as follows: |
'''swingComponents.put(Constants.JLABEL, new String[]{"",""});''' | '''swingComponents.put(Constants.JLABEL, new String[]{"",""});''' | ||
− | + | Currently, the supported event listeners are Action Listener and Change Listener. | |
− | === Binding | + | === Binding expressions for dynamic instances === |
1. In order to be able to create a binding expression for an instance in Play-Out, each Dynamic instance should have the following code: | 1. In order to be able to create a binding expression for an instance in Play-Out, each Dynamic instance should have the following code: | ||
public class BindedButton extends JButton{ | public class BindedButton extends JButton{ | ||
Line 71: | Line 66: | ||
− | + | You are now ready to start playing in. | |
'''[http://www.youtube.com/watch?v=zelYmRtCJk8 Watch a Demo]''' | '''[http://www.youtube.com/watch?v=zelYmRtCJk8 Watch a Demo]''' |
Revision as of 10:59, 28 March 2012
Contents
Create a new LSC project
From PlayGo perspective: File-->New-->LSC Project
Write your Swing code
Using the WindowBuilder plugin
One possible option for creating the Swing GUI application is to use the WindowBuilder plugin. Follow these instructions:
- Install the WindowBuilder plugin from: [1]
- Use the System Model view to define the classes and objects that participate in your application.
- Classes that have a GUI representation should extend one of the Swing available classes (JButton, JTextField, etc...).
- Classes that have a GUI representation should be marked as such (check the 'GUI' radio button, by clicking the corresponding radio button when creating a class).
- Create the application window using the WindowBuilder plugin.
- Use the "Choose Component" option to choose the classes defined using the System Model.
- In the application window->design tab, under the constructor->name field, write the name of the object as was given to it in the System Model (since the System Model object and the GUI component are the exact same object in the application).
Manually writing Java Swing code
- You can choose to write the GUI in pure Java Swing code.
- Once the code is complete, use the import button from the System Model view to create a System Model from the Java Code.
Make your GUI play-in-able
Right-click your LSC project-->Properties-->PlayGo-->Play-In. Check the "Make GUI Play-in-able" check box:
All public methods that are defined in your component's class will appear in the component's right-click menu during play-in. If you wish to omit one of the methods, do the following:
1. Add import il.ac.wis.cs.gwt.server.stubs.annotation.NonPlayInable; to your class
2. Add the @NonPlayInable annotation before the method you'd like to omit
Supported Swing components and component's default action
All Swing components that are made play-in-able once clicking the "Make GUI play-in-able" check box, are defined in the swingComponents hash table under il.ac.wis.cs.automateplayin.GUIComponents.java in the guitoolkit project.
The components are added along with their event listeners and their default action.
For example, JButton is added to the hash table as follows:
swingComponents.put(Constants.JBUTTON, new String[]{Constants.ACTION_LISTENER,Constants.CLICK_ACTION});
Components that have no default action are added with no listener and default action; e.g., JLable is added as follows: swingComponents.put(Constants.JLABEL, new String[]{"",""});
Currently, the supported event listeners are Action Listener and Change Listener.
Binding expressions for dynamic instances
1. In order to be able to create a binding expression for an instance in Play-Out, each Dynamic instance should have the following code:
public class BindedButton extends JButton{
static HashMap<String, BindedButton> allButtons= new HashMap<String, BindedButton>();
public BindedButton(String name) { super(); this.name = name; allButtons.put(name, this); }
...
public static BindedButton getButton(String buttonName) { BindedButton button = allButtons.get(buttonName); return button; } }
You are now ready to start playing in.
Watch a Demo