Merge branch 'bug/JAL-1707_retrieve-pdb-structure-for-rna' into Release_2_8_3_Branch
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 24 Apr 2015 13:53:01 +0000 (14:53 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Fri, 24 Apr 2015 13:53:01 +0000 (14:53 +0100)
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/gui/AlignViewport.java
src/jalview/gui/FontChooser.java
src/jalview/gui/UserDefinedColours.java
src/jalview/jbgui/GSplitFrame.java
src/jalview/util/MappingUtils.java
test/jalview/gui/FontChooserTest.java

index 3d572f5..42dfca9 100644 (file)
@@ -1142,6 +1142,7 @@ status.das_feature_fetching_cancelled = DAS Feature Fetching Cancelled
 status.das_feature_fetching_complete = DAS Feature Fetching Complete
 status.fetching_db_refs = Fetching db refs
 label.font_doesnt_have_letters_defined = Font doesn't have letters defined\nso cannot be used\nwith alignment data
+label.font_too_small = Font size is too small
 label.error_loading_file_params = Error loading file {0}
 label.error_loading_jalview_file = Error loading Jalview file
 warn.out_of_memory_when_action = Out of memory when {0}\!\!\nSee help files for increasing Java Virtual Machine memory.
index 241fff2..6db40cf 100644 (file)
@@ -1097,6 +1097,7 @@ status.das_feature_fetching_cancelled = Recuperaci
 status.das_feature_fetching_complete = Recuperación de características DAS completada
 status.fetching_db_refs = Recuperando db refs
 label.font_doesnt_have_letters_defined = La fuente no tiene letras definidas\npor lo que no puede emplease\ncon datos de alineamientos
+label.font_too_small = Tamaño de la letra es demasiado pequeña
 label.error_loading_file_params = Error cargando el fichero {0}
 label.error_loading_jalview_file = Error cargando el fichero Jalview 
 warn.out_of_memory_when_action = Sin memoria al {0}\!\!\nConsulte los ficheros de ayuda para ajustar la memoria de la m\u00E1quina virtual de Java.
index c59d201..cf12145 100644 (file)
@@ -857,14 +857,6 @@ public class AlignViewport extends AlignmentViewport implements
     final boolean openInNewWindow = (response == 2);
 
     /*
-     * Create the AlignFrame first (which creates the new alignment's datasets),
-     * before attempting sequence mapping.
-     */
-    AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
-            AlignFrame.DEFAULT_HEIGHT);
-    newAlignFrame.setTitle(title);
-
-    /*
      * Identify protein and dna alignments. Make a copy of this one if opening
      * in a new split pane.
      */
@@ -873,6 +865,23 @@ public class AlignViewport extends AlignmentViewport implements
     AlignmentI protein = al.isNucleotide() ? thisAlignment : al;
     final AlignmentI cdna = al.isNucleotide() ? al : thisAlignment;
 
+    /*
+     * Map sequences. At least one should get mapped as we have already passed
+     * the test for 'mappability'. Any mappings made will be added to the
+     * protein alignment. Note creating dataset sequences on the new alignment
+     * is a pre-requisite for building mappings.
+     */
+    al.setDataset(null);
+    AlignmentUtils.mapProteinToCdna(protein, cdna);
+
+    /*
+     * Create the AlignFrame for the added alignment. Note this will include the
+     * cDNA consensus annotation if it is protein (because the alignment holds
+     * mappings to nucleotide)
+     */
+    AlignFrame newAlignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
+            AlignFrame.DEFAULT_HEIGHT);
+    newAlignFrame.setTitle(title);
     newAlignFrame.statusBar.setText(MessageManager.formatMessage(
             "label.successfully_loaded_file", new Object[]
             { title }));
@@ -891,13 +900,6 @@ public class AlignViewport extends AlignmentViewport implements
               AlignFrame.DEFAULT_HEIGHT);
     }
 
