From ade62c16010f34db45fe7d53026ad2cc393c5755 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 11 Feb 2015 09:06:22 +0000 Subject: [PATCH] JAL-1654 allow font to be specified without modifying column width --- src/jalview/gui/AlignViewport.java | 16 +++++++++++----- src/jalview/gui/FontChooser.java | 20 ++++++++++++-------- src/jalview/gui/Jalview2XML.java | 7 ++++--- src/jalview/gui/Jalview2XML_V1.java | 5 +++-- src/jalview/gui/SeqPanel.java | 4 +++- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index c4ac828..feeb694 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -275,7 +275,7 @@ public class AlignViewport extends AlignmentViewport implements style = 2; } - setFont(new Font(fontName, style, Integer.parseInt(fontSize))); + setFont(new Font(fontName, style, Integer.parseInt(fontSize)), true); alignment .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0)); @@ -468,8 +468,11 @@ public class AlignViewport extends AlignmentViewport implements /** * update view settings with the given font. You may need to call * alignPanel.fontChanged to update the layout geometry + * + * @param setGrid + * when true, charWidth/height is set according to font mentrics */ - public void setFont(Font f) + public void setFont(Font f, boolean setGrid) { font = f; @@ -478,8 +481,11 @@ public class AlignViewport extends AlignmentViewport implements java.awt.FontMetrics fm = c.getFontMetrics(font); int w = viewStyle.getCharWidth(), ww = fm.charWidth('M'), h = viewStyle .getCharHeight(); - setCharHeight(fm.getHeight()); - setCharWidth(ww); + if (setGrid) + { + setCharHeight(fm.getHeight()); + setCharWidth(ww); + } viewStyle.setFontName(font.getName()); viewStyle.setFontStyle(font.getStyle()); viewStyle.setFontSize(font.getSize()); @@ -492,7 +498,7 @@ public class AlignViewport extends AlignmentViewport implements { super.setViewStyle(settingsForView); setFont(new Font(viewStyle.getFontName(), viewStyle.getFontStyle(), - viewStyle.getFontSize())); + viewStyle.getFontSize()), false); } /** diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index 36e4c52..7738e96 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -20,14 +20,18 @@ */ package jalview.gui; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -import jalview.bin.*; -import jalview.jbgui.*; +import jalview.bin.Cache; +import jalview.jbgui.GFontChooser; import jalview.util.MessageManager; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.event.ActionEvent; + +import javax.swing.JInternalFrame; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; + /** * DOCUMENT ME! * @@ -167,7 +171,7 @@ public class FontChooser extends GFontChooser { if (ap != null) { - ap.av.setFont(oldFont); + ap.av.setFont(oldFont, true); ap.paintAlignment(true); } else if (tp != null) @@ -236,7 +240,7 @@ public class FontChooser extends GFontChooser } else if (ap != null) { - ap.av.setFont(newFont); + ap.av.setFont(newFont, true); ap.fontChanged(); } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 7bac591..6186323 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -3664,10 +3664,11 @@ public class Jalview2XML af.viewport.setConservationSelected(view.getConservationSelected()); af.viewport.setShowJVSuffix(view.getShowFullId()); af.viewport.setRightAlignIds(view.getRightAlignIds()); - af.viewport.setFont(new java.awt.Font(view.getFontName(), view - .getFontStyle(), view.getFontSize())); + af.viewport.setFont( + new java.awt.Font(view.getFontName(), view.getFontStyle(), view + .getFontSize()), true); // TODO: allow custom charWidth/Heights to be restored by updating them - // after setting font + // after setting font - which means set above to false af.viewport.setRenderGaps(view.getRenderGaps()); af.viewport.setWrapAlignment(view.getWrapAlignment()); af.viewport.setShowAnnotation(view.getShowAnnotation()); diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index e30497d..0d73020 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -371,8 +371,9 @@ public class Jalview2XML_V1 af.viewport.setColourText(view.getShowColourText()); af.viewport.setConservationSelected(view.getConservationSelected()); af.viewport.setShowJVSuffix(view.getShowFullId()); - af.viewport.setFont(new java.awt.Font(view.getFontName(), view - .getFontStyle(), view.getFontSize())); + af.viewport.setFont( + new java.awt.Font(view.getFontName(), view.getFontStyle(), view + .getFontSize()), true); af.viewport.setRenderGaps(view.getRenderGaps()); af.viewport.setWrapAlignment(view.getWrapAlignment()); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index bd8bb7c..a7e4057 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -867,7 +867,9 @@ public class SeqPanel extends JPanel implements MouseListener, fontSize = 1; } - av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize)); + av.setFont( + new Font(av.font.getName(), av.font.getStyle(), fontSize), + true); av.setCharWidth(oldWidth); ap.fontChanged(); } -- 1.7.10.2