1 package tim.prune.gui.map;
3 import javax.swing.ImageIcon;
5 import tim.prune.gui.IconManager;
8 * Class to provide a library of waypoint icon definitions
10 public abstract class WpIconLibrary
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;
21 public static final int SIZE_SMALL = 0;
22 public static final int SIZE_MEDIUM = 1;
23 public static final int SIZE_LARGE = 2;
25 /** Array of x and y offsets for the icons */
26 private static int[] _PIXEL_OFFSETS = null;
28 /** Static block to initialise offsets */
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
39 /** @return array of Integers representing waypoint types */
40 public static Integer[] getWaypointTypes()
42 return new Integer[] {WAYPT_DEFAULT, WAYPT_RING_POINT, WAYPT_PLECTRUM, WAYPT_CIRCLE, WAYPT_PIN};
46 * @param inType icon type
47 * @return the name of the specified icon, used for settings dialog
49 public static String getIconName(int inType)
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";
58 default: return "default";
63 * @param inType icon type
64 * @param inSize icon size (small/medium/large)
65 * @return icon definition for the specified icon
67 public static WpIconDefinition getIconDefinition(int inType, int inSize)
69 String iconName = getIconName(inType);
70 String sizeSuffix = null;
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;
78 // Look up offsets in the static array
79 int xOffset = 0, yOffset = 0;
81 xOffset = _PIXEL_OFFSETS[inType * 6 + inSize * 2];
82 yOffset = _PIXEL_OFFSETS[inType * 6 + inSize * 2 + 1];
84 catch (ArrayIndexOutOfBoundsException obe) {} // ignore, leave offsets at 0
85 WpIconDefinition iconDef = new WpIconDefinition(iconName, xOffset, yOffset);
87 ImageIcon icon = IconManager.getImageIcon(IconManager.WAYPOINT_ICON_PREFIX
88 + iconDef.getName() + sizeSuffix + IconManager.WAYPOINT_ICON_SUFFIX);
89 iconDef.setIcon(icon);