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 hashCode = " + f1.hashCode());
47 System.out.println("f2 hashCode = " + f2.hashCode());
48 System.out.println(map.get(f2));
51 * Put some content in a JFrame and show it
55 System.out.println("ab;c;".split(";"));
56 new DecimalFormat("###,###").format((Integer) 1);
57 JFrame main = new JFrame();
58 main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
59 JMenu menu = new JMenu("testing");
60 menu.setHorizontalAlignment(SwingConstants.RIGHT);
61 main.setContentPane(getVisualPaneContent(menu));
62 main.setJMenuBar(new JMenuBar());
63 main.getJMenuBar().add(menu);
65 main.setVisible(true);
69 * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
73 Container getVisualPaneContent(JMenu menu)
75 JPanel panel = new JPanel();
76 panel.setPreferredSize(new Dimension(400, 500));
77 panel.setOpaque(true);
78 panel.setLayout(new BorderLayout());
80 JPanel firstColumn = new JPanel();
81 firstColumn.setLayout(new GridLayout(10, 1));
82 firstColumn.setBorder(new TitledBorder("column 1"));
86 * - checkbox label and text extend outside the enclosing panel in JS
88 Font font = new Font("Verdana", Font.PLAIN, 11);
90 JLabel l1 = new JLabel(getImage("test2.png"));
91 l1.setText("trailing right");
92 l1.setHorizontalTextPosition(SwingConstants.TRAILING);
93 l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
94 l1.setHorizontalAlignment(SwingConstants.RIGHT);
96 JLabel l2 = new JLabel(getImage("test2.png"));
97 l2.setText("leading left");
99 l2.setHorizontalTextPosition(SwingConstants.LEADING);
100 l2.setHorizontalAlignment(SwingConstants.LEFT);
102 JButton b1 = new JButton("right left");
103 b1.setIcon(getImage("test2.png"));
105 b1.setHorizontalTextPosition(SwingConstants.RIGHT);
106 b1.setHorizontalAlignment(SwingConstants.LEFT);
113 JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
115 cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
116 cb3.setHorizontalTextPosition(SwingConstants.LEADING);
117 cb3.setHorizontalAlignment(SwingConstants.TRAILING);
119 JCheckBox cb4 = new JCheckBox("leading,right-to-left");
121 cb4.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
122 cb4.setHorizontalTextPosition(SwingConstants.LEADING);
124 JCheckBox cb5 = new JCheckBox("trailing,left-to-right");
126 cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
127 cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
129 JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
131 rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
132 rb1.setHorizontalTextPosition(SwingConstants.TRAILING);
134 JRadioButton rb2 = new JRadioButton("right,left-to-right");
136 rb2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
137 rb2.setHorizontalTextPosition(SwingConstants.RIGHT);
139 JRadioButton rb3 = new JRadioButton("right,right-to-left");
141 rb3.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
142 rb3.setHorizontalTextPosition(SwingConstants.RIGHT);
146 firstColumn.add(cb3);
147 firstColumn.add(cb4);
148 firstColumn.add(cb5);
149 firstColumn.add(rb1);
150 firstColumn.add(rb2);
151 firstColumn.add(rb3);
152 firstColumn.setBounds(200, 20, 200, 500);
154 JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
156 cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
157 cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
159 JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
161 cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
162 cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
164 JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
166 cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
167 cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
169 JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
171 cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
172 cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
174 JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
176 rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
177 rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
179 JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
181 rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
182 rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
184 JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
186 rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
187 rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
189 JMenu m1 = new JMenu("left");
190 JMenu m2 = new JMenu("right");
201 JPanel theTab = new JPanel();
203 theTab.setLayout(null);
204 theTab.add(firstColumn);
210 private ImageIcon getImage(String name) {
211 ImageIcon icon = new ImageIcon(getClass().getResource(name));
213 while(icon.getImageLoadStatus() == MediaTracker.LOADING)
216 } catch (InterruptedException e) {