About
The
latitude longitude formatter palette integrates in Interface Builder a formatter
for latitude and longitude editing in a NSCell. The mechanism is divided
in two parts :
- The Interface
Builder palette, which controls the settings of the formatter
- The formatter
itself whose code is defined in a separated framework
Palette
The palette adds
a tab in the palette window of Interface Builder. This palette
has only one item : it represents the latitude and longitude formatter. If you want to use this formatter for a NSCell, you just
have to drag and drop it on this NSCell, the inspector will enable you
to choose display settings (see more details below)
Formatter
The formatter
generates a string with the internal double value which represents the
latitude or longitude. Also, when the user edits the NSCell to modify
the value, the formatter reads and generates the associated double value.
This formatter has been designed to make user input as simple and
friendly as possible (see string formatting options and input parsing
notes below)
Howto
Use the formatter
with Interface Builder
Such as number
formatters, you have to open the palette's tab, and drag the
formatter and drop it into the NSCell you want to format. To edit the
format, open the Inspector (menu Tools->Show Info), and you will
get the settings window (inspector).
There are two main
ways to edit the format, you can choose to use the default format or a
user predefined format. The default format is defined with common
representation (° ', " symbols) and two decimal values for the
seconds. You can choose if you want to display minutes, seconds and
literal symbol for cardinal direction (N, S, E, W).
User predefined
formats come with some examples : you can edit or remove these
formats or add custom ones. To edit the predefined formats, use the text
field and specify the action you want with the + (add), - (remove) and
= (modify) buttons.
A
format should be
composed of one to three number formats (these are the same as the
NSNumberFormatter, see NSNumberFormatter documentation for more
informations), and for each number, a string which permits to identify
it. It can be composed of one, two or three number formats. The first
will represent the degrees, the second the minutes and the third the
seconds.
The formatter has
been designed to be less restrictive as possible. So you can choose any
formats you want, but be careful, and respect these rules :
- Always put at
least one character between number formats (it can be a space)
- Never separate
number formats by more than one string (deg
in #0deg #0min
is right deg f
in #0deg f#0min
is wrong). The formatter will react as expected, but user experience
can become puzzling (the input "deg " will be recognized but "deg f"
won't).
- Do not try to
create a format that wouldn't display degrees value (or seconds without
minutes), that's simply impossible. Note that if user specifies the type
of the value, the formatter will recognize it (with the format #0°
#0' the input 30'
will be parsed as thirty minutes, even if the degree value is missing).
See notes for user input
Use the formatter
directly in my code
To use the formatter
directly in your code, just include the provided header, and
instantiate it. Method descriptions :
- The method [setFormat:(NSString
*)] takes a format as defined
above.
- To parse a string
an get the corresponding NSNumber, just call [getObjectValue:(id
*)anObject forString:(NSString *)string errorDescription:(NSString
**)error]. This method return
YES if the string has been parsed successfully, else it returns NO.
anObject will be initialized with the NSNumber, string is the NSString
to parse and if error is not nil an error will be reported in this
string in case of failure.
- [(NSString
*)stringForObjectValue:(id)anObject]
returns the string formatted with the format (default if none has been
specified by setFormat:) corresponding to the NSNumber "anObject".