JAL-1563 Implemented hack to make table both scrollable and resizable and made Unipro...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 28 Apr 2016 12:03:06 +0000 (13:03 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 28 Apr 2016 12:03:06 +0000 (13:03 +0100)
src/jalview/fts/core/GFTSPanel.java
src/jalview/fts/service/uniprot/UniProtFTSRestClient.java

index f8a9034..a35e827 100644 (file)
@@ -65,6 +65,7 @@ import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableColumn;
 
 /**
  * This class provides the swing GUI layout for FTS Panel and implements most of
@@ -90,7 +91,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   protected JButton btn_cancel = new JButton();
 
-  protected JTextField txt_search = new JTextField(20);
+  protected JTextField txt_search = new JTextField(35);
 
   protected SequenceFetcher seqFetcher;
 
@@ -100,6 +101,51 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   private JTable tbl_summary = new JTable()
   {
+    private boolean inLayout;
+
+    @Override
+    public boolean getScrollableTracksViewportWidth()
+    {
+      return hasExcessWidth();
+
+    }
+
+    @Override
+    public void doLayout()
+    {
+      if (hasExcessWidth())
+      {
+        autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
+      }
+      inLayout = true;
+      super.doLayout();
+      inLayout = false;
+      autoResizeMode = AUTO_RESIZE_OFF;
+    }
+
+    protected boolean hasExcessWidth()
+    {
+      return getPreferredSize().width < getParent().getWidth();
+    }
+
+    @Override
+    public void columnMarginChanged(ChangeEvent e)
+    {
+      if (isEditing())
+      {
+        removeEditor();
+      }
+      TableColumn resizingColumn = getTableHeader().getResizingColumn();
+      // Need to do this here, before the parent's
+      // layout manager calls getPreferredSize().
+      if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF
+              && !inLayout)
+      {
+        resizingColumn.setPreferredWidth(resizingColumn.getWidth());
+      }
+      resizeAndRepaint();
+    }
+
     @Override
     public String getToolTipText(MouseEvent evt)
     {
@@ -180,7 +226,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     lbl_loading.setVisible(false);
     lbl_loading.setFont(new java.awt.Font("Verdana", 0, 12));
 
-    tbl_summary.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
     tbl_summary.setAutoCreateRowSorter(true);
     tbl_summary.getTableHeader().setReorderingAllowed(false);
     tbl_summary.addMouseListener(new MouseAdapter()
@@ -298,10 +343,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
         }
       }
     });
-
-    scrl_searchResult.setPreferredSize(new Dimension(500, 300));
-    scrl_searchResult
-            .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+    scrl_searchResult.setPreferredSize(new Dimension(800, 400));
 
     cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12));
     cmb_searchTarget.addActionListener(new ActionListener()
@@ -435,7 +477,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
       }
     };
     tabbedPane.addChangeListener(changeListener);
-    tabbedPane.setPreferredSize(new Dimension(500, 300));
+    tabbedPane.setPreferredSize(new Dimension(800, 400));
     tabbedPane.add(searchTabTitle, scrl_searchResult);
     tabbedPane.add(configureCols, new FTSDataColumnPreferences(
             PreferenceSource.SEARCH_SUMMARY, getFTSRestClient()));
@@ -457,7 +499,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     mainFrame.setVisible(true);
     mainFrame.setContentPane(this);
     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
-    Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), 800, 400);
+    Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), 900, 500);
   }
 
   public class DeferredTextInputListener implements DocumentListener
index f6d7221..2af1d56 100644 (file)
@@ -73,6 +73,7 @@ public class UniProtFTSRestClient extends FTSRestClient
             .queryParam("format", "tab")
             .queryParam("columns", wantedFields)
             .queryParam("limit", String.valueOf(responseSize))
+            .queryParam("sort", "score")
             .queryParam("query", query);
     // Execute the REST request
     ClientResponse clientResponse = webResource