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