Skip to content

Commit f4ecfe3

Browse files
committed
Dotty 3.0.0-M1 support done. Remove structural types
- Action.Trigger.Wrapper, Oriented.Wrapper, Orientable.Wrapper have been removed; one must mix in Action.Trigger, Oriented, Orientable instead and implement the methods - Swing.PeerContainer is not a structural type but a trait, that must be mixed in - clean up some examples - remove lanuage feature lazy vals from package object
1 parent 449ef57 commit f4ecfe3

22 files changed

+202
-203
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ lazy val scalaTestVersion = "3.2.3"
22

33
lazy val commonSettings = Seq(
44
crossScalaVersions += "3.0.0-M1",
5-
scalaVersion := "3.0.0-M1", // while working in IntelliJ
5+
scalaVersion := "2.13.3",
6+
scalacOptions ++= Seq("-deprecation", "-feature"),
67
)
78

89
lazy val swing = project.in(file("."))

examples/src/main/scala/scala/swing/examples/LinePainting.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ object LinePainting extends SimpleSwingApplication {
4747
var path = new geom.GeneralPath
4848

4949
def lineTo(p: Point): Unit = {
50-
path.lineTo(p.x, p.y); repaint()
50+
path.lineTo(p.x.toFloat, p.y.toFloat); repaint()
5151
}
5252

5353
def moveTo(p: Point): Unit = {
54-
path.moveTo(p.x, p.y); repaint()
54+
path.moveTo(p.x.toFloat, p.y.toFloat); repaint()
5555
}
5656

5757
override def paintComponent(g: Graphics2D): Unit = {

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

Lines changed: 85 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2929
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
31+
3132
package scala.swing.examples.tutorials.components
3233

33-
import scala.swing._
34-
import scala.swing.event.ButtonClicked
35-
import javax.swing.{ Box, BoxLayout, JDialog, JFrame, ImageIcon, UIManager }
36-
import java.awt.{ BorderLayout, Color, Component, Dimension, Graphics, Image, Point, Toolkit }
3734
import java.awt.image.BufferedImage
35+
import java.awt.{Color, Dimension, Graphics, Image, Point, Toolkit}
3836
import java.net.URL
3937

38+
import javax.swing.{ImageIcon, JDialog, JFrame, UIManager}
39+
40+
import scala.swing._
41+
import scala.swing.event.ButtonClicked
42+
4043
/*
4144
* Tutorial: How to Make Frames (Main Windows)
4245
* http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
@@ -49,75 +52,75 @@ import java.net.URL
4952
* setIconImage. It uses the file /scala/swing/examples/tutorials/images/FD.jpg.
5053
*/
5154
class FrameDemo2 {
52-
private var lastLocation: Point = null
53-
private var defaultButton: Button = null
54-
// private val maxX = 500
55-
// private val maxY = 500
56-
//constants for action commands
57-
val NO_DECORATIONS = "no_dec";
58-
val LF_DECORATIONS = "laf_dec";
59-
val WS_DECORATIONS = "ws_dec";
60-
val CREATE_WINDOW = "new_win";
61-
val DEFAULT_ICON = "def_icon";
62-
val FILE_ICON = "file_icon";
63-
val PAINT_ICON = "paint_icon";
64-
65-
//true if the next frame created should have no window decorations
66-
var noDecorations = false;
67-
68-
//true if the next frame created should have setIconImage called
69-
var specifyIcon = false;
70-
71-
//true if the next frame created should have a custom painted icon
72-
var createIcon = false;
73-
74-
val screenSize: Dimension = Toolkit.getDefaultToolkit().getScreenSize()
75-
val maxX = screenSize.width - 50
76-
val maxY = screenSize.height - 50
77-
78-
//Create a new MyFrame object and show it.
55+
private var lastLocation : Point = null
56+
private var defaultButton : Button = null
57+
58+
// constants for action commands
59+
val NO_DECORATIONS = "no_dec"
60+
val LF_DECORATIONS = "laf_dec"
61+
val WS_DECORATIONS = "ws_dec"
62+
val CREATE_WINDOW = "new_win"
63+
val DEFAULT_ICON = "def_icon"
64+
val FILE_ICON = "file_icon"
65+
val PAINT_ICON = "paint_icon"
66+
67+
// true if the next frame created should have no window decorations
68+
var noDecorations = false
69+
70+
// true if the next frame created should have setIconImage called
71+
var specifyIcon = false
72+
73+
// true if the next frame created should have a custom painted icon
74+
var createIcon = false
75+
76+
val screenSize: Dimension = Toolkit.getDefaultToolkit.getScreenSize
77+
78+
val maxX: Int = screenSize.width - 50
79+
val maxY: Int = screenSize.height - 50
80+
81+
// Creates a new MyFrame object and show it.
7982
def showNewWindow(): Unit = {
80-
//Take care of the no window decorations case.
81-
//NOTE: Unless you really need the functionality
82-
//provided by JFrame, you would usually use a
83-
//Window or JWindow instead of an undecorated JFrame.
83+
// Take care of the no window decorations case.
84+
// NOTE: Unless you really need the functionality
85+
// provided by JFrame, you would usually use a
86+
// Window or JWindow instead of an undecorated JFrame.
8487
val frame: Option[Frame] = if (noDecorations) Some(new MyFrameUndecorated()) else Some(new MyFrame())
85-
//Set window location.
88+
// Set window location.
8689
if (frame.isDefined) {
8790
val f = frame.get
8891
if (lastLocation != null) {
8992
//Move the window over and down 40 pixels.
90-
lastLocation.translate(40, 40);
93+
lastLocation.translate(40, 40)
9194
if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
92-
lastLocation.setLocation(0, 0);
95+
lastLocation.setLocation(0, 0)
9396
}
9497
f.location = lastLocation
9598
} else {
9699
lastLocation = f.location
97100
}
98101

99-
//Calling setIconImage sets the icon displayed when the window
100-
//is minimized. Most window systems (or look and feels, if
101-
//decorations are provided by the look and feel) also use this
102-
//icon in the window decorations.
102+
// Calling setIconImage sets the icon displayed when the window
103+
// is minimized. Most window systems (or look and feels, if
104+
// decorations are provided by the look and feel) also use this
105+
// icon in the window decorations.
103106
if (specifyIcon) {
104107
if (createIcon) {
105-
//create an icon from scratch
108+
// create an icon from scratch
106109
f.iconImage = FrameDemo2.createFDImage()
107110
} else {
108-
//get the icon from a file
111+
// get the icon from a file
109112
f.iconImage = FrameDemo2.getFDImage().get
110113
}
111114
}
112115
}
113116
}
114117

115-
// Create the window-creation controls that go in the main window.
118+
// Creates the window-creation controls that go in the main window.
116119
def createOptionControls(frame: Frame): BoxPanel = {
117-
val label1 = new Label("Decoration options for subsequently created frames:")
118-
val bg1 = new ButtonGroup()
119-
val label2 = new Label("Icon options:")
120-
val bg2 = new ButtonGroup()
120+
val label1 = new Label("Decoration options for subsequently created frames:")
121+
val bg1 = new ButtonGroup()
122+
val label2 = new Label("Icon options:")
123+
val bg2 = new ButtonGroup()
121124

122125
//Create the buttons
123126
val rb1 = new RadioButton() {
@@ -197,7 +200,7 @@ class FrameDemo2 {
197200
box
198201
}
199202

200-
//Create the button that goes in the main window.
203+
// Creates the button that goes in the main window.
201204
def createButtonPane(frame: Frame): FlowPanel = {
202205
val button = new Button("New window")
203206
defaultButton = button
@@ -207,7 +210,7 @@ class FrameDemo2 {
207210
case ButtonClicked(`button`) => showNewWindow()
208211
}
209212

210-
//Center the button in a panel with some space around it.
213+
// Center the button in a panel with some space around it.
211214
val pane = new FlowPanel() {
212215
border = Swing.EmptyBorder(5, 5, 5, 5)
213216
contents += button
@@ -220,12 +223,12 @@ class FrameDemo2 {
220223
class MyFrame extends Frame {
221224
title = "A window"
222225

223-
//This button lets you close even an undecorated window.
224-
val button = new Button("Close window") {
226+
// This button lets you close even an undecorated window.
227+
val button: Button = new Button("Close window") {
225228
xLayoutAlignment = java.awt.Component.CENTER_ALIGNMENT
226229
}
227230

228-
//Place the button near the bottom of the window.
231+
// Place the button near the bottom of the window.
229232
contents = new BoxPanel(Orientation.Vertical) {
230233
contents += Swing.VGlue
231234
contents += button
@@ -241,18 +244,19 @@ class MyFrame extends Frame {
241244
preferredSize = new Dimension(150, 150)
242245
pack()
243246
visible = true
244-
override def closeOperation() = close()
247+
248+
override def closeOperation(): Unit = close()
245249
}
246250

247251
class MyFrameUndecorated extends Frame with RichWindow.Undecorated {
248252
visible = false
249-
//This button lets you close even an undecorated window.
250-
val button = new Button("Close window") {
253+
// This button lets you close even an undecorated window.
254+
val button: Button = new Button("Close window") {
251255
xLayoutAlignment = java.awt.Component.CENTER_ALIGNMENT
252256
}
253257

254-
//Place the button near the bottom of the window.
255-
//Undecorated windows are not supported in scala swing.
258+
// Place the button near the bottom of the window.
259+
// Undecorated windows are not supported in scala swing.
256260
contents = new BoxPanel(Orientation.Vertical) {
257261
contents += Swing.VGlue
258262
contents += button
@@ -268,53 +272,54 @@ class MyFrameUndecorated extends Frame with RichWindow.Undecorated {
268272
preferredSize = new Dimension(150, 150)
269273
pack()
270274
visible = true
271-
override def closeOperation() = close()
275+
276+
override def closeOperation(): Unit = close()
272277
}
273278

274279
object FrameDemo2 extends SimpleSwingApplication {
275-
//Creates an icon-worthy Image from scratch.
280+
// Creates an icon-worthy Image from scratch.
276281
def createFDImage(): Image = {
277-
//Create a 16x16 pixel image.
282+
// Create a 16x16 pixel image.
278283
val bi = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB)
279-
//Draw into it.
280-
val g: Graphics = bi.getGraphics()
281-
g.setColor(Color.BLACK);
284+
// Draw into it.
285+
val g: Graphics = bi.getGraphics
286+
g.setColor(Color.BLACK)
282287
g.fillRect(0, 0, 15, 15)
283288
g.setColor(Color.RED)
284289
g.fillOval(5, 3, 6, 6)
285290

286-
//Clean up.
291+
// Clean up.
287292
g.dispose()
288293

289-
//Return it.
294+
// Return it.
290295
bi
291296
}
292297

293298
// Returns an Image Option or None.
294299
def getFDImage(): Option[Image] = {
295-
val imgURL: URL = getClass().getResource("/scala/swing/examples/tutorials/images/FD.jpg");
300+
val imgURL: URL = getClass.getResource("/scala/swing/examples/tutorials/images/FD.jpg")
296301
if (imgURL != null) {
297-
return Some(new ImageIcon(imgURL).getImage)
302+
Some(new ImageIcon(imgURL).getImage)
298303
} else {
299-
return None
304+
None
300305
}
301306
}
302307

303-
lazy val top: Frame { val demo: FrameDemo2 } = new Frame() {
308+
object top extends Frame {
304309
title = "FrameDemo2"
305-
//Use the Java look and feel. This needs to be done before the frame is created
306-
//so the companion object FrameDemo2 cannot simply extend SimpleSwingApplcation.
310+
// Use the Java look and feel. This needs to be done before the frame is created
311+
// so the companion object FrameDemo2 cannot simply extend SimpleSwingApplication.
307312
try {
308313
UIManager.setLookAndFeel(
309-
UIManager.getCrossPlatformLookAndFeelClassName());
314+
UIManager.getCrossPlatformLookAndFeelClassName)
310315
} catch {
311-
case e: Exception => ;
316+
case _: Exception => ()
312317
}
313-
//Make sure we have nice window decorations.
314-
JFrame.setDefaultLookAndFeelDecorated(true);
315-
JDialog.setDefaultLookAndFeelDecorated(true);
316-
//Create and set up the content pane.
317-
val demo = new FrameDemo2();
318+
// Make sure we have nice window decorations.
319+
JFrame .setDefaultLookAndFeelDecorated(true)
320+
JDialog.setDefaultLookAndFeelDecorated(true)
321+
// Create and set up the content pane.
322+
val demo = new FrameDemo2()
318323
}
319324
val bp: BorderPanel = new BorderPanel() {
320325
layout(top.demo.createOptionControls(top)) = BorderPanel.Position.Center

0 commit comments

Comments
 (0)