1 package tim.prune.config;
6 * Class to hold a colour scheme for GpsPrune, including
7 * colours for background, points, selections and texts
9 public class ColourScheme
12 private Color[] _colours = new Color[NUM_COLOURS];
15 private static final Color[] DEFAULT_COLOURS = {Color.WHITE, Color.BLUE, Color.GREEN,
16 Color.BLACK, Color.RED, Color.ORANGE, Color.BLACK, Color.GRAY};
19 public static final int IDX_BACKGROUND = 0;
20 public static final int IDX_POINT = 1;
21 public static final int IDX_SELECTION = 2;
22 public static final int IDX_TEXT = 3;
23 public static final int IDX_PRIMARY = 4;
24 public static final int IDX_SECONDARY = 5;
25 public static final int IDX_BORDERS = 6;
26 public static final int IDX_LINES = 7;
28 private static final int NUM_COLOURS = 8;
32 * Load the colour scheme from the given String
33 * @param inCodes comma-separated hex codes describing colours
35 public void loadFromHex(String inCodes)
37 if (inCodes != null && inCodes.length() > 5)
39 String[] codes = inCodes.split(",");
40 final int numCodes = (codes.length > NUM_COLOURS ? NUM_COLOURS : codes.length);
41 for (int i=0; i<numCodes; i++) {
42 _colours[i] = ColourUtils.colourFromHex(codes[i]);
48 * @return colour to use for given index
50 public Color getColour(int inIndex)
52 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
53 Color currColour = _colours[inIndex];
54 return (currColour != null ? currColour : DEFAULT_COLOURS[inIndex]);
58 * @return default colour for given index
60 public static Color getDefaultColour(int inIndex)
62 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
63 return DEFAULT_COLOURS[inIndex];
67 * Edit one of the colours to a new value
68 * @param inIndex index of colour
69 * @param inColour colour to set
71 public void setColour(int inIndex, Color inColour)
73 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
74 _colours[inIndex] = inColour;
78 * @return colour scheme as string of concatenated hex codes
80 public String toString()
82 StringBuffer buff = new StringBuffer();
83 for (int i=0; i<NUM_COLOURS; i++) {
84 buff.append(ColourUtils.makeHexCode(getColour(i)));
87 return buff.toString();