JAL-2094 first pass with jalview.api.ColorI interface
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 May 2016 13:21:55 +0000 (14:21 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 5 May 2016 13:21:55 +0000 (14:21 +0100)
70 files changed:
examples/exampleFeatures.txt
src/MCview/AppletPDBCanvas.java
src/MCview/Atom.java
src/MCview/Bond.java
src/MCview/PDBCanvas.java
src/MCview/PDBChain.java
src/jalview/api/AlignViewportI.java
src/jalview/api/FeatureColourI.java
src/jalview/api/FeatureRenderer.java
src/jalview/api/SequenceRenderer.java
src/jalview/api/ViewStyleI.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AnnotationColourChooser.java
src/jalview/appletgui/FeatureColourChooser.java
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/FeatureSettings.java
src/jalview/appletgui/IdCanvas.java
src/jalview/appletgui/OverviewPanel.java
src/jalview/appletgui/RotatableCanvas.java
src/jalview/appletgui/SeqCanvas.java
src/jalview/appletgui/SequenceRenderer.java
src/jalview/appletgui/TreeCanvas.java
src/jalview/appletgui/UserDefinedColours.java
src/jalview/controller/AlignViewController.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/ext/ensembl/EnsemblGene.java
src/jalview/ext/jmol/JmolCommands.java
src/jalview/ext/rbvi/chimera/ChimeraCommands.java
src/jalview/ext/varna/VarnaCommands.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationExporter.java
src/jalview/gui/AppVarna.java
src/jalview/gui/FeatureColourChooser.java
src/jalview/gui/FeatureRenderer.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/IdCanvas.java
src/jalview/gui/Jalview2XML.java
src/jalview/gui/Jalview2XML_V1.java
src/jalview/gui/RotatableCanvas.java
src/jalview/gui/SeqCanvas.java
src/jalview/gui/SequenceRenderer.java
src/jalview/gui/TextColourChooser.java
src/jalview/gui/TreeCanvas.java
src/jalview/io/AnnotationFile.java
src/jalview/io/FeaturesFile.java
src/jalview/io/HTMLOutput.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JSONFile.java
src/jalview/io/PDBFeatureSettings.java
src/jalview/io/packed/JalviewDataset.java
src/jalview/io/packed/ParsePackedSet.java
src/jalview/renderer/seqfeatures/FeatureRenderer.java
src/jalview/schemes/FeatureColour.java [new file with mode: 0644]
src/jalview/schemes/FeatureColourAdapter.java
src/jalview/schemes/UserColourScheme.java
src/jalview/util/ColorUtils.java
src/jalview/util/Format.java
src/jalview/viewmodel/AlignmentViewport.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java
src/jalview/viewmodel/seqfeatures/FeatureRendererSettings.java
src/jalview/viewmodel/styles/ViewStyle.java
src/jalview/ws/jws1/SeqSearchWSThread.java
src/jalview/ws/jws2/AADisorderClient.java
test/MCview/PDBChainTest.java
test/jalview/ext/rbvi/chimera/ChimeraCommandsTest.java
test/jalview/gui/SequenceRendererTest.java
test/jalview/io/FeaturesFileTest.java
test/jalview/schemes/FeatureColourTest.java [new file with mode: 0644]
test/jalview/util/ColorUtilsTest.java
test/jalview/viewmodel/styles/ViewStyleTest.java

index dfadb50..b7038f5 100755 (executable)
@@ -1,5 +1,5 @@
 ST-TURN-IIL    blue|255,0,255|absolute|20.0|95.0|below|66.0
-GAMMA-TURN-CLASSIC             red|0,255,255|20.0|95.0|below|66.0
+GAMMA-TURN-CLASSIC     red|0,255,255|20.0|95.0|below|66.0
 BETA-TURN-IR   9a6a94
 BETA-TURN-IL   d6a6ca
 BETA-BULGE     1dc451
@@ -22,8 +22,10 @@ NEST-RL      3e16b2
 ASX-TURN-IIL   a67c98
 BETA-TURN-IIR  c79792
 PHOSPHORYLATION (T)    c88395
-BETA-TURN-IIL  8b5b50
-ST-MOTIF       ac25a1
+BETA-TURN-IIL  label
+#8b5b50
+ST-MOTIF       label|||0|0
+#ac25a1
 
 STARTGROUP     uniprot
 Iron-sulfur (2Fe-2S)   FER_CAPAA       -1      39      39      METAL
index df98833..89318d5 100644 (file)
@@ -27,10 +27,12 @@ import jalview.appletgui.SequenceRenderer;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.io.StructureFile;
+import jalview.schemes.Colour;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -584,8 +586,8 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
         for (int i = 0; i < chain.bonds.size(); i++)
         {
           Bond tmp = chain.bonds.elementAt(i);
-          tmp.startCol = Color.lightGray;
-          tmp.endCol = Color.lightGray;
+          tmp.startCol = Colour.lightGray;
+          tmp.endCol = Colour.lightGray;
           if (chain != mainchain)
           {
             continue;
@@ -660,26 +662,27 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       {
         if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
         {
-          g.setColor(tmpBond.startCol.darker().darker());
+          g.setColor(ColorUtils.getColor(tmpBond.startCol).darker()
+                  .darker());
           drawLine(g, xstart, ystart, xmid, ymid);
 
-          g.setColor(tmpBond.endCol.darker().darker());
+          g.setColor(ColorUtils.getColor(tmpBond.endCol).darker().darker());
           drawLine(g, xmid, ymid, xend, yend);
         }
         else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
         {
-          g.setColor(tmpBond.startCol.darker());
+          g.setColor(ColorUtils.getColor(tmpBond.startCol).darker());
           drawLine(g, xstart, ystart, xmid, ymid);
 
-          g.setColor(tmpBond.endCol.darker());
+          g.setColor(ColorUtils.getColor(tmpBond.endCol).darker());
           drawLine(g, xmid, ymid, xend, yend);
         }
         else
         {
-          g.setColor(tmpBond.startCol);
+          g.setColor(ColorUtils.getColor(tmpBond.startCol));
           drawLine(g, xstart, ystart, xmid, ymid);
 
-          g.setColor(tmpBond.endCol);
+          g.setColor(ColorUtils.getColor(tmpBond.endCol));
           drawLine(g, xmid, ymid, xend, yend);
         }
 
@@ -704,9 +707,9 @@ public class AppletPDBCanvas extends Panel implements MouseListener,
       }
       else if (!depthcue && !bymolecule)
       {
-        g.setColor(tmpBond.startCol);
+        g.setColor(ColorUtils.getColor(tmpBond.startCol));
         drawLine(g, xstart, ystart, xmid, ymid);
-        g.setColor(tmpBond.endCol);
+        g.setColor(ColorUtils.getColor(tmpBond.endCol));
         drawLine(g, xmid, ymid, xend, yend);
       }
       else
index 68a7c21..7db845b 100755 (executable)
  */
 package MCview;
 
+import jalview.api.ColorI;
+import jalview.schemes.Colour;
 import jalview.schemes.ResidueProperties;
 
-import java.awt.Color;
-
 public class Atom
 {
   public float x;
@@ -46,7 +46,7 @@ public class Atom
 
   public int type;
 
-  Color color = Color.lightGray;
+  ColorI color = Colour.lightGray;
 
   public String chain;
 
index 371ccd5..57d77bd 100755 (executable)
@@ -20,7 +20,8 @@
  */
 package MCview;
 
-import java.awt.Color;
+import jalview.api.ColorI;
+import jalview.schemes.Colour;
 
 public class Bond
 {
@@ -28,9 +29,9 @@ public class Bond
 
   float[] end;
 
-  Color startCol = Color.lightGray;
+  ColorI startCol = Colour.lightGray;
 
-  Color endCol = Color.lightGray;
+  ColorI endCol = Colour.lightGray;
 
   public Atom at1;
 
index 1c7a1f7..d8e0366 100644 (file)
@@ -27,10 +27,12 @@ import jalview.gui.AlignmentPanel;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.SequenceRenderer;
 import jalview.io.StructureFile;
+import jalview.schemes.Colour;
 import jalview.structure.AtomSpec;
 import jalview.structure.StructureListener;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.awt.Dimension;
@@ -553,8 +555,8 @@ public class PDBCanvas extends JPanel implements MouseListener,
         for (int i = 0; i < chain.bonds.size(); i++)
         {
           Bond tmp = chain.bonds.elementAt(i);
-          tmp.startCol = Color.lightGray;
-          tmp.endCol = Color.lightGray;
+          tmp.startCol = Colour.lightGray;
+          tmp.endCol = Colour.lightGray;
           if (chain != mainchain)
           {
             continue;
@@ -629,26 +631,27 @@ public class PDBCanvas extends JPanel implements MouseListener,
         if (tmpBond.start[2] < (centre[2] - (maxwidth / 6)))
         {
 
-          g.setColor(tmpBond.startCol.darker().darker());
+          g.setColor(ColorUtils.getColor(tmpBond.startCol).darker()
+                  .darker());
           drawLine(g, xstart, ystart, xmid, ymid);
-          g.setColor(tmpBond.endCol.darker().darker());
+          g.setColor(ColorUtils.getColor(tmpBond.endCol).darker().darker());
           drawLine(g, xmid, ymid, xend, yend);
 
         }
         else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6)))
         {
-          g.setColor(tmpBond.startCol.darker());
+          g.setColor(ColorUtils.getColor(tmpBond.startCol).darker());
           drawLine(g, xstart, ystart, xmid, ymid);
 
-          g.setColor(tmpBond.endCol.darker());
+          g.setColor(ColorUtils.getColor(tmpBond.endCol).darker());
           drawLine(g, xmid, ymid, xend, yend);
         }
         else
         {
-          g.setColor(tmpBond.startCol);
+          g.setColor(ColorUtils.getColor(tmpBond.startCol));
           drawLine(g, xstart, ystart, xmid, ymid);
 
-          g.setColor(tmpBond.endCol);
+          g.setColor(ColorUtils.getColor(tmpBond.endCol));
           drawLine(g, xmid, ymid, xend, yend);
         }
       }
@@ -672,9 +675,9 @@ public class PDBCanvas extends JPanel implements MouseListener,
       }
       else if (!depthcue && !bymolecule)
       {
-        g.setColor(tmpBond.startCol);
+        g.setColor(ColorUtils.getColor(tmpBond.startCol));
         drawLine(g, xstart, ystart, xmid, ymid);
-        g.setColor(tmpBond.endCol);
+        g.setColor(ColorUtils.getColor(tmpBond.endCol));
         drawLine(g, xmid, ymid, xend, yend);
       }
       else
@@ -684,14 +687,16 @@ public class PDBCanvas extends JPanel implements MouseListener,
 
       if (highlightBond1 != null && highlightBond1 == tmpBond)
       {
-        g.setColor(tmpBond.endCol.brighter().brighter().brighter()
+        g.setColor(ColorUtils.getColor(tmpBond.endCol).brighter()
+                .brighter().brighter()
                 .brighter());
         drawLine(g, xmid, ymid, xend, yend);
       }
 
       if (highlightBond2 != null && highlightBond2 == tmpBond)
       {
-        g.setColor(tmpBond.startCol.brighter().brighter().brighter()
+        g.setColor(ColorUtils.getColor(tmpBond.startCol).brighter()
+                .brighter().brighter()
                 .brighter());
         drawLine(g, xstart, ystart, xmid, ymid);
       }
index 3b84ee3..e048cd6 100755 (executable)
 package MCview;
 
 import jalview.analysis.AlignSeq;
+import jalview.api.ColorI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.Mapping;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureMapping;
@@ -486,26 +488,26 @@ public class PDBChain
       }
       else
       {
-        b.startCol = Color.gray;
-        b.endCol = Color.gray;
+        b.startCol = Colour.gray;
+        b.endCol = Colour.gray;
       }
     }
   }
 
-  public static Color getChargeColour(String resName)
+  public static ColorI getChargeColour(String resName)
   {
-    Color result = Color.lightGray;
+    ColorI result = Colour.lightGray;
     if ("ASP".equals(resName) || "GLU".equals(resName))
     {
-      result = Color.red;
+      result = Colour.red;
     }
     else if ("LYS".equals(resName) || "ARG".equals(resName))
     {
-      result = Color.blue;
+      result = Colour.blue;
     }
     else if ("CYS".equals(resName))
     {
-      result = Color.yellow;
+      result = Colour.yellow;
     }
     return result;
   }
@@ -525,15 +527,17 @@ public class PDBChain
       try
       {
         index = ResidueProperties.aa3Hash.get(b.at1.resName).intValue();
-        b.startCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+        b.startCol = new Colour(cs.findColour(ResidueProperties.aa[index]
+                .charAt(0)));
 
         index = ResidueProperties.aa3Hash.get(b.at2.resName).intValue();
-        b.endCol = cs.findColour(ResidueProperties.aa[index].charAt(0));
+        b.endCol = new Colour(cs.findColour(ResidueProperties.aa[index]
+                .charAt(0)));
 
       } catch (Exception e)
       {
-        b.startCol = Color.gray;
-        b.endCol = Color.gray;
+        b.startCol = Colour.gray;
+        b.endCol = Colour.gray;
       }
     }
   }
@@ -542,8 +546,8 @@ public class PDBChain
   {
     for (Bond b : bonds)
     {
-      b.startCol = col;
-      b.endCol = col;
+      b.startCol = new Colour(col);
+      b.endCol = new Colour(col);
     }
   }
 
index 45e77ba..c7d7a37 100644 (file)
@@ -31,7 +31,6 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 
-import java.awt.Color;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -179,9 +178,9 @@ public interface AlignViewportI extends ViewStyleI
   void updateGroupAnnotationSettings(boolean applyGlobalSettings,
           boolean preserveNewGroupSettings);
 
-  void setSequenceColour(SequenceI seq, Color col);
+  void setSequenceColour(SequenceI seq, ColorI col);
 
-  Color getSequenceColour(SequenceI seq);
+  ColorI getSequenceColour(SequenceI seq);
 
   void updateSequenceIdColours();
 
index d8363f4..f68d7a7 100644 (file)
@@ -1,6 +1,6 @@
 package jalview.api;
 
-import java.awt.Color;
+import jalview.datamodel.SequenceFeature;
 
 public interface FeatureColourI
 {
@@ -18,21 +18,21 @@ public interface FeatureColourI
    * 
    * @return
    */
-  Color getColour();
+  ColorI getColour();
 
   /**
    * Returns the minimum colour (when isGraduatedColour answers true)
    * 
    * @return
    */
-  Color getMinColour();
+  ColorI getMinColour();
 
   /**
    * Returns the maximum colour (when isGraduatedColour answers true)
    * 
    * @return
    */
-  Color getMaxColour();
+  ColorI getMaxColour();
 
   /**
    * Answers true if the feature is coloured by label (description); only
@@ -73,10 +73,71 @@ public interface FeatureColourI
    */
   float getThreshold();
 
+  float getMax();
+
+  /**
+   * Returns the minimum score of the graduated colour range
+   * 
+   * @return
+   */
+  float getMin();
+
+  /**
+   * Answers true if either isAboveThreshold or isBelowThreshold answers true
+   * 
+   * @return
+   */
+  boolean hasThreshold();
+
+  /**
+   * Returns the computed colour for the given sequence feature
+   * 
+   * @param feature
+   * @return
+   */
+  ColorI getColor(SequenceFeature feature);
+
+  /**
+   * Answers true if the feature has a simple colour, or is coloured by label,
+   * or has a graduated colour and the score of this feature instance is within
+   * the range to render (if any), i.e. does not lie below or above any
+   * threshold set.
+   * 
+   * @param feature
+   * @return
+   */
+  boolean isColored(SequenceFeature feature);
+
   /**
-   * Answers true if ?
+   * Update the min-max range for a graduated colour scheme
+   * 
+   * @param min
+   * @param max
+   */
+  void updateBounds(float min, float max);
+
+  /**
+   * Returns the colour in Jalview features file format
    * 
    * @return
    */
-  boolean isLowToHigh();
+  String toJalviewFormat(String featureType);
+
+  void setThreshold(float f);
+
+  boolean isAutoScaled();
+
+  void setAutoScaled(boolean b);
+
+  boolean isSimpleColour();
+
+  void setAboveThreshold(boolean b);
+
+  void setThresholdMinMax(boolean b);
+
+  void setBelowThreshold(boolean b);
+
+  void setColourByLabel(boolean b);
+
+  void setGraduatedColour(boolean b);
 }
index d9795a6..5477f57 100644 (file)
@@ -23,7 +23,6 @@ package jalview.api;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 
-import java.awt.Color;
 import java.util.List;
 import java.util.Map;
 
@@ -48,7 +47,7 @@ public interface FeatureRenderer
    *          - column position
    * @return
    */
-  Color findFeatureColour(Color col, SequenceI sequenceI, int r);
+  ColorI findFeatureColour(ColorI col, SequenceI sequenceI, int r);
 
   /**
    * trigger the feature discovery process for a newly created feature renderer.
@@ -60,17 +59,15 @@ public interface FeatureRenderer
    * @param ft
    * @return display style for a feature
    */
-  Object getFeatureStyle(String ft);
+  FeatureColourI getFeatureStyle(String ft);
 
   /**
    * update the feature style for a particular feature
    * 
-   * @param ft
-   * @param ggc
-   *          - currently allows java.awt.Color and
-   *          jalview.schemes.GraduatedColor
+   * @param featureType
+   * @param featureColour
    */
-  void setColour(String ft, Object ggc);
+  void setColour(String featureType, FeatureColourI featureColour);
 
   AlignViewportI getViewport();
 
@@ -85,7 +82,7 @@ public interface FeatureRenderer
    * 
    * @return
    */
-  Map<String, Object> getFeatureColours();
+  Map<String, FeatureColourI> getFeatureColours();
 
   /**
    * query the alignment view to find all features
@@ -100,7 +97,7 @@ public interface FeatureRenderer
    * 
    * @return
    */
-  Map<String, Object> getDisplayedFeatureCols();
+  Map<String, FeatureColourI> getDisplayedFeatureCols();
 
   /**
    * get all registered groups
index d708902..81bb386 100644 (file)
@@ -22,13 +22,11 @@ package jalview.api;
 
 import jalview.datamodel.SequenceI;
 
-import java.awt.Color;
-
 public interface SequenceRenderer
 {
 
-  Color getResidueBoxColour(SequenceI sequenceI, int r);
+  ColorI getResidueBoxColour(SequenceI sequenceI, int r);
 
-  Color getResidueColour(SequenceI seq, int position, FeatureRenderer fr);
+  ColorI getResidueColour(SequenceI seq, int position, FeatureRenderer fr);
 
 }
index db82dcf..2375a72 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.api;
 
-import java.awt.Color;
-
 public interface ViewStyleI
 {
 
@@ -148,9 +146,9 @@ public interface ViewStyleI
    */
   void setColourByReferenceSeq(boolean colourByReferenceSeq);
 
-  Color getTextColour();
+  ColorI getTextColour();
 
-  Color getTextColour2();
+  ColorI getTextColour2();
 
   int getThresholdTextColour();
 
@@ -166,11 +164,11 @@ public interface ViewStyleI
 
   void setShowColourText(boolean showColourText);
 
-  void setTextColour(Color textColour);
+  void setTextColour(ColorI textColour);
 
   void setThresholdTextColour(int thresholdTextColour);
 
-  void setTextColour2(Color textColour2);
+  void setTextColour2(ColorI textColour2);
 
   boolean isSeqNameItalics();
 
index e5f0053..8f1f2fd 100644 (file)
@@ -25,6 +25,7 @@ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
 import jalview.api.FeatureRenderer;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.api.SequenceStructureBinding;
@@ -367,7 +368,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     boolean featuresFile = false;
     try
     {
-      Map<String, Object> colours = alignPanel.seqPanel.seqCanvas
+      Map<String, FeatureColourI> colours = alignPanel.seqPanel.seqCanvas
               .getFeatureRenderer().getFeatureColours();
       boolean relaxedIdMatching = viewport.applet.getDefaultParameter(
               "relaxedidmatch", false);
@@ -1399,7 +1400,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     return annotation;
   }
 
-  private Map<String, Object> getDisplayedFeatureCols()
+  private Map<String, FeatureColourI> getDisplayedFeatureCols()
   {
     if (alignPanel.getFeatureRenderer() != null
             && viewport.getFeaturesDisplayed() != null)
index 57b182c..15346a3 100644 (file)
@@ -309,6 +309,7 @@ public class AnnotationColourChooser extends Panel implements
 
   Checkbox thresholdIsMin = new Checkbox();
 
+  @Override
   public void actionPerformed(ActionEvent evt)
   {
     if (evt.getSource() == thresholdValue)
@@ -351,6 +352,7 @@ public class AnnotationColourChooser extends Panel implements
     }
   }
 
+  @Override
   public void itemStateChanged(ItemEvent evt)
   {
     if (evt.getSource() == currentColours)
@@ -368,6 +370,7 @@ public class AnnotationColourChooser extends Panel implements
     changeColour();
   }
 
+  @Override
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
     if (!adjusting)
@@ -552,23 +555,28 @@ public class AnnotationColourChooser extends Panel implements
 
   }
 
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
+  @Override
   public void mousePressed(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
     ap.paintAlignment(true);
   }
 
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseExited(MouseEvent evt)
   {
   }
index 46a67c4..7638b3b 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.GraphLine;
 import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Checkbox;
@@ -60,9 +63,9 @@ public class FeatureColourChooser extends Panel implements ActionListener,
 
   // AlignmentPanel ap;
 
-  GraduatedColor cs;
+  FeatureColourI cs;
 
-  Object oldcs;
+  FeatureColourI oldcs;
 
   Hashtable oldgroupColours;
 
@@ -91,29 +94,30 @@ public class FeatureColourChooser extends Panel implements ActionListener,
   {
     this.type = type;
     fr = frenderer;
-    float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
+    float mm[] = fr.getMinMax().get(type)[0];
     min = mm[0];
     max = mm[1];
     oldcs = fr.getFeatureColours().get(type);
-    if (oldcs instanceof GraduatedColor)
+    if (oldcs.isGraduatedColour())
     {
-      cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
+      cs = new FeatureColour((FeatureColour) oldcs, min, max);
     }
     else
     {
       // promote original color to a graduated color
       Color bl = Color.black;
-      if (oldcs instanceof Color)
+      if (oldcs.isSimpleColour())
       {
-        bl = (Color) oldcs;
+        bl = ColorUtils.getColor(oldcs.getColour());
       }
       // original colour becomes the maximum colour
-      cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
+      cs = new FeatureColour(new Colour(Color.white), new Colour(bl),
+              mm[0], mm[1]);
     }
-    minColour.setBackground(cs.getMinColor());
-    maxColour.setBackground(cs.getMaxColor());
-    minColour.setForeground(cs.getMinColor());
-    maxColour.setForeground(cs.getMaxColor());
+    minColour.setBackground(ColorUtils.getColor(cs.getMinColour()));
+    maxColour.setBackground(ColorUtils.getColor(cs.getMaxColour()));
+    minColour.setForeground(ColorUtils.getColor(cs.getMinColour()));
+    maxColour.setForeground(ColorUtils.getColor(cs.getMaxColour()));
     colourFromLabel.setState(cs.isColourByLabel());
     adjusting = true;
 
@@ -123,10 +127,8 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     } catch (Exception ex)
     {
     }
-    threshold
-            .select(cs.getThreshType() == AnnotationColourGradient.NO_THRESHOLD ? 0
-                    : cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
-                            : 2);
+    threshold.select(cs.isAboveThreshold() ? 1 : (cs.isBelowThreshold() ? 2
+            : 0));
 
     adjusting = false;
     changeColour();
@@ -259,6 +261,7 @@ public class FeatureColourChooser extends Panel implements ActionListener,
 
   private GraphLine threshline;
 
+  @Override
   public void actionPerformed(ActionEvent evt)
   {
     if (evt.getSource() == thresholdValue)
@@ -286,6 +289,7 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     }
   }
 
+  @Override
   public void itemStateChanged(ItemEvent evt)
   {
     maxColour.setEnabled(!colourFromLabel.getState());
@@ -293,27 +297,28 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     changeColour();
   }
 
+  @Override
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
     if (!adjusting)
     {
-      thresholdValue.setText(((float) slider.getValue() / 1000f) + "");
+      thresholdValue.setText((slider.getValue() / 1000f) + "");
       valueChanged();
     }
   }
 
   protected void valueChanged()
   {
-    threshline.value = (float) slider.getValue() / 1000f;
-    cs.setThresh(threshline.value);
+    threshline.value = slider.getValue() / 1000f;
+    cs.setThreshold(threshline.value);
     changeColour();
     PaintRefresher.Refresh(this, fr.getViewport().getSequenceSetId());
     // ap.paintAlignment(false);
   }
 
