Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add shortcut keys and modifiers, update tests
  • Loading branch information
Risto Yrjänä committed Jul 22, 2012
1 parent ced7430 commit 8ea2490
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 20 deletions.
4 changes: 2 additions & 2 deletions addon/src/main/scala/vaadin/scala/Button.scala
Expand Up @@ -35,7 +35,7 @@ package listeners {
} }


class Button(override val p: com.vaadin.ui.Button with ButtonMixin = new com.vaadin.ui.Button with ButtonMixin) 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 private var _clickShortcut: Option[KeyShortcut] = None


Expand All @@ -44,7 +44,7 @@ class Button(override val p: com.vaadin.ui.Button with ButtonMixin = new com.vaa
_clickShortcut = clickShortcut _clickShortcut = clickShortcut
clickShortcut match { clickShortcut match {
case None => p.removeClickShortcut 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) def clickShortcut_=(clickShortcut: KeyShortcut): Unit = this.clickShortcut = Option(clickShortcut)
Expand Down
146 changes: 144 additions & 2 deletions addon/src/main/scala/vaadin/scala/Shortcut.scala
@@ -1,4 +1,146 @@
package vaadin.scala package vaadin.scala


// FIXME: keyCode and modifiers should be something else than Ints case class KeyShortcut(keyCode: KeyCode, modifiers: KeyModifier*)
case class KeyShortcut(keyCode: Int, modifiers: Int*)
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)
}
17 changes: 8 additions & 9 deletions addon/src/main/scala/vaadin/scala/Window.scala
Expand Up @@ -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) 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_=(positionX: Int) = p.setPositionX(positionX)
def positionX: Int = p.getPositionX def positionX: Int = p.getPositionX
Expand Down Expand Up @@ -43,17 +43,16 @@ class Window(override val p: com.vaadin.ui.Window with WindowMixin = new com.vaa
_closeShortcut = cs _closeShortcut = cs
closeShortcut match { closeShortcut match {
case None => p.removeCloseShortcut() 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) def closeShortcut_=(cs: KeyShortcut): Unit = this.closeShortcut = Option(cs)



// TODO: return wrapped Terminal // TODO: return wrapped Terminal
def terminal = Option(p.getTerminal) def terminal = Option(p.getTerminal)

override def parent: Option[Window] = wrapperFor[Window](p.getParent) override def parent: Option[Window] = wrapperFor[Window](p.getParent)

def theme: Option[String] = Option(p.getTheme) def theme: Option[String] = Option(p.getTheme)
def theme_=(theme: Option[String]) = p.setTheme(theme.getOrElse(null)) def theme_=(theme: Option[String]) = p.setTheme(theme.getOrElse(null))
def theme_=(theme: String) = p.setTheme(theme) def theme_=(theme: String) = p.setTheme(theme)
Expand All @@ -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_=(draggable: Boolean) = p.setDraggable(draggable)
def draggable: Boolean = p.isDraggable def draggable: Boolean = p.isDraggable

def name: Option[String] = Option(p.getName) def name: Option[String] = Option(p.getName)
def name_=(name: Option[String]) = p.setName(name.getOrElse(null)) def name_=(name: Option[String]) = p.setName(name.getOrElse(null))
def name_=(name: String) = p.setName(name) def name_=(name: String) = p.setName(name)

def scrollIntoView(component: Component) = p.scrollIntoView(component.p) def scrollIntoView(component: Component) = p.scrollIntoView(component.p)

def browserWindowHeight: Int = p.getBrowserWindowHeight def browserWindowHeight: Int = p.getBrowserWindowHeight
def browserWindowWidth: Int = p.getBrowserWindowWidth def browserWindowWidth: Int = p.getBrowserWindowWidth

def executeJavaScript(javaScript: String) = p.executeJavaScript(javaScript) def executeJavaScript(javaScript: String) = p.executeJavaScript(javaScript)


def showNotification(caption: String) = p.showNotification(caption) def showNotification(caption: String) = p.showNotification(caption)
Expand Down
8 changes: 4 additions & 4 deletions addon/src/test/scala/vaadin/scala/tests/ButtonTests.scala
Expand Up @@ -22,7 +22,7 @@ class ButtonTests extends FunSuite {
test("clickShortcut") { test("clickShortcut") {
val button = new Button val button = new Button


val clickShortcut = KeyShortcut(com.vaadin.event.ShortcutAction.KeyCode.ENTER); val clickShortcut = KeyShortcut(KeyCode.ENTER, KeyModifier.SHIFT);


assert(button.clickShortcut === None) assert(button.clickShortcut === None)


Expand All @@ -38,12 +38,12 @@ class ButtonTests extends FunSuite {


test("htmlContentAllowed") { test("htmlContentAllowed") {
val button = new Button val button = new Button

assert(!button.htmlContentAllowed) assert(!button.htmlContentAllowed)

button.htmlContentAllowed = true button.htmlContentAllowed = true
assert(button.htmlContentAllowed) assert(button.htmlContentAllowed)

} }


test("clickListeners, add a clicklistener") { test("clickListeners, add a clicklistener") {
Expand Down
6 changes: 3 additions & 3 deletions addon/src/test/scala/vaadin/scala/tests/WindowTests.scala
Expand Up @@ -130,7 +130,7 @@ class WindowTests extends FunSuite with BeforeAndAfter with MockitoSugar {
window.browserWindowWidth window.browserWindowWidth
Mockito.verify(vaadinWindowSpy).getBrowserWindowWidth Mockito.verify(vaadinWindowSpy).getBrowserWindowWidth
} }

test("javascript") { test("javascript") {
window.executeJavaScript("javascript") window.executeJavaScript("javascript")
Mockito.verify(vaadinWindowSpy).executeJavaScript("javascript") Mockito.verify(vaadinWindowSpy).executeJavaScript("javascript")
Expand Down Expand Up @@ -166,11 +166,11 @@ class WindowTests extends FunSuite with BeforeAndAfter with MockitoSugar {
window.showNotification(notification) window.showNotification(notification)
Mockito.verify(vaadinWindowSpy).showNotification(notification.p) Mockito.verify(vaadinWindowSpy).showNotification(notification.p)
} }

test("closeShortcut") { test("closeShortcut") {
val window = new Window val window = new Window


val clickShortcut = KeyShortcut(com.vaadin.event.ShortcutAction.KeyCode.ENTER); val clickShortcut = KeyShortcut(KeyCode.ENTER, KeyModifier.ALT);


assert(window.closeShortcut === None) assert(window.closeShortcut === None)


Expand Down

0 comments on commit 8ea2490

Please sign in to comment.