Skip to content

Commit 2fb8d2e

Browse files
committed
begin Dotty support (WIP, still fails)
- RichWindow - we cannot override internal class InterfaceMixin, thus introduce InterfaceMixin2 - ScrollPane.BarPolicy cannot be an Enumeration because we cannot override internal class Value. Make it a case class instead - Window#SuperMixin causes a compiler bug in Dotty ("dotc: wrong number of arguments at crossCast for (x$0: java.awt.GraphicsConfiguration): java.awt.Window: (java.awt.Window#<init> : (x$0: java.awt.GraphicsConfiguration): java.awt.Window ), expected: 1, found: 0"
1 parent 13ae8d8 commit 2fb8d2e

File tree

15 files changed

+81
-72
lines changed

15 files changed

+81
-72
lines changed

build.sbt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1+
lazy val scalaTestVersion = "3.2.2"
2+
3+
lazy val commonSettings = Seq(
4+
crossScalaVersions += "0.27.0-RC1",
5+
scalaVersion := "0.27.0-RC1", // while working in IntelliJ
6+
)
7+
18
lazy val swing = project.in(file("."))
29
.settings(ScalaModulePlugin.scalaModuleSettings)
310
.settings(ScalaModulePlugin.scalaModuleOsgiSettings)
11+
.settings(commonSettings)
412
.settings(
513
name := "scala-swing",
614
OsgiKeys.exportPackage := Seq(s"scala.swing.*;version=${version.value}"),
715
scalaModuleMimaPreviousVersion := Some("2.1.0"),
816
// set the prompt (for this build) to include the project id.
917
ThisBuild / shellPrompt := { state => Project.extract(state).currentRef.project + "> " },
1018
libraryDependencies ++= Seq(
11-
"org.scalatest" %% "scalatest-flatspec" % "3.2.0" % Test,
12-
"org.scalatest" %% "scalatest-shouldmatchers" % "3.2.0" % Test,
19+
"org.scalatest" %% "scalatest-flatspec" % scalaTestVersion % Test,
20+
"org.scalatest" %% "scalatest-shouldmatchers" % scalaTestVersion % Test,
1321
),
1422
// Adds a `src/main/scala-2.13+` source directory for Scala 2.13 and newer
1523
// and a `src/main/scala-2.13-` source directory for Scala version older than 2.13
1624
Compile / unmanagedSourceDirectories += {
1725
val sourceDir = (Compile / sourceDirectory).value
1826
CrossVersion.partialVersion(scalaVersion.value) match {
1927
case Some((2, n)) if n >= 13 => sourceDir / "scala-2.13+"
28+
case Some((0, _)) => sourceDir / "scala-2.13+" // Dotty
2029
case _ => sourceDir / "scala-2.13-"
2130
}
2231
}
2332
)
2433