-  public void minColour_actionPerformed(Color newCol)
+  public void minColour_actionPerformed(Color c)
   {
-    if (newCol == null)
+    if (c == null)
     {
       UserDefinedColours udc = new UserDefinedColours(this,
               minColour.getBackground(), owner,
@@ -321,8 +326,8 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     }
     else
     {
-      minColour.setBackground(newCol);
-      minColour.setForeground(newCol);
+      minColour.setBackground(c);
+      minColour.setForeground(c);
       minColour.repaint();
       changeColour();
     }
@@ -369,8 +374,9 @@ public class FeatureColourChooser extends Panel implements ActionListener,
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
-    GraduatedColor acg = new GraduatedColor(minColour.getBackground(),
-            maxColour.getBackground(), min, max);
+    FeatureColour acg = new FeatureColour(new Colour(
+            minColour.getBackground()), new Colour(
+            maxColour.getBackground()), min, max);
 
     acg.setColourByLabel(colourFromLabel.getState());
     maxColour.setEnabled(!colourFromLabel.getState());
@@ -393,7 +399,7 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
     {
       adjusting = true;
-      acg.setThresh(threshline.value);
+      acg.setThreshold(threshline.value);
 
       float range = max * 1000f - min * 1000f;
 
@@ -406,17 +412,17 @@ public class FeatureColourChooser extends Panel implements ActionListener,
       adjusting = false;
     }
 
-    acg.setThreshType(aboveThreshold);
+    acg.setAboveThreshold(true);
     if (thresholdIsMin.getState()
             && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
     {
       if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
       {
-        acg = new GraduatedColor(acg, threshline.value, max);
+        acg = new FeatureColour(acg, threshline.value, max);
       }
       else
       {
-        acg = new GraduatedColor(acg, min, threshline.value);
+        acg = new FeatureColour(acg, min, threshline.value);
       }
     }
 
@@ -434,14 +440,17 @@ public class FeatureColourChooser extends Panel implements ActionListener,
 
   }
 
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
+  @Override
   public void mousePressed(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
     if (evt.getSource() == minColour || evt.getSource() == maxColour)
@@ -456,10 +465,12 @@ public class FeatureColourChooser extends Panel implements ActionListener,
     // ap.paintAlignment(true);
   }
 
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseExited(MouseEvent evt)
   {
   }
index 03d4ce6..b979674 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.io.FeaturesFile;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -43,6 +47,9 @@ import java.awt.TextArea;
 import java.awt.TextField;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.Hashtable;
 
 /**
  * DOCUMENT ME!
@@ -88,51 +95,35 @@ public class FeatureRenderer extends
     /**
      * render a feature style in the amend feature dialog box
      */
-    public void updateColor(Object newcol)
+    public void updateColor(FeatureColourI newcol)
     {
-
-      Color bg, col = null;
-      GraduatedColor gcol = null;
+      Color bg = null;
       String vlabel = "";
-      if (newcol instanceof Color)
-      {
-        isGcol = false;
-        col = (Color) newcol;
-        gcol = null;
-      }
-      else if (newcol instanceof GraduatedColor)
+      if (newcol.isSimpleColour())
       {
-        isGcol = true;
-        gcol = (GraduatedColor) newcol;
-        col = null;
+        bg = ColorUtils.getColor(newcol.getColour());
+        setBackground(bg);
       }
       else
       {
-        throw new Error(
-                MessageManager
-                        .getString("error.invalid_colour_for_mycheckbox"));
-      }
-      if (col != null)
-      {
-        setBackground(bg = col);
-      }
-      else
-      {
-        if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
+        if (newcol.isAboveThreshold())
+        {
+          vlabel += " (>)";
+        }
+        else if (newcol.isBelowThreshold())
         {
-          vlabel += " "
-                  + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
-                          : "(<)");
+          vlabel += " (<)";
         }
-        if (isColourByLabel = gcol.isColourByLabel())
+
+        if (isColourByLabel = newcol.isColourByLabel())
         {
           setBackground(bg = Color.white);
           vlabel += " (by Label)";
         }
         else
         {
-          setBackground(bg = gcol.getMinColor());
-          maxCol = gcol.getMaxColor();
+          setBackground(bg = ColorUtils.getColor(newcol.getMinColour()));
+          maxCol = ColorUtils.getColor(newcol.getMaxColour());
         }
       }
       label = vlabel;
@@ -239,11 +230,12 @@ public class FeatureRenderer extends
             ap.seqPanel.seqCanvas.highlightSearchResults(highlight);
 
           }
-          Object col = getFeatureStyle(name.getText());
+          FeatureColourI col = getFeatureStyle(name.getText());
           if (col == null)
           {
-            col = new jalview.schemes.UserColourScheme()
+            Color generatedColour = UserColourScheme
                     .createColourFromName(name.getText());
+            col = new FeatureColour(new Colour(generatedColour));
           }
 
           colourPanel.updateColor(col);
@@ -351,21 +343,16 @@ public class FeatureRenderer extends
     start.setText(features[0].getBegin() + "");
     end.setText(features[0].getEnd() + "");
     description.setText(features[0].getDescription());
-    Color col = getColour(name.getText());
-    if (col == null)
-    {
-      col = new jalview.schemes.UserColourScheme()
-              .createColourFromName(name.getText());
-    }
-    Object fcol = getFeatureStyle(name.getText());
+    // lookup (or generate) the feature colour
+    FeatureColourI fcol = getFeatureStyle(name.getText());
     // simply display the feature color in a box
     colourPanel.updateColor(fcol);
     dialog.setResizable(true);
     // TODO: render the graduated color in the box.
-    colourPanel.addMouseListener(new java.awt.event.MouseAdapter()
+    colourPanel.addMouseListener(new MouseAdapter()
     {
       @Override
-      public void mousePressed(java.awt.event.MouseEvent evt)
+      public void mousePressed(MouseEvent evt)
       {
         if (!colourPanel.isGcol)
         {
@@ -373,15 +360,14 @@ public class FeatureRenderer extends
         }
         else
         {
-          FeatureColourChooser fcc = new FeatureColourChooser(
-                  ap.alignFrame, name.getText());
+          new FeatureColourChooser(ap.alignFrame, name.getText());
           dialog.transferFocus();
         }
       }
     });
     dialog.setVisible(true);
 
-    jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
+    FeaturesFile ffile = new FeaturesFile();
 
     if (dialog.accept)
     {
@@ -410,7 +396,9 @@ public class FeatureRenderer extends
         if (!colourPanel.isGcol)
         {
           // update colour - otherwise its already done.
-          setColour(sf.type, colourPanel.getBackground());
+          setColour(
+                  sf.type,
+                  new FeatureColour(new Colour(colourPanel.getBackground())));
         }
         try
         {
@@ -450,7 +438,8 @@ public class FeatureRenderer extends
         {
           setGroupVisibility(lastFeatureGroupAdded, true);
         }
-        setColour(lastFeatureAdded, newColour); // was fcol
+        setColour(lastFeatureAdded,
+                new FeatureColour(new Colour(newColour))); // was fcol
         setVisible(lastFeatureAdded);
         findAllFeatures(false); // different to original applet behaviour ?
         // findAllFeatures();
index 7ae318c..e765f31 100755 (executable)
  */
 package jalview.appletgui;
 
+import jalview.api.FeatureColourI;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceFeature;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -190,10 +190,10 @@ public class FeatureSettings extends Panel implements ItemListener,
           int x, int y)
   {
     final String type = check.type;
-    final Object typeCol = fr.getFeatureStyle(type);
-    java.awt.PopupMenu men = new PopupMenu(MessageManager.formatMessage(
+    final FeatureColourI typeCol = fr.getFeatureStyle(type);
+    PopupMenu men = new PopupMenu(MessageManager.formatMessage(
             "label.settings_for_type", new String[] { type }));
-    java.awt.MenuItem scr = new MenuItem(
+    MenuItem scr = new MenuItem(
             MessageManager.getString("label.sort_by_score"));
     men.add(scr);
     final FeatureSettings me = this;
@@ -243,7 +243,7 @@ public class FeatureSettings extends Panel implements ItemListener,
         // graduated colourschemes for those where minmax exists for the
         // positional features
         MenuItem mxcol = new MenuItem(
-                (typeCol instanceof Color) ? "Graduated Colour"
+                (typeCol.isSimpleColour()) ? "Graduated Colour"
                         : "Single Colour");
         men.add(mxcol);
         mxcol.addActionListener(new ActionListener()
@@ -252,7 +252,7 @@ public class FeatureSettings extends Panel implements ItemListener,
           @Override
           public void actionPerformed(ActionEvent e)
           {
-            if (typeCol instanceof Color)
+            if (typeCol.isSimpleColour())
             {
               new FeatureColourChooser(me, type);
               // write back the current colour object to update the table
@@ -260,8 +260,7 @@ public class FeatureSettings extends Panel implements ItemListener,
             }
             else
             {
-              new UserDefinedColours(me, check.type,
-                      ((GraduatedColor) typeCol));
+              new UserDefinedColours(me, check.type, typeCol);
             }
           }
 
@@ -637,19 +636,9 @@ public class FeatureSettings extends Panel implements ItemListener,
     }
   }
 
-  public void setUserColour(String feature, Object originalColour)
+  public void setUserColour(String feature, FeatureColourI originalColour)
   {
-    if (originalColour instanceof Color
-            || originalColour instanceof GraduatedColor)
-    {
-      fr.setColour(feature, originalColour);
-    }
-    else
-    {
-      throw new Error(
-              MessageManager
-                      .getString("error.implementation_error_unsupported_feature_colour_object"));
-    }
+    fr.setColour(feature, originalColour);
     refreshTable();
   }
 
@@ -686,10 +675,11 @@ public class FeatureSettings extends Panel implements ItemListener,
 
     if (evt.getClickCount() > 1)
     {
-      Object fcol = fr.getFeatureStyle(check.type);
-      if (fcol instanceof Color)
+      FeatureColourI fcol = fr.getFeatureStyle(check.type);
+      if (fcol.isSimpleColour())
       {
-        new UserDefinedColours(this, check.type, (Color) fcol);
+        new UserDefinedColours(this, check.type, ColorUtils.getColor(fcol
+                .getColour()));
       }
       else
       {
@@ -721,49 +711,34 @@ public class FeatureSettings extends Panel implements ItemListener,
 
     boolean hasLink;
 
-    GraduatedColor gcol;
-
-    Color col;
+    FeatureColourI col;
 
-    public void updateColor(Object newcol)
+    public void updateColor(FeatureColourI newcol)
     {
-      if (newcol instanceof Color)
-      {
-        col = (Color) newcol;
-        gcol = null;
-      }
-      else if (newcol instanceof GraduatedColor)
-      {
-        gcol = (GraduatedColor) newcol;
-        col = null;
-      }
-      else
+      col = newcol;
+      if (col.isSimpleColour())
       {
-        throw new Error(
-                MessageManager
-                        .getString("error.invalid_colour_for_mycheckbox"));
-      }
-      if (col != null)
-      {
-        setBackground(col);
+        setBackground(ColorUtils.getColor(col.getColour()));
       }
       else
       {
         String vlabel = type;
-        if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
+        if (col.isAboveThreshold())
+        {
+          vlabel += " (>)";
+        }
+        else if (col.isBelowThreshold())
         {
-          vlabel += " "
-                  + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
-                          : "(<)");
+          vlabel += " (<)";
         }
-        if (gcol.isColourByLabel())
+        if (col.isColourByLabel())
         {
           setBackground(Color.white);
           vlabel += " (by Label)";
         }
         else
         {
-          setBackground(gcol.getMinColor());
+          setBackground(ColorUtils.getColor(col.getMinColour()));
         }
         this.setLabel(vlabel);
       }
@@ -780,7 +755,7 @@ public class FeatureSettings extends Panel implements ItemListener,
     }
 
     public MyCheckbox(String type, boolean selected, boolean b,
-            Object featureStyle)
+            FeatureColourI featureStyle)
     {
       this(type, selected, b);
       updateColor(featureStyle);
@@ -790,31 +765,28 @@ public class FeatureSettings extends Panel implements ItemListener,
     public void paint(Graphics g)
     {
       Dimension d = getSize();
-      if (gcol != null)
+      if (col.isColourByLabel())
       {
-        if (gcol.isColourByLabel())
-        {
-          g.setColor(Color.white);
-          g.fillRect(d.width / 2, 0, d.width / 2, d.height);
-          /*
-           * g.setColor(Color.black); Font f=g.getFont().deriveFont(9);
-           * g.setFont(f);
-           * 
-           * // g.setFont(g.getFont().deriveFont( //
-           * AffineTransform.getScaleInstance( //
-           * width/g.getFontMetrics().stringWidth("Label"), //
-           * height/g.getFontMetrics().getHeight()))); g.drawString("Label",
-           * width/2, 0);
-           */
+        g.setColor(Color.white);
+        g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+        /*
+         * g.setColor(Color.black); Font f=g.getFont().deriveFont(9);
+         * g.setFont(f);
+         * 
+         * // g.setFont(g.getFont().deriveFont( //
+         * AffineTransform.getScaleInstance( //
+         * width/g.getFontMetrics().stringWidth("Label"), //
+         * height/g.getFontMetrics().getHeight()))); g.drawString("Label",
+         * width/2, 0);
+         */
 
-        }
-        else
-        {
-          Color maxCol = gcol.getMaxColor();
-          g.setColor(maxCol);
-          g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+      }
+      else if (col.isGraduatedColour())
+      {
+        Color maxCol = ColorUtils.getColor(col.getMaxColour());
+        g.setColor(maxCol);
+        g.fillRect(d.width / 2, 0, d.width / 2, d.height);
 
-        }
       }
 
       if (hasLink)
index d72e91f..4386dee 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.appletgui;
 
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.awt.Font;
@@ -78,7 +79,7 @@ public class IdCanvas extends Panel
     }
     else
     {
-      gg.setColor(av.getSequenceColour(s));
+      gg.setColor(ColorUtils.getColor(av.getSequenceColour(s)));
       gg.fillRect(0, ((i - starty) * charHeight) + ypos, getSize().width,
               charHeight);
       gg.setColor(Color.black);
@@ -293,7 +294,7 @@ public class IdCanvas extends Panel
         }
         else
         {
-          currentColor = av.getSequenceColour(seq);
+          currentColor = ColorUtils.getColor(av.getSequenceColour(seq));
           currentTextColor = Color.black;
         }
 
index bc64728..edf8645 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.appletgui;
 
 import jalview.datamodel.AlignmentI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.awt.Dimension;
@@ -344,11 +345,12 @@ public class OverviewPanel extends Panel implements Runnable,
 
         if (seq.getLength() > lastcol)
         {
-          color = sr.getResidueBoxColour(seq, lastcol);
+          color = ColorUtils.getColor(sr.getResidueBoxColour(seq, lastcol));
 
           if (av.isShowSequenceFeatures())
           {
-            color = fr.findFeatureColour(color, seq, lastcol);
+            color = ColorUtils.getColor(fr.findFeatureColour(color, seq,
+                    lastcol));
           }
         }
         else
index 5c91ea8..615edbd 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequencePoint;
 import jalview.math.RotatableMatrix;
+import jalview.util.ColorUtils;
 import jalview.util.Format;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
@@ -126,6 +127,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
+  @Override
   public void setPoints(Vector points, int npoint)
   {
     this.points = points;
@@ -287,7 +289,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
       dim = height;
     }
 
-    return (float) (dim * scalefactor / (2 * maxwidth));
+    return dim * scalefactor / (2 * maxwidth);
   }
 
   public void findCentre()
@@ -304,6 +306,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
     // System.out.println("Centre z " + centre[2]);
   }
 
+  @Override
   public Dimension getPreferredSize()
   {
     if (prefsize != null)
@@ -316,16 +319,19 @@ public class RotatableCanvas extends Panel implements MouseListener,
     }
   }
 
+  @Override
   public Dimension getMinimumSize()
   {
     return getPreferredSize();
   }
 
+  @Override
   public void update(Graphics g)
   {
     paint(g);
   }
 
+  @Override
   public void paint(Graphics g)
   {
     if (points == null)
@@ -397,8 +403,8 @@ public class RotatableCanvas extends Panel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
-      int y = (int) ((float) (sp.coord[1] - centre[1]) * scale)
+      int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth;
+      int y = (int) ((sp.coord[1] - centre[1]) * scale)
               + halfheight;
       float z = sp.coord[1] - centre[2];
 
@@ -408,7 +414,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
       }
       else
       {
-        g.setColor(av.getSequenceColour(sp.sequence));
+        g.setColor(ColorUtils.getColor(av.getSequenceColour(sp.sequence)));
       }
 
       if (av.getSelectionGroup() != null)
@@ -445,14 +451,17 @@ public class RotatableCanvas extends Panel implements MouseListener,
     return prefsize;
   }
 
+  @Override
   public void keyTyped(KeyEvent evt)
   {
   }
 
+  @Override
   public void keyReleased(KeyEvent evt)
   {
   }
 
+  @Override
   public void keyPressed(KeyEvent evt)
   {
     if (evt.getKeyCode() == KeyEvent.VK_UP)
@@ -491,22 +500,27 @@ public class RotatableCanvas extends Panel implements MouseListener,
     }
   }
 
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseExited(MouseEvent evt)
   {
   }
 
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
   }
 
+  @Override
   public void mousePressed(MouseEvent evt)
   {
     int x = evt.getX();
@@ -551,6 +565,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
+  @Override
   public void mouseMoved(MouseEvent evt)
   {
     SequenceI found = findPoint(evt.getX(), evt.getY());
@@ -567,6 +582,7 @@ public class RotatableCanvas extends Panel implements MouseListener,
     repaint();
   }
 
+  @Override
   public void mouseDragged(MouseEvent evt)
   {
     mx = evt.getX();
@@ -574,8 +590,8 @@ public class RotatableCanvas extends Panel implements MouseListener,
 
     rotmat.setIdentity();
 
-    rotmat.rotate((float) (my - omy), 'x');
-    rotmat.rotate((float) (mx - omx), 'y');
+    rotmat.rotate(my - omy, 'x');
+    rotmat.rotate(mx - omx, 'y');
 
     for (int i = 0; i < npoint; i++)
     {
@@ -609,8 +625,8 @@ public class RotatableCanvas extends Panel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale + (float) getSize().width / 2.0);
-      int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale + (float) getSize().height / 2.0);
+      int tmp1 = (int) ((sp.coord[0] - centre[0]) * scale + getSize().width / 2.0);
+      int tmp2 = (int) ((sp.coord[1] - centre[1]) * scale + getSize().height / 2.0);
 
       if (tmp1 > x1 && tmp1 < x2 && tmp2 > y1 && tmp2 < y2)
       {
@@ -638,9 +654,9 @@ public class RotatableCanvas extends Panel implements MouseListener,
     {
 
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int px = (int) ((float) (sp.coord[0] - centre[0]) * scale)
+      int px = (int) ((sp.coord[0] - centre[0]) * scale)
               + halfwidth;
-      int py = (int) ((float) (sp.coord[1] - centre[1]) * scale)
+      int py = (int) ((sp.coord[1] - centre[1]) * scale)
               + halfheight;
 
       if (Math.abs(px - x) < 3 && Math.abs(py - y) < 3)
index 024fdc7..0e5c0e7 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Color;
@@ -731,7 +732,7 @@ public class SeqCanvas extends Panel
               }
               else
               {
-                g.setColor(group.getOutlineColour());
+                g.setColor(ColorUtils.getColor(group.getOutlineColour()));
               }
             }
           }
index 09b50c4..a64686a 100755 (executable)
  */
 package jalview.appletgui;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 
 import java.awt.Color;
@@ -67,7 +69,8 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     this.renderGaps = renderGaps;
   }
 
-  public Color getResidueBoxColour(SequenceI seq, int i)
+  @Override
+  public ColorI getResidueBoxColour(SequenceI seq, int i)
   {
     allGroups = av.getAlignment().findAllGroups(seq);
 
@@ -83,7 +86,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       getBoxColour(av.getGlobalColourScheme(), seq, i);
     }
 
-    return resBoxColour;
+    return new Colour(resBoxColour);
   }
 
   /**
@@ -97,12 +100,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
    * @return
    */
   @Override
-  public Color getResidueColour(final SequenceI seq, int position,
+  public ColorI getResidueColour(final SequenceI seq, int position,
           FeatureRenderer fr)
   {
     // TODO replace 8 or so code duplications with calls to this method
     // (refactored as needed)
-    Color col = getResidueBoxColour(seq, position);
+    ColorI col = getResidueBoxColour(seq, position);
 
     if (fr != null)
     {
index edcd961..626960d 100755 (executable)
@@ -27,10 +27,12 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.Format;
 import jalview.util.MappingUtils;
 import jalview.viewmodel.AlignmentViewport;
@@ -176,7 +178,8 @@ public class TreeCanvas extends Panel implements MouseListener,
         }
         else
         {
-          g.setColor(av.getSequenceColour(seq).darker());
+          g.setColor(ColorUtils.getColor(av.getSequenceColour(seq))
+                  .darker());
         }
 
       }
@@ -403,7 +406,7 @@ public class TreeCanvas extends Panel implements MouseListener,
 
       if (node.element() instanceof SequenceI)
       {
-        av.setSequenceColour((SequenceI) node.element(), c);
+        av.setSequenceColour((SequenceI) node.element(), new Colour(c));
       }
     }
     else
@@ -707,7 +710,7 @@ public class TreeCanvas extends Panel implements MouseListener,
           for (SequenceI seq : mappedGroup.getSequences())
           {
             // TODO why does gui require col.brighter() here??
-            codingComplement.setSequenceColour(seq, col);
+            codingComplement.setSequenceColour(seq, new Colour(col));
           }
         }
       }
index 57cf669..b1ccd51 100644 (file)
  */
 package jalview.appletgui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.SequenceGroup;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.FeatureColour;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Button;
@@ -59,7 +62,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   Button selectedButton;
 
-  Vector oldColours = new Vector();
+  Vector<Color> oldColours = new Vector<Color>();
 
   ColourSchemeI oldColourScheme;
 
@@ -75,7 +78,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   String originalLabel;
 
-  Object originalColour;
+  FeatureColourI originalColour;
 
   int R = 0, G = 0, B = 0;
 
@@ -117,7 +120,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
   public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
   {
     caller = fr;
-    originalColour = fr.colourPanel.getBackground();
+    originalColour = new FeatureColour(new Colour(
+            fr.colourPanel.getBackground()));
     originalLabel = "Feature Colour";
     setForDialog("Select Feature Colour", alignframe);
     setTargetColour(fr.colourPanel.getBackground());
@@ -134,21 +138,21 @@ public class UserDefinedColours extends Panel implements ActionListener,
    * 
    * @param caller
    *          - handles events
-   * @param col1
+   * @param col
    *          - original colour
    * @param alignframe
    *          - the parent Frame for the dialog
    * @param title
    *          - window title
    */
-  public UserDefinedColours(Component caller, Color col1, Frame alignframe,
+  public UserDefinedColours(Component caller, Color col, Frame alignframe,
           String title)
   {
     this.caller = caller;
-    originalColour = col1;
+    originalColour = new FeatureColour(new Colour(col));
     originalLabel = title;
     setForDialog(title, alignframe);
-    setTargetColour(col1);
+    setTargetColour(col);
     dialog.setVisible(true);
   }
 
@@ -161,7 +165,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
    */
   public UserDefinedColours(Object caller, String label, Color colour)
   {
-    this(caller, label, colour, colour);
+    this(caller, label, new FeatureColour(new Colour(colour)), colour);
   }
 
   /**
@@ -172,13 +176,14 @@ public class UserDefinedColours extends Panel implements ActionListener,
    * @param graduatedColor
    */
   public UserDefinedColours(FeatureSettings me, String type,
-          GraduatedColor graduatedColor)
+          FeatureColourI graduatedColor)
   {
-    this(me, type, graduatedColor, graduatedColor.getMaxColor());
+    this(me, type, graduatedColor, ColorUtils.getColor(graduatedColor
+            .getMaxColour()));
   }
 
-  private UserDefinedColours(Object caller, String label, Object ocolour,
-          Color colour)
+  private UserDefinedColours(Object caller, String label,
+          FeatureColourI ocolour, Color colour)
   {
     this.caller = caller;
     originalColour = ocolour;
@@ -228,6 +233,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   }
 
+  @Override
   public void actionPerformed(ActionEvent evt)
   {
     final Object source = evt.getSource();
@@ -257,6 +263,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
     }
   }
 
