JAL-1667 updated test and internationalization messages
[jalview.git] / src / jalview / jbgui / GStructureChooser.java
index 7224b78..cbd6f1a 100644 (file)
@@ -1,15 +1,35 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
+ * Copyright (C) 2014 The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
 package jalview.jbgui;
 
 import jalview.gui.AlignmentPanel;
 import jalview.gui.Desktop;
 import jalview.util.MessageManager;
-import jalview.ws.uimodel.PDBSearchResponse.PDBResponseSummary;
+import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
 
 import java.awt.BorderLayout;
 import java.awt.CardLayout;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
-import java.awt.Image;
 import java.awt.event.ActionEvent;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
@@ -29,56 +49,59 @@ import javax.swing.JTextField;
 import javax.swing.ListSelectionModel;
 
 @SuppressWarnings("serial")
+/**
+ * GUI layout for structure chooser 
+ * @author tcnofoegbu
+ *
+ */
 public abstract class GStructureChooser extends JPanel implements
         ItemListener
 {
-  protected String frameTitle = "Structure Chooser";
+  protected String frameTitle = MessageManager
+          .getString("label.structure_chooser");
 
   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
 
-
-
-  protected JComboBox<FilterOptions> filterOptionsComboBox = new JComboBox<FilterOptions>();
+  protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
 
   protected AlignmentPanel ap;
 
-  protected JLabel resultLabel = new JLabel("Select : ");
+  protected JLabel lbl_result = new JLabel(
+          MessageManager.getString("label.select") /* "Select : " */);
 
-  protected JButton ok = new JButton();
+  protected JButton btn_ok = new JButton();
 
-  protected JButton cancel = new JButton();
+  protected JButton btn_cancel = new JButton();
 
-  protected JButton pdbFromFile = new JButton();
+  protected JButton btn_pdbFromFile = new JButton();
 
-  protected JTextField search = new JTextField(16);
+  protected JTextField txt_search = new JTextField(18);
 
-  protected JPanel actionPanel = new JPanel();
+  private JPanel pnl_actions = new JPanel();
 
-  protected JPanel filterPanel = new JPanel();
+  private JPanel pnl_filter = new JPanel();
 
-  protected JPanel idInputPanel = new JPanel();
+  private JPanel pnl_idInput = new JPanel();
 
-  protected JPanel fileChooserPanel = new JPanel();
+  private JPanel pnl_fileChooser = new JPanel();
 
-  protected JPanel switchableViewsPanel = new JPanel(new CardLayout());
+  protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
 
-  protected CardLayout switchableViewsLayout = (CardLayout) (switchableViewsPanel
+  protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
           .getLayout());
 
-  protected BorderLayout mainLayout = new BorderLayout();
-
-  protected BorderLayout idInputPanelLayout = new BorderLayout();
-
-  protected BorderLayout fileChooserPanelLayout = new BorderLayout();
+  private BorderLayout mainLayout = new BorderLayout();
 
-  protected JCheckBox rememberSettings = new JCheckBox("Don't ask me again");
+  protected JCheckBox chk_rememberSettings = new JCheckBox(
+          MessageManager.getString("label.dont_ask_me_again"));
 
-  protected JCheckBox invertFilter = new JCheckBox("Invert");
+  protected JCheckBox chk_invertFilter = new JCheckBox(
+          MessageManager.getString("label.invert"));
 
   protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
           "/images/loading.gif"));
 
-  protected JLabel loadingImageLabel = new JLabel(loadingImage);
+  protected JLabel lbl_loading = new JLabel(loadingImage);
 
   protected static final String VIEWS_FILTER = "VIEWS_FILTER";
 
@@ -86,14 +109,12 @@ public abstract class GStructureChooser extends JPanel implements
 
   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
 
-  protected JList<PDBResponseSummary> jListFoundStructures = new JList<PDBResponseSummary>();
+  protected JList<PDBResponseSummary> jList_FoundStructures = new JList<PDBResponseSummary>();
 
-  // protected JScrollPane foundStructuresScroller = new JScrollPane(
-  // jListFoundStructures);
+  protected JTable tbl_summary = new JTable();
 
-  protected JTable summaryTable = new JTable();
-  protected JScrollPane foundStructuresScroller = new JScrollPane(
-          summaryTable);
+  protected JScrollPane scrl_foundStructures = new JScrollPane(
+          tbl_summary);
 
   public GStructureChooser()
   {
@@ -109,20 +130,25 @@ public abstract class GStructureChooser extends JPanel implements
     }
   }
 
+  /**
+   * Initializes the GUI default properties
+   * 
+   * @throws Exception
+   */
   private void jbInit() throws Exception
   {
-    ok.setFont(new java.awt.Font("Verdana", 0, 12));
-    ok.setText(MessageManager.getString("action.view"));
-    ok.addActionListener(new java.awt.event.ActionListener()
+    btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_ok.setText(MessageManager.getString("action.view"));
+    btn_ok.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
         ok_ActionPerformed();
       }
     });
-    cancel.setFont(new java.awt.Font("Verdana", 0, 12));
-    cancel.setText(MessageManager.getString("action.cancel"));
-    cancel.addActionListener(new java.awt.event.ActionListener()
+    btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
+    btn_cancel.setText(MessageManager.getString("action.cancel"));
+    btn_cancel.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
@@ -130,9 +156,10 @@ public abstract class GStructureChooser extends JPanel implements
       }
     });
 
