From 0a94254977a8824ad154325a8ccb6d6d1d4e4dec Mon Sep 17 00:00:00 2001 From: hansonr Date: Thu, 1 Aug 2019 12:49:09 -0500 Subject: [PATCH] JAL-3253-applet JAL-3383 Overview additional int for Color (shader) fixes problem with JavaScript timing for container resized --- src/jalview/gui/OverviewCanvas.java | 12 +-- src/jalview/gui/OverviewPanel.java | 71 ++++++++++-------- src/jalview/renderer/OverviewResColourFinder.java | 2 +- src/jalview/renderer/ResidueShader.java | 83 +++++++++++++++++++++ src/jalview/renderer/ResidueShaderI.java | 2 + src/jalview/util/ColorUtils.java | 36 +++++++++ 6 files changed, 164 insertions(+), 42 deletions(-) diff --git a/src/jalview/gui/OverviewCanvas.java b/src/jalview/gui/OverviewCanvas.java index b6df722..de55996 100644 --- a/src/jalview/gui/OverviewCanvas.java +++ b/src/jalview/gui/OverviewCanvas.java @@ -47,7 +47,7 @@ public class OverviewCanvas extends JPanel private boolean disposed = false; - private BufferedImage lastMiniMe = null; + BufferedImage lastMiniMe = null; // Can set different properties in this seqCanvas than // main visible SeqCanvas @@ -177,11 +177,7 @@ public class OverviewCanvas extends JPanel synchronized void finalizeDraw(BufferedImage miniMe) { - if (or == null) - { - System.out.println("OC or is null"); - } - else if (showProgress) + if (showProgress && or != null) { or.removePropertyChangeListener(progressPanel); } @@ -196,7 +192,7 @@ public class OverviewCanvas extends JPanel } else { - if (showAnnotation) + if (showAnnotation && or != null) { or.drawGraph(av.getAlignmentConservationAnnotation()); } @@ -303,7 +299,7 @@ public class OverviewCanvas extends JPanel od.drawBox(g); } - private int ndraw, npaint, nrepaint; + // private int ndraw, npaint, nrepaint; // @Override // public void repaint() diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 532028c..5694c3d 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -120,39 +120,7 @@ public class OverviewPanel extends JPanel @Override public void componentResized(ComponentEvent evt) { - int ph = (progressPanel.getParent() == null ? 0 - : progressPanel.getHeight()); - // Resize is called on the initial display of the overview. - // This code adjusts sizes to account for the progress bar if it has not - // already been accounted for, which triggers another resize call for - // the correct sizing, at which point the overview image is updated. - // (This avoids a double recalculation of the image.) - if (getWidth() == od.getWidth() - && getHeight() == od.getHeight() + ph) - { - // BH: resizing is now exceptionally fast. - // updateOverviewImage(); - } - else - { - int w = getWidth(); - int h = getHeight(); - if ((w > 0) && (h > 0)) - { - if (dim != null) - { - dim.setSize(w, h - ph); - } - od.setWidth(w); - od.setHeight(h - ph); - updateOverviewImage(); - // repaint(); - } - // BH 2019.07.29 this is unnecessary -- it is what layout managers are - // for: - // setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + - // ph)); - } + resizePanel(); } }); @@ -270,6 +238,43 @@ public class OverviewPanel extends JPanel // } } + protected void resizePanel() + { + int ph = (progressPanel.getParent() == null ? 0 + : progressPanel.getHeight()); + // Resize is called on the initial display of the overview. + // This code adjusts sizes to account for the progress bar if it has not + // already been accounted for, which triggers another resize call for + // the correct sizing, at which point the overview image is updated. + // (This avoids a double recalculation of the image.) + if (getWidth() == od.getWidth() && getHeight() == od.getHeight() + ph) + { + if (canvas.lastMiniMe == null) + { + updateOverviewImage(); + } + } + else + { + int w = getWidth(); + int h = getHeight(); + if ((w > 0) && (h > 0)) + { + if (dim != null) + { + dim.setSize(w, h - ph); + } + od.setWidth(w); + od.setHeight(h - ph); + updateOverviewImage(); + } + // BH 2019.07.29 this is unnecessary -- it is what layout managers are + // for: + // setPreferredSize(new Dimension(od.getWidth(), od.getHeight() + + // ph)); + } + } + /** * Create the appropriate type of OverViewDimensions, with the desired size. */ diff --git a/src/jalview/renderer/OverviewResColourFinder.java b/src/jalview/renderer/OverviewResColourFinder.java index b950542..94e7c5b 100644 --- a/src/jalview/renderer/OverviewResColourFinder.java +++ b/src/jalview/renderer/OverviewResColourFinder.java @@ -90,7 +90,7 @@ public class OverviewResColourFinder extends ResidueColourFinder return (isGap ? GAP_COLOUR : RESIDUE_COLOUR); } return (isGap && !shader.getColourScheme().hasGapColour() ? GAP_COLOUR - : shader.findColour(currentChar, i, seq).getRGB()); + : shader.findColourInt(currentChar, i, seq)); } public int getResidueColourInt(boolean showBoxes, ResidueShaderI shader, diff --git a/src/jalview/renderer/ResidueShader.java b/src/jalview/renderer/ResidueShader.java index c031170..73a5efd 100644 --- a/src/jalview/renderer/ResidueShader.java +++ b/src/jalview/renderer/ResidueShader.java @@ -262,6 +262,36 @@ public class ResidueShader implements ResidueShaderI return colour; } + @Override + public int findColourInt(char symbol, int position, SequenceI seq) + { + if (colourScheme == null) + { + return -1;// Color.white; // Colour is 'None' + } + + /* + * get 'base' colour + */ + ProfileI profile = consensus == null ? null : consensus.get(position); + String modalResidue = profile == null ? null + : profile.getModalResidue(); + float pid = profile == null ? 0f + : profile.getPercentageIdentity(ignoreGaps); + int colour = colourScheme + .findColour(symbol, position, seq, modalResidue, pid).getRGB(); + + /* + * apply PID threshold and consensus fading if in force + */ + if (!Comparison.isGap(symbol)) + { + colour = adjustColourInt(symbol, position, colour); + } + + return colour; + } + /** * Adjusts colour by applying thresholding or conservation shading, if in * force. That is @@ -293,6 +323,20 @@ public class ResidueShader implements ResidueShaderI return colour; } + protected int adjustColourInt(char symbol, int column, int colour) + { + if (!aboveThreshold(symbol, column)) + { + colour = -1;// Color.white; + } + + if (conservationColouring) + { + colour = applyConservationInt(colour, column); + } + return colour; + } + /** * Answers true if there is a consensus profile for the specified column, and * the given residue matches the consensus (or joint consensus) residue for @@ -398,6 +442,45 @@ public class ResidueShader implements ResidueShaderI return ColorUtils.bleachColour(currentColour, bleachFactor); } + protected int applyConservationInt(int currentColour, int column) + { + if (conservation == null || conservation.length <= column) + { + return currentColour; + } + char conservationScore = conservation[column]; + + /* + * if residues are fully conserved (* or 11), or all properties + * are conserved (+ or 10), leave colour unchanged + */ + if (conservationScore == '*' || conservationScore == '+' + || conservationScore == (char) 10 + || conservationScore == (char) 11) + { + return currentColour; + } + + if (Comparison.isGap(conservationScore)) + { + return -1;// Color.white; + } + + /* + * convert score 0-9 to a bleaching factor 1.1 - 0.2 + */ + float bleachFactor = (11 - (conservationScore - '0')) / 10f; + + /* + * scale this up by 0-5 (percentage slider / 20) + * as a result, scores of: 0 1 2 3 4 5 6 7 8 9 + * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100% + */ + bleachFactor *= (conservationIncrement / 20f); + + return ColorUtils.bleachColourInt(currentColour, bleachFactor); + } + /** * @see jalview.renderer.ResidueShaderI#getColourScheme() */ diff --git a/src/jalview/renderer/ResidueShaderI.java b/src/jalview/renderer/ResidueShaderI.java index 4d97171..2f14a5d 100644 --- a/src/jalview/renderer/ResidueShaderI.java +++ b/src/jalview/renderer/ResidueShaderI.java @@ -82,4 +82,6 @@ public interface ResidueShaderI public abstract void setColourScheme(ColourSchemeI cs); + int findColourInt(char symbol, int position, SequenceI seq); + } \ No newline at end of file diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 3eb080b..a2d8d3e 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -199,6 +199,42 @@ public class ColorUtils } } + public static int bleachColourInt(int colour, float bleachFactor) + { + if (bleachFactor >= 1f) + { + return -1;// Color.WHITE; + } + if (bleachFactor <= -1f) + { + return 0xFF000000;// Color.BLACK; + } + if (bleachFactor == 0f) + { + return colour; + } + + int red = (colour >> 16) & 0xFF;// getRed(); + int green = (colour >> 8) & 0xFF;// colour.getGreen(); + int blue = colour & 0xFF;// .getBlue(); + + if (bleachFactor > 0) + { + red += (255 - red) * bleachFactor; + green += (255 - green) * bleachFactor; + blue += (255 - blue) * bleachFactor; + } + else + { + float factor = 1 + bleachFactor; + red *= factor; + green *= factor; + blue *= factor; + } + return 0xFF000000 | (red << 16) | (green << 8) | blue;// new Color(red, + // green, blue); + } + /** * Parses a string into a Color, where the accepted formats are *