blob: 6d0c34375e32dad7ef2ecf787d73cf37f0df0f84 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner <florian.pirchner@gmail.com> - Initial implementation
*/
package org.eclipse.osbp.vaadin.addons.keyevents.sample;
import javax.servlet.annotation.WebServlet;
import org.eclipse.osbp.vaadin.addons.keyevents.KeyEventExtension;
import com.vaadin.annotations.Push;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
@SuppressWarnings("serial")
@Theme("valo")
// @Push(transport = Transport.LONG_POLLING, value = PushMode.AUTOMATIC)
@Push
public class KeyEventsSample extends UI {
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = KeyEventsSample.class, widgetset = "org.eclipse.osbp.vaadin.addons.keyevents.KeyEventsWidgetset")
public static class Servlet extends VaadinServlet {
String a = "";
}
@Override
protected void init(VaadinRequest request) {
Panel p1 = new Panel();
setContent(p1);
Panel p2 = new Panel();
p1.setContent(p2);
TextField t = new TextField("text");
p2.setContent(t);
KeyEventExtension ext = KeyEventExtension.addTo(p2);
ext.setCallback(e -> {
if(e.charCode > 95 && e.charCode < 106 ) {
e.charCode -= 48;
} else if(!e.shiftKeyDown && e.charCode > 57 && e.charCode < 91) {
e.charCode += 32;
} else if(e.shiftKeyDown && e.charCode > 47 && e.charCode < 58) {
e.charCode -= 16;
} else if(e.charCode == 192) { // ö
if(e.shiftKeyDown) {
e.charCode = 0xD6;
} else {
e.charCode = 0xF6;
}
} else if(e.charCode == 222) { // ä
if(e.shiftKeyDown) {
e.charCode = 0xC4;
} else {
e.charCode = 0xE4;
}
} else if(e.charCode == 186) { // ü
if(e.shiftKeyDown) {
e.charCode = 0xDC;
} else {
e.charCode = 0xFC;
}
} else if(e.charCode == 219) { // ß
if(e.shiftKeyDown) {
e.charCode = 63;
} else {
e.charCode = 0xDF;
}
}
t.setValue(t.getValue() + (char)e.charCode);
return;
// t.setValue(" "+e.charCode+" "+(char)e.charCode);
});
this.focus();
}
}