Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add shortcut keys and modifiers, update tests

  • Loading branch information...
commit 8ea249077d0d259e378a234da20f1fa3c1cba9dc 1 parent ced7430
@ripla ripla authored
View
4 addon/src/main/scala/vaadin/scala/Button.scala
@@ -35,7 +35,7 @@ package listeners {
}
class Button(override val p: com.vaadin.ui.Button with ButtonMixin = new com.vaadin.ui.Button with ButtonMixin)
- extends AbstractField(p) with BlurNotifier with FocusNotifier {
+ extends AbstractField(p) with BlurNotifier with FocusNotifier {
private var _clickShortcut: Option[KeyShortcut] = None
@@ -44,7 +44,7 @@ class Button(override val p: com.vaadin.ui.Button with ButtonMixin = new com.vaa
_clickShortcut = clickShortcut
clickShortcut match {
case None => p.removeClickShortcut
- case Some(clickShortcut) => p.setClickShortcut(clickShortcut.keyCode, clickShortcut.modifiers: _*)
+ case Some(clickShortcut) => p.setClickShortcut(clickShortcut.keyCode.value, clickShortcut.modifiers.map(_.value): _*)
}
}
def clickShortcut_=(clickShortcut: KeyShortcut): Unit = this.clickShortcut = Option(clickShortcut)
View
146 addon/src/main/scala/vaadin/scala/Shortcut.scala
@@ -1,4 +1,146 @@
package vaadin.scala
-// FIXME: keyCode and modifiers should be something else than Ints
-case class KeyShortcut(keyCode: Int, modifiers: Int*)
+case class KeyShortcut(keyCode: KeyCode, modifiers: KeyModifier*)
+
+case class KeyCode(value: Int)
+case class KeyModifier(value: Int)
+
+object KeyCode {
+ //FIXME: case correct
+ val ENTER = KeyCode(13)
+
+ val ESCAPE = KeyCode(27)
+
+ val PAGE_UP = KeyCode(33)
+
+ val PAGE_DOWN = KeyCode(34)
+
+ val TAB = KeyCode(9)
+
+ val ARROW_LEFT = KeyCode(37)
+
+ val ARROW_UP = KeyCode(38)
+
+ val ARROW_RIGHT = KeyCode(39)
+
+ val ARROW_DOWN = KeyCode(40)
+
+ val BACKSPACE = KeyCode(8)
+
+ val DELETE = KeyCode(46)
+
+ val INSERT = KeyCode(45)
+
+ val END = KeyCode(35)
+
+ val HOME = KeyCode(36)
+
+ val F1 = KeyCode(112)
+
+ val F2 = KeyCode(113)
+
+ val F3 = KeyCode(114)
+
+ val F4 = KeyCode(115)
+
+ val F5 = KeyCode(116)
+
+ val F6 = KeyCode(117)
+
+ val F7 = KeyCode(118)
+
+ val F8 = KeyCode(119)
+
+ val F9 = KeyCode(120)
+
+ val F10 = KeyCode(121)
+
+ val F11 = KeyCode(122)
+
+ val F12 = KeyCode(123)
+
+ val A = KeyCode(65)
+
+ val B = KeyCode(66)
+
+ val C = KeyCode(67)
+
+ val D = KeyCode(68)
+
+ val E = KeyCode(69)
+
+ val F = KeyCode(70)
+
+ val G = KeyCode(71)
+
+ val H = KeyCode(72)
+
+ val I = KeyCode(73)
+
+ val J = KeyCode(74)
+
+ val K = KeyCode(75)
+
+ val L = KeyCode(76)
+
+ val M = KeyCode(77)
+
+ val N = KeyCode(78)
+
+ val O = KeyCode(79)
+
+ val P = KeyCode(80)
+
+ val Q = KeyCode(81)
+
+ val R = KeyCode(82)
+
+ val S = KeyCode(83)
+
+ val T = KeyCode(84)
+
+ val U = KeyCode(85)
+
+ val V = KeyCode(86)
+
+ val W = KeyCode(87)
+
+ val X = KeyCode(88)
+
+ val Y = KeyCode(89)
+
+ val Z = KeyCode(90)
+
+ val NUM0 = KeyCode(48)
+
+ val NUM1 = KeyCode(49)
+
+ val NUM2 = KeyCode(50)
+
+ val NUM3 = KeyCode(51)
+
+ val NUM4 = KeyCode(52)
+
+ val NUM5 = KeyCode(53)
+
+ val NUM6 = KeyCode(54)
+
+ val NUM7 = KeyCode(55)
+
+ val NUM8 = KeyCode(56)
+
+ val NUM9 = KeyCode(57)
+
+ val SPACEBAR = KeyCode(32)
+}
+
+object KeyModifier {
+ //FIXME: case correct
+ val SHIFT = KeyModifier(16)
+
+ val CTRL = KeyModifier(17)
+
+ val ALT = KeyModifier(18)
+
+ val META = KeyModifier(91)
+}
View
17 addon/src/main/scala/vaadin/scala/Window.scala
@@ -12,7 +12,7 @@ class WindowCloseListener(action: com.vaadin.ui.Window#CloseEvent => Unit) exten
}
class Window(override val p: com.vaadin.ui.Window with WindowMixin = new com.vaadin.ui.Window with WindowMixin)
- extends Panel(p) with BlurNotifier with FocusNotifier {
+ extends Panel(p) with BlurNotifier with FocusNotifier {
def positionX_=(positionX: Int) = p.setPositionX(positionX)
def positionX: Int = p.getPositionX
@@ -43,17 +43,16 @@ class Window(override val p: com.vaadin.ui.Window with WindowMixin = new com.vaa
_closeShortcut = cs
closeShortcut match {
case None => p.removeCloseShortcut()
- case Some(closeShortcut) => p.setCloseShortcut(closeShortcut.keyCode, closeShortcut.modifiers: _*)
+ case Some(closeShortcut) => p.setCloseShortcut(closeShortcut.keyCode.value, closeShortcut.modifiers.map(_.value): _*)
}
}
def closeShortcut_=(cs: KeyShortcut): Unit = this.closeShortcut = Option(cs)
-
// TODO: return wrapped Terminal
def terminal = Option(p.getTerminal)
-
+
override def parent: Option[Window] = wrapperFor[Window](p.getParent)
-
+
def theme: Option[String] = Option(p.getTheme)
def theme_=(theme: Option[String]) = p.setTheme(theme.getOrElse(null))
def theme_=(theme: String) = p.setTheme(theme)
@@ -68,16 +67,16 @@ class Window(override val p: com.vaadin.ui.Window with WindowMixin = new com.vaa
def draggable_=(draggable: Boolean) = p.setDraggable(draggable)
def draggable: Boolean = p.isDraggable
-
+
def name: Option[String] = Option(p.getName)
def name_=(name: Option[String]) = p.setName(name.getOrElse(null))
def name_=(name: String) = p.setName(name)
-
+
def scrollIntoView(component: Component) = p.scrollIntoView(component.p)
-
+
def browserWindowHeight: Int = p.getBrowserWindowHeight
def browserWindowWidth: Int = p.getBrowserWindowWidth
-
+
def executeJavaScript(javaScript: String) = p.executeJavaScript(javaScript)
def showNotification(caption: String) = p.showNotification(caption)
View
8 addon/src/test/scala/vaadin/scala/tests/ButtonTests.scala
@@ -22,7 +22,7 @@ class ButtonTests extends FunSuite {
test("clickShortcut") {
val button = new Button
- val clickShortcut = KeyShortcut(com.vaadin.event.ShortcutAction.KeyCode.ENTER);
+ val clickShortcut = KeyShortcut(KeyCode.ENTER, KeyModifier.SHIFT);
assert(button.clickShortcut === None)
@@ -38,12 +38,12 @@ class ButtonTests extends FunSuite {
test("htmlContentAllowed") {
val button = new Button
-
+
assert(!button.htmlContentAllowed)
-
+
button.htmlContentAllowed = true
assert(button.htmlContentAllowed)
-
+
}
test("clickListeners, add a clicklistener") {
View
6 addon/src/test/scala/vaadin/scala/tests/WindowTests.scala
@@ -130,7 +130,7 @@ class WindowTests extends FunSuite with BeforeAndAfter with MockitoSugar {
window.browserWindowWidth
Mockito.verify(vaadinWindowSpy).getBrowserWindowWidth
}
-
+
test("javascript") {
window.executeJavaScript("javascript")
Mockito.verify(vaadinWindowSpy).executeJavaScript("javascript")
@@ -166,11 +166,11 @@ class WindowTests extends FunSuite with BeforeAndAfter with MockitoSugar {
window.showNotification(notification)
Mockito.verify(vaadinWindowSpy).showNotification(notification.p)
}
-
+
test("closeShortcut") {
val window = new Window
- val clickShortcut = KeyShortcut(com.vaadin.event.ShortcutAction.KeyCode.ENTER);
+ val clickShortcut = KeyShortcut(KeyCode.ENTER, KeyModifier.ALT);
assert(window.closeShortcut === None)
Please sign in to comment.
Something went wrong with that request. Please try again.