Hi

I have a problem with extension to ULCMobile TextField for Symbol barcode
scanner support. I need to call setValue() when scan button on device is
pressed and then to transfer focus to the next focusable component. 

As I don't know any other way to test this behaviour, I test it in
development mode by KeyboardAction being registered when the focus on
textfield is gained and unregistered when the focus is lost.
Everything's working fine this way, but the code is deployed to the target
device (Symbol MC9090), the test application is not responding.
The test application registers FocusListener and ValueChangeListener in
order to log the behaviour.

I think the order of the events in the development mode is different from
the one happening on the actual device. In the device log, there are no
statements about the focus being transfered.

Log from development mode:

application started
1191223496248 client focus gained listener: registered.keyboardaction
1191223496264 server focus gained listener: componentName ean8
1191223497811 client action listener: getValue null
1191223497811 client action listener: setValue value 1
1191223497811 client action listener: updateStateULC
1191223497811 client action listener: fireValueChangedULC
1191223497826 server valuechanged listener: setText 1: 52 - value 1
1191223497826 client action listener: transferFocus
1191223497826 client focus lost listener: unregistered.keyboardaction
1191223497826 server focus lost listener: componentName ean8
1191223497826 client focus gained listener: registered.keyboardaction
1191223497842 server focus gained listener: componentName ean8_2
1191223499045 client action listener: getValue null
1191223499045 client action listener: setValue value 1
1191223499045 client action listener: updateStateULC
1191223499045 client action listener: fireValueChangedULC
1191223499061 server valuechanged listener: setText 2: 52 - value 1
1191223499061 client action listener: transferFocus
1191223499061 client focus lost listener: unregistered.keyboardaction
1191223499061 server focus lost listener: componentName ean8_2
1191223499061 client focus gained listener: registered.keyboardaction
1191223499061 server focus gained listener: componentName ean8 dispose
Dispose

Client log from device:
1191137864267 client focus gained listener: registered.keyboardaction
1191137869603 client action listener: getValue null
1191137869776 client action listener: setValue value 1
1191137870084 client action listener: updateStateULC
1191137870247 client action listener: fireValueChangedULC
1191137870627 client focus lost listener: unregistered.keyboardaction
1191137871019 client focus gained listener: registered.keyboardaction

Server log (times arent synchronized on client and server):
09:37:15,587 INFO  [STDOUT] application started
09:37:19,618 INFO  [STDOUT] 1191224239618 server focus gained listener:
componentName ean8
09:37:25,431 INFO  [STDOUT] 1191224245431 server valuechanged listener:
setText 1: 52 - value 1
09:37:25,837 INFO  [STDOUT] 1191224245837 server focus lost listener:
componentName ean8

Application was terminated, so dispose messages are missing.

Thanks for reply

Vlado


--------------------------------------------------------------------------
Tato sprava a vsetky pripojene subory su doverne a urcene vyhradne osobam
alebo organizaciam, ktorym boli adresovane. Ak ste dostali tento e-mail
omylom, prosim, upovedomte Chemosvit, a.s. ([EMAIL PROTECTED]).

This email and any files transmitted are confidential and intended
solely for the use of the individual or entity to which they are
addressed. If you have received this email in error, please notify
Chemosvit, a.s. ([EMAIL PROTECTED]).
--------------------------------------------------------------------------- 
import com.ulcmobile.base.application.ULCTextField;

public class ULCSymbolTextField extends ULCTextField {
	private static final long serialVersionUID = 1L;

	public static final byte DECODER_UPCE0 = 48;
	public static final byte DECODER_UPCE1 = 49;
	public static final byte DECODER_UPCA = 50;
	public static final byte DECODER_MSI = 51;
	public static final byte DECODER_EAN8 = 52;
	public static final byte DECODER_EAN13 = 53;
	public static final byte DECODER_CODABAR = 54;
	public static final byte DECODER_CODE39 = 55;
	public static final byte DECODER_D2OF5 = 56;
	public static final byte DECODER_I2OF5 = 57;
	public static final byte DECODER_CODE11 = 58;
	public static final byte DECODER_CODE93 = 59;
	public static final byte DECODER_CODE128 = 60;
	public static final byte DECODER_PDF417 = 64;
	public static final byte DECODER_TRIOPTIC39 = 66;
	public static final byte DECODER_MICROPDF = 69;
	public static final byte DECODER_MAXICODE = 72;
	public static final byte DECODER_DATAMATRIX = 73;
	public static final byte DECODER_QRCODE = 74;
	public static final byte DECODER_POINTER = 80;
	public static final byte DECODER_IMAGE = 81;
	public static final byte DECODER_SIGNATURE = 82;
	public static final byte DECODER_USPOSTNET = 97;
	public static final byte DECODER_USPLANET = 98;
	public static final byte DECODER_UKPOSTAL = 99;
	public static final byte DECODER_JAPPOSTAL = 100;
	public static final byte DECODER_AUSPOSTAL = 101;
	public static final byte DECODER_DUTCHPOSTAL = 102;

	private byte decoderId;

	public ULCSymbolTextField(byte decoderId) {
		this(decoderId, null, 0);
	}

	public ULCSymbolTextField(byte decoderId, int columns) {
		this(decoderId, null, columns);
	}

	public ULCSymbolTextField(byte decoderId, String text, int columns) {
		super(text, columns);
		this.decoderId = decoderId;
	}

	public ULCSymbolTextField(byte decoderId, String text) {
		this(decoderId, text, 0);
	}

	public String typeString() {
		return "UISymbolTextField";
	}

	protected void uploadStateUI() {
		super.uploadStateUI();
		setStateUI("decoderId", null, decoderId);
	}

