preliminary hack fix for synthetic reference issue
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Thu, 20 Dec 2018 11:41:12 +0000 (05:41 -0600)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Thu, 20 Dec 2018 11:41:12 +0000 (05:41 -0600)
           RecentlyOpened
         inner/ /subclasses
       JalviewFileChooser
          \          /
           JFileChooser
                 Component

So Component can be retrieved two ways through JFileChooser. (1) as the
original JalviewFileChooser object
(2) as the superclass of RecentlyOpened.

I will look into it. For now it is sufficient to simply move
RecentlyOpened to be at least a static class. I just made it another
top-level class.

src/jalview/io/JalviewFileChooser.java

index 88a337a..9667d7f 100755 (executable)
@@ -126,7 +126,7 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
   public JalviewFileChooser(String dir)
   {
     super(safePath(dir));
-    setAccessory(new RecentlyOpened());
+    setAccessory(new RecentlyOpened(this));
   }
 
   public JalviewFileChooser(String dir, String[] suffix, String[] desc,
@@ -197,7 +197,12 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
      * code below here is not reached in JalviewJS, instead
      * propertyChange() is called for dialog action
      */
+    /**
+     * @j2sNative
+     */
+    {
     handleResponse(value);
+    }
     return value;
   }
 
@@ -233,7 +238,7 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
       setFileFilter(chosen);
     }
 
-    setAccessory(new RecentlyOpened());
+    setAccessory(new RecentlyOpened(this));
   }
 
   @Override
@@ -418,78 +423,6 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
     }
   }
 
-  class RecentlyOpened extends JPanel
-  {
-    private static final long serialVersionUID = 1L;
-    JList<String> list;
-
-    RecentlyOpened()
-    {
-      setPreferredSize(new Dimension(300,100));
-      String historyItems = Cache.getProperty("RECENT_FILE");
-      StringTokenizer st;
-      Vector<String> recent = new Vector<>();
-
-      if (historyItems != null)
-      {
-        st = new StringTokenizer(historyItems, "\t");
-
-        while (st.hasMoreTokens())
-        {
-          recent.addElement(st.nextToken());
-        }
-      }
-
-      list = new JList<>(recent);
-  
-      DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
-//      dlcr.setHorizontalAlignment(DefaultListCellRenderer.RIGHT);
-      list.setCellRenderer(dlcr);
-
-      list.addMouseListener(new MouseAdapter()
-      {
-        @Override
-        public void mousePressed(MouseEvent evt)
-        {
-          recentListSelectionChanged(list.getSelectedValue());
-        }
-      });
-
-      this.setBorder(new javax.swing.border.TitledBorder(
-              MessageManager.getString("label.recently_opened")));
-
-      final JScrollPane scroller = new JScrollPane(list);
-
-      SpringLayout layout = new SpringLayout();
-      layout.putConstraint(SpringLayout.WEST, scroller, 5,
-              SpringLayout.WEST, this);
-      layout.putConstraint(SpringLayout.NORTH, scroller, 5,
-              SpringLayout.NORTH, this);
-
-      if (Platform.isAMac())
-      {
-        scroller.setPreferredSize(new Dimension(500, 100));
-      }
-      else
-      {
-        scroller.setPreferredSize(new Dimension(530, 200));
-      }
-
-      this.add(scroller);
-
-      javax.swing.SwingUtilities.invokeLater(new Runnable()
-      {
-        @Override
-        public void run()
-        {
-          scroller.getHorizontalScrollBar()
-                  .setValue(scroller.getHorizontalScrollBar().getMaximum());
-        }
-      });
-
-    }
-
-  }
 
   @Override
   public DialogRunnerI setResponseHandler(Object response, Runnable action)
@@ -537,3 +470,78 @@ public class JalviewFileChooser extends JFileChooser implements DialogRunnerI,
     }
   }
 }
+
+class RecentlyOpened extends JPanel
+{
+  private static final long serialVersionUID = 1L;
+  JList<String> list;
+  private JalviewFileChooser chooser;
+
+  RecentlyOpened(JalviewFileChooser chooser) 
+  {
+       this.chooser = chooser;
+    setPreferredSize(new Dimension(300,100));
+    String historyItems = Cache.getProperty("RECENT_FILE");
+    StringTokenizer st;
+    Vector<String> recent = new Vector<>();
+
+    if (historyItems != null)
+    {
+      st = new StringTokenizer(historyItems, "\t");
+
+      while (st.hasMoreTokens())
+      {
+        recent.addElement(st.nextToken());
+      }
+    }
+
+    list = new JList<>(recent);
+
+    DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
+//    dlcr.setHorizontalAlignment(DefaultListCellRenderer.RIGHT);
+    list.setCellRenderer(dlcr);
+
+    list.addMouseListener(new MouseAdapter()
+    {
+      @Override
+      public void mousePressed(MouseEvent evt)
+      {
+        chooser.recentListSelectionChanged(list.getSelectedValue());
+      }
+    });
+
+    this.setBorder(new javax.swing.border.TitledBorder(
+            MessageManager.getString("label.recently_opened")));
+
+    final JScrollPane scroller = new JScrollPane(list);
+
+    SpringLayout layout = new SpringLayout();
+    layout.putConstraint(SpringLayout.WEST, scroller, 5,
+            SpringLayout.WEST, this);
+    layout.putConstraint(SpringLayout.NORTH, scroller, 5,
+            SpringLayout.NORTH, this);
+
+    if (Platform.isAMac())
+    {
+      scroller.setPreferredSize(new Dimension(500, 100));
+    }
+    else
+    {
+      scroller.setPreferredSize(new Dimension(530, 200));
+    }
+
+    this.add(scroller);
+
+    javax.swing.SwingUtilities.invokeLater(new Runnable()
+    {
+      @Override
+      public void run()
+      {
+        scroller.getHorizontalScrollBar()
+                .setValue(scroller.getHorizontalScrollBar().getMaximum());
+      }
+    });
+
+  }
+
+}