From f9e86edb330898f638ab3713b9534e9b6364a3d4 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 19 Apr 2017 16:16:36 +0100 Subject: [PATCH] JAL-2435 mirror font changes with middle mouse drag --- src/jalview/appletgui/FontChooser.java | 5 ++- src/jalview/gui/FontChooser.java | 5 +++ src/jalview/gui/SeqPanel.java | 64 +++++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/jalview/appletgui/FontChooser.java b/src/jalview/appletgui/FontChooser.java index 96dfc20..991fb96 100644 --- a/src/jalview/appletgui/FontChooser.java +++ b/src/jalview/appletgui/FontChooser.java @@ -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 { diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index 547f528..ec4ab49 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -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(); } } diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index db7aa36..fd3ca76 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -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()); -- 1.7.10.2