Skip to content

Commit

Permalink
Merge pull request #549 from digital-preservation/uiAdjustments
Browse files Browse the repository at this point in the history
UI adjustments
  • Loading branch information
techncl authored Feb 21, 2025
2 parents 3166c59 + 0ab2277 commit d19d365
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import scala.util.{Failure, Success, Try, Using}
* @author Adam Retter <adam.retter@googlemail.com>
*/
object CsvValidatorUi extends SimpleSwingApplication {
var prefSizeHeightChanged = true

override def startup(args: Array[String]) : Unit = {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
Expand All @@ -60,7 +62,28 @@ object CsvValidatorUi extends SimpleSwingApplication {
private lazy val txtCsvFile = new JTextField(30)
private lazy val txtCsvSchemaFile = new JTextField(30)

private def changeHeightOfOutputPane(heightDiff: Int): Unit = {
// need to normalise the height change by converting it to "rows"
val heightChangeAsRows = Math.ceil(heightDiff / 50f).toInt // 30 is just an arbitrary number that seemed to work fine
val newHeight = if((txtArReport.rows + heightChangeAsRows) <= 1) txtArReport.rows + 1
else if((txtArReport.rows + heightChangeAsRows) > 40) 40
else txtArReport.rows + heightChangeAsRows

// sometimes the size and preferredSize height stay the same even when the window gets larger so just make box size large in this case
val finalHeight = if(heightDiff == 0 && !prefSizeHeightChanged) 40 else newHeight
txtArReport.rows = Math.abs(finalHeight)
}

def top: SJXFrame = new SJXFrame {
this.listenTo(this) // add a listener to the window to listen for all changes to the window
private var previousHeight = this.preferredSize.height
this.reactions += onResize {
val heightDiff = this.size.height - this.preferredSize.height

changeHeightOfOutputPane(heightDiff)
prefSizeHeightChanged = previousHeight != this.preferredSize.height
previousHeight = this.preferredSize.height
}

title = "CSV Validator"
peer.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
Expand All @@ -70,11 +93,12 @@ object CsvValidatorUi extends SimpleSwingApplication {
//handle resizing the main window, when resizing the settings panel
settings.settingsGroup.reactions += SJXTaskPane.onViewStateChanged {
val newSize = if(settings.settingsGroup.collapsed) {
txtArReport.rows = 35
txtArReport.rows = 40
this.size
} else {
txtArReport.rows = 9
new Dimension(this.size.getWidth.toInt, (this.size.getHeight + settings.size.getHeight).toInt)
val settingsHeight = settings.size.getHeight
new Dimension(this.size.getWidth.toInt, (this.preferredSize.getHeight + settingsHeight).toInt)
}
this.preferredSize = newSize
this.pack()
Expand Down Expand Up @@ -237,7 +261,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
}.map(Some(_)).getOrElse(None)
}

private val txtArReport = new TextArea(35,30)
private val txtArReport = new TextArea()

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

val saveLabel = "Save Results"
val saveLabel = "Save Results..."
reportFileChooser.title = saveLabel
private val btnSave = new Button(saveLabel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package uk.gov.nationalarchives.csv.validator.ui

import swing._
import scala.swing.event.{ButtonClicked, Key, KeyPressed, MouseClicked}
import scala.swing.event.{ButtonClicked, Key, KeyPressed, MouseClicked, UIElementResized}
import swing.FileChooser.Result
import swing.GridBagPanel.Anchor
import java.beans.{PropertyChangeEvent, PropertyChangeListener}
Expand Down Expand Up @@ -164,4 +164,8 @@ object ScalaSwingHelpers {
f(e)
}
}

def onResize(action: => Unit) : Reactions.Reaction = {
case evt: UIElementResized => action
}
}

0 comments on commit d19d365

Please sign in to comment.