Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/scala/scala/swing/BoxPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package scala.swing


/**
* A panel that lays out its contents one after the other,
* either horizontally or vertically.
Expand All @@ -23,4 +24,10 @@ class BoxPanel(orientation: Orientation.Value) extends Panel with SequentialCont
p.setLayout(l)
p
}

def alignmentX = peer.getAlignmentX
def alignmentX_=(a:Alignment.Value) peer.setAlignmentX(a.id)

def alignmentY = peer.getAlignmentY
def alignmentY_=(a:Alignment.Value) peer.setAlignmentX(a.id)
}
8 changes: 5 additions & 3 deletions src/main/scala/scala/swing/Button.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ object Button {
*
* @see javax.swing.JButton
*/
class Button(text0: String) extends AbstractButton with Publisher {
override lazy val peer: JButton = new JButton(text0) with SuperMixin
def this() = this("")
class Button(text0: String, icon0:Icon) extends AbstractButton with Publisher {
override lazy val peer: JButton = new JButton(text0, toNullIcon(icon0)) with SuperMixin
def this() = this("", EmptyIcon)
def this(s:String) = this(s, EmptyIcon)
def this(i:Icon) = this("", i)
def this(a: Action) = {
this("")
action = a
Expand Down
71 changes: 71 additions & 0 deletions src/main/scala/scala/swing/CardPanel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2007-2010, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */

package scala.swing

import swing.CardPanel.Card


object CardPanel {
class Card protected[CardPanel](val comp: scala.swing.Component, val name: String) extends Proxy {
def self = comp

}
}

/**
* A panel that displays only one component at a time.
* based on: http://download.oracle.com/javase/tutorial/uiswing/layout/card.html
*
* @author andy hicks
* @see java.awt.CardLayout
*/
class CardPanel(hgap: Int, vgap: Int) extends Panel with Publisher {
def this() = this(0, 0)

peer.setLayout(new java.awt.CardLayout(vgap, hgap))
private def cardLayout = peer.getLayout.asInstanceOf[java.awt.CardLayout]




object card extends BufferWrapper[Card] {
/** add card to panel. */
def +=(card:Card):this.type = { peer.add(card.comp.peer, card.name);this }

protected def insertAt(n: Int, c: Card) {
peer.add(c.comp.peer, n.toString)
}

override def remove(n: Int): Card = { val t = peer.getComponent(n);peer.remove(n);t.asInstanceOf[Card]}
def length = peer.getComponentCount
def apply(n: Int) = new Card(UIElement.cachedWrapper[Component](peer.getComponent(n).asInstanceOf[javax.swing.JComponent]), "")

}


/** Show the first item. */
def first { cardLayout.first(peer) }

/** Show the last item. */
def last { cardLayout.last(peer) }

/** Show the previous item. */
def next { cardLayout.next(peer) }

/** Show the previous item. */
def previous { cardLayout.previous(peer) }

/** Show the Nth item. */
def show(s: String) { cardLayout.show( peer, s) }

// def vGap: Int = layoutManager.getVgap
// def vGap_=(n: Int) { layoutManager.setVgap(n) }
// def hGap: Int = layoutManager.getHgap
// def hGap_=(n: Int) { layoutManager.setHgap(n) }
}
9 changes: 6 additions & 3 deletions src/main/scala/scala/swing/CheckBox.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import javax.swing._
*
* @see javax.swing.JCheckBox
*/
class CheckBox(text: String) extends ToggleButton {
override lazy val peer: JCheckBox = new JCheckBox(text) with SuperMixin
def this() = this("")
class CheckBox(text: String, icon0:Icon, selected:Boolean) extends ToggleButton {
override lazy val peer: JCheckBox = new JCheckBox(text, toNullIcon(icon0), selected) with SuperMixin
def this() = this("", EmptyIcon, false)
def this(text:String) = this(text, EmptyIcon, false)
def this(text:String, icon:Icon) = this(text, icon, false)
def this(icon:Icon) = this("", icon, false)

def borderPaintedFlat: Boolean = peer.isBorderPaintedFlat
def borderPaintedFlat_=(flat: Boolean) { peer.setBorderPaintedFlat(flat) }
Expand Down
49 changes: 49 additions & 0 deletions src/main/scala/scala/swing/ColorChooser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2007-2010, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */



package scala.swing

case class ColorChangeEvent( c: Color) extends event.Event

/**
* Wrapper for JColorChooser.
*
* @author [email protected]
* @see javax.swing.JColorChooser
*/
object ColorChooser {
def showDialog(parent:Component, title:String, color:Color ): scala.Option[Color] = {
toOption[Color](javax.swing.JColorChooser.showDialog(parent.peer, title, color))
}

}

class ColorChooser( color0: java.awt.Color ) extends Component {
import javax.swing.JColorChooser

def this() = this( java.awt.Color.white )

override lazy val peer:JColorChooser = new javax.swing.JColorChooser(color0) with SuperMixin

peer.getSelectionModel().addChangeListener(new javax.swing.event.ChangeListener {
def stateChanged(e: javax.swing.event.ChangeEvent) {
publish( new ColorChangeEvent(peer.getColor))
}
})



def color: Color = peer.getColor
def color_=(c: Color) = peer.setColor(c)

def dragEnabled: Boolean = peer.getDragEnabled
def dragEnabled_=(b: Boolean) = peer.setDragEnabled(b)

}
3 changes: 3 additions & 0 deletions src/main/scala/scala/swing/Label.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Label(text0: String, icon0: Icon, align: Alignment.Value) extends Componen

def this() = this("", EmptyIcon, Alignment.Center)
def this(s: String) = this(s, EmptyIcon, Alignment.Center)
def this(s: String, a:Alignment.Value) = this(s, EmptyIcon, a)
def this(icon1: Icon) = this("", icon1, Alignment.Center)

def text: String = peer.getText
def text_=(s: String) = peer.setText(s)
def icon: Icon = peer.getIcon
Expand Down
6 changes: 4 additions & 2 deletions src/main/scala/scala/swing/RichWindow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ sealed trait RichWindow extends Window {

def title: String = peer.getTitle
def title_=(s: String) = peer.setTitle(s)



/**
* The menu bar of this frame or `NoMenuBar` if no menu bar is set.
*/
Expand Down Expand Up @@ -91,7 +92,8 @@ class Frame extends RichWindow {
def maximize() { peer.setExtendedState(peer.getExtendedState | AWTFrame.MAXIMIZED_BOTH) }
def unmaximize() { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.MAXIMIZED_BOTH) }
def maximized() { (peer.getExtendedState & AWTFrame.MAXIMIZED_BOTH) != 0 }



def iconImage: Image = peer.getIconImage
def iconImage_=(i: Image) { peer.setIconImage(i) }
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/scala/swing/Swing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ object Swing {

def TitledBorder(border: Border, title: String) =
BorderFactory.createTitledBorder(border, title)


def TitledBorder(title: String) = BorderFactory.createTitledBorder(title)

/**
* Schedule the given code to be executed on the Swing event dispatching
* thread (EDT). Returns immediately.
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/scala/swing/TabbedPane.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ class TabbedPane extends Component with Publisher {
* Possible values are Left, Right, Top, Bottom.
*/
def tabPlacement(b: Alignment.Value) { peer.setTabPlacement(b.id) }


def titleAt(idx:Int, title:String) { peer.setTitleAt(idx, title)}
def toolTipTextAt(idx:Int, text:String) {peer.setToolTipTextAt(idx, text)}
def selectedIndex(idx:Int) {peer.setSelectedIndex(idx)}


/**
* The current page selection
*/
Expand Down
9 changes: 7 additions & 2 deletions src/main/scala/scala/swing/UIElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,17 @@ trait UIElement extends Proxy with LazyPublisher {
def visible_=(b: Boolean) { peer.setVisible(b) }
def showing: Boolean = peer.isShowing
def displayable: Boolean = peer.isDisplayable


def graphicsConfiguration = peer.getGraphicsConfiguration

def repaint() { peer.repaint }
def repaint(rect: Rectangle) { peer.repaint(rect.x, rect.y, rect.width, rect.height) }
def ignoreRepaint: Boolean = peer.getIgnoreRepaint
def ignoreRepaint_=(b: Boolean) { peer.setIgnoreRepaint(b) }


def invalidate() { peer.invalidate }
def validate() { peer.validate }

protected def onFirstSubscribe {
peer.addComponentListener(new java.awt.event.ComponentListener {
def componentHidden(e: java.awt.event.ComponentEvent) {
Expand Down
89 changes: 89 additions & 0 deletions src/main/scala/scala/swing/test/CardPanelDemo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2007-2010, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */

package scala.swing
package test

import event._
import BorderPanel._
import java.awt.Dimension

//import scala.swing.CardPanel.Card

import scala.swing.CardPanel._

/**
* CardPanel Demo
* Based on http://download.oracle.com/javase/tutorial/uiswing/layout/card.html
*
* @author andy hicks
*/
object CardPanelDemo extends SimpleSwingApplication {

def top = new MainFrame {
title = "CardPanel Demo"
size = new Dimension(400, 400)

contents = ui
}

def ui = new BorderPanel {

val BUTTONPANEL = "Card with JButtons"
val TEXTPANEL = "Card with JTextField"

val cb = new ComboBox(BUTTONPANEL :: TEXTPANEL :: Nil)
val first = new Button("First") {
reactions += { case ButtonClicked(_) => println("first"); card.first }
}
val last = new Button("Last") {
reactions += { case ButtonClicked(_) => println("last"); card.last }
}
val next = new Button("Next") {
reactions += { case ButtonClicked(_) => println("next"); card.next }
}

val prev = new Button("Prev") {
reactions += { case ButtonClicked(_) => println("previous"); card.previous }
}

val cmd = new FlowPanel() {
contents += first
contents += last
contents += cb
contents += next
contents += prev
}

reactions += {
case SelectionChanged(`cb`) => card.show(cb.selection.item)
}
listenTo(cb.selection)

//Create the "cards".
val buttons = new FlowPanel() {
contents += new Button("Button 1")
contents += new Button("Button 2")
contents += new Button("Button 3")
}

val text = new FlowPanel() {
contents += new TextField("TextField", 20)
}

val card = new CardPanel() {
card += new Card(buttons, BUTTONPANEL)
card += new Card(text, TEXTPANEL)
}

layout( cmd ) = Position.North
layout( card) = Position.Center
}

}

Loading