JAL-2944 ’new view’ and ‘add to view’ button rather than selecting from combo box...
authorJim Procter <jprocter@issues.jalview.org>
Mon, 9 Apr 2018 09:17:12 +0000 (10:17 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 9 Apr 2018 09:17:12 +0000 (10:17 +0100)
src/jalview/gui/StructureChooser.java
src/jalview/jbgui/GStructureChooser.java

index 1b69989..cd1cfc3 100644 (file)
@@ -142,13 +142,11 @@ public class StructureChooser extends GStructureChooser
     if (Desktop.instance != null)
     {
       targetView.removeAllItems();
-      targetView.addItem(
-              new StructureViewer(ap.getStructureSelectionManager()));
       if (lastTargetedView != null && !lastTargetedView.isVisible())
       {
         lastTargetedView = null;
       }
-      int linkedViewsAt = 1;
+      int linkedViewsAt = 0;
       for (StructureViewerBase view : Desktop.instance
               .getStructureViewers(null, null))
       {
@@ -166,12 +164,16 @@ public class StructureChooser extends GStructureChooser
           targetView.addItem(viewHandler);
         }
       }
-      targetView.setVisible(targetView.getItemCount() > 1);
-
-      // finally, restore last targeted view by default.
-      if (lastTargetedView != null)
-      {
-        targetView.setSelectedItem(lastTargetedView);
+      targetView.setVisible(targetView.getItemCount() > 0);
+      btn_view.setVisible(targetView.isVisible());
+      if (targetView.isVisible()) {
+        // finally, restore last targeted view by default.
+        if (lastTargetedView != null)
+        {
+          targetView.setSelectedItem(lastTargetedView);
+        } else {
+          targetView.setSelectedIndex(0);
+        }
       }
     }
   }
@@ -817,7 +819,17 @@ public class StructureChooser extends GStructureChooser
    * Handles action event for btn_ok
    */
   @Override
-  public void ok_ActionPerformed()
+  public void newview_ActionPerformed()
+  {
+    targetView.setSelectedItem(null);
+    showStructures(false);
+  }
+
+  /**
+   * Handles action event for btn_ok
+   */
+  @Override
+  public void view_ActionPerformed()
   {
     showStructures(false);
   }
index 810813b..523ab7e 100644 (file)
@@ -105,6 +105,9 @@ public abstract class GStructureChooser extends JPanel
 
   protected JButton btn_view = new JButton();
 
+  protected JButton btn_newview = new JButton(
+          MessageManager.getString("label.new_view"));
+
   protected JButton btn_cancel = new JButton();
 
   protected JButton btn_pdbFromFile = new JButton();
@@ -329,7 +332,7 @@ public abstract class GStructureChooser extends JPanel
         case KeyEvent.VK_ENTER: // enter key
           if (btn_view.isEnabled())
           {
-            ok_ActionPerformed();
+            view_ActionPerformed();
           }
           break;
         case KeyEvent.VK_TAB: // tab key
@@ -378,7 +381,7 @@ public abstract class GStructureChooser extends JPanel
         case KeyEvent.VK_ENTER: // enter key
           if (btn_view.isEnabled())
           {
-            ok_ActionPerformed();
+            view_ActionPerformed();
           }
           break;
         case KeyEvent.VK_TAB: // tab key
@@ -404,14 +407,36 @@ public abstract class GStructureChooser extends JPanel
         }
       }
     });
+    btn_newview.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_newview.setText(MessageManager.getString("action.new_view"));
+    btn_newview.addActionListener(new java.awt.event.ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        newview_ActionPerformed();
+      }
+    });
+    btn_newview.addKeyListener(new KeyAdapter()
+    {
+      @Override
+      public void keyPressed(KeyEvent evt)
+      {
+        if (evt.getKeyCode() == KeyEvent.VK_ENTER)
+        {
+          newview_ActionPerformed();
+        }
+      }
+    });
+
     btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
-    btn_view.setText(MessageManager.getString("action.view"));
+    btn_view.setText(MessageManager.getString("action.add"));
     btn_view.addActionListener(new java.awt.event.ActionListener()
     {
       @Override
       public void actionPerformed(ActionEvent e)
       {
-        ok_ActionPerformed();
+        view_ActionPerformed();
       }
     });
     btn_view.addKeyListener(new KeyAdapter()
@@ -421,7 +446,7 @@ public abstract class GStructureChooser extends JPanel
       {
         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
         {
-          ok_ActionPerformed();
+          view_ActionPerformed();
         }
       }
     });
@@ -523,11 +548,13 @@ public abstract class GStructureChooser extends JPanel
     chk_invertFilter.addItemListener(this);
 
     targetView.setVisible(false);
-    pnl_actions.add(targetView,"wrap");
-    pnl_actions.add(chk_rememberSettings);
-    pnl_actions.add(btn_view);
-    pnl_actions.add(btn_cancel);
+    pnl_actions.add(targetView, "left");
+    pnl_actions.add(btn_view, "wrap");
     pnl_actions.add(chk_superpose, "left");
+    pnl_actions.add(btn_newview);
+    pnl_actions.add(btn_cancel, "right");
+
+    // pnl_actions.add(chk_rememberSettings);
 
     // pnl_filter.add(lbl_result);
     pnl_main.add(cmb_filterOption);
@@ -557,13 +584,15 @@ public abstract class GStructureChooser extends JPanel
         JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
                 .getSource();
         int index = sourceTabbedPane.getSelectedIndex();
-        btn_view.setVisible(true);
+        btn_view.setVisible(targetView.isVisible());
+        btn_newview.setVisible(true);
         btn_cancel.setVisible(true);
         if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
         {
           btn_view.setEnabled(false);
           btn_cancel.setEnabled(false);
           btn_view.setVisible(false);
+          btn_newview.setEnabled(false);
           btn_cancel.setVisible(false);
           previousWantedFields = pdbDocFieldPrefs
                   .getStructureSummaryFields()
@@ -912,7 +941,9 @@ public abstract class GStructureChooser extends JPanel
 
   protected abstract void stateChanged(ItemEvent e);
 
-  protected abstract void ok_ActionPerformed();
+  protected abstract void view_ActionPerformed();
+
+  protected abstract void newview_ActionPerformed();
 
   protected abstract void pdbFromFile_actionPerformed();