org.geotoolkit.gui.swing.referencing
Class CoordinateChooser

Object
  extended by Component
      extended by Container
          extended by JComponent
              extended by CoordinateChooser
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Dialog

public class CoordinateChooser
extends JComponent
implements Dialog

A pane of controls designed to allow a user to select spatio-temporal coordinates. Current implementation uses geographic coordinates (longitudes/latitudes) and dates according some locale calendar. Future version may allow the use of user-specified coordinate system. Latitudes are constrained in the range 90°S to 90°N inclusive. Longitudes are constrained in the range 180°W to 180°E inclusive. By default, dates are constrained in the range January 1st, 1970 up to the date at the time the widget was created.


Demo
The image on the left side gives an example of this widget appearance. To try this component in your browser, see the demonstration applet.

Since:
2.3
Version:
3.14
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
Serialized Form
Module:
display/geotk-widgets-swing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int GEOGRAPHIC_AREA
          An enumeration constant for showing or hiding the geographic area selector.
static int RESOLUTION
          An enumeration constant for showing or hiding the resolution selector.
static int TIME_RANGE
          An enumeration constant for showing or hiding the time range selector.
 
Fields inherited from class JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CoordinateChooser()
          Constructs a default coordinate chooser.
CoordinateChooser(Date minTime, Date maxTime)
          Constructs a coordinate chooser with date constrained in the specified range.
 
Method Summary
 void addChangeListener(int selectors, ChangeListener listener)
          Adds a change listener to the listener list.
 void commitEdit()
          Forces the current value to be taken from the editable fields and set them as the current values.
 JComponent getAccessory()
          Returns the accessory component.
 Date getEndTime()
          Returns the end time, or null if there is none.
 Rectangle2D getGeographicArea()
          Gets the geographic area, in latitude and longitude degrees.
 Dimension2D getPreferredResolution()
          Returns the preferred resolution.
 Date getStartTime()
          Returns the start time, or null if there is none.
 TimeZone getTimeZone()
          Returns the time zone used for displaying dates.
 boolean isSelectorVisible(int selector)
          Tells if a selector is currently visible or not.
 void removeChangeListener(int selectors, ChangeListener listener)
          Removes a change listener from the listener list.
 void setAccessory(JComponent accessory)
          Sets the accessory component.
 void setGeographicArea(Rectangle2D area)
          Sets the geographic area, in latitude and longitude degrees.
 void setPreferredResolution(Dimension2D resolution)
          Sets the preferred resolution.
 void setSelectorVisible(int selectors, boolean visible)
          Sets the visible state of one or many selectors.
 void setTimeRange(Date startTime, Date endTime)
          Sets the time range.
 void setTimeZone(TimeZone timezone)
          Sets the time zone.
 boolean showDialog(Component owner)
          Shows a dialog box requesting input from the user.
 boolean showDialog(Component owner, String title)
          Shows a dialog box requesting input from the user.
 
Methods inherited from class JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GEOGRAPHIC_AREA

public static final int GEOGRAPHIC_AREA
An enumeration constant for showing or hiding the geographic area selector. Used as argument for isSelectorVisible(int) and setSelectorVisible(int, boolean).

See Also:
TIME_RANGE, RESOLUTION, isSelectorVisible(int), setSelectorVisible(int, boolean), addChangeListener(int, javax.swing.event.ChangeListener), removeChangeListener(int, javax.swing.event.ChangeListener), Constant Field Values

TIME_RANGE

public static final int TIME_RANGE
An enumeration constant for showing or hiding the time range selector. Used as argument for isSelectorVisible(int) and setSelectorVisible(int, boolean).

See Also:
GEOGRAPHIC_AREA, RESOLUTION, isSelectorVisible(int), setSelectorVisible(int, boolean), addChangeListener(int, javax.swing.event.ChangeListener), removeChangeListener(int, javax.swing.event.ChangeListener), Constant Field Values

RESOLUTION

public static final int RESOLUTION
An enumeration constant for showing or hiding the resolution selector. Used as argument for isSelectorVisible(int) and setSelectorVisible(int, boolean).

See Also:
GEOGRAPHIC_AREA, TIME_RANGE, isSelectorVisible(int), setSelectorVisible(int, boolean), addChangeListener(int, javax.swing.event.ChangeListener), removeChangeListener(int, javax.swing.event.ChangeListener), Constant Field Values
Constructor Detail

CoordinateChooser

public CoordinateChooser()
Constructs a default coordinate chooser. Date will be constrained in the range from January 1st, 1970 00:00 UTC up to the current time.


CoordinateChooser

public CoordinateChooser(Date minTime,
                         Date maxTime)
Constructs a coordinate chooser with date constrained in the specified range. Note that the [minTime..maxTime] range is not the same than the range given to setTimeRange(java.util.Date, java.util.Date). The later set only the time range shown in the widget, while this constructor set also the minimum and maximum dates allowed.

Parameters:
minTime - The minimal date allowed.
maxTime - the maximal date allowed.
Method Detail

isSelectorVisible

public boolean isSelectorVisible(int selector)
Tells if a selector is currently visible or not. The default CoordinateChooser contains three selectors: one for geographic area, one for time range and one for the preferred resolution.

Parameters:
selector - One of the following constants: GEOGRAPHIC_AREA, TIME_RANGE or RESOLUTION.
Returns:
true if the specified selector is visible, or false otherwise.
Throws:
IllegalArgumentException - if selector is not legal.

setSelectorVisible

