@@ -47,6 +47,8 @@ import scala.util.{Failure, Success, Try, Using}
4747 * @author Adam Retter <[email protected] > 4848 */
4949object 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
0 commit comments