X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FColourSchemes.java;h=e11540cea8ed7858e2c10344d341e4669cc7dca5;hb=f6a84063f10ea1ae9898310c541961cd1d53dd8a;hp=99e97592c55bb2c8f52de2a32c1f9ad908825391;hpb=f6123f656fa387e11f506dedd09672a0d0ff5ac5;p=jalview.git diff --git a/src/jalview/schemes/ColourSchemes.java b/src/jalview/schemes/ColourSchemes.java index 99e9759..e11540c 100644 --- a/src/jalview/schemes/ColourSchemes.java +++ b/src/jalview/schemes/ColourSchemes.java @@ -20,24 +20,20 @@ */ package jalview.schemes; +import jalview.api.AlignViewportI; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.ColorUtils; +import java.awt.Color; import java.util.LinkedHashMap; import java.util.Map; -public class ColourSchemes +public class ColourSchemes implements ApplicationSingletonI { - /* - * singleton instance of this class - */ - private static ColourSchemes instance = new ColourSchemes(); - - /* - * a map from scheme name (lower-cased) to an instance of it - */ - private Map schemes; /** * Returns the singleton instance of this class @@ -46,7 +42,8 @@ public class ColourSchemes */ public static ColourSchemes getInstance() { - return instance; + return (ColourSchemes) ApplicationSingletonProvider + .getInstance(ColourSchemes.class); } private ColourSchemes() @@ -55,6 +52,51 @@ public class ColourSchemes } /** + * ColourSchemeProperty "static" + */ + public Color[] rnaHelices = null; + + /** + * delete the existing cached RNA helices colours + */ + public static void resetRnaHelicesShading() + { + getInstance().rnaHelices = null; + } + + public static void initRnaHelicesShading(int n) + { + int i = 0; + ColourSchemes j = getInstance(); + + if (j.rnaHelices == null) + { + j.rnaHelices = new Color[n + 1]; + } + else if (j.rnaHelices != null && j.rnaHelices.length <= n) + { + Color[] t = new Color[n + 1]; + System.arraycopy(j.rnaHelices, 0, t, 0, j.rnaHelices.length); + i = j.rnaHelices.length; + j.rnaHelices = t; + } + else + { + return; + } + // Generate random colors and store + for (; i <= n; i++) + { + j.rnaHelices[i] = ColorUtils.generateRandomColor(Color.white); + } + } + + /** + * a map from scheme name (lower-cased) to an instance of it + */ + private Map schemes; + + /** * Loads an instance of each standard or user-defined colour scheme * * @return @@ -65,7 +107,7 @@ public class ColourSchemes * store in an order-preserving map, so items can be added to menus * in the order in which they are 'discovered' */ - schemes = new LinkedHashMap(); + schemes = new LinkedHashMap<>(); for (JalviewColourScheme cs : JalviewColourScheme.values()) { @@ -76,6 +118,7 @@ public class ColourSchemes { System.err.println("Error instantiating colour scheme for " + cs.toString() + " " + e.getMessage()); + e.printStackTrace(); } } } @@ -126,6 +169,7 @@ public class ColourSchemes * * @param name * name of the colour scheme + * @param viewport * @param forData * the data to be coloured * @param optional @@ -134,7 +178,7 @@ public class ColourSchemes * @return */ public ColourSchemeI getColourScheme(String name, - AnnotatedCollectionI forData, + AlignViewportI viewport, AnnotatedCollectionI forData, Map hiddenRepSequences) { if (name == null) @@ -142,7 +186,8 @@ public class ColourSchemes return null; } ColourSchemeI cs = schemes.get(name.toLowerCase()); - return cs == null ? null : cs.getInstance(forData, hiddenRepSequences); + return cs == null ? null + : cs.getInstance(viewport, forData); } /** @@ -158,7 +203,7 @@ public class ColourSchemes public ColourSchemeI getColourScheme(String name, AnnotatedCollectionI forData) { - return getColourScheme(name, forData, null); + return getColourScheme(name, null, forData, null); } /**