public void setSelectorVisible(int selectors,
                               boolean visible)
Sets the visible state of one or many selectors. All selectors are visible by default.

Parameters:
selectors - Any bitwise combinations of GEOGRAPHIC_AREA, TIME_RANGE and/or RESOLUTION.
visible - true to show the selectors, or false to hide them.
Throws:
IllegalArgumentException - if selectors contains illegal bits.

getGeographicArea

public Rectangle2D getGeographicArea()
Gets the geographic area, in latitude and longitude degrees.

Returns:
The current geographic area of interest.

setGeographicArea

public void setGeographicArea(Rectangle2D area)
Sets the geographic area, in latitude and longitude degrees.

Parameters:
area - The new geographic area of interest.

getPreferredResolution

public Dimension2D getPreferredResolution()
Returns the preferred resolution. A null value means that the best available resolution should be used.

Returns:
The current preferred resolution, or null for the best available one.

setPreferredResolution

public void setPreferredResolution(Dimension2D resolution)
Sets the preferred resolution. A null value means that the best available resolution should be used.

Parameters:
resolution - The new preferred resolution, or null for the best available one.

getTimeZone

public TimeZone getTimeZone()
Returns the time zone used for displaying dates.

Returns:
The current timezone.

setTimeZone

public void setTimeZone(TimeZone timezone)
Sets the time zone. This method change the control's display. It doesn't change the date values, i.e. it has no effect on previous or future call to setTimeRange(java.util.Date, java.util.Date).

Parameters:
timezone - The new timezone.

getStartTime

public Date getStartTime()
Returns the start time, or null if there is none.

Returns:
The start time, or null if none.

getEndTime

public Date getEndTime()
Returns the end time, or null if there is none.

Returns:
The end time, or null if none.

setTimeRange

public void setTimeRange(Date startTime,
                         Date endTime)
Sets the time range.

Parameters:
startTime - The start time.
endTime - The end time.
See Also:
getStartTime(), getEndTime()

getAccessory

public JComponent getAccessory()
Returns the accessory component.

Returns:
The accessory component, or null if there is none.

setAccessory

public void setAccessory(JComponent accessory)
Sets the accessory component. An accessory is often used to show available data. However, it can be used for anything that the programmer wishes, such as extra custom coordinate chooser controls.

Note: If there was a previous accessory, you should unregister any listeners that the accessory might have registered with the coordinate chooser.

Parameters:
accessory - The accessory component, or null to remove any previous accessory.

commitEdit

public void commitEdit()
                throws ParseException
Forces the current value to be taken from the editable fields and set them as the current values. If this operation fails for at least one field, this method will set the focus on the offending field before to throw the exception.

This method is typically invoked after Dialog.showDialog(Component, String) returned true and before to read the values from the dialog widget.

Specified by:
commitEdit in interface Dialog
Throws:
ParseException - If at least one values couldn't be commited.
See Also:
JFormattedTextField.commitEdit(), JSpinner.commitEdit()

addChangeListener

public void addChangeListener(int selectors,
                              ChangeListener listener)
Adds a change listener to the listener list. This change listener will be notify when a value changed. The change may be in a geographic coordinate field, a date field, a resolution field, etc. The watched values depend on the selectors arguments: GEOGRAPHIC_AREA will watches for the bounding box (East, West, North and South value); TIME_RANGE watches for start time and end time; RESOLUTION watches for the resolution along East-West and North-South axis. Bitwise combinations are allowed. For example, GEOGRAPHIC_AREA | TIME_RANGE will register a listener for both geographic area and time range.

The source of ChangeEvents delivered to ChangeListeners will be in most case the SpinnerModel for the edited field.

Parameters:
selectors - Any bitwise combinations of GEOGRAPHIC_AREA, TIME_RANGE and/or RESOLUTION.
listener - The listener to add to the specified selectors.
Throws:
IllegalArgumentException - if selectors contains illegal bits.

removeChangeListener

public void removeChangeListener(int selectors,
                                 ChangeListener listener)
Removes a change listener from the listener list.

Parameters:
selectors - Any bitwise combinations of GEOGRAPHIC_AREA, TIME_RANGE and/or RESOLUTION.
listener - The listener to remove from the specified selectors.
Throws:
IllegalArgumentException - if selectors contains illegal bits.

showDialog

public boolean showDialog(Component owner)
Shows a dialog box requesting input from the user. The dialog box will be parented to owner. If owner is contained into a JDesktopPane, the dialog box will appears as an internal frame.

This method can be invoked from any thread (may or may not be the Swing thread).

Parameters:
owner - The parent component for the dialog box, or null if there is no parent.
Returns:
true if user pressed the "Ok" button, or false otherwise (e.g. pressing "Cancel" or closing the dialog box from the title bar).

showDialog

public boolean showDialog(Component owner,
                          String title)
Shows a dialog box requesting input from the user. The dialog box will be parented to owner. If owner is contained into a JDesktopPane, the dialog box will appears as an internal frame.

Multi-threading
Geotk implementations allow this method to be invoked from any thread. If the caller thread is not the Swing thread, then the execution of this method will be registered in the AWT Event Queue and the caller thread will block until completion.

Specified by:
showDialog in interface Dialog
Parameters:
owner - The parent component for the dialog box, or null if there is no parent.
title - The dialog box title.
Returns:
true if user pressed the "Ok" button, or false otherwise (e.g. pressing "Cancel" or closing the dialog box from the title bar).


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.