3b6ca2e42ca6b66288f2d784f41099f996e8279b
[jalview.git] / utils / JalviewJSTest.java
1 import java.awt.BorderLayout;
2 import java.awt.Container;
3 import java.awt.Dimension;
4 import java.awt.Font;
5 import java.awt.GridLayout;
6
7 import javax.swing.JCheckBox;
8 import javax.swing.JFrame;
9 import javax.swing.JPanel;
10 import javax.swing.SwingConstants;
11 import javax.swing.border.TitledBorder;
12
13 /**
14  * A class with a main method entry point for ad hoc tests of JalviewJS
15  * behaviour. The J2S transpiler should generate an html entry point for this
16  * class, allowing comparison between Java and Javascript execution.
17  */
18 public class JalviewJSTest extends JPanel
19 {
20   public static void main(String[] args)
21   {
22     new JalviewJSTest().doTest();
23   }
24
25   /**
26    * Put some content in a JFrame and show it
27    */
28   void doTest()
29   {
30     JFrame main = new JFrame();
31     main.setContentPane(getVisualPaneContent());
32     main.pack();
33     main.setVisible(true);
34   }
35
36   /**
37    * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
38    * problems
39    */
40   Container getVisualPaneContent()
41   {
42     JPanel panel = new JPanel();
43     panel.setPreferredSize(new Dimension(400, 300));
44     panel.setOpaque(true);
45     panel.setLayout(new BorderLayout());
46
47     JPanel firstColumn = new JPanel();
48     firstColumn.setLayout(new GridLayout(6, 1));
49     firstColumn.setBorder(new TitledBorder("column 1"));
50
51     /*
52      * bug 21/08/18:
53      * - checkbox label and text extend outside the enclosing panel in JS
54      */
55     JCheckBox cb1 = new JCheckBox();
56     Font font = new Font("Verdana", Font.PLAIN, 11);
57     cb1.setFont(font);
58     cb1.setText("Maximise Window");
59     cb1.setHorizontalTextPosition(SwingConstants.LEADING);
60     cb1.setHorizontalAlignment(SwingConstants.RIGHT);
61
62     /*
63      * bug 21/08/18:
64      * - label should precede checkbox, but it doesn't
65      */
66     JCheckBox cb2 = new JCheckBox("Open Overview");
67     cb2.setFont(font);
68     cb2.setHorizontalTextPosition(SwingConstants.LEADING);
69     // uncommenting this line gives 'leading text', but
70     // also results in label and checkbox outside container
71     //cb2.setHorizontalAlignment(SwingConstants.RIGHT);
72
73     firstColumn.add(cb1);
74     firstColumn.add(cb2);
75     firstColumn.setBounds(20, 20, 200, 200);
76
77     JPanel theTab = new JPanel();
78     theTab.setLayout(null);
79     theTab.add(firstColumn);
80     panel.add(theTab);
81
82     return panel;
83   }
84 }