Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package examples.swing | ||
|
||
import swing._ | ||
import event._ | ||
import Swing._ | ||
|
||
/** | ||
* @author John Sullivan | ||
* @author Ingo Maier | ||
*/ | ||
object PopupDemo extends SimpleSwingApplication { | ||
def top = new MainFrame { | ||
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 ButtonClicked(b) => popupMenu.show(b, 0, b.bounds.height) | ||
case PopupMenuCanceled(m) => println("Menu " + m + " canceled.") | ||
} | ||
listenTo(popupMenu) | ||
listenTo(button) | ||
|
||
contents = new FlowPanel(button) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2007-2012, 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) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ Scala API ** | ||
** / __/ __// _ | / / / _ | (c) 2007-2012, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | ||
** /____/\___/_/ |_/____/_/ | | ** | ||
** |/ ** | ||
\* */ | ||
|
||
|
||
|
||
package scala.swing | ||
package event | ||
|
||
abstract class PopupMenuEvent extends ComponentEvent | ||
|
||
case class PopupMenuCanceled(source: PopupMenu) extends PopupMenuEvent | ||
case class PopupMenuWillBecomeInvisible(source: PopupMenu) extends PopupMenuEvent | ||
case class PopupMenuWillBecomeVisible(source: PopupMenu) extends PopupMenuEvent |