2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import jalview.gui.JvOptionPane;
23 import jalview.util.JSONUtils;
25 import java.awt.BorderLayout;
26 import java.awt.ComponentOrientation;
27 import java.awt.Container;
28 import java.awt.Dimension;
30 import java.awt.GridLayout;
31 import java.awt.MediaTracker;
33 import java.text.DecimalFormat;
34 import java.util.HashMap;
35 import java.util.Locale;
38 import javax.swing.ImageIcon;
39 import javax.swing.JButton;
40 import javax.swing.JCheckBox;
41 import javax.swing.JCheckBoxMenuItem;
42 import javax.swing.JFrame;
43 import javax.swing.JLabel;
44 import javax.swing.JMenu;
45 import javax.swing.JMenuBar;
46 import javax.swing.JPanel;
47 import javax.swing.JRadioButton;
48 import javax.swing.JRadioButtonMenuItem;
49 import javax.swing.SwingConstants;
50 import javax.swing.WindowConstants;
51 import javax.swing.border.TitledBorder;
53 import org.json.simple.parser.ParseException;
56 * A class with a main method entry point for ad hoc tests of JalviewJS
57 * behaviour. The J2S transpiler should generate an html entry point for this
58 * class, allowing comparison between Java and Javascript execution.
60 public class JalviewJSTest extends JPanel
62 public static void main(String[] args)
64 new JalviewJSTest().doTest6();
70 * check for transpiler fix associated with JSONParser yylex.java use of charAt()
71 * instead of codePointAt(); moved here from PDBFTSRestClient
81 String result = s + x + y + z;
82 System.out.println("Expected " + "e103982102, found " + result);
85 Map<String, Object> jsonObj = (Map<String, Object>) JSONUtils
87 System.out.println(jsonObj);
88 } catch (ParseException e)
95 * Dialog message truncation
99 JFrame main = new JFrame();
100 main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
101 main.setContentPane(new JPanel());
102 main.setMinimumSize(new Dimension(100, 100));
104 main.setVisible(true);
107 * like AlignFrame.delete_actionPerformed()
108 * except here it works fine, also in JS
110 JvOptionPane dialog = JvOptionPane.newOptionDialog(null);
111 Object[] options = new Object[] { "OK", "Cancel" };
112 String msg = "<html>Deleting all sequences will close the alignment window.<br>Confirm deletion or Cancel.";
113 dialog.showDialog(msg, "", JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
119 Float fl = new Float(0f);
120 System.out.println(fl.isInfinite());
121 System.out.println(fl.isNaN());
123 System.out.println(Float.isInfinite(0f));
124 System.out.println(Float.isFinite(0f));
125 System.out.println(Float.isNaN(0f));
130 System.out.println("Mungo".toLowerCase(Locale.getDefault()));
131 System.out.println("Mungo".toLowerCase(Locale.ENGLISH));
132 System.out.println("Mungo".toLowerCase(Locale.ROOT));
136 Map<File, String> map = new HashMap<>();
137 File f1 = new File("/var/folders/y/xyz");
138 File f2 = new File("/var/folders/y/xyz");
139 map.put(f1, "hello world");
140 System.out.println("f1.equals(f2) = " + f1.equals(f2));
141 System.out.println("f1 hashCode = " + f1.hashCode());
142 System.out.println("f2 hashCode = " + f2.hashCode());
143 System.out.println(map.get(f2));
147 * Put some content in a JFrame and show it
151 System.out.println("ab;c;".split(";"));
152 new DecimalFormat("###,###").format((Integer) 1);
153 JFrame main = new JFrame();
154 main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
155 JMenu menu = new JMenu("testing");
156 menu.setHorizontalAlignment(SwingConstants.RIGHT);
157 main.setContentPane(getVisualPaneContent(menu));
158 main.setJMenuBar(new JMenuBar());
159 main.getJMenuBar().add(menu);
161 main.setVisible(true);
165 * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
169 Container getVisualPaneContent(JMenu menu)
171 JPanel panel = new JPanel();
172 panel.setPreferredSize(new Dimension(400, 500));
173 panel.setOpaque(true);
174 panel.setLayout(new BorderLayout());
176 JPanel firstColumn = new JPanel();
177 firstColumn.setLayout(new GridLayout(10, 1));
178 firstColumn.setBorder(new TitledBorder("column 1"));
182 * - checkbox label and text extend outside the enclosing panel in JS
184 Font font = new Font("Verdana", Font.PLAIN, 11);
186 JLabel l1 = new JLabel(getImage("test2.png"));
187 l1.setText("trailing right");
188 l1.setHorizontalTextPosition(SwingConstants.TRAILING);
189 l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
190 l1.setHorizontalAlignment(SwingConstants.RIGHT);
192 JLabel l2 = new JLabel(getImage("test2.png"));
193 l2.setText("leading left");
195 l2.setHorizontalTextPosition(SwingConstants.LEADING);
196 l2.setHorizontalAlignment(SwingConstants.LEFT);
198 JButton b1 = new JButton("right left");
199 b1.setIcon(getImage("test2.png"));
201 b1.setHorizontalTextPosition(SwingConstants.RIGHT);
202 b1.setHorizontalAlignment(SwingConstants.LEFT);
209 JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
211 cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
212 cb3.setHorizontalTextPosition(SwingConstants.LEADING);
213 cb3.setHorizontalAlignment(SwingConstants.TRAILING);
215 JCheckBox cb4 = new JCheckBox("leading,right-to-left");
217 cb4.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
218 cb4.setHorizontalTextPosition(SwingConstants.LEADING);
220 JCheckBox cb5 = new JCheckBox("trailing,left-to-right");
222 cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
223 cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
225 JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
227 rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
228 rb1.setHorizontalTextPosition(SwingConstants.TRAILING);
230 JRadioButton rb2 = new JRadioButton("right,left-to-right");
232 rb2.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
233 rb2.setHorizontalTextPosition(SwingConstants.RIGHT);
235 JRadioButton rb3 = new JRadioButton("right,right-to-left");
237 rb3.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
238 rb3.setHorizontalTextPosition(SwingConstants.RIGHT);
242 firstColumn.add(cb3);
243 firstColumn.add(cb4);
244 firstColumn.add(cb5);
245 firstColumn.add(rb1);
246 firstColumn.add(rb2);
247 firstColumn.add(rb3);
248 firstColumn.setBounds(200, 20, 200, 500);
250 JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
252 cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
253 cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
255 JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
257 cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
258 cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
260 JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
262 cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
263 cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
265 JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
267 cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
268 cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
270 JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
272 rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
273 rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
275 JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
277 rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
278 rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
280 JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
282 rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
283 rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
285 JMenu m1 = new JMenu("left");
286 JMenu m2 = new JMenu("right");
297 JPanel theTab = new JPanel();
299 theTab.setLayout(null);
300 theTab.add(firstColumn);
306 private ImageIcon getImage(String name) {
307 ImageIcon icon = new ImageIcon(getClass().getResource(name));
309 while(icon.getImageLoadStatus() == MediaTracker.LOADING)
313 } catch (InterruptedException e) {