📄 j_fusionsample1.java
字号:
package Rfid_test;
import java.awt.Toolkit;
import java.util.ResourceBundle;
import java.util.Locale;
import com.symbol.fusion.wlan.Wlan;
import com.symbol.fusion.wlan.Adapters;
import com.symbol.fusion.wlan.Profiles;
import com.symbol.fusion.wlan.WlanConstants;
import com.symbol.fusion.wlan.WlanException;
import com.symbol.fusion.FusionException;
import com.symbol.fusion.wlan.SignalQualityListener;
import com.symbol.fusion.wlan.SignalQualityEvent;
import com.symbol.fusion.wlan.Adapter;
import com.symbol.fusion.Config;
import com.symbol.fusion.Diagnostics;
import com.symbol.fusion.Version;
import com.symbol.fusion.wlan.Profile;
import com.symbol.fusion.wlan.AdhocProfileData;
import com.symbol.fusion.wlan.InfrastructureProfileData;
import symbol.Win32;
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
/**
*
* @author kdimunge
*
* This sample demonstrates most of the important features provided by Fusion
* class libraries.
* This sample is localized and is referring "J_FusionSample1_en_US.properties" file
* to get locale data.
*/
public class J_FusionSample1 implements SignalQualityListener, SelectionListener, KeyListener, MouseListener {
Wlan wlan; //instance of Wlan
Adapters adapters; //instance of Adapters
Profiles profiles; //instance of Profiles
Adapter adapter; //instance of Adapter
Profile profile; //instance of Profile
Config config; //instance of Config
Version version; //instance of Version
Diagnostics diagnostics; //instance of Diagnostics
Table tblMain;
Table tblVersions;
Table tblProfiles;
Table tblAbout;
private GridLayout gridLayout;
private GridData gridData1;
private GridData gridData2;
private GridData gridData3;
private GridData gridData4;
private GridData gridData5;
private GridData gridData6;
private GridData gridData7;
private GridData gridData8;
Shell shell;
Display display;
int width;
int height;
int newQuality = 0;
int newStrength = 0;
String essid = "";
String activeProfile = "";
String nQuality = "";
String nStrength = "";
String nMacAddress = "";
//this is the default fully qualified log file path
final String logFileName = "\\FusionLog.txt";
private int currentTable = 0; // 0 - tblMain
// 1 - tblVersions
// 2 - tblProfiles
// 3 - tblAbout
private int switchNo = 0;
private int digitsCount = 0;
long lastKeyTime = 0;
//This reference is never been used but WSDD would not
//deploy the class whitout a reference
J_FusionSample1Res_en_US dummyResource = null;
public J_FusionSample1()throws Exception{
wlan = new Wlan(); //construct Wlan object
config = new Config(); //construct Config object
version = config.getVersion(); //get reference of Version
adapters = wlan.getAdapters(); //get reference of Adapters
profiles = wlan.getProfiles(); //get reference of Profiles
diagnostics = config.getDiagnostics(); //get reference of Diagnostics
//get first element of Adapters (usually one WLAN adapter resides in device)
adapter = adapters.get(0);
//add signal quality listener
adapter.addSignalQualityListener(this);
gridLayout = new GridLayout();
gridLayout.numColumns = 1;
display = new Display ();
shell = new Shell (display, SWT.TITLE);
shell.setText("J_FusionSample1");
width = Toolkit.getDefaultToolkit().getScreenSize().width;
height = Toolkit.getDefaultToolkit().getScreenSize().height;
shell.setBounds(0, 0, width, height-25);
shell.setLayout(gridLayout);
gridData1 = new GridData(GridData.FILL_BOTH);
gridData1.horizontalSpan = 1;
gridData1.exclude=true;
gridData2 = new GridData(GridData.FILL_BOTH);
gridData2.horizontalSpan = 1;
gridData2.exclude = true;
gridData3 = new GridData(GridData.FILL_BOTH);
gridData3.horizontalSpan = 1;
gridData3.exclude = true;
gridData4 = new GridData(GridData.FILL_BOTH);
gridData4.horizontalSpan = 1;
gridData4.exclude = true;
gridData5 = new GridData(GridData.FILL_BOTH);
gridData5.horizontalSpan = 1;
gridData5.exclude = true;
gridData6 = new GridData(GridData.FILL_BOTH);
gridData6.horizontalSpan = 1;
gridData6.exclude = true;
gridData7 = new GridData(GridData.FILL_BOTH);
gridData7.horizontalSpan = 1;
gridData7.exclude = true;
gridData8 = new GridData(GridData.FILL_BOTH);
gridData8.horizontalSpan = 1;
gridData8.exclude = true;
createSampleProfiles();//create two sample profiles
profiles.refresh(); //refresh profile list
createMainList(); //create start-up screen
updateMainList(); //update start-up screen
createVersionList(); //create version screen
createProfileList(); //create profile screen
createAbout(); //create about box
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
public static void main (String [] args) {
try{
J_FusionSample1 j_FusionSample1 = new J_FusionSample1();
}catch(FusionException fe){
System.out.println("error code : " + fe.getErrorcode());
System.out.println("error code : " + fe.getDescription());
fe.printStackTrace();
}catch(WlanException we){
System.out.println("error code : " + we.getErrorcode());
System.out.println("error code : " + we.getDescription());
we.printStackTrace();
}catch(Exception fe){
fe.printStackTrace();
}
}
void createMainList(){
tblMain = new Table (shell, SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION);
tblMain.setHeaderVisible (true);
ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
String[] titles = {res.getString("LST_MAIN_TITLE_HASH"),
res.getString("LST_MAIN_TITLE_ITEM"),
res.getString("LST_MAIN_TITLE_VALUE")};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (tblMain, SWT.NONE);
column.setText (titles [i]);
}
int i = 0;
TableItem item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_EXIT"));
item.setText (2, "");
item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_SIGNAL"));
item.setText (2, "");
item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_SSID"));
item.setText (2, "");
item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_PROFILES"));
item.setText (2, "");
item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_VERSIONS"));
item.setText (2, "");
item = new TableItem (tblMain, SWT.NONE);
item.setText (0, ""+ (i++) +"");
item.setText (1, res.getString("LST_MAIN_ITEM_ABOUT"));
item.setText (2, "");
tblMain.setSize (tblMain.computeSize (width,height));
tblMain.getColumn(0).setWidth((width*10)/100);//occupy 10% of the width
tblMain.getColumn(1).setWidth((width*30)/100);//occupy 30% of the width
tblMain.getColumn(2).setWidth((width*60)/100);//occupy 60% of the width
tblMain.setSelection(0);
tblMain.setFocus();
tblMain.setLayoutData(gridData1);
tblMain.addSelectionListener(this);
tblMain.addKeyListener(this);
tblMain.addMouseListener(this);
tblMain.setVisible(true);
}
void createVersionList()throws Exception{
tblVersions = new Table (shell, SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION);
tblVersions.setHeaderVisible (true);
ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
String[] titles = {res.getString("LST_VERSIONS_TITLE_HASH"),
res.getString("LST_VERSIONS_TITLE_COMPONENT"),
res.getString("LST_VERSIONS_TITLE_VERSION")};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (tblVersions, SWT.NONE);
column.setText (titles [i]);
}
int i = 0;
TableItem item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_BACK"));
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_FUSION"));
item.setText (2, version.getFusion());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_CFG_EDITOR"));
item.setText (2, version.getConfigurationEditor());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_LOGIN_SERVICE"));
item.setText (2, version.getLoginService());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_PHOTON_DRIVER"));
item.setText (2, version.getPhotonDriver());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_WCDIAG"));
item.setText (2, version.getWcDiag());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_WCLAUNCH"));
item.setText (2, version.getWcLaunch());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_WCSAPI"));
item.setText (2, version.getWcsApi());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_WCSRV"));
item.setText (2, version.getWcSrv());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_WCSTATUS"));
item.setText (2, version.getWcStatus());
item = new TableItem (tblVersions, SWT.NONE);
item.setText (0, (i < 10 ? "0"+ (i++) : ""+ (i++)));
item.setText (1, res.getString("LST_VERSIONS_COMPONENT_FUSION_PUBLIC_API"));
item.setText (2, version.getFusionPublicApi());
tblVersions.getColumn(0).setWidth((width*10)/100);//occupy 10% of the width
tblVersions.getColumn(1).setWidth((width*60)/100);//occupy 60% of the width
tblVersions.getColumn(2).setWidth((width*30)/100);//occupy 30% of the width
tblVersions.setSize (tblMain.computeSize (width,height));
tblVersions.setLayoutData(gridData2);
tblVersions.addSelectionListener(this);
tblVersions.addKeyListener(this);
tblVersions.addMouseListener(this);
tblVersions.setVisible(false);
}
void createProfileList()throws Exception{
ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
tblProfiles = new Table (shell, SWT.H_SCROLL|SWT.V_SCROLL|SWT.FULL_SELECTION);
tblProfiles.setHeaderVisible (true);
String[] titles = {res.getString("LST_PROFILES_TITLE_HASH"),
res.getString("LST_PROFILES_TITLE_PROFILE_NAME"),
res.getString("LST_PROFILES_TITLE_PROFILE_ID")};
for (int i=0; i<titles.length; i++) {
TableColumn column = new TableColumn (tblProfiles, SWT.NONE);
column.setText (titles [i]);
}
tblProfiles.getColumn(0).setWidth((width*10)/100);//occupy 10% of the width
tblProfiles.getColumn(1).setWidth((width*60)/100);//occupy 60% of the width
tblProfiles.getColumn(2).setWidth((width*30)/100);//occupy 30% of the width
tblProfiles.setLayoutData(gridData4);
tblProfiles.setSize (tblMain.computeSize (width,height));
tblProfiles.addSelectionListener(this);
tblProfiles.addKeyListener(this);
tblProfiles.addMouseListener(this);
tblProfiles.setVisible(false);
}
void updateProfileList(){
ResourceBundle res = ResourceBundle.getBundle("J_FusionSample1Res", new Locale("en","US"));
tblProfiles.removeAll();
TableItem item = new TableItem (tblProfiles, SWT.NONE);
int j = 0;
int noProfiles = profiles.getLength();
item.setText (0, (noProfiles > 10 ? "0"+ (j++) : ""+ (j++)));
item.setText (1, res.getString("LST_PROFILES_PROFILE_NAME_BACK"));
//populate tblProfiles with available profiles
for(int i=0; i<noProfiles;i++){
item = new TableItem (tblProfiles, SWT.NONE);
if (noProfiles > 10)
{
if(j < 10)
item.setText (0, "0"+ (j++));
else
item.setText (0, ""+ (j++));
}
else{
item.setText (0, ""+ (j++));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -