Skip to content

Commit 3e5040b

Browse files
author
Allan Jacobs
committed
Merge with andy1138-tutorial. In the process, ListDemo's cancel button was fixed and some stray comments were removed.
1 parent 93f97aa commit 3e5040b

32 files changed

+701
-968
lines changed
318 KB
Loading

examples/src/main/scala/scala/swing/examples/tutorials/components/ButtonDemo.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package scala.swing.examples.tutorials.components
3232

3333
import scala.swing._
3434
import scala.swing.event.ButtonClicked
35-
import javax.swing.UIManager
3635

3736
/**
3837
* Tutorial: How to Use Buttons, Check Boxes, and Radio Buttons
@@ -97,18 +96,16 @@ class ButtonDemo extends FlowPanel {
9796
middle.enabled = false
9897
disable.enabled = false
9998
}
100-
101-
10299
}
103100

104101
object ButtonDemo extends SimpleSwingApplication {
105-
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
102+
def createImageIcon(path: String): Option[javax.swing.ImageIcon] =
106103
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))
107-
}
108-
UIManager.put("swing.boldMetal", false)
104+
109105
lazy val top = new MainFrame() {
110106
title = "ButtonDemo"
111-
//Create and set up the content pane.
112-
contents = new ButtonDemo();
107+
javax.swing.UIManager.put("swing.boldMetal", false)
108+
109+
contents = new ButtonDemo()
113110
}
114111
}

examples/src/main/scala/scala/swing/examples/tutorials/components/ButtonHtmlDemo.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import scala.swing._
3434
import scala.swing.event.ButtonClicked
3535
import java.awt.Font
3636

37-
/**
37+
/*
3838
* Tutorial: How to Use Buttons, Check Boxes, and Radio Buttons
3939
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/button.html]]
4040
*
@@ -47,9 +47,9 @@ import java.awt.Font
4747
* /scala/swing/examples/tutorials/images/left.gif
4848
*/
4949
class ButtonHtmlDemo extends FlowPanel {
50-
val leftButtonIcon = ButtonHtmlDemo.createImageIcon("/scala/swing/examples/tutorials/images/right.gif").get
51-
val middleButtonIcon = ButtonHtmlDemo.createImageIcon("/scala/swing/examples/tutorials/images/middle.gif").get
52-
val rightButtonIcon = ButtonHtmlDemo.createImageIcon("/scala/swing/examples/tutorials/images/left.gif").get
50+
val leftButtonIcon = createImageIcon("/scala/swing/examples/tutorials/images/right.gif").get
51+
val middleButtonIcon = createImageIcon("/scala/swing/examples/tutorials/images/middle.gif").get
52+
val rightButtonIcon = createImageIcon("/scala/swing/examples/tutorials/images/left.gif").get
5353
//
5454
val disable: Button = new Button("<html><center><b><u>D</u>isable</b><br>" +
5555
"<font color=#ffffdd>middle button</font>") {
@@ -102,12 +102,19 @@ class ButtonHtmlDemo extends FlowPanel {
102102
middle.enabled = false
103103
disable.enabled = false
104104
}
105+
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
106+
val imgURL: java.net.URL = getClass().getResource(path)
107+
val img: Option[javax.swing.ImageIcon] = if (imgURL != null) {
108+
Some(Swing.Icon(imgURL))
109+
} else {
110+
None
111+
}
112+
img
113+
}
114+
105115
}
106116

