JAL-4026 update the viewport’s wrapped width after calculating it
[jalview.git] / utils / test / JalviewJSTest.java
index d8fb401..3e08024 100644 (file)
@@ -1,4 +1,7 @@
 package test;
+import jalview.gui.JvOptionPane;
+import jalview.util.JSONUtils;
+
 import java.awt.BorderLayout;
 import java.awt.ComponentOrientation;
 import java.awt.Container;
@@ -6,7 +9,11 @@ import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.GridLayout;
 import java.awt.MediaTracker;
-import java.awt.MenuItem;
+import java.io.File;
+import java.text.DecimalFormat;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
 
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -23,6 +30,8 @@ import javax.swing.SwingConstants;
 import javax.swing.WindowConstants;
 import javax.swing.border.TitledBorder;
 
+import org.json.simple.parser.ParseException;
+
 /**
  * A class with a main method entry point for ad hoc tests of JalviewJS
  * behaviour. The J2S transpiler should generate an html entry point for this
@@ -32,14 +41,95 @@ public class JalviewJSTest extends JPanel
 {
   public static void main(String[] args)
   {
-    new JalviewJSTest().doTest();
+    new JalviewJSTest().doTest6();
+  }
+  
+  void doTest6()
+  {
+    /*
+     * check for transpiler fix associated with JSONParser yylex.java use of charAt()
+     * instead of codePointAt(); moved here from PDBFTSRestClient
+     */
+
+    String s = "e";
+    char c = 'c';
+    char f = 'f';
+    s += c | f;
+    int x = c & f;
+    int y = 2 & c;
+    int z = c ^ 5;
+    String result = s + x + y + z;
+    System.out.println("Expected " + "e103982102, found " + result);
+    try
+    {
+      Map<String, Object> jsonObj = (Map<String, Object>) JSONUtils
+              .parse("{\"a\":3}");
+      System.out.println(jsonObj);
+    } catch (ParseException e)
+    {
+      e.printStackTrace();
+    }
   }
 
   /**
+   * Dialog message truncation
+   */
+  void doTest5()
+  {
+    JFrame main = new JFrame();
+    main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+    main.setContentPane(new JPanel());
+    main.setMinimumSize(new Dimension(100,  100));
+    main.pack();
+    main.setVisible(true);
+    
+    /*
+     * like AlignFrame.delete_actionPerformed()
+     * except here it works fine, also in JS
+     */
+    JvOptionPane dialog = JvOptionPane.newOptionDialog(null);
+    Object[] options = new Object[] { "OK", "Cancel" };
+       String msg = "<html>Deleting all sequences will close the alignment window.<br>Confirm deletion or Cancel.";
+       dialog.showDialog(msg, "", JvOptionPane.DEFAULT_OPTION, JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
+
+  }
+
+  void doTest4() 
+  {
+         Float fl = new Float(0f);
+         System.out.println(fl.isInfinite());
+         System.out.println(fl.isNaN());
+
+         System.out.println(Float.isInfinite(0f));
+         System.out.println(Float.isFinite(0f));
+         System.out.println(Float.isNaN(0f));
+  }
+
+  void doTest3() 
+  {
+           System.out.println("Mungo".toLowerCase(Locale.getDefault()));
+           System.out.println("Mungo".toLowerCase(Locale.ENGLISH));
+    System.out.println("Mungo".toLowerCase(Locale.ROOT));
+  }
+  
+  void doTest2() {
+         Map<File, String> map = new HashMap<>();
+         File f1 = new File("/var/folders/y/xyz");
+         File f2 = new File("/var/folders/y/xyz");
+         map.put(f1,  "hello world");
+         System.out.println("f1.equals(f2) = " + f1.equals(f2));
+         System.out.println("f1 hashCode = " + f1.hashCode());
+         System.out.println("f2 hashCode = " + f2.hashCode());
+         System.out.println(map.get(f2));
+  }
+  
+  /**
    * Put some content in a JFrame and show it
    */
-  void doTest()
+  void doTest1()
   {
+         System.out.println("ab;c;".split(";"));
+    new DecimalFormat("###,###").format((Integer) 1);
     JFrame main = new JFrame();
     main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     JMenu menu = new JMenu("testing");
@@ -197,10 +287,12 @@ private ImageIcon getImage(String name) {
     ImageIcon icon = new ImageIcon(getClass().getResource(name));
 
     while(icon.getImageLoadStatus() == MediaTracker.LOADING)
-               try {
-                       Thread.sleep(10);
-               } catch (InterruptedException e) {
-               }
+    {
+      try {
+       Thread.sleep(10);
+      } catch (InterruptedException e) {
+      }
+    }
     return icon;
 }
 }