Skip to content

Commit d19d365

Browse files
authored
Merge pull request #549 from digital-preservation/uiAdjustments
UI adjustments
2 parents 3166c59 + 0ab2277 commit d19d365

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

csv-validator-ui/src/main/scala/uk/gov/nationalarchives/csv/validator/ui/CsvValidatorUi.scala

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import scala.util.{Failure, Success, Try, Using}
4747
* @author Adam Retter <[email protected]>
4848
*/
4949
object CsvValidatorUi extends SimpleSwingApplication {
50+
var prefSizeHeightChanged = true
51+
5052
override def startup(args: Array[String]) : Unit = {
5153
try {
5254
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
@@ -60,7 +62,28 @@ object CsvValidatorUi extends SimpleSwingApplication {
6062
private lazy val txtCsvFile = new JTextField(30)
6163
private lazy val txtCsvSchemaFile = new JTextField(30)
6264

65+
private def changeHeightOfOutputPane(heightDiff: Int): Unit = {
66+
// need to normalise the height change by converting it to "rows"
67+
val heightChangeAsRows = Math.ceil(heightDiff / 50f).toInt // 30 is just an arbitrary number that seemed to work fine
68+
val newHeight = if((txtArReport.rows + heightChangeAsRows) <= 1) txtArReport.rows + 1
69+
else if((txtArReport.rows + heightChangeAsRows) > 40) 40
70+
else txtArReport.rows + heightChangeAsRows
71+
72+
// sometimes the size and preferredSize height stay the same even when the window gets larger so just make box size large in this case
73+
val finalHeight = if(heightDiff == 0 && !prefSizeHeightChanged) 40 else newHeight
74+
txtArReport.rows = Math.abs(finalHeight)
75+
}
76+
6377
def top: SJXFrame = new SJXFrame {
78+
this.listenTo(this) // add a listener to the window to listen for all changes to the window
79+
private var previousHeight = this.preferredSize.height
80+
this.reactions += onResize {
81+
val heightDiff = this.size.height - this.preferredSize.height
82+
83+
changeHeightOfOutputPane(heightDiff)
84+
prefSizeHeightChanged = previousHeight != this.preferredSize.height
85+
previousHeight = this.preferredSize.height
86+
}
6487

6588
title = "CSV Validator"
6689
peer.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
@@ -70,11 +93,12 @@ object CsvValidatorUi extends SimpleSwingApplication {
7093
//handle resizing the main window, when resizing the settings panel
7194
settings.settingsGroup.reactions += SJXTaskPane.onViewStateChanged {
7295
val newSize = if(settings.settingsGroup.collapsed) {
73-
txtArReport.rows = 35
96+
txtArReport.rows = 40
7497
this.size
7598
} else {
7699
txtArReport.rows = 9
77-
new Dimension(this.size.getWidth.toInt, (this.size.getHeight + settings.size.getHeight).toInt)
100+
val settingsHeight = settings.size.getHeight
101+
new Dimension(this.size.getWidth.toInt, (this.preferredSize.getHeight + settingsHeight).toInt)
78102
}
79103
this.preferredSize = newSize
80104
this.pack()
@@ -237,7 +261,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
237261
}.map(Some(_)).getOrElse(None)
238262
}
239263

240-
private val txtArReport = new TextArea(35,30)
264+
private val txtArReport = new TextArea()
241265

242266
/**
243267
* The main UI of the application
@@ -440,7 +464,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
440464
private val reportFileChooser = new FileChooser(lastReportPath)
441465
reportFileChooser.multiSelectionEnabled = false
442466

443-
val saveLabel = "Save Results"
467+
val saveLabel = "Save Results..."
444468
reportFileChooser.title = saveLabel
445469
private val btnSave = new Button(saveLabel)
446470

csv-validator-ui/src/main/scala/uk/gov/nationalarchives/csv/validator/ui/ScalaSwingHelpers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
package uk.gov.nationalarchives.csv.validator.ui
1010

1111
import swing._
12-
import scala.swing.event.{ButtonClicked, Key, KeyPressed, MouseClicked}
12+
import scala.swing.event.{ButtonClicked, Key, KeyPressed, MouseClicked, UIElementResized}
1313
import swing.FileChooser.Result
1414
import swing.GridBagPanel.Anchor
1515
import java.beans.{PropertyChangeEvent, PropertyChangeListener}
@@ -164,4 +164,8 @@ object ScalaSwingHelpers {
164164
f(e)
165165
}
166166
}
167+
168+
def onResize(action: => Unit) : Reactions.Reaction = {
169+
case evt: UIElementResized => action
170+
}
167171
}

0 commit comments

Comments
 (0)