JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / jbgui / GStructureChooser.java
index a30be66..4261d67 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -40,6 +40,7 @@ import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.KeyAdapter;
@@ -65,6 +66,7 @@ import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.ListCellRenderer;
+import javax.swing.Timer;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
@@ -104,13 +106,13 @@ public abstract class GStructureChooser extends JPanel
   protected String frameTitle = MessageManager
           .getString("label.structure_chooser");
 
-  protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
+  public JInternalFrame mainFrame = new JInternalFrame(frameTitle);
 
-  protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<>();
+  public JComboBox<FilterOption> cmb_filterOption = new JComboBox<>();
 
-  protected AlignmentPanel ap;
+  public AlignmentPanel ap;
 
-  protected StringBuilder errorWarning = new StringBuilder();
+  public StringBuilder errorWarning = new StringBuilder();
 
   protected JButton btn_add;
 
@@ -121,14 +123,14 @@ public abstract class GStructureChooser extends JPanel
   protected JCheckBox chk_superpose = new JCheckBox(
           MessageManager.getString("label.superpose_structures"));
 
-  protected JTextField txt_search = new JTextField(14);
+  public JTextField txt_search = new JTextField(14);
 
   protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
 
   protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
           .getLayout());
 
-  protected JCheckBox chk_invertFilter = new JCheckBox(
+  public JCheckBox chk_invertFilter = new JCheckBox(
           MessageManager.getString("label.invert"));
 
   protected ImageIcon loadingImage = new ImageIcon(
@@ -143,29 +145,29 @@ public abstract class GStructureChooser extends JPanel
   protected ImageIcon warningImage = new ImageIcon(
           getClass().getResource("/images/warning.gif"));
 
-  protected JLabel lbl_loading = new JLabel(loadingImage);
+  public JLabel lbl_loading = new JLabel(loadingImage);
 
   protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
 
   protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
 
-  protected AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel();
+  public AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel();
 
-  protected AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel();
+  public AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel();
 
   protected JComboBox<StructureViewer> targetView = new JComboBox<>();
 
-  protected JTable tbl_local_pdb = new JTable();
+  public JTable tbl_local_pdb = new JTable();
 
   protected JTabbedPane pnl_filter = new JTabbedPane();
 
-  protected FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
+  public FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
           PreferenceSource.STRUCTURE_CHOOSER,
           PDBFTSRestClient.getInstance());
 
   protected FTSDataColumnI[] previousWantedFields;
 
-  protected static Map<String, Integer> tempUserPrefs = new HashMap<>();
+  public static Map<String, Integer> tempUserPrefs = new HashMap<>();
 
   private JTable tbl_summary = new JTable()
   {
@@ -255,10 +257,33 @@ public abstract class GStructureChooser extends JPanel
       mainFrame.pack();
     } catch (Exception e)
     {
+      System.out.println(e); // for JavaScript TypeError
       e.printStackTrace();
     }
   }
 
+  // BH SwingJS optimization
+  // (a) 100-ms interruptable timer for text entry -- BH 1/10/2019
+  // (b) two-character minimum, at least for JavaScript.
+  
+  private Timer timer; 
+  
+  protected void txt_search_ActionPerformedDelayed() {
+         if (timer != null) {
+                 timer.stop();
+         }
+         timer = new Timer(300, new ActionListener() {
+
+               @Override
+               public void actionPerformed(ActionEvent e) {
+                       txt_search_ActionPerformed();
+               }                 
+         });
+         timer.setRepeats(false);
+         timer.start();
+  }
+  //
+  
   /**
    * Initializes the GUI default properties
    * 
@@ -485,19 +510,19 @@ public abstract class GStructureChooser extends JPanel
       @Override
       public void insertUpdate(DocumentEvent e)
       {
-        txt_search_ActionPerformed();
+        txt_search_ActionPerformedDelayed();
       }
 
       @Override
       public void removeUpdate(DocumentEvent e)
       {
-        txt_search_ActionPerformed();
+        txt_search_ActionPerformedDelayed();
       }
 
       @Override
       public void changedUpdate(DocumentEvent e)
       {
-        txt_search_ActionPerformed();
+        txt_search_ActionPerformedDelayed();
       }
     });
 
@@ -636,7 +661,8 @@ public abstract class GStructureChooser extends JPanel
     Desktop.addInternalFrame(mainFrame, frameTitle, width, height);
   }
 
-  protected void closeAction(int preferredHeight)
+
+  public void closeAction(int preferredHeight)
   {
     // System.out.println(">>>>>>>>>> closing internal frame!!!");
     // System.out.println("width : " + mainFrame.getWidth());