summaryrefslogtreecommitdiff
path: root/src/swing/scala/swing/PopupMenu.scala
blob: e82c3a1b28b6486b2c8fa00881f74c7f6f089b74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2007-2013, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */



package scala.swing

import javax.swing.JPopupMenu
import javax.swing.event.{PopupMenuListener, PopupMenuEvent}
import event._

/**
 * A popup menu.
 * 
 * Example usage:
 *
 * {{{
 * val popupMenu = new PopupMenu {
 *   contents += new Menu("menu 1") {
 *     contents += new RadioMenuItem("radio 1.1")
 *     contents += new RadioMenuItem("radio 1.2")
 *   }
 *   contents += new Menu("menu 2") {
 *     contents += new RadioMenuItem("radio 2.1")
 *     contents += new RadioMenuItem("radio 2.2")
 *   }
 * }
 * val button = new Button("Show Popup Menu")
 * reactions += {
 *   case e: ButtonClicked => popupMenu.show(button, 0, button.bounds.height)
 * }
 * listenTo(button)
 * }}}
 * 
 * @author John Sullivan
 * @author Ingo Maier
 * @see javax.swing.JPopupMenu
 */
class PopupMenu extends Component with SequentialContainer.Wrapper with Publisher {
  override lazy val peer: JPopupMenu = new JPopupMenu with SuperMixin 

  peer.addPopupMenuListener(new PopupMenuListener {
  	def popupMenuCanceled(e: PopupMenuEvent) {
  	  publish(PopupMenuCanceled(PopupMenu.this))
  	}
  	def popupMenuWillBecomeInvisible(e: PopupMenuEvent) {
  	  publish(PopupMenuWillBecomeInvisible(PopupMenu.this))
  	}
  	def popupMenuWillBecomeVisible(e: PopupMenuEvent) {
  	  publish(PopupMenuWillBecomeVisible(PopupMenu.this))
  	}
  })

  def show(invoker: Component, x: Int, y: Int): Unit = peer.show(invoker.peer, x, y)

  def margin: Insets = peer.getMargin
  def label: String = peer.getLabel
  def label_=(s: String) { peer.setLabel(s) }
}