us.zuercher.gpx2map.gui
Class Main

java.lang.Object
  extended by us.zuercher.gpx2map.gui.Main

public class Main
extends Object

Main is the main entry point into the graphical user interface of gpx2map.

Author:
Stephan Zuercher

Nested Class Summary
private static class Main.LocalFileFilter
          LocalFileFilter is a FileFilter for a JFileChooser.
 
Field Summary
 Action aboutAction
          About action.
 Action aboutCloseButtonAction
          About close button action.
private  JDialog aboutDialog
          The about dialog, when open.
 JRadioButton allRadio
          Bound by all radio button.
 Action browseCacheDirAction
          Cache directory browse action.
 Action browseGpxFileAction
          GPX browse file action.
 Action browseOutputFileAction
          Output file browse action.
 Action browseRtePtStyleFileAction
          Route-point style file browse action.
 Action browseTrkPtStyleFileAction
          Track style file browse action.
 Action browseWayPtStyleFileAction
          Way-point style file browse button action.
 JTextField cacheDirField
          Cache directory field.
private static String COLOR_BUTTON_POSTFIX
          Suffix for marker color buttons.
private static String COLOR_BUTTON_PREFIX
          Prefix for marker color buttons.
 JLabel coordsNwLabel
          Bound by coords northwest label.
 JLabel coordsNwLatDegLabel
          Bound by coords northwest latitude degrees label.
 JFormattedTextField coordsNwLatField
          Bound by coords northwest latitude field.
 JLabel coordsNwLonDegLabel
          Bound by coords northwest longitude degrees label.
 JFormattedTextField coordsNwLonField
          Bound by coords northwest longitude field.
 JRadioButton coordsRadio
          Bound by coords radio button.
 ItemListener coordsRadioListener
          Bound by coords radio button listener.
 JLabel coordsSeLabel
          Bound by coords southeast label.
 JLabel coordsSeLatDegLabel
          Bound by coords southeast latitude degrees label.
 JFormattedTextField coordsSeLatField
          Bound by coords southeast latitude field.
 JLabel coordsSeLonDegLabel
          Bound by coords southeast longitude degrees label.
 JFormattedTextField coordsSeLonField
          Bound by coords southeast longitude field.
private static Color DEFAULT_COLOR
          Default marker color.
private  ActionListener dialogCancelListener
          File dialog Cancel listener.
private  boolean dialogOk
          File dialog result.
private  ActionListener dialogOkListener
          File dialog OK listener.
 Action executeAction
          Execute action.
 JComboBox fontCombo
          Font name combo box.
 JComboBox fontSizeCombo
          Font size combo box.
 JTextField gpxFileField
          GPX file field.
private  ItemListener gpxFileIgnoreItemListener
           
 JCheckBox gpxFileIgnoreRtePts
          GPX ignore routescheckbox.
 JCheckBox gpxFileIgnoreTrkPts
          GPX ignore tracks checkbox.
 JCheckBox gpxFileIgnoreWayPts
          GPX ignore way-points checkbox.
private  MapSourceComboBoxModel.MapSourceChoice mapSourceChoice
          Currently selected combo choice.
 JComboBox mapSourceCombo
          Map source combo box.
 Action mapSourceComboAction
          Map source combo box change action.
 JPanel mapSourcePanel
          Map source box's panel.
private  List<JComboBox> mapSourcePropertyComboFields
           
private  List<JLabel> mapSourcePropertyLabels
           
private  List<JTextField> mapSourcePropertyTextFields
           
 JTextField marginField
          Margin field.
 JRadioButton metersRadio
          Meters radio button.
 JTextField outputFileField
          Output file field.
 JRadioButton pixelsRadio
          Pixels radio button.
private static File propertyFile
          Properties file.
private  JFrame root
          Main frame of the application.
 JRadioButton routesRadio
          Bound by routes radio button.
