From a3ce24b1e321dec8b391c7225483a3feb1e4180e Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Wed, 18 Sep 2024 20:41:37 +0200 Subject: [PATCH 01/10] Update README.md bump version --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9d11fab..9c98e1d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ If your program looks like this: ``` //> using scala 3.3 -//> using lib se.lth.cs::introprog:1.3.1 +//> using lib se.lth.cs::introprog:1.4.0 @main def run = val w = introprog.PixelWindow() @@ -46,7 +46,7 @@ See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api You can also give the `introprog` dependency directly at the command line, instead of the `using lib` directive: ``` -scala-cli run . --dep se.lth.cs::introprog:1.3.1 +scala-cli run . --dep se.lth.cs::introprog:1.4.0 ``` ### Using sbt @@ -56,7 +56,7 @@ You need [Scala Build Tool](https://www.scala-sbt.org/download.html) at least ve Put this text in a file called `build.sbt` ``` scalaVersion := "3.3.0" -libraryDependencies += "se.lth.cs" %% "introprog" % "1.3.1" +libraryDependencies += "se.lth.cs" %% "introprog" % "1.4.0" ``` When you run `sbt` in terminal the `introprog` package is automatically downloaded and made available on your classpath. From e86d1ddaa97a34aea61c88882577369995d7eea3 Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Fri, 8 Nov 2024 13:30:28 +0100 Subject: [PATCH 02/10] Update README.md bump Scala version --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9c98e1d..8b4ded7 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 1.0.0. -Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file: +Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file (bump your Scala version to the latest available): ``` -//> using scala 3.3 -//> using lib se.lth.cs::introprog:1.3.1 +//> using scala 3.5.2 +//> using dep se.lth.cs::introprog:1.3.1 ``` You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") @@ -31,8 +31,8 @@ You run your code with `scala-cli run .` (note the ending dot, meaning "this dir If your program looks like this: ``` -//> using scala 3.3 -//> using lib se.lth.cs::introprog:1.4.0 +//> using scala 3.5.2 +//> using dep se.lth.cs::introprog:1.4.0 @main def run = val w = introprog.PixelWindow() From af4e1c0ac2109732693d4c43e6035deaccf3dc60 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 8 Nov 2024 14:11:59 +0100 Subject: [PATCH 03/10] update readme, add scala repl, lib -> dep, bump versions etc --- README.md | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8b4ded7..0e5f174 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,31 @@ This repo is used in this course *(in Swedish)*: http://cs.lth.se/pgk with cours ## How to use introprog-scalalib -### Using scala-cli +### Getting started using scala from the command line -You need [Scala Command Line Interface](https://scala-cli.virtuslab.org/install) at least version 1.0.0. +You need to have [Scala installed](https://www.scala-lang.org/download/) using version 3.5.2 or later. -Add these magic comment lines starting with `//>` in the beginning of your Scala 3 file (bump your Scala version to the latest available): +You can start the Scala REPL in the current directory with `introprog` directly available to play with using this command in a terminal window: +``` +scala repl . --dep se.lth.cs::introprog:1.4.0 +``` + +You can then open a drawing window like so: +```scala +scala> val w = introprog.PixelWindow() +val w: introprog.PixelWindow = introprog.PixelWindow@34f60be9 + +scala> w.drawText("Hello introprog.PixelWindow!", x = 100, y = 100) +``` + +If you want to use `introprog` in your program, add these magic comment lines starting with `//>` in the beginning of your Scala 3 file (update the version number after `//> using scala` to the [latest release](https://www.scala-lang.org/)): ``` //> using scala 3.5.2 //> using dep se.lth.cs::introprog:1.3.1 ``` -You run your code with `scala-cli run .` (note the ending dot, meaning "this dir") +You can then run your code with `scala run .` (note the ending dot, meaning "current dir") If your program looks like this: @@ -42,20 +55,18 @@ You should see green text in a new window after executing: ``` scala-cli run . ``` -See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) +See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) for more things you can do with a PixelWindow. -You can also give the `introprog` dependency directly at the command line, instead of the `using lib` directive: +You can also give the `introprog` dependency directly at the command line, instead of the `using dep` directive: ``` scala-cli run . --dep se.lth.cs::introprog:1.4.0 ``` -### Using sbt +### Getting started using sbt -You need [Scala Build Tool](https://www.scala-sbt.org/download.html) at least version 1.5.2 (preferably 1.6.2 or later). - -Put this text in a file called `build.sbt` +If you use the [Scala Build Tool, version 1.6 or later](https://www.scala-sbt.org/download.html) then put this text in a file called `build.sbt` ``` -scalaVersion := "3.3.0" +scalaVersion := "3.5.2" libraryDependencies += "se.lth.cs" %% "introprog" % "1.4.0" ``` @@ -68,6 +79,7 @@ scala> val w = new introprog.PixelWindow() scala> w.fill(100,100,100,100,java.awt.Color.red) ``` See: [api documentation for PixelWindow](https://fileadmin.cs.lth.se/pgk/api/api/introprog/PixelWindow.html) + ### Older Scala versions If you want to use Scala 2.13 with 2.13.5 or later then use these special settings in `build.sbt`, esp. note that you should use version 1.1.5 of introprog: From d629077d3217fc188a99eb8844eb8e9ea1d7d8a6 Mon Sep 17 00:00:00 2001 From: EliasAAradsson Date: Sat, 9 Nov 2024 10:53:26 +0100 Subject: [PATCH 04/10] Improve documentation for Dialog --- src/main/scala/introprog/Dialog.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/scala/introprog/Dialog.scala b/src/main/scala/introprog/Dialog.scala index 288233e..d961759 100644 --- a/src/main/scala/introprog/Dialog.scala +++ b/src/main/scala/introprog/Dialog.scala @@ -6,7 +6,14 @@ object Dialog: Swing.init() // get platform-specific look and feel - /** Show a file choice dialog starting in `startDir` with confirm `button` text. */ + /** + * Show a file choice dialog starting in `startDir` with confirm `button` text. + * + * @param button the text displayed in this file choice dialog's confirm button + * @param startDir the starting directory of this file choice dialog + * @return the file path entered by user upon pressing confirm button, + * an empty `String` if user pressed the file choice dialog's cancel button + */ def file(button: String = "Open", startDir: String = "~"): String = val fs = new JFileChooser(new java.io.File(startDir)) fs.showDialog(null, button) match From f75bc1008bcee3f734a60423f9b80408257f5b44 Mon Sep 17 00:00:00 2001 From: EliasAAradsson Date: Sun, 17 Nov 2024 19:05:36 +0100 Subject: [PATCH 05/10] Tidy up documentation for method `input` --- src/main/scala/introprog/Dialog.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/scala/introprog/Dialog.scala b/src/main/scala/introprog/Dialog.scala index d961759..a45bdfd 100644 --- a/src/main/scala/introprog/Dialog.scala +++ b/src/main/scala/introprog/Dialog.scala @@ -23,9 +23,13 @@ object Dialog: /** Show a dialog with a `message` text. */ def show(message: String): Unit = JOptionPane.showMessageDialog(null, message) - /** Show a `message` asking for input with `init` value. Return user input. + /** + * Show a `message` asking for input with `init` value. Return user input. * - * Returns empty string on Cancel. */ + * @param message prompt text displayed for user + * @param init intitial value displayed in input dialog + * @return user input, or an empty string on Cancel + */ def input(message: String, init: String = ""): String = Option(JOptionPane.showInputDialog(message, init)).getOrElse("") From cf845a7736d380fb0dc1e7fd78b89224d5333c4d Mon Sep 17 00:00:00 2001 From: EliasAAradsson Date: Sun, 17 Nov 2024 19:13:18 +0100 Subject: [PATCH 06/10] Remove unexpected reverse of button order in method `select` --- src/main/scala/introprog/Dialog.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/introprog/Dialog.scala b/src/main/scala/introprog/Dialog.scala index d961759..6532cfc 100644 --- a/src/main/scala/introprog/Dialog.scala +++ b/src/main/scala/introprog/Dialog.scala @@ -40,7 +40,7 @@ object Dialog: scala.util.Try{ val chosenIndex = JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION, - JOptionPane.QUESTION_MESSAGE, null, buttons.reverse.toArray, null) + JOptionPane.QUESTION_MESSAGE, null, buttons.toArray, null) buttons(buttons.length - 1 - chosenIndex) }.getOrElse("") From 8ff117bd4be77c8d93a1c82a7089bdc6eed007d0 Mon Sep 17 00:00:00 2001 From: EliasAAradsson Date: Sun, 17 Nov 2024 23:21:00 +0100 Subject: [PATCH 07/10] Make method `select` nice Modify indexing in method `select` in order to match previous removal of reverse. Improve documentation of aforementioned method. --- src/main/scala/introprog/Dialog.scala | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/scala/introprog/Dialog.scala b/src/main/scala/introprog/Dialog.scala index fe54afd..b9e17c8 100644 --- a/src/main/scala/introprog/Dialog.scala +++ b/src/main/scala/introprog/Dialog.scala @@ -39,13 +39,22 @@ object Dialog: null, question, title, JOptionPane.OK_CANCEL_OPTION ) == JOptionPane.OK_OPTION - /** Show a selection dialog with `buttons`. Return a string with the chosen button text. */ + /** + * Show a selection dialog with `buttons`. Return a `String` with the chosen button text. + * + * @param message text describing the choice to be made by the user + * @param buttons the sequence of buttons to be displayed in this dialog + * @param title the title of this dialog + * @return a `String` with the chosen button text + */ def select(message: String, buttons: Seq[String], title: String = "Select"): String = scala.util.Try{ val chosenIndex = - JOptionPane.showOptionDialog(null, message, title, JOptionPane.DEFAULT_OPTION, - JOptionPane.QUESTION_MESSAGE, null, buttons.toArray, null) - buttons(buttons.length - 1 - chosenIndex) + JOptionPane.showOptionDialog( + null, message, title, JOptionPane.DEFAULT_OPTION, + JOptionPane.QUESTION_MESSAGE, null, buttons.toArray, null + ) + buttons(chosenIndex) }.getOrElse("") /** Show a color selection dialog and return the color that the user selected. */ From b2243b433ef710e1ec3fef4a2b59b3a525b3e150 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Wed, 19 Feb 2025 12:12:25 +0100 Subject: [PATCH 08/10] update publish instructions --- PUBLISH.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PUBLISH.md b/PUBLISH.md index 88da291..802218e 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -126,7 +126,7 @@ sbt:introprog> publishSigned [info] published introprog_3 to https://oss.sonatype.org/service/local/staging/deploy/maven2/se/lth/cs/introprog_3/1.4.0/introprog_3-1.4.0-sources.jar.asc ``` -OOOPS! TODO: I already had this file: `cat ~/.sbt/sonatype_credential` pulled in by `cat ~/.sbt/1.0/sonatype.sbt` so I should remove the last of them as Credentials is now included in the build.sbt +OOOPS! TODO: I already had this file: `cat ~/.sbt/sonatype_credential` pulled in by `cat ~/.sbt/1.0/sonatype.sbt` so I should remove the last of them as Credentials is now included in the build.sbt as in `credentials += Credentials(Path.userHome / ".sbt" / ".credentials")` 5. After you have done `sbt publishSigned` then log into Sonatype Nexus here: (if the page does not load, clear the browser's cache by pressing Ctrl+F5) https://oss.sonatype.org/#welcome From 9a0a2391d098c3e6bb207d4e733403625af9be9f Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Wed, 13 Aug 2025 14:05:57 +0200 Subject: [PATCH 09/10] change workflow runner version to ubuntu-latest --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3a1a008..ade6fc0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: Build on: [push] jobs: Test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Check out repository code uses: actions/checkout@v2 From f5c498c5957a5aab872e85e5bc9c266cca550764 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Wed, 13 Aug 2025 14:09:25 +0200 Subject: [PATCH 10/10] use official recommended github actions at https://www.scala-sbt.org/1.x/docs/GitHub-Actions-with-sbt.html --- .github/workflows/main.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ade6fc0..72ee9ae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,11 +1,19 @@ -name: Build -on: [push] +name: CI +on: + pull_request: + push: jobs: - Test: + test: runs-on: ubuntu-latest steps: - - name: Check out repository code - uses: actions/checkout@v2 - - name: SBT Build - run: sbt test - shell: bash + - name: Checkout + uses: actions/checkout@v4 + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + - name: Setup sbt launcher + uses: sbt/setup-sbt@v1 + - name: Build and Test + run: sbt +test