From a2a41986667a3d2f611b4e7c8432d9cdd05527a6 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 17 Mar 2005 10:38:38 +0000 Subject: [PATCH] idwidth is calculated in this panel, not idcanvas --- src/jalview/gui/AlignmentPanel.java | 66 ++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index da68ab9..ca17c20 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -12,6 +12,8 @@ import com.sun.image.codec.jpeg.*; import java.io.*; import java.awt.image.*; +import gnu.jpdf.*; + public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable { @@ -31,30 +33,19 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene this.av = av; seqPanel = new SeqPanel (av, this); idPanel = new IdPanel (av, this); + scalePanel = new ScalePanel(av, this); scorePanel = new ScorePanel(av); ssPanel = new SecondaryStructurePanel(av); secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER); - idPanelHolder.add(idPanel, BorderLayout.CENTER); - idPanel.addNotify(); - javax.swing.JFrame f = new javax.swing.JFrame(); - f.addNotify(); - FontMetrics fm = f.getGraphics().getFontMetrics(av.font); - AlignmentI al = av.getAlignment(); + idPanelHolder.add(idPanel, BorderLayout.CENTER); + IdwidthAdjuster iap = new IdwidthAdjuster(this); + idSpaceFillerPanel1.add(iap, BorderLayout.CENTER); - int i = 0; - int idWidth = 0; - while (i < al.getHeight() && al.getSequenceAt(i) != null) - { - SequenceI s = al.getSequenceAt(i); - String str = s.getDisplayId(); - if (fm.stringWidth(str) > idWidth) - idWidth = fm.stringWidth(str); - i++; - } - hscrollFillerPanel.setPreferredSize(new Dimension(idWidth, 12)); + idPanel.idCanvas.setPreferredSize(calculateIdWidth()); + hscrollFillerPanel.setPreferredSize(calculateIdWidth()); scalePanelHolder.add(scalePanel, BorderLayout.CENTER); scorePanelHolder.add(scorePanel, BorderLayout.CENTER); @@ -113,6 +104,38 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene }); } + Dimension calculateIdWidth() + { + Graphics g = this.getGraphics(); + if(g==null) + { + javax.swing.JFrame f = new javax.swing.JFrame(); + f.addNotify(); + g = f.getGraphics(); + } + + FontMetrics fm = g.getFontMetrics(av.font); + 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); + if(av.getShowFullId()) + id = s.getDisplayId(); + else + id = s.getName(); + + if (fm.stringWidth(id) > idWidth) + idWidth = fm.stringWidth(id); + i++; + } + + return new Dimension(idWidth, 12); + } + public void highlightSearchResults(int [] results) { @@ -164,8 +187,8 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene hscroll.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); - idSpaceFillerPanel1.setVisible(!wrap); + // idSpaceFillerPanel.setVisible(!wrap); + // idWidthAdjusterPanel.setVisible(!wrap); RefreshPanels(); @@ -340,7 +363,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth(); + int idWidth = calculateIdWidth().width; pg.setColor(Color.white); @@ -418,7 +441,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException { - int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth(); + int idWidth = calculateIdWidth().width; if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth) pwidth = seqPanel.seqCanvas.getWidth() + idWidth; @@ -518,3 +541,4 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene + -- 1.7.10.2