95737d49858710673b5f32e8ec70f5fba7fe3027
[jalview.git] / utils / test / JalviewJSTest.java
1 package test;
2 import java.awt.BorderLayout;
3 import java.awt.ComponentOrientation;
4 import java.awt.Container;
5 import java.awt.Dimension;
6 import java.awt.Font;
7 import java.awt.GridLayout;
8
9 import javax.swing.JCheckBox;
10 import javax.swing.JFrame;
11 import javax.swing.JPanel;
12 import javax.swing.JRadioButton;
13 import javax.swing.SwingConstants;
14 import javax.swing.border.TitledBorder;
15
16 /**
17  * A class with a main method entry point for ad hoc tests of JalviewJS
18  * behaviour. The J2S transpiler should generate an html entry point for this
19  * class, allowing comparison between Java and Javascript execution.
20  */
21 @SuppressWarnings("serial")
22 public class JalviewJSTest extends JPanel
23 {
24   public static void main(String[] args)
25   {
26     new JalviewJSTest().doTest();
27   }
28
29   /**
30    * Put some content in a JFrame and show it
31    */
32   void doTest()
33   {
34     JFrame main = new JFrame();
35     main.setContentPane(getVisualPaneContent());
36     main.pack();
37     main.setVisible(true);
38   }
39
40   /**
41    * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
42    * problems
43    */
44   Container getVisualPaneContent()
45   {
46     JPanel panel = new JPanel();
47     panel.setPreferredSize(new Dimension(400, 500));
48     panel.setOpaque(true);
49     panel.setLayout(new BorderLayout());
50
51     JPanel firstColumn = new JPanel();
52     firstColumn.setLayout(new GridLayout(10, 1));
53     firstColumn.setBorder(new TitledBorder("column 1"));
54
55     /*
56      * bug 21/08/18:
57      * - checkbox label and text extend outside the enclosing panel in JS
58      */
59     JCheckBox cb1 = new JCheckBox();
60     Font font = new Font("Verdana", Font.PLAIN, 11);
61     cb1.setFont(font);
62     cb1.setText("Maximise Window");
63     cb1.setHorizontalTextPosition(SwingConstants.LEADING);
64     cb1.setHorizontalAlignment(SwingConstants.LEFT);
65
66     /*
67      * bug 21/08/18:
68      * - label should precede checkbox, but it doesn't
69      */
70     JCheckBox cb2 = new JCheckBox("Open Overview");
71     cb2.setFont(font);
72     cb2.setHorizontalTextPosition(SwingConstants.LEADING);
73     // uncommenting this line gives 'leading text', but
74     // also results in label and checkbox outside container
75     //cb2.setHorizontalAlignment(SwingConstants.RIGHT);
76
77     
78 //    ImageIcon icon =  new ImageIcon(getClass()
79 //            .getClassLoader()
80 //            .getResource("test2.png"), "test");
81 //    
82     JCheckBox cb3 = new JCheckBox("leading,left-to-right");
83     cb3.setFont(font);
84     cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
85     cb3.setHorizontalTextPosition(SwingConstants.LEADING);
86
87     JCheckBox cb4 = new JCheckBox("leading,right-to-left");
88     cb4.setFont(font);
89     cb4.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
90     cb4.setHorizontalTextPosition(SwingConstants.LEADING);
91
92     JCheckBox cb5 = new JCheckBox("trailing,left-to-right");
93     cb5.setFont(font);
94     cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
95     cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
96
97     JCheckBox cb6 = new JCheckBox("trailing,right-to-left");
98     cb6.setFont(font);
99     cb6.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
100     cb6.setHorizontalTextPosition(SwingConstants.TRAILING);
101
102     JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
103     rb1.setFont(font);
104     rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
105     rb1.setHorizontalTextPosition(SwingConstants.TRAILING);
106
107     JRadioButton rb2 = new JRadioButton("right,left-to-right");
108     rb2.setFont(font);
109     rb2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
110     rb2.setHorizontalTextPosition(SwingConstants.RIGHT);
111
112     JRadioButton rb3 = new JRadioButton("right,right-to-left");
113     rb3.setFont(font);
114     rb3.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
115     rb3.setHorizontalTextPosition(SwingConstants.RIGHT);
116
117
118     
119     firstColumn.add(cb1);
120     firstColumn.add(cb2);
121     firstColumn.add(cb3);
122     firstColumn.add(cb4);
123     firstColumn.add(cb5);
124     firstColumn.add(cb6);
125     firstColumn.add(rb1);
126     firstColumn.add(rb2);
127     firstColumn.add(rb3);
128     firstColumn.setBounds(20, 20, 200, 500);
129
130     JPanel theTab = new JPanel();
131     theTab.setLayout(null);
132     theTab.add(firstColumn);
133     panel.add(theTab);
134
135     return panel;
136   }
137 }