private AlignViewport av;
- // Can set different properties in this seqCanvas than
- // main visible SeqCanvas
- private SequenceRenderer sr;
-
private jalview.renderer.seqfeatures.FeatureRenderer fr;
private Frame nullFrame;
nullFrame = new Frame();
nullFrame.addNotify();
- sr = new SequenceRenderer(av);
- sr.graphics = nullFrame.getGraphics();
- sr.renderGaps = false;
- // sr.forOverview = true;
fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
}
setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
- or = new OverviewRenderer(sr, fr, od, av.getAlignment(),
+ or = new OverviewRenderer(fr, od, av.getAlignment(),
av.getResidueShading());
miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.renderer.ResidueShaderI;
+import jalview.renderer.ResidueColourFinder;
import jalview.renderer.seqfeatures.FeatureColourFinder;
import java.awt.Color;
boolean renderGaps = true;
- SequenceGroup currentSequenceGroup = null;
-
SequenceGroup[] allGroups = null;
Color resBoxColour;
Graphics graphics;
+ ResidueColourFinder resColourFinder;
+
public SequenceRenderer(AlignViewport av)
{
this.av = av;
+ resColourFinder = new ResidueColourFinder();
}
/**
this.renderGaps = renderGaps;
}
- protected Color getResidueBoxColour(SequenceI seq, int i)
- {
- allGroups = av.getAlignment().findAllGroups(seq);
-
- if (inCurrentSequenceGroup(i))
- {
- if (currentSequenceGroup.getDisplayBoxes())
- {
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
- }
- }
- else if (av.getShowBoxes())
- {
- getBoxColour(av.getResidueShading(), seq, i);
- }
-
- return resBoxColour;
- }
-
/**
* Get the residue colour at the given sequence position - as determined by
* the sequence group colour (if any), else the colour scheme, possibly
{
// TODO replace 8 or so code duplications with calls to this method
// (refactored as needed)
- Color col = getResidueBoxColour(seq, position);
-
- if (finder != null)
- {
- col = finder.findFeatureColour(col, seq, position);
- }
- return col;
- }
-
- void getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
- {
- if (shader.getColourScheme() != null)
- {
- resBoxColour = shader.findColour(seq.getCharAt(i), i, seq);
- }
- else
- {
- resBoxColour = Color.white;
- }
-
+ return resColourFinder.getResidueColour(av.getResidueShading(),
+ allGroups, seq, position, finder);
}
public Color findSequenceColour(SequenceI seq, int i)
int curWidth = av.getCharWidth(), avCharWidth = av.getCharWidth(), avCharHeight = av
.getCharHeight();
+ Color resBoxColour = Color.white;
Color tempColour = null;
while (i <= end)
{
resBoxColour = Color.white;
if (i < length)
{
- if (inCurrentSequenceGroup(i))
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(allGroups, i);
+ if (currentSequenceGroup != null)
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq,
i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getResidueShading(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
}
}
continue;
}
- if (inCurrentSequenceGroup(i))
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(allGroups, i);
+ if (currentSequenceGroup != null)
{
if (!currentSequenceGroup.getDisplayText())
{
if (currentSequenceGroup.getColourText())
{
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq, i);
graphics.setColor(resBoxColour.darker());
}
if (currentSequenceGroup.getShowNonconserved())
if (av.getColourText())
{
- getBoxColour(av.getResidueShading(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
if (av.getShowBoxes())
{
graphics.setColor(resBoxColour.darker());
return sequenceChar;
}
- boolean inCurrentSequenceGroup(int res)
- {
- if (allGroups == null)
- {
- return false;
- }
-
- for (int i = 0; i < allGroups.length; i++)
- {
- if (allGroups[i].getStartRes() <= res
- && allGroups[i].getEndRes() >= res)
- {
- currentSequenceGroup = allGroups[i];
- return true;
- }
- }
-
- return false;
- }
-
public void drawHighlightedText(SequenceI seq, int start, int end,
int x1, int y1)
{
setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
- or = new OverviewRenderer(sr, fr, od, av.getAlignment(),
+ or = new OverviewRenderer(fr, od, av.getAlignment(),
av.getResidueShading());
miniMe = or.draw(od.getRows(av.getAlignment()),
od.getColumns(av.getAlignment()));
import jalview.api.AlignViewportI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.renderer.ResidueShaderI;
+import jalview.renderer.ResidueColourFinder;
import jalview.renderer.seqfeatures.FeatureColourFinder;
import java.awt.Color;
SequenceGroup[] allGroups = null;
- Color resBoxColour;
+ // Color resBoxColour;
Graphics graphics;
boolean monospacedFont;
+ ResidueColourFinder resColourFinder;
+
/**
* Creates a new SequenceRenderer object
*
public SequenceRenderer(AlignViewportI viewport)
{
this.av = viewport;
+ resColourFinder = new ResidueColourFinder();
}
/**
this.renderGaps = renderGaps;
}
- protected Color getResidueBoxColour(SequenceI seq, int i)
- {
- // rate limiting step when rendering overview for lots of groups
- allGroups = av.getAlignment().findAllGroups(seq);
-
- SequenceGroup currentSequenceGroup = inCurrentSequenceGroup(i);
- if (currentSequenceGroup != null)
- {
- if (currentSequenceGroup.getDisplayBoxes())
- {
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
- }
- }
- else if (av.getShowBoxes())
- {
- getBoxColour(av.getResidueShading(), seq, i);
- }
-
- return resBoxColour;
- }
-
/**
* Get the residue colour at the given sequence position - as determined by
* the sequence group colour (if any), else the colour scheme, possibly
public Color getResidueColour(final SequenceI seq, int position,
FeatureColourFinder finder)
{
- Color col = getResidueBoxColour(seq, position);
-
- if (finder != null)
- {
- col = finder.findFeatureColour(col, seq, position);
- }
- return col;
+ return resColourFinder.getResidueColour(av.getResidueShading(),
+ allGroups, seq, position,
+ finder);
}
- /**
- * DOCUMENT ME!
- *
- * @param shader
- * DOCUMENT ME!
- * @param seq
- * DOCUMENT ME!
- * @param i
- * DOCUMENT ME!
- */
- void getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
- {
- if (shader.getColourScheme() != null)
- {
- resBoxColour = shader.findColour(seq.getCharAt(i), i, seq);
- }
- else
- {
- resBoxColour = Color.white;
- }
- }
+
/**
* DOCUMENT ME!
public synchronized void drawBoxes(SequenceI seq, int start, int end,
int y1)
{
+ Color resBoxColour = Color.white;
+
if (seq == null)
{
return; // fix for racecondition
if (i < length)
{
- SequenceGroup currentSequenceGroup = inCurrentSequenceGroup(i);
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(
+ allGroups, i);
if (currentSequenceGroup != null)
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq,
i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getResidueShading(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
}
}
boolean srep = av.isDisplayReferenceSeq();
boolean getboxColour = false;
boolean isarep = av.getAlignment().getSeqrep() == seq;
+ Color resBoxColour = Color.white;
for (int i = start; i <= end; i++)
{
continue;
}
- SequenceGroup currentSequenceGroup = inCurrentSequenceGroup(i);
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(
+ allGroups, i);
if (currentSequenceGroup != null)
{
if (!currentSequenceGroup.getDisplayText())
|| currentSequenceGroup.getColourText())
{
getboxColour = true;
- getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq,
i);
if (currentSequenceGroup.getColourText())
if (av.getColourText())
{
getboxColour = true;
- getBoxColour(av.getResidueShading(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
if (av.getShowBoxes())
{
{
if (!getboxColour)
{
- getBoxColour(av.getResidueShading(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
}
if (resBoxColour.getRed() + resBoxColour.getBlue()
/**
* DOCUMENT ME!
*
- * @param res
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- SequenceGroup inCurrentSequenceGroup(int res)
- {
- if (allGroups == null)
- {
- return null;
- }
-
- for (int i = 0; i < allGroups.length; i++)
- {
- if ((allGroups[i].getStartRes() <= res)
- && (allGroups[i].getEndRes() >= res))
- {
- return (allGroups[i]);
- }
- }
-
- return null;
- }
-
- /**
- * DOCUMENT ME!
- *
* @param seq
* DOCUMENT ME!
* @param start
import jalview.datamodel.SequenceI;
import jalview.renderer.seqfeatures.FeatureColourFinder;
import jalview.renderer.seqfeatures.FeatureRenderer;
-import jalview.util.Comparison;
import jalview.viewmodel.OverviewDimensions;
import java.awt.Color;
{
private FeatureColourFinder finder;
- private jalview.api.SequenceRenderer sr;
-
// image to render on
private BufferedImage miniMe;
private ResidueShaderI shader;
- public OverviewRenderer(jalview.api.SequenceRenderer seqRenderer,
- FeatureRenderer fr, OverviewDimensions od, AlignmentI alignment,
+ private ResidueColourFinder resColFinder;
+
+ public OverviewRenderer(FeatureRenderer fr, OverviewDimensions od,
+ AlignmentI alignment,
ResidueShaderI resshader)
{
- sr = seqRenderer;
finder = new FeatureColourFinder(fr);
+ resColFinder = new OverviewResColourFinder();
al = alignment;
shader = resshader;
if ((seq != null) && (seq.getLength() > lastcol))
{
- color = getResidueColour(allGroups, seq, lastcol, fcfinder);
+ color = resColFinder.getResidueColour(shader, allGroups, seq, lastcol,
+ fcfinder);
}
if (isHidden)
return color.getRGB();
}
- private Color getResidueColour(SequenceGroup[] allGroups,
- final SequenceI seq, int position,
- FeatureColourFinder finder)
- {
- Color col = getResidueBoxColour(allGroups, seq, position);
-
- if (finder != null)
- {
- col = finder.findFeatureColour(col, seq, position);
- }
- return col;
- }
-
- protected Color getResidueBoxColour(SequenceGroup[] allGroups,
- SequenceI seq, int i)
- {
-
- ResidueShaderI currentShader;
-
- SequenceGroup currentSequenceGroup = inCurrentSequenceGroup(allGroups,
- i);
- if (currentSequenceGroup != null)
- {
- currentShader = currentSequenceGroup.getGroupColourScheme();
- }
- else
- {
- currentShader = shader;
- }
-
- return getBoxColour(currentShader, seq, i);
- }
-
- SequenceGroup inCurrentSequenceGroup(SequenceGroup[] allGroups, int res)
- {
- if (allGroups == null)
- {
- return null;
- }
-
- for (int i = 0; i < allGroups.length; i++)
- {
- if ((allGroups[i].getStartRes() <= res)
- && (allGroups[i].getEndRes() >= res))
- {
- return (allGroups[i]);
- }
- }
-
- return null;
- }
-
- Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
- {
- Color resBoxColour = Color.white;
- char currentChar = seq.getCharAt(i);
-
- if (shader.getColourScheme() != null)
- {
- if (Comparison.isGap(currentChar)
- && !shader.getColourScheme().hasGapColour())
- {
- resBoxColour = Color.lightGray;
- }
- else
- {
- resBoxColour = shader.findColour(currentChar, i, seq);
- }
- }
- else if (Comparison.isGap(currentChar))
- {
- resBoxColour = Color.lightGray;
- }
-
- return resBoxColour;
- }
-
/**
* Draw the alignment annotation in the overview panel
*
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.renderer;
+
+import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
+
+import java.awt.Color;
+
+public class OverviewResColourFinder extends ResidueColourFinder
+{
+ @Override
+ public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
+ {
+ Color resBoxColour = Color.white;
+ char currentChar = seq.getCharAt(i);
+
+ if (shader.getColourScheme() != null)
+ {
+ if (Comparison.isGap(currentChar)
+ && !shader.getColourScheme().hasGapColour())
+ {
+ resBoxColour = Color.lightGray;
+ }
+ else
+ {
+ resBoxColour = shader.findColour(currentChar, i, seq);
+ }
+ }
+ else if (Comparison.isGap(currentChar))
+ {
+ resBoxColour = Color.lightGray;
+ }
+
+ return resBoxColour;
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.renderer;
+
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.renderer.seqfeatures.FeatureColourFinder;
+
+import java.awt.Color;
+
+public class ResidueColourFinder
+{
+ public ResidueColourFinder()
+ {
+ }
+
+ public Color getResidueColour(ResidueShaderI shader,
+ SequenceGroup[] allGroups,
+ final SequenceI seq, int position, FeatureColourFinder finder)
+ {
+ Color col = getResidueBoxColour(shader, allGroups, seq, position);
+
+ if (finder != null)
+ {
+ col = finder.findFeatureColour(col, seq, position);
+ }
+ return col;
+ }
+
+ private Color getResidueBoxColour(ResidueShaderI shader,
+ SequenceGroup[] allGroups,
+ SequenceI seq, int i)
+ {
+
+ ResidueShaderI currentShader;
+
+ SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
+ i);
+ if (currentSequenceGroup != null)
+ {
+ currentShader = currentSequenceGroup.getGroupColourScheme();
+ }
+ else
+ {
+ currentShader = shader;
+ }
+
+ return getBoxColour(currentShader, seq, i);
+ }
+
+ public SequenceGroup getCurrentSequenceGroup(SequenceGroup[] allGroups,
+ int res)
+ {
+ if (allGroups == null)
+ {
+ return null;
+ }
+
+ for (int i = 0; i < allGroups.length; i++)
+ {
+ if ((allGroups[i].getStartRes() <= res)
+ && (allGroups[i].getEndRes() >= res))
+ {
+ return (allGroups[i]);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param shader
+ * DOCUMENT ME!
+ * @param seq
+ * DOCUMENT ME!
+ * @param i
+ * DOCUMENT ME!
+ */
+ public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
+ {
+ Color resBoxColour = Color.white;
+ if (shader.getColourScheme() != null)
+ {
+ resBoxColour = shader.findColour(seq.getCharAt(i), i, seq);
+ }
+ return resBoxColour;
+ }
+
+}
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.gui;
-
-import static org.testng.AssertJUnit.assertEquals;
-
-import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Sequence;
-import jalview.datamodel.SequenceI;
-import jalview.schemes.ZappoColourScheme;
-
-import java.awt.Color;
-
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-public class SequenceRendererTest
-{
-
- @BeforeClass(alwaysRun = true)
- public void setUpJvOptionPane()
- {
- JvOptionPane.setInteractiveMode(false);
- JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
- }
-
- @Test(groups = { "Functional" })
- public void testGetResidueBoxColour_zappo()
- {
- SequenceI seq = new Sequence("name", "MATVLGSPRAPAFF"); // FER1_MAIZE...
- AlignmentI al = new Alignment(new SequenceI[] { seq });
- final AlignViewport av = new AlignViewport(al);
- SequenceRenderer sr = new SequenceRenderer(av);
- av.setGlobalColourScheme(new ZappoColourScheme());
-
- // @see ResidueProperties.zappo
- 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
- }
-
- @Test(groups = { "Functional" })
- public void testGetResidueBoxColour_none()
- {
- SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
- AlignmentI al = new Alignment(new SequenceI[] { seq });
- final AlignViewport av = new AlignViewport(al);
- SequenceRenderer sr = new SequenceRenderer(av);
-
- assertEquals(Color.white, sr.getResidueBoxColour(seq, 0));
- assertEquals(Color.white, sr.getResidueBoxColour(seq, 2));
-
- // set for overview
- /* sr.forOverview = true;
- assertEquals(Color.lightGray, sr.getResidueBoxColour(seq, 0));
- assertEquals(Color.white, sr.getResidueBoxColour(seq, 2));*/
- }
-
- // TODO more tests for getResidueBoxColour covering groups, feature rendering,
- // gaps, overview...
-
-}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.renderer;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignViewport;
+import jalview.gui.JvOptionPane;
+import jalview.schemes.UserColourScheme;
+import jalview.schemes.ZappoColourScheme;
+
+import java.awt.Color;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class OverviewResColourFinderTest
+{
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueBoxColour_none()
+ {
+ SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new OverviewResColourFinder();
+
+ // gaps are grey, residues white
+ assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 0, null));
+ assertEquals(Color.lightGray, rcf
+ .getResidueColour(av.getResidueShading(), null, seq, 2, null));
+
+ // boxes off does not change anything
+ av.setShowBoxes(false);
+ assertEquals(Color.white, rcf
+ .getResidueColour(av.getResidueShading(), null, seq, 0, null));
+ assertEquals(Color.lightGray, rcf
+ .getResidueColour(av.getResidueShading(),
+ null, seq, 2, null));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueBoxColour_zappo()
+ {
+ SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
+ // gap
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new OverviewResColourFinder();
+ av.setGlobalColourScheme(new ZappoColourScheme());
+
+ // @see ResidueProperties.zappo
+ assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 0, null)); // M
+ assertEquals(Color.green, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 2, null)); // T
+ assertEquals(Color.magenta, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 5, null)); // G
+ assertEquals(Color.orange, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 12, null)); // F
+
+ // gap colour not specified so gaps are lightGray
+ assertEquals(Color.lightGray, rcf
+ .getResidueColour(av.getResidueShading(), null, seq, 3, null));
+
+ // boxes off does not change anything
+ av.setShowBoxes(false);
+
+ assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 0, null)); // M
+ assertEquals(Color.green, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 2, null)); // T
+ assertEquals(Color.magenta, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 5, null)); // G
+ assertEquals(Color.orange, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 12, null)); // F
+
+ // gap colour not specified so gaps are lightGray
+ assertEquals(Color.lightGray, rcf
+ .getResidueColour(av.getResidueShading(), null, seq, 3, null));
+
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueBoxColour_userdef()
+ {
+ SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
+ // gap
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new OverviewResColourFinder();
+
+ Color[] newColours = new Color[24];
+ for (int i = 0; i < 24; i++)
+ {
+ newColours[i] = null;
+ }
+
+ av.setGlobalColourScheme(new UserColourScheme(newColours));
+
+ // gap colour not specified so gaps are lightGray
+ assertEquals(Color.lightGray, rcf
+ .getResidueColour(av.getResidueShading(), null, seq, 3, null));
+
+ newColours[23] = Color.pink;
+ av.setGlobalColourScheme(new UserColourScheme(newColours));
+
+ // gap colour specified as pink
+ assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 3, null));
+ }
+}
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.renderer;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignViewport;
+import jalview.gui.JvOptionPane;
+import jalview.schemes.UserColourScheme;
+import jalview.schemes.ZappoColourScheme;
+
+import java.awt.Color;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ResidueColourFinderTest
+{
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueColour_zappo()
+ {
+ SequenceI seq = new Sequence("name", "MATVLGSPRAPAFF"); // FER1_MAIZE...
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new ResidueColourFinder();
+ av.setGlobalColourScheme(new ZappoColourScheme());
+
+ // @see ResidueProperties.zappo
+ assertEquals(Color.pink,
+ rcf.getResidueColour(av.getResidueShading(), null, seq, 0,
+ null)); // M
+ assertEquals(Color.green,
+ rcf.getResidueColour(av.getResidueShading(), null, seq, 2,
+ null)); // T
+ assertEquals(Color.magenta,
+ rcf.getResidueColour(av.getResidueShading(), null, seq, 5,
+ null)); // G
+ assertEquals(Color.orange,
+ rcf.getResidueColour(av.getResidueShading(), null, seq, 12,
+ null)); // F
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueColour_none()
+ {
+ SequenceI seq = new Sequence("name", "MA--TVLGSPRAPAFF");
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new ResidueColourFinder();
+
+ assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 0, null));
+ assertEquals(Color.white, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 2, null));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testGetResidueColour_userdef()
+ {
+ SequenceI seq = new Sequence("name", "MAT--GSPRAPAFF"); // FER1_MAIZE... + a
+ // gap
+ AlignmentI al = new Alignment(new SequenceI[] { seq });
+ final AlignViewport av = new AlignViewport(al);
+ ResidueColourFinder rcf = new ResidueColourFinder();
+
+ Color[] newColours = new Color[24];
+ for (int i = 0; i < 24; i++)
+ {
+ newColours[i] = null;
+ }
+
+ av.setGlobalColourScheme(new UserColourScheme(newColours));
+
+ // gap colour not specified so gaps are null
+ assertEquals(null, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 3, null));
+
+ newColours[23] = Color.pink;
+ av.setGlobalColourScheme(new UserColourScheme(newColours));
+
+ // gap colour specified as pink
+ assertEquals(Color.pink, rcf.getResidueColour(av.getResidueShading(),
+ null, seq, 3, null));
+ }
+
+ // TODO more tests for getResidueBoxColour covering groups, feature rendering,
+ // gaps, overview...
+
+}