JAL-2074 Improvement to StructureChooser and FTS interfaces to remember the user...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 30 Jun 2016 14:59:00 +0000 (15:59 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 30 Jun 2016 14:59:00 +0000 (15:59 +0100)
src/jalview/fts/api/GFTSPanelI.java
src/jalview/fts/core/FTSRestResponse.java
src/jalview/fts/core/GFTSPanel.java
src/jalview/fts/service/pdb/PDBFTSPanel.java
src/jalview/fts/service/uniprot/UniprotFTSPanel.java
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GStructureChooser.java

index ce63576..f86c3bc 100644 (file)
@@ -21,6 +21,8 @@
 
 package jalview.fts.api;
 
+import java.util.Map;
+
 import javax.swing.JTable;
 
 /**
@@ -127,4 +129,12 @@ public interface GFTSPanelI
    * @param isEnabled
    */
   public void setNextPageButtonEnabled(boolean isEnabled);
+
+  /**
+   * The HashMap used to store user preferences for summary table columns,
+   * window size and position
+   * 
+   * @return
+   */
+  public Map<String, Integer> getTempUserPrefs();
 }
index 8078d43..92ea5f8 100644 (file)
@@ -25,6 +25,7 @@ import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 
 import java.util.Collection;
+import java.util.Map;
 
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
@@ -134,7 +135,8 @@ public class FTSRestResponse
   }
 
   public static void configureTableColumn(JTable tbl_summary,
-          Collection<FTSDataColumnI> wantedFields)
+          Collection<FTSDataColumnI> wantedFields,
+          Map<String, Integer> columnPrefs)
   {
     for (FTSDataColumnI wantedField : wantedFields)
     {
@@ -144,8 +146,11 @@ public class FTSRestResponse
                 wantedField.getMinWidth());
         tbl_summary.getColumn(wantedField.getName()).setMaxWidth(
                 wantedField.getMaxWidth());
+        int prefedWidth = columnPrefs.get(wantedField.getName()) == null ? wantedField
+                .getPreferredWidth() : columnPrefs.get(wantedField
+                .getName());
         tbl_summary.getColumn(wantedField.getName()).setPreferredWidth(
-                wantedField.getPreferredWidth());
+                prefedWidth);
       } catch (Exception e)
       {
         e.printStackTrace();
@@ -153,15 +158,15 @@ public class FTSRestResponse
       if (wantedField.getDataType().getDataTypeClass() == Double.class)
       {
         DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
-                wantedField.getDataType().isFormtted(),
-                wantedField.getDataType().getSignificantFigures());
+                wantedField.getDataType().isFormtted(), wantedField
+                        .getDataType().getSignificantFigures());
         tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
       }
       else if (wantedField.getDataType().getDataTypeClass() == Integer.class)
       {
         DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
-                wantedField.getDataType().isFormtted(),
-                wantedField.getDataType().getSignificantFigures());
+                wantedField.getDataType().isFormtted(), wantedField
+                        .getDataType().getSignificantFigures());
         tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
       }
     }
index b288aa5..33fa020 100644 (file)
@@ -66,6 +66,7 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
+import javax.swing.event.InternalFrameEvent;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableColumn;
 
@@ -146,7 +147,6 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   protected static final DecimalFormat totalNumberformatter = new DecimalFormat(
           "###,###");
-
   private JTable tbl_summary = new JTable()
   {
     private boolean inLayout;
@@ -190,6 +190,8 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
               && !inLayout)
       {
         resizingColumn.setPreferredWidth(resizingColumn.getWidth());
+        String colHeader = resizingColumn.getHeaderValue().toString();
+        getTempUserPrefs().put(colHeader, resizingColumn.getWidth());
       }
       resizeAndRepaint();
     }
@@ -244,6 +246,10 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
    */
   private void jbInit() throws Exception
   {
+    Integer width = getTempUserPrefs().get("FTSPanel.width") == null ? 800
+            : getTempUserPrefs().get("FTSPanel.width");
+    Integer height = getTempUserPrefs().get("FTSPanel.height") == null ? 400
+            : getTempUserPrefs().get("FTSPanel.height");
     lbl_warning.setVisible(false);
     lbl_warning.setFont(new java.awt.Font("Verdana", 0, 12));
     lbl_loading.setVisible(false);
@@ -428,7 +434,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
         }
       }
     });
-    scrl_searchResult.setPreferredSize(new Dimension(800, 400));
+    scrl_searchResult.setPreferredSize(new Dimension(width, height));
 
     cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12));
     cmb_searchTarget.addActionListener(new ActionListener()
@@ -571,7 +577,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
       }
     };
     tabbedPane.addChangeListener(changeListener);
-    tabbedPane.setPreferredSize(new Dimension(800, 400));
+    tabbedPane.setPreferredSize(new Dimension(width, height));
     tabbedPane.add(searchTabTitle, scrl_searchResult);
     tabbedPane.add(configureCols, new FTSDataColumnPreferences(
             PreferenceSource.SEARCH_SUMMARY, getFTSRestClient()));
