📄 view.java
字号:
* that will live in the MenuBar on the PocketPC. SWT on the PPC * currently has a bug that prevents MenuItem's from triggering * ArmEvent's when clicked. // Mac's will not tolerate images in the menu bar, and // it just doesn't look right unless you're on a PocketPC if (StringUtil.equalsIgnoreCase(System.getProperty("os.name"), "windows ce")) { MenuItem start = new MenuItem(menuBar, SWT.PUSH); start.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start"+(Stumbler.getStumbler().isStumbling() ? "-hot" : "")+".png"))); start.addArmListener(new ArmListener(){ public void widgetArmed (ArmEvent e) { MenuItem mi = (MenuItem) e.widget; System.out.println("blah!!!!!!"); if (Stumbler.getStumbler().isStumbling()) { Stumbler.getStumbler().stopStumbling(); mi.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start.png"))); } else { Stumbler.getStumbler().startStumbling(); mi.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start-hot.png"))); } } }); } */ } public static void reportError (String msg) { MessageBox mb = new MessageBox(View.shell, SWT.ICON_ERROR | SWT.OK); mb.setMessage("Error: " + msg); mb.open(); } }class Status extends Composite implements Runnable { Label gps; Label bt; Label wifi; Label logSize; Button toggleStumble; Composite line1; Composite line2; public Status (Composite parent) { super(parent, SWT.NONE); setSize(225, 20); { RowLayout rl = new RowLayout(SWT.VERTICAL); rl.marginTop = 0; rl.marginLeft = 3; rl.marginRight = 3; rl.justify = true; setLayout(rl); } line1 = new Composite(this, SWT.NONE); { RowLayout rl = new RowLayout(SWT.HORIZONTAL); rl.marginTop = 0; rl.marginLeft = 3; rl.marginRight = 3; rl.justify = true; line1.setLayout(rl); gps = new Label(line1, SWT.NONE); //new Label(line1, SWT.SEPARATOR); wifi = new Label(line1, SWT.NONE); //new Label(line1, SWT.SEPARATOR); bt = new Label(line1, SWT.NONE); } line2 = new Composite(this, SWT.NONE); { RowLayout rl = new RowLayout(SWT.HORIZONTAL); rl.marginTop = 0; rl.marginLeft = 3; rl.marginRight = 3; rl.justify = true; line2.setLayout(rl); //toggleStumble = new Button(line2, SWT.FLAT | SWT.NO_TRIM) ; logSize = new Label(line2, SWT.NONE); /* toggleStumble.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start"+(Stumbler.getStumbler().isStumbling() ? "-hot" : "")+".png"))); toggleStumble.addSelectionListener(new SelectionListener(){ public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected (SelectionEvent e) { System.out.println("blah!!!!!!"); if (Stumbler.getStumbler().isStumbling()) { Stumbler.getStumbler().stopStumbling(); Status.this.toggleStumble.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start.png"))); } else { Stumbler.getStumbler().startStumbling(); Status.this.toggleStumble.setImage(new Image(View.display, this.getClass().getClassLoader().getResourceAsStream("resources/start-hot.png"))); } } }); */ } gps.setText("No GPS"); bt.setText("0 BT"); wifi.setText("0 AP"); logSize.setText("Log Empty"); View.display.timerExec(1000, this); } public void receiverUpdated (Receiver r) { } public void run () { if (View.shell.isDisposed()) return; WiFiReceiver wr = (WiFiReceiver) Stumbler.getStumbler().getReceiver(WiFiSpotter.class); if (wr != null) { wifi.setText(wr.totalNumBeacons() + " AP"); wifi.setSize(wifi.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } BluetoothReceiver br = (BluetoothReceiver) Stumbler.getStumbler().getReceiver(BluetoothSpotter.class); if (br != null) { bt.setText(br.totalNumBeacons() + " BT"); bt.setSize(bt.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } GPSReceiver gr = (GPSReceiver) Stumbler.getStumbler().getReceiver(NMEAGPSSpotter.class); if (gr != null) { String text = "No GPS"; if (gr.hasLock() == GPSMeasurement.NO_INFO_RE_A_LOCK) text = "No Lock"; else if (gr.hasLock() == GPSMeasurement.HAVE_A_LOCK) text = "GPS Lock"; gps.setText(text); gps.setSize(gps.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } line1.setSize(line1.computeSize(SWT.DEFAULT, SWT.DEFAULT)); String logFile = Stumbler.getStumbler().getLogFile(); if (logFile != null) { File f = new File(logFile); logSize.setText("Logged " + (f.length()/1024) + "k"); logSize.setSize(logSize.computeSize(SWT.DEFAULT, SWT.DEFAULT)); line2.setSize(line2.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } this.setSize(this.computeSize(SWT.DEFAULT, SWT.DEFAULT)); View.display.timerExec(1000, this); }}class BeaconTable extends Composite implements ReceiverListener { final static int THRESHOLD_STALE = 5000; final static int THRESHOLD_REMOVE = 15000; private Table tbl; Hashtable container = new Hashtable(); public BeaconTable (Composite parent) { super(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight = 0; layout.marginWidth = 0; setLayout(layout); GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.verticalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; gd.grabExcessVerticalSpace = true; gd.widthHint = 225; gd.heightHint = 200; tbl = new Table(this, SWT.BORDER); tbl.setLinesVisible(true); tbl.setHeaderVisible(true); tbl.setLayoutData(gd); // define columns String[] cols = { "Address" , "Name", "Type", "RSSI", "Mode", "Lat", "Lon"}; int[] colWidths = { 120, 80, 40, 50, 70, 70, 70 }; for (int i = 0;i<cols.length; i++ ) { TableColumn col = new TableColumn(tbl, SWT.NULL); col.setText(cols[i]); col.setWidth(colWidths[i]); } for (Enumeration e = Stumbler.getStumbler().getReceivers(); e.hasMoreElements(); ) { Receiver r = (Receiver) e.nextElement(); if (r instanceof WiFiReceiver) r.addListener(this); } View.display.timerExec(1000, new Runnable(){ public void run () { if (View.shell.isDisposed()) return; BeaconTable.this.tbl.removeAll(); for (Enumeration e = container.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); Hashtable h = (Hashtable) container.get(key); long time = ( (Long) h.get("time")).longValue(); if ((System.currentTimeMillis() - time) >= THRESHOLD_REMOVE) { container.remove(key); continue; } TableItem ti = new TableItem(BeaconTable.this.tbl, SWT.NONE); ti.setText(new String[]{ (String) h.get("address"), (String) h.get("name"), (String) h.get("type"), (String) h.get("rssi"), (String) h.get("mode"), (String) h.get("lat"), (String) h.get("lon") }); if ((System.currentTimeMillis() - time) >= THRESHOLD_STALE) { ti.setForeground(View.display.getSystemColor(SWT.COLOR_GRAY)); } } View.display.timerExec(1000, this); } }); } public void receiverUpdated (Receiver r) { Hashtable[] data = ((BeaconReceiver) r).getBeaconData(); if (data == null) { return; } for (int i=0;i<data.length;i++) { data[i].put("time", new Long(System.currentTimeMillis())); container.put(data[i].get("address"), data[i]); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -