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
}

0 commit comments

Comments
 (0)