Skip to content

Commit 18055d0

Browse files
author
Hugo Miguel Ferreira
committed
First original modern clients example working.
1 parent 7df1078 commit 18055d0

11 files changed

+301
-3
lines changed

build.sc

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// cSpell:ignore scalalib, helloworld, coursier, Deps, unmanaged, classpath
2-
// cSpell:ignore javafx, controlsfx, openjfx
1+
// cSpell:ignore scalalib, helloworld, coursier, Deps, unmanaged, classpath, JVM's, customizer, dprism
2+
// cSpell:ignore javafx, controlsfx, openjfx, munit
33

44
import coursier.core.Resolution
55
import mill._
@@ -181,7 +181,6 @@ object HelloWorldJava extends OpenJFX {
181181

182182
}
183183

184-
185184
object HelloWorldScala extends OpenJFX with ScalaModule {
186185
def scalaVersion = T{ ScalaVersion }
187186

@@ -195,3 +194,33 @@ object HelloWorldScala extends OpenJFX with ScalaModule {
195194

196195

197196

197+
object modernClients extends ScalaModule {
198+
def scalaVersion = T{ ScalaVersion }
199+
200+
object HelloWorldScala extends OpenJFX with ScalaModule {
201+
def scalaVersion = T{ ScalaVersion }
202+
203+
override def mainClass: T[Option[String]] = Some("helloworld.HelloWorld")
204+
205+
override def ivyDeps = Agg(
206+
ivy"$CONTROLS",
207+
ivy"$CONTROLSFX",
208+
)
209+
210+
}
211+
212+
object HelloModernWorld extends OpenJFX with ScalaModule {
213+
def scalaVersion = T{ ScalaVersion }
214+
215+
override def mainClass: T[Option[String]] = Some("helloworld.HelloWorld")
216+
217+
override def ivyDeps = Agg(
218+
ivy"$CONTROLS",
219+
ivy"$CONTROLSFX",
220+
ivy"$FXML"
221+
)
222+
223+
}
224+
225+
}
226+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.effect.Bloom?>
5+
<?import javafx.scene.image.Image?>
6+
<?import javafx.scene.image.ImageView?>
7+
<?import javafx.scene.layout.AnchorPane?>
8+
<?import javafx.scene.layout.ColumnConstraints?>
9+
<?import javafx.scene.layout.GridPane?>
10+
<?import javafx.scene.layout.RowConstraints?>
11+
<?import javafx.scene.text.Font?>
12+
13+
<GridPane alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
14+
<columnConstraints>
15+
<ColumnConstraints />
16+
</columnConstraints>
17+
<rowConstraints>
18+
<RowConstraints />
19+
</rowConstraints>
20+
<children>
21+
<ImageView pickOnBounds="true" preserveRatio="true">
22+
<image>
23+
<Image url="@1024px-ISS-RapidScat_nadir_adapter_removed_from_CRS-4_Dragon_trunk_(ISS041E049097).jpg" />
24+
</image>
25+
</ImageView>
26+
<AnchorPane prefHeight="200.0" prefWidth="200.0">
27+
<children>
28+
<Label layoutX="195.0" layoutY="163.0" text="Hello World" textFill="WHITE">
29+
<font>
30+
<Font name="Courier" size="96.0" />
31+
</font>
32+
</Label>
33+
<Label layoutX="373.0" layoutY="267.0" text="Java" textFill="#ffa518">
34+
<font>
35+
<Font size="77.0" />
36+
</font>
37+
</Label>
38+
<Label layoutX="542.0" layoutY="267.0" text="FX" textFill="#5382a1">
39+
<font>
40+
<Font size="77.0" />
41+
</font>
42+
</Label>
43+
</children>
44+
<effect>
45+
<Bloom />
46+
</effect>
47+
</AnchorPane>
48+
</children>
49+
</GridPane>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package sample;
2+
3+
public class Controller {
4+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package sample;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
/**
10+
*
11+
* ./mill mill.scalalib.GenIdea/idea
12+
*
13+
* ./mill -i modernClients.HelloModernWorld.runMain sample.Main
14+
* ./mill -i --watch modernClients.HelloModernWorld.runMain sample.Main
15+
*
16+
* Note on resources (see StackOverflow link below): Mill's convention is to
17+
* place a resources directory on the lowest level Mill module. To access
18+
* these resources one must use the path relative to the application (Mill
19+
* module) and not the class (because resources are not copied to the compiled
20+
* class directory).
21+
*
22+
* If you want to keep the resources next to the classes, these would require
23+
* you change Mill behavior to copy them, or do it yourself.
24+
*
25+
* @see https://stackoverflow.com/questions/22000423/javafx-and-maven-nullpointerexception-location-is-required
26+
* @see https://stackoverflow.com/questions/12124657/getting-started-on-scala-javafx-desktop-application-development
27+
*/
28+
public class Main extends Application {
29+
30+
@Override
31+
public void start(Stage primaryStage) throws Exception{
32+
//System.out.println(System.getProperty("user.dir"));
33+
// Place a resources directory at the same level as Mill module
34+
// Both loads will work relative to the module
35+
Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml"));
36+
//Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("sample.fxml"));
37+
//Parent root = FXMLLoader.load(getClass().getResource("resources/sample.fxml"));
38+
primaryStage.setTitle("Hello Modern World");
39+
primaryStage.setScene(new Scene(root));
40+
primaryStage.show();
41+
}
42+
43+
44+
public static void main(String[] args) {
45+
launch(args);
46+
}
47+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.effect.Bloom?>
5+
<?import javafx.scene.image.Image?>
6+
<?import javafx.scene.image.ImageView?>
7+
<?import javafx.scene.layout.AnchorPane?>
8+
<?import javafx.scene.layout.ColumnConstraints?>
9+
<?import javafx.scene.layout.GridPane?>
10+
<?import javafx.scene.layout.RowConstraints?>
11+
<?import javafx.scene.text.Font?>
12+
13+
<GridPane alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
14+
<columnConstraints>
15+
<ColumnConstraints />
16+
</columnConstraints>
17+
<rowConstraints>
18+
<RowConstraints />
19+
</rowConstraints>
20+
<children>
21+
<ImageView pickOnBounds="true" preserveRatio="true">
22+
<image>
23+
<Image url="@1024px-ISS-RapidScat_nadir_adapter_removed_from_CRS-4_Dragon_trunk_(ISS041E049097).jpg" />
24+
</image>
25+
</ImageView>
26+
<AnchorPane prefHeight="200.0" prefWidth="200.0">
27+
<children>
28+
<Label layoutX="195.0" layoutY="163.0" text="Hello World" textFill="WHITE">
29+
<font>
30+
<Font name="Courier" size="96.0" />
31+
</font>
32+
</Label>
33+
<Label layoutX="373.0" layoutY="267.0" text="Java" textFill="#ffa518">
34+
<font>
35+
<Font size="77.0" />
36+
</font>
37+
</Label>
38+
<Label layoutX="542.0" layoutY="267.0" text="FX" textFill="#5382a1">
39+
<font>
40+
<Font size="77.0" />
41+
</font>
42+
</Label>
43+
</children>
44+
<effect>
45+
<Bloom />
46+
</effect>
47+
</AnchorPane>
48+
</children>
49+
</GridPane>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package button
2+
3+
import javafx.application.Application
4+
import javafx.stage.Stage
5+
import javafx.scene.Scene
6+
import javafx.scene.layout.VBox
7+
import javafx.scene.control.Button
8+
9+
class ButtonApp extends Application {
10+
11+
override def start(stage: Stage) = {
12+
System.out.println("STARTED Modern Scala!")
13+
var button = new Button("Please Modern Scala Click Me!")
14+
button.setOnAction(e => stage.close())
15+
var box = new VBox()
16+
box.getChildren().add(button)
17+
var scene = new Scene(box)
18+
stage.setScene(scene)
19+
stage.setTitle("Just a Modern Scala button")
20+
stage.show()
21+
}
22+
23+
def launchIt():Unit={
24+
Application.launch()
25+
}
26+
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package button
2+
3+
/**
4+
*
5+
* ./mill mill.scalalib.GenIdea/idea
6+
*
7+
* ./mill -i modernClients.HelloWorldScala.runMain button.Main
8+
* ./mill -i --watch modernClients.HelloWorldScala.runMain button.Main
9+
*
10+
*
11+
* @see https://stackoverflow.com/questions/12124657/getting-started-on-scala-javafx-desktop-application-development
12+
*/
13+
object Main {
14+
def main(args: Array[String]) =
15+
val app = new ButtonApp
16+
app.launchIt()
17+
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package helloworld
2+
3+
// cSpell:ignore helloworld
4+
5+
import javafx.application.Application
6+
import javafx.event.ActionEvent
7+
import javafx.event.EventHandler
8+
import javafx.scene.Scene
9+
import javafx.scene.control.Button
10+
import javafx.scene.layout.StackPane
11+
import javafx.stage.Stage
12+
13+
/**
14+
*
15+
* ./mill mill.scalalib.GenIdea/idea
16+
*
17+
* ./mill -i modernClients.HelloWorldScala.run
18+
* ./mill -i modernClients.HelloWorldScala.runMain helloworld.HelloWorld
19+
* ./mill -i --watch modernClients.HelloWorldScala.run
20+
*
21+
* @see https://stackoverflow.com/questions/12124657/getting-started-on-scala-javafx-desktop-application-development
22+
*/
23+
class HelloWorld extends Application {
24+
25+
override def start(primaryStage: Stage) = {
26+
primaryStage.setTitle("Hello Modern Scala World!")
27+
val btn = new Button()
28+
btn.setText("Say 'Hello Modern Scala World'")
29+
btn.setOnAction(new EventHandler[ActionEvent]() {
30+
override def handle(event: ActionEvent) = {
31+
System.out.println("Hello Modern Scala World!")
32+
}
33+
})
34+
35+
val root = new StackPane()
36+
root.getChildren().add(btn)
37+
primaryStage.setScene(new Scene(root, 300, 250))
38+
primaryStage.show()
39+
}
40+
}
41+
42+
object HelloWorld:
43+
def main(args: Array[String]) =
44+
Application.launch(classOf[HelloWorld], args: _*)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* cspell: disable-next-line */
2+
package HelloWorld
3+
4+
// cSpell:ignore splotly, munit
5+
6+
/**
7+
* ./mill mill.scalalib.GenIdea/idea
8+
*
9+
* ./mill -i HelloWorld.test
10+
* ./mill -i HelloWorld.test.testLocal
11+
* ./mill -i HelloWorld.test HelloWorld.PlotSpec.*
12+
* ./mill -i HelloWorld.test HelloWorld.PlotSpec.hello // test("hello")
13+
*
14+
* Extending `TestCase` to get access to `setUp`
15+
*
16+
* https://github.com/sbt/junit-interface#junit-interface
17+
* ./mill -i managed.test --tests=test1 Only matches test names (not classes)
18+
*
19+
*
20+
*/
21+
class PlotSpec extends munit.FunSuite {
22+
23+
test("hello") {
24+
val obtained = 42
25+
val expected = 43
26+
assertEquals(obtained, expected)
27+
}
28+
29+
}
30+
31+

0 commit comments

Comments
 (0)