+  @Override
   public void adjustmentValueChanged(AdjustmentEvent evt)
   {
     if (evt.getSource() == rScroller)
@@ -420,6 +427,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
     button.setFont(new java.awt.Font("Verdana", 1, 10));
     button.addMouseListener(new java.awt.event.MouseAdapter()
     {
+      @Override
       public void mousePressed(MouseEvent e)
       {
         colourButtonPressed(e);
@@ -451,7 +459,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
     {
       if (caller instanceof FeatureSettings)
       {
-        ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
+        ((FeatureSettings) caller).setUserColour(originalLabel,
+                new FeatureColour(new Colour(getColor())));
       }
       else if (caller instanceof AnnotationColourChooser)
       {
@@ -468,7 +477,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
       }
       else if (caller instanceof FeatureRenderer)
       {
-        ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
+        ((FeatureRenderer) caller).colourPanel
+                .updateColor(new FeatureColour(new Colour(getColor())));
       }
       else if (caller instanceof FeatureColourChooser)
       {
@@ -537,12 +547,14 @@ public class UserDefinedColours extends Panel implements ActionListener,
         if (originalLabel.equals("Min Colour"))
         {
           ((AnnotationColourChooser) caller)
-                  .minColour_actionPerformed((Color) originalColour);
+                  .minColour_actionPerformed(ColorUtils
+                          .getColor(originalColour.getColour()));
         }
         else
         {
           ((AnnotationColourChooser) caller)
-                  .maxColour_actionPerformed((Color) originalColour);
+                  .maxColour_actionPerformed(ColorUtils
+                          .getColor(originalColour.getColour()));
         }
       }
       else if (caller instanceof FeatureRenderer)
@@ -556,12 +568,14 @@ public class UserDefinedColours extends Panel implements ActionListener,
         if (originalLabel.indexOf("inimum") > -1)
         {
           ((FeatureColourChooser) caller)
-                  .minColour_actionPerformed((Color) originalColour);
+                  .minColour_actionPerformed(ColorUtils
+                          .getColor(originalColour.getColour()));
         }
         else
         {
           ((FeatureColourChooser) caller)
-                  .maxColour_actionPerformed((Color) originalColour);
+                  .maxColour_actionPerformed(ColorUtils
+                          .getColor(originalColour.getColour()));
         }
       }
       if (dialog != null)
@@ -576,7 +590,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
     Color[] newColours = new Color[24];
     for (int i = 0; i < 24; i++)
     {
-      newColours[i] = (Color) oldColours.elementAt(i);
+      newColours[i] = oldColours.elementAt(i);
       buttonPanel.getComponent(i).setBackground(newColours[i]);
     }
 
index 24439ca..5ab522e 100644 (file)
@@ -25,6 +25,7 @@ import jalview.api.AlignViewControllerGuiI;
 import jalview.api.AlignViewControllerI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.commands.OrderCommand;
 import jalview.datamodel.AlignmentI;
@@ -34,6 +35,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.io.FeaturesFile;
+import jalview.schemes.Colour;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -112,10 +114,10 @@ public class AlignViewController implements AlignViewControllerI
         viewport.getAlignment().addGroup(gps[g]);
         Color col = new Color((int) (Math.random() * 255),
                 (int) (Math.random() * 255), (int) (Math.random() * 255));
-        col = col.brighter();
+        ColorI newcol = new Colour(col.brighter());
         for (SequenceI sq : gps[g].getSequences(null))
         {
-          viewport.setSequenceColour(sq, col);
+          viewport.setSequenceColour(sq, newcol);
         }
       }
       return true;
index 0e8fa17..b9cdf0e 100755 (executable)
@@ -22,6 +22,8 @@ package jalview.datamodel;
 
 import jalview.analysis.AAFrequency;
 import jalview.analysis.Conservation;
+import jalview.api.ColorI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
 
@@ -82,15 +84,15 @@ public class SequenceGroup implements AnnotatedCollectionI
   // end column (base 0)
   int endRes = 0;
 
-  public Color outlineColour = Color.black;
+  public ColorI outlineColour = Colour.black;
 
-  public Color idColour = null;
+  public ColorI idColour = null;
 
   public int thresholdTextColour = 0;
 
-  public Color textColour = Color.black;
+  public ColorI textColour = Colour.black;
 
-  public Color textColour2 = Color.white;
+  public ColorI textColour2 = Colour.white;
 
   /**
    * consensus calculation property
@@ -796,7 +798,7 @@ public class SequenceGroup implements AnnotatedCollectionI
    */
   public void setOutlineColour(Color c)
   {
-    outlineColour = c;
+    outlineColour = new Colour(c);
   }
 
   /**
@@ -804,7 +806,7 @@ public class SequenceGroup implements AnnotatedCollectionI
    * 
    * @return DOCUMENT ME!
    */
-  public Color getOutlineColour()
+  public ColorI getOutlineColour()
   {
     return outlineColour;
   }
@@ -877,7 +879,7 @@ public class SequenceGroup implements AnnotatedCollectionI
   /**
    * @return the idColour
    */
-  public Color getIdColour()
+  public ColorI getIdColour()
   {
     return idColour;
   }
@@ -888,12 +890,13 @@ public class SequenceGroup implements AnnotatedCollectionI
    */
   public void setIdColour(Color idColour)
   {
-    this.idColour = idColour;
+    this.idColour = new Colour(idColour);
   }
 
   /**
    * @return the representative sequence for this group
    */
+  @Override
   public SequenceI getSeqrep()
   {
     return seqrep;
@@ -906,6 +909,7 @@ public class SequenceGroup implements AnnotatedCollectionI
    * @param seqrep
    *          the seqrep to set (null means no sequence representative)
    */
+  @Override
   public void setSeqrep(SequenceI seqrep)
   {
     this.seqrep = seqrep;
@@ -915,6 +919,7 @@ public class SequenceGroup implements AnnotatedCollectionI
    * 
    * @return true if group has a sequence representative
    */
+  @Override
   public boolean hasSeqrep()
   {
     return seqrep != null;
index 4dd1bba..b320e83 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.ext.ensembl;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureColourI;
 import jalview.api.FeatureSettingsModelI;
 import jalview.datamodel.AlignmentI;
@@ -8,11 +9,11 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.io.gff.SequenceOntologyFactory;
 import jalview.io.gff.SequenceOntologyI;
+import jalview.schemes.Colour;
 import jalview.schemes.FeatureColourAdapter;
 import jalview.schemes.FeatureSettingsAdapter;
 import jalview.util.MapList;
 
-import java.awt.Color;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.ArrayList;
@@ -551,9 +552,9 @@ public class EnsemblGene extends EnsemblSeqProxy
           {
 
             @Override
-            public Color getColour()
+            public ColorI getColour()
             {
-              return Color.RED;
+              return Colour.red;
             }
           };
         }
index d5676c5..0114d1c 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.jmol;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;
@@ -28,7 +29,6 @@ import jalview.structure.StructureMapping;
 import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 
-import java.awt.Color;
 import java.util.ArrayList;
 
 /**
@@ -93,7 +93,7 @@ public class JmolCommands
 
               lastPos = pos;
 
-              Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
+              ColorI col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
 
               if (fr != null)
               {
index a551ca2..930d6fe 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.rbvi.chimera;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;
@@ -30,7 +31,6 @@ import jalview.structure.StructureSelectionManager;
 import jalview.util.ColorUtils;
 import jalview.util.Comparison;
 
-import java.awt.Color;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -58,7 +58,7 @@ public class ChimeraCommands
           SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
+    Map<ColorI, Map<Integer, Map<String, List<int[]>>>> colourMap = buildColoursMap(
             ssm, files, sequence, sr, fr, alignment);
 
     List<String> colourCommands = buildColourCommands(colourMap);
@@ -86,7 +86,7 @@ public class ChimeraCommands
    * @return
    */
   protected static List<String> buildColourCommands(
-          Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap)
+          Map<ColorI, Map<Integer, Map<String, List<int[]>>>> colourMap)
   {
     /*
      * This version concatenates all commands into a single String (semi-colon
@@ -96,7 +96,7 @@ public class ChimeraCommands
     List<String> commands = new ArrayList<String>();
     StringBuilder sb = new StringBuilder(256);
     boolean firstColour = true;
-    for (Color colour : colourMap.keySet())
+    for (ColorI colour : colourMap.keySet())
     {
       String colourCode = ColorUtils.toTkCode(colour);
       if (!firstColour)
@@ -161,13 +161,13 @@ public class ChimeraCommands
    * Ordering is by order of addition (for colours and positions), natural ordering (for models and chains)
    * </pre>
    */
-  protected static Map<Color, Map<Integer, Map<String, List<int[]>>>> buildColoursMap(
+  protected static Map<ColorI, Map<Integer, Map<String, List<int[]>>>> buildColoursMap(
           StructureSelectionManager ssm, String[] files,
           SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
           AlignmentI alignment)
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
-    Color lastColour = null;
+    Map<ColorI, Map<Integer, Map<String, List<int[]>>>> colourMap = new LinkedHashMap<ColorI, Map<Integer, Map<String, List<int[]>>>>();
+    ColorI lastColour = null;
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
@@ -202,7 +202,7 @@ public class ChimeraCommands
                 continue;
               }
 
-              Color colour = sr.getResidueColour(seq, r, fr);
+              ColorI colour = sr.getResidueColour(seq, r, fr);
               final String chain = mapping[m].getChain();
 
               /*
@@ -251,8 +251,8 @@ public class ChimeraCommands
    * @param chain
    */
   protected static void addColourRange(
-          Map<Color, Map<Integer, Map<String, List<int[]>>>> colourMap,
-          Color colour, int model, int startPos, int endPos, String chain)
+          Map<ColorI, Map<Integer, Map<String, List<int[]>>>> colourMap,
+          ColorI colour, int model, int startPos, int endPos, String chain)
   {
     /*
      * Get/initialize map of data for the colour
index a41e10e..d0d0b5b 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.varna;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.api.SequenceRenderer;
 import jalview.datamodel.AlignmentI;
@@ -27,7 +28,6 @@ import jalview.datamodel.SequenceI;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureSelectionManager;
 
-import java.awt.Color;
 import java.util.ArrayList;
 
 /**
@@ -58,7 +58,9 @@ public class VarnaCommands
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
 
       if (mapping == null || mapping.length < 1)
+      {
         continue;
+      }
 
       int lastPos = -1;
       for (int s = 0; s < sequence[pdbfnum].length; s++)
@@ -79,14 +81,18 @@ public class VarnaCommands
               int pos = mapping[m].getPDBResNum(asp.findPosition(r));
 
               if (pos < 1 || pos == lastPos)
+              {
                 continue;
+              }
 
               lastPos = pos;
 
-              Color col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
+              ColorI col = sr.getResidueBoxColour(sequence[pdbfnum][s], r);
 
               if (fr != null)
+              {
                 col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
+              }
               String newSelcom = (mapping[m].getChain() != " " ? ":"
                       + mapping[m].getChain() : "")
                       + "/"
index f06ca94..7b0d717 100644 (file)
@@ -33,6 +33,7 @@ import jalview.jbgui.GAlignmentPanel;
 import jalview.math.AlignmentDimension;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureSelectionManager;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 
@@ -1068,7 +1069,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
       }
       else
       {
-        currentColor = av.getSequenceColour(seq);
+        currentColor = ColorUtils.getColor(av.getSequenceColour(seq));
         currentTextColor = Color.black;
       }
 
index d688ddd..cffc52f 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.SequenceI;
 import jalview.io.AnnotationFile;
@@ -157,7 +158,7 @@ public class AnnotationExporter extends JPanel
     {
       FeaturesFile formatter = new FeaturesFile();
       SequenceI[] sequences = ap.av.getAlignment().getSequencesArray();
-      Map<String, Object> featureColours = ap.getFeatureRenderer()
+      Map<String, FeatureColourI> featureColours = ap.getFeatureRenderer()
               .getDisplayedFeatureCols();
       boolean includeNonPositional = ap.av.isShowNPFeats();
       if (GFFFormat.isSelected())
index f4a4f4d..e754adf 100644 (file)
@@ -32,6 +32,7 @@ import jalview.structure.SelectionListener;
 import jalview.structure.SelectionSource;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
+import jalview.util.ColorUtils;
 import jalview.util.Comparison;
 import jalview.util.MessageManager;
 import jalview.util.ShiftList;
@@ -424,7 +425,7 @@ public class AppVarna extends JInternalFrame implements SelectionListener,
       }
       selectionHighlighter.highlightRegion(rna, start, end);
       selectionHighlighter.getLastHighlight().setOutlineColor(
-              seqsel.getOutlineColour());
+              ColorUtils.getColor(seqsel.getOutlineColour()));
       // TODO - translate column markings to positions on structure if present.
       vab.updateSelectedRNA(rna);
     }
index 064d58b..ac22aca 100644 (file)
  */
 package jalview.gui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.GraphLine;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -33,7 +35,6 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.util.Hashtable;
 
 import javax.swing.BorderFactory;
 import javax.swing.JCheckBox;
@@ -52,16 +53,16 @@ public class FeatureColourChooser extends JalviewDialog
   // FeatureSettings fs;
   FeatureRenderer fr;
 
-  private GraduatedColor cs;
+  private FeatureColourI cs;
 
-  private Object oldcs;
+  private FeatureColourI oldcs;
 
   /**
    * 
    * @return the last colour setting selected by user - either oldcs (which may
    *         be a java.awt.Color) or the new GraduatedColor
    */
-  public Object getLastColour()
+  public FeatureColourI getLastColour()
   {
     if (cs == null)
     {
@@ -70,8 +71,6 @@ public class FeatureColourChooser extends JalviewDialog
     return cs;
   }
 
-  Hashtable oldgroupColours;
-
   AlignmentPanel ap;
 
   boolean adjusting = false;
@@ -127,7 +126,7 @@ public class FeatureColourChooser extends JalviewDialog
       }
     });
 
-    float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
+    float mm[] = fr.getMinMax().get(type)[0];
     min = mm[0];
     max = mm[1];
 
@@ -139,32 +138,35 @@ public class FeatureColourChooser extends JalviewDialog
     scaleFactor = (max == min) ? 1f : 100f / (max - min);
 
     oldcs = fr.getFeatureColours().get(type);
-    if (oldcs instanceof GraduatedColor)
+    if (!oldcs.isSimpleColour())
     {
-      if (((GraduatedColor) oldcs).isAutoScale())
+      if (oldcs.isAutoScaled())
       {
         // update the scale
-        cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
+        cs = new FeatureColour((FeatureColour) oldcs, min, max);
       }
       else
       {
-        cs = new GraduatedColor((GraduatedColor) oldcs);
+        cs = new FeatureColour((FeatureColour) oldcs);
       }
     }
     else
     {
       // promote original color to a graduated color
-      Color bl = Color.black;
-      if (oldcs instanceof Color)
+      Color bl = ColorUtils.getColor(oldcs.getColour());
+      if (bl == null)
       {
-        bl = (Color) oldcs;
+        bl = Color.BLACK;
       }
       // original colour becomes the maximum colour
-      cs = new GraduatedColor(Color.white, bl, mm[0], mm[1]);
+      cs = new FeatureColour(new Colour(Color.white), new Colour(bl),
+              mm[0], mm[1]);
       cs.setColourByLabel(false);
     }
-    minColour.setBackground(oldminColour = cs.getMinColor());
-    maxColour.setBackground(oldmaxColour = cs.getMaxColor());
+    minColour.setBackground(oldminColour = ColorUtils.getColor(cs
+            .getMinColour()));
+    maxColour.setBackground(oldmaxColour = ColorUtils.getColor(cs
+            .getMaxColour()));
     adjusting = true;
 
     try
@@ -174,18 +176,15 @@ public class FeatureColourChooser extends JalviewDialog
     {
     }
     // update the gui from threshold state
-    thresholdIsMin.setSelected(!cs.isAutoScale());
+    thresholdIsMin.setSelected(!cs.isAutoScaled());
     colourByLabel.setSelected(cs.isColourByLabel());
-    if (cs.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
+    if (cs.hasThreshold())
     {
       // initialise threshold slider and selector
-      threshold
-              .setSelectedIndex(cs.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD ? 1
-                      : 2);
+      threshold.setSelectedIndex(cs.isAboveThreshold() ? 1 : 2);
       slider.setEnabled(true);
       thresholdValue.setEnabled(true);
-      threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
-              "Threshold", Color.black);
+      threshline = new GraphLine((max - min) / 2f, "Threshold", Color.black);
 
     }
 
@@ -395,50 +394,52 @@ public class FeatureColourChooser extends JalviewDialog
       return;
     }
 
-    int aboveThreshold = AnnotationColourGradient.NO_THRESHOLD;
+    boolean aboveThreshold = false;
+    boolean belowThreshold = false;
     if (threshold.getSelectedIndex() == 1)
     {
-      aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;
+      aboveThreshold = true;
     }
     else if (threshold.getSelectedIndex() == 2)
     {
-      aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;
+      belowThreshold = true;
     }
+    boolean hasThreshold = aboveThreshold || belowThreshold;
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
 
-    GraduatedColor acg;
+    FeatureColourI acg;
     if (cs.isColourByLabel())
     {
-      acg = new GraduatedColor(oldminColour, oldmaxColour, min, max);
+      acg = new FeatureColour(new Colour(oldminColour), new Colour(
+              oldmaxColour), min, max);
     }
     else
     {
-      acg = new GraduatedColor(oldminColour = minColour.getBackground(),
-              oldmaxColour = maxColour.getBackground(), min, max);
+      acg = new FeatureColour(new Colour(
+              oldminColour = minColour.getBackground()), new Colour(
+              oldmaxColour = maxColour.getBackground()), min, max);
 
     }
 
-    if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)
+    if (!hasThreshold)
     {
       slider.setEnabled(false);
       thresholdValue.setEnabled(false);
       thresholdValue.setText("");
       thresholdIsMin.setEnabled(false);
     }
-    else if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD
-            && threshline == null)
+    else if (threshline == null)
     {
       // todo visual indication of feature threshold
-      threshline = new jalview.datamodel.GraphLine((max - min) / 2f,
-              "Threshold", Color.black);
+      threshline = new GraphLine((max - min) / 2f, "Threshold", Color.black);
     }
 
