JAL-4034 Fix #2 show an icon and a button to press to initiate search
[jalview.git] / src / jalview / jbgui / GStructureChooser.java
index d43495e..d8101e3 100644 (file)
 
 package jalview.jbgui;
 
-import jalview.datamodel.SequenceI;
-import jalview.fts.api.FTSDataColumnI;
-import jalview.fts.core.FTSDataColumnPreferences;
-import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
-import jalview.fts.service.pdb.PDBFTSRestClient;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.Desktop;
-import jalview.gui.JvSwingUtils;
-import jalview.gui.StructureViewer;
-import jalview.util.MessageManager;
-
 import java.awt.BorderLayout;
 import java.awt.CardLayout;
 import java.awt.Component;
@@ -39,6 +28,7 @@ import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.GridLayout;
+import java.awt.Point;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
@@ -74,6 +64,14 @@ import javax.swing.event.DocumentListener;
 import javax.swing.event.InternalFrameEvent;
 import javax.swing.table.TableColumn;
 
+import jalview.datamodel.SequenceI;
+import jalview.fts.api.FTSDataColumnI;
+import jalview.fts.core.FTSDataColumnPreferences;
+import jalview.gui.AlignmentPanel;
+import jalview.gui.Desktop;
+import jalview.gui.JvSwingUtils;
+import jalview.gui.StructureViewer;
+import jalview.util.MessageManager;
 import net.miginfocom.swing.MigLayout;
 
 @SuppressWarnings("serial")
@@ -88,7 +86,7 @@ public abstract class GStructureChooser extends JPanel
 {
   private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
 
-  protected static final String VIEWS_FILTER = "VIEWS_FILTER";
+  public static final String VIEWS_FILTER = "VIEWS_FILTER";
 
   protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
 
@@ -120,6 +118,11 @@ public abstract class GStructureChooser extends JPanel
 
   protected JButton btn_pdbFromFile = new JButton();
 
+  // holder for icon and button
+  protected JPanel pnl_queryTDB;
+
+  protected JButton btn_queryTDB = new JButton();
+
   protected JCheckBox chk_superpose = new JCheckBox(
           MessageManager.getString("label.superpose_structures"));
 
@@ -145,6 +148,9 @@ public abstract class GStructureChooser extends JPanel
   protected ImageIcon warningImage = new ImageIcon(
           getClass().getResource("/images/warning.gif"));
 
+  protected ImageIcon tdbImage = new ImageIcon(getClass()
+          .getResource("/images/3d-beacons-logo-transparent.png"));
+
   protected JLabel lbl_loading = new JLabel(loadingImage);
 
   protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
@@ -162,8 +168,9 @@ public abstract class GStructureChooser extends JPanel
   protected JTabbedPane pnl_filter = new JTabbedPane();
 
   protected abstract FTSDataColumnPreferences getFTSDocFieldPrefs();
-  protected abstract void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs);
 
+  protected abstract void setFTSDocFieldPrefs(
+          FTSDataColumnPreferences newPrefs);
 
   protected FTSDataColumnI[] previousWantedFields;
 
@@ -250,6 +257,7 @@ public abstract class GStructureChooser extends JPanel
   public GStructureChooser()
   {
   }
+
   protected void initDialog()
   {
 
@@ -265,29 +273,33 @@ public abstract class GStructureChooser extends JPanel
       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();
+
+  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
    * 
@@ -306,15 +318,44 @@ public abstract class GStructureChooser extends JPanel
     tbl_summary.addMouseListener(new MouseAdapter()
     {
       @Override
+      public void mousePressed(MouseEvent e)
+      {
+        if (!popupAction(e))
+        {
+          super.mousePressed(e);
+        }
+      }
+
+      @Override
       public void mouseClicked(MouseEvent e)
       {
-        validateSelections();
+        if (!popupAction(e))
+        {
+          validateSelections();
+        }
       }
 
       @Override
       public void mouseReleased(MouseEvent e)
       {
-        validateSelections();
+        if (!popupAction(e))
+        {
+          validateSelections();
+        }
+      }
+
+      boolean popupAction(MouseEvent e)
+      {
+        if (e.isPopupTrigger())
+        {
+          Point pt = e.getPoint();
+          int selectedRow = tbl_summary.rowAtPoint(pt);
+          if (showPopupFor(selectedRow, pt.x, pt.y))
+          {
+            return true;
+          }
+        }
+        return false;
       }
     });
     tbl_summary.addKeyListener(new KeyAdapter()
@@ -431,7 +472,9 @@ public abstract class GStructureChooser extends JPanel
       }
     });
 
