+/*
+ * 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.schemes;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;
import jalview.datamodel.SequenceFeature;
+import jalview.gui.JvOptionPane;
+import jalview.util.ColorUtils;
import jalview.util.Format;
import java.awt.Color;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class FeatureColourTest
{
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ @Test(groups = { "Functional" })
+ public void testCopyConstructor()
+ {
+ /*
+ * plain colour
+ */
+ FeatureColour fc = new FeatureColour(Color.RED);
+ FeatureColour fc1 = new FeatureColour(fc);
+ assertTrue(fc1.getColour().equals(Color.RED));
+ assertFalse(fc1.isGraduatedColour());
+ assertFalse(fc1.isColourByLabel());
+
+ /*
+ * min-max colour
+ */
+ fc = new FeatureColour(Color.gray, Color.black, 10f, 20f);
+ fc.setAboveThreshold(true);
+ fc.setThreshold(12f);
+ fc1 = new FeatureColour(fc);
+ assertTrue(fc1.isGraduatedColour());
+ assertFalse(fc1.isColourByLabel());
+ assertTrue(fc1.isAboveThreshold());
+ assertEquals(12f, fc1.getThreshold());
+ assertEquals(Color.gray, fc1.getMinColour());
+ assertEquals(Color.black, fc1.getMaxColour());
+ assertEquals(10f, fc1.getMin());
+ assertEquals(20f, fc1.getMax());
+
+ /*
+ * colour by label
+ */
+ fc = new FeatureColour();
+ fc.setColourByLabel(true);
+ fc1 = new FeatureColour(fc);
+ assertTrue(fc1.isColourByLabel());
+ assertFalse(fc1.isGraduatedColour());
+ }
+
@Test(groups = { "Functional" })
public void testIsColored_simpleColour()
{
fc.setColourByLabel(true);
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
null);
- Color expected = UserColourScheme.createColourFromName("desc");
+ Color expected = ColorUtils.createColourFromName("desc");
assertEquals(expected, fc.getColor(sf));
}
@Test(groups = { "Functional" })
public void testGetColor_Graduated()
{
- // graduated colour from score 0 to 100, gray(128, 128, 128) to red(255, 0, 0)
+ // graduated colour from score 0 to 100, gray(128, 128, 128) to red(255, 0,
+ // 0)
FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f);
// feature score is 75 which is 3/4 of the way from GRAY to RED
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f,
String redHex = Format.getHexString(Color.RED);
String hexColour = redHex;
assertEquals("domain\t" + hexColour, fc.toJalviewFormat("domain"));
-
+
/*
* colour by label (no threshold)
*/
*/
fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f);
String greenHex = Format.getHexString(Color.GREEN);
- String expected = String.format("domain\t%s|%s|12.0|25.0|none",
+ String expected = String.format("domain\t%s|%s|abso|12.0|25.0|none",
greenHex, redHex);
assertEquals(expected, fc.toJalviewFormat("domain"));
* colour ranges over the actual score ranges (not min/max)
*/
fc.setAutoScaled(true);
- expected = String.format("domain\t%s|%s|abso|12.0|25.0|none", greenHex,
+ expected = String.format("domain\t%s|%s|12.0|25.0|none", greenHex,
redHex);
assertEquals(expected, fc.toJalviewFormat("domain"));
*/
fc.setThreshold(12.5f);
fc.setBelowThreshold(true);
- expected = String.format("domain\t%s|%s|abso|12.0|25.0|below|12.5",
+ expected = String.format("domain\t%s|%s|12.0|25.0|below|12.5",
greenHex, redHex);
assertEquals(expected, fc.toJalviewFormat("domain"));
*/
fc.setThreshold(12.5f);
fc.setAboveThreshold(true);
+ fc.setAutoScaled(false);
expected = String.format("domain\t%s|%s|abso|12.0|25.0|above|12.5",
greenHex, redHex);
assertEquals(expected, fc.toJalviewFormat("domain"));
assertEquals(Color.GREEN, fc.getMaxColour());
assertEquals(10f, fc.getMin());
assertEquals(20f, fc.getMax());
+
+ descriptor = String
+ .format("blue|255,0,255|absolute|20.0|95.0|below|66.0");
+ fc = FeatureColour.parseJalviewFeatureColour(descriptor);
+ assertTrue(fc.isGraduatedColour());
}
}