JAL-2360 refactoring for JalviewColourScheme enum,
[jalview.git] / src / jalview / schemes / JalviewColourScheme.java
diff --git a/src/jalview/schemes/JalviewColourScheme.java b/src/jalview/schemes/JalviewColourScheme.java
new file mode 100644 (file)
index 0000000..355ff83
--- /dev/null
@@ -0,0 +1,204 @@
+package jalview.schemes;
+
+import jalview.datamodel.AnnotatedCollectionI;
+
+import java.awt.Color;
+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)
+    {
+      Color[] col = new Color[24];
+      for (int i = 0; i < 24; i++)
+      {
+        col[i] = Color.white;
+      }
+      return new UserColourScheme("white");
+    }
+  };
+
+  static Map<String, JalviewColourScheme> names = new HashMap<String, JalviewColourScheme>();
+
+  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());
+  }
+
+  /**
+   * Constructor given the name of the colour scheme (as used in Jalview
+   * parameters). Note this is not necessarily the same as the 'display name'
+   * used in menu options (as this may be language-dependent).
+   * 
+   * @param s
+   */
+  JalviewColourScheme(String s)
+  {
+    name = s;
+  }
+
+  /**
+   * Returns an instance of the colour scheme with which to colour the given
+   * data
+   * 
+   * @param coll
+   * @return
+   */
+  public abstract ColourSchemeI getColourScheme(AnnotatedCollectionI coll);
+
+  /**
+   * Returns the 'official' name of this colour scheme. This is the name that
+   * identifies the colour scheme as a start-up parameter for the Jalview
+   * application or applet. Note that it may not be the name shown in menu
+   * options, as these may be internationalised.
+   */
+  @Override
+  public String toString()
+  {
+    return name;
+  }
+}