1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// TLCockpit
// Copyright 2017-2018 Norbert Preining
// Licensed according to GPLv3+
//
// Front end for tlmgr
package TLCockpit
import TLCockpit.ApplicationMain.stage
import TeXLive.TLPaperConf
import com.typesafe.scalalogging.LazyLogging
import scalafx.Includes._
import scalafx.collections.ObservableBuffer
import scalafx.geometry.{HPos, Insets}
import scalafx.scene.control._
import scalafx.scene.layout._
class PaperDialog(paperconf: Map[String, TLPaperConf]) extends LazyLogging {
case class Result(selected: Map[String,String])
val dialog = new Dialog[Result]() {
initOwner(stage)
title = s"Paper configuration"
headerText = s"Paper configuration"
resizable = true
}
dialog.dialogPane().buttonTypes = Seq(ButtonType.OK, ButtonType.Cancel)
val grid = new GridPane() {
hgap = 10
vgap = 10
padding = Insets(20)
}
var crow = 0
def update_all_to(str: String): Unit = {
cbseq.foreach(f => f._2.value = str)
}
grid.add(new Label("Set all to:"), 0, crow)
grid.add(new HBox(20) {
children = List(
new Button("a4") { onAction = _ => update_all_to("a4") },
new Button("letter") { onAction = _ => update_all_to("letter")}
)}, 1, crow)
crow += 1
def do_one(k: String, v: ChoiceBox[String], row: Int): Int = {
grid.add(new Label(k), 0, row)
grid.add(v, 1, row)
row + 1
}
val cbseq: Map[String, ChoiceBox[String]] = paperconf.map { p =>
val prog: String = p._1
val opts: TLPaperConf = p._2
val paperopts: Seq[String] = opts.options
val cb = new ChoiceBox[String](ObservableBuffer(paperopts.sorted))
cb.value = paperopts.head
crow = do_one(prog,cb, crow)
(prog, cb)
}
grid.columnConstraints = Seq(new ColumnConstraints(100, 100, 150), new ColumnConstraints(150, 150, 5000, Priority.Always, HPos.LEFT, true))
dialog.dialogPane().content = grid
dialog.width = 300
// dialog.height = 1500
dialog.resultConverter = dialogButton =>
if (dialogButton == ButtonType.OK)
Result(cbseq.mapValues(_.value.value))
else
null
def showAndWait(): Option[Map[String,String]] = {
val result = dialog.showAndWait()
result match {
case Some(Result(foo)) =>
logger.debug("Got result " + foo)
Some(foo)
case Some(foo) =>
logger.debug("Got strange result " + foo)
None
case None =>
None
}
}
}
|