X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FAnnotationRenderer.java;h=3fdcb3b7f548e080a804d25cee8de8d80f6dfaf1;hb=refs%2Fheads%2Freleases%2FRelease_2_10_0_Branch;hp=2d8428901eb68fd1c0cd7bb283eaef6ced0f301d;hpb=6a951ef313becea88861eb3f48c244be82da1ca0;p=jalview.git diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 2d84289..3fdcb3b 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -22,6 +22,7 @@ package jalview.renderer; import jalview.analysis.AAFrequency; import jalview.analysis.CodingUtils; +import jalview.analysis.Rna; import jalview.analysis.StructureFrequency; import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentAnnotation; @@ -29,6 +30,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; +import jalview.util.Platform; import java.awt.BasicStroke; import java.awt.Color; @@ -43,8 +45,6 @@ import java.awt.image.ImageObserver; import java.util.BitSet; import java.util.Hashtable; -import com.stevesoft.pat.Regex; - public class AnnotationRenderer { private static final int UPPER_TO_LOWER = 'a' - 'A'; // 32 @@ -58,6 +58,70 @@ public class AnnotationRenderer */ private final boolean debugRedraw; + private int charWidth, endRes, charHeight; + + private boolean validCharWidth, hasHiddenColumns; + + private FontMetrics fm; + + private final boolean MAC = Platform.isAMac(); + + boolean av_renderHistogram = true, av_renderProfile = true, + av_normaliseProfile = false; + + ColourSchemeI profcolour = null; + + private ColumnSelection columnSelection; + + private Hashtable[] hconsensus; + + private Hashtable[] complementConsensus; + + private Hashtable[] hStrucConsensus; + + private boolean av_ignoreGapsConsensus; + + /** + * attributes set from AwtRenderPanelI + */ + /** + * old image used when data is currently being calculated and cannot be + * rendered + */ + private Image fadedImage; + + /** + * panel being rendered into + */ + private ImageObserver annotationPanel; + + /** + * width of image to render in panel + */ + private int imgWidth; + + /** + * offset to beginning of visible area + */ + private int sOffset; + + /** + * offset to end of visible area + */ + private int visHeight; + + /** + * indicate if the renderer should only render the visible portion of the + * annotation given the current view settings + */ + private boolean useClip = true; + + /** + * master flag indicating if renderer should ever try to clip. not enabled for + * jalview 2.8.1 + */ + private boolean canClip = false; + public AnnotationRenderer() { this(false); @@ -75,15 +139,26 @@ public class AnnotationRenderer this.debugRedraw = debugRedraw; } - public void drawStemAnnot(Graphics g, Annotation[] row_annotations, - int lastSSX, int x, int y, int iconOffset, int startRes, - int column, boolean validRes, boolean validEnd) + /** + * Remove any references and resources when this object is no longer required + */ + public void dispose() + { + hconsensus = null; + complementConsensus = null; + hStrucConsensus = null; + fadedImage = null; + annotationPanel = null; + } + + void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX, + int x, int y, int iconOffset, int startRes, int column, + boolean validRes, boolean validEnd) { g.setColor(STEM_COLOUR); int sCol = (lastSSX / charWidth) + startRes; int x1 = lastSSX; int x2 = (x * charWidth); - Regex closeparen = new Regex("(\\))"); char dc = (column == 0 || row_annotations[column - 1] == null) ? ' ' : row_annotations[column - 1].secondaryStructure; @@ -93,15 +168,17 @@ public class AnnotationRenderer boolean diffdownstream = !validRes || !validEnd || row_annotations[column] == null || dc != row_annotations[column].secondaryStructure; - // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream); - // If a closing base pair half of the stem, display a backward arrow - if (column > 0 && ResidueProperties.isCloseParenRNA(dc)) - { + if (column > 0 && Rna.isClosingParenthesis(dc)) + { if (diffupstream) // if (validRes && column>1 && row_annotations[column-2]!=null && // dc.equals(row_annotations[column-2].displayCharacter)) { + /* + * if new annotation with a closing base pair half of the stem, + * display a backward arrow + */ g.fillPolygon(new int[] { lastSSX + 5, lastSSX + 5, lastSSX }, new int[] { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3); @@ -114,10 +191,13 @@ public class AnnotationRenderer } else { - // display a forward arrow if (diffdownstream) { + /* + * if annotation ending with an opeing base pair half of the stem, + * display a forward arrow + */ g.fillPolygon(new int[] { x2 - 5, x2 - 5, x2 }, new int[] { y + iconOffset, y + 14 + iconOffset, y + 8 + iconOffset }, 3); x2 -= 5; @@ -131,71 +211,7 @@ public class AnnotationRenderer g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7); } - private int charWidth, endRes, charHeight; - - private boolean validCharWidth, hasHiddenColumns; - - private FontMetrics fm; - - private final boolean MAC = jalview.util.Platform.isAMac(); - - boolean av_renderHistogram = true, av_renderProfile = true, - av_normaliseProfile = false; - - ColourSchemeI profcolour = null; - - private ColumnSelection columnSelection; - - private Hashtable[] hconsensus; - - private Hashtable[] complementConsensus; - - private Hashtable[] hStrucConsensus; - - private boolean av_ignoreGapsConsensus; - - /** - * attributes set from AwtRenderPanelI - */ - /** - * old image used when data is currently being calculated and cannot be - * rendered - */ - private Image fadedImage; - - /** - * panel being rendered into - */ - private ImageObserver annotationPanel; - - /** - * width of image to render in panel - */ - private int imgWidth; - - /** - * offset to beginning of visible area - */ - private int sOffset; - - /** - * offset to end of visible area - */ - private int visHeight; - - /** - * indicate if the renderer should only render the visible portion of the - * annotation given the current view settings - */ - private boolean useClip = true; - - /** - * master flag indicating if renderer should ever try to clip. not enabled for - * jalview 2.8.1 - */ - private boolean canClip = false; - - public void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, + void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations, int lastSSX, int x, int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) @@ -206,7 +222,6 @@ public class AnnotationRenderer int sCol = (lastSSX / charWidth) + startRes; int x1 = lastSSX; int x2 = (x * charWidth); - Regex closeparen = new Regex("}|]|<|[a-z]"); String dc = (column == 0 || row_annotations[column - 1] == null) ? "" : row_annotations[column - 1].displayCharacter; @@ -218,8 +233,7 @@ public class AnnotationRenderer || !dc.equals(row_annotations[column].displayCharacter); // System.out.println("Column "+column+" diff up: "+diffupstream+" down:"+diffdownstream); // If a closing base pair half of the stem, display a backward arrow - if (column > 0 && closeparen.search(dc))// closeletter_b.search(dc)||closeletter_c.search(dc)||closeletter_d.search(dc)||closecrochet.search(dc)) - // ) + if (column > 0 && Rna.isClosingParenthesis(dc)) { if (diffupstream) @@ -321,7 +335,7 @@ public class AnnotationRenderer * @param column * @return */ - public int[] getProfileFor(AlignmentAnnotation aa, int column) + int[] getProfileFor(AlignmentAnnotation aa, int column) { // TODO : consider refactoring the global alignment calculation // properties/rendering attributes as a global 'alignment group' which holds @@ -598,7 +612,7 @@ public class AnnotationRenderer if (columnSelection != null) { - if (columnSelection.isSelected(column)) + if (columnSelection.contains(column)) { g.fillRect(x * charWidth, y, charWidth, charHeight); } @@ -750,7 +764,7 @@ public class AnnotationRenderer validEnd); break; } - + // no break if isRNA - falls through to drawNotCanonicalAnnot! case 'E': if (!isRNA) { @@ -759,6 +773,7 @@ public class AnnotationRenderer validEnd); break; } + // no break if isRNA - fall through to drawNotCanonicalAnnot! case '{': case '}': @@ -866,7 +881,6 @@ public class AnnotationRenderer { validRes = true; } - // x ++; if (row.hasIcons) @@ -881,6 +895,7 @@ public class AnnotationRenderer startRes, column, validRes, validEnd); break; } + // no break if isRNA - fall through to drawNotCanonicalAnnot! case 'E': if (!isRNA) @@ -889,6 +904,7 @@ public class AnnotationRenderer startRes, column, validRes, validEnd); break; } + // no break if isRNA - fall through to drawNotCanonicalAnnot! case '(': case ')': // Stem case for RNA secondary structure @@ -1069,15 +1085,15 @@ public class AnnotationRenderer private Color sdNOTCANONICAL_COLOUR; - public void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, - int x, int y, int iconOffset, int startRes, int column, + void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x, + int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) { g.setColor(GLYPHLINE_COLOR); g.fillRect(lastSSX, y + 6 + iconOffset, (x * charWidth) - lastSSX, 2); } - public void drawSheetAnnot(Graphics g, Annotation[] row, + void drawSheetAnnot(Graphics g, Annotation[] row, int lastSSX, int x, int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) @@ -1101,8 +1117,8 @@ public class AnnotationRenderer } - public void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, - int x, int y, int iconOffset, int startRes, int column, + void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x, + int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) { g.setColor(HELIX_COLOUR); @@ -1161,7 +1177,7 @@ public class AnnotationRenderer g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 8); } - public void drawLineGraph(Graphics g, AlignmentAnnotation _aa, + void drawLineGraph(Graphics g, AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes, int eRes, int y, float min, float max, int graphHeight) { @@ -1254,7 +1270,7 @@ public class AnnotationRenderer } } - public void drawBarGraph(Graphics g, AlignmentAnnotation _aa, + void drawBarGraph(Graphics g, AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes, int eRes, float min, float max, int y, boolean renderHistogram, boolean renderProfile, boolean normaliseProfile) @@ -1385,8 +1401,9 @@ public class AnnotationRenderer scl = htn * scale * profl[c++]; lm = ofont.getLineMetrics(dc, 0, 1, g.getFontMetrics() .getFontRenderContext()); - g.setFont(ofont.deriveFont(AffineTransform.getScaleInstance( - wdth, scl / lm.getAscent()))); + Font font = ofont.deriveFont(AffineTransform.getScaleInstance( + wdth, scl / lm.getAscent())); + g.setFont(font); lm = g.getFontMetrics().getLineMetrics(dc, 0, 1, g); // Debug - render boxes around characters