2534
lazy val examples = project.in(file("examples"))
2635
.dependsOn(swing)
36+
.settings(commonSettings)
2737
.settings(
2838
scalaVersion := (swing / scalaVersion).value,
2939
run / fork := true,
@@ -32,6 +42,7 @@ lazy val examples = project.in(file("examples"))
3242

3343
lazy val uitest = project.in(file("uitest"))
3444
.dependsOn(swing)
45+
.settings(commonSettings)
3546
.settings(
3647
scalaVersion := (swing / scalaVersion).value,
3748
run / fork := true,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,19 @@ class ButtonHtmlDemo extends FlowPanel {
8888
listenTo(enable)
8989

9090
reactions += {
91-
case ButtonClicked(`enable`) => enableMiddle
92-
case ButtonClicked(`disable`) => disableMiddle
91+
case ButtonClicked(`enable`) => enableMiddle()
92+
case ButtonClicked(`disable`) => disableMiddle()
9393
}
9494

9595
def enableMiddle(): Unit = {
96-
enable.enabled = false
97-
middle.enabled = true
98-
disable.enabled = true
96+
enable .enabled = false
97+
middle .enabled = true
98+
disable .enabled = true
9999
}
100100
def disableMiddle(): Unit = {
101-
enable.enabled = true
102-
middle.enabled = false
103-
disable.enabled = false
101+
enable .enabled = true
102+
middle .enabled = false
103+
disable .enabled = false
104104
}
105105
def createImageIcon(path: String): Option[javax.swing.ImageIcon] = {
106106
val imgURL: java.net.URL = getClass().getResource(path)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@ class MyFrame extends Frame {
241241
preferredSize = new Dimension(150, 150)
242242
pack()
243243
visible = true
244-
override def closeOperation() = {
245-
close
246-
}
244+
override def closeOperation() = close()
247245
}
248246

249247
class MyFrameUndecorated extends Frame with RichWindow.Undecorated {
@@ -270,9 +268,7 @@ class MyFrameUndecorated extends Frame with RichWindow.Undecorated {
270268
preferredSize = new Dimension(150, 150)
271269
pack()
272270
visible = true
273-
override def closeOperation() = {
274-
close
275-
}
271+
override def closeOperation() = close()
276272
}
277273

278274
object FrameDemo2 extends SimpleSwingApplication {

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,16 @@ class IconDemoApp extends MainFrame {
123123
}.toList
124124
}
125125

126-
f.foreach {
127-
thumbs:List[Option[ThumbnailAction]] =>
128-
buttonBar.contents.dropRight(1)
129-
thumbs.foreach{ thumbAction => {
130-
thumbAction.foreach { ta =>
131-
buttonBar.contents += new Button(ta)
132-
}
133-
}}
134-
buttonBar.contents += Swing.Glue
126+
f.foreach { thumbs =>
127+
buttonBar.contents.dropRight(1)
128+
thumbs.foreach { thumbAction =>
129+
thumbAction.foreach { ta =>
130+
buttonBar.contents += new Button(ta)
131+
}
132+
}
133+
buttonBar.contents += Swing.Glue
135134
}
136135

137-
138136
/**
139137
* Resizes an image using a Graphics2D object backed by a BufferedImage.
140138
* @param srcImg - source image to scale

examples/src/main/scala/scala/swing/examples/tutorials/layout/BoxLayoutDemo2.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ class BoxLayoutDemo2 extends BorderPanel {
9393
}
9494

9595
def notifyBldComponents(): Unit = {
96-
for (i <- 0 until NumComponents)
96+
for (i <- 0 until NumComponents) {
9797
bldComponent(i).setSizeRestriction(restrictSize)
98-
bldComponent(0).revalidate
98+
}
99+
bldComponent(0).revalidate()
99100
}
100101
}
101102

examples/src/main/scala/scala/swing/examples/tutorials/layout/DiagonalLayout.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DiagonalLayout(private var vgap: Int) extends LayoutManager {
4848

4949
private var sizeUnknown: Boolean = true
5050

51-
def this() {
51+
def this() = {
5252
this(5)
5353
}
5454

project/plugins.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.2.0")
1+
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "2.2.1")
2+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.2") // cross-compile for dotty
3+

src/main/scala/scala/swing/ButtonGroup.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class ButtonGroup(initialButtons: AbstractButton*) {
3232
override def size: Int = peer.getButtonCount
3333

3434
def iterator: Iterator[AbstractButton] = new Iterator[AbstractButton] {
35-
private val enum = peer.getElements
36-
def next(): AbstractButton = UIElement.cachedWrapper[AbstractButton](enum.nextElement())
37-
def hasNext: Boolean = enum.hasMoreElements
35+
private val elements = peer.getElements
36+
def next(): AbstractButton = UIElement.cachedWrapper[AbstractButton](elements.nextElement())
37+
def hasNext: Boolean = elements.hasMoreElements
3838
}
3939
}
4040
buttons ++= initialButtons

src/main/scala/scala/swing/MainFrame.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ package scala.swing
1616
* A frame that can be used for main application windows. It shuts down the
1717
* framework and quits the application when closed.
1818
*/
19-
class MainFrame(gc: java.awt.GraphicsConfiguration = null) extends Frame(gc) {
19+
class MainFrame(/*gc: java.awt.GraphicsConfiguration = null*/) extends Frame /*(gc)*/ {
2020
override def closeOperation(): Unit = sys.exit(0)
2121
}

src/main/scala/scala/swing/Publisher.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private[swing] trait LazyPublisher extends Publisher {
7979

8080
import scala.ref._
8181

82-
private[swing] trait SingleRefCollection[+A <: AnyRef] extends Iterable[A] { self =>
82+
private[swing] trait SingleRefCollection[/*+*/ A <: AnyRef] extends Iterable[A] { self =>
8383

8484
trait Ref[+B <: AnyRef] extends Reference[B] {
8585
override def hashCode(): Int = get match {
@@ -119,7 +119,7 @@ private[swing] trait SingleRefCollection[+A <: AnyRef] extends Iterable[A] { sel
119119
while (!ahead && elems.hasNext) {
120120
// make sure we have a reference to the next element,
121121
// otherwise it might be garbage collected
122-
val next = elems.next.get
122+
val next = elems.next().get
123123
ahead = next.isDefined
124124
if (ahead) hd = next.get
125125
}

src/main/scala/scala/swing/RichWindow.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
package scala.swing
1414

15-
import java.awt.{Frame => AWTFrame, Window => AWTWindow}
15+
import java.awt.event.WindowEvent
16+
import java.awt.{GraphicsConfigTemplate, GraphicsConfiguration, Frame => AWTFrame, Window => AWTWindow}
1617

1718
import javax.swing.{Icon, JDialog, JFrame, JMenuBar, JOptionPane, UIManager}
1819

@@ -37,9 +38,9 @@ object RichWindow {
3738
* window is either a dialog or a frame at some point.
3839
*/
3940
sealed trait RichWindow extends Window {
40-
def peer: AWTWindow with InterfaceMixin
41+
def peer: AWTWindow with InterfaceMixin2
4142

42-
trait InterfaceMixin extends super.InterfaceMixin {
43+
trait InterfaceMixin2 extends InterfaceMixin {
4344
def getJMenuBar: JMenuBar
4445
def setJMenuBar(b: JMenuBar): Unit
4546
def setUndecorated(b: Boolean): Unit
@@ -79,13 +80,16 @@ sealed trait RichWindow extends Window {
7980
* @see javax.swing.JFrame
8081
*/
8182
class Frame(gc: java.awt.GraphicsConfiguration = null) extends RichWindow {
82-
override lazy val peer: JFrame with InterfaceMixin = new JFrame(gc) with InterfaceMixin with SuperMixin
83+
override lazy val peer: JFrame with InterfaceMixin2 = new JFrame(gc) with InterfaceMixin2 with SuperMixin
8384

84-
def iconify(): Unit = { peer.setExtendedState(peer.getExtendedState | AWTFrame.ICONIFIED) }
85-
def uniconify(): Unit = { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.ICONIFIED) }
85+
def iconify() : Unit = { peer.setExtendedState(peer.getExtendedState | AWTFrame.ICONIFIED) }
86+
def uniconify() : Unit = { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.ICONIFIED) }
87+
8688
def iconified: Boolean = (peer.getExtendedState & AWTFrame.ICONIFIED) != 0
87-
def maximize(): Unit = { peer.setExtendedState(peer.getExtendedState | AWTFrame.MAXIMIZED_BOTH) }
89+
90+
def maximize() : Unit = { peer.setExtendedState(peer.getExtendedState | AWTFrame.MAXIMIZED_BOTH) }
8891
def unmaximize(): Unit = { peer.setExtendedState(peer.getExtendedState & ~AWTFrame.MAXIMIZED_BOTH) }
92+
8993
def maximized: Boolean = (peer.getExtendedState & AWTFrame.MAXIMIZED_BOTH) != 0
9094

9195
def iconImage: Image = peer.getIconImage
@@ -189,11 +193,11 @@ object Dialog {
189193
* @see javax.swing.JDialog
190194
*/
191195
class Dialog(owner: Window, gc: java.awt.GraphicsConfiguration = null) extends RichWindow {
192-
override lazy val peer: JDialog with InterfaceMixin =
193-
if (owner == null) new JDialog with InterfaceMixin with SuperMixin
196+
override lazy val peer: JDialog with InterfaceMixin2 =
197+
if (owner == null) new JDialog with InterfaceMixin2 with SuperMixin
194198
else owner match {
195-
case f: Frame => new JDialog(f.peer, "", false, gc) with InterfaceMixin with SuperMixin
196-
case d: Dialog => new JDialog(d.peer, "", false, gc) with InterfaceMixin with SuperMixin
199+
case f: Frame => new JDialog(f.peer, "", false, gc) with InterfaceMixin2 with SuperMixin
200+
case d: Dialog => new JDialog(d.peer, "", false, gc) with InterfaceMixin2 with SuperMixin
197201
}
198202

199203
def this() = this(null)

src/main/scala/scala/swing/ScrollPane.scala

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,21 @@ import javax.swing.{JScrollPane, ScrollPaneConstants}
1717
import scala.collection.immutable
1818

1919
object ScrollPane {
20-
object BarPolicy extends Enumeration {
20+
object BarPolicy {
2121
import ScrollPaneConstants._
22-
val AsNeeded = new Value(HORIZONTAL_SCROLLBAR_AS_NEEDED,
23-
VERTICAL_SCROLLBAR_AS_NEEDED)
24-
val Never = new Value(HORIZONTAL_SCROLLBAR_NEVER,
25-
VERTICAL_SCROLLBAR_NEVER)
26-
val Always = new Value(HORIZONTAL_SCROLLBAR_ALWAYS,
27-
VERTICAL_SCROLLBAR_ALWAYS)
22+
val AsNeeded = BarPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_AS_NEEDED)
23+
val Never = BarPolicy(HORIZONTAL_SCROLLBAR_NEVER , VERTICAL_SCROLLBAR_NEVER )
24+
val Always = BarPolicy(HORIZONTAL_SCROLLBAR_ALWAYS , VERTICAL_SCROLLBAR_ALWAYS )
2825

29-
def wrap(id: Int): BarPolicy.Value = id match {
26+
def wrap(id: Int): Value = id match {
3027
case HORIZONTAL_SCROLLBAR_AS_NEEDED | VERTICAL_SCROLLBAR_AS_NEEDED => AsNeeded
3128
case HORIZONTAL_SCROLLBAR_NEVER | VERTICAL_SCROLLBAR_NEVER => Never
3229
case HORIZONTAL_SCROLLBAR_ALWAYS | VERTICAL_SCROLLBAR_ALWAYS => Always
3330
}
34-
35-
class Value(val horizontalPeer: Int, val verticalPeer: Int) extends super.Val {
36-
override def id: Int = horizontalPeer
37-
}
31+
32+
type Value = BarPolicy
3833
}
34+
final case class BarPolicy(val horizontalPeer: Int, val verticalPeer: Int)
3935
}
4036

4137
/**

src/main/scala/scala/swing/Table.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object Table {
9191
}
9292

9393
class LabelRenderer[A](convert: A => (Icon, String)) extends AbstractRenderer[A, Label](new Label) {
94-
def this() {
94+
def this() = {
9595
this(a => (null, a.toString))
9696
}
9797

src/main/scala/scala/swing/Window.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.swing
1414

1515
import java.awt.event.{WindowEvent, WindowListener}
16-
import java.awt.{Window => AWTWindow}
16+
import java.awt.{GraphicsConfiguration, Window => AWTWindow}
1717

1818
/**
1919
* A window with decoration such as a title, border, and action buttons.
@@ -48,22 +48,23 @@ abstract class Window extends UIElement with RootPanel with Publisher { outer =>
4848
}
4949
def defaultButton: Option[Button] =
5050
toOption(peer.getRootPane.getDefaultButton) map UIElement.cachedWrapper[Button]
51-
def defaultButton_=(b: Button): Unit = {
51+
52+
def defaultButton_=(b: Button): Unit =
5253
peer.getRootPane.setDefaultButton(b.peer)
53-
}
54-
def defaultButton_=(b: Option[Button]): Unit = {
54+
55+
def defaultButton_=(b: Option[Button]): Unit =
5556
peer.getRootPane.setDefaultButton(b.map(_.peer).orNull)
56-
}
5757

5858
def dispose(): Unit = peer.dispose()
5959

6060
def pack(): this.type = { peer.pack(); this }
6161

62-
def setLocationRelativeTo(c: UIElement): Unit = peer.setLocationRelativeTo(c.peer)
63-
def centerOnScreen(): Unit = peer.setLocationRelativeTo(null)
64-
def location_=(p: Point): Unit = peer.setLocation(p)
65-
def size_=(size: Dimension): Unit = peer.setSize(size)
66-
def bounds_=(rect: Rectangle): Unit = peer.setBounds(rect)
62+
def setLocationRelativeTo(c: UIElement) : Unit = peer.setLocationRelativeTo(c.peer)
63+
def centerOnScreen() : Unit = peer.setLocationRelativeTo(null)
64+
65+
def location_= (p : Point ): Unit = peer.setLocation(p )
66+
def size_= (size : Dimension ): Unit = peer.setSize (size )
67+
def bounds_= (rect : Rectangle ): Unit = peer.setBounds (rect )
6768

6869
def owner: Window = UIElement.cachedWrapper[Window](peer.getOwner)
6970

src/main/scala/scala/swing/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ package object swing {
9090
type Image = java.awt.Image
9191
type Font = java.awt.Font
9292

93-
implicit lazy val reflectiveCalls = scala.language.reflectiveCalls
94-
implicit lazy val implicitConversions = scala.language.implicitConversions
93+
implicit lazy val reflectiveCalls : languageFeature.reflectiveCalls = scala.language.reflectiveCalls
94+
implicit lazy val implicitConversions: languageFeature.implicitConversions = scala.language.implicitConversions
9595

9696
private[swing] def ifNull [A](o: Object, a: A): A = if(o eq null) a else o.asInstanceOf[A]
9797
private[swing] def toOption [A](o: Object): Option[A] = if(o eq null) None else Some(o.asInstanceOf[A])

0 commit comments

Comments
 (0)