@@ -596,9 +602,40 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
     mainFrame.setVisible(true);
     mainFrame.setContentPane(this);
     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
-    Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), 900, 500);
+    mainFrame
+            .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+            {
+              @Override
+              public void internalFrameClosing(InternalFrameEvent e)
+              {
+                closeAction();
+              }
+            });
+    mainFrame.setVisible(true);
+    mainFrame.setContentPane(this);
+    mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+    Integer x = getTempUserPrefs().get("FTSPanel.x");
+    Integer y = getTempUserPrefs().get("FTSPanel.y");
+    if (x != null && y != null)
+    {
+      mainFrame.setLocation(x, y);
+    }
+    Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), width, height);
   }
 
+  protected void closeAction()
+  {
+    // System.out.println(">>>>>>>>>> closing internal frame!!!");
+    // System.out.println("width : " + this.getWidth());
+    // System.out.println("heigh : " + this.getHeight());
+    // System.out.println("x : " + mainFrame.getX());
+    // System.out.println("y : " + mainFrame.getY());
+    getTempUserPrefs().put("FTSPanel.width", this.getWidth());
+    getTempUserPrefs().put("FTSPanel.height", pnl_results.getHeight());
+    getTempUserPrefs().put("FTSPanel.x", mainFrame.getX());
+    getTempUserPrefs().put("FTSPanel.y", mainFrame.getY());
+    mainFrame.dispose();
+  }
   public class DeferredTextInputListener implements DocumentListener
   {
     private final Timer swingTimer;
@@ -719,7 +756,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   protected void btn_back_ActionPerformed()
   {
-    mainFrame.dispose();
+    closeAction();
     new SequenceFetcher(progressIdicator);
   }
 
@@ -732,7 +769,7 @@ public abstract class GFTSPanel extends JPanel implements GFTSPanelI
 
   protected void btn_cancel_ActionPerformed()
   {
-    mainFrame.dispose();
+    closeAction();
   }
 
   /**
index 32c171e..5f5c716 100644 (file)
@@ -29,7 +29,9 @@ import jalview.fts.core.GFTSPanel;
 import jalview.gui.SequenceFetcher;
 import jalview.util.MessageManager;
 
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 
 @SuppressWarnings("serial")
 public class PDBFTSPanel extends GFTSPanel
@@ -39,6 +41,8 @@ public class PDBFTSPanel extends GFTSPanel
 
   private String ftsFrameTitle = defaultFTSFrameTitle;
 
+  private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
+
   public PDBFTSPanel(SequenceFetcher seqFetcher)
   {
     pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize();
@@ -101,7 +105,7 @@ public class PDBFTSPanel extends GFTSPanel
                     FTSRestResponse.getTableModel(request,
                     resultList.getSearchSummary()));
             FTSRestResponse.configureTableColumn(getResultTable(),
-                    wantedFields);
+                    wantedFields, tempUserPrefs);
             getResultTable().setVisible(true);
           }
 
@@ -267,4 +271,10 @@ public class PDBFTSPanel extends GFTSPanel
     return true;
   }
 
+  @Override
+  public Map<String, Integer> getTempUserPrefs()
+  {
+    return tempUserPrefs;
+  }
+
 }
index b1aa5f1..9c2c5ce 100644 (file)
@@ -29,7 +29,9 @@ import jalview.fts.core.GFTSPanel;
 import jalview.gui.SequenceFetcher;
 import jalview.util.MessageManager;
 
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 
 @SuppressWarnings("serial")
 public class UniprotFTSPanel extends GFTSPanel
@@ -40,7 +42,7 @@ public class UniprotFTSPanel extends GFTSPanel
 
   private String ftsFrameTitle = defaultFTSFrameTitle;
 
-
+  private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
 
   public UniprotFTSPanel(SequenceFetcher seqFetcher)
   {
@@ -104,7 +106,7 @@ public class UniprotFTSPanel extends GFTSPanel
                     FTSRestResponse.getTableModel(request,
                             resultList.getSearchSummary()));
             FTSRestResponse.configureTableColumn(getResultTable(),
-                    wantedFields);
+                    wantedFields, tempUserPrefs);
             getResultTable().setVisible(true);
           }
 
@@ -225,4 +227,10 @@ public class UniprotFTSPanel extends GFTSPanel
     return ftsFrameTitle;
   }
 
+  @Override
+  public Map<String, Integer> getTempUserPrefs()
+  {
+    return tempUserPrefs;
+  }
+
 }
index 8bccc6b..13fa460 100644 (file)
@@ -457,7 +457,7 @@ public class StructureChooser extends GStructureChooser implements
                   lastPdbRequest, reorderedStructuresSet));
 
           FTSRestResponse.configureTableColumn(getResultTable(),
-                  wantedFields);
+                  wantedFields, tempUserPrefs);
           getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
           getResultTable().getColumn("Ref Sequence").setMinWidth(100);
           getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
@@ -834,7 +834,7 @@ public class StructureChooser extends GStructureChooser implements
           launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
                   new SequenceI[] { selectedSequence });
     }
-    mainFrame.dispose();
+        closeAction();
       }
     }).start();
   }
index 44f659d..e571064 100644 (file)
@@ -44,6 +44,8 @@ import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -61,6 +63,7 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
+import javax.swing.event.InternalFrameEvent;
 import javax.swing.table.TableColumn;
 
 @SuppressWarnings("serial")
@@ -171,6 +174,8 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected FTSDataColumnI[] previousWantedFields;
 
+  protected static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
+
   private JTable tbl_summary = new JTable()
   {
     private boolean inLayout;
@@ -214,6 +219,8 @@ public abstract class GStructureChooser extends JPanel implements
               && !inLayout)
       {
         resizingColumn.setPreferredWidth(resizingColumn.getWidth());
+        String colHeader = resizingColumn.getHeaderValue().toString();
+        tempUserPrefs.put(colHeader, resizingColumn.getWidth());
       }
       resizeAndRepaint();
     }
@@ -269,6 +276,10 @@ public abstract class GStructureChooser extends JPanel implements
    */
   private void jbInit() throws Exception
   {
+    Integer width = tempUserPrefs.get("structureChooser.width") == null ? 800
+            : tempUserPrefs.get("structureChooser.width");
+    Integer height = tempUserPrefs.get("structureChooser.height") == null ? 400
+            : tempUserPrefs.get("structureChooser.height");
     tbl_summary.setAutoCreateRowSorter(true);
     tbl_summary.getTableHeader().setReorderingAllowed(false);
     tbl_summary.addMouseListener(new MouseAdapter()
@@ -402,7 +413,7 @@ public abstract class GStructureChooser extends JPanel implements
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        mainFrame.dispose();
+        closeAction();
       }
     });
     btn_cancel.addKeyListener(new KeyAdapter()
@@ -412,7 +423,7 @@ public abstract class GStructureChooser extends JPanel implements
       {
         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
         {
-          mainFrame.dispose();
+          closeAction();
         }
       }
     });
