X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=4d10db02945a1d3fab89c62585de0e8a34ab4c7f;hb=8ecde76adb5ba58ed98ee23b94c75b69f7877bb1;hp=1a8e79fb6175eab09b01de632fea18b0931e1aef;hpb=d53294db69b6bb2fe39415b28abb98092234ce67;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 1a8e79f..4d10db0 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -22,6 +22,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; @@ -55,7 +56,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI BufferedImage image; -// Graphics2D gg; + // Graphics2D gg; int imgHeight = 0; @@ -79,7 +80,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI this.av = av; PaintRefresher.Register(this, av.getSequenceSetId()); av.getRanges().addPropertyChangeListener(this); - } + } /** * DOCUMENT ME! @@ -198,12 +199,12 @@ public class IdCanvas extends JPanel implements ViewportListenerI gg.translate(0, transY); - drawIds(gg, av, ss, es, searchResults); + drawIds(gg, av, ss, es, searchResults, true, getWidth()); gg.translate(0, -transY); gg.dispose(); - + fastPaint = true; // Call repaint on alignment panel so that repaints from other alignment @@ -223,41 +224,42 @@ public class IdCanvas extends JPanel implements ViewportListenerI { g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); - + if (fastPaint) { fastPaint = false; g.drawImage(image, 0, 0, this); - + return; } - + int oldHeight = imgHeight; - + imgHeight = getHeight(); imgHeight -= (imgHeight % av.getCharHeight()); - + if (imgHeight < 1) { return; } - + if (oldHeight != imgHeight || image.getWidth(this) != getWidth()) { - image = new BufferedImage(getWidth(), imgHeight, - BufferedImage.TYPE_INT_RGB); + image = new BufferedImage(getWidth(), imgHeight, + BufferedImage.TYPE_INT_RGB); } - + Graphics2D gg = image.createGraphics(); - + // Fill in the background 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,true, getWidth()); gg.dispose(); - + g.drawImage(image, 0, 0, this); } @@ -272,15 +274,17 @@ public class IdCanvas extends JPanel implements ViewportListenerI * @param startSeq * @param endSeq * @param selection + * @param forGUI when false rendering for print + * @param panelWidth width used to calculate righthand margin - usually idCanvas.getWidth() + * */ - void drawIds(Graphics2D g, AlignViewport alignViewport, final int startSeq, - final int endSeq, List selection) + void drawIds(Graphics2D g, AlignViewport alignViewport, + final int startSeq, final int endSeq, List selection, boolean forGUI, int panelWidth) { Font font = alignViewport.getFont(); if (alignViewport.isSeqNameItalics()) { - setIdfont(new Font(font.getName(), Font.ITALIC, - font.getSize())); + setIdfont(new Font(font.getName(), Font.ITALIC, font.getSize())); } else { @@ -303,12 +307,11 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (alignViewport.getWrapAlignment()) { - drawIdsWrapped(g, alignViewport, startSeq, getHeight()); + drawIdsWrapped(g, alignViewport, startSeq, getHeight(), panelWidth,forGUI); return; } // Now draw the id strings - int panelWidth = getWidth(); int xPos = 0; // Now draw the id strings @@ -348,8 +351,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI g.setColor(currentColor); int charHeight = alignViewport.getCharHeight(); - g.fillRect(0, (i - startSeq) * charHeight, - getWidth(), charHeight); + g.fillRect(0, (i - startSeq) * charHeight, getWidth(), charHeight); g.setColor(currentTextColor); @@ -361,8 +363,9 @@ public class IdCanvas extends JPanel implements ViewportListenerI xPos = panelWidth - fm.stringWidth(string) - 4; } - g.drawString(string, xPos, (((i - startSeq) * charHeight) + charHeight) - - (charHeight / 5)); + g.drawString(string, xPos, + (((i - startSeq) * charHeight) + charHeight) + - (charHeight / 5)); if (hasHiddenRows && av.getShowHiddenMarkers()) { @@ -382,6 +385,25 @@ public class IdCanvas extends JPanel implements ViewportListenerI void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, int startSeq, int pageHeight) { + drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1, true); + } + + /** + * render sequence IDs and annotation labels when wrapped - without GUI junk + * @param g + * @param av2 + * @param i + * @param totalHeight + */ + public void drawIdsWrappedNoGUI(Graphics2D g, AlignViewport av2, int i, + int totalHeight) + { + drawIdsWrapped(g, av2, totalHeight, totalHeight, i,false); + } + + public void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, + int startSeq, int pageHeight, int idWidth, boolean forGUI) + { int alignmentWidth = alignViewport.getAlignment().getWidth(); final int alheight = alignViewport.getAlignment().getHeight(); @@ -396,6 +418,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI AnnotationLabels labels = null; if (alignViewport.isShowAnnotation()) { + // in wrapped mode, no alignPanel reference is available + // FIXME: make the renderer not create a new object in wrapped mode everytime! labels = new AnnotationLabels(alignViewport); } @@ -428,8 +452,23 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (labels != null && alignViewport.isShowAnnotation()) { + int getWidth = getWidth(); + int thisIdWidth = getWidth; g.translate(0, ypos + (alheight * charHeight)); - labels.drawComponent(g, getWidth()); + if (!manuallyAdjusted()) + { + int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,forGUI, + null, false); + thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth; + if (thisIdWidth > getWidth) + { + this.setPreferredSize( + new Dimension(thisIdWidth, this.getHeight())); + this.repaint(); + alignViewport.setIdWidth(thisIdWidth); + } + } + labels.drawComponent(g, false, thisIdWidth, forGUI); g.translate(0, -ypos - (alheight * charHeight)); } @@ -448,7 +487,8 @@ public class IdCanvas extends JPanel implements ViewportListenerI * @param starty * @param yoffset */ - void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, int starty, int yoffset) + void drawMarker(Graphics2D g, AlignViewport alignViewport, int seqIndex, + int starty, int yoffset) { SequenceI[] hseqs = alignViewport.getAlignment() .getHiddenSequences().hiddenSequences; @@ -491,8 +531,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI /* * vertices of the triangle, below or above hidden seqs */ - int[] xPoints = new int[] - { getWidth() - charHeight, + int[] xPoints = new int[] { getWidth() - charHeight, getWidth() - charHeight, getWidth() }; int yShift = seqIndex - starty; @@ -585,4 +624,17 @@ public class IdCanvas extends JPanel implements ViewportListenerI repaint(); } } + + private boolean manuallyAdjusted = false; + + public boolean manuallyAdjusted() + { + return manuallyAdjusted; + } + + public void setManuallyAdjusted(boolean b) + { + manuallyAdjusted = b; + } + }