Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: irate/swt/plugin/lircremote/FunctionSetup.java


1   // Copyright 2003 Stephen Blackheath
2   
3   package irate.swt.plugin.lircremote;
4   
5   import org.eclipse.swt.widgets.*;
6   import org.eclipse.swt.layout.*;
7   import org.eclipse.swt.events.*;
8   import org.eclipse.swt.SWT;
9   import irate.plugin.*;
10  import irate.plugin.lircremote.LircRemoteControlPlugin;
11  import irate.plugin.lircremote.LircRemoteControlListener;
12  import irate.plugin.lircremote.Function;
13  
14  /**
15   * Dialog box to set up the buttons that correspond to a function.
16   */
17  public class FunctionSetup
18    implements LircRemoteControlListener
19  {
20    private Display display;
21    private boolean done = false;
22    private List list;
23  
24    public FunctionSetup(Display display_, PluginApplication app, LircRemoteControlPlugin plugin, Function func)
25    {
26      this.display = display_;
27      final Shell shell = new Shell(display);
28      shell.setText("Set up "+func.getName());
29      shell.addShellListener(new ShellAdapter()
30      {
31        public void shellClosed(ShellEvent e){
32          done=true;
33        }
34      });
35      GridLayout layout = new GridLayout(1, false);
36      shell.setLayout(layout);
37  
38      Label heading1 = new Label(shell, SWT.NONE);
39      heading1.setText("This is the list of buttons that will trigger the");
40      Label heading2 = new Label(shell, SWT.NONE);
41      heading2.setText(func.getName()+" function.");
42      Label heading3 = new Label(shell, SWT.NONE);
43      heading3.setText("Press button on remote control to add it to the list.");
44  
45      org.eclipse.swt.widgets.Button clear = new org.eclipse.swt.widgets.Button(shell, SWT.NONE);
46      clear.setText("Clear list");
47  
48      list = new List(shell, SWT.NONE);
49      for (int i = 0; i < func.buttons.size(); i++) {
50        irate.plugin.lircremote.Button button = (irate.plugin.lircremote.Button) func.buttons.get(i); 
51        list.add(button.getID());
52      }
53      GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.VERTICAL_ALIGN_FILL);
54      gd.widthHint = 200;
55      gd.heightHint = 150;
56      list.setLayoutData(gd);
57  
58      clear.addSelectionListener(new SelectionAdapter(){
59        public void widgetSelected(SelectionEvent e){
60          list.removeAll();
61        }
62      });
63  
64      org.eclipse.swt.widgets.Button ok = new org.eclipse.swt.widgets.Button(shell, SWT.NONE);
65      ok.setText("OK");
66      gd = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
67      ok.setLayoutData(gd);
68      ok.addSelectionListener(new SelectionAdapter(){
69        public void widgetSelected(SelectionEvent e){
70          done = true;
71        }
72      });
73      shell.pack();    
74      shell.open();
75      plugin.addLircRemoteControlListener(this);
76      while (!done) {
77        if (!display.readAndDispatch()) display.sleep();
78      }
79      plugin.removeLircRemoteControlListener(this);
80  
81      String[] buttonIDs = list.getItems();
82      func.buttons.clear();
83      for (int i = 0; i < buttonIDs.length; i++)
84        func.buttons.add(new irate.plugin.lircremote.Button(buttonIDs[i], func.getRepeatPolicy()));
85      shell.close();
86      shell.dispose();
87    }
88  
89    public void connectStatusChanged(LircRemoteControlPlugin plugin, boolean connected)
90    {
91    }
92  
93    public void buttonPressed(LircRemoteControlPlugin plugin, final irate.plugin.lircremote.Button button)
94    {
95      if (button.getRepeatCount() == 0)
96        display.asyncExec(new Runnable() {
97          public void run() {
98            if (list.indexOf(button.getID()) < 0)
99              list.add(button.getID());
100         }
101       });
102   }
103 }
104