Skip to content

Commit 3b9759b

Browse files
committed
Removed circular referencing which was causing the main frame to be recreated again and fixed some minor UI resizing issues
1 parent 4a5ff45 commit 3b9759b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import scala.util.Using
4040
* @author Adam Retter <[email protected]>
4141
*/
4242
object CsvValidatorUi extends SimpleSwingApplication {
43-
4443
override def startup(args: Array[String]) : Unit = {
4544
try {
4645
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
@@ -52,10 +51,11 @@ object CsvValidatorUi extends SimpleSwingApplication {
5251
}
5352

5453
def top = new SJXFrame {
54+
5555
title = "CSV Validator"
5656
peer.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
5757
contents = {
58-
val settings = new SettingsPanel
58+
val settings = new SettingsPanel(this)
5959

6060
//handle resizing the main window, when resizing the settings panel
6161
settings.settingsGroup.reactions += SJXTaskPane.onViewStateChanged {
@@ -64,10 +64,9 @@ object CsvValidatorUi extends SimpleSwingApplication {
6464
} else {
6565
new Dimension(this.size.getWidth.toInt, (this.size.getHeight + settings.size.getHeight).toInt)
6666
}
67-
this.size = newSize
67+
this.preferredSize = newSize
6868
this.pack()
6969
}
70-
7170
new ContentPanel(settings)
7271
}
7372
}
@@ -408,7 +407,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
408407
* us to break up the code easily, hopefully
409408
* making it more understandable.
410409
*/
411-
private class SettingsPanel extends SJXTaskPaneContainer {
410+
private class SettingsPanel(parentFrame: SJXFrame) extends SJXTaskPaneContainer {
412411

413412
private lazy val CHARACTER_ENCODINGS =
414413
if(Charset.defaultCharset.name == "UTF-8") {
@@ -455,7 +454,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
455454

456455
private val spTblPathSubstitutions = new ScrollPane(tblPathSubstitutions)
457456
private val btnAddPathSubstitution = new Button("Add Path Substitution...")
458-
btnAddPathSubstitution.reactions += onClick(addToTableDialog(top, "Add Path Substitution...", tblPathSubstitutions, tblPathSubstitutions.addRow))
457+
btnAddPathSubstitution.reactions += onClick(addToTableDialog(parentFrame, "Add Path Substitution...", tblPathSubstitutions, tblPathSubstitutions.addRow))
459458

460459
private val settingsGroupLayout = new GridBagPanel {
461460
private val c = new Constraints

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object ScalaSwingHelpers {
2626
/**
2727
* Opens a FileChooser and sets the path of the chosen file as the text of a Text Component
2828
*
29-
* @param fileChooser
29+
* @param fileChooser FileChooser which is Used to open file dialogs
3030
* @param output A text component which displays the absolute path of the chosen file
3131
* @param locateOver A component over which the FileChooser dialog should be located
3232
*/
@@ -37,7 +37,7 @@ object ScalaSwingHelpers {
3737
/**
3838
* Opens a FileChooser and sends the result to a function
3939
*
40-
* @param fileChooser
40+
* @param fileChooser FileChooser which is Used to open file dialogs
4141
* @param result A function which takes the chosen file
4242
* @param locateOver A component over which the FileChooser dialog should be located
4343
*/
@@ -67,10 +67,10 @@ object ScalaSwingHelpers {
6767

6868
val btnOk = new Button("Ok")
6969

70-
val optionLayout = new GridBagPanel {
70+
val optionLayout: GridBagPanel = new GridBagPanel {
7171
val c = new Constraints
7272

73-
for(colIdx <- (0 to table.model.getColumnCount - 1)) {
73+
for(colIdx <- 0 to table.model.getColumnCount - 1) {
7474
c.gridx = 0
7575
c.gridy = colIdx
7676
c.anchor = Anchor.LineStart
@@ -93,6 +93,7 @@ object ScalaSwingHelpers {
9393
dialog.modal = true
9494
dialog.title = title
9595
dialog.contents = optionLayout
96+
dialog.setLocationRelativeTo(owner)
9697

9798
btnOk.reactions += onClick(result({
9899
val textValues = for{
@@ -130,7 +131,7 @@ object ScalaSwingHelpers {
130131
action
131132
}
132133

133-
def PropertyChangeListener(f: PropertyChangeEvent => Unit) = new PropertyChangeListener {
134+
def PropertyChangeListener(f: PropertyChangeEvent => Unit): PropertyChangeListener = new PropertyChangeListener {
134135
def propertyChange(e: PropertyChangeEvent) : Unit = {
135136
f(e)
136137
}

0 commit comments

Comments
 (0)