JAL-2435 mirror font changes with middle mouse drag
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 19 Apr 2017 15:16:36 +0000 (16:16 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 19 Apr 2017 15:16:36 +0000 (16:16 +0100)
src/jalview/appletgui/FontChooser.java
src/jalview/gui/FontChooser.java
src/jalview/gui/SeqPanel.java

index 96dfc20..991fb96 100644 (file)
@@ -125,8 +125,9 @@ public class FontChooser extends Panel implements ItemListener
   {
     this.ap = ap;
     oldFont = ap.av.getFont();
-    oldCharWidth = ap.av.getViewStyle().getCharWidth();
-    oldScaleProtein = ap.av.getViewStyle().isScaleProteinAsCdna();
+    oldCharWidth = ap.av.getCharWidth();
+    oldScaleProtein = ap.av.isScaleProteinAsCdna();
+    oldMirrorFont = ap.av.isProteinFontAsCdna();
 
     try
     {
index 547f528..ec4ab49 100755 (executable)
@@ -226,6 +226,10 @@ public class FontChooser extends GFontChooser
         ap.av.getCodingComplement().setScaleProteinAsCdna(oldProteinScale);
         ap.av.getCodingComplement().setProteinFontAsCdna(oldMirrorFont);
         ap.av.getCodingComplement().setFont(oldComplementFont, true);
+        SplitFrame splitFrame = (SplitFrame) ap.alignFrame
+                .getSplitViewContainer();
+        splitFrame.adjustLayout();
+        splitFrame.repaint();
       }
     }
     else if (tp != null)
@@ -322,6 +326,7 @@ public class FontChooser extends GFontChooser
          */
         SplitFrame splitFrame = (SplitFrame) ap.alignFrame
                 .getSplitViewContainer();
+        splitFrame.adjustLayout();
         splitFrame.repaint();
       }
     }
index db7aa36..fd3ca76 100644 (file)
@@ -944,30 +944,36 @@ public class SeqPanel extends JPanel implements MouseListener,
   }
 
   /**
-   * DOCUMENT ME!
-   * 
-   * @param evt
-   *          DOCUMENT ME!
+   * {@inheritDoc}
    */
   @Override
   public void mouseDragged(MouseEvent evt)
   {
     if (mouseWheelPressed)
     {
+      boolean inSplitFrame = ap.av.getCodingComplement() != null;
+      boolean copyChanges = inSplitFrame && av.isProteinFontAsCdna();
+
       int oldWidth = av.getCharWidth();
 
       // Which is bigger, left-right or up-down?
       if (Math.abs(evt.getY() - lastMousePress.getY()) > Math.abs(evt
               .getX() - lastMousePress.getX()))
       {
+        /*
+         * on drag up or down, decrement or increment font size
+         */
         int fontSize = av.font.getSize();
+        boolean fontChanged = false;
 
         if (evt.getY() < lastMousePress.getY())
         {
+          fontChanged = true;
           fontSize--;
         }
         else if (evt.getY() > lastMousePress.getY())
         {
+          fontChanged = true;
           fontSize++;
         }
 
@@ -976,24 +982,56 @@ public class SeqPanel extends JPanel implements MouseListener,
           fontSize = 1;
         }
 
-        av.setFont(
-                new Font(av.font.getName(), av.font.getStyle(), fontSize),
-                true);
-        av.setCharWidth(oldWidth);
-        ap.fontChanged();
+        if (fontChanged)
+        {
+          Font newFont = new Font(av.font.getName(), av.font.getStyle(),
+                  fontSize);
+          av.setFont(newFont, true);
+          av.setCharWidth(oldWidth);
+          ap.fontChanged();
+          if (copyChanges)
+          {
+            ap.av.getCodingComplement().setFont(newFont, true);
+            SplitFrame splitFrame = (SplitFrame) ap.alignFrame
+                    .getSplitViewContainer();
+            splitFrame.adjustLayout();
+            splitFrame.repaint();
+          }
+        }
       }
       else
       {
+        /*
+         * on drag left or right, decrement or increment character width
+         */
+        int newWidth = 0;
         if (evt.getX() < lastMousePress.getX() && av.getCharWidth() > 1)
         {
-          av.setCharWidth(av.getCharWidth() - 1);
+          newWidth = av.getCharWidth() - 1;
+          av.setCharWidth(newWidth);
         }
         else if (evt.getX() > lastMousePress.getX())
         {
-          av.setCharWidth(av.getCharWidth() + 1);
+          newWidth = av.getCharWidth() + 1;
+          av.setCharWidth(newWidth);
+        }
+        if (newWidth > 0)
+        {
+          ap.paintAlignment(false);
+          if (copyChanges)
+          {
+            /*
+             * need to ensure newWidth is set on cdna, regardless of which
+             * panel the mouse drag happened in; protein will compute its 
+             * character width as 1:1 or 3:1
+             */
+            av.getCodingComplement().setCharWidth(newWidth);
+            SplitFrame splitFrame = (SplitFrame) ap.alignFrame
+                    .getSplitViewContainer();
+            splitFrame.adjustLayout();
+            splitFrame.repaint();
+          }
         }
-
-        ap.paintAlignment(false);
       }
 
       FontMetrics fm = getFontMetrics(av.getFont());