private  Color rtePtColor
          Current route-point color.
 Action rtePtColorAction
          Route-point color action.
 JButton rtePtColorButton
          Route-point color button.
 JCheckBox rtePtLabel
          Route-point labelling check box.
 JFormattedTextField rtePtSizeField
          Route-point marker size field.
 JSpinner rtePtSizeSpinner
          Route-point marker size spinner.
 JComboBox rtePtStyleCombo
          Route-point style combo box.
 Action rtePtStyleComboAction
          Route-point style combo box action.
 JButton rtePtStyleFileBrowseButton
          Route-point style file browse button.
 JTextField rtePtStyleFileField
          Route-point style file field.
 Action saveSettingsAction
          Save setting action.
private  Text text
          Localized text singleton.
 JRadioButton tracksRadio
          Bound by tracks radio button.
private  Color trkPtColor
          Current track color.
 Action trkPtColorAction
          Track color button action.
 JButton trkPtColorButton
          Track color button.
 JCheckBox trkPtJoin
          Track segment joining check box.
 JCheckBox trkPtLabel
          Track labelling check box.
 JFormattedTextField trkPtSizeField
          Track style marker size field.
 JSpinner trkPtSizeSpinner
          Track style marker size spinner.
 JComboBox trkPtStyleCombo
          Track style combo box.
 Action trkPtStyleComboAction
          Track style combo box action.
 JButton trkPtStyleFileBrowseButton
          Track style file browse button.
 JTextField trkPtStyleFileField
          Track style file field.
 JRadioButton wayPointsRadio
          Bound by way-points radio button.
private  Color wayPtColor
          Current way-point color.
 Action wayPtColorAction
          Way-point color button action.
 JButton wayPtColorButton
          Way-point color button.
 JFormattedTextField wayPtSizeField
          Way-point marker size field.
 JSpinner wayPtSizeSpinner
          Way-point marker size spinner.
 JComboBox wayPtStyleCombo
          Way-point style combo box.
 Action wayPtStyleComboAction
          Way-point style combo box action.
 JButton wayPtStyleFileBrowseButton
          Way-point style file browse button.
 JTextField wayPtStyleFileField
          Way-point style file field.
private  WindowListener windowListener
          Listens for window closing events and handles graceful exits.
 
Constructor Summary
private Main()
          Constructs a new Main object.
 
Method Summary
private  void about()
           
private  Color chooseColor(Color initialColor, String titleKey)
          Display a color chooser and return the user's selected Color.
private  String chooseDir(String titleKey, File currentValue)
          Displays a directory chooser.
private  String chooseFile(String titleKey, Collection<FileFormatDescriptor> formats, File currentValue, boolean save)
          Displays a file chooser.
private  String chooseFile(String titleKey, String descKey, String suffix, File currentValue, boolean save)
          Displays a file chooser.
private  String chooseImageFile(String titleKey, File currentValue, boolean ppmOnly, boolean save)
          Display an image file chooser.
private  void configureMarkerSpinnerEditor(JSpinner spinner, JFormattedTextField field)
          Configure a spinner and formatted text field to work together.
private  void execute()
          Applies the GUI settings to the Gpx2Map and generates/plots the map.
private  File getCurrentFile(JTextComponent fileField)
          Convert the contents of a JTextComponent into a File.
private  MarkerStyle getMarkerStyle(JComboBox styleCombo, String fileText)
           
private  boolean loadSettings()
          Load current settings from the settings file.
static void main(String[] args)
          Main entry point for the Gpx2Map GUI.
private  void saveSettings()
          Save the current settings for later use.
private  void setComboBoxSelection(JComboBox comboBox, String value)
          Iterates over the given JComboBox's items and marks the item whose display name matches the given value as selected.
private  void showUserInterface()
          Display the Gpx2Map user interface.
static void start(String localeName)
          Simplified entry point for Main.
private  String toHexString(int x)
          Convert an integer to a minimum two-digit hex string.
private  void updateColor(JButton colorButton, Color color)
          Modifies the color of a "color button." Colors buttons are simply a JButton with an HTML table as the button label content.
private  void updateMapSourceProperties()
          Update the map source property controls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_COLOR

private static final Color DEFAULT_COLOR
Default marker color.


propertyFile

private static final File propertyFile
Properties file.


