Merge branch 'Release_2_8_1_Branch' into Release_2_8_1_Branch_i18n
authorJim Procter <jprocter@dundee.ac.uk>
Sat, 5 Apr 2014 12:24:40 +0000 (13:24 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Sat, 5 Apr 2014 12:24:40 +0000 (13:24 +0100)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignmentPanel.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/Desktop.java

index d4922b0..5e6df04 100644 (file)
@@ -122,7 +122,28 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       ex.printStackTrace();
     }
-
+    // need to get window geometry before we calculate alignment layout
+    if (applet != null)
+    {
+      String param;
+      try
+      {
+        param = applet.getParameter("windowWidth");
+        if (param != null)
+        {
+          int width = Integer.parseInt(param);
+          DEFAULT_WIDTH = width;
+        }
+        param = applet.getParameter("windowHeight");
+        if (param != null)
+        {
+          int height = Integer.parseInt(param);
+          DEFAULT_HEIGHT = height;
+        }
+      } catch (Exception ex)
+      {
+      }
+    }
     viewport = new AlignViewport(al, applet);
     alignPanel = new AlignmentPanel(this, viewport);
     avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
@@ -174,23 +195,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         centreColumnLabelFlag.setState(true);
         centreColumnLabelFlag_stateChanged();
       }
-      try
-      {
-        param = applet.getParameter("windowWidth");
-        if (param != null)
-        {
-          int width = Integer.parseInt(param);
-          DEFAULT_WIDTH = width;
-        }
-        param = applet.getParameter("windowHeight");
-        if (param != null)
-        {
-          int height = Integer.parseInt(param);
-          DEFAULT_HEIGHT = height;
-        }
-      } catch (Exception ex)
-      {
-      }
 
     }
     if (viewport.getAlignment().isNucleotide())
index b34a5bb..5a49281 100644 (file)
@@ -84,7 +84,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER);
 
     sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH);
-
     alabels = new AnnotationLabels(this);
 
     setAnnotationVisible(av.showAnnotation);
@@ -138,7 +137,6 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
         }
       }
     });
-
   }
 
   public SequenceRenderer getSequenceRenderer()
@@ -480,12 +478,27 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
     int mheight = height;
     Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize();
     int seqandannot = d.height - scalePanelHolder.getSize().height;
-    // sets initial preferred height
-    if ((height + 40) > seqandannot / 2)
+
+    if (adjustPanelHeight)
     {
-      height = seqandannot / 2;
+      // NOTE: this logic is different in the application. Need a better algorithm to define behaviour
+      // sets initial preferred height
+      // try and set height according to alignment
+      float sscaling = (float) ((av.getCharHeight() * av.getAlignment().getHeight())/(1.0*mheight));
+      if (sscaling > 0.5)
+      {
+        // if the alignment is too big then
+        // default is 0.5 split
+        height = seqandannot / 2;
+      }
+      else
+      {
+        // otherwise just set the panel so that one row of sequence is visible 
+        height = -av.getCharHeight() * 1
+                + (int) (seqandannot * (1 - sscaling));
+      }
     }
-    if (!adjustPanelHeight)
+    else
     {
       // maintain same window layout whilst updating sliders
       height = annotationPanelHolder.getSize().height;
index 541c7c2..6bfe4bd 100644 (file)
@@ -422,16 +422,30 @@ public class AlignmentPanel extends GAlignmentPanel implements
   protected void validateAnnotationDimensions(boolean adjustPanelHeight)
   {
     int height = annotationPanel.adjustPanelHeight();
-
-    if (hscroll.isVisible())
-    {
-      height += hscroll.getPreferredSize().height;
-    }
-    if (height > alignFrame.getHeight() / 2)
-    {
-      height = alignFrame.getHeight() / 2;
+    
+    int theight = av.getCharHeight() * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0 : av.getAlignment().getHiddenSequences().getSize()));
+    float sscaling = (float) (theight/(1.0*theight+height));
+    float ascaling=(float)(height*1.0/alignFrame.getHeight());
+    int rheight = alignFrame.getHeight() - height - av.getCharHeight();
+    if (adjustPanelHeight)
+    {
+      // NOTE: this logic is different in the applet. Need a better algorithm to define behaviour
+      // try and set height according to alignment
+      if (ascaling>0 && sscaling < 0.5)
+      {
+        // if the alignment is too big then
+        // default is 0.5 split
+        height = alignFrame.getHeight() / 2;
+      }
+      else
+      {
+        // if space for more than one sequence row left when annotation is fully displayed then set height to annotation height
+        // otherwise, leave at least two lines of sequence shown.  
+        height = (rheight>av.getCharHeight()) ? height : (-av.getCharHeight() * 3
+                + (int) (alignFrame.getHeight() * (1 - sscaling)));
+      }
     }
-    if (!adjustPanelHeight)
+    else
     {
       // maintain same window layout whilst updating sliders
       height = annotationScroller.getSize().height;
index 6715537..d54c887 100644 (file)
@@ -807,6 +807,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
    */
   public void drop(DropTargetDropEvent evt)
   {
+    boolean success=true;
     Transferable t = evt.getTransferable();
     java.util.List files = null;
     java.util.List protocols = null;
@@ -855,6 +856,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       }
     } catch (Exception e)
     {
+      success=false;
     }
 
     if (files != null)
@@ -883,8 +885,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         }
       } catch (Exception ex)
       {
+        success=false;
       }
     }
+    evt.dropComplete(success); // need this to ensure input focus is properly transfered to any new windows created 
   }
 
   /**
@@ -914,7 +918,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
               .getSelectedFile().getParent());
 
       String format = null;
-      if (chooser.getSelectedFormat().equals("Jalview"))
+      if (chooser.getSelectedFormat()!=null && chooser.getSelectedFormat().equals("Jalview"))
       {
         format = "Jalview";
       }