-    /*
-     * Map sequences. At least one should get mapped as we have already passed
-     * the test for 'mappability'. Any mappings made will be added to the
-     * protein alignment.
-     */
-    AlignmentUtils.mapProteinToCdna(protein, cdna);
-
     try
     {
       newAlignFrame.setMaximum(jalview.bin.Cache.getDefault(
@@ -939,7 +941,9 @@ public class AlignViewport extends AlignmentViewport implements
           AlignmentI complement, Set<AlignedCodonFrame> mappings)
   {
     /*
-     * Open in split pane. DNA sequence above, protein below.
+     * Make a new frame with a copy of the alignment we are adding to. If this
+     * is protein, the new frame will have a cDNA consensus annotation row
+     * added.
      */
     AlignFrame copyMe = new AlignFrame(complement,
             AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
@@ -957,6 +961,10 @@ public class AlignViewport extends AlignmentViewport implements
     proteinFrame.setVisible(true);
     String linkedTitle = MessageManager
             .getString("label.linked_view_title");
+
+    /*
+     * Open in split pane. DNA sequence above, protein below.
+     */
     JInternalFrame splitFrame = new SplitFrame(cdnaFrame, proteinFrame);
     Desktop.addInternalFrame(splitFrame, linkedTitle, -1, -1);
 
index 381fbe3..2ffb166 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.gui;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.event.ActionEvent;
+import java.awt.geom.Rectangle2D;
 
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
@@ -44,6 +45,9 @@ public class FontChooser extends GFontChooser
 
   TreePanel tp;
 
+  /*
+   * The font on opening the dialog (to be restored on Cancel)
+   */
   Font oldFont;
 
   boolean oldProteinScale;
@@ -52,6 +56,13 @@ public class FontChooser extends GFontChooser
 
   JInternalFrame frame;
 
+  /*
+   * The last font settings selected in the dialog
+   */
+  private Font lastSelected = null;
+
+  private boolean lastSelMono = false;
+
   /**
    * Creates a new FontChooser object.
    * 
@@ -212,14 +223,6 @@ public class FontChooser extends GFontChooser
     }
   }
 
-  private Font lastSelected = null;
-
-  private int lastSelStyle = 0;
-
-  private int lastSelSize = 0;
-
-  private boolean lastSelMono = false;
-
   /**
    * DOCUMENT ME!
    */
@@ -229,35 +232,49 @@ public class FontChooser extends GFontChooser
     {
       // initialise with original font
       lastSelected = oldFont;
-      lastSelSize = oldFont.getSize();
-      lastSelStyle = oldFont.getStyle();
       FontMetrics fm = getGraphics().getFontMetrics(oldFont);
-      double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
-              .getStringBounds("I", getGraphics()).getWidth();
-      lastSelMono = mw == iw;
+      double mw = fm.getStringBounds("M", getGraphics()).getWidth();
+      double iw = fm.getStringBounds("I", getGraphics()).getWidth();
+      lastSelMono = (mw == iw); // == on double - flaky?
     }
 
     Font newFont = new Font(fontName.getSelectedItem().toString(),
             fontStyle.getSelectedIndex(),
             (Integer) fontSize.getSelectedItem());
     FontMetrics fm = getGraphics().getFontMetrics(newFont);
-    double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
-            .getStringBounds("I", getGraphics()).getWidth();
+    double mw = fm.getStringBounds("M", getGraphics()).getWidth();
+    final Rectangle2D iBounds = fm.getStringBounds("I", getGraphics());
+    double iw = iBounds.getWidth();
     if (mw < 1 || iw < 1)
     {
+      final String messageKey = iBounds.getHeight() < 1 ? "label.font_doesnt_have_letters_defined"
+              : "label.font_too_small";
       JOptionPane
               .showInternalMessageDialog(
                       this,
-                      MessageManager.getString("label.font_doesnt_have_letters_defined"),
+              MessageManager.getString(messageKey),
                       MessageManager.getString("label.invalid_font"), JOptionPane.WARNING_MESSAGE);
       /*
-       * Restore previous values - size first to avoid recursive calls to this
-       * point!
+       * Restore the changed value - note this will reinvoke this method via the
+       * ActionListener, but now validation should pass
        */
-      fontSize.setSelectedItem(lastSelSize);
-      fontName.setSelectedItem(lastSelected.getName());
-      fontStyle.setSelectedIndex(lastSelStyle);
-      monospaced.setSelected(lastSelMono);
+      if (lastSelected.getSize() != (Integer) fontSize.getSelectedItem()) // autoboxing
+      {
+        fontSize.setSelectedItem(lastSelected.getSize());
+      }
+      if (!lastSelected.getName().equals(
+              fontName.getSelectedItem().toString()))
+      {
+        fontName.setSelectedItem(lastSelected.getName());
+      }
+      if (lastSelected.getStyle() != fontStyle.getSelectedIndex())
+      {
+        fontStyle.setSelectedIndex(lastSelected.getStyle());
+      }
+      if (lastSelMono != monospaced.isSelected())
+      {
+        monospaced.setSelected(lastSelMono);
+      }
       return;
     }
     if (tp != null)
@@ -271,7 +288,11 @@ public class FontChooser extends GFontChooser
     }
 
     monospaced.setSelected(mw == iw);
-    // remember last selected
+
+    /*
+     * Remember latest valid selection, so it can be restored if followed by an
+     * invalid one
+     */
     lastSelected = newFont;
   }
 
index c5562c6..a907187 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.datamodel.SequenceGroup;
-import jalview.io.JalviewFileChooser;
-import jalview.jbgui.GUserDefinedColours;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
-import jalview.util.ColorUtils;
-import jalview.util.MessageManager;
-
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
@@ -50,6 +40,16 @@ import javax.swing.JOptionPane;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
+import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.datamodel.SequenceGroup;
+import jalview.io.JalviewFileChooser;
+import jalview.jbgui.GUserDefinedColours;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
+import jalview.util.MessageManager;
+
 /**
  * This panel allows the user to assign colours to Amino Acid residue codes, and
  * save the colour scheme.
@@ -454,26 +454,40 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void okButton_actionPerformed(ActionEvent e)
   {
-               //Check if the user have done any selection
-               boolean showWarning = (upperCaseButtons==null) ||
-                                       ((upperCaseButtons!=null) && (upperCaseButtons.size()==0)) ||
-                                       (lowerCaseButtons==null) ||
-                                       ((lowerCaseButtons!=null) && (lowerCaseButtons.size()==0));
-               if (showWarning){
-               JOptionPane.showMessageDialog(Desktop.desktop,
-                       MessageManager.getString("label.no_colour_selection_in_scheme"),MessageManager.getString("label.no_colour_selection_warn"),
-                       JOptionPane.WARNING_MESSAGE);
-                       
-               }else{
-                   applyButton_actionPerformed(null);
-               
-                   try
-                   {
-                     frame.setClosed(true);
-                   } catch (Exception ex)
-                   {
-                   }
-               }
+    if (isNoSelectionMade())
+    {
+      JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
+              .getString("label.no_colour_selection_in_scheme"),
+              MessageManager.getString("label.no_colour_selection_warn"),
+              JOptionPane.WARNING_MESSAGE);
+    }
+    else
+    {
+      applyButton_actionPerformed(null);
+
+      try
+      {
+        frame.setClosed(true);
+      } catch (Exception ex)
+      {
+      }
+    }
+  }
+
+  /**
+   * Returns true if the user has not made any colour selection (including if
+   * 'case-sensitive' selected and no lower-case colour chosen).
+   * 
+   * @return
+   */
+  protected boolean isNoSelectionMade()
+  {
+    final boolean noUpperCaseSelected = upperCaseButtons == null
+            || upperCaseButtons.isEmpty();
+    final boolean noLowerCaseSelected = caseSensitive.isSelected()
+            && (lowerCaseButtons == null || lowerCaseButtons.isEmpty());
+    final boolean noSelectionMade = noUpperCaseSelected || noLowerCaseSelected;
+    return noSelectionMade;
   }
 
   /**
@@ -485,12 +499,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void applyButton_actionPerformed(ActionEvent e)
   {
-       //Check if the user have done any selection
-       boolean showWarning = (upperCaseButtons==null) ||
-                               ((upperCaseButtons!=null) && (upperCaseButtons.size()==0)) ||
-                               (lowerCaseButtons==null) ||
-                               ((lowerCaseButtons!=null) && (lowerCaseButtons.size()==0));
-       if (showWarning){
+    if (isNoSelectionMade())
+    {
         JOptionPane.showMessageDialog(Desktop.desktop,
                 MessageManager.getString("label.no_colour_selection_in_scheme"),MessageManager.getString("label.no_colour_selection_warn"),
                 JOptionPane.WARNING_MESSAGE);
@@ -700,7 +710,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
         name = jucs.getColour(i).getName();
         if (ResidueProperties.aa3Hash.containsKey(name))
         {
-          index = ((Integer) ResidueProperties.aa3Hash.get(name))
+          index = ResidueProperties.aa3Hash.get(name)
                   .intValue();
         }
         else
index a377571..bcd5f64 100644 (file)
@@ -45,7 +45,8 @@ public class GSplitFrame extends JInternalFrame
     splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topFrame,
             bottomFrame);
     splitPane.setVisible(true);
-    final double ratio = topFrame.getHeight()
+    final double ratio = bottomFrame.getHeight() == 0 ? 0.5d : topFrame
+            .getHeight()
             / (double) (topFrame.getHeight() + bottomFrame.getHeight());
     splitPane.setDividerLocation(ratio);
     splitPane.setResizeWeight(ratio);
index 4aed258..df21355 100644 (file)
@@ -413,18 +413,18 @@ public final class MappingUtils
     SequenceI[] sortOrder = command.getSequenceOrder(undo);
     List<SequenceI> mappedOrder = new ArrayList<SequenceI>();
     int j = 0;
+
+    /*
+     * Assumption: we are only interested in a cDNA/protein mapping; refactor in
+     * future if we want to support sorting (c)dna as (c)dna or protein as
+     * protein
+     */
+    boolean mappingToNucleotide = mapTo.isNucleotide();
     for (SequenceI seq : sortOrder)
     {
       for (AlignedCodonFrame acf : mappings)
       {
-        /*
-         * Try protein-to-Dna, failing that try dna-to-protein
-         */
-        SequenceI mappedSeq = acf.getDnaForAaSeq(seq);
-        if (mappedSeq == null)
-        {
-          mappedSeq = acf.getAaForDnaSeq(seq);
-        }
+        SequenceI mappedSeq = mappingToNucleotide ? acf.getDnaForAaSeq(seq) : acf.getAaForDnaSeq(seq);
         if (mappedSeq != null)
         {
           for (SequenceI seq2 : mapTo.getSequences())
index d724fac..338a48f 100644 (file)
@@ -20,10 +20,11 @@ public class FontChooserTest
   {
     String[] fonts = java.awt.GraphicsEnvironment
             .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+    final Canvas canvas = new Canvas();
     for (int pointSize = 1;; pointSize++)
     {
       System.out.println(System.lineSeparator()
-              + "Fonts with insufficient width at " + pointSize + "pt:");
+              + "Plain fonts with sub-pixel width at " + pointSize + "pt:");
       if (pointSize == 1)
       {
         System.out.println("All except:");
@@ -32,7 +33,7 @@ public class FontChooserTest
       for (String fontname : fonts)
       {
         Font newFont = new Font(fontname, Font.PLAIN, pointSize);
-        FontMetrics fontm = new Canvas().getFontMetrics(newFont);
+        FontMetrics fontm = canvas.getFontMetrics(newFont);
         double iw = fontm.getStringBounds("I", null).getWidth();
         final boolean tooSmall = iw < 1d;
         if (tooSmall)