From bbbad521d82472ce439a6375603694f2137b79dd Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 15 Mar 2017 12:55:25 +0000 Subject: [PATCH] JAL-2443 push getResidueBoxColour inside getResidueColour --- src/MCview/AppletPDBCanvas.java | 16 ++++---------- src/MCview/PDBCanvas.java | 16 ++++---------- src/jalview/api/SequenceRenderer.java | 2 -- src/jalview/appletgui/OverviewPanel.java | 9 ++------ src/jalview/appletgui/SequenceRenderer.java | 3 +-- src/jalview/ext/jmol/JmolCommands.java | 9 ++------ src/jalview/ext/varna/VarnaCommands.java | 9 +++----- src/jalview/gui/OverviewPanel.java | 7 +------ src/jalview/gui/SequenceRenderer.java | 14 +++++-------- test/jalview/gui/SequenceRendererTest.java | 8 +++---- test/jalview/schemes/ColourSchemesTest.java | 30 +++++++++++++-------------- 11 files changed, 41 insertions(+), 82 deletions(-) diff --git a/src/MCview/AppletPDBCanvas.java b/src/MCview/AppletPDBCanvas.java index 1602cb4..3ae0650 100644 --- a/src/MCview/AppletPDBCanvas.java +++ b/src/MCview/AppletPDBCanvas.java @@ -607,23 +607,15 @@ public class AppletPDBCanvas extends Panel implements MouseListener, if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.startCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.startCol = finder.findFeatureColour(tmp.startCol, - sequence[s], pos); - } + tmp.startCol = sr.getResidueColour(sequence[s], pos, + finder); } pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.endCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.endCol = finder.findFeatureColour(tmp.endCol, - sequence[s], pos); - } + tmp.endCol = sr + .getResidueColour(sequence[s], pos, finder); } } } diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java index ae58758..08bca8c 100644 --- a/src/MCview/PDBCanvas.java +++ b/src/MCview/PDBCanvas.java @@ -575,23 +575,15 @@ public class PDBCanvas extends JPanel implements MouseListener, if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.startCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.startCol = finder.findFeatureColour(tmp.startCol, - sequence[s], pos); - } + tmp.startCol = sr.getResidueColour(sequence[s], pos, + finder); } pos = mapping[m].getSeqPos(tmp.at2.resNumber) - 1; if (pos > 0) { pos = sequence[s].findIndex(pos); - tmp.endCol = sr.getResidueBoxColour(sequence[s], pos); - if (showFeatures) - { - tmp.endCol = finder.findFeatureColour(tmp.endCol, - sequence[s], pos); - } + tmp.endCol = sr + .getResidueColour(sequence[s], pos, finder); } } diff --git a/src/jalview/api/SequenceRenderer.java b/src/jalview/api/SequenceRenderer.java index 5e772a4..54f7fb6 100644 --- a/src/jalview/api/SequenceRenderer.java +++ b/src/jalview/api/SequenceRenderer.java @@ -28,8 +28,6 @@ import java.awt.Color; public interface SequenceRenderer { - Color getResidueBoxColour(SequenceI sequenceI, int r); - Color getResidueColour(SequenceI seq, int position, FeatureColourFinder finder); diff --git a/src/jalview/appletgui/OverviewPanel.java b/src/jalview/appletgui/OverviewPanel.java index 8427c77..251e1c8 100755 --- a/src/jalview/appletgui/OverviewPanel.java +++ b/src/jalview/appletgui/OverviewPanel.java @@ -352,16 +352,11 @@ public class OverviewPanel extends Panel implements Runnable, if (seq.getLength() > lastcol) { - color = sr.getResidueBoxColour(seq, lastcol); - - if (av.isShowSequenceFeatures()) - { - color = finder.findFeatureColour(color, seq, lastcol); - } + color = sr.getResidueColour(seq, lastcol, finder); } else { - color = Color.white; // White + color = Color.white; } if (hiddenRow diff --git a/src/jalview/appletgui/SequenceRenderer.java b/src/jalview/appletgui/SequenceRenderer.java index b5586c9..78ed4a3 100755 --- a/src/jalview/appletgui/SequenceRenderer.java +++ b/src/jalview/appletgui/SequenceRenderer.java @@ -69,8 +69,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer this.renderGaps = renderGaps; } - @Override - public Color getResidueBoxColour(SequenceI seq, int i) + protected Color getResidueBoxColour(SequenceI seq, int i) { allGroups = av.getAlignment().findAllGroups(seq); diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index a1ff3c5..4212749 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -102,13 +102,8 @@ public class JmolCommands lastPos = pos; - Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r); - - if (fr != null) - { - col = finder - .findFeatureColour(col, sequence[pdbfnum][s], r); - } + Color col = sr.getResidueColour(sequence[pdbfnum][s], r, + finder); /* * shade hidden regions darker diff --git a/src/jalview/ext/varna/VarnaCommands.java b/src/jalview/ext/varna/VarnaCommands.java index 617dc8f..d65f1d5 100644 --- a/src/jalview/ext/varna/VarnaCommands.java +++ b/src/jalview/ext/varna/VarnaCommands.java @@ -48,7 +48,7 @@ public class VarnaCommands public static String[] getColourBySequenceCommand( StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, - FeatureColourFinder fr, + FeatureColourFinder finder, AlignmentI alignment) { ArrayList str = new ArrayList(); @@ -88,12 +88,9 @@ public class VarnaCommands lastPos = pos; - Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r); + Color col = sr.getResidueColour(sequence[pdbfnum][s], r, + finder); - if (fr != null) - { - col = fr.findFeatureColour(col, sequence[pdbfnum][s], r); - } String newSelcom = (mapping[m].getChain() != " " ? ":" + mapping[m].getChain() : "") + "/" diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 7fdb610..4097c40 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -370,12 +370,7 @@ public class OverviewPanel extends JPanel implements Runnable if (seq.getLength() > lastcol) { - color = sr.getResidueBoxColour(seq, lastcol); - - if (av.isShowSequenceFeatures()) - { - color = finder.findFeatureColour(color, seq, lastcol); - } + color = sr.getResidueColour(seq, lastcol, finder); } else { diff --git a/src/jalview/gui/SequenceRenderer.java b/src/jalview/gui/SequenceRenderer.java index 764ef3f..1c0420d 100755 --- a/src/jalview/gui/SequenceRenderer.java +++ b/src/jalview/gui/SequenceRenderer.java @@ -53,14 +53,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer boolean forOverview = false; /** - * Creates a new SequenceRenderer object. + * Creates a new SequenceRenderer object * - * @param av - * DOCUMENT ME! + * @param viewport */ - public SequenceRenderer(AlignViewport av) + public SequenceRenderer(AlignViewport viewport) { - this.av = av; + this.av = viewport; } /** @@ -83,8 +82,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer this.renderGaps = renderGaps; } - @Override - public Color getResidueBoxColour(SequenceI seq, int i) + protected Color getResidueBoxColour(SequenceI seq, int i) { // rate limiting step when rendering overview for lots of groups allGroups = av.getAlignment().findAllGroups(seq); @@ -118,8 +116,6 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer public Color getResidueColour(final SequenceI seq, int position, FeatureColourFinder finder) { - // TODO replace 8 or so code duplications with calls to this method - // (refactored as needed) Color col = getResidueBoxColour(seq, position); if (finder != null) diff --git a/test/jalview/gui/SequenceRendererTest.java b/test/jalview/gui/SequenceRendererTest.java index 81289b0..29a9a52 100644 --- a/test/jalview/gui/SequenceRendererTest.java +++ b/test/jalview/gui/SequenceRendererTest.java @@ -53,10 +53,10 @@ public class SequenceRendererTest av.setGlobalColourScheme(new ZappoColourScheme()); // @see ResidueProperties.zappo - assertEquals(Color.pink, sr.getResidueColour(seq, 0, null)); // M - assertEquals(Color.green, sr.getResidueColour(seq, 2, null)); // T - assertEquals(Color.magenta, sr.getResidueColour(seq, 5, null)); // G - assertEquals(Color.orange, sr.getResidueColour(seq, 12, null)); // F + assertEquals(Color.pink, sr.getResidueBoxColour(seq, 0)); // M + assertEquals(Color.green, sr.getResidueBoxColour(seq, 2)); // T + assertEquals(Color.magenta, sr.getResidueBoxColour(seq, 5)); // G + assertEquals(Color.orange, sr.getResidueBoxColour(seq, 12)); // F } // TODO more tests for getResidueBoxColour covering groups, feature rendering, // gaps, overview... diff --git a/test/jalview/schemes/ColourSchemesTest.java b/test/jalview/schemes/ColourSchemesTest.java index 4618ed7..0aaa38c 100644 --- a/test/jalview/schemes/ColourSchemesTest.java +++ b/test/jalview/schemes/ColourSchemesTest.java @@ -228,9 +228,9 @@ public class ColourSchemesTest * set and check Taylor colours */ af.changeColour_actionPerformed(JalviewColourScheme.Taylor.toString()); - Color taylor1 = sr.getResidueBoxColour(seq, 88); // E 255,0,102 - Color taylor2 = sr.getResidueBoxColour(seq, 89); // A 204,255,0 - Color taylor3 = sr.getResidueBoxColour(seq, 90); // G 255,153,0 + Color taylor1 = sr.getResidueColour(seq, 88, null); // E 255,0,102 + Color taylor2 = sr.getResidueColour(seq, 89, null); // A 204,255,0 + Color taylor3 = sr.getResidueColour(seq, 90, null); // G 255,153,0 assertEquals(taylor1, new Color(255, 0, 102)); assertEquals(taylor2, new Color(204, 255, 0)); assertEquals(taylor3, new Color(255, 153, 0)); @@ -239,9 +239,9 @@ public class ColourSchemesTest * set and check Zappo colours */ af.changeColour_actionPerformed(JalviewColourScheme.Zappo.toString()); - Color zappo1 = sr.getResidueBoxColour(seq, 88); // E red - Color zappo2 = sr.getResidueBoxColour(seq, 89); // A pink - Color zappo3 = sr.getResidueBoxColour(seq, 90); // G magenta + Color zappo1 = sr.getResidueColour(seq, 88, null); // E red + Color zappo2 = sr.getResidueColour(seq, 89, null); // A pink + Color zappo3 = sr.getResidueColour(seq, 90, null); // G magenta assertEquals(zappo1, Color.red); assertEquals(zappo2, Color.pink); assertEquals(zappo3, Color.magenta); @@ -250,9 +250,9 @@ public class ColourSchemesTest * set 'stripy' colours - odd columns are Taylor and even are Zappo */ af.changeColour_actionPerformed("stripy"); - Color stripy1 = sr.getResidueBoxColour(seq, 88); - Color stripy2 = sr.getResidueBoxColour(seq, 89); - Color stripy3 = sr.getResidueBoxColour(seq, 90); + Color stripy1 = sr.getResidueColour(seq, 88, null); + Color stripy2 = sr.getResidueColour(seq, 89, null); + Color stripy3 = sr.getResidueColour(seq, 90, null); assertEquals(stripy1, zappo1); assertEquals(stripy2, taylor2); assertEquals(stripy3, zappo3); @@ -261,9 +261,9 @@ public class ColourSchemesTest * set and check Clustal colours */ af.changeColour_actionPerformed(JalviewColourScheme.Clustal.toString()); - Color clustal1 = sr.getResidueBoxColour(seq, 88); - Color clustal2 = sr.getResidueBoxColour(seq, 89); - Color clustal3 = sr.getResidueBoxColour(seq, 90); + Color clustal1 = sr.getResidueColour(seq, 88, null); + Color clustal2 = sr.getResidueColour(seq, 89, null); + Color clustal3 = sr.getResidueColour(seq, 90, null); assertEquals(clustal1, ClustalColour.MAGENTA.colour); assertEquals(clustal2, ClustalColour.BLUE.colour); assertEquals(clustal3, ClustalColour.ORANGE.colour); @@ -272,9 +272,9 @@ public class ColourSchemesTest * set 'MyClustal' colours - uses AWT colour equivalents */ af.changeColour_actionPerformed("MyClustal"); - Color myclustal1 = sr.getResidueBoxColour(seq, 88); - Color myclustal2 = sr.getResidueBoxColour(seq, 89); - Color myclustal3 = sr.getResidueBoxColour(seq, 90); + Color myclustal1 = sr.getResidueColour(seq, 88, null); + Color myclustal2 = sr.getResidueColour(seq, 89, null); + Color myclustal3 = sr.getResidueColour(seq, 90, null); assertEquals(myclustal1, Color.MAGENTA); assertEquals(myclustal2, Color.BLUE); assertEquals(myclustal3, Color.ORANGE); -- 1.7.10.2