Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / schemes / JalviewColourScheme.java
index 7044a10..da49fac 100644 (file)
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.schemes;
 
-import jalview.datamodel.AnnotatedCollectionI;
-
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * An enum with the colour schemes supported by Jalview.
  */
 public enum JalviewColourScheme
 {
-  Clustal("Clustal")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new ClustalxColourScheme(coll, null);
-    }
-  },
-  Blosum62("Blosum62")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new Blosum62ColourScheme();
-    }
-  },
-  PID("% Identity")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new PIDColourScheme();
-    }
-  },
-  Zappo("Zappo")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new ZappoColourScheme();
-    }
-  },
-  Taylor("Taylor")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new TaylorColourScheme();
-    }
-  },
-  Hydrophobic("Hydrophobic")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new HydrophobicColourScheme();
-    }
-  },
-  Helix("Helix Propensity")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new HelixColourScheme();
-    }
-  },
-  Strand("Strand Propensity")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new StrandColourScheme();
-    }
-  },
-  Turn("Turn Propensity")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new TurnColourScheme();
-    }
-  },
-  Buried("Buried Index")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new BuriedColourScheme();
-    }
-  },
-  Nucleotide("Nucleotide")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new NucleotideColourScheme();
-    }
-  },
-  PurinePyrimidine("Purine/Pyrimidine")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new PurinePyrimidineColourScheme();
-    }
-  },
-  TCoffee("T-Coffee Scores")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new TCoffeeColourScheme(coll);
-    }
-  },
-  RNAHelices("RNA Helices")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new RNAHelicesColour(coll);
-    }
-  },
-  // RNAInteraction("RNA Interaction type")
-  // {
-  // @Override
-  // public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-  // {
-  // return new RNAInteractionColourScheme();
-  // }
-  // },
-  UserDefined("User Defined")
-  {
-    @Override
-    public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
-    {
-      return new UserColourScheme("white");
-    }
-  };
-
-  static Map<String, JalviewColourScheme> names = new HashMap<String, JalviewColourScheme>();
+  /*
+   * the order of declaration is the default order in which 
+   * items are added to Colour menus
+   */
+  Clustal("Clustal", ClustalxColourScheme.class),
+  Blosum62("Blosum62", Blosum62ColourScheme.class),
+  PID("% Identity", PIDColourScheme.class),
+  Zappo("Zappo", ZappoColourScheme.class),
+  Taylor("Taylor", TaylorColourScheme.class),
+  Flower("gecos-flower", FlowerColourScheme.class),
+  Blossom("gecos-blossom", BlossomColourScheme.class),
+  Sunset("gecos-sunset", SunsetColourScheme.class),
+  Ocean("gecos-ocean", OceanColourScheme.class),
+  Hydrophobic("Hydrophobic", HydrophobicColourScheme.class),
+  Helix("Helix Propensity", HelixColourScheme.class),
+  Strand("Strand Propensity", StrandColourScheme.class),
+  Turn("Turn Propensity", TurnColourScheme.class),
+  Buried("Buried Index", BuriedColourScheme.class),
+  Nucleotide("Nucleotide", NucleotideColourScheme.class),
+  NucleotideAmbiguity("Nucleotide Ambiguity",
+          NucleotideAmbiguityColourScheme.class),
+  PurinePyrimidine("Purine/Pyrimidine", PurinePyrimidineColourScheme.class),
+  RNAHelices("RNA Helices", RNAHelicesColour.class),
+  TCoffee("T-Coffee Scores", TCoffeeColourScheme.class),
+  IdColour("Sequence ID", IdColourScheme.class),;
+  // RNAInteraction("RNA Interaction type", RNAInteractionColourScheme.class)
 
   private String name;
 
-  static
-  {
-    for (JalviewColourScheme scheme : values())
-    {
-      names.put(scheme.name.toLowerCase(), scheme);
-    }
-  }
-
-  /**
-   * Answers the colour scheme with the 'given name', or null if name is invalid
-   * or null. The name is not case-sensitive.
-   * 
-   * @param name
-   * @return
-   */
-  public static JalviewColourScheme forName(String name)
-  {
-    return name == null ? null : names.get(name.toLowerCase());
-  }
+  private Class<? extends ColourSchemeI> myClass;
 
   /**
    * Constructor given the name of the colour scheme (as used in Jalview
@@ -170,19 +63,21 @@ public enum JalviewColourScheme
    * 
    * @param s
    */
-  JalviewColourScheme(String s)
+  JalviewColourScheme(String s, Class<? extends ColourSchemeI> cl)
   {
     name = s;
+    myClass = cl;
   }
 
   /**
-   * Returns an instance of the colour scheme with which to colour the given
-   * data
+   * Returns the class of the colour scheme
    * 
-   * @param coll
    * @return
    */
-  public abstract ColourSchemeI getColourScheme(AnnotatedCollectionI coll);
+  public Class<? extends ColourSchemeI> getSchemeClass()
+  {
+    return myClass;
+  }
 
   /**
    * Returns the 'official' name of this colour scheme. This is the name that