-    btn_newView = new JButton(MessageManager.getString("action.new_view"));
+    btn_newView = new JButton(
+            MessageManager.formatMessage("action.new_structure_view_with",
+                    StructureViewer.getViewerType().toString()));
     btn_newView.setFont(VERDANA_12);
     btn_newView.addActionListener(new java.awt.event.ActionListener()
     {
@@ -453,6 +496,9 @@ public abstract class GStructureChooser extends JPanel
       }
     });
 
+    // TODO: JAL-3898 - get list of available external programs to view
+    // structures with
+
     btn_add = new JButton(MessageManager.getString("action.add"));
     btn_add.setFont(VERDANA_12);
     btn_add.addActionListener(new java.awt.event.ActionListener()
@@ -547,6 +593,13 @@ public abstract class GStructureChooser extends JPanel
     });
 
     chk_invertFilter.addItemListener(this);
+    btn_queryTDB = new JButton(
+            MessageManager.getString("label.search_3dbeacons"));
+    btn_queryTDB.setFont(VERDANA_12);
+    btn_queryTDB.setToolTipText(
+            MessageManager.getString("label.find_models_from_3dbeacons"));
+    btn_queryTDB.setPreferredSize(new Dimension(300, 24));
+    btn_queryTDB.setVisible(false);
 
     targetView.setVisible(false);
 
@@ -557,10 +610,18 @@ public abstract class GStructureChooser extends JPanel
     actionsPanel.add(btn_newView);
     actionsPanel.add(btn_cancel, "right");
 
-    JPanel pnl_main = new JPanel();
-    pnl_main.add(cmb_filterOption);
-    pnl_main.add(lbl_loading);
-    pnl_main.add(chk_invertFilter);
+    JPanel pnl_main = new JPanel(new BorderLayout());
+    JPanel pnl_controls = new JPanel();
+    pnl_queryTDB = new JPanel(new FlowLayout());
+    pnl_queryTDB.setBackground(getBackground());
+    pnl_queryTDB.add(new JLabel(tdbImage));
+    pnl_queryTDB.add(btn_queryTDB);
+    pnl_queryTDB.setVisible(false);
+    pnl_main.add(pnl_queryTDB, BorderLayout.NORTH);
+    pnl_controls.add(cmb_filterOption);
+    pnl_controls.add(lbl_loading);
+    pnl_controls.add(chk_invertFilter);
+    pnl_main.add(pnl_controls, BorderLayout.CENTER);
     lbl_loading.setVisible(false);
 
     JPanel pnl_fileChooser = new JPanel(new FlowLayout());
@@ -665,8 +726,9 @@ public abstract class GStructureChooser extends JPanel
     Desktop.addInternalFrame(mainFrame, frameTitle, width, height);
   }
 
+  protected abstract boolean showPopupFor(int selectedRow, int x, int y);
 
-protected void closeAction(int preferredHeight)
+  protected void closeAction(int preferredHeight)
   {
     // System.out.println(">>>>>>>>>> closing internal frame!!!");
     // System.out.println("width : " + mainFrame.getWidth());
@@ -704,91 +766,6 @@ protected void closeAction(int preferredHeight)
   }
 
   /**
-   * This inner class provides the data model for the structure filter combo-box
-   * 
-   * @author tcnofoegbu
-   *
-   */
-  public class FilterOption
-  {
-    private String name;
-
-    private String value;
-
-    private String view;
-
-    private boolean addSeparatorAfter;
-
-    /**
-     * Model for structure filter option
-     * 
-     * @param name
-     *          - the name of the Option
-     * @param value
-     *          - the value of the option
-     * @param view
-     *          - the category of the filter option
-     * @param addSeparatorAfter
-     *          - if true, a horizontal separator is rendered immediately after
-     *          this filter option, otherwise
-     */
-    public FilterOption(String name, String value, String view,
-            boolean addSeparatorAfter)
-    {
-      this.name = name;
-      this.value = value;
-      this.view = view;
-      this.addSeparatorAfter = addSeparatorAfter;
-    }
-
-    public String getName()
-    {
-      return name;
-    }
-
-    public void setName(String name)
-    {
-      this.name = name;
-    }
-
-    public String getValue()
-    {
-      return value;
-    }
-
-    public void setValue(String value)
-    {
-      this.value = value;
-    }
-
-    public String getView()
-    {
-      return view;
-    }
-
-    public void setView(String view)
-    {
-      this.view = view;
-    }
-
-    @Override
-    public String toString()
-    {
-      return this.name;
-    }
-
-    public boolean isAddSeparatorAfter()
-    {
-      return addSeparatorAfter;
-    }
-
-    public void setAddSeparatorAfter(boolean addSeparatorAfter)
-    {
-      this.addSeparatorAfter = addSeparatorAfter;
-    }
-  }
-
-  /**
    * This inner class provides the provides the data model for associate
    * sequence combo-box - cmb_assSeq
    *