View Javadoc

1   package org.ximtec.igesture.tool.view.devicemanager.wizard;
2   
3   import java.awt.EventQueue;
4   import java.awt.Rectangle;
5   import java.util.ArrayList;
6   
7   import org.netbeans.api.wizard.WizardDisplayer;
8   import org.netbeans.spi.wizard.Wizard;
9   import org.netbeans.spi.wizard.WizardBranchController;
10  import org.ximtec.igesture.io.AbstractGestureDevice;
11  import org.ximtec.igesture.io.User;
12  import org.ximtec.igesture.tool.view.devicemanager.DeviceManagerController;
13  
14  /**
15   * A wizard to add devices.
16   * @author Bjorn Puype, bpuype@gmail.com
17   *
18   */
19  public class AddDeviceWizard {
20  
21  	private Wizard wizard;
22  	private WizardBranchController brancher;
23  	private DeviceManagerController controller;
24  	
25  	public AddDeviceWizard(DeviceManagerController controller, boolean enableRecognisers)
26  	{
27  		if(!enableRecognisers)
28  		{
29  			AddDeviceWizardProvider provider = new AddDeviceWizardProvider(controller);
30  			wizard = provider.createWizard();
31  		}
32  		else
33  		{
34  			AddDeviceWizardBranchController brancher = new AddDeviceWizardBranchController(controller);
35  			wizard = brancher.createWizard();
36  		}
37  		this.controller = controller;
38  	}
39  	
40  	/**
41  	 * Run the wizard
42  	 */
43  	public void execute()
44  	{
45  		Runnable s = new Runnable(){
46  
47  			@Override
48  			public void run() {
49  				ArrayList<Object> association = (ArrayList<Object>)WizardDisplayer.showWizard (wizard, new Rectangle (10, 10, 600, 400));
50  				
51  				//connect to the found device
52  				if(association != null)//if not cancelled 				//TODO move to finish??
53  				{
54  					((AbstractGestureDevice<?,?>)association.get(0)).connect();
55  					//add the found device
56  					controller.addDevice((AbstractGestureDevice<?,?>)association.get(0), (User)association.get(1));
57  				}
58  				
59  			}
60  			
61  		};
62  		EventQueue.invokeLater(s);
63  	}
64  }