Difference between revisions of "How to define play-in-able Swing GUI application"

From WeizmannWiki
Jump to: navigation, search
(New page: ===Create a new LSC project=== From PlayGo perspective: File-->New-->LSC Project ===Write your Swing code=== ====Using WindowBuilder plugin==== One possible option for creating the Swing ...)
 
(Binding expression for dynamic instances)
Line 71: Line 71:
  
  
<big>You are ready to start playing-in.</big>
+
<big>You are ready to start playing in.</big>
 
'''[http://www.youtube.com/watch?v=zelYmRtCJk8 Watch a Demo]'''
 
'''[http://www.youtube.com/watch?v=zelYmRtCJk8 Watch a Demo]'''

Revision as of 14:36, 18 December 2011

Create a new LSC project

From PlayGo perspective: File-->New-->LSC Project

Write your Swing code

Using WindowBuilder plugin

One possible option for creating the Swing GUI application is using the WindowBuilder plugin. Follow the instructions below:

  1. Install the WindowBuilder plugin from: [1]
  2. Use the System Model view to define the classes and object that participate in your application.
    1. Classes that has a gui representation (that are actually part of the GUI) should extend one of the Swing available classes (JButton, JTextField, etc...).
    2. Classes that has a gui representation should be marked as such (check the 'GUI' radio button).
  3. Create the application window using the WindowBuilder plugin.
    1. Use the "Choose Component" option to choose the classes defined using the System Model a the application GUI components.
    2. In the application window->design tab, write under the constructor->name field 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

  1. One can choose to write the GUI in pure Java Swing code.
  2. 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 Playinable

Right click your LSC project-->Properties-->click "Play-In" section under "PlayGo"-->check the "Make GUI playinable" check box.

This action will add the il.ac.wis.cs.playgo.guitoolkit to the aspect path.

If the run configuration argument Ddev is true, the guitoolkit project will be added, otherwise the guitoolkit jar is added.

Right click menu

All public methods which are defined in your component's class will appear in the component's right click menu in 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

More info...

Supported Swing components & component's default action

All swing components which are made play-in-able once clicking the "Make GUI play-in-able" check box, are defined in 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.

e.g JButton is added to the hash table as follows: swingComponents.put(Constants.JBUTTON, new String[]{Constants.ACTION_LISTENER,Constants.CLICK_ACTION});

Components which 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[]{"",""});

For now, the supported event listeners are Action Listener and Change Listener.

Binding expression 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 ready to start playing in. Watch a Demo