COLOR_BUTTON_PREFIX

private static String COLOR_BUTTON_PREFIX
Prefix for marker color buttons.


COLOR_BUTTON_POSTFIX

private static String COLOR_BUTTON_POSTFIX
Suffix for marker color buttons.


text

private final Text text
Localized text singleton.


root

private JFrame root
Main frame of the application.


gpxFileField

public JTextField gpxFileField
GPX file field.


browseGpxFileAction

public Action browseGpxFileAction
GPX browse file action.


gpxFileIgnoreTrkPts

public JCheckBox gpxFileIgnoreTrkPts
GPX ignore tracks checkbox.


gpxFileIgnoreRtePts

public JCheckBox gpxFileIgnoreRtePts
GPX ignore routescheckbox.


gpxFileIgnoreWayPts

public JCheckBox gpxFileIgnoreWayPts
GPX ignore way-points checkbox.


gpxFileIgnoreItemListener

private ItemListener gpxFileIgnoreItemListener

outputFileField

public JTextField outputFileField
Output file field.


browseOutputFileAction

public Action browseOutputFileAction
Output file browse action.


mapSourcePanel

public JPanel mapSourcePanel
Map source box's panel.


mapSourceCombo

public JComboBox mapSourceCombo
Map source combo box.


mapSourceChoice

private MapSourceComboBoxModel.MapSourceChoice mapSourceChoice
Currently selected combo choice.


mapSourceComboAction

public Action mapSourceComboAction
Map source combo box change action.


mapSourcePropertyLabels

private List<JLabel> mapSourcePropertyLabels

mapSourcePropertyTextFields

private List<JTextField> mapSourcePropertyTextFields

mapSourcePropertyComboFields

private List<JComboBox> mapSourcePropertyComboFields

cacheDirField

public JTextField cacheDirField
Cache directory field.


browseCacheDirAction

public Action browseCacheDirAction
Cache directory browse action.


marginField

public JTextField marginField
Margin field.


metersRadio

public JRadioButton metersRadio
Meters radio button.


pixelsRadio

public JRadioButton pixelsRadio
Pixels radio button.


tracksRadio

public JRadioButton tracksRadio
Bound by tracks radio button.


routesRadio

public JRadioButton routesRadio
Bound by routes radio button.


wayPointsRadio

public JRadioButton wayPointsRadio
Bound by way-points radio button.


allRadio

public JRadioButton allRadio
Bound by all radio button.


coordsRadio

public JRadioButton coordsRadio
Bound by coords radio button.


coordsRadioListener

public ItemListener coordsRadioListener
Bound by coords radio button listener.


coordsNwLabel

public JLabel coordsNwLabel
Bound by coords northwest label.


coordsNwLatField

public JFormattedTextField coordsNwLatField
Bound by coords northwest latitude field.


coordsNwLatDegLabel

public JLabel coordsNwLatDegLabel
Bound by coords northwest latitude degrees label.


coordsNwLonField

public JFormattedTextField coordsNwLonField
Bound by coords northwest longitude field.


coordsNwLonDegLabel

public JLabel coordsNwLonDegLabel
Bound by coords northwest longitude degrees label.


coordsSeLabel

public JLabel coordsSeLabel
Bound by coords southeast label.


coordsSeLatField

public JFormattedTextField coordsSeLatField
Bound by coords southeast latitude field.


coordsSeLatDegLabel

public JLabel coordsSeLatDegLabel
Bound by coords southeast latitude degrees label.


coordsSeLonField

public JFormattedTextField coordsSeLonField
Bound by coords southeast longitude field.


coordsSeLonDegLabel

public JLabel coordsSeLonDegLabel
Bound by coords southeast longitude degrees label.


fontCombo

public JComboBox fontCombo
Font name combo box.


fontSizeCombo

public JComboBox fontSizeCombo
Font size combo box.


trkPtColor

private Color trkPtColor
Current track color.


trkPtColorButton

public JButton trkPtColorButton
Track color button.


trkPtColorAction

public Action trkPtColorAction
Track color button action.