107117
object ButtonHtmlDemo extends SimpleSwingApplication {
108-
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
109-
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))
110-
}
111118
lazy val top = new MainFrame() {
112119
title = "ButtonHtmlDemo"
113120
//Create and set up the content pane.

examples/src/main/scala/scala/swing/examples/tutorials/components/CheckboxDemo.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ import scala.swing.event.ButtonClicked
3535
import scala.swing.event.Key
3636
import java.awt.Font
3737

38-
import scala.swing.examples.tutorials.components.ButtonDemo._
3938

4039
/**
4140
* Tutorial: How to Use Buttons, Check Boxes, and Radio Buttons
42-
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/button.html]]
41+
* http://docs.oracle.com/javase/tutorial/uiswing/components/button.html
4342
*
4443
* Source code reference:
4544
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/CheckBoxDemoProject/src/components/CheckBoxDemo.java]]
@@ -50,7 +49,7 @@ import scala.swing.examples.tutorials.components.ButtonDemo._
5049
* geek-cg--.gif, ..., geek-cght.gif.
5150
*/
5251
class CheckboxDemo extends BorderPanel {
53-
/*
52+
/**
5453
* Four accessory choices provide for 16 different
5554
* combinations. The image for each combination is
5655
* contained in a separate image file whose name indicates
@@ -146,7 +145,7 @@ class CheckboxDemo extends BorderPanel {
146145
pictureLabel.tooltip = choices.toString
147146

148147
//Get the icon corresponding to the image.
149-
createImageIcon( s"/scala/swing/examples/tutorials/images/geek/geek-$choices.gif") match {
148+
CheckboxDemo.createImageIcon( s"/scala/swing/examples/tutorials/images/geek/geek-$choices.gif") match {
150149
case Some( icon ) =>
151150
pictureLabel.icon = icon
152151
pictureLabel.text = null

examples/src/main/scala/scala/swing/examples/tutorials/components/ComboBoxDemo.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ import scala.swing.event.SelectionChanged
3636
import java.awt.{ Dimension, Font }
3737
import javax.swing.BorderFactory
3838

39-
40-
/**
39+
/*
4140
* Tutorial: How to Use Combo Boxes
4241
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html]]
4342
*
4443
* Source code reference:
45-
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ComboBoxDemoProject/src/components/ComboBoxDemo.java]]
44+
* http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ComboBoxDemoProject/src/components/ComboBoxDemo.java
4645
*/
4746
class ComboBoxDemo extends BorderPanel {
4847

@@ -78,14 +77,14 @@ class ComboBoxDemo extends BorderPanel {
7877
}
7978

8079
def updateLabel(s: String): Unit = {
81-
picture.icon =
82-
ComboBoxDemo.createImageIcon("/scala/swing/examples/tutorials/images/" + s + ".gif").getOrElse( Swing.EmptyIcon )
80+
val ic = ComboBoxDemo.createImageIcon(s"/scala/swing/examples/tutorials/images/$s.gif")
81+
picture.icon = imgIcon.getOrElse( Swing.EmptyIcon )
8382
}
8483
}
8584

8685
object ComboBoxDemo extends SimpleSwingApplication {
8786

88-
/** Returns an ImageIcon option, or None if the path was invalid. */
87+
/** Returns an ImageIcon, or null if the path was invalid. */
8988
def createImageIcon(path: String ): Option[javax.swing.ImageIcon] =
9089
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))
9190

examples/src/main/scala/scala/swing/examples/tutorials/components/ComboBoxDemo2.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ComboBoxDemo2 extends BoxPanel(Orientation.Vertical) {
6666
val patternList = new ComboBox[String](patternExamples) {
6767
makeEditable()
6868
selection.item = patternExamples(0)
69-
xLayoutAlignment = 0.0 // Left
7069
}
7170

7271
//Create the UI for displaying result.

examples/src/main/scala/scala/swing/examples/tutorials/components/CustomComboBoxDemo.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ package scala.swing.examples.tutorials.components
3333

3434
import scala.swing._
3535
import javax.swing.ImageIcon
36+
import java.net.URL
3637
import java.awt.{ Dimension, Font }
3738

3839
/**
@@ -109,11 +110,9 @@ class CustomComboBoxDemo extends BorderPanel {
109110

110111
object CustomComboBoxDemo extends SimpleSwingApplication {
111112

112-
/** Returns an ImageIcon, or null if the path was invalid. */
113-
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
113+
def createImageIcon(path: String): Option[javax.swing.ImageIcon] =
114114
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))
115-
}
116-
115+
117116
lazy val top = new MainFrame() {
118117
title = "CustomComboBoxDemo"
119118

examples/src/main/scala/scala/swing/examples/tutorials/components/DialogDemo.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,8 @@ class DialogDemo(val frame: Frame) extends BorderPanel {
380380
}
381381

382382
object DialogDemo extends SimpleSwingApplication {
383-
384-
/** Returns an ImageIcon option, or None if the path was invalid. */
385-
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
383+
def createImageIcon(path: String): Option[javax.swing.ImageIcon] =
386384
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))
387-
}
388385

