]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/map/WpIconLibrary.java
Version 19, May 2018
[GpsPrune.git] / tim / prune / gui / map / WpIconLibrary.java
1 package tim.prune.gui.map;
2
3 import javax.swing.ImageIcon;
4
5 import tim.prune.gui.IconManager;
6
7 /**
8  * Class to provide a library of waypoint icon definitions
9  */
10 public abstract class WpIconLibrary
11 {
12         /** Types of waypoint */
13         public static final int WAYPT_DEFAULT = 0;
14         public static final int WAYPT_RING_POINT = 1;
15         public static final int WAYPT_PLECTRUM = 2;
16         public static final int WAYPT_CIRCLE = 3;
17         public static final int WAYPT_PIN = 4;
18         public static final int WAYPT_NUMBER_OF_ICONS = WAYPT_PIN + 1;
19
20         /** Sizes of icon */
21         public static final int SIZE_SMALL = 0;
22         public static final int SIZE_MEDIUM = 1;
23         public static final int SIZE_LARGE = 2;
24
25         /** Array of x and y offsets for the icons */
26         private static int[] _PIXEL_OFFSETS = null;
27
28         /** Static block to initialise offsets */
29         static
30         {
31                 _PIXEL_OFFSETS = new int[] {0, 0, 0, 0, 0, 0, // default
32                         8,  13, 12, 22, 14, 26, // ringpt
33                         7,  15, 12, 24, 14, 27, // plectrum
34                         8,  8,  12, 12, 14, 14, // ring
35                         2,  15, 4,  23, 4,  27  // pin
36                 };
37         }
38
39         /** @return array of Integers representing waypoint types */
40         public static Integer[] getWaypointTypes()
41         {
42                 return new Integer[] {WAYPT_DEFAULT, WAYPT_RING_POINT, WAYPT_PLECTRUM, WAYPT_CIRCLE, WAYPT_PIN};
43         }
44
45         /**
46          * @param inType icon type
47          * @return the name of the specified icon, used for settings dialog
48          */
49         public static String getIconName(int inType)
50         {
51                 switch (inType)
52                 {
53                         case WAYPT_RING_POINT: return "ringpt";
54                         case WAYPT_PLECTRUM:   return "plectrum";
55                         case WAYPT_CIRCLE:     return "ring";
56                         case WAYPT_PIN:        return "pin";
57                         case WAYPT_DEFAULT:
58                         default:               return "default";
59                 }
60         }
61
62         /**
63          * @param inType icon type
64          * @param inSize icon size (small/medium/large)
65          * @return icon definition for the specified icon
66          */
67         public static WpIconDefinition getIconDefinition(int inType, int inSize)
68         {
69                 String iconName = getIconName(inType);
70                 String sizeSuffix = null;
71                 switch (inSize)
72                 {
73                         case SIZE_SMALL:  sizeSuffix = "_s"; break;
74                         case SIZE_MEDIUM: sizeSuffix = "_m"; break;
75                         case SIZE_LARGE:  sizeSuffix = "_l"; break;
76                         default:          sizeSuffix = "_m"; inSize = SIZE_MEDIUM; break;
77                 }
78                 // Look up offsets in the static array
79                 int xOffset = 0, yOffset = 0;
80                 try {
81                         xOffset = _PIXEL_OFFSETS[inType * 6 + inSize * 2];
82                         yOffset = _PIXEL_OFFSETS[inType * 6 + inSize * 2 + 1];
83                 }
84                 catch (ArrayIndexOutOfBoundsException obe) {} // ignore, leave offsets at 0
85                 WpIconDefinition iconDef = new WpIconDefinition(iconName, xOffset, yOffset);
86                 // Get icon
87                 ImageIcon icon = IconManager.getImageIcon(IconManager.WAYPOINT_ICON_PREFIX
88                         + iconDef.getName() + sizeSuffix + IconManager.WAYPOINT_ICON_SUFFIX);
89                 iconDef.setIcon(icon);
90                 return iconDef;
91         }
92 }