trkPtStyleCombo

public JComboBox trkPtStyleCombo
Track style combo box.


trkPtStyleComboAction

public Action trkPtStyleComboAction
Track style combo box action.


trkPtStyleFileField

public JTextField trkPtStyleFileField
Track style file field.


trkPtStyleFileBrowseButton

public JButton trkPtStyleFileBrowseButton
Track style file browse button.


browseTrkPtStyleFileAction

public Action browseTrkPtStyleFileAction
Track style file browse action.


trkPtSizeField

public JFormattedTextField trkPtSizeField
Track style marker size field.


trkPtSizeSpinner

public JSpinner trkPtSizeSpinner
Track style marker size spinner.


trkPtLabel

public JCheckBox trkPtLabel
Track labelling check box.


trkPtJoin

public JCheckBox trkPtJoin
Track segment joining check box.


rtePtColor

private Color rtePtColor
Current route-point color.


rtePtColorButton

public JButton rtePtColorButton
Route-point color button.


rtePtColorAction

public Action rtePtColorAction
Route-point color action.


rtePtStyleCombo

public JComboBox rtePtStyleCombo
Route-point style combo box.


rtePtStyleComboAction

public Action rtePtStyleComboAction
Route-point style combo box action.


rtePtStyleFileField

public JTextField rtePtStyleFileField
Route-point style file field.


rtePtStyleFileBrowseButton

public JButton rtePtStyleFileBrowseButton
Route-point style file browse button.


browseRtePtStyleFileAction

public Action browseRtePtStyleFileAction
Route-point style file browse action.


rtePtSizeField

public JFormattedTextField rtePtSizeField
Route-point marker size field.


rtePtSizeSpinner

public JSpinner rtePtSizeSpinner
Route-point marker size spinner.


rtePtLabel

public JCheckBox rtePtLabel
Route-point labelling check box.


wayPtColor

private Color wayPtColor
Current way-point color.


wayPtColorButton

public JButton wayPtColorButton
Way-point color button.


wayPtColorAction

public Action wayPtColorAction
Way-point color button action.


wayPtStyleCombo

public JComboBox wayPtStyleCombo
Way-point style combo box.


wayPtStyleComboAction

public Action wayPtStyleComboAction
Way-point style combo box action.


wayPtStyleFileField

public JTextField wayPtStyleFileField
Way-point style file field.


wayPtStyleFileBrowseButton

public JButton wayPtStyleFileBrowseButton
Way-point style file browse button.


browseWayPtStyleFileAction

public Action browseWayPtStyleFileAction
Way-point style file browse button action.


wayPtSizeField

public JFormattedTextField wayPtSizeField
Way-point marker size field.


wayPtSizeSpinner

public JSpinner wayPtSizeSpinner
Way-point marker size spinner.


aboutAction

public Action aboutAction
About action.


aboutCloseButtonAction

public Action aboutCloseButtonAction
About close button action.


aboutDialog

private JDialog aboutDialog
The about dialog, when open.


saveSettingsAction

public Action saveSettingsAction
Save setting action.


executeAction

public Action executeAction
Execute action.


windowListener

private WindowListener windowListener
Listens for window closing events and handles graceful exits.


dialogOk

private boolean dialogOk
File dialog result.


dialogOkListener

private ActionListener dialogOkListener
File dialog OK listener.


dialogCancelListener

private ActionListener dialogCancelListener
File dialog Cancel listener.

Constructor Detail

Main

private Main()
Constructs a new Main object.

Method Detail

start

public static void start(String localeName)
Simplified entry point for Main.

Parameters:
localeName - name of a locale (in lang_COUNTRY_variant) format where lang is the ISO 630 language code (lower case), COUNTRY is the optional ISO 3166 country code (upper case), and variant is the optional variant name. If localeName is null, the system default locale is used.

main

public static void main(String[] args)
Main entry point for the Gpx2Map GUI.

Parameters:
args - unused

showUserInterface

private void showUserInterface()
Display the Gpx2Map user interface.


configureMarkerSpinnerEditor

