net.lucidviews.util.gui.swing
Class JWebAddress

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by net.lucidviews.util.gui.swing.JWebAddress
All Implemented Interfaces:
ActionListener, FocusListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class JWebAddress
extends JPanel
implements ActionListener, FocusListener, KeyListener

A label and text-field composite for entering a web address.

Since:
1.3
Version:
$Revision: 1.1.2.1 $
Author:
Stephen Battey
See Also:
Serialized Form

Nested Class Summary
static class JWebAddress.WebAddressActionEvent
          An ActionEvent specific to the JWebAddress component.
static class JWebAddress.WebAddressDropTarget
          A DropTarget that accepts addresses dropped onto the input field.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  URL currentAddress
          The last confirmed address.
private static String DEFAULT_LABEL
          The default label, used when none is specified.
private static Border DEFAULT_LABEL_BORDER
          The default border for the label.
protected  JTextField inputField
          The input field into which the user types the web address.
protected  JLabel label
          The label that prompts the user to enter a web address.
protected  Collection<ActionListener> listeners
          Registered listeners, waiting for notification of a change of address.
private static long serialVersionUID
          Serialisation version id.
 
Fields inherited from class javax.swing.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 java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JWebAddress(String toolTipText)
          Create a component for the input of a web address.
JWebAddress(String toolTipText, Border labelBorder)
          Create a component for the input of a web address.
JWebAddress(String toolTipText, String label)
          Create a component for the input of a web address.
JWebAddress(String toolTipText, String label, Border labelBorder)
          Create a component for the input of a web address.
 
Method Summary
 void actionPerformed(ActionEvent e)
          
 void addActionListener(ActionListener listener)
          Register a listener that wants to be notified of interactions with the web address.
 void focusGained(FocusEvent e)
          
 void focusLost(FocusEvent e)
          
 URL getAddress()
          Get the current address.
 void go()
          Go to the location that has been entered into this web address component.
 void go(int modifiers)
          Go to the location that has been entered into this web address component.
 void keyPressed(KeyEvent e)
          
 void keyReleased(KeyEvent e)
          
 void keyTyped(KeyEvent e)
          
 void removeActionListener(ActionListener listener)
          Un-register a listener that does not want to be notified of interactions with the web address.
 void resetAddress()
          Reset the text displayed to the last confirmed URL (confirmed by a call to setAddress.
 void resetAddress(URL address)
          Confirm the URL being used.
 void setAddress(String address)
          Set the web address.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 
Methods inherited from class java.awt.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 java.awt.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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serialisation version id.

See Also:
Constant Field Values

DEFAULT_LABEL

private static final String DEFAULT_LABEL
The default label, used when none is specified.

See Also:
Constant Field Values

DEFAULT_LABEL_BORDER

private static final Border DEFAULT_LABEL_BORDER
The default border for the label.


listeners

protected Collection<ActionListener> listeners
Registered listeners, waiting for notification of a change of address.


currentAddress

protected URL currentAddress
The last confirmed address. This may not match the address currently typed into the input box.

See Also:
inputField

label

protected JLabel label
The label that prompts the user to enter a web address.


inputField

protected JTextField inputField
The input field into which the user types the web address. NB: the text in the input field will only match the current address after the user confirms the address (by pressing return) and the parent component confirms the address exists and is now being used.

See Also:
currentAddress
Constructor Detail

JWebAddress

public JWebAddress(String toolTipText)
Create a component for the input of a web address.
The component will display the specified text as a tool tip. The default border and label will be used.

Parameters:
toolTipText - text to display when user hovers their pointer over the web address

JWebAddress

public JWebAddress(String toolTipText,
                   String label)
Create a component for the input of a web address.
The component will display the specified tool tip and label. The default border will be used.

Parameters:
toolTipText - text to display when user hovers their pointer over the web address
label - text to display beside the input box, it should describe what to enter into the address bar

JWebAddress

public JWebAddress(String toolTipText,
                   Border labelBorder)
Create a component for the input of a web address.
The component will display the specified tool tip. The default label will be used. The default border will be used around the label.

Parameters:
toolTipText - text to display when user hovers their pointer over the web address
labelBorder - border applied around the label

JWebAddress

public JWebAddress(String toolTipText,
                   String label,
                   Border labelBorder)
Create a component for the input of a web address.
The component will display the specified tool tip and label.

Parameters:
toolTipText - text to display when user hovers their pointer over the web address
label - text to display beside the input box, it should describe what to enter into the address bar
labelBorder - border applied around the label
Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Register a listener that wants to be notified of interactions with the web address.

Parameters:
listener - object that is to receive notifications

removeActionListener

public void removeActionListener(ActionListener listener)
Un-register a listener that does not want to be notified of interactions with the web address.

Parameters:
listener - object that is no longer to receive notifications

getAddress

public URL getAddress()
Get the current address.
NB: this is the last verified address, not the address being entered by the user into the input field.

Returns:
the most address confirmed as being used

resetAddress

public void resetAddress()
Reset the text displayed to the last confirmed URL (confirmed by a call to setAddress.

Call this method to reset user edits.


resetAddress

public void resetAddress(URL address)
Confirm the URL being used.
Call this method when handling a WebAddressActionEvent to confirm that the URL entered by the user is valid and is being used.

Parameters:
address - the URL of the file that is now being used

setAddress

public void setAddress(String address)
Set the web address.
NB: this only changes the address in the address bar it does not submit the address. To submit the address you will need to call the go method.

Parameters:
address - the web address
See Also:
go()

go

public void go()
Go to the location that has been entered into this web address component.


go

public void go(int modifiers)
Go to the location that has been entered into this web address component.

Parameters:
modifiers - the modifier keys (Alt, Ctrl, etc) that were pressed when the command to 'go' was received

actionPerformed

public void actionPerformed(ActionEvent e)

Specified by:
actionPerformed in interface ActionListener

focusGained

public void focusGained(FocusEvent e)

Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)

Specified by:
focusLost in interface FocusListener

keyTyped

public void keyTyped(KeyEvent e)

Specified by:
keyTyped in interface KeyListener

keyPressed

public void keyPressed(KeyEvent e)

Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)

Specified by:
keyReleased in interface KeyListener