From: Jim Procter Date: Tue, 7 Apr 2020 11:48:59 +0000 (+0100) Subject: Merge branch 'bug/JAL-247autoIdWidthSeqMarker' into develop X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=610c3b982af35c03ca23cb8592a5519f478157cc;hp=-c;p=jalview.git Merge branch 'bug/JAL-247autoIdWidthSeqMarker' into develop --- 610c3b982af35c03ca23cb8592a5519f478157cc diff --combined src/jalview/gui/AlignmentPanel.java index dfe0ffa,87a771d..8191e05 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@@ -73,11 -73,6 +73,11 @@@ import javax.swing.SwingUtilities public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable, AlignmentViewPanel, ViewportListenerI { + /* + * spare space in pixels between sequence id and alignment panel + */ + private static final int ID_WIDTH_PADDING = 4; + public AlignViewport av; OverviewPanel overviewPanel; @@@ -238,6 -233,8 +238,6 @@@ getAnnotationPanel().adjustPanelHeight(); Dimension d = calculateIdWidth(); - - d.setSize(d.width + 4, d.height); getIdPanel().getIdCanvas().setPreferredSize(d); hscrollFillerPanel.setPreferredSize(d); @@@ -245,24 -242,20 +245,24 @@@ } /** - * Calculate the width of the alignment labels based on the displayed names - * and any bounds on label width set in preferences. + * Calculates the width of the alignment labels based on the displayed names + * and any bounds on label width set in preferences. The calculated width is + * also set as a property of the viewport. * * @return Dimension giving the maximum width of the alignment label panel * that should be used. */ public Dimension calculateIdWidth() { + int oldWidth = av.getIdWidth(); + // calculate sensible default width when no preference is available Dimension r = null; if (av.getIdWidth() < 0) { int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300); - int maxwidth = Math.max(20, Math.min(afwidth - 200, 2 * afwidth / 3)); + int idWidth = Math.min(afwidth - 200, 2 * afwidth / 3); + int maxwidth = Math.max(IdwidthAdjuster.MIN_ID_WIDTH, idWidth); r = calculateIdWidth(maxwidth); av.setIdWidth(r.width); } @@@ -272,16 -265,6 +272,16 @@@ r.width = av.getIdWidth(); r.height = 0; } + + /* + * fudge: if desired width has changed, update layout + * (see also paintComponent - updates layout on a repaint) + */ + if (r.width != oldWidth) + { + idPanelHolder.setPreferredSize(r); + validate(); + } return r; } @@@ -294,7 -277,7 +294,7 @@@ * @return Dimension giving the maximum width of the alignment label panel * that should be used. */ - public Dimension calculateIdWidth(int maxwidth) + protected Dimension calculateIdWidth(int maxwidth) { Container c = new Container(); @@@ -304,13 -287,19 +304,13 @@@ AlignmentI al = av.getAlignment(); int i = 0; int idWidth = 0; - String id; while ((i < al.getHeight()) && (al.getSequenceAt(i) != null)) { SequenceI s = al.getSequenceAt(i); - - id = s.getDisplayId(av.getShowJVSuffix()); - - if (fm.stringWidth(id) > idWidth) - { - idWidth = fm.stringWidth(id); - } - + String id = s.getDisplayId(av.getShowJVSuffix()); + int stringWidth = fm.stringWidth(id); + idWidth = Math.max(idWidth, stringWidth); i++; } @@@ -324,16 -313,18 +324,16 @@@ while (i < al.getAlignmentAnnotation().length) { String label = al.getAlignmentAnnotation()[i].label; - - if (fm.stringWidth(label) > idWidth) - { - idWidth = fm.stringWidth(label); - } - + int stringWidth = fm.stringWidth(label); + idWidth = Math.max(idWidth, stringWidth); i++; } } - return new Dimension( - maxwidth < 0 ? idWidth : Math.min(maxwidth, idWidth), 12); + int w = maxwidth < 0 ? idWidth : Math.min(maxwidth, idWidth); + w += ID_WIDTH_PADDING; + + return new Dimension(w, 12); } /** @@@ -833,6 -824,12 +833,6 @@@ } } - /** - * DOCUMENT ME! - * - * @param g - * DOCUMENT ME! - */ @Override public void paintComponent(Graphics g) { @@@ -997,7 -994,7 +997,7 @@@ List selection = av.getSelectionGroup() == null ? null : av.getSelectionGroup().getSequences(null); idCanvas.drawIds((Graphics2D) idGraphics, av, startSeq, endSeq - 1, - selection); + selection, idWidth); idGraphics.setFont(av.getFont()); idGraphics.translate(0, -scaleHeight); @@@ -1072,7 -1069,7 +1072,7 @@@ int cHeight = av.getAlignment().getHeight() * av.getCharHeight() + hgap + annotationHeight; - int idWidth = getVisibleIdWidth(false); + final int idWidth = getVisibleIdWidth(false); int maxwidth = av.getAlignment().getVisibleWidth(); @@@ -1101,7 -1098,7 +1101,7 @@@ * draw sequence ids and annotation labels (if shown) */ IdCanvas idCanvas = getIdPanel().getIdCanvas(); - idCanvas.drawIdsWrapped((Graphics2D) g, av, 0, totalHeight); + idCanvas.drawIdsWrapped((Graphics2D) g, av, 0, totalHeight, idWidth); g.translate(idWidth, 0); @@@ -1138,22 -1135,21 +1138,22 @@@ * be returned * @return */ - public int getVisibleIdWidth(boolean onscreen) + protected int getVisibleIdWidth(boolean onscreen) { // see if rendering offscreen - check preferences and calc width accordingly if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false)) { - return calculateIdWidth(-1).width + 4; + return calculateIdWidth(-1).width; } - Integer idwidth = null; - if (onscreen || (idwidth = Cache - .getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null) + Integer idwidth = onscreen ? null + : Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH"); + if (idwidth != null) { - int w = getIdPanel().getWidth(); - return (w > 0 ? w : calculateIdWidth().width + 4); + return idwidth.intValue() + ID_WIDTH_PADDING; } - return idwidth.intValue() + 4; + + int w = getIdPanel().getWidth(); + return (w > 0 ? w : calculateIdWidth().width); } void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file) diff --combined src/jalview/gui/IdCanvas.java index a925227,b408c1b..35a932d --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@@ -20,6 -20,10 +20,6 @@@ */ package jalview.gui; -import jalview.datamodel.SequenceI; -import jalview.viewmodel.ViewportListenerI; -import jalview.viewmodel.ViewportRanges; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; @@@ -33,10 -37,6 +33,10 @@@ import java.util.List import javax.swing.JPanel; +import jalview.datamodel.SequenceI; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; + /** * DOCUMENT ME! * @@@ -85,20 -85,21 +85,21 @@@ public class IdCanvas extends JPanel im * DOCUMENT ME! * * @param g - * DOCUMENT ME! + * DOCUMENT ME! * @param hiddenRows - * true - check and display hidden row marker if need be + * true - check and display hidden row marker if need be * @param s - * DOCUMENT ME! + * DOCUMENT ME! * @param i - * DOCUMENT ME! + * DOCUMENT ME! * @param starty - * DOCUMENT ME! + * DOCUMENT ME! * @param ypos - * DOCUMENT ME! + * DOCUMENT ME! + * @param idWidth */ public void drawIdString(Graphics2D g, boolean hiddenRows, SequenceI s, - int i, int starty, int ypos) + int i, int starty, int ypos, int idWidth) { int xPos = 0; int panelWidth = getWidth(); @@@ -137,9 -138,9 +138,9 @@@ g.drawString(s.getDisplayId(av.getShowJVSuffix()), xPos, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5)); - if (hiddenRows) + if (hiddenRows && av.getShowHiddenMarkers()) { - drawMarker(g, av, i, starty, ypos); + drawMarker(g, av, i, starty, ypos, idWidth); } } @@@ -196,7 -197,7 +197,7 @@@ gg.translate(0, transY); - drawIds(gg, av, ss, es, searchResults); + drawIds(gg, av, ss, es, searchResults, getWidth()); gg.translate(0, -transY); @@@ -252,7 -253,7 +253,7 @@@ gg.setColor(Color.white); gg.fillRect(0, 0, getWidth(), imgHeight); - drawIds(gg, av, av.getRanges().getStartSeq(), av.getRanges().getEndSeq(), searchResults); + drawIds(gg, av, av.getRanges().getStartSeq(), av.getRanges().getEndSeq(), searchResults, getWidth()); g.drawImage(image, 0, 0, this); } @@@ -260,17 -261,18 +261,18 @@@ /** * Draws sequence ids from sequence index startSeq to endSeq (inclusive), with * the font and other display settings configured on the viewport. Ids of - * sequences included in the selection are coloured grey, otherwise the - * current id colour for the sequence id is used. + * sequences included in the selection are coloured grey, otherwise the current + * id colour for the sequence id is used. * * @param g * @param alignViewport * @param startSeq * @param endSeq * @param selection + * @param idWidth */ void drawIds(Graphics2D g, AlignViewport alignViewport, final int startSeq, - final int endSeq, List selection) + final int endSeq, List selection, int idWidth) { Font font = alignViewport.getFont(); if (alignViewport.isSeqNameItalics()) @@@ -299,7 -301,7 +301,7 @@@ if (alignViewport.getWrapAlignment()) { - drawIdsWrapped(g, alignViewport, startSeq, getHeight()); + drawIdsWrapped(g, alignViewport, startSeq, getHeight(), getWidth()); return; } @@@ -359,9 -361,9 +361,9 @@@ g.drawString(string, xPos, (((i - startSeq) * charHeight) + charHeight) - (charHeight / 5)); - if (hasHiddenRows) + if (hasHiddenRows && av.getShowHiddenMarkers()) { - drawMarker(g, alignViewport, i, startSeq, 0); + drawMarker(g, alignViewport, i, startSeq, 0, idWidth); } } } @@@ -373,9 -375,10 +375,10 @@@ * @param g * @param alignViewport * @param startSeq + * @param idWidth */ void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, - int startSeq, int pageHeight) + int startSeq, int pageHeight, int idWidth) { int alignmentWidth = alignViewport.getAlignment().getWidth(); final int alheight = alignViewport.getAlignment().getHeight(); @@@ -418,7 -421,7 +421,7 @@@ { g.setFont(getIdfont()); } - drawIdString(g, hasHiddenRows, s, i, 0, ypos); + drawIdString(g, hasHiddenRows, s, i, 0, ypos, idWidth); } if (labels != null && alignViewport.isShowAnnotation()) @@@ -434,16 -437,17 +437,17 @@@ } /** - * Draws a marker (a blue right-pointing triangle) between sequences to - * indicate hidden sequences. + * Draws a marker (a blue right-pointing triangle) between sequences to indicate + * hidden sequences. * * @param g * @param alignViewport * @param seqIndex * @param starty * @param yoffset + * @param idWidth */ - void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, int starty, int yoffset) + void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, int starty, int yoffset, int idWidth) { SequenceI[] hseqs = alignViewport.getAlignment() .getHiddenSequences().hiddenSequences; @@@ -486,9 -490,8 +490,8 @@@ /* * vertices of the triangle, below or above hidden seqs */ - int[] xPoints = new int[] - { getWidth() - charHeight, - getWidth() - charHeight, getWidth() }; + int[] xPoints = new int[] { idWidth - charHeight, idWidth - charHeight, + idWidth }; int yShift = seqIndex - starty; if (below)