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;
10 import java.text.DecimalFormat;
11 import java.util.HashMap;
14 import javax.swing.ImageIcon;
15 import javax.swing.JButton;
16 import javax.swing.JCheckBox;
17 import javax.swing.JCheckBoxMenuItem;
18 import javax.swing.JFrame;
19 import javax.swing.JLabel;
20 import javax.swing.JMenu;
21 import javax.swing.JMenuBar;
22 import javax.swing.JPanel;
23 import javax.swing.JRadioButton;
24 import javax.swing.JRadioButtonMenuItem;
25 import javax.swing.SwingConstants;
26 import javax.swing.WindowConstants;
27 import javax.swing.border.TitledBorder;
30 * A class with a main method entry point for ad hoc tests of JalviewJS
31 * behaviour. The J2S transpiler should generate an html entry point for this
32 * class, allowing comparison between Java and Javascript execution.
34 public class JalviewJSTest extends JPanel
36 public static void main(String[] args)
38 new JalviewJSTest().doTest2();
42 Map<File, String> map = new HashMap<>();
43 File f1 = new File("/var/folders/y/xyz");
44 File f2 = new File("/var/folders/y/xyz");
45 map.put(f1, "hello world");
46 System.out.println("f1.equals(f2) = " + f1.equals(f2));
47 System.out.println("f1 hashCode = " + f1.hashCode());
48 System.out.println("f2 hashCode = " + f2.hashCode());
49 System.out.println(map.get(f2));
52 * Put some content in a JFrame and show it
56 System.out.println("ab;c;".split(";"));
57 new DecimalFormat("###,###").format((Integer) 1);
58 JFrame main = new JFrame();
59 main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
60 JMenu menu = new JMenu("testing");
61 menu.setHorizontalAlignment(SwingConstants.RIGHT);
62 main.setContentPane(getVisualPaneContent(menu));
63 main.setJMenuBar(new JMenuBar());
64 main.getJMenuBar().add(menu);
66 main.setVisible(true);
70 * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
74 Container getVisualPaneContent(JMenu menu)
76 JPanel panel = new JPanel();
77 panel.setPreferredSize(new Dimension(400, 500));
78 panel.setOpaque(true);
79 panel.setLayout(new BorderLayout());
81 JPanel firstColumn = new JPanel();
82 firstColumn.setLayout(new GridLayout(10, 1));
83 firstColumn.setBorder(new TitledBorder("column 1"));
87 * - checkbox label and text extend outside the enclosing panel in JS
89 Font font = new Font("Verdana", Font.PLAIN, 11);
91 JLabel l1 = new JLabel(getImage("test2.png"));
92 l1.setText("trailing right");
93 l1.setHorizontalTextPosition(SwingConstants.TRAILING);
94 l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
95 l1.setHorizontalAlignment(SwingConstants.RIGHT);
97 JLabel l2 = new JLabel(getImage("test2.png"));
98 l2.setText("leading left");
100 l2.setHorizontalTextPosition(SwingConstants.LEADING);
101 l2.setHorizontalAlignment(SwingConstants.LEFT);
103 JButton b1 = new JButton("right left");
104 b1.setIcon(getImage("test2.png"));
106 b1.setHorizontalTextPosition(SwingConstants.RIGHT);
107 b1.setHorizontalAlignment(SwingConstants.LEFT);
114 JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
116 cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
117 cb3.setHorizontalTextPosition(SwingConstants.LEADING);
118 cb3.setHorizontalAlignment(SwingConstants.TRAILING);
120 JCheckBox cb4 = new JCheckBox("leading,right-to-left");
122 cb4.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
123 cb4.setHorizontalTextPosition(SwingConstants.LEADING);
125 JCheckBox cb5 = new JCheckBox("trailing,left-to-right");
127 cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
128 cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
130 JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
132 rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
133 rb1.setHorizontalTextPosition(SwingConstants.TRAILING);
135 JRadioButton rb2 = new JRadioButton("right,left-to-right");
137 rb2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
138 rb2.setHorizontalTextPosition(SwingConstants.RIGHT);
140 JRadioButton rb3 = new JRadioButton("right,right-to-left");
142 rb3.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
143 rb3.setHorizontalTextPosition(SwingConstants.RIGHT);
147 firstColumn.add(cb3);
148 firstColumn.add(cb4);
149 firstColumn.add(cb5);
150 firstColumn.add(rb1);
151 firstColumn.add(rb2);
152 firstColumn.add(rb3);
153 firstColumn.setBounds(200, 20, 200, 500);
155 JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
157 cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
158 cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
160 JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
162 cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
163 cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
165 JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
167 cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
168 cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
170 JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
172 cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
173 cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
175 JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
177 rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
178 rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
180 JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
182 rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
183 rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
185 JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
187 rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
188 rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
190 JMenu m1 = new JMenu("left");
191 JMenu m2 = new JMenu("right");
202 JPanel theTab = new JPanel();
204 theTab.setLayout(null);
205 theTab.add(firstColumn);
211 private ImageIcon getImage(String name) {
212 ImageIcon icon = new ImageIcon(getClass().getResource(name));
214 while(icon.getImageLoadStatus() == MediaTracker.LOADING)
217 } catch (InterruptedException e) {