1   /*
2    * Copyright 2008 motej
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License. 
15   */
16  package motej.demos.classic;
17  
18  import java.awt.BorderLayout;
19  
20  import javax.swing.JFrame;
21  import javax.swing.SwingUtilities;
22  
23  import motej.Mote;
24  import motej.MoteFinder;
25  import motej.MoteFinderListener;
26  import motej.request.ReportModeRequest;
27  import motejx.extensions.classic.ClassicController;
28  
29  /**
30   * 
31   * <p>
32   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
33   */
34  public class ClassicControllerButtonsDemo {
35  
36  	public static void main(String[] args) {
37  		final JFrame frame = new JFrame();
38  		frame.getContentPane().setLayout(new BorderLayout());
39  		
40  		MoteFinder.getMoteFinder().addMoteFinderListener(new MoteFinderListener() {
41  		
42  			public void moteFound(Mote mote) {
43  				ClassicController cc = null;
44  				while(cc == null) {
45  					cc = mote.<ClassicController>getExtension();
46  				}
47  				
48  				final DigitalButtonPanel p = new DigitalButtonPanel(cc);
49  				SwingUtilities.invokeLater(new Runnable() {
50  				
51  					public void run() {
52  						frame.getContentPane().add(p.getPanel(), BorderLayout.CENTER);
53  						frame.pack();
54  					}
55  				});
56  				
57  				mote.setPlayerLeds(new boolean[] { true, false, false, false });
58  				mote.setReportMode(ReportModeRequest.DATA_REPORT_0x32);
59  			}
60  		});
61  		MoteFinder.getMoteFinder().startDiscovery();
62  		
63  		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
64  		frame.pack();
65  		frame.setVisible(true);
66  	}
67  }