X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FIdCanvas.java;h=2faea017a8144c7a6c04c62a270ddd5c07484026;hb=f680b9a507cc1643c9eead990e15026c1eca4e6e;hp=e284bbe0638cb409f5e080cebbf7c23815c4e74e;hpb=31714b90648bba773f68736b8c1700ae53805eee;p=jalview.git diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index e284bbe..2faea01 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; @@ -201,7 +202,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI gg.translate(0, transY); - drawIds(gg, av, ss, es, searchResults); + drawIds(gg, av, ss, es, searchResults,true); gg.translate(0, -transY); @@ -258,7 +259,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI gg.fillRect(0, 0, getWidth(), imgHeight); drawIds(gg, av, av.getRanges().getStartSeq(), - av.getRanges().getEndSeq(), searchResults); + av.getRanges().getEndSeq(), searchResults,true); gg.dispose(); @@ -278,7 +279,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI * @param selection */ void drawIds(Graphics2D g, AlignViewport alignViewport, - final int startSeq, final int endSeq, List selection) + final int startSeq, final int endSeq, List selection, boolean forGUI) { Font font = alignViewport.getFont(); if (alignViewport.isSeqNameItalics()) @@ -321,11 +322,11 @@ public class IdCanvas extends JPanel implements ViewportListenerI int colWid = 20; int panelWidth = Math.max(fullPanelWidth / 2, fullPanelWidth - (colWid * visible.size())); - int xPos = 0; // Now draw the id strings for (int i = startSeq; i <= endSeq; i++) { + int xPos = 0; SequenceI sequence = alignViewport.getAlignment().getSequenceAt(i); if (sequence == null) @@ -377,28 +378,33 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (visible != null && visible.size() > 0) { - xPos = panelWidth + 2; - for (IdColumn col : visible) + try { - ColumnCell col_cell = id_cols.getCellFor(sequence, col); - if (col_cell == null) - { - g.setColor(Color.gray); - g.fillRect(xPos, (i - startSeq) * charHeight, xPos + colWid - 4, - charHeight); - } - else + xPos = panelWidth + 2; + for (IdColumn col : visible) { - g.setColor(col_cell.bg); - g.fillRect(xPos, (i - startSeq) * charHeight, xPos + colWid - 4, - charHeight); - g.setColor(col_cell.fg); - g.drawString(col_cell.label, xPos, - (((i - startSeq) * charHeight) + charHeight) - - (charHeight / 5)); + ColumnCell col_cell = id_cols.getCellFor(sequence, col); + if (col_cell == null) + { + g.setColor(Color.gray); + g.fillRect(xPos + 1, (i - startSeq) * charHeight, + xPos + colWid - 3, charHeight); + } + else + { + g.setColor(col_cell.bg); + g.fillRect(xPos + 1, (i - startSeq) * charHeight, + xPos + colWid - 3, charHeight); + g.setColor(col_cell.fg); + g.drawString(col_cell.label, xPos, + (((i - startSeq) * charHeight) + charHeight) + - (charHeight / 5)); + } + xPos += colWid; + g.setColor(currentTextColor); } - xPos += colWid; - g.setColor(currentTextColor); + } catch (Exception q) + { } } if (hasHiddenRows && av.getShowHiddenMarkers()) @@ -419,6 +425,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); + } + + 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(); @@ -465,8 +490,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); + 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)); } @@ -622,4 +662,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; + } + }