24
24
import java .awt .AWTException ;
25
25
import java .awt .BorderLayout ;
26
26
import java .awt .Dimension ;
27
+ import java .awt .FlowLayout ;
27
28
import java .awt .Font ;
28
29
import java .awt .GraphicsConfiguration ;
29
30
import java .awt .GraphicsDevice ;
69
70
import javax .swing .JSplitPane ;
70
71
import javax .swing .JTextArea ;
71
72
import javax .swing .Timer ;
73
+ import javax .swing .border .Border ;
72
74
import javax .swing .text .JTextComponent ;
73
75
import javax .swing .text .html .HTMLEditorKit ;
74
76
import javax .swing .text .html .StyleSheet ;
@@ -655,6 +657,8 @@ private static JComponent createInstructionUIPanel(String instructions,
655
657
boolean addLogArea ,
656
658
int logAreaRows ) {
657
659
JPanel main = new JPanel (new BorderLayout ());
660
+ main .setBorder (createFrameBorder ());
661
+
658
662
timeoutHandlerPanel = new TimeoutHandlerPanel (testTimeOut );
659
663
main .add (timeoutHandlerPanel , BorderLayout .NORTH );
660
664
@@ -664,7 +668,7 @@ private static JComponent createInstructionUIPanel(String instructions,
664
668
text .setEditable (false );
665
669
666
670
JPanel textPanel = new JPanel (new BorderLayout ());
667
- textPanel .setBorder (createEmptyBorder (4 , 0 , 0 , 0 ));
671
+ textPanel .setBorder (createEmptyBorder (GAP , 0 , GAP , 0 ));
668
672
textPanel .add (new JScrollPane (text ), BorderLayout .CENTER );
669
673
670
674
main .add (textPanel , BorderLayout .CENTER );
@@ -681,7 +685,8 @@ private static JComponent createInstructionUIPanel(String instructions,
681
685
timeoutHandlerPanel .stop ();
682
686
});
683
687
684
- JPanel buttonsPanel = new JPanel ();
688
+ JPanel buttonsPanel = new JPanel (new FlowLayout (FlowLayout .CENTER ,
689
+ GAP , 0 ));
685
690
buttonsPanel .add (btnPass );
686
691
buttonsPanel .add (btnFail );
687
692
@@ -692,10 +697,12 @@ private static JComponent createInstructionUIPanel(String instructions,
692
697
if (addLogArea ) {
693
698
logArea = new JTextArea (logAreaRows , columns );
694
699
logArea .setEditable (false );
700
+ logArea .setBorder (createTextBorder ());
695
701
696
702
Box buttonsLogPanel = Box .createVerticalBox ();
697
703
698
704
buttonsLogPanel .add (buttonsPanel );
705
+ buttonsLogPanel .add (Box .createVerticalStrut (GAP ));
699
706
buttonsLogPanel .add (new JScrollPane (logArea ));
700
707
701
708
main .add (buttonsLogPanel , BorderLayout .SOUTH );
@@ -713,7 +720,7 @@ private static JTextComponent configurePlainText(String instructions,
713
720
JTextArea text = new JTextArea (instructions , rows , columns );
714
721
text .setLineWrap (true );
715
722
text .setWrapStyleWord (true );
716
- text .setBorder (createEmptyBorder ( 4 , 4 , 4 , 4 ));
723
+ text .setBorder (createTextBorder ( ));
717
724
return text ;
718
725
}
719
726
@@ -735,6 +742,29 @@ private static JTextComponent configureHTML(String instructions,
735
742
return text ;
736
743
}
737
744
745
+ /** A default gap between components. */
746
+ private static final int GAP = 4 ;
747
+
748
+ /**
749
+ * Creates a default border for frames or dialogs.
750
+ * It uses the default gap of {@value GAP}.
751
+ *
752
+ * @return the border for frames and dialogs
753
+ */
754
+ private static Border createFrameBorder () {
755
+ return createEmptyBorder (GAP , GAP , GAP , GAP );
756
+ }
757
+
758
+ /**
759
+ * Creates a border set to text area.
760
+ * It uses the default gap of {@value GAP}.
761
+ *
762
+ * @return the border for text area
763
+ */
764
+ private static Border createTextBorder () {
765
+ return createEmptyBorder (GAP , GAP , GAP , GAP );
766
+ }
767
+
738
768
739
769
/**
740
770
* Creates a test UI window.
@@ -1086,26 +1116,30 @@ public void awaitAndCheck() throws InterruptedException, InvocationTargetExcepti
1086
1116
* Requests the description of the test failure reason from the tester.
1087
1117
*/
1088
1118
private static void requestFailureReason () {
1089
- final JDialog dialog = new JDialog (frame , "Test Failure " , true );
1090
- dialog . setTitle ( "Failure reason" );
1091
- JPanel jPanel = new JPanel ( new BorderLayout () );
1092
- JTextArea jTextArea = new JTextArea ( 5 , 20 );
1119
+ final JDialog dialog = new JDialog (frame , "Failure reason " , true );
1120
+
1121
+ JTextArea reason = new JTextArea ( 5 , 20 );
1122
+ reason . setBorder ( createTextBorder () );
1093
1123
1094
1124
JButton okButton = new JButton ("OK" );
1095
1125
okButton .addActionListener ((ae ) -> {
1096
- String text = jTextArea .getText ();
1126
+ String text = reason .getText ();
1097
1127
setFailureReason (FAILURE_REASON
1098
1128
+ (!text .isEmpty () ? text : EMPTY_REASON ));
1099
1129
dialog .setVisible (false );
1100
1130
});
1101
1131
1102
- jPanel . add ( new JScrollPane ( jTextArea ), BorderLayout .CENTER );
1103
-
1104
- JPanel okayBtnPanel = new JPanel ( );
1132
+ JPanel okayBtnPanel = new JPanel ( new FlowLayout ( FlowLayout .CENTER ,
1133
+ GAP , 0 ));
1134
+ okayBtnPanel . setBorder ( createEmptyBorder ( GAP , 0 , 0 , 0 ) );
1105
1135
okayBtnPanel .add (okButton );
1106
1136
1107
- jPanel .add (okayBtnPanel , BorderLayout .SOUTH );
1108
- dialog .add (jPanel );
1137
+ JPanel main = new JPanel (new BorderLayout ());
1138
+ main .setBorder (createFrameBorder ());
1139
+ main .add (new JScrollPane (reason ), BorderLayout .CENTER );
1140
+ main .add (okayBtnPanel , BorderLayout .SOUTH );
1141
+
1142
+ dialog .add (main );
1109
1143
dialog .setLocationRelativeTo (frame );
1110
1144
dialog .pack ();
1111
1145
dialog .setVisible (true );
0 commit comments