2 import java.awt.BorderLayout;
3 import java.awt.ComponentOrientation;
4 import java.awt.Container;
5 import java.awt.Dimension;
7 import java.awt.GridLayout;
8 import java.awt.MediaTracker;
9 import java.text.DecimalFormat;
11 import javax.swing.ImageIcon;
12 import javax.swing.JButton;
13 import javax.swing.JCheckBox;
14 import javax.swing.JCheckBoxMenuItem;
15 import javax.swing.JFrame;
16 import javax.swing.JLabel;
17 import javax.swing.JMenu;
18 import javax.swing.JMenuBar;
19 import javax.swing.JPanel;
20 import javax.swing.JRadioButton;
21 import javax.swing.JRadioButtonMenuItem;
22 import javax.swing.SwingConstants;
23 import javax.swing.WindowConstants;
24 import javax.swing.border.TitledBorder;
27 * A class with a main method entry point for ad hoc tests of JalviewJS
28 * behaviour. The J2S transpiler should generate an html entry point for this
29 * class, allowing comparison between Java and Javascript execution.
31 public class JalviewJSTest extends JPanel
33 public static void main(String[] args)
35 new JalviewJSTest().doTest();
39 * Put some content in a JFrame and show it
43 new DecimalFormat("###,###").format((Integer) 1);
44 JFrame main = new JFrame();
45 main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
46 JMenu menu = new JMenu("testing");
47 menu.setHorizontalAlignment(SwingConstants.RIGHT);
48 main.setContentPane(getVisualPaneContent(menu));
49 main.setJMenuBar(new JMenuBar());
50 main.getJMenuBar().add(menu);
52 main.setVisible(true);
56 * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
60 Container getVisualPaneContent(JMenu menu)
62 JPanel panel = new JPanel();
63 panel.setPreferredSize(new Dimension(400, 500));
64 panel.setOpaque(true);
65 panel.setLayout(new BorderLayout());
67 JPanel firstColumn = new JPanel();
68 firstColumn.setLayout(new GridLayout(10, 1));
69 firstColumn.setBorder(new TitledBorder("column 1"));
73 * - checkbox label and text extend outside the enclosing panel in JS
75 Font font = new Font("Verdana", Font.PLAIN, 11);
77 JLabel l1 = new JLabel(getImage("test2.png"));
78 l1.setText("trailing right");
79 l1.setHorizontalTextPosition(SwingConstants.TRAILING);
80 l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
81 l1.setHorizontalAlignment(SwingConstants.RIGHT);
83 JLabel l2 = new JLabel(getImage("test2.png"));
84 l2.setText("leading left");
86 l2.setHorizontalTextPosition(SwingConstants.LEADING);
87 l2.setHorizontalAlignment(SwingConstants.LEFT);
89 JButton b1 = new JButton("right left");
90 b1.setIcon(getImage("test2.png"));
92 b1.setHorizontalTextPosition(SwingConstants.RIGHT);
93 b1.setHorizontalAlignment(SwingConstants.LEFT);
100 JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
102 cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
103 cb3.setHorizontalTextPosition(SwingConstants.LEADING);
104 cb3.setHorizontalAlignment(SwingConstants.TRAILING);
106 JCheckBox cb4 = new JCheckBox("leading,right-to-left");
108 cb4.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
109 cb4.setHorizontalTextPosition(SwingConstants.LEADING);
111 JCheckBox cb5 = new JCheckBox("trailing,left-to-right");
113 cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
114 cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
116 JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
118 rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
119 rb1.setHorizontalTextPosition(SwingConstants.TRAILING);
121 JRadioButton rb2 = new JRadioButton("right,left-to-right");
123 rb2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
124 rb2.setHorizontalTextPosition(SwingConstants.RIGHT);
126 JRadioButton rb3 = new JRadioButton("right,right-to-left");
128 rb3.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
129 rb3.setHorizontalTextPosition(SwingConstants.RIGHT);
133 firstColumn.add(cb3);
134 firstColumn.add(cb4);
135 firstColumn.add(cb5);
136 firstColumn.add(rb1);
137 firstColumn.add(rb2);
138 firstColumn.add(rb3);
139 firstColumn.setBounds(200, 20, 200, 500);
141 JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
143 cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
144 cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
146 JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
148 cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
149 cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
151 JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
153 cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
154 cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
156 JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
158 cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
159 cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
161 JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
163 rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
164 rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
166 JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
168 rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
169 rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
171 JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
173 rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
174 rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
176 JMenu m1 = new JMenu("left");
177 JMenu m2 = new JMenu("right");
188 JPanel theTab = new JPanel();
190 theTab.setLayout(null);
191 theTab.add(firstColumn);
197 private ImageIcon getImage(String name) {
198 ImageIcon icon = new ImageIcon(getClass().getResource(name));
200 while(icon.getImageLoadStatus() == MediaTracker.LOADING)
203 } catch (InterruptedException e) {