All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xworker.swt.util.VerifyEventToInputStream Maven / Gradle / Ivy

package xworker.swt.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;

public class VerifyEventToInputStream implements VerifyKeyListener{
	PipedInputStream in = null;
	PipedOutputStream out = null;
	boolean doit = false;
	
	public VerifyEventToInputStream(boolean doit) throws IOException{
		out = new PipedOutputStream();
		in = new PipedInputStream(out);
		this.doit = doit;
	}
	
	public InputStream getInputStream(){
		return in;
	}

	@Override
	public void verifyKey(VerifyEvent event) {
		try {
			if(event.text != null){
				out.write(event.text.getBytes());
			}else if(event.character != -1){
				out.write(event.character);
			}
			
			
			event.doit = doit;
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy