]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/config/ColourScheme.java
5f3e0cd725c396b48bf3ead4bfe72e05d88a46d0
[GpsPrune.git] / tim / prune / config / ColourScheme.java
1 package tim.prune.config;
2
3 import java.awt.Color;
4
5 /**
6  * Class to hold a colour scheme for Prune, including
7  * colours for background, points, selections and texts
8  */
9 public class ColourScheme
10 {
11         // Current colours
12         private Color[] _colours = new Color[NUM_COLOURS];
13
14         // Default 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};
17
18         // Colour indices
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;
27         // Number of colours
28         private static final int NUM_COLOURS = 8;
29
30
31         /**
32          * Load the colour scheme from the given String
33          * @param inCodes comma-separated hex codes describing colours
34          */
35         public void loadFromHex(String inCodes)
36         {
37                 if (inCodes != null && inCodes.length() > 5)
38                 {
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]);
43                         }
44                 }
45         }
46
47         /**
48          * @return colour to use for given index
49          */
50         public Color getColour(int inIndex)
51         {
52                 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
53                 Color currColour = _colours[inIndex];
54                 return (currColour != null ? currColour : DEFAULT_COLOURS[inIndex]);
55         }
56
57         /**
58          * @return default colour for given index
59          */
60         public static Color getDefaultColour(int inIndex)
61         {
62                 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
63                 return DEFAULT_COLOURS[inIndex];
64         }
65
66         /**
67          * Edit one of the colours to a new value
68          * @param inIndex index of colour
69          * @param inColour colour to set
70          */
71         public void setColour(int inIndex, Color inColour)
72         {
73                 assert (inIndex >= 0 && inIndex < NUM_COLOURS);
74                 _colours[inIndex] = inColour;
75         }
76
77         /**
78          * @return colour scheme as string of concatenated hex codes
79          */
80         public String toString()
81         {
82                 StringBuffer buff = new StringBuffer();
83                 for (int i=0; i<NUM_COLOURS; i++) {
84                         buff.append(ColourUtils.makeHexCode(getColour(i)));
85                         buff.append(',');
86                 }
87                 return buff.toString();
88         }
89 }