-    pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
-    pdbFromFile.setText("             Select PDB File             ");
-    pdbFromFile.addActionListener(new java.awt.event.ActionListener()
+    btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
+    String btn_title = MessageManager.getString("label.select_pdb_file");
+    btn_pdbFromFile.setText("             " + btn_title + "            ");
+    btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
     {
       public void actionPerformed(ActionEvent e)
       {
@@ -140,50 +167,47 @@ public abstract class GStructureChooser extends JPanel implements
       }
     });
 
-    jListFoundStructures
+    jList_FoundStructures
             .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
-    jListFoundStructures.setLayoutOrientation(JList.VERTICAL);
-    jListFoundStructures.setVisibleRowCount(-1);
-    foundStructuresScroller.setPreferredSize(new Dimension(500, 300));
-    foundStructuresScroller
+    jList_FoundStructures.setLayoutOrientation(JList.VERTICAL);
+    jList_FoundStructures.setVisibleRowCount(-1);
+    scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
+    scrl_foundStructures
             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
-    filterOptionsComboBox.setFont(new java.awt.Font("Verdana", 0, 12));
-    invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
-    rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
+    cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
+    chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
+    chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
 
-    filterOptionsComboBox.addItemListener(this);
-    invertFilter.addItemListener(this);
+    cmb_filterOption.addItemListener(this);
+    chk_invertFilter.addItemListener(this);
 
-    actionPanel.add(rememberSettings);
-    actionPanel.add(ok);
-    actionPanel.add(cancel);
+    pnl_actions.add(chk_rememberSettings);
+    pnl_actions.add(btn_ok);
+    pnl_actions.add(btn_cancel);
 
+    pnl_filter.add(lbl_result);
+    pnl_filter.add(cmb_filterOption);
+    lbl_loading.setVisible(false);
 
-    filterPanel.add(resultLabel);
-    filterPanel.add(filterOptionsComboBox);
-    loadingImageLabel.setVisible(false);
+    pnl_filter.add(lbl_loading);
 
-    filterPanel.add(loadingImageLabel);
+    pnl_filter.add(chk_invertFilter);
 
-    filterPanel.add(invertFilter);
+    pnl_idInput.setLayout(new FlowLayout());
+    pnl_idInput.add(txt_search);
 
-    idInputPanel.setLayout(new FlowLayout());
-    idInputPanel.add(search);
-
-
-    fileChooserPanel.setLayout(new FlowLayout());
-    fileChooserPanel.add(pdbFromFile);
-
-    switchableViewsPanel.add(fileChooserPanel, VIEWS_FROM_FILE);
-    switchableViewsPanel.add(idInputPanel, VIEWS_ENTER_ID);
-    switchableViewsPanel.add(foundStructuresScroller, VIEWS_FILTER);
+    pnl_fileChooser.setLayout(new FlowLayout());
+    pnl_fileChooser.add(btn_pdbFromFile);
 
+    pnl_switchableViews.add(pnl_fileChooser, VIEWS_FROM_FILE);
+    pnl_switchableViews.add(pnl_idInput, VIEWS_ENTER_ID);
+    pnl_switchableViews.add(scrl_foundStructures, VIEWS_FILTER);
     
     this.setLayout(mainLayout);
-    this.add(filterPanel, java.awt.BorderLayout.NORTH);
-    this.add(switchableViewsPanel, java.awt.BorderLayout.CENTER);
-    this.add(actionPanel, java.awt.BorderLayout.SOUTH);
+    this.add(pnl_filter, java.awt.BorderLayout.NORTH);
+    this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
+    this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
 
     mainFrame.setVisible(true);
     mainFrame.setContentPane(this);
@@ -192,23 +216,22 @@ public abstract class GStructureChooser extends JPanel implements
   }
 
   
-  private ImageIcon scaleImageIcone(ImageIcon imageIcon, int width, int height)
-  {
-    Image image = imageIcon.getImage(); // transform it
-
-    Image newimg = image.getScaledInstance(width, height,
-            java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
-
-    return new ImageIcon(newimg);
-  }
-  
   @Override
+  /**
+   * Event listener for the 'filter' combo-box and 'invert' check-box
+   */
   public void itemStateChanged(ItemEvent e)
   {
     stateChanged(e);
   }
 
-  public class FilterOptions
+  /**
+   * This inner class provides the data model for the structure filter combo-box
+   * 
+   * @author tcnofoegbu
+   *
+   */
+  public class FilterOption
   {
     private String name;
 
@@ -216,20 +239,13 @@ public abstract class GStructureChooser extends JPanel implements
 
     private String view;
 
-    public FilterOptions(String name, String value, String view)
+    public FilterOption(String name, String value, String view)
     {
       this.name = name;
       this.value = value;
       this.view = view;
     }
 
-    // public FilterOptions(PDBDocField field, String view)
-    // {
-    // this.name = "Best " + field.getName();
-    // this.value = field.getCode();
-    // this.view = view;
-    // }
-
     public String getName()
     {
       return name;
@@ -266,13 +282,18 @@ public abstract class GStructureChooser extends JPanel implements
     }
   }
 
+  public JComboBox<FilterOption> getCmbFilterOption()
+  {
+    return cmb_filterOption;
+  }
+
   protected abstract void stateChanged(ItemEvent e);
 
   protected abstract void updateCurrentView();
 
   protected abstract void ok_ActionPerformed();
 
-  protected abstract void populateFilterOptions();
+  protected abstract void populateFilterComboBox();
 
   protected abstract void pdbFromFile_actionPerformed();
 }