private void configureMarkerSpinnerEditor(JSpinner spinner,
                                          JFormattedTextField field)
Configure a spinner and formatted text field to work together. Overcomes a limitation in SwixML that prevents configuring the editor for a spinner.

Parameters:
spinner - a JSpinner
field - a JFormattedTextField to associate with the JSpinner

updateMapSourceProperties

private void updateMapSourceProperties()
Update the map source property controls. First tests that the map source selection has actually changed. If so, removes any existing controls for map source properties and replaces them with controls for the new map source's property controls.


updateColor

private void updateColor(JButton colorButton,
                         Color color)
Modifies the color of a "color button." Colors buttons are simply a JButton with an HTML table as the button label content.

Parameters:
colorButton - the button to modify
color - the button's new color

toHexString

private String toHexString(int x)
Convert an integer to a minimum two-digit hex string.

Parameters:
x - an integer
Returns:
hex-string representing x, minimum two digits with leading zero as necessary

chooseColor

private Color chooseColor(Color initialColor,
                          String titleKey)
Display a color chooser and return the user's selected Color.

Parameters:
initialColor - the chooser's initial color
titleKey - resource key for the chooser's title, may not required parameters
Returns:
the user's selected Color or null, if the dialog is canceled.

chooseDir

private String chooseDir(String titleKey,
                         File currentValue)
Displays a directory chooser.

Parameters:
titleKey - resource key of title for the chooser, may not require parameters
currentValue - initial value for the chooser
Returns:
new directory or null if the dialog is canceled.

chooseFile

private String chooseFile(String titleKey,
                          String descKey,
                          String suffix,
                          File currentValue,
                          boolean save)
Displays a file chooser.

Parameters:
titleKey - resource key of title for the chooser, may not require parameters
descKey - resource key of file type description (e.g., "JPEG Images"); may not require parameters
suffix - file type suffix (e.g., ".jpeg")
currentValue - current file name
save - flag indicating whether this is to be a save dialog
Returns:
the user's new file choice or null if canceled

chooseFile

private String chooseFile(String titleKey,
                          Collection<FileFormatDescriptor> formats,
                          File currentValue,
                          boolean save)
Displays a file chooser.

Parameters:
titleKey - resource key of title for the chooser, may not require parameters
formats - FileFormatDescriptor objects for formats to accept in the dialog ("all files" is always available); first entry is the default
currentValue - current file name
save - flag indicating whether this is to be a save dialog
Returns:
the user's new file choice or null if canceled

chooseImageFile

private String chooseImageFile(String titleKey,
                               File currentValue,
                               boolean ppmOnly,
                               boolean save)
Display an image file chooser.

Parameters:
titleKey - resource key of title for the chooser, may not require parameters
currentValue - the chooser's starting file
ppmOnly - if true, only Netpbm images will be shown as a file type option
save - flag indicating whether this is to be a save dialog
Returns:
the user's new file choice or null if canceled

execute

private void execute()
Applies the GUI settings to the Gpx2Map and generates/plots the map.


getMarkerStyle

private MarkerStyle getMarkerStyle(JComboBox styleCombo,
                                   String fileText)

about

private void about()

saveSettings

private void saveSettings()
Save the current settings for later use.


loadSettings

private boolean loadSettings()
                      throws StartupException
Load current settings from the settings file. May only be called before the Gpx2Map window is displayed, as it throws StartupException. StartupException is only thrown for cases where the error demands further investigation:

Returns:
true if settings were successfully loaded; false if there were not settings to load
Throws:
StartupException - on some errors, see above

setComboBoxSelection

private void setComboBoxSelection(JComboBox comboBox,
                                  String value)
Iterates over the given JComboBox's items and marks the item whose display name matches the given value as selected. If no matching item is found, the previously selected item remains selected.

Parameters:
comboBox - the JComboBox to modify
value - the display name of the item to select

getCurrentFile

private File getCurrentFile(JTextComponent fileField)
Convert the contents of a JTextComponent into a File.

Parameters:
fileField - the JTextComponent to convert.
Returns:
a File representing the contents of fileField or null if fileField is empty