@@ -440,9 +451,9 @@ public abstract class GStructureChooser extends JPanel implements
       }
     });
 
-    scrl_foundStructures.setPreferredSize(new Dimension(800, 400));
+    scrl_foundStructures.setPreferredSize(new Dimension(width, height));
 
-    scrl_localPDB.setPreferredSize(new Dimension(800, 400));
+    scrl_localPDB.setPreferredSize(new Dimension(width, height));
     scrl_localPDB
             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
@@ -538,7 +549,7 @@ public abstract class GStructureChooser extends JPanel implements
       }
     };
     pnl_filter.addChangeListener(changeListener);
-    pnl_filter.setPreferredSize(new Dimension(800, 400));
+    pnl_filter.setPreferredSize(new Dimension(width, height));
     pnl_filter.add(foundStructureSummary, scrl_foundStructures);
     pnl_filter.add(configureCols, pdbDocFieldPrefs);
 
@@ -559,12 +570,40 @@ public abstract class GStructureChooser extends JPanel implements
     statusPanel.add(statusBar, null);
     this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
 
+    mainFrame
+            .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
+            {
+              @Override
+              public void internalFrameClosing(InternalFrameEvent e)
+              {
+                closeAction();
+              }
+            });
     mainFrame.setVisible(true);
     mainFrame.setContentPane(this);
     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
-    Desktop.addInternalFrame(mainFrame, frameTitle, 900, 500);
+    Integer x = tempUserPrefs.get("structureChooser.x");
+    Integer y = tempUserPrefs.get("structureChooser.y");
+    if (x != null && y != null)
+    {
+      mainFrame.setLocation(x, y);
+    }
+    Desktop.addInternalFrame(mainFrame, frameTitle, width, height);
   }
 
+  protected void closeAction()
+  {
+    // System.out.println(">>>>>>>>>> closing internal frame!!!");
+    // System.out.println("width : " + mainFrame.getWidth());
+    // System.out.println("heigh : " + mainFrame.getHeight());
+    // System.out.println("x : " + mainFrame.getX());
+    // System.out.println("y : " + mainFrame.getY());
+    tempUserPrefs.put("structureChooser.width", pnl_filter.getWidth());
+    tempUserPrefs.put("structureChooser.height", pnl_filter.getHeight());
+    tempUserPrefs.put("structureChooser.x", mainFrame.getX());
+    tempUserPrefs.put("structureChooser.y", mainFrame.getY());
+    mainFrame.dispose();
+  }
   public boolean wantedFieldsUpdated()
   {
     if (previousWantedFields == null)