Latitude Longitude Formatter Palette

  • 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)

  • Download

    Download at sourceforge

  • Install

    Palette

    Just double-click on the .palette file, Interface builder will load it and automatically adds it into the palette window. If you want to remove the palette, edit palettes preferences (Tools->Palettes->Palettes Preferences) and remove it from the Cocoa Framework pane.

    Formatter

    You have to install the formatter framework into the Library/Frameworks folder (/System/Library/Frameworks/ for a system wide installation) to be able to launch the application using this formatter.

    Uninstall

    Remove the installed files.

  • 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).

    Drag and drop illustration

    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.

    Inspector window

    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".
  • Notes

    User Input

    User input parsing is convenient, the user doesn't need to respect stricly the format. See these examples :

    Format Input Formatted value
    #0.####° L 30 15  30.25° N
    #0.####° L -15' 0.25° S
    #0.####° 30" 0.00833°
    #0° #0' #0" 30" 0° 0' 30"
    #0° #0.##' -30 -30° 0'
    #0° #0.##' 30 15" 30° 0.25'
    #0° #0' #0" 30 25 15 30° 25' 15"
    #0d #0m #0s 30 25 15 30d 25m 15s
    Add zeros or placeholder (_) to align display output
    00° 00' 00" 2 2 2 02° 02' 02"
    00.00000° 5 05.00000°
    _0° _0' _0" 2 2 2  2°  2'  2"
    _0.00000° 5  5.00000°


Valid HTML 4.01! SourceForge.net Logo Valid CSS!

Nicolas Cherel - Magic Instinct Software