JAL-3032 JAL-3084 test class for JS layout bug(s)
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 21 Aug 2018 11:16:50 +0000 (12:16 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 21 Aug 2018 11:16:50 +0000 (12:16 +0100)
utils/JalviewJSTest.java [new file with mode: 0644]

diff --git a/utils/JalviewJSTest.java b/utils/JalviewJSTest.java
new file mode 100644 (file)
index 0000000..3b6ca2e
--- /dev/null
@@ -0,0 +1,84 @@
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.GridLayout;
+
+import javax.swing.JCheckBox;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.border.TitledBorder;
+
+/**
+ * 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
+ * class, allowing comparison between Java and Javascript execution.
+ */
+public class JalviewJSTest extends JPanel
+{
+  public static void main(String[] args)
+  {
+    new JalviewJSTest().doTest();
+  }
+
+  /**
+   * Put some content in a JFrame and show it
+   */
+  void doTest()
+  {
+    JFrame main = new JFrame();
+    main.setContentPane(getVisualPaneContent());
+    main.pack();
+    main.setVisible(true);
+  }
+
+  /**
+   * Builds a cut-down 'Preferences Visual tab' for a minimal test of layout
+   * problems
+   */
+  Container getVisualPaneContent()
+  {
+    JPanel panel = new JPanel();
+    panel.setPreferredSize(new Dimension(400, 300));
+    panel.setOpaque(true);
+    panel.setLayout(new BorderLayout());
+
+    JPanel firstColumn = new JPanel();
+    firstColumn.setLayout(new GridLayout(6, 1));
+    firstColumn.setBorder(new TitledBorder("column 1"));
+
+    /*
+     * 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.RIGHT);
+
+    /*
+     * 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);
+
+    firstColumn.add(cb1);
+    firstColumn.add(cb2);
+    firstColumn.setBounds(20, 20, 200, 200);
+
+    JPanel theTab = new JPanel();
+    theTab.setLayout(null);
+    theTab.add(firstColumn);
+    panel.add(theTab);
+
+    return panel;
+  }
+}