389386
lazy val top = new MainFrame() {
390387
title = "DialogDemo"

examples/src/main/scala/scala/swing/examples/tutorials/components/FormattedTextFieldDemo.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ package scala.swing.examples.tutorials.components
3333
import scala.swing._
3434
import java.text.NumberFormat
3535
import java.awt.Color
36-
import javax.swing.UIManager
3736

38-
/**
37+
/*
3938
* Tutorial: How to Use Formatted Text Fields
40-
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html]]
39+
* http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html
4140
*
4241
* Source code reference:
43-
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FormattedTextFieldDemoProject/src/components/FormattedTextFieldDemo.java]]
42+
* http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FormattedTextFieldDemoProject/src/components/FormattedTextFieldDemo.java
4443
*
4544
* FormattedTextFieldDemo.scala requires no other files.
4645
*
@@ -162,10 +161,11 @@ class FormattedTextFieldDemo extends BorderPanel {
162161
}
163162

164163
object FormattedTextFieldDemo extends SimpleSwingApplication {
165-
UIManager.put("swing.boldMetal", false)
166164
lazy val top = new MainFrame() {
167165
title = "FormattedTextFieldDemo"
168166
//Create and set up the content pane.
169-
contents = new FormattedTextFieldDemo()
167+
javax.swing.UIManager.put("swing.boldMetal", false)
168+
contents = new FormattedTextFieldDemo();
170169
}
170+
javax.swing.SwingUtilities.updateComponentTreeUI(top.peer)
171171
}

examples/src/main/scala/scala/swing/examples/tutorials/components/FrameDemo2.scala

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import java.awt.{ BorderLayout, Color, Component, Dimension, Graphics, Image, Po
3737
import java.awt.image.BufferedImage
3838
import java.net.URL
3939

40-
/**
40+
/*
4141
* Tutorial: How to Make Frames (Main Windows)
42-
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html]]
42+
* http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
4343
*
4444
* Source code reference:
45-
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemo2Project/src/components/FrameDemo2.java]]
45+
* http://docs.oracle.com/javase/tutorial/uiswing/examples/components/FrameDemo2Project/src/components/FrameDemo2.java
4646
*
4747
* FrameDemo2.scala shows off the window decoration features added in
4848
* 1.4, plus some window positioning code and (optionally)
@@ -264,18 +264,6 @@ class MyFrame extends Frame {
264264
}
265265

266266
object FrameDemo2 extends SimpleSwingApplication {
267-
//Use the Java look and feel. This needs to be done before the frame is created
268-
//so the companion object FrameDemo2 cannot simply extend SimpleSwingApplcation.
269-
try {
270-
UIManager.setLookAndFeel(
271-
UIManager.getCrossPlatformLookAndFeelClassName());
272-
} catch {
273-
case e: Exception => ;
274-
}
275-
//Make sure we have nice window decorations.
276-
JFrame.setDefaultLookAndFeelDecorated(true);
277-
JDialog.setDefaultLookAndFeelDecorated(true);
278-
279267
//Creates an icon-worthy Image from scratch.
280268
def createFDImage(): Image = {
281269
//Create a 16x16 pixel image.
@@ -306,13 +294,26 @@ object FrameDemo2 extends SimpleSwingApplication {
306294

307295
lazy val top = new Frame() {
308296
title = "FrameDemo2"
297+
//Use the Java look and feel. This needs to be done before the frame is created
298+
//so the companion object FrameDemo2 cannot simply extend SimpleSwingApplcation.
299+
try {
300+
UIManager.setLookAndFeel(
301+
UIManager.getCrossPlatformLookAndFeelClassName());
302+
} catch {
303+
case e: Exception => ;
304+
}
305+
//Make sure we have nice window decorations.
306+
JFrame.setDefaultLookAndFeelDecorated(true);
307+
JDialog.setDefaultLookAndFeelDecorated(true);
309308
//Create and set up the content pane.
310309
val demo = new FrameDemo2();
311310
//Add components to it.
312311
val contentPane = peer.getContentPane()
312+
313313
}
314314
top.contentPane.add(top.demo.createOptionControls(top),
315315
BorderLayout.CENTER)
316316
top.contentPane.add(top.demo.createButtonPane(top),
317317
BorderLayout.PAGE_END)
318-
}
318+
javax.swing.SwingUtilities.updateComponentTreeUI(top.peer)
319+
}

0 commit comments

Comments
 (0)