	public byte getDecoderId() {
		return decoderId;
	}

	public void setDecoderId(byte decoderId) {
		this.decoderId = setStateUI("decoderId", this.decoderId, decoderId);
	}
}
import com.ulcmobile.base.application.AbstractApplication;
import com.ulcmobile.base.application.ULCBoxPane;
import com.ulcmobile.base.application.ULCContainer;
import com.ulcmobile.base.application.ULCFrame;
import com.ulcmobile.base.application.ULCLabel;
import com.ulcmobile.base.application.ULCTextField;
import com.ulcmobile.base.application.event.FocusEvent;
import com.ulcmobile.base.application.event.ValueChangedEvent;
import com.ulcmobile.base.application.event.serializable.IFocusListener;
import com.ulcmobile.base.application.event.serializable.IValueChangedListener;
import com.ulcmobile.base.development.DevelopmentRunner;

public class TestSymbolComponent extends AbstractApplication {
	private static final long serialVersionUID = 1L;

	private static int scanCounter = 0;
	private ULCSymbolTextField ean8;
	private ULCSymbolTextField ean8_2;
	private ULCLabel output;

	public void start() {
		System.out.println("application started");
		ULCFrame frame = new ULCFrame("Symbol Test");
		frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
		//frame.setSize(ClientContext.getScreenWidth(), ClientContext.getScreenHeight());
		frame.setSize(240,240);
		frame.setContentPane(createContent());
		frame.setResizable(true);
		frame.setVisible(true);
		ean8.requestFocus();
	}

	private ULCContainer createContent() {
		ULCBoxPane content = new ULCBoxPane(2, 2);
		ean8 = new ULCSymbolTextField(ULCSymbolTextField.DECODER_EAN8);
		ean8.setName("ean8");
		ean8.addFocusListener(new TestFocusListener());
		ean8.addValueChangedListener(new ScanOutputListener());
		ean8_2 = new ULCSymbolTextField(ULCSymbolTextField.DECODER_EAN8);
		ean8_2.setName("ean8_2");
		ean8_2.addFocusListener(new TestFocusListener());
		ean8_2.addValueChangedListener(new ScanOutputListener());
		
		output = new ULCLabel("");
		content.add(new ULCLabel("EAN8"));
		content.add(ULCBoxPane.BOX_EXPAND_CENTER, ean8);
		content.add(new ULCLabel("EAN8 2"));
		content.add(ULCBoxPane.BOX_EXPAND_CENTER, ean8_2);
		content.add(2, ULCBoxPane.BOX_EXPAND_CENTER, output);
		return content;
	}

	private class TestFocusListener implements IFocusListener{
		private static final long serialVersionUID = 1L;
		public void focusGained(FocusEvent event) {
			System.out.println(System.currentTimeMillis() + " server focus gained listener: componentName " + ((ULCTextField)event.getSource()).getName());
		}

		public void focusLost(FocusEvent event) {
			System.out.println(System.currentTimeMillis() + " server focus lost listener: componentName " + ((ULCTextField)event.getSource()).getName());
		}
	}
		
	private class ScanOutputListener implements IValueChangedListener{
		private static final long serialVersionUID = 1L;
		public void valueChanged(ValueChangedEvent event) {
			ULCSymbolTextField source = (ULCSymbolTextField)event.getSource();
			String text = ++scanCounter + ": " + source.getDecoderId() + " - "+ source.getText();
			System.out.println(System.currentTimeMillis() + " server valuechanged listener: setText " + text);
			output.setText(text);
		}
	}
	
	public static void main(String[] args) {
		DevelopmentRunner.setApplicationClass(TestSymbolComponent.class);
		DevelopmentRunner.main(args);
	}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;

import javax.swing.JComponent;
import javax.swing.KeyStroke;

import com.ulcmobile.base.client.UITextField;

public class UISymbolTextField extends UITextField {

	protected void postInitializeState() {
		getBasicTextField().addFocusListener(new StartScanListener());
		super.postInitializeState();
	}

	public void setDecoderId(byte decoderId) {
	}

	private class StartScanListener implements FocusListener {
		private ActionListener listener;

		public void focusGained(FocusEvent e) {
			if (!e.isTemporary()) {
					if (listener == null) {
						listener = new MyScannerListener();
					}
					System.out.println(System.currentTimeMillis() + " client focus gained listener: registered.keyboardaction");					
					getBasicTextField().registerKeyboardAction(listener, KeyStroke.getKeyStroke(KeyEvent.VK_F12, KeyEvent.VK_UNDEFINED), JComponent.WHEN_FOCUSED);
			}
		}

		public void focusLost(FocusEvent e) {
			if (!e.isTemporary()) {
				System.out.println(System.currentTimeMillis() + " client focus lost listener: unregistered.keyboardaction");
				getBasicTextField().unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_F12, KeyEvent.VK_UNDEFINED));
			}
		}
	}

	public void dispose() {
		super.dispose();
		System.out.println("dispose");
	}

	private class MyScannerListener implements ActionListener {
		private int counter = 0;
		public void actionPerformed(ActionEvent e) {
				String text = "value " + ++counter ;
				System.out.println(System.currentTimeMillis() + " client action listener: getValue " + getValue());
				System.out.println(System.currentTimeMillis() + " client action listener: setValue " + text);
				setValue(text);
				System.out.println(System.currentTimeMillis() + " client action listener: updateStateULC");
				updateStateULC("value", text);
				System.out.println(System.currentTimeMillis() + " client action listener: fireValueChangedULC");
				fireValueChangedULC();
				getBasicTextComponent().transferFocus();
				System.out.println(System.currentTimeMillis() + " client action listener: transferFocus");
		}
	}

}

Reply via email to