JAL-3026 Jmol functioning; some issues
[jalview.git] / utils / test / JalviewJSTest.java
index 95737d4..d8fb401 100644 (file)
@@ -5,12 +5,22 @@ import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.GridLayout;
+import java.awt.MediaTracker;
+import java.awt.MenuItem;
 
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
+import javax.swing.JRadioButtonMenuItem;
 import javax.swing.SwingConstants;
+import javax.swing.WindowConstants;
 import javax.swing.border.TitledBorder;
 
 /**
@@ -18,7 +28,6 @@ import javax.swing.border.TitledBorder;
  * behaviour. The J2S transpiler should generate an html entry point for this
  * class, allowing comparison between Java and Javascript execution.
  */
-@SuppressWarnings("serial")
 public class JalviewJSTest extends JPanel
 {
   public static void main(String[] args)
@@ -32,7 +41,12 @@ public class JalviewJSTest extends JPanel
   void doTest()
   {
     JFrame main = new JFrame();
-    main.setContentPane(getVisualPaneContent());
+    main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+    JMenu menu = new JMenu("testing");
+    menu.setHorizontalAlignment(SwingConstants.RIGHT);
+    main.setContentPane(getVisualPaneContent(menu));
+    main.setJMenuBar(new JMenuBar());
+    main.getJMenuBar().add(menu);
     main.pack();
     main.setVisible(true);
   }
@@ -40,8 +54,9 @@ public class JalviewJSTest extends JPanel
   /**
    * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
    * problems
+ * @param menu 
    */
-  Container getVisualPaneContent()
+  Container getVisualPaneContent(JMenu menu)
   {
     JPanel panel = new JPanel();
     panel.setPreferredSize(new Dimension(400, 500));
@@ -56,33 +71,36 @@ public class JalviewJSTest extends JPanel
      * bug 21/08/18:
      * - checkbox label and text extend outside the enclosing panel in JS
      */
-    JCheckBox cb1 = new JCheckBox();
     Font font = new Font("Verdana", Font.PLAIN, 11);
-    cb1.setFont(font);
-    cb1.setText("Maximise Window");
-    cb1.setHorizontalTextPosition(SwingConstants.LEADING);
-    cb1.setHorizontalAlignment(SwingConstants.LEFT);
 
-    /*
-     * bug 21/08/18:
-     * - label should precede checkbox, but it doesn't
-     */
-    JCheckBox cb2 = new JCheckBox("Open Overview");
-    cb2.setFont(font);
-    cb2.setHorizontalTextPosition(SwingConstants.LEADING);
-    // uncommenting this line gives 'leading text', but
-    // also results in label and checkbox outside container
-    //cb2.setHorizontalAlignment(SwingConstants.RIGHT);
+    JLabel l1 = new JLabel(getImage("test2.png"));
+    l1.setText("trailing right");
+    l1.setHorizontalTextPosition(SwingConstants.TRAILING);
+    l1.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    l1.setHorizontalAlignment(SwingConstants.RIGHT);
+
+    JLabel l2 = new JLabel(getImage("test2.png"));
+    l2.setText("leading left");
+    l2.setFont(font);
+    l2.setHorizontalTextPosition(SwingConstants.LEADING);
+    l2.setHorizontalAlignment(SwingConstants.LEFT);
+
+    JButton b1 = new JButton("right left");
+    b1.setIcon(getImage("test2.png"));
+    b1.setFont(font);
+    b1.setHorizontalTextPosition(SwingConstants.RIGHT);
+    b1.setHorizontalAlignment(SwingConstants.LEFT);
+
+    firstColumn.add(l1);
+    firstColumn.add(l2);
+    firstColumn.add(b1);
 
     
-//    ImageIcon icon =  new ImageIcon(getClass()
-//            .getClassLoader()
-//            .getResource("test2.png"), "test");
-//    
-    JCheckBox cb3 = new JCheckBox("leading,left-to-right");
+    JCheckBox cb3 = new JCheckBox("leading,left-to-right,rt");
     cb3.setFont(font);
     cb3.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
     cb3.setHorizontalTextPosition(SwingConstants.LEADING);
+    cb3.setHorizontalAlignment(SwingConstants.TRAILING);
 
     JCheckBox cb4 = new JCheckBox("leading,right-to-left");
     cb4.setFont(font);
@@ -94,11 +112,6 @@ public class JalviewJSTest extends JPanel
     cb5.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
     cb5.setHorizontalTextPosition(SwingConstants.TRAILING);
 
-    JCheckBox cb6 = new JCheckBox("trailing,right-to-left");
-    cb6.setFont(font);
-    cb6.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
-    cb6.setHorizontalTextPosition(SwingConstants.TRAILING);
-
     JRadioButton rb1 = new JRadioButton("trailing,right-to-left");
     rb1.setFont(font);
     rb1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
@@ -116,22 +129,78 @@ public class JalviewJSTest extends JPanel
 
 
     
-    firstColumn.add(cb1);
-    firstColumn.add(cb2);
     firstColumn.add(cb3);
     firstColumn.add(cb4);
     firstColumn.add(cb5);
-    firstColumn.add(cb6);
     firstColumn.add(rb1);
     firstColumn.add(rb2);
     firstColumn.add(rb3);
-    firstColumn.setBounds(20, 20, 200, 500);
-
+    firstColumn.setBounds(200, 20, 200, 500);
+
+    JCheckBoxMenuItem cb3m = new JCheckBoxMenuItem("leading,left-to-right");
+    cb3m.setFont(font);
+    cb3m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    cb3m.setHorizontalTextPosition(SwingConstants.LEADING);
+
+    JCheckBoxMenuItem cb4m = new JCheckBoxMenuItem("leading,right-to-left");
+    cb4m.setFont(font);
+    cb4m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    cb4m.setHorizontalTextPosition(SwingConstants.LEADING);
+
+    JCheckBoxMenuItem cb5m = new JCheckBoxMenuItem("trailing,left-to-right");
+    cb5m.setFont(font);
+    cb5m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    cb5m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JCheckBoxMenuItem cb6m = new JCheckBoxMenuItem("trailing,right-to-left");
+    cb6m.setFont(font);
+    cb6m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    cb6m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JRadioButtonMenuItem rb1m = new JRadioButtonMenuItem("trailing,right-to-left");
+    rb1m.setFont(font);
+    rb1m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    rb1m.setHorizontalTextPosition(SwingConstants.TRAILING);
+
+    JRadioButtonMenuItem rb2m = new JRadioButtonMenuItem("right,left-to-right");
+    rb2m.setFont(font);
+    rb2m.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
+    rb2m.setHorizontalTextPosition(SwingConstants.RIGHT);
+
+    JRadioButtonMenuItem rb3m = new JRadioButtonMenuItem("right,right-to-left");
+    rb3m.setFont(font);
+    rb3m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+    rb3m.setHorizontalTextPosition(SwingConstants.RIGHT);
+
+    JMenu m1 = new JMenu("left");
+    JMenu m2 = new JMenu("right");
+    menu.add(m1);
+    menu.add(m2);
+    m1.add(cb3m);
+    m2.add(cb4m);
+    m1.add(cb5m);
+    m2.add(cb6m);
+    m2.add(rb1m);
+    m1.add(rb2m);
+    m2.add(rb3m);
+    
     JPanel theTab = new JPanel();
+    
     theTab.setLayout(null);
     theTab.add(firstColumn);
     panel.add(theTab);
 
     return panel;
   }
+
+private ImageIcon getImage(String name) {
+    ImageIcon icon = new ImageIcon(getClass().getResource(name));
+
+    while(icon.getImageLoadStatus() == MediaTracker.LOADING)
+               try {
+                       Thread.sleep(10);
+               } catch (InterruptedException e) {
+               }
+    return icon;
+}
 }