From fc895e8dacdbb7f49df0ec5c9f475b841082e9b3 Mon Sep 17 00:00:00 2001 From: hansonr Date: Thu, 10 Jan 2019 22:48:06 -0600 Subject: [PATCH] JS optimization for too aggressive dynamic operation when entering PDB IDs (proposal only) --- src/jalview/gui/StructureChooser.java | 29 +++++++++++++++--------- src/jalview/jbgui/GStructureChooser.java | 36 ++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 97ff404..d4d077f 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -83,7 +83,7 @@ public class StructureChooser extends GStructureChooser private FTSRestRequest lastPdbRequest; - private FTSRestClientI pdbRestCleint; + private FTSRestClientI pdbRestClient; private String selectedPdbFileName; @@ -217,7 +217,7 @@ public class StructureChooser extends GStructureChooser void fetchStructuresMetaData() { long startTime = System.currentTimeMillis(); - pdbRestCleint = PDBFTSRestClient.getInstance(); + pdbRestClient = PDBFTSRestClient.getInstance(); Collection wantedFields = pdbDocFieldPrefs .getStructureSummaryFields(); @@ -239,7 +239,7 @@ public class StructureChooser extends GStructureChooser FTSRestResponse resultList; try { - resultList = pdbRestCleint.executeRequest(pdbRequest); + resultList = pdbRestClient.executeRequest(pdbRequest); } catch (Exception e) { e.printStackTrace(); @@ -461,7 +461,7 @@ public class StructureChooser extends GStructureChooser public void run() { long startTime = System.currentTimeMillis(); - pdbRestCleint = PDBFTSRestClient.getInstance(); + pdbRestClient = PDBFTSRestClient.getInstance(); lbl_loading.setVisible(true); Collection wantedFields = pdbDocFieldPrefs .getStructureSummaryFields(); @@ -497,7 +497,7 @@ public class StructureChooser extends GStructureChooser FTSRestResponse resultList; try { - resultList = pdbRestCleint.executeRequest(pdbRequest); + resultList = pdbRestClient.executeRequest(pdbRequest); } catch (Exception e) { e.printStackTrace(); @@ -1192,19 +1192,26 @@ public class StructureChooser extends GStructureChooser && !discoveredStructuresSet.isEmpty(); } + protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes this. + // Doing a search for "1" or "1c" is valuable? + // Those work but are enormously slow. + @Override protected void txt_search_ActionPerformed() { + String text = txt_search.getText().trim(); + if (text.length() >= PDB_ID_MIN) new Thread() { - @Override + + @Override public void run() { errorWarning.setLength(0); isValidPBDEntry = false; - if (txt_search.getText().length() > 0) + if (text.length() > 0) { - String searchTerm = txt_search.getText().toLowerCase(); + String searchTerm = text.toLowerCase(); searchTerm = searchTerm.split(":")[0]; // System.out.println(">>>>> search term : " + searchTerm); List wantedFields = new ArrayList<>(); @@ -1215,12 +1222,12 @@ public class StructureChooser extends GStructureChooser pdbRequest.setWantedFields(wantedFields); pdbRequest.setSearchTerm(searchTerm + ")"); pdbRequest.setAssociatedSequence(selectedSequence); - pdbRestCleint = PDBFTSRestClient.getInstance(); - wantedFields.add(pdbRestCleint.getPrimaryKeyColumn()); + pdbRestClient = PDBFTSRestClient.getInstance(); + wantedFields.add(pdbRestClient.getPrimaryKeyColumn()); FTSRestResponse resultList; try { - resultList = pdbRestCleint.executeRequest(pdbRequest); + resultList = pdbRestClient.executeRequest(pdbRequest); } catch (Exception e) { errorWarning.append(e.getMessage()); diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 768051f..be94301 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -40,12 +40,15 @@ 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; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -65,6 +68,8 @@ import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.ListCellRenderer; +import javax.swing.SwingUtilities; +import javax.swing.Timer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@ -260,6 +265,28 @@ public abstract class GStructureChooser extends JPanel } } + // 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 * @@ -486,19 +513,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(); } }); @@ -637,7 +664,8 @@ public abstract class GStructureChooser extends JPanel Desktop.addInternalFrame(mainFrame, frameTitle, width, height); } - protected void closeAction(int preferredHeight) + +protected void closeAction(int preferredHeight) { // System.out.println(">>>>>>>>>> closing internal frame!!!"); // System.out.println("width : " + mainFrame.getWidth()); -- 1.7.10.2