-    if (aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
+    if (hasThreshold)
     {
       adjusting = true;
-      acg.setThresh(threshline.value);
+      acg.setThreshold(threshline.value);
 
       float range = (max - min) * scaleFactor;
 
@@ -453,18 +454,18 @@ public class FeatureColourChooser extends JalviewDialog
       adjusting = false;
     }
 
-    acg.setThreshType(aboveThreshold);
-    if (thresholdIsMin.isSelected()
-            && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
+    acg.setAboveThreshold(aboveThreshold);
+    acg.setBelowThreshold(belowThreshold);
+    if (thresholdIsMin.isSelected() && hasThreshold)
     {
       acg.setAutoScaled(false);
-      if (aboveThreshold == AnnotationColourGradient.ABOVE_THRESHOLD)
+      if (aboveThreshold)
       {
-        acg = new GraduatedColor(acg, threshline.value, max);
+        acg = new FeatureColour((FeatureColour) acg, threshline.value, max);
       }
       else
       {
-        acg = new GraduatedColor(acg, min, threshline.value);
+        acg = new FeatureColour((FeatureColour) acg, min, threshline.value);
       }
     }
     else
@@ -554,7 +555,7 @@ public class FeatureColourChooser extends JalviewDialog
   public void valueChanged()
   {
     threshline.value = slider.getValue() / scaleFactor;
-    cs.setThresh(threshline.value);
+    cs.setThreshold(threshline.value);
     changeColour();
     ap.paintAlignment(false);
   }
index 1cf15ac..0284105 100644 (file)
  */
 package jalview.gui;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -94,7 +98,7 @@ public class FeatureRenderer extends
 
   static String lastDescriptionAdded;
 
-  Object oldcol, fcol;
+  FeatureColourI oldcol, fcol;
 
   int featureIndex = 0;
 
@@ -126,20 +130,19 @@ public class FeatureRenderer extends
       @Override
       public void mousePressed(MouseEvent evt)
       {
-        if (fcol instanceof Color)
+        if (fcol.isSimpleColour())
         {
           Color col = JColorChooser.showDialog(Desktop.desktop,
                   MessageManager.getString("label.select_feature_colour"),
-                  ((Color) fcol));
+                  ColorUtils.getColor(fcol.getColour()));
           if (col != null)
           {
-            fcol = col;
-            updateColourButton(bigPanel, colour, col);
+            fcol = new FeatureColour(new Colour(col));
+            updateColourButton(bigPanel, colour, fcol);
           }
         }
         else
         {
-
           if (fcc == null)
           {
             final String type = features[featureIndex].getType();
@@ -206,11 +209,11 @@ public class FeatureRenderer extends
             ap.getSeqPanel().seqCanvas.highlightSearchResults(highlight);
 
           }
-          Object col = getFeatureStyle(name.getText());
+          FeatureColourI col = getFeatureStyle(name.getText());
           if (col == null)
           {
-            col = new jalview.schemes.UserColourScheme()
-                    .createColourFromName(name.getText());
+            col = new FeatureColour(new Colour(UserColourScheme
+                    .createColourFromName(name.getText())));
           }
           oldcol = fcol = col;
           updateColourButton(bigPanel, colour, col);
@@ -420,27 +423,26 @@ public class FeatureRenderer extends
    * update the amend feature button dependent on the given style
    * 
    * @param bigPanel
+   * @param colour
    * @param col
-   * @param col2
    */
   protected void updateColourButton(JPanel bigPanel, JLabel colour,
-          Object col2)
+          FeatureColourI col)
   {
     colour.removeAll();
     colour.setIcon(null);
     colour.setToolTipText(null);
     colour.setText("");
 
-    if (col2 instanceof Color)
+    if (col.isSimpleColour())
     {
-      colour.setBackground((Color) col2);
+      colour.setBackground(ColorUtils.getColor(col.getColour()));
     }
     else
     {
       colour.setBackground(bigPanel.getBackground());
       colour.setForeground(Color.black);
-      FeatureSettings.renderGraduatedColor(colour, (GraduatedColor) col2);
-      // colour.setForeground(colour.getBackground());
+      FeatureSettings.renderGraduatedColor(colour, col);
     }
   }
 
index 40635c0..187d3d0 100644 (file)
  */
 package jalview.gui;
 
+import jalview.api.FeatureColourI;
 import jalview.api.FeatureSettingsControllerI;
 import jalview.bin.Cache;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.Help.HelpId;
 import jalview.io.JalviewFileChooser;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.schemabinding.version2.JalviewUserColours;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.util.ColorUtils;
+import jalview.util.Format;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.util.QuickSort;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.dbsources.das.api.jalviewSourceI;
 
@@ -160,8 +166,8 @@ public class FeatureSettings extends JPanel implements
 
     table.setDefaultEditor(Color.class, new ColorEditor(this));
 
-    table.setDefaultEditor(GraduatedColor.class, new ColorEditor(this));
-    table.setDefaultRenderer(GraduatedColor.class, new ColorRenderer());
+    table.setDefaultEditor(FeatureColour.class, new ColorEditor(this));
+    table.setDefaultRenderer(FeatureColour.class, new ColorRenderer());
     table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
     table.addMouseListener(new MouseAdapter()
@@ -251,7 +257,7 @@ public class FeatureSettings extends JPanel implements
 
     frame = new JInternalFrame();
     frame.setContentPane(this);
-    if (new jalview.util.Platform().isAMac())
+    if (Platform.isAMac())
     {
       Desktop.addInternalFrame(frame,
               MessageManager.getString("label.sequence_feature_settings"),
@@ -281,6 +287,8 @@ public class FeatureSettings extends JPanel implements
           final Object typeCol, final Map<String, float[][]> minmax, int x,
           int y)
   {
+    final FeatureColourI featureColour = (FeatureColourI) typeCol;
+
     JPopupMenu men = new JPopupMenu(MessageManager.formatMessage(
             "label.settings_for_param", new String[] { type }));
     JMenuItem scr = new JMenuItem(
@@ -336,7 +344,7 @@ public class FeatureSettings extends JPanel implements
         // positional features
         final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem(
                 "Graduated Colour");
-        mxcol.setSelected(!(typeCol instanceof Color));
+        mxcol.setSelected(!featureColour.isSimpleColour());
         men.add(mxcol);
         mxcol.addActionListener(new ActionListener()
         {
@@ -347,7 +355,7 @@ public class FeatureSettings extends JPanel implements
           {
             if (e.getSource() == mxcol)
             {
-              if (typeCol instanceof Color)
+              if (featureColour.isSimpleColour())
               {
                 FeatureColourChooser fc = new FeatureColourChooser(me.fr,
                         type);
@@ -361,8 +369,8 @@ public class FeatureSettings extends JPanel implements
                         "Select new Colour", true, // modal
                         colorChooser, this, // OK button handler
                         null); // no CANCEL button handler
-                colorChooser.setColor(((GraduatedColor) typeCol)
-                        .getMaxColor());
+                colorChooser.setColor(ColorUtils.getColor(featureColour
+                        .getMaxColour()));
                 dialog.setVisible(true);
               }
             }
@@ -447,13 +455,13 @@ public class FeatureSettings extends JPanel implements
   /**
    * contains a float[3] for each feature type string. created by setTableData
    */
-  Hashtable typeWidth = null;
+  Map<String, float[]> typeWidth = null;
 
   @Override
   synchronized public void discoverAllFeatureData()
   {
-    Vector allFeatures = new Vector();
-    Vector allGroups = new Vector();
+    Vector<String> allFeatures = new Vector<String>();
+    Vector<String> allGroups = new Vector<String>();
     SequenceFeature[] tmpfeatures;
     String group;
     for (int i = 0; i < af.getViewport().getAlignment().getHeight(); i++)
@@ -559,13 +567,13 @@ public class FeatureSettings extends JPanel implements
       return;
     }
     resettingTable = true;
-    typeWidth = new Hashtable();
+    typeWidth = new Hashtable<String, float[]>();
     // TODO: change avWidth calculation to 'per-sequence' average and use long
     // rather than float
     float[] avWidth = null;
     SequenceFeature[] tmpfeatures;
     String group = null, type;
-    Vector visibleChecks = new Vector();
+    Vector<String> visibleChecks = new Vector<String>();
 
     // Find out which features should be visible depending on which groups
     // are selected / deselected
@@ -606,7 +614,7 @@ public class FeatureSettings extends JPanel implements
         }
         else
         {
-          avWidth = (float[]) typeWidth.get(tmpfeatures[index].getType());
+          avWidth = typeWidth.get(tmpfeatures[index].getType());
         }
         avWidth[0]++;
         if (tmpfeatures[index].getBegin() > tmpfeatures[index].getEnd())
@@ -751,8 +759,7 @@ public class FeatureSettings extends JPanel implements
         InputStreamReader in = new InputStreamReader(new FileInputStream(
                 file), "UTF-8");
 
-        jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
-        jucs = jucs.unmarshal(in);
+        JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
 
         for (int i = jucs.getColourCount() - 1; i >= 0; i--)
         {
@@ -771,7 +778,8 @@ public class FeatureSettings extends JPanel implements
               Cache.log.warn("Couldn't parse out graduated feature color.",
                       e);
             }
-            GraduatedColor gcol = new GraduatedColor(mincol, maxcol,
+            FeatureColourI gcol = new FeatureColour(new Colour(mincol),
+                    new Colour(maxcol),
                     newcol.getMin(), newcol.getMax());
             if (newcol.hasAutoScale())
             {
@@ -783,31 +791,28 @@ public class FeatureSettings extends JPanel implements
             }
             if (newcol.hasThreshold())
             {
-              gcol.setThresh(newcol.getThreshold());
-              gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD); // default
+              gcol.setThreshold(newcol.getThreshold());
             }
             if (newcol.getThreshType().length() > 0)
             {
               String ttyp = newcol.getThreshType();
-              if (ttyp.equalsIgnoreCase("NONE"))
-              {
-                gcol.setThreshType(AnnotationColourGradient.NO_THRESHOLD);
-              }
               if (ttyp.equalsIgnoreCase("ABOVE"))
               {
-                gcol.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);
+                gcol.setAboveThreshold(true);
               }
               if (ttyp.equalsIgnoreCase("BELOW"))
               {
-                gcol.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);
+                gcol.setBelowThreshold(true);
               }
             }
             fr.setColour(name = newcol.getName(), gcol);
           }
           else
           {
-            fr.setColour(name = jucs.getColour(i).getName(), new Color(
-                    Integer.parseInt(jucs.getColour(i).getRGB(), 16)));
+            Color color = new Color(
+                    Integer.parseInt(jucs.getColour(i).getRGB(), 16));
+            fr.setColour(name = jucs.getColour(i).getName(),
+                    new FeatureColour(new Colour(color)));
           }
           fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount());
         }
@@ -851,50 +856,40 @@ public class FeatureSettings extends JPanel implements
         PrintWriter out = new PrintWriter(new OutputStreamWriter(
                 new FileOutputStream(choice), "UTF-8"));
 
-        Set fr_colours = fr.getAllFeatureColours();
-        Iterator e = fr_colours.iterator();
+        Set<String> fr_colours = fr.getAllFeatureColours();
+        Iterator<String> e = fr_colours.iterator();
         float[] sortOrder = new float[fr_colours.size()];
         String[] sortTypes = new String[fr_colours.size()];
         int i = 0;
         while (e.hasNext())
         {
-          sortTypes[i] = e.next().toString();
+          sortTypes[i] = e.next();
           sortOrder[i] = fr.getOrder(sortTypes[i]);
           i++;
         }
-        jalview.util.QuickSort.sort(sortOrder, sortTypes);
+        QuickSort.sort(sortOrder, sortTypes);
         sortOrder = null;
-        Object fcol;
-        GraduatedColor gcol;
         for (i = 0; i < sortTypes.length; i++)
         {
           jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
           col.setName(sortTypes[i]);
-          col.setRGB(jalview.util.Format.getHexString(fr.getColour(col
-                  .getName())));
-          fcol = fr.getFeatureStyle(sortTypes[i]);
-          if (fcol instanceof GraduatedColor)
+          FeatureColourI fcol = fr.getFeatureStyle(sortTypes[i]);
+          if (fcol.isSimpleColour())
           {
-            gcol = (GraduatedColor) fcol;
-            col.setMin(gcol.getMin());
-            col.setMax(gcol.getMax());
-            col.setMinRGB(jalview.util.Format.getHexString(gcol
-                    .getMinColor()));
-            col.setAutoScale(gcol.isAutoScale());
-            col.setThreshold(gcol.getThresh());
-            col.setColourByLabel(gcol.isColourByLabel());
-            switch (gcol.getThreshType())
-            {
-            case AnnotationColourGradient.NO_THRESHOLD:
-              col.setThreshType("NONE");
-              break;
-            case AnnotationColourGradient.ABOVE_THRESHOLD:
-              col.setThreshType("ABOVE");
-              break;
-            case AnnotationColourGradient.BELOW_THRESHOLD:
-              col.setThreshType("BELOW");
-              break;
-            }
+            col.setRGB(Format.getHexString(fcol.getColour()));
+          }
+          else
+          {
+            col.setRGB(Format.getHexString(fcol.getMaxColour()));
+            col.setMin(fcol.getMin());
+            col.setMax(fcol.getMax());
+            col.setMinRGB(jalview.util.Format.getHexString(fcol
+                    .getMinColour()));
+            col.setAutoScale(fcol.isAutoScaled());
+            col.setThreshold(fcol.getThreshold());
+            col.setColourByLabel(fcol.isColourByLabel());
+            col.setThreshType(fcol.isAboveThreshold() ? "ABOVE" : (fcol
+                    .isBelowThreshold() ? "BELOW" : "NONE"));
           }
           ucs.addColour(col);
         }
@@ -930,7 +925,7 @@ public class FeatureSettings extends JPanel implements
     int num = 0;
     for (int i = 0; i < data.length; i++)
     {
-      awidth = (float[]) typeWidth.get(data[i][0]);
+      awidth = typeWidth.get(data[i][0]);
       if (awidth[0] > 0)
       {
         width[i] = awidth[1] / awidth[0];// *awidth[0]*awidth[2]; - better
@@ -1253,7 +1248,8 @@ public class FeatureSettings extends JPanel implements
     fetchDAS.setEnabled(false);
     cancelDAS.setEnabled(true);
     dassourceBrowser.setGuiEnabled(false);
-    Vector selectedSources = dassourceBrowser.getSelectedSources();
+    Vector<jalviewSourceI> selectedSources = dassourceBrowser
+            .getSelectedSources();
     doDasFeatureFetch(selectedSources, true, true);
   }
 
@@ -1312,7 +1308,7 @@ public class FeatureSettings extends JPanel implements
    *          Vector of Strings to resolve to DAS source nicknames.
    * @return sources that are present in source list.
    */
-  public List<jalviewSourceI> resolveSourceNicknames(Vector sources)
+  public List<jalviewSourceI> resolveSourceNicknames(Vector<String> sources)
   {
     return dassourceBrowser.sourceRegistry.resolveSourceNicknames(sources);
   }
@@ -1323,7 +1319,7 @@ public class FeatureSettings extends JPanel implements
    * 
    * @return vector of selected das source nicknames
    */
-  public Vector getSelectedSources()
+  public Vector<jalviewSourceI> getSelectedSources()
   {
     return dassourceBrowser.getSelectedSources();
   }
@@ -1337,7 +1333,7 @@ public class FeatureSettings extends JPanel implements
    *          if true then runs in same thread, otherwise passes to the Swing
    *          executor
    */
-  public void fetchDasFeatures(Vector sources, boolean block)
+  public void fetchDasFeatures(Vector<String> sources, boolean block)
   {
     initDasSources();
     List<jalviewSourceI> resolved = dassourceBrowser.sourceRegistry
@@ -1503,10 +1499,11 @@ public class FeatureSettings extends JPanel implements
     }
 
     @Override
-    public Component getTableCellRendererComponent(JTable table,
+    public Component getTableCellRendererComponent(JTable tbl,
             Object color, boolean isSelected, boolean hasFocus, int row,
             int column)
     {
+      FeatureColourI cellColour = (FeatureColourI) color;
       // JLabel comp = new JLabel();
       // comp.
       setOpaque(true);
@@ -1514,11 +1511,11 @@ public class FeatureSettings extends JPanel implements
       // setBounds(getBounds());
       Color newColor;
       setToolTipText(baseTT);
-      setBackground(table.getBackground());
-      if (color instanceof GraduatedColor)
+      setBackground(tbl.getBackground());
+      if (!cellColour.isSimpleColour())
       {
-        Rectangle cr = table.getCellRect(row, column, false);
-        FeatureSettings.renderGraduatedColor(this, (GraduatedColor) color,
+        Rectangle cr = tbl.getCellRect(row, column, false);
+        FeatureSettings.renderGraduatedColor(this, cellColour,
                 (int) cr.getWidth(), (int) cr.getHeight());
 
       }
@@ -1526,8 +1523,7 @@ public class FeatureSettings extends JPanel implements
       {
         this.setText("");
         this.setIcon(null);
-        newColor = (Color) color;
-        // comp.
+        newColor = ColorUtils.getColor(cellColour.getColour());
         setBackground(newColor);
         // comp.setToolTipText("RGB value: " + newColor.getRed() + ", "
         // + newColor.getGreen() + ", " + newColor.getBlue());
@@ -1537,9 +1533,8 @@ public class FeatureSettings extends JPanel implements
         if (selectedBorder == null)
         {
           selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
-                  table.getSelectionBackground());
+                  tbl.getSelectionBackground());
         }
-        // comp.
         setBorder(selectedBorder);
       }
       else
@@ -1547,9 +1542,8 @@ public class FeatureSettings extends JPanel implements
         if (unselectedBorder == null)
         {
           unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
-                  table.getBackground());
+                  tbl.getBackground());
         }
-        // comp.
         setBorder(unselectedBorder);
       }
 
@@ -1563,7 +1557,7 @@ public class FeatureSettings extends JPanel implements
    * @param comp
    * @param gcol
    */
-  public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol)
+  public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol)
   {
     int w = comp.getWidth(), h = comp.getHeight();
     if (w < 20)
@@ -1579,23 +1573,23 @@ public class FeatureSettings extends JPanel implements
     renderGraduatedColor(comp, gcol, w, h);
   }
 
-  public static void renderGraduatedColor(JLabel comp, GraduatedColor gcol,
+  public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
           int w, int h)
   {
     boolean thr = false;
     String tt = "";
     String tx = "";
-    if (gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD)
+    if (gcol.isAboveThreshold())
     {
       thr = true;
       tx += ">";
-      tt += "Thresholded (Above " + gcol.getThresh() + ") ";
+      tt += "Thresholded (Above " + gcol.getThreshold() + ") ";
     }
-    if (gcol.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
+    if (gcol.isBelowThreshold())
     {
       thr = true;
       tx += "<";
-      tt += "Thresholded (Below " + gcol.getThresh() + ") ";
+      tt += "Thresholded (Below " + gcol.getThreshold() + ") ";
     }
     if (gcol.isColourByLabel())
     {
@@ -1609,7 +1603,7 @@ public class FeatureSettings extends JPanel implements
     }
     else
     {
-      Color newColor = gcol.getMaxColor();
+      Color newColor = ColorUtils.getColor(gcol.getMaxColour());
       comp.setBackground(newColor);
       // System.err.println("Width is " + w / 2);
       Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
@@ -1637,7 +1631,7 @@ public class FeatureSettings extends JPanel implements
 
 class FeatureIcon implements Icon
 {
-  GraduatedColor gcol;
+  FeatureColourI gcol;
 
   Color backg;
 
@@ -1649,7 +1643,7 @@ class FeatureIcon implements Icon
 
   Color mpcolour = Color.white;
 
-  FeatureIcon(GraduatedColor gfc, Color bg, int w, int h, boolean mspace)
+  FeatureIcon(FeatureColourI gfc, Color bg, int w, int h, boolean mspace)
   {
     gcol = gfc;
     backg = bg;
@@ -1689,7 +1683,7 @@ class FeatureIcon implements Icon
       g.setColor(backg);
       g.fillRect(0, 0, width, height);
       // need an icon here.
-      g.setColor(gcol.getMaxColor());
+      g.setColor(ColorUtils.getColor(gcol.getMaxColour()));
 
       g.setFont(new Font("Verdana", Font.PLAIN, 9));
 
@@ -1703,7 +1697,7 @@ class FeatureIcon implements Icon
     }
     else
     {
-      Color minCol = gcol.getMinColor();
+      Color minCol = ColorUtils.getColor(gcol.getMinColour());
       g.setColor(minCol);
       g.fillRect(0, 0, s1, height);
       if (midspace)
@@ -1711,7 +1705,7 @@ class FeatureIcon implements Icon
         g.setColor(Color.white);
         g.fillRect(s1, 0, e1 - s1, height);
       }
-      g.setColor(gcol.getMaxColor());
+      g.setColor(ColorUtils.getColor(gcol.getMaxColour()));
       g.fillRect(0, e1, width - e1, height);
     }
   }
@@ -1722,14 +1716,12 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
 {
   FeatureSettings me;
 
-  GraduatedColor currentGColor;
+  FeatureColourI currentColor;
 
   FeatureColourChooser chooser;
 
   String type;
 
-  Color currentColor;
-
   JButton button;
 
   JColorChooser colorChooser;
@@ -1769,11 +1761,12 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
     {
       // The user has clicked the cell, so
       // bring up the dialog.
-      if (currentColor != null)
+      if (currentColor.isSimpleColour())
       {
         // bring up simple color chooser
-        button.setBackground(currentColor);
-        colorChooser.setColor(currentColor);
+        button.setBackground(ColorUtils.getColor(currentColor.getColour()));
+        colorChooser
+                .setColor(ColorUtils.getColor(currentColor.getColour()));
         dialog.setVisible(true);
       }
       else
@@ -1790,15 +1783,14 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
     }
     else
     { // User pressed dialog's "OK" button.
-      if (currentColor != null)
+      if (currentColor.isSimpleColour())
       {
-        currentColor = colorChooser.getColor();
+        currentColor = new FeatureColour(
+                new Colour(colorChooser.getColor()));
       }
       else
       {
-        // class cast exceptions may be raised if the chooser created on a
-        // non-graduated color
-        currentGColor = (GraduatedColor) chooser.getLastColour();
+        currentColor = chooser.getLastColour();
       }
       me.table.setValueAt(getCellEditorValue(), selectedRow, 1);
       fireEditingStopped();
@@ -1810,10 +1802,6 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
   @Override
   public Object getCellEditorValue()
   {
-    if (currentColor == null)
-    {
-      return currentGColor;
-    }
     return currentColor;
   }
 
@@ -1822,18 +1810,16 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
   public Component getTableCellEditorComponent(JTable table, Object value,
           boolean isSelected, int row, int column)
   {
-    currentGColor = null;
-    currentColor = null;
+    currentColor = (FeatureColourI) value;
     this.selectedRow = row;
     type = me.table.getValueAt(row, 0).toString();
     button.setOpaque(true);
     button.setBackground(me.getBackground());
-    if (value instanceof GraduatedColor)
+    if (!currentColor.isSimpleColour())
     {
-      currentGColor = (GraduatedColor) value;
       JLabel btn = new JLabel();
       btn.setSize(button.getSize());
-      FeatureSettings.renderGraduatedColor(btn, currentGColor);
+      FeatureSettings.renderGraduatedColor(btn, currentColor);
       button.setBackground(btn.getBackground());
       button.setIcon(btn.getIcon());
       button.setText(btn.getText());
@@ -1842,8 +1828,7 @@ class ColorEditor extends AbstractCellEditor implements TableCellEditor,
     {
       button.setText("");
       button.setIcon(null);
-      currentColor = (Color) value;
-      button.setBackground(currentColor);
+      button.setBackground(ColorUtils.getColor(currentColor.getColour()));
     }
     return button;
   }
index 37be8bc..2cb5bcd 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 
 import java.awt.BorderLayout;
 import java.awt.Color;
@@ -121,7 +122,7 @@ public class IdCanvas extends JPanel
     }
     else
     {
-      gg.setColor(av.getSequenceColour(s));
+      gg.setColor(ColorUtils.getColor(av.getSequenceColour(s)));
       gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),
               charHeight);
       gg.setColor(Color.black);
@@ -383,7 +384,8 @@ public class IdCanvas extends JPanel
         }
         else
         {
-          currentColor = av.getSequenceColour(sequence);
+          currentColor = ColorUtils
+                  .getColor(av.getSequenceColour(sequence));
           currentTextColor = Color.black;
         }
 
index 2799a7e..ef5802e 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.gui;
 
+import jalview.api.FeatureColourI;
 import jalview.api.ViewStyleI;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
@@ -69,9 +70,10 @@ import jalview.schemabinding.version2.Tree;
 import jalview.schemabinding.version2.UserColours;
 import jalview.schemabinding.version2.Viewport;
 import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.FeatureColour;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
@@ -90,6 +92,7 @@ import jalview.ws.params.ArgumentI;
 import jalview.ws.params.AutoCalcSetting;
 import jalview.ws.params.WsParamSetI;
 
+import java.awt.Color;
 import java.awt.Rectangle;
 import java.io.BufferedReader;
 import java.io.DataInputStream;
@@ -1194,34 +1197,32 @@ public class Jalview2XML
                 .getFeatureRenderer().getRenderOrder()
                 .toArray(new String[0]);
 
-        Vector settingsAdded = new Vector();
-        Object gstyle = null;
-        GraduatedColor gcol = null;
+        Vector<String> settingsAdded = new Vector<String>();
         if (renderOrder != null)
         {
           for (int ro = 0; ro < renderOrder.length; ro++)
           {
-            gstyle = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
+            FeatureColourI gstyle = ap.getSeqPanel().seqCanvas
+                    .getFeatureRenderer()
                     .getFeatureStyle(renderOrder[ro]);
             Setting setting = new Setting();
             setting.setType(renderOrder[ro]);
-            if (gstyle instanceof GraduatedColor)
+            if (!gstyle.isSimpleColour())
             {
-              gcol = (GraduatedColor) gstyle;
-              setting.setColour(gcol.getMaxColor().getRGB());
-              setting.setMincolour(gcol.getMinColor().getRGB());
-              setting.setMin(gcol.getMin());
-              setting.setMax(gcol.getMax());
-              setting.setColourByLabel(gcol.isColourByLabel());
-              setting.setAutoScale(gcol.isAutoScale());
-              setting.setThreshold(gcol.getThresh());
-              setting.setThreshstate(gcol.getThreshType());
+              setting.setColour(gstyle.getMaxColour().getRGB());
+              setting.setMincolour(gstyle.getMinColour().getRGB());
+              setting.setMin(gstyle.getMin());
+              setting.setMax(gstyle.getMax());
+              setting.setColourByLabel(gstyle.isColourByLabel());
+              setting.setAutoScale(gstyle.isAutoScaled());
+              setting.setThreshold(gstyle.getThreshold());
+              // -1 = No threshold, 0 = Below, 1 = Above
+              setting.setThreshstate(gstyle.isAboveThreshold() ? 1
+                      : (gstyle.isBelowThreshold() ? 0 : -1));
             }
             else
             {
-              setting.setColour(ap.getSeqPanel().seqCanvas
-                      .getFeatureRenderer().getColour(renderOrder[ro])
-                      .getRGB());
+              setting.setColour(gstyle.getColour().getRGB());
             }
 
             setting.setDisplay(av.getFeaturesDisplayed().isVisible(
@@ -1237,36 +1238,11 @@ public class Jalview2XML
           }
         }
 
-        // Make sure we save none displayed feature settings
-        Iterator en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                .getFeatureColours().keySet().iterator();
-        while (en.hasNext())
-        {
-          String key = en.next().toString();
-          if (settingsAdded.contains(key))
-          {
-            continue;
-          }
-
-          Setting setting = new Setting();
-          setting.setType(key);
-          setting.setColour(ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                  .getColour(key).getRGB());
-
-          setting.setDisplay(false);
-          float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
-                  .getOrder(key);
-          if (rorder > -1)
-          {
-            setting.setOrder(rorder);
-          }
-          fs.addSetting(setting);
-          settingsAdded.addElement(key);
-        }
         // is groups actually supposed to be a map here ?
-        en = ap.getSeqPanel().seqCanvas.getFeatureRenderer()
+        Iterator<String> en = ap.getSeqPanel().seqCanvas
+                .getFeatureRenderer()
                 .getFeatureGroups().iterator();
-        Vector groupsAdded = new Vector();
+        Vector<String> groupsAdded = new Vector<String>();
         while (en.hasNext())
         {
           String grp = en.next().toString();
@@ -1283,7 +1259,6 @@ public class Jalview2XML
           groupsAdded.addElement(grp);
         }
         jms.setFeatureSettings(fs);
-
       }
 
       if (av.hasHiddenColumns())
@@ -3147,8 +3122,8 @@ public class Jalview2XML
 
         sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
 
-        sg.textColour = new java.awt.Color(jGroup.getTextCol1());
-        sg.textColour2 = new java.awt.Color(jGroup.getTextCol2());
+        sg.textColour = new Colour(jGroup.getTextCol1());
+        sg.textColour2 = new Colour(jGroup.getTextCol2());
         sg.setShowNonconserved(jGroup.hasShowUnconserved() ? jGroup
                 .isShowUnconserved() : false);
         sg.thresholdTextColour = jGroup.getTextColThreshold();
@@ -4148,7 +4123,7 @@ public class Jalview2XML
     for (int i = 0; i < JSEQ.length; i++)
     {
       af.viewport.setSequenceColour(af.viewport.getAlignment()
-              .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
+              .getSequenceAt(i), new Colour(JSEQ[i].getColour()));
     }
 
     af.viewport.setGatherViewsHere(view.getGatheredViews());
@@ -4234,8 +4209,8 @@ public class Jalview2XML
 
     af.viewport.setShowText(view.getShowText());
 
-    af.viewport.setTextColour(new java.awt.Color(view.getTextCol1()));
-    af.viewport.setTextColour2(new java.awt.Color(view.getTextCol2()));
+    af.viewport.setTextColour(new Colour(view.getTextCol1()));
+    af.viewport.setTextColour2(new Colour(view.getTextCol2()));
     af.viewport.setThresholdTextColour(view.getTextColThreshold());
     af.viewport.setShowUnconserved(view.hasShowUnconserved() ? view
             .isShowUnconserved() : false);
@@ -4354,25 +4329,34 @@ public class Jalview2XML
       af.viewport.setFeaturesDisplayed(fdi = new FeaturesDisplayed());
       String[] renderOrder = new String[jms.getFeatureSettings()
               .getSettingCount()];
-      Hashtable featureGroups = new Hashtable();
-      Hashtable featureColours = new Hashtable();
-      Hashtable featureOrder = new Hashtable();
+      Map<String, FeatureColourI> featureColours = new Hashtable<String, FeatureColourI>();
+      Map<String, Float> featureOrder = new Hashtable<String, Float>();
 
       for (int fs = 0; fs < jms.getFeatureSettings().getSettingCount(); fs++)
       {
         Setting setting = jms.getFeatureSettings().getSetting(fs);
         if (setting.hasMincolour())
         {
-          GraduatedColor gc = setting.hasMin() ? new GraduatedColor(
-                  new java.awt.Color(setting.getMincolour()),
-                  new java.awt.Color(setting.getColour()),
-                  setting.getMin(), setting.getMax()) : new GraduatedColor(
-                  new java.awt.Color(setting.getMincolour()),
-                  new java.awt.Color(setting.getColour()), 0, 1);
+          FeatureColourI gc = setting.hasMin() ? new FeatureColour(
+                  new Colour(new Color(setting.getMincolour())),
+                  new Colour(new Color(setting.getColour())),
+                  setting.getMin(), setting.getMax()) : new FeatureColour(
+                  new Colour(new Color(setting.getMincolour())),
+                  new Colour(new Color(setting.getColour())),
+                  0, 1);
           if (setting.hasThreshold())
           {
-            gc.setThresh(setting.getThreshold());
-            gc.setThreshType(setting.getThreshstate());
+            gc.setThreshold(setting.getThreshold());
+            int threshstate = setting.getThreshstate();
+            // -1 = None, 0 = Below, 1 = Above threshold
+            if (threshstate == 0)
+            {
+              gc.setBelowThreshold(true);
+            }
+            else if (threshstate == 1)
+            {
+              gc.setAboveThreshold(true);
+            }
           }
           gc.setAutoScaled(true); // default
           if (setting.hasAutoScale())
@@ -4388,8 +4372,8 @@ public class Jalview2XML
         }
         else
         {
-          featureColours.put(setting.getType(),
-                  new java.awt.Color(setting.getColour()));
+          featureColours.put(setting.getType(), new FeatureColour(
+                  new Colour(new Color(setting.getColour()))));
         }
         renderOrder[fs] = setting.getType();
         if (setting.hasOrder())
@@ -4406,7 +4390,7 @@ public class Jalview2XML
           fdi.setVisible(setting.getType());
         }
       }
-      Hashtable fgtable = new Hashtable();
+      Map<String, Boolean> fgtable = new Hashtable<String, Boolean>();
       for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++)
       {
         Group grp = jms.getFeatureSettings().getGroup(gs);
index 61e20fa..fb27e19 100755 (executable)
@@ -35,6 +35,7 @@ import jalview.binding.Tree;
 import jalview.binding.UserColours;
 import jalview.binding.Viewport;
 import jalview.datamodel.PDBEntry;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
@@ -310,7 +311,7 @@ public class Jalview2XML_V1
     for (int i = 0; i < JSEQ.length; i++)
     {
       af.viewport.setSequenceColour(af.viewport.getAlignment()
-              .getSequenceAt(i), new java.awt.Color(JSEQ[i].getColour()));
+              .getSequenceAt(i), new Colour(JSEQ[i].getColour()));
     }
 
     // af.changeColour() );
index 0719fa0..cd2ecfe 100755 (executable)
@@ -25,6 +25,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequencePoint;
 import jalview.math.RotatableMatrix;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
@@ -136,6 +137,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
 
     addMouseWheelListener(new MouseWheelListener()
     {
+      @Override
       public void mouseWheelMoved(MouseWheelEvent e)
       {
         if (e.getWheelRotation() > 0)
@@ -162,6 +164,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
 
   boolean first = true;
 
+  @Override
   public void setPoints(Vector points, int npoint)
   {
     this.points = points;
@@ -327,7 +330,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
       dim = height;
     }
 
-    return (float) ((dim * scalefactor) / (2 * maxwidth));
+    return (dim * scalefactor) / (2 * maxwidth);
   }
 
   /**
@@ -352,6 +355,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Dimension getPreferredSize()
   {
     if (prefsize != null)
@@ -369,6 +373,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * 
    * @return DOCUMENT ME!
    */
+  @Override
   public Dimension getMinimumSize()
   {
     return getPreferredSize();
@@ -380,6 +385,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param g
    *          DOCUMENT ME!
    */
+  @Override
   public void paintComponent(Graphics g1)
   {
 
@@ -474,8 +480,8 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
-      int y = (int) ((float) (sp.coord[1] - centre[1]) * scale)
+      int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth;
+      int y = (int) ((sp.coord[1] - centre[1]) * scale)
               + halfheight;
       float z = sp.coord[1] - centre[2];
 
@@ -485,7 +491,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
       }
       else
       {
-        g.setColor(av.getSequenceColour(sp.sequence));
+        g.setColor(ColorUtils.getColor(av.getSequenceColour(sp.sequence)));
       }
 
       if (av.getSelectionGroup() != null)
@@ -546,6 +552,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void keyTyped(KeyEvent evt)
   {
   }
@@ -556,6 +563,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void keyReleased(KeyEvent evt)
   {
   }
@@ -566,6 +574,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void keyPressed(KeyEvent evt)
   {
     if (evt.getKeyCode() == KeyEvent.VK_UP)
@@ -597,6 +606,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseClicked(MouseEvent evt)
   {
   }
@@ -607,6 +617,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseEntered(MouseEvent evt)
   {
   }
@@ -617,6 +628,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseExited(MouseEvent evt)
   {
   }
@@ -627,6 +639,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseReleased(MouseEvent evt)
   {
   }
@@ -637,6 +650,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mousePressed(MouseEvent evt)
   {
     int x = evt.getX();
@@ -689,6 +703,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
   // controller.handleSequenceSelectionEvent(new
   // SequenceSelectionEvent(this,sel));
   // }
+  @Override
   public void mouseMoved(MouseEvent evt)
   {
     SequenceI found = findPoint(evt.getX(), evt.getY());
@@ -709,6 +724,7 @@ public class RotatableCanvas extends JPanel implements MouseListener,
    * @param evt
    *          DOCUMENT ME!
    */
+  @Override
   public void mouseDragged(MouseEvent evt)
   {
     mx = evt.getX();
@@ -724,8 +740,8 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     {
       rotmat.setIdentity();
 
-      rotmat.rotate((float) (my - omy), 'x');
-      rotmat.rotate((float) (mx - omx), 'y');
+      rotmat.rotate(my - omy, 'x');
+      rotmat.rotate(mx - omx, 'y');
 
       for (int i = 0; i < npoint; i++)
       {
@@ -772,8 +788,8 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int tmp1 = (int) (((sp.coord[0] - centre[0]) * scale) + ((float) getWidth() / 2.0));
-      int tmp2 = (int) (((sp.coord[1] - centre[1]) * scale) + ((float) getHeight() / 2.0));
+      int tmp1 = (int) (((sp.coord[0] - centre[0]) * scale) + (getWidth() / 2.0));
+      int tmp2 = (int) (((sp.coord[1] - centre[1]) * scale) + (getHeight() / 2.0));
 
       if ((tmp1 > x1) && (tmp1 < x2) && (tmp2 > y1) && (tmp2 < y2))
       {
@@ -813,9 +829,9 @@ public class RotatableCanvas extends JPanel implements MouseListener,
     for (int i = 0; i < npoint; i++)
     {
       SequencePoint sp = (SequencePoint) points.elementAt(i);
-      int px = (int) ((float) (sp.coord[0] - centre[0]) * scale)
+      int px = (int) ((sp.coord[0] - centre[0]) * scale)
               + halfwidth;
-      int py = (int) ((float) (sp.coord[1] - centre[1]) * scale)
+      int py = (int) ((sp.coord[1] - centre[1]) * scale)
               + halfheight;
 
       if ((Math.abs(px - x) < 3) && (Math.abs(py - y) < 3))
index 0f24b4b..8a120c5 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
 
 import java.awt.BasicStroke;
 import java.awt.BorderLayout;
@@ -844,7 +845,7 @@ public class SeqCanvas extends JComponent
               else
               {
                 g.setStroke(new BasicStroke());
-                g.setColor(group.getOutlineColour());
+                g.setColor(ColorUtils.getColor(group.getOutlineColour()));
               }
             }
           }
index 258a229..f215f9d 100755 (executable)
  */
 package jalview.gui;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureRenderer;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
+import jalview.util.ColorUtils;
 
 import java.awt.Color;
 import java.awt.FontMetrics;
@@ -89,7 +92,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
   }
 
   @Override
-  public Color getResidueBoxColour(SequenceI seq, int i)
+  public ColorI getResidueBoxColour(SequenceI seq, int i)
   {
     allGroups = av.getAlignment().findAllGroups(seq);
 
@@ -105,7 +108,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       getBoxColour(av.getGlobalColourScheme(), seq, i);
     }
 
-    return resBoxColour;
+    return new Colour(resBoxColour);
   }
 
   /**
@@ -119,12 +122,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
    * @return
    */
   @Override
-  public Color getResidueColour(final SequenceI seq, int position,
+  public ColorI getResidueColour(final SequenceI seq, int position,
           FeatureRenderer fr)
   {
     // TODO replace 8 or so code duplications with calls to this method
     // (refactored as needed)
-    Color col = getResidueBoxColour(seq, position);
+    ColorI col = getResidueBoxColour(seq, position);
 
     if (fr != null)
     {
@@ -303,7 +306,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
     {
       end = seq.getLength() - 1;
     }
-    graphics.setColor(av.getTextColour());
+    graphics.setColor(ColorUtils.getColor(av.getTextColour()));
 
     if (monospacedFont && av.getShowText() && allGroups.length == 0
             && !av.getColourText() && av.getThresholdTextColour() == 0)
@@ -330,7 +333,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
       for (int i = start; i <= end; i++)
       {
 
-        graphics.setColor(av.getTextColour());
+        graphics.setColor(ColorUtils.getColor(av.getTextColour()));
         getboxColour = false;
         s = seq.getCharAt(i);
 
@@ -362,13 +365,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
               if (resBoxColour.getRed() + resBoxColour.getBlue()
                       + resBoxColour.getGreen() < currentSequenceGroup.thresholdTextColour)
               {
-                graphics.setColor(currentSequenceGroup.textColour2);
+                graphics.setColor(ColorUtils.getColor(currentSequenceGroup.textColour2));
               }
             }
           }
           else
           {
-            graphics.setColor(currentSequenceGroup.textColour);
+            graphics.setColor(ColorUtils.getColor(currentSequenceGroup.textColour));
           }
           if (!isarep && !isgrep
                   && currentSequenceGroup.getShowNonconserved()) // todo
@@ -412,7 +415,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer
             if (resBoxColour.getRed() + resBoxColour.getBlue()
                     + resBoxColour.getGreen() < av.getThresholdTextColour())
             {
-              graphics.setColor(av.getTextColour2());
+              graphics.setColor(ColorUtils.getColor(av.getTextColour2()));
             }
           }
           if (!isarep && av.getShowUnconserved())
index 6bac6df..2ec1c18 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.gui;
 
 import jalview.datamodel.SequenceGroup;
+import jalview.schemes.Colour;
 import jalview.util.MessageManager;
 
 import java.awt.BorderLayout;
@@ -89,6 +90,7 @@ public class TextColourChooser
 
     col1.addMouseListener(new MouseAdapter()
     {
+      @Override
       public void mousePressed(MouseEvent e)
       {
         Color col = JColorChooser.showDialog(bigpanel,
@@ -104,6 +106,7 @@ public class TextColourChooser
 
     col2.addMouseListener(new MouseAdapter()
     {
+      @Override
       public void mousePressed(MouseEvent e)
       {
         Color col = JColorChooser.showDialog(bigpanel,
@@ -119,6 +122,7 @@ public class TextColourChooser
 
     slider.addChangeListener(new ChangeListener()
     {
+      @Override
       public void stateChanged(ChangeEvent evt)
       {
         thresholdChanged(slider.getValue());
@@ -138,14 +142,14 @@ public class TextColourChooser
     {
       if (sg == null)
       {
-        ap.av.setTextColour(new Color(original1));
-        ap.av.setTextColour2(new Color(original2));
+        ap.av.setTextColour(new Colour(original1));
+        ap.av.setTextColour2(new Colour(original2));
         ap.av.setThresholdTextColour(originalThreshold);
       }
       else
       {
-        sg.textColour = new Color(original1);
-        sg.textColour2 = new Color(original2);
+        sg.textColour = new Colour(original1);
+        sg.textColour2 = new Colour(original2);
         sg.thresholdTextColour = originalThreshold;
       }
     }
@@ -155,7 +159,7 @@ public class TextColourChooser
   {
     if (sg == null)
     {
-      ap.av.setTextColour(col);
+      ap.av.setTextColour(new Colour(col));
       if (ap.av.getColourAppliesToAllGroups())
       {
         setGroupTextColour();
@@ -163,7 +167,7 @@ public class TextColourChooser
     }
     else
     {
-      sg.textColour = col;
+      sg.textColour = new Colour(col);
     }
 
     ap.paintAlignment(true);
@@ -173,7 +177,7 @@ public class TextColourChooser
   {
     if (sg == null)
     {
-      ap.av.setTextColour2(col);
+      ap.av.setTextColour2(new Colour(col));
       if (ap.av.getColourAppliesToAllGroups())
       {
         setGroupTextColour();
@@ -181,7 +185,7 @@ public class TextColourChooser
     }
     else
     {
-      sg.textColour2 = col;
+      sg.textColour2 = new Colour(col);
     }
 
     ap.paintAlignment(true);
index f21c5e7..149a587 100755 (executable)
@@ -27,11 +27,13 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.SequenceNode;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
 import jalview.schemes.UserColourScheme;
 import jalview.structure.SelectionSource;
+import jalview.util.ColorUtils;
 import jalview.util.Format;
 import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
@@ -245,7 +247,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         }
         else
         {
-          g.setColor(av.getSequenceColour(seq).darker());
+          g.setColor(ColorUtils.getColor(av.getSequenceColour(seq))
+                  .darker());
         }
       }
       else
@@ -522,7 +525,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
           for (int a = 0; a < aps.length; a++)
           {
             final SequenceI seq = (SequenceI) node.element();
-            aps[a].av.setSequenceColour(seq, c);
+            aps[a].av.setSequenceColour(seq, new Colour(c));
           }
         }
       }
@@ -1002,7 +1005,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
               codingComplement.getAlignment().addGroup(mappedGroup);
               for (SequenceI seq : mappedGroup.getSequences())
               {
-                codingComplement.setSequenceColour(seq, col.brighter());
+                codingComplement.setSequenceColour(seq,
+                        new Colour(col.brighter()));
               }
             }
           }
index 8b3aa98..9ef9ee8 100755 (executable)
@@ -30,6 +30,7 @@ import jalview.datamodel.GraphLine;
 import jalview.datamodel.HiddenSequences;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.ResidueProperties;
@@ -1670,11 +1671,13 @@ public class AnnotationFile
         }
         else if (key.equalsIgnoreCase("textCol1"))
         {
-          sg.textColour = new UserColourScheme(value).findColour('A');
+          sg.textColour = new Colour(
+                  new UserColourScheme(value).findColour('A'));
         }
         else if (key.equalsIgnoreCase("textCol2"))
         {
-          sg.textColour2 = new UserColourScheme(value).findColour('A');
+          sg.textColour2 = new Colour(
+                  new UserColourScheme(value).findColour('A'));
         }
         else if (key.equalsIgnoreCase("textColThreshold"))
         {
index 2dd5f26..40f83d3 100755 (executable)
@@ -23,6 +23,7 @@ package jalview.io;
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.SequenceIdMatcher;
 import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
 import jalview.api.FeaturesSourceI;
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.Alignment;
@@ -33,15 +34,13 @@ import jalview.datamodel.SequenceI;
 import jalview.io.gff.GffHelperBase;
 import jalview.io.gff.GffHelperFactory;
 import jalview.io.gff.GffHelperI;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.FeatureColour;
 import jalview.schemes.UserColourScheme;
 import jalview.util.Format;
 import jalview.util.MapList;
 import jalview.util.ParseHtmlBodyAndLinks;
 import jalview.util.StringUtils;
 
-import java.awt.Color;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -140,7 +139,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    *          - process html strings into plain text
    * @return true if features were added
    */
-  public boolean parse(AlignmentI align, Map<String, Object> colours,
+  public boolean parse(AlignmentI align,
+          Map<String, FeatureColourI> colours,
           boolean removeHTML)
   {
     return parse(align, colours, removeHTML, false);
@@ -177,7 +177,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    *          - when true, ID matches to compound sequence IDs are allowed
    * @return true if features were added
    */
-  public boolean parse(AlignmentI align, Map<String, Object> colours,
+  public boolean parse(AlignmentI align,
+          Map<String, FeatureColourI> colours,
           boolean removeHTML, boolean relaxedIdmatching)
   {
     Map<String, String> gffProps = new HashMap<String, String>();
@@ -297,7 +298,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @param featureGroup
    */
   protected boolean parseJalviewFeature(String line, String[] gffColumns,
-          AlignmentI alignment, Map<String, Object> featureColours,
+          AlignmentI alignment, Map<String, FeatureColourI> featureColours,
           boolean removeHTML, boolean relaxedIdMatching, String featureGroup)
   {
     /*
@@ -350,7 +351,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
        * synthesize a colour from the feature type
        */
       UserColourScheme ucs = new UserColourScheme(ft);
-      featureColours.put(ft, ucs.findColour('A'));
+      featureColours.put(ft, new FeatureColour(ucs.findColour('A')));
     }
     SequenceFeature sf = new SequenceFeature(ft, desc, "", startPos,
             endPos, featureGroup);
@@ -393,9 +394,9 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    *          map to which to add derived colour specification
    */
   protected void parseFeatureColour(String line, String featureType,
-          String[] gffColumns, Map<String, Object> colours)
+          String[] gffColumns, Map<String, FeatureColourI> colours)
   {
-    Object colour = null;
+    FeatureColourI colour = null;
     String colscheme = gffColumns[1];
     if (colscheme.indexOf("|") > -1
             || colscheme.trim().equalsIgnoreCase("label"))
@@ -405,7 +406,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
     else
     {
       UserColourScheme ucs = new UserColourScheme(colscheme);
-      colour = ucs.findColour('A');
+      colour = new FeatureColour(ucs.findColour('A'));
     }
     if (colour != null)
     {
@@ -420,7 +421,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @param colourDescriptor
    * @return
    */
-  protected GraduatedColor parseGraduatedColourScheme(String line,
+  protected FeatureColourI parseGraduatedColourScheme(String line,
           String colourDescriptor)
   {
     // Parse '|' separated graduated colourscheme fields:
@@ -530,10 +531,10 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
       maxcol = "000000";
     }
 
-    GraduatedColor colour = null;
+    FeatureColourI colour = null;
     try
     {
-      colour = new GraduatedColor(
+      colour = new FeatureColour(
               new UserColourScheme(mincol).findColour('A'),
               new UserColourScheme(maxcol).findColour('A'), min, max);
     } catch (Exception e)
@@ -548,21 +549,23 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
       colour.setAutoScaled(abso == null);
       // add in any additional parameters
       String ttype = null, tval = null;
+      boolean hasThreshold = false;
       if (gcol.hasMoreTokens())
       {
         // threshold type and possibly a threshold value
         ttype = gcol.nextToken();
         if (ttype.toLowerCase().startsWith("below"))
         {
-          colour.setThreshType(AnnotationColourGradient.BELOW_THRESHOLD);
+          colour.setBelowThreshold(true);
+          hasThreshold = true;
         }
         else if (ttype.toLowerCase().startsWith("above"))
         {
-          colour.setThreshType(AnnotationColourGradient.ABOVE_THRESHOLD);
+          colour.setAboveThreshold(true);
+          hasThreshold = true;
         }
         else
         {
-          colour.setThreshType(AnnotationColourGradient.NO_THRESHOLD);
           if (!ttype.toLowerCase().startsWith("no"))
           {
             System.err.println("Ignoring unrecognised threshold type : "
@@ -570,13 +573,13 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
           }
         }
       }
-      if (colour.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
+      if (hasThreshold)
       {
         try
         {
           gcol.nextToken();
           tval = gcol.nextToken();
-          colour.setThresh(new Float(tval).floatValue());
+          colour.setThreshold(new Float(tval).floatValue());
         } catch (Exception e)
         {
           System.err.println("Couldn't parse threshold value as a float: ("
@@ -703,7 +706,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @return features file contents
    */
   public String printJalviewFormat(SequenceI[] sequences,
-          Map<String, Object> visible)
+          Map<String, FeatureColourI> visible)
   {
     return printJalviewFormat(sequences, visible, true, true);
   }
@@ -713,7 +716,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * 
    * @param sequences
    *          source of features
-   * @param visible
+   * @param featureColours
    *          hash of Colours for each feature type
    * @param visOnly
    *          when true only feature types in 'visible' will be output
@@ -723,68 +726,62 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @return features file contents
    */
   public String printJalviewFormat(SequenceI[] sequences,
-          Map<String, Object> visible, boolean visOnly, boolean nonpos)
+          Map<String, FeatureColourI> featureColours, boolean visOnly,
+          boolean nonpos)
   {
     StringBuilder out = new StringBuilder(256);
     boolean featuresGen = false;
-    if (visOnly && !nonpos && (visible == null || visible.size() < 1))
+    if (visOnly && !nonpos
+            && (featureColours == null || featureColours.size() < 1))
     {
       // no point continuing.
       return "No Features Visible";
     }
 
-    if (visible != null && visOnly)
+    if (featureColours != null && visOnly)
     {
       // write feature colours only if we're given them and we are generating
       // viewed features
       // TODO: decide if feature links should also be written here ?
-      Iterator<String> en = visible.keySet().iterator();
+      Iterator<String> en = featureColours.keySet().iterator();
       String featureType, color;
       while (en.hasNext())
       {
-        featureType = en.next().toString();
-
-        if (visible.get(featureType) instanceof GraduatedColor)
+        featureType = en.next();
+        FeatureColourI fc = featureColours.get(featureType);
+        if (fc.isSimpleColour())
         {
-          GraduatedColor gc = (GraduatedColor) visible.get(featureType);
-          color = (gc.isColourByLabel() ? "label|" : "")
-                  + Format.getHexString(gc.getMinColor()) + "|"
-                  + Format.getHexString(gc.getMaxColor())
-                  + (gc.isAutoScale() ? "|" : "|abso|") + gc.getMin() + "|"
-                  + gc.getMax() + "|";
-          if (gc.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
-          {
-            if (gc.getThreshType() == AnnotationColourGradient.BELOW_THRESHOLD)
+          color = Format.getHexString(fc.getColour());
+        }
+        else
+        {
+          color = (fc.isColourByLabel() ? "label|" : "")
+                  + Format.getHexString(fc.getMinColour()) + "|"
+                  + Format.getHexString(fc.getMaxColour())
+                  + (fc.isAutoScaled() ? "|" : "|abso|") + fc.getMin() + "|"
+                  + fc.getMax() + "|";
+            if (fc.isBelowThreshold())
             {
               color += "below";
             }
-            else
+            else if (fc.isAboveThreshold())
             {
-              if (gc.getThreshType() != AnnotationColourGradient.ABOVE_THRESHOLD)
-              {
-                System.err.println("WARNING: Unsupported threshold type ("
-                        + gc.getThreshType() + ") : Assuming 'above'");
-              }
               color += "above";
             }
             // add the value
-            color += "|" + gc.getThresh();
+            color += "|" + fc.getThreshold();
           }
-          else
-          {
-            color += "none";
-          }
-        }
-        else if (visible.get(featureType) instanceof Color)
-        {
-          color = Format.getHexString((Color) visible.get(featureType));
-        }
-        else
-        {
-          // legacy support for integer objects containing colour triplet values
-          color = Format.getHexString(new Color(Integer.parseInt(visible
-                  .get(featureType).toString())));
-        }
+//          else
+//          {
+//            color += "none";
+//          }
+        // else
+        // {
+        // // legacy support for integer objects containing colour triplet
+        // values
+        // color = Format.getHexString(new Color(Integer
+        // .parseInt(fc.toString())));
+        // }
         out.append(featureType);
         out.append(TAB);
         out.append(color);
@@ -806,7 +803,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
         {
           isnonpos = features[j].begin == 0 && features[j].end == 0;
           if ((!nonpos && isnonpos)
-                  || (!isnonpos && visOnly && !visible
+                  || (!isnonpos && visOnly && !featureColours
                           .containsKey(features[j].type)))
           {
             continue;
@@ -846,7 +843,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
           {
             isnonpos = features[j].begin == 0 && features[j].end == 0;
             if ((!nonpos && isnonpos)
-                    || (!isnonpos && visOnly && !visible
+                    || (!isnonpos && visOnly && !featureColours
                             .containsKey(features[j].type)))
             {
               // skip if feature is nonpos and we ignore them or if we only
@@ -1003,7 +1000,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * @return
    */
   public String printGffFormat(SequenceI[] sequences,
-          Map<String, Object> visible)
+          Map<String, FeatureColourI> visible)
   {
     return printGffFormat(sequences, visible, true, true);
   }
@@ -1013,14 +1010,15 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
    * 
    * @param sequences
    *          the sequences whose features are to be output
-   * @param visible
+   * @param featureColours
    *          a map whose keys are the type names of visible features
    * @param outputVisibleOnly
    * @param includeNonPositionalFeatures
    * @return
    */
   public String printGffFormat(SequenceI[] sequences,
-          Map<String, Object> visible, boolean outputVisibleOnly,
+          Map<String, FeatureColourI> featureColours,
+          boolean outputVisibleOnly,
           boolean includeNonPositionalFeatures)
   {
     StringBuilder out = new StringBuilder(256);
@@ -1045,7 +1043,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
           // TODO why the test !isnonpos here?
           // what about not visible non-positional features?
           if (!isnonpos && outputVisibleOnly
-                  && !visible.containsKey(sf.type))
+                  && !featureColours.containsKey(sf.type))
           {
             /*
              * ignore not visible features if not wanted
index df0dc06..6c6224c 100755 (executable)
  */
 package jalview.io;
 
+import jalview.api.ColorI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.FeatureRenderer;
 import jalview.gui.SequenceRenderer;
+import jalview.schemes.Colour;
 import jalview.util.MessageManager;
 
-import java.awt.Color;
 import java.awt.Font;
 import java.io.PrintWriter;
 
@@ -40,7 +41,7 @@ public class HTMLOutput
 
   jalview.renderer.seqfeatures.FeatureRenderer fr;
 
-  Color color;
+  ColorI color;
 
   public HTMLOutput(AlignmentPanel ap, SequenceRenderer sr,
           FeatureRenderer fr1)
@@ -155,7 +156,7 @@ public class HTMLOutput
         }
         else
         {
-          color = Color.white;
+          color = Colour.white;
         }
 
         if (color.getRGB() < -1)
@@ -257,7 +258,7 @@ public class HTMLOutput
           }
           else
           {
-            color = Color.white;
+            color = Colour.white;
           }
 
           if (color.getRGB() < -1)
index e554b8e..79c055e 100644 (file)
@@ -30,6 +30,7 @@ import jalview.gui.HTMLOptions;
 import jalview.gui.IProgressIndicator;
 import jalview.gui.OOMWarning;
 import jalview.math.AlignmentDimension;
+import jalview.util.ColorUtils;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
@@ -308,7 +309,7 @@ public class HtmlSvgOutput
       }
       else
       {
-        currentColor = av.getSequenceColour(seq);
+        currentColor = ColorUtils.getColor(av.getSequenceColour(seq));
         currentTextColor = Color.black;
       }
       pg[0].setColor(currentColor);
index 36980f8..dfd351a 100644 (file)
@@ -46,6 +46,7 @@ import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.json.binding.biojson.v1.SequenceFeaturesPojo;
 import jalview.json.binding.biojson.v1.SequenceGrpPojo;
 import jalview.json.binding.biojson.v1.SequencePojo;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.schemes.UserColourScheme;
 import jalview.viewmodel.seqfeatures.FeaturesDisplayed;
@@ -344,7 +345,7 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
                   String.valueOf(seq.hashCode()));
 
           String featureColour = (fr == null) ? null : jalview.util.Format
-                  .getHexString(fr.findFeatureColour(Color.white, seq,
+                  .getHexString(fr.findFeatureColour(Colour.white, seq,
                           seq.findIndex(sf.getBegin())));
           jsonFeature.setXstart(seq.findIndex(sf.getBegin()) - 1);
           jsonFeature.setXend(seq.findIndex(sf.getEnd()));
index 83bb37e..0c2f030 100644 (file)
@@ -1,11 +1,11 @@
 package jalview.io;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureColourI;
+import jalview.schemes.Colour;
 import jalview.schemes.FeatureColourAdapter;
 import jalview.schemes.FeatureSettingsAdapter;
 
-import java.awt.Color;
-
 public class PDBFeatureSettings extends FeatureSettingsAdapter
 {
 
@@ -29,9 +29,9 @@ public class PDBFeatureSettings extends FeatureSettingsAdapter
       {
 
         @Override
-        public Color getColour()
+        public ColorI getColour()
         {
-          return Color.RED;
+          return Colour.red;
         }
       };
     }
index 817ba9c..63263d2 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.io.packed;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.io.NewickFile;
@@ -57,7 +58,7 @@ public class JalviewDataset
   /**
    * @return the featureColours
    */
-  public Map<String, Object> getFeatureColours()
+  public Map<String, FeatureColourI> getFeatureColours()
   {
     return featureColours;
   }
@@ -66,7 +67,7 @@ public class JalviewDataset
    * @param featureColours
    *          the featureColours to set
    */
-  public void setFeatureColours(Map<String, Object> featureColours)
+  public void setFeatureColours(Map<String, FeatureColourI> featureColours)
   {
     this.featureColours = featureColours;
   }
@@ -187,7 +188,7 @@ public class JalviewDataset
   /**
    * current set of feature colours
    */
-  Map<String, Object> featureColours;
+  Map<String, FeatureColourI> featureColours;
 
   /**
    * original identity of each sequence in results
@@ -201,7 +202,7 @@ public class JalviewDataset
     seqDetails = new Hashtable();
     al = new ArrayList<AlignmentSet>();
     parentDataset = null;
-    featureColours = new HashMap<String, Object>();
+    featureColours = new HashMap<String, FeatureColourI>();
   }
 
   /**
@@ -209,7 +210,8 @@ public class JalviewDataset
    * 
    * @param parentAlignment
    */
-  public JalviewDataset(AlignmentI aldataset, Map<String, Object> fc,
+  public JalviewDataset(AlignmentI aldataset,
+          Map<String, FeatureColourI> fc,
           Hashtable seqDets)
   {
     // TODO not used - remove?
@@ -231,7 +233,8 @@ public class JalviewDataset
    *          (may be null) alignment to associate new annotation and trees
    *          with.
    */
-  public JalviewDataset(AlignmentI aldataset, Map<String, Object> fc,
+  public JalviewDataset(AlignmentI aldataset,
+          Map<String, FeatureColourI> fc,
           Hashtable seqDets, AlignmentI parentAlignment)
   {
     this();
index 01369b9..71999f0 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.io.packed;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.AlignmentI;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.FileParse;
@@ -157,7 +158,7 @@ public class ParsePackedSet
         // if not, create one.
         if (context.featureColours == null)
         {
-          context.featureColours = new HashMap<String, Object>();
+          context.featureColours = new HashMap<String, FeatureColourI>();
         }
         try
         {
index 0d14cd9..e6e3071 100644 (file)
  */
 package jalview.renderer.seqfeatures;
 
+import jalview.api.ColorI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 
 import java.awt.AlphaComposite;
@@ -169,14 +171,19 @@ public class FeatureRenderer extends FeatureRendererModel
   BufferedImage offscreenImage;
 
   @Override
-  public Color findFeatureColour(Color initialCol, SequenceI seq, int res)
+  public ColorI findFeatureColour(ColorI initialCol, SequenceI seq, int res)
   {
-    return new Color(findFeatureColour(initialCol.getRGB(), seq, res));
+    return new Colour(findFeatureColour(initialCol.getRGB(), seq, res));
+  }
+
+  public ColorI findFeatureColour(Color initialCol, SequenceI seq, int res)
+  {
+    return findFeatureColour(new Colour(initialCol), seq, res);
   }
 
   /**
-   * This is used by the Molecule Viewer and Overview to get the accurate
-   * colourof the rendered sequence
+   * This is used by the Molecule Viewer and Overview to get the accurate colour
+   * of the rendered sequence
    */
   public synchronized int findFeatureColour(int initialCol,
           final SequenceI seq, int column)
@@ -246,7 +253,7 @@ public class FeatureRenderer extends FeatureRendererModel
       }
       else
       {
-        return ((Integer) currentColour).intValue();
+        return currentColour.intValue();
       }
     }
 
@@ -262,6 +269,8 @@ public class FeatureRenderer extends FeatureRendererModel
 
   int epos;
 
+  private Integer currentColour;
+
   public synchronized void drawSequence(Graphics g, final SequenceI seq,
           int start, int end, int y1)
   {
diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java
new file mode 100644 (file)
index 0000000..37c85d4
--- /dev/null
@@ -0,0 +1,684 @@
+package jalview.schemes;
+
+import jalview.api.ColorI;
+import jalview.api.FeatureColourI;
+import jalview.datamodel.SequenceFeature;
+import jalview.util.Format;
+
+import java.awt.Color;
+import java.util.StringTokenizer;
+
+/**
+ * A class that wraps either a simple colour or a graduated colour
+ */
+public class FeatureColour implements FeatureColourI
+{
+  private static final String BAR = "|";
+
+  final private ColorI colour;
+
+  final private ColorI minColour;
+
+  final private ColorI maxColour;
+
+  private boolean graduatedColour;
+
+  private boolean colourByLabel;
+
+  private float threshold;
+
+  private float base;
+
+  private float range;
+
+  private boolean belowThreshold;
+
+  private boolean aboveThreshold;
+
+  private boolean thresholdIsMinOrMax;
+
+  private boolean isHighToLow;
+
+  private boolean autoScaled;
+
+  final private float minRed;
+
+  final private float minGreen;
+
+  final private float minBlue;
+
+  final private float deltaRed;
+
+  final private float deltaGreen;
+
+  final private float deltaBlue;
+
+  /**
+   * Parses a Jalview features file format colour descriptor
+   * [label|][mincolour|maxcolour
+   * |[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue] Examples:
+   * <ul>
+   * <li>red</li>
+   * <li>a28bbb</li>
+   * <li>25,125,213</li>
+   * <li>label</li>
+   * <li>label|||0.0|0.0|above|12.5</li>
+   * <li>label|||0.0|0.0|below|12.5</li>
+   * <li>red|green|12.0|26.0|none</li>
+   * <li>a28bbb|3eb555|12.0|26.0|above|12.5</li>
+   * <li>a28bbb|3eb555|abso|12.0|26.0|below|12.5</li>
+   * </ul>
+   * 
+   * @param descriptor
+   * @return
+   * @throws IllegalArgumentException
+   *           if not parseable
+   */
+  public static FeatureColour parseJalviewFeatureColour(String descriptor)
+  {
+    StringTokenizer gcol = new StringTokenizer(descriptor, "|", true);
+    float min = Float.MIN_VALUE;
+    float max = Float.MAX_VALUE;
+    boolean labelColour = false;
+
+    String mincol = gcol.nextToken();
+    if (mincol == "|")
+    {
+      throw new IllegalArgumentException(
+              "Expected either 'label' or a colour specification in the line: "
+                      + descriptor);
+    }
+    String maxcol = null;
+    if (mincol.toLowerCase().indexOf("label") == 0)
+    {
+      labelColour = true;
+      mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
+      // skip '|'
+      mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);
+    }
+
+    if (!labelColour && !gcol.hasMoreTokens())
+    {
+      /*
+       * only a simple colour specification - parse it
+       */
+      Color colour = UserColourScheme.getColourFromString(descriptor);
+      if (colour == null)
+      {
+        throw new IllegalArgumentException("Invalid colour descriptor: "
+                + descriptor);
+      }
+      return new FeatureColour(new Colour(colour));
+    }
+
+    /*
+     * autoScaled == true: colours range over actual score range; autoScaled ==
+     * false ('abso'): colours range over min/max range
+     */
+    boolean autoScaled = false;
+    String tok = null, minval, maxval;
+    if (mincol != null)
+    {
+      // at least four more tokens
+      if (mincol.equals("|"))
+      {
+        mincol = "";
+      }
+      else
+      {
+        gcol.nextToken(); // skip next '|'
+      }
+      maxcol = gcol.nextToken();
+      if (maxcol.equals("|"))
+      {
+        maxcol = "";
+      }
+      else
+      {
+        gcol.nextToken(); // skip next '|'
+      }
+      tok = gcol.nextToken();
+      gcol.nextToken(); // skip next '|'
+      if (tok.toLowerCase().indexOf("abso") != 0)
+      {
+        minval = tok;
+        autoScaled = true;
+      }
+      else
+      {
+        minval = gcol.nextToken();
+        gcol.nextToken(); // skip next '|'
+      }
+      maxval = gcol.nextToken();
+      if (gcol.hasMoreTokens())
+      {
+        gcol.nextToken(); // skip next '|'
+      }
+      try
+      {
+        if (minval.length() > 0)
+        {
+          min = new Float(minval).floatValue();
+        }
+      } catch (Exception e)
+      {
+        throw new IllegalArgumentException(
+                "Couldn't parse the minimum value for graduated colour ("
+                        + descriptor + ")");
+      }
+      try
+      {
+        if (maxval.length() > 0)
+        {
+          max = new Float(maxval).floatValue();
+        }
+      } catch (Exception e)
+      {
+        throw new IllegalArgumentException(
+                "Couldn't parse the maximum value for graduated colour ("
+                        + descriptor + ")");
+      }
+    }
+    else
+    {
+      // add in some dummy min/max colours for the label-only
+      // colourscheme.
+      mincol = "FFFFFF";
+      maxcol = "000000";
+    }
+
+    /*
+     * construct the FeatureColour
+     */
+    FeatureColour featureColour;
+    try
+    {
+      featureColour = new FeatureColour(new Colour(new UserColourScheme(
+              mincol).findColour('A')), new Colour(new UserColourScheme(
+              maxcol).findColour('A')), min, max);
+      featureColour.setColourByLabel(labelColour);
+      featureColour.setAutoScaled(autoScaled);
+      // add in any additional parameters
+      String ttype = null, tval = null;
+      if (gcol.hasMoreTokens())
+      {
+        // threshold type and possibly a threshold value
+        ttype = gcol.nextToken();
+        if (ttype.toLowerCase().startsWith("below"))
+        {
+          featureColour.setBelowThreshold(true);
+        }
+        else if (ttype.toLowerCase().startsWith("above"))
+        {
+          featureColour.setAboveThreshold(true);
+        }
+        else
+        {
+          if (!ttype.toLowerCase().startsWith("no"))
+          {
+            System.err.println("Ignoring unrecognised threshold type : "
+                    + ttype);
+          }
+        }
+      }
+      if (featureColour.hasThreshold())
+      {
+        try
+        {
+          gcol.nextToken();
+          tval = gcol.nextToken();
+          featureColour.setThreshold(new Float(tval).floatValue());
+        } catch (Exception e)
+        {
+          System.err.println("Couldn't parse threshold value as a float: ("
+                  + tval + ")");
+        }
+      }
+      if (gcol.hasMoreTokens())
+      {
+        System.err
+                .println("Ignoring additional tokens in parameters in graduated colour specification\n");
+        while (gcol.hasMoreTokens())
+        {
+          System.err.println("|" + gcol.nextToken());
+        }
+        System.err.println("\n");
+      }
+      return featureColour;
+    } catch (Exception e)
+    {
+      throw new IllegalArgumentException(e.getMessage());
+    }
+  }
+
+  /**
+   * Default constructor
+   */
+  public FeatureColour()
+  {
+    this((ColorI) null);
+  }
+
+  /**
+   * Constructor given a simple colour
+   * 
+   * @param c
+   */
+  public FeatureColour(ColorI c)
+  {
+    minColour = new Colour(Color.WHITE);
+    maxColour = new Colour(Color.BLACK);
+    minRed = 0f;
+    minGreen = 0f;
+    minBlue = 0f;
+    deltaRed = 0f;
+    deltaGreen = 0f;
+    deltaBlue = 0f;
+    colour = c;
+  }
+
+  public FeatureColour(Color c)
+  {
+    this(new Colour(c));
+  }
+
+  /**
+   * Constructor given a colour range and a score range
+   * 
+   * @param low
+   * @param high
+   * @param min
+   * @param max
+   */
+  public FeatureColour(ColorI low, ColorI high, float min, float max)
+  {
+    graduatedColour = true;
+    colour = null;
+    minColour = low;
+    maxColour = high;
+    threshold = Float.NaN;
+    isHighToLow = min >= max;
+    minRed = low.getRed() / 255f;
+    minGreen = low.getGreen() / 255f;
+    minBlue = low.getBlue() / 255f;
+    deltaRed = (high.getRed() / 255f) - minRed;
+    deltaGreen = (high.getGreen() / 255f) - minGreen;
+    deltaBlue = (high.getBlue() / 255f) - minBlue;
+    if (isHighToLow)
+    {
+      base = max;
+      range = min - max;
+    }
+    else
+    {
+      base = min;
+      range = max - min;
+    }
+  }
+
+  public FeatureColour(Color low, Color high, float min, float max)
+  {
+    this(new Colour(low), new Colour(high), min, max);
+  }
+  /**
+   * Copy constructor
+   * 
+   * @param fc
+   */
+  public FeatureColour(FeatureColour fc)
+  {
+    colour = fc.colour;
+    minColour = fc.minColour;
+    maxColour = fc.maxColour;
+    minRed = fc.minRed;
+    minGreen = fc.minGreen;
+    minBlue = fc.minBlue;
+    deltaRed = fc.deltaRed;
+    deltaGreen = fc.deltaGreen;
+    deltaBlue = fc.deltaBlue;
+    base = fc.base;
+    range = fc.range;
+    isHighToLow = fc.isHighToLow;
+    setAboveThreshold(fc.isAboveThreshold());
+    setBelowThreshold(fc.isBelowThreshold());
+    setThreshold(fc.getThreshold());
+    setAutoScaled(fc.isAutoScaled());
+    setColourByLabel(fc.isColourByLabel());
+  }
+  
+  /**
+   * Copy constructor with new min/max ranges
+   * @param fc
+   * @param min
+   * @param max
+   */
+  public FeatureColour(FeatureColour fc, float min, float max)
+  {
+    this(fc);
+    graduatedColour = true;
+    updateBounds(min, max);
+  }
+
+  @Override
+  public boolean isGraduatedColour()
+  {
+    return graduatedColour;
+  }
+
+  /**
+   * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to
+   * false.
+   */
+  @Override
+  public void setGraduatedColour(boolean b)
+  {
+    graduatedColour = b;
+    if (b)
+    {
+      setColourByLabel(false);
+    }
+  }
+
+  @Override
+  public ColorI getColour()
+  {
+    return colour;
+  }
+
+  @Override
+  public ColorI getMinColour()
+  {
+    return minColour;
+  }
+
+  @Override
+  public ColorI getMaxColour()
+  {
+    return maxColour;
+  }
+
+  @Override
+  public boolean isColourByLabel()
+  {
+    return colourByLabel;
+  }
+
+  /**
+   * Sets the 'colour by label' flag. If true, also sets 'graduated colour' to
+   * false.
+   */
+  @Override
+  public void setColourByLabel(boolean b)
+  {
+    colourByLabel = b;
+    if (b)
+    {
+      setGraduatedColour(false);
+    }
+  }
+  @Override
+  public boolean isBelowThreshold()
+  {
+    return belowThreshold;
+  }
+
+  @Override
+  public void setBelowThreshold(boolean b)
+  {
+    belowThreshold = b;
+    if (b)
+    {
+      setAboveThreshold(false);
+    }
+  }
+
+  @Override
+  public boolean isAboveThreshold()
+  {
+    return aboveThreshold;
+  }
+
+  @Override
+  public void setAboveThreshold(boolean b)
+  {
+    aboveThreshold = b;
+    if (b)
+    {
+      setBelowThreshold(false);
+    }
+  }
+
+  @Override
+  public boolean isThresholdMinMax()
+  {
+    return thresholdIsMinOrMax;
+  }
+
+  @Override
+  public void setThresholdMinMax(boolean b)
+  {
+    thresholdIsMinOrMax = b;
+  }
+
+  @Override
+  public float getThreshold()
+  {
+    return threshold;
+  }
+
+  @Override
+  public void setThreshold(float f)
+  {
+    threshold = f;
+  }
+
+  @Override
+  public boolean isAutoScaled()
+  {
+    return autoScaled;
+  }
+
+  @Override
+  public void setAutoScaled(boolean b)
+  {
+    this.autoScaled = b;
+  }
+
+  /**
+   * Updates the base and range appropriately for the given minmax range
+   * 
+   * @param min
+   * @param max
+   */
+  @Override
+  public void updateBounds(float min, float max)
+  {
+    if (max < min)
+    {
+      base = max;
+      range = min - max;
+      isHighToLow = true;
+    }
+    else
+    {
+      base = min;
+      range = max - min;
+      isHighToLow = false;
+    }
+  }
+
+  /**
+   * Returns the colour for the given instance of the feature. This may be a
+   * simple colour, a colour generated from the feature description (if
+   * isColourByLabel()), or a colour derived from the feature score (if
+   * isGraduatedColour()).
+   * 
+   * @param feature
+   * @return
+   */
+  @Override
+  public ColorI getColor(SequenceFeature feature)
+  {
+    if (isColourByLabel())
+    {
+      return new Colour(UserColourScheme.createColourFromName(feature
+              .getDescription()));
+    }
+
+    if (!isGraduatedColour())
+    {
+      return getColour();
+    }
+
+    // todo should we check for above/below threshold here?
+    if (range == 0.0)
+    {
+      return getMaxColour();
+    }
+    float scr = feature.getScore();
+    if (Float.isNaN(scr))
+    {
+      return getMinColour();
+    }
+    float scl = (scr - base) / range;
+    if (isHighToLow)
+    {
+      scl = -scl;
+    }
+    if (scl < 0f)
+    {
+      scl = 0f;
+    }
+    if (scl > 1f)
+    {
+      scl = 1f;
+    }
+    return new Colour(new Color(minRed + scl * deltaRed, minGreen + scl
+            * deltaGreen, minBlue + scl * deltaBlue));
+  }
+
+  /**
+   * Returns the maximum score of the graduated colour range
+   * 
+   * @return
+   */
+  @Override
+  public float getMax()
+  {
+    // regenerate the original values passed in to the constructor
+    return (isHighToLow) ? base : (base + range);
+  }
+
+  /**
+   * Returns the minimum score of the graduated colour range
+   * 
+   * @return
+   */
+  @Override
+  public float getMin()
+  {
+    // regenerate the original value passed in to the constructor
+    return (isHighToLow) ? (base + range) : base;
+  }
+
+  /**
+   * Answers true if the feature has a simple colour, or is coloured by label,
+   * or has a graduated colour and the score of this feature instance is within
+   * the range to render (if any), i.e. does not lie below or above any
+   * threshold set.
+   * 
+   * @param feature
+   * @return
+   */
+  @Override
+  public boolean isColored(SequenceFeature feature)
+  {
+    if (isColourByLabel() || !isGraduatedColour())
+    {
+      return true;
+    }
+
+    float val = feature.getScore();
+    if (Float.isNaN(val))
+    {
+      return true;
+    }
+    if (Float.isNaN(this.threshold))
+    {
+      return true;
+    }
+
+    if (isAboveThreshold() && val <= threshold)
+    {
+      return false;
+    }
+    if (isBelowThreshold() && val >= threshold)
+    {
+      return false;
+    }
+    return true;
+  }
+
+  @Override
+  public boolean isSimpleColour()
+  {
+    return (!isColourByLabel() && !isGraduatedColour());
+  }
+
+  @Override
+  public boolean hasThreshold()
+  {
+    return isAboveThreshold() || isBelowThreshold();
+  }
+
+  @Override
+  public String toJalviewFormat(String featureType)
+  {
+    String colourString = null;
+    if (isSimpleColour())
+    {
+      colourString = Format.getHexString(getColour());
+    }
+    else
+    {
+      StringBuilder sb = new StringBuilder(32);
+      if (isColourByLabel())
+      {
+        sb.append("label");
+        if (hasThreshold())
+        {
+          sb.append(BAR).append(BAR).append(BAR);
+        }
+      }
+      if (isGraduatedColour())
+      {
+        sb.append(Format.getHexString(getMinColour())).append(BAR);
+        sb.append(Format.getHexString(getMaxColour())).append(BAR);
+        if (isAutoScaled())
+        {
+          sb.append("abso").append(BAR);
+        }
+      }
+      if (hasThreshold() || isGraduatedColour())
+      {
+        sb.append(getMin()).append(BAR);
+        sb.append(getMax()).append(BAR);
+        if (isBelowThreshold())
+        {
+          sb.append("below").append(BAR).append(getThreshold());
+        }
+        else if (isAboveThreshold())
+        {
+          sb.append("above").append(BAR).append(getThreshold());
+        }
+        else
+        {
+          sb.append("none");
+        }
+      }
+      colourString = sb.toString();
+    }
+    return String.format("%s\t%s", featureType, colourString);
+  }
+
+}
index a86bee4..cc03dd3 100644 (file)
@@ -1,8 +1,8 @@
 package jalview.schemes;
 
+import jalview.api.ColorI;
 import jalview.api.FeatureColourI;
-
-import java.awt.Color;
+import jalview.datamodel.SequenceFeature;
 
 /**
  * A convenience class with implementations of FeatureColourI methods. Override
@@ -17,21 +17,21 @@ public class FeatureColourAdapter implements FeatureColourI
   }
 
   @Override
-  public Color getColour()
+  public ColorI getColour()
   {
-    return Color.BLACK;
+    return Colour.black;
   }
 
   @Override
-  public Color getMinColour()
+  public ColorI getMinColour()
   {
-    return Color.WHITE;
+    return Colour.white;
   }
 
   @Override
-  public Color getMaxColour()
+  public ColorI getMaxColour()
   {
-    return Color.BLACK;
+    return Colour.black;
   }
 
   @Override
@@ -65,9 +65,91 @@ public class FeatureColourAdapter implements FeatureColourI
   }
 
   @Override
-  public boolean isLowToHigh()
+  public float getMax()
+  {
+    return 0;
+  }
+
+  @Override
+  public float getMin()
+  {
+    return 0;
+  }
+
+  @Override
+  public boolean hasThreshold()
+  {
+    return false;
+  }
+
+  @Override
+  public ColorI getColor(SequenceFeature feature)
+  {
+    return null;
+  }
+
+  @Override
+  public boolean isColored(SequenceFeature feature)
+  {
+    return false;
+  }
+
+  @Override
+  public void updateBounds(float min, float max)
+  {
+  }
+
+  @Override
+  public String toJalviewFormat(String featureType)
+  {
+    return null;
+  }
+
+  @Override
+  public void setThreshold(float f)
+  {
+  }
+
+  @Override
+  public boolean isAutoScaled()
+  {
+    return false;
+  }
+
+  @Override
+  public void setAutoScaled(boolean b)
+  {
+  }
+
+  @Override
+  public boolean isSimpleColour()
+  {
+    return false;
+  }
+
+  @Override
+  public void setAboveThreshold(boolean b)
+  {
+  }
+
+  @Override
+  public void setThresholdMinMax(boolean b)
+  {
+  }
+
+  @Override
+  public void setBelowThreshold(boolean b)
+  {
+  }
+
+  @Override
+  public void setColourByLabel(boolean b)
+  {
+  }
+
+  @Override
+  public void setGraduatedColour(boolean b)
   {
-    return true;
   }
 
 }
index b1e4d58..2bc2d26 100755 (executable)
@@ -136,7 +136,7 @@ public class UserColourScheme extends ResidueColourScheme
 
   }
 
-  public Color createColourFromName(String name)
+  public static Color createColourFromName(String name)
   {
     int r, g, b;
 
index 31d1ded..4ba17d5 100644 (file)
 
 package jalview.util;
 
+import jalview.api.ColorI;
+
 import java.awt.Color;
 import java.util.Random;
 
 public class ColorUtils
 {
 
+  public static Color getColor(ColorI c)
+  {
+    return new Color(c.getRed(), c.getGreen(), c.getBlue());
+  }
   /**
    * Generates a random color, will mix with input color. Code taken from
    * http://stackoverflow
@@ -68,7 +74,7 @@ public class ColorUtils
    *      ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/colortool.html#
    *      tkcode
    */
-  public static final String toTkCode(Color colour)
+  public static final String toTkCode(ColorI colour)
   {
     String colstring = "#" + ((colour.getRed() < 16) ? "0" : "")
             + Integer.toHexString(colour.getRed())
index d14e4ad..44963f3 100755 (executable)
  */
 package jalview.util;
 
+import jalview.api.ColorI;
+
+import java.awt.Color;
+
 /**
  * DOCUMENT ME!
  * 
@@ -270,7 +274,37 @@ public class Format
    *              if bad format
    * 
    */
-  public static String getHexString(java.awt.Color color)
+  public static String getHexString(final Color c)
+  {
+    return getHexString(new ColorI()
+    {
+
+      @Override
+      public int getRed()
+      {
+        return c.getRed();
+      }
+
+      @Override
+      public int getGreen()
+      {
+        return c.getGreen();
+      }
+
+      @Override
+      public int getBlue()
+      {
+        return c.getBlue();
+      }
+
+      @Override
+      public int getRGB()
+      {
+        return c.getRGB();
+      }
+    });
+  }
+  public static String getHexString(ColorI color)
   {
     String r;
     String g;
index fbd1622..1a42611 100644 (file)
@@ -25,6 +25,7 @@ import jalview.analysis.Conservation;
 import jalview.api.AlignCalcManagerI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
+import jalview.api.ColorI;
 import jalview.api.FeaturesDisplayedI;
 import jalview.api.ViewStyleI;
 import jalview.commands.CommandI;
@@ -42,6 +43,7 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.Blosum62ColourScheme;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
 import jalview.schemes.ResidueProperties;
@@ -57,7 +59,6 @@ import jalview.workers.ComplementConsensusThread;
 import jalview.workers.ConsensusThread;
 import jalview.workers.StrucConsensusThread;
 
-import java.awt.Color;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.BitSet;
@@ -1237,7 +1238,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   protected boolean showConsensus = true;
 
-  private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
+  private Map<SequenceI, ColorI> sequenceColours = new HashMap<SequenceI, ColorI>();
 
   protected SequenceAnnotationOrder sortAnnotationsBy = null;
 
@@ -2059,14 +2060,14 @@ public abstract class AlignmentViewport implements AlignViewportI,
   }
 
   @Override
-  public Color getSequenceColour(SequenceI seq)
+  public ColorI getSequenceColour(SequenceI seq)
   {
-    Color sqc = sequenceColours.get(seq);
-    return (sqc == null ? Color.white : sqc);
+    ColorI sqc = sequenceColours.get(seq);
+    return (sqc == null ? Colour.white : sqc);
   }
 
   @Override
-  public void setSequenceColour(SequenceI seq, Color col)
+  public void setSequenceColour(SequenceI seq, ColorI col)
   {
     if (col == null)
     {
@@ -2223,7 +2224,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    * @see jalview.api.ViewStyleI#getTextColour()
    */
   @Override
-  public Color getTextColour()
+  public ColorI getTextColour()
   {
     return viewStyle.getTextColour();
   }
@@ -2233,7 +2234,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    * @see jalview.api.ViewStyleI#getTextColour2()
    */
   @Override
-  public Color getTextColour2()
+  public ColorI getTextColour2()
   {
     return viewStyle.getTextColour2();
   }
@@ -2304,7 +2305,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
    */
   @Override
-  public void setTextColour(Color textColour)
+  public void setTextColour(ColorI textColour)
   {
     viewStyle.setTextColour(textColour);
   }
@@ -2324,7 +2325,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
    */
   @Override
-  public void setTextColour2(Color textColour2)
+  public void setTextColour2(ColorI textColour2)
   {
     viewStyle.setTextColour2(textColour2);
   }
index 848f565..52cfb50 100644 (file)
@@ -27,7 +27,10 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.renderer.seqfeatures.FeatureRenderer;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
 import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.Color;
@@ -52,17 +55,14 @@ public abstract class FeatureRendererModel implements
    */
   protected float transparency = 1.0f;
 
-  protected Map<String, Object> featureColours = new ConcurrentHashMap<String, Object>();
+  protected Map<String, FeatureColourI> featureColours = new ConcurrentHashMap<String, FeatureColourI>();
 
   protected Map<String, Boolean> featureGroups = new ConcurrentHashMap<String, Boolean>();
 
-  protected Object currentColour;
-
-  /*
-   * feature types in ordering of rendering, where last means on top
-   */
   protected String[] renderOrder;
 
+  Map<String, Float> featureOrder = null;
+
   protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(
           this);
 
@@ -449,7 +449,6 @@ public abstract class FeatureRendererModel implements
     List<String> allfeatures = new ArrayList<String>(allFeatures);
     String[] oldRender = renderOrder;
     renderOrder = new String[allfeatures.size()];
-    Object mmrange, fc = null;
     boolean initOrders = (featureOrder == null);
     int opos = 0;
     if (oldRender != null && oldRender.length > 0)
@@ -469,16 +468,13 @@ public abstract class FeatureRendererModel implements
             allfeatures.remove(oldRender[j]);
             if (minmax != null)
             {
-              mmrange = minmax.get(oldRender[j]);
+              float[][] mmrange = minmax.get(oldRender[j]);
               if (mmrange != null)
               {
-                fc = featureColours.get(oldRender[j]);
-                if (fc != null && fc instanceof GraduatedColor
-                        && ((GraduatedColor) fc).isAutoScale())
+                FeatureColourI fc = featureColours.get(oldRender[j]);
+                if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled())
                 {
-                  ((GraduatedColor) fc).updateBounds(
-                          ((float[][]) mmrange)[0][0],
-                          ((float[][]) mmrange)[0][1]);
+                  fc.updateBounds(mmrange[0][0], mmrange[0][1]);
                 }
               }
             }
@@ -502,15 +498,13 @@ public abstract class FeatureRendererModel implements
       if (minmax != null)
       {
         // update from new features minmax if necessary
-        mmrange = minmax.get(newf[i]);
+        float[][] mmrange = minmax.get(newf[i]);
         if (mmrange != null)
         {
-          fc = featureColours.get(newf[i]);
-          if (fc != null && fc instanceof GraduatedColor
-                  && ((GraduatedColor) fc).isAutoScale())
+          FeatureColourI fc = featureColours.get(newf[i]);
+          if (fc != null && !fc.isSimpleColour() && fc.isAutoScaled())
           {
-            ((GraduatedColor) fc).updateBounds(((float[][]) mmrange)[0][0],
-                    ((float[][]) mmrange)[0][1]);
+            fc.updateBounds(mmrange[0][0], mmrange[0][1]);
           }
         }
       }
@@ -522,7 +516,7 @@ public abstract class FeatureRendererModel implements
         setOrder(newf[i], i / (float) denom);
       }
       // set order from newly found feature from persisted ordering.
-      sortOrder[i] = 2 - ((Float) featureOrder.get(newf[i])).floatValue();
+      sortOrder[i] = 2 - featureOrder.get(newf[i]).floatValue();
       if (i < iSize)
       {
         // only sort if we need to
@@ -540,52 +534,25 @@ public abstract class FeatureRendererModel implements
 
   /**
    * get a feature style object for the given type string. Creates a
-   * java.awt.Color for a featureType with no existing colourscheme. TODO:
-   * replace return type with object implementing standard abstract colour/style
-   * interface
+   * java.awt.Color for a featureType with no existing colourscheme.
    * 
    * @param featureType
-   * @return java.awt.Color or GraduatedColor
+   * @return
    */
   @Override
-  public Object getFeatureStyle(String featureType)
+  public FeatureColourI getFeatureStyle(String featureType)
   {
-    Object fc = featureColours.get(featureType);
+    FeatureColourI fc = featureColours.get(featureType);
     if (fc == null)
     {
-      jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme();
-      Color col = ucs.createColourFromName(featureType);
-      featureColours.put(featureType, fc = col);
+      Color col = UserColourScheme.createColourFromName(featureType);
+      fc = new FeatureColour(new Colour(col));
+      featureColours.put(featureType, fc);
     }
     return fc;
   }
 
   /**
-   * return a nominal colour for this feature
-   * 
-   * @param featureType
-   * @return standard color, or maximum colour for graduated colourscheme
-   */
-  public Color getColour(String featureType)
-  {
-    Object fc = getFeatureStyle(featureType);
-
-    if (fc instanceof Color)
-    {
-      return (Color) fc;
-    }
-    else
-    {
-      if (fc instanceof GraduatedColor)
-      {
-        return ((GraduatedColor) fc).getMaxColor();
-      }
-    }
-    throw new Error("Implementation Error: Unrecognised render object "
-            + fc.getClass() + " for features of type " + featureType);
-  }
-
-  /**
    * calculate the render colour for a specific feature using current feature
    * settings.
    * 
@@ -594,33 +561,14 @@ public abstract class FeatureRendererModel implements
    */
   public Color getColour(SequenceFeature feature)
   {
-    Object fc = getFeatureStyle(feature.getType());
-    if (fc instanceof Color)
-    {
-      return (Color) fc;
-    }
-    else
-    {
-      if (fc instanceof GraduatedColor)
-      {
-        return ((GraduatedColor) fc).findColor(feature);
-      }
-    }
-    throw new Error("Implementation Error: Unrecognised render object "
-            + fc.getClass() + " for features of type " + feature.getType());
+    FeatureColourI fc = getFeatureStyle(feature.getType());
+    return ColorUtils.getColor(fc.getColor(feature));
   }
 
   protected boolean showFeature(SequenceFeature sequenceFeature)
   {
-    Object fc = getFeatureStyle(sequenceFeature.type);
-    if (fc instanceof GraduatedColor)
-    {
-      return ((GraduatedColor) fc).isColored(sequenceFeature);
-    }
-    else
-    {
-      return true;
-    }
+    FeatureColourI fc = getFeatureStyle(sequenceFeature.type);
+    return fc.isColored(sequenceFeature);
   }
 
   protected boolean showFeatureOfType(String type)
@@ -629,26 +577,9 @@ public abstract class FeatureRendererModel implements
   }
 
   @Override
-  public void setColour(String featureType, Object col)
+  public void setColour(String featureType, FeatureColourI col)
   {
-    // overwrite
-    // Color _col = (col instanceof Color) ? ((Color) col) : (col instanceof
-    // GraduatedColor) ? ((GraduatedColor) col).getMaxColor() : null;
-    // Object c = featureColours.get(featureType);
-    // if (c == null || c instanceof Color || (c instanceof GraduatedColor &&
-    // !((GraduatedColor)c).getMaxColor().equals(_col)))
-    if (col instanceof FeatureColourI)
-    {
-      if (((FeatureColourI) col).isGraduatedColour())
-      {
-        col = new GraduatedColor((FeatureColourI) col);
-      }
-      else
-      {
-        col = ((FeatureColourI) col).getColour();
-      }
-    }
-      featureColours.put(featureType, col);
+     featureColours.put(featureType, col);
   }
 
   public void setTransparency(float value)
@@ -661,8 +592,6 @@ public abstract class FeatureRendererModel implements
     return transparency;
   }
 
-  Map featureOrder = null;
-
   /**
    * analogous to colour - store a normalized ordering for all feature types in
    * this rendering context.
@@ -677,7 +606,7 @@ public abstract class FeatureRendererModel implements
   {
     if (featureOrder == null)
     {
-      featureOrder = new Hashtable();
+      featureOrder = new Hashtable<String, Float>();
     }
     featureOrder.put(type, new Float(position));
     return position;
@@ -695,14 +624,14 @@ public abstract class FeatureRendererModel implements
     {
       if (featureOrder.containsKey(type))
       {
-        return ((Float) featureOrder.get(type)).floatValue();
+        return featureOrder.get(type).floatValue();
       }
     }
     return -1;
   }
 
   @Override
-  public Map<String, Object> getFeatureColours()
+  public Map<String, FeatureColourI> getFeatureColours()
   {
     return featureColours;
   }
@@ -768,8 +697,7 @@ public abstract class FeatureRendererModel implements
       for (int i = 0; i < data.length; i++)
       {
         String type = data[i][0].toString();
-        setColour(type, data[i][1]); // todo : typesafety - feature color
-        // interface object
+        setColour(type, (FeatureColourI) data[i][1]);
         if (((Boolean) data[i][2]).booleanValue())
         {
           av_featuresdisplayed.setVisible(type);
@@ -887,13 +815,13 @@ public abstract class FeatureRendererModel implements
    * @return list of groups
    */
   @Override
-  public List getGroups(boolean visible)
+  public List<String> getGroups(boolean visible)
   {
     if (featureGroups != null)
     {
-      ArrayList gp = new ArrayList();
+      List<String> gp = new ArrayList<String>();
 
-      for (Object grp : featureGroups.keySet())
+      for (String grp : featureGroups.keySet())
       {
         Boolean state = featureGroups.get(grp);
         if (state.booleanValue() == visible)
@@ -935,19 +863,19 @@ public abstract class FeatureRendererModel implements
   }
 
   @Override
-  public Hashtable getDisplayedFeatureCols()
+  public Map<String, FeatureColourI> getDisplayedFeatureCols()
   {
-    Hashtable fcols = new Hashtable();
+    Map<String, FeatureColourI> fcols = new Hashtable<String, FeatureColourI>();
     if (getViewport().getFeaturesDisplayed() == null)
     {
       return fcols;
     }
-    Iterator<String> en = getViewport().getFeaturesDisplayed()
+    Iterator<String> features = getViewport().getFeaturesDisplayed()
             .getVisibleFeatures();
-    while (en.hasNext())
+    while (features.hasNext())
     {
-      String col = en.next();
-      fcols.put(col, getColour(col));
+      String feature = features.next();
+      fcols.put(feature, getFeatureStyle(feature));
     }
     return fcols;
   }
@@ -958,10 +886,6 @@ public abstract class FeatureRendererModel implements
     return av.getFeaturesDisplayed();
   }
 
-  /**
-   * Returns a (possibly empty) list of visible feature types, in render order
-   * (last is on top)
-   */
   @Override
   public List<String> getDisplayedFeatureTypes()
   {
index 1985b6d..908b5b4 100644 (file)
  */
 package jalview.viewmodel.seqfeatures;
 
-import jalview.schemes.GraduatedColor;
+import jalview.api.FeatureColourI;
+import jalview.schemes.FeatureColour;
 
 import java.util.Arrays;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -32,24 +32,27 @@ public class FeatureRendererSettings implements Cloneable
 {
   String[] renderOrder;
 
-  Map featureGroups;
+  Map<String, Boolean> featureGroups;
 
-  Map featureColours;
+  Map<String, FeatureColourI> featureColours;
 
   float transparency;
 
-  Map featureOrder;
+  Map<String, Float> featureOrder;
 
   public FeatureRendererSettings(String[] renderOrder,
-          Hashtable featureGroups, Hashtable featureColours,
-          float transparency, Hashtable featureOrder)
+          Map<String, Boolean> featureGroups,
+          Map<String, FeatureColourI> featureColours, float transparency,
+          Map<String, Float> featureOrder)
   {
     super();
     this.renderOrder = Arrays.copyOf(renderOrder, renderOrder.length);
-    this.featureGroups = new ConcurrentHashMap(featureGroups);
-    this.featureColours = new ConcurrentHashMap(featureColours);
+    this.featureGroups = new ConcurrentHashMap<String, Boolean>(
+            featureGroups);
+    this.featureColours = new ConcurrentHashMap<String, FeatureColourI>(
+            featureColours);
     this.transparency = transparency;
-    this.featureOrder = new ConcurrentHashMap(featureOrder);
+    this.featureOrder = new ConcurrentHashMap<String, Float>(featureOrder);
   }
 
   /**
@@ -61,9 +64,9 @@ public class FeatureRendererSettings implements Cloneable
           jalview.viewmodel.seqfeatures.FeatureRendererModel fr)
   {
     renderOrder = null;
-    featureGroups = new ConcurrentHashMap();
-    featureColours = new ConcurrentHashMap();
-    featureOrder = new ConcurrentHashMap();
+    featureGroups = new ConcurrentHashMap<String, Boolean>();
+    featureColours = new ConcurrentHashMap<String, FeatureColourI>();
+    featureOrder = new ConcurrentHashMap<String, Float>();
     if (fr.renderOrder != null)
     {
       this.renderOrder = new String[fr.renderOrder.length];
@@ -72,26 +75,29 @@ public class FeatureRendererSettings implements Cloneable
     }
     if (fr.featureGroups != null)
     {
-      this.featureGroups = new ConcurrentHashMap(fr.featureGroups);
+      this.featureGroups = new ConcurrentHashMap<String, Boolean>(
+              fr.featureGroups);
     }
     if (fr.featureColours != null)
     {
-      this.featureColours = new ConcurrentHashMap(fr.featureColours);
+      this.featureColours = new ConcurrentHashMap<String, FeatureColourI>(
+              fr.featureColours);
     }
-    Iterator en = fr.featureColours.keySet().iterator();
+    Iterator<String> en = fr.featureColours.keySet().iterator();
     while (en.hasNext())
     {
-      Object next = en.next();
-      Object val = featureColours.get(next);
-      if (val instanceof GraduatedColor)
+      String next = en.next();
+      FeatureColourI val = featureColours.get(next);
+      if (!val.isSimpleColour())
       {
-        featureColours.put(next, new GraduatedColor((GraduatedColor) val));
+        featureColours.put(next, new FeatureColour((FeatureColour) val));
       }
     }
     this.transparency = fr.transparency;
     if (fr.featureOrder != null)
     {
-      this.featureOrder = new ConcurrentHashMap(fr.featureOrder);
+      this.featureOrder = new ConcurrentHashMap<String, Float>(
+              fr.featureOrder);
     }
   }
 }
index 14a1bde..0e66de1 100644 (file)
@@ -20,9 +20,9 @@
  */
 package jalview.viewmodel.styles;
 
+import jalview.api.ColorI;
 import jalview.api.ViewStyleI;
-
-import java.awt.Color;
+import jalview.schemes.Colour;
 
 /**
  * A container for holding alignment view properties. View properties are
@@ -133,9 +133,9 @@ public class ViewStyle implements ViewStyleI
    */
   protected boolean showUnconserved = false;
 
-  Color textColour = Color.black;
+  ColorI textColour = Colour.black;
 
-  Color textColour2 = Color.white;
+  ColorI textColour2 = Colour.white;
 
   /**
    * PID or consensus threshold
@@ -519,7 +519,7 @@ public class ViewStyle implements ViewStyleI
    * @return the textColour
    */
   @Override
-  public Color getTextColour()
+  public ColorI getTextColour()
   {
     return textColour;
   }
@@ -528,7 +528,7 @@ public class ViewStyle implements ViewStyleI
    * @return the textColour2
    */
   @Override
-  public Color getTextColour2()
+  public ColorI getTextColour2()
   {
     return textColour2;
   }
@@ -906,7 +906,7 @@ public class ViewStyle implements ViewStyleI
    *          the textColour to set
    */
   @Override
-  public void setTextColour(Color textColour)
+  public void setTextColour(ColorI textColour)
   {
     this.textColour = textColour;
   }
@@ -916,7 +916,7 @@ public class ViewStyle implements ViewStyleI
    *          the textColour2 to set
    */
   @Override
-  public void setTextColour2(Color textColour2)
+  public void setTextColour2(ColorI textColour2)
   {
     this.textColour2 = textColour2;
   }
index b2e9b35..66fddd1 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.ws.jws1;
 
 import jalview.analysis.AlignSeq;
+import jalview.api.FeatureColourI;
 import jalview.bin.Cache;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentView;
@@ -172,7 +173,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
      * @return null or { Alignment(+features and annotation), NewickFile)}
      */
     public Object[] getAlignment(Alignment dataset,
-            Map<String, Object> featureColours)
+            Map<String, FeatureColourI> featureColours)
     {
 
       if (result != null && result.isFinished())
@@ -622,7 +623,7 @@ class SeqSearchWSThread extends JWS1Thread implements WSClientI
     // NewickFile nf[] = new NewickFile[jobs.length];
     for (int j = 0; j < jobs.length; j++)
     {
-      Map<String, Object> featureColours = new HashMap<String, Object>();
+      Map<String, FeatureColourI> featureColours = new HashMap<String, FeatureColourI>();
       Alignment al = null;
       NewickFile nf = null;
       if (jobs[j].hasResults())
index f4b1c31..ea6310a 100644 (file)
  */
 package jalview.ws.jws2;
 
+import jalview.api.FeatureColourI;
 import jalview.bin.Cache;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.GraphLine;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
+import jalview.schemes.FeatureColour;
 import jalview.schemes.UserColourScheme;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.params.WsParamSetI;
@@ -306,8 +308,8 @@ public class AADisorderClient extends JabawsCalcWorker
                 annot.description += "<br/>" + threshNote;
               }
               annot.description += "</html>";
-              Color col = new UserColourScheme(typeName)
-                      .createColourFromName(typeName + scr.getMethod());
+              Color col = UserColourScheme.createColourFromName(typeName
+                      + scr.getMethod());
               for (int p = 0, ps = annot.annotations.length; p < ps; p++)
               {
                 if (annot.annotations[p] != null)
@@ -335,13 +337,14 @@ public class AADisorderClient extends JabawsCalcWorker
                   .cloneFeatureRenderer();
           for (String ft : fc.keySet())
           {
-            Object gc = fr.getFeatureStyle(ft);
-            if (gc instanceof Color)
+            FeatureColourI gc = fr.getFeatureStyle(ft);
+            if (gc.isSimpleColour())
             {
               // set graduated color as fading to white for minimum, and
               // autoscaling to values on alignment
-              GraduatedColor ggc = new GraduatedColor(Color.white,
-                      (Color) gc, Float.MIN_VALUE, Float.MAX_VALUE);
+              FeatureColourI ggc = new FeatureColour(
+                      new Colour(Color.white),
+                      gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE);
               ggc.setAutoScaled(true);
               fr.setColour(ft, ggc);
             }
index ff745ac..6ee688f 100644 (file)
@@ -26,10 +26,12 @@ import static org.testng.AssertJUnit.assertSame;
 import static org.testng.AssertJUnit.assertTrue;
 
 import jalview.analysis.AlignSeq;
+import jalview.api.ColorI;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.TaylorColourScheme;
 import jalview.structure.StructureViewSettings;
@@ -138,10 +140,10 @@ public class PDBChainTest
     c.makeBond(a2, a3);
     c.setChainColours(Color.PINK);
     assertEquals(2, c.bonds.size());
-    assertEquals(Color.PINK, c.bonds.get(0).startCol);
-    assertEquals(Color.PINK, c.bonds.get(0).endCol);
-    assertEquals(Color.PINK, c.bonds.get(1).startCol);
-    assertEquals(Color.PINK, c.bonds.get(1).endCol);
+    assertEquals(Colour.pink, c.bonds.get(0).startCol);
+    assertEquals(Colour.pink, c.bonds.get(0).endCol);
+    assertEquals(Colour.pink, c.bonds.get(1).startCol);
+    assertEquals(Colour.pink, c.bonds.get(1).endCol);
   }
 
   /**
@@ -151,8 +153,8 @@ public class PDBChainTest
   @Test(groups = { "Functional" })
   public void testSetChainColours_colourScheme()
   {
-    Color alaColour = new Color(204, 255, 0);
-    Color glyColour = new Color(255, 153, 0);
+    ColorI alaColour = new Colour(204, 255, 0);
+    ColorI glyColour = new Colour(255, 153, 0);
     a1.resName = "ALA";
     a2.resName = "GLY";
     a3.resName = "XXX"; // no colour defined
@@ -172,20 +174,20 @@ public class PDBChainTest
     // bond a2 to a3 - no colour found for a3
     // exception handling defaults to gray
     b = c.bonds.get(2);
-    assertEquals(Color.gray, b.startCol);
-    assertEquals(Color.gray, b.endCol);
+    assertEquals(Colour.gray, b.startCol);
+    assertEquals(Colour.gray, b.endCol);
   }
 
   @Test(groups = { "Functional" })
   public void testGetChargeColour()
   {
-    assertEquals(Color.red, PDBChain.getChargeColour("ASP"));
-    assertEquals(Color.red, PDBChain.getChargeColour("GLU"));
-    assertEquals(Color.blue, PDBChain.getChargeColour("LYS"));
-    assertEquals(Color.blue, PDBChain.getChargeColour("ARG"));
-    assertEquals(Color.yellow, PDBChain.getChargeColour("CYS"));
-    assertEquals(Color.lightGray, PDBChain.getChargeColour("ALA"));
-    assertEquals(Color.lightGray, PDBChain.getChargeColour(null));
+    assertEquals(Colour.red, PDBChain.getChargeColour("ASP"));
+    assertEquals(Colour.red, PDBChain.getChargeColour("GLU"));
+    assertEquals(Colour.blue, PDBChain.getChargeColour("LYS"));
+    assertEquals(Colour.blue, PDBChain.getChargeColour("ARG"));
+    assertEquals(Colour.yellow, PDBChain.getChargeColour("CYS"));
+    assertEquals(Colour.lightGray, PDBChain.getChargeColour("ALA"));
+    assertEquals(Colour.lightGray, PDBChain.getChargeColour(null));
   }
 
   /**
@@ -205,16 +207,16 @@ public class PDBChainTest
     assertEquals(3, c.bonds.size());
     // bond a1 to a2
     Bond b = c.bonds.get(0);
-    assertEquals(Color.red, b.startCol);
-    assertEquals(Color.blue, b.endCol);
+    assertEquals(Colour.red, b.startCol);
+    assertEquals(Colour.blue, b.endCol);
     // bond a2 to a3
     b = c.bonds.get(1);
-    assertEquals(Color.blue, b.startCol);
-    assertEquals(Color.yellow, b.endCol);
+    assertEquals(Colour.blue, b.startCol);
+    assertEquals(Colour.yellow, b.endCol);
     // bond a3 to a4
     b = c.bonds.get(2);
-    assertEquals(Color.yellow, b.startCol);
-    assertEquals(Color.lightGray, b.endCol);
+    assertEquals(Colour.yellow, b.startCol);
+    assertEquals(Colour.lightGray, b.endCol);
   }
 
   /**
index 29c7d16..6e11a88 100644 (file)
@@ -23,7 +23,9 @@ package jalview.ext.rbvi.chimera;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertTrue;
 
-import java.awt.Color;
+import jalview.api.ColorI;
+import jalview.schemes.Colour;
+
 import java.util.Arrays;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -36,47 +38,47 @@ public class ChimeraCommandsTest
   @Test(groups = { "Functional" })
   public void testAddColourRange()
   {
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
-    ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A");
-    ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A");
-    ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B");
-    ChimeraCommands.addColourRange(map, Color.red, 1, 3, 5, "A");
-    ChimeraCommands.addColourRange(map, Color.red, 0, 1, 4, "B");
-    ChimeraCommands.addColourRange(map, Color.orange, 0, 5, 9, "C");
+    Map<ColorI, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<ColorI, Map<Integer, Map<String, List<int[]>>>>();
+    ChimeraCommands.addColourRange(map, Colour.pink, 1, 2, 4, "A");
+    ChimeraCommands.addColourRange(map, Colour.pink, 1, 8, 8, "A");
+    ChimeraCommands.addColourRange(map, Colour.pink, 1, 5, 7, "B");
+    ChimeraCommands.addColourRange(map, Colour.red, 1, 3, 5, "A");
+    ChimeraCommands.addColourRange(map, Colour.red, 0, 1, 4, "B");
+    ChimeraCommands.addColourRange(map, Colour.orange, 0, 5, 9, "C");
 
     // three colours mapped
     assertEquals(3, map.keySet().size());
 
     // Red has two models, Pink and Orange one each
-    assertEquals(2, map.get(Color.red).keySet().size());
-    assertEquals(1, map.get(Color.orange).keySet().size());
-    assertEquals(1, map.get(Color.pink).keySet().size());
+    assertEquals(2, map.get(Colour.red).keySet().size());
+    assertEquals(1, map.get(Colour.orange).keySet().size());
+    assertEquals(1, map.get(Colour.pink).keySet().size());
 
     // pink model 1 has two chains, red.0 / red.1 / orange.0 one each
-    assertEquals(2, map.get(Color.pink).get(1).keySet().size());
-    assertEquals(1, map.get(Color.red).get(0).keySet().size());
-    assertEquals(1, map.get(Color.red).get(1).keySet().size());
-    assertEquals(1, map.get(Color.orange).get(0).keySet().size());
+    assertEquals(2, map.get(Colour.pink).get(1).keySet().size());
+    assertEquals(1, map.get(Colour.red).get(0).keySet().size());
+    assertEquals(1, map.get(Colour.red).get(1).keySet().size());
+    assertEquals(1, map.get(Colour.orange).get(0).keySet().size());
 
     // inspect positions
-    List<int[]> posList = map.get(Color.pink).get(1).get("A");
+    List<int[]> posList = map.get(Colour.pink).get(1).get("A");
     assertEquals(2, posList.size());
     assertTrue(Arrays.equals(new int[] { 2, 4 }, posList.get(0)));
     assertTrue(Arrays.equals(new int[] { 8, 8 }, posList.get(1)));
 
-    posList = map.get(Color.pink).get(1).get("B");
+    posList = map.get(Colour.pink).get(1).get("B");
     assertEquals(1, posList.size());
     assertTrue(Arrays.equals(new int[] { 5, 7 }, posList.get(0)));
 
-    posList = map.get(Color.red).get(0).get("B");
+    posList = map.get(Colour.red).get(0).get("B");
     assertEquals(1, posList.size());
     assertTrue(Arrays.equals(new int[] { 1, 4 }, posList.get(0)));
 
-    posList = map.get(Color.red).get(1).get("A");
+    posList = map.get(Colour.red).get(1).get("A");
     assertEquals(1, posList.size());
     assertTrue(Arrays.equals(new int[] { 3, 5 }, posList.get(0)));
 
-    posList = map.get(Color.orange).get(0).get("C");
+    posList = map.get(Colour.orange).get(0).get("C");
     assertEquals(1, posList.size());
     assertTrue(Arrays.equals(new int[] { 5, 9 }, posList.get(0)));
   }
@@ -85,15 +87,15 @@ public class ChimeraCommandsTest
   public void testBuildColourCommands()
   {
 
-    Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
-    ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
-    ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
-    ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
-    ChimeraCommands.addColourRange(map, Color.blue, 1, 1, 1, "A");
-    ChimeraCommands.addColourRange(map, Color.blue, 1, 4, 7, "B");
-    ChimeraCommands.addColourRange(map, Color.yellow, 1, 8, 8, "A");
-    ChimeraCommands.addColourRange(map, Color.yellow, 1, 3, 5, "A");
-    ChimeraCommands.addColourRange(map, Color.red, 0, 3, 5, "A");
+    Map<ColorI, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<ColorI, Map<Integer, Map<String, List<int[]>>>>();
+    ChimeraCommands.addColourRange(map, Colour.blue, 0, 2, 5, "A");
+    ChimeraCommands.addColourRange(map, Colour.blue, 0, 7, 7, "B");
+    ChimeraCommands.addColourRange(map, Colour.blue, 0, 9, 23, "A");
+    ChimeraCommands.addColourRange(map, Colour.blue, 1, 1, 1, "A");
+    ChimeraCommands.addColourRange(map, Colour.blue, 1, 4, 7, "B");
+    ChimeraCommands.addColourRange(map, Colour.yellow, 1, 8, 8, "A");
+    ChimeraCommands.addColourRange(map, Colour.yellow, 1, 3, 5, "A");
+    ChimeraCommands.addColourRange(map, Colour.red, 0, 3, 5, "A");
 
     // Colours should appear in the Chimera command in the order in which
     // they were added; within colour, by model, by chain, and positions as
index aa3b756..7a9e744 100644 (file)
@@ -26,10 +26,9 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.Colour;
 import jalview.schemes.ZappoColourScheme;
 
-import java.awt.Color;
-
 import org.testng.annotations.Test;
 
 public class SequenceRendererTest
@@ -45,10 +44,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(Colour.pink, sr.getResidueColour(seq, 0, null)); // M
+    assertEquals(Colour.green, sr.getResidueColour(seq, 2, null)); // T
+    assertEquals(Colour.magenta, sr.getResidueColour(seq, 5, null)); // G
+    assertEquals(Colour.orange, sr.getResidueColour(seq, 12, null)); // F
   }
   // TODO more tests for getResidueBoxColour covering groups, feature rendering,
   // gaps, overview...
index 385e049..6bd06cd 100644 (file)
@@ -26,16 +26,15 @@ import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.GraduatedColor;
+import jalview.schemes.Colour;
 
-import java.awt.Color;
 import java.io.File;
 import java.io.IOException;
 import java.util.Map;
@@ -53,7 +52,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     FeaturesFile featuresFile = new FeaturesFile(
             "examples/exampleFeatures.txt", FormatAdapter.FILE);
@@ -67,8 +66,8 @@ public class FeaturesFileTest
      */
     colours = af.getFeatureRenderer().getFeatureColours();
     assertEquals("26 feature group colours not found", 26, colours.size());
-    assertEquals(colours.get("Cath"), new Color(0x93b1d1));
-    assertEquals(colours.get("ASX-MOTIF"), new Color(0x6addbb));
+    assertEquals(colours.get("Cath").getColour(), new Colour(0x93b1d1));
+    assertEquals(colours.get("ASX-MOTIF").getColour(), new Colour(0x6addbb));
 
     /*
      * verify (some) features on sequences
@@ -140,7 +139,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     // GFF2 uses space as name/value separator in column 9
     String gffData = "METAL\tcc9900\n" + "GFF\n"
@@ -154,7 +153,7 @@ public class FeaturesFileTest
     // verify colours read or synthesized
     colours = af.getFeatureRenderer().getFeatureColours();
     assertEquals("1 feature group colours not found", 1, colours.size());
-    assertEquals(colours.get("METAL"), new Color(0xcc9900));
+    assertEquals(colours.get("METAL").getColour(), new Colour(0xcc9900));
 
     // verify feature on FER_CAPAA
     SequenceFeature[] sfs = al.getSequenceAt(0).getDatasetSequence()
@@ -205,32 +204,31 @@ public class FeaturesFileTest
     FeaturesFile ff = new FeaturesFile();
 
     // colour by label:
-    GraduatedColor gc = ff.parseGraduatedColourScheme(
+    FeatureColourI gc = ff.parseGraduatedColourScheme(
             "BETA-TURN-IR\t9a6a94", "label");
     assertTrue(gc.isColourByLabel());
-    assertEquals(Color.white, gc.getMinColor());
-    assertEquals(Color.black, gc.getMaxColor());
-    assertTrue(gc.isAutoScale());
+    assertEquals(Colour.white, gc.getMinColour());
+    assertEquals(Colour.black, gc.getMaxColour());
+    assertTrue(gc.isAutoScaled());
 
     // using colour name, rgb, etc:
     String spec = "blue|255,0,255|absolute|20.0|95.0|below|66.0";
     gc = ff.parseGraduatedColourScheme("BETA-TURN-IR\t" + spec, spec);
     assertFalse(gc.isColourByLabel());
-    assertEquals(Color.blue, gc.getMinColor());
-    assertEquals(new Color(255, 0, 255), gc.getMaxColor());
-    assertFalse(gc.isAutoScale());
-    assertFalse(gc.getTolow());
+    assertEquals(Colour.blue, gc.getMinColour());
+    assertEquals(new Colour(255, 0, 255), gc.getMaxColour());
+    assertFalse(gc.isAutoScaled());
+    // assertFalse(gc.getTolow());
     assertEquals(20.0f, gc.getMin(), 0.001f);
     assertEquals(95.0f, gc.getMax(), 0.001f);
-    assertEquals(AnnotationColourGradient.BELOW_THRESHOLD,
-            gc.getThreshType());
-    assertEquals(66.0f, gc.getThresh(), 0.001f);
+    assertTrue(gc.isBelowThreshold());
+    assertEquals(66.0f, gc.getThreshold(), 0.001f);
 
     // inverse gradient high to low:
     spec = "blue|255,0,255|95.0|20.0|below|66.0";
     gc = ff.parseGraduatedColourScheme("BETA-TURN-IR\t" + spec, spec);
-    assertTrue(gc.isAutoScale());
-    assertTrue(gc.getTolow());
+    assertTrue(gc.isAutoScaled());
+    // assertTrue(gc..getTolow());
   }
 
   /**
@@ -244,7 +242,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
     // GFF3 uses '=' separator for name/value pairs in colum 9
     String gffData = "##gff-version 3\n"
@@ -296,7 +294,7 @@ public class FeaturesFileTest
     File f = new File("examples/uniref50.fa");
     AlignmentI al = readAlignmentFile(f);
     AlignFrame af = new AlignFrame(al, 500, 500);
-    Map<String, Object> colours = af.getFeatureRenderer()
+    Map<String, FeatureColourI> colours = af.getFeatureRenderer()
             .getFeatureColours();
 
     /*
diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java
new file mode 100644 (file)
index 0000000..ccae3e8
--- /dev/null
@@ -0,0 +1,314 @@
+package jalview.schemes;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.fail;
+
+import jalview.api.ColorI;
+import jalview.datamodel.SequenceFeature;
+import jalview.util.Format;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class FeatureColourTest
+{
+  @Test(groups = { "Functional" })
+  public void testIsColored_simpleColour()
+  {
+    FeatureColour fc = new FeatureColour(Color.RED);
+    assertTrue(fc.isColored(new SequenceFeature()));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testIsColored_colourByLabel()
+  {
+    FeatureColour fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    assertTrue(fc.isColored(new SequenceFeature()));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testIsColored_aboveThreshold()
+  {
+    // graduated colour range from score 20 to 100
+    FeatureColour fc = new FeatureColour(new Colour(Color.WHITE),
+            new Colour(Color.BLACK), 20f, 100f);
+
+    // score 0 is adjusted to bottom of range
+    SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 0f,
+            null);
+    assertTrue(fc.isColored(sf));
+    assertEquals(fc.getColor(sf), Colour.white);
+
+    // score 120 is adjusted to top of range
+    sf.setScore(120f);
+    assertEquals(fc.getColor(sf), Colour.black);
+
+    // value below threshold is still rendered
+    // setting threshold has no effect yet...
+    fc.setThreshold(60f);
+    sf.setScore(36f);
+    assertTrue(fc.isColored(sf));
+    assertEquals(fc.getColor(sf), new Colour(204, 204, 204));
+
+    // now apply threshold:
+    fc.setAboveThreshold(true);
+    assertFalse(fc.isColored(sf));
+    // colour is still returned though ?!?
+    assertEquals(fc.getColor(sf), new Colour(204, 204, 204));
+
+    sf.setScore(84); // above threshold now
+    assertTrue(fc.isColored(sf));
+    assertEquals(fc.getColor(sf), new Colour(51, 51, 51));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetColor_simpleColour()
+  {
+    FeatureColour fc = new FeatureColour(Colour.red);
+    assertEquals(fc.getColor(new SequenceFeature()), Colour.red);
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetColor_colourByLabel()
+  {
+    FeatureColour fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
+            null);
+    ColorI expected = new Colour(
+            UserColourScheme.createColourFromName("desc"));
+    assertEquals(fc.getColor(sf), expected);
+    // 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)
+    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,
+            null);
+    // the colour gradient is computed in float values from 0-1 (where 1 == 255)
+    float red = 128 / 255f + 3 / 4f * (255 - 128) / 255f;
+    float green = 128 / 255f + 3 / 4f * (0 - 128) / 255f;
+    float blue = 128 / 255f + 3 / 4f * (0 - 128) / 255f;
+    Colour expected = new Colour(red, green, blue);
+    assertEquals(fc.getColor(sf), expected);
+    // assertEquals(expected, fc.getColor(sf));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testGetColor_belowThreshold()
+  {
+    // gradient from [50, 150] from WHITE(255, 255, 255) to BLACK(0, 0, 0)
+    FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f,
+            150f);
+    SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f,
+            null);
+    fc.setThreshold(100f); // ignore for now
+    assertTrue(fc.isColored(sf));
+    assertEquals(fc.getColor(sf), new Colour(204, 204, 204));
+    // assertEquals(new Color(204, 204, 204), fc.getColor(sf));
+
+    fc.setAboveThreshold(true); // feature lies below threshold
+    assertFalse(fc.isColored(sf));
+    assertEquals(fc.getColor(sf), new Colour(204, 204, 204));
+    // assertEquals(new Color(204, 204, 204), fc.getColor(sf));
+  }
+
+  /**
+   * Test output of feature colours to Jalview features file format
+   */
+  @Test(groups = { "Functional" })
+  public void testToJalviewFormat()
+  {
+    /*
+     * plain colour - to RGB hex code
+     */
+    FeatureColour fc = new FeatureColour(Color.RED);
+    String redHex = Format.getHexString(Color.RED);
+    String hexColour = redHex;
+    assertEquals("domain\t" + hexColour, fc.toJalviewFormat("domain"));
+    
+    /*
+     * colour by label (no threshold)
+     */
+    fc = new FeatureColour();
+    fc.setColourByLabel(true);
+    assertEquals("domain\tlabel", fc.toJalviewFormat("domain"));
+
+    /*
+     * colour by label (autoscaled) (an odd state you can reach by selecting
+     * 'above threshold', then deselecting 'threshold is min/max' then 'colour
+     * by label')
+     */
+    fc.setAutoScaled(true);
+    assertEquals("domain\tlabel", fc.toJalviewFormat("domain"));
+
+    /*
+     * colour by label (above threshold) (min/max values are output though not
+     * used by this scheme)
+     */
+    fc.setAutoScaled(false);
+    fc.setThreshold(12.5f);
+    fc.setAboveThreshold(true);
+    assertEquals("domain\tlabel|||0.0|0.0|above|12.5",
+            fc.toJalviewFormat("domain"));
+
+    /*
+     * colour by label (below threshold)
+     */
+    fc.setBelowThreshold(true);
+    assertEquals("domain\tlabel|||0.0|0.0|below|12.5",
+            fc.toJalviewFormat("domain"));
+
+    /*
+     * graduated colour, 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",
+            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,
+            redHex);
+    assertEquals(expected, fc.toJalviewFormat("domain"));
+
+    /*
+     * graduated colour below threshold
+     */
+    fc.setThreshold(12.5f);
+    fc.setBelowThreshold(true);
+    expected = String.format("domain\t%s|%s|abso|12.0|25.0|below|12.5",
+            greenHex, redHex);
+    assertEquals(expected, fc.toJalviewFormat("domain"));
+
+    /*
+     * graduated colour above threshold
+     */
+    fc.setThreshold(12.5f);
+    fc.setAboveThreshold(true);
+    expected = String.format("domain\t%s|%s|abso|12.0|25.0|above|12.5",
+            greenHex, redHex);
+    assertEquals(expected, fc.toJalviewFormat("domain"));
+  }
+
+  /**
+   * Test parsing of feature colours from Jalview features file format
+   */
+  @Test(groups = { "Functional" })
+  public void testParseJalviewFeatureColour()
+  {
+    /*
+     * simple colour by name
+     */
+    FeatureColour fc = FeatureColour.parseJalviewFeatureColour("red");
+    assertTrue(fc.isSimpleColour());
+    assertEquals(fc.getColour(), Colour.red);
+
+    /*
+     * simple colour by hex code
+     */
+    fc = FeatureColour.parseJalviewFeatureColour(Format
+            .getHexString(Color.RED));
+    assertTrue(fc.isSimpleColour());
+    assertEquals(fc.getColour(), Colour.red);
+    // assertEquals(Color.RED, fc.getColour());
+
+    /*
+     * simple colour by rgb triplet
+     */
+    fc = FeatureColour.parseJalviewFeatureColour("255,0,0");
+    assertTrue(fc.isSimpleColour());
+    assertEquals(fc.getColour(), Colour.red);
+    // assertEquals(Color.RED, fc.getColour());
+
+    /*
+     * malformed colour
+     */
+    try
+    {
+      fc = FeatureColour.parseJalviewFeatureColour("oops");
+      fail("expected exception");
+    } catch (IllegalArgumentException e)
+    {
+      assertEquals("Invalid colour descriptor: oops", e.getMessage());
+    }
+
+    /*
+     * colour by label (no threshold)
+     */
+    fc = FeatureColour.parseJalviewFeatureColour("label");
+    assertTrue(fc.isColourByLabel());
+    assertFalse(fc.hasThreshold());
+
+    /*
+     * colour by label (with threshold)
+     */
+    fc = FeatureColour
+            .parseJalviewFeatureColour("label|||0.0|0.0|above|12.0");
+    assertTrue(fc.isColourByLabel());
+    assertTrue(fc.isAboveThreshold());
+    assertEquals(12.0f, fc.getThreshold());
+
+    /*
+     * graduated colour (by name) (no threshold)
+     */
+    fc = FeatureColour.parseJalviewFeatureColour("red|green|10.0|20.0");
+    assertTrue(fc.isGraduatedColour());
+    assertFalse(fc.hasThreshold());
+    assertEquals(fc.getMinColour(), Colour.red);
+    // assertEquals(Color.RED, fc.getMinColour());
+    assertEquals(fc.getMaxColour(), Colour.green);
+    // assertEquals(Color.GREEN, fc.getMaxColour());
+    assertEquals(10f, fc.getMin());
+    assertEquals(20f, fc.getMax());
+    assertTrue(fc.isAutoScaled());
+
+    /*
+     * graduated colour (by hex code) (above threshold)
+     */
+    String descriptor = String.format("%s|%s|10.0|20.0|above|15",
+            Format.getHexString(Color.RED),
+            Format.getHexString(Color.GREEN));
+    fc = FeatureColour.parseJalviewFeatureColour(descriptor);
+    assertTrue(fc.isGraduatedColour());
+    assertTrue(fc.hasThreshold());
+    assertTrue(fc.isAboveThreshold());
+    assertEquals(15f, fc.getThreshold());
+    assertEquals(fc.getMinColour(), Colour.red);
+    // assertEquals(Color.RED, fc.getMinColour());
+    assertEquals(fc.getMaxColour(), Colour.green);
+    // assertEquals(Color.GREEN, fc.getMaxColour());
+    assertEquals(10f, fc.getMin());
+    assertEquals(20f, fc.getMax());
+    assertTrue(fc.isAutoScaled());
+
+    /*
+     * graduated colour (by RGB triplet) (below threshold), absolute scale
+     */
+    descriptor = String.format("255,0,0|0,255,0|abso|10.0|20.0|below|15");
+    fc = FeatureColour.parseJalviewFeatureColour(descriptor);
+    assertTrue(fc.isGraduatedColour());
+    assertFalse(fc.isAutoScaled());
+    assertTrue(fc.hasThreshold());
+    assertTrue(fc.isBelowThreshold());
+    assertEquals(15f, fc.getThreshold());
+    assertEquals(fc.getMinColour(), Colour.red);
+    // assertEquals(Color.RED, fc.getMinColour());
+    assertEquals(fc.getMaxColour(), Colour.green);
+    // assertEquals(Color.GREEN, fc.getMaxColour());
+    assertEquals(10f, fc.getMin());
+    assertEquals(20f, fc.getMax());
+  }
+}
index a82b9c0..e20fc5c 100644 (file)
@@ -23,6 +23,8 @@ package jalview.util;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNull;
 
+import jalview.schemes.Colour;
+
 import java.awt.Color;
 
 import org.testng.annotations.Test;
@@ -66,11 +68,11 @@ public class ColorUtilsTest
   @Test(groups = { "Functional" })
   public void testToTkCode()
   {
-    assertEquals("#fffafa", ColorUtils.toTkCode(new Color(255, 250, 250))); // snow
-    assertEquals("#e6e6fa", ColorUtils.toTkCode(new Color(230, 230, 250))); // lavender
-    assertEquals("#dda0dd", ColorUtils.toTkCode(new Color(221, 160, 221))); // plum
-    assertEquals("#800080", ColorUtils.toTkCode(new Color(128, 0, 128))); // purple
-    assertEquals("#00ff00", ColorUtils.toTkCode(new Color(0, 255, 0))); // lime
+    assertEquals("#fffafa", ColorUtils.toTkCode(new Colour(255, 250, 250))); // snow
+    assertEquals("#e6e6fa", ColorUtils.toTkCode(new Colour(230, 230, 250))); // lavender
+    assertEquals("#dda0dd", ColorUtils.toTkCode(new Colour(221, 160, 221))); // plum
+    assertEquals("#800080", ColorUtils.toTkCode(new Colour(128, 0, 128))); // purple
+    assertEquals("#00ff00", ColorUtils.toTkCode(new Colour(0, 255, 0))); // lime
   }
 
   @Test(groups = { "Functional" })
index 200cfbb..1262587 100644 (file)
@@ -24,7 +24,9 @@ import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
-import java.awt.Color;
+import jalview.api.ColorI;
+import jalview.schemes.Colour;
+
 import java.lang.reflect.Field;
 import java.util.Random;
 
@@ -150,10 +152,10 @@ public class ViewStyleTest
     {
       field.set(vs, "Joe" + field.get(vs));
     }
-    else if (type.equals(Color.class))
+    else if (type.equals(ColorI.class))
     {
-      field.set(vs, Color.RED.equals(field.get(vs)) ? Color.BLACK
-              : Color.RED);
+      field.set(vs, Colour.red.equals(field.get(vs)) ? Colour.black
+              : Colour.red);
     }
     else
     {