Package org.jdesktop.swingx.hyperlink
Class HyperlinkAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- org.jdesktop.swingx.action.AbstractActionExt
-
- org.jdesktop.swingx.hyperlink.AbstractHyperlinkAction<java.net.URI>
-
- org.jdesktop.swingx.hyperlink.HyperlinkAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.ItemListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
public class HyperlinkAction extends AbstractHyperlinkAction<java.net.URI>
A implementation wrappingDesktop
actions BROWSE and MAIL, that is URI-related.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
HyperlinkAction.BrowseVisitor
private class
HyperlinkAction.MailVisitor
private class
HyperlinkAction.URIVisitor
Thin wrapper around Desktop functionality to allow uniform handling of different actions in HyperlinkAction.
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Desktop.Action
desktopAction
private static java.util.logging.Logger
LOG
private HyperlinkAction.URIVisitor
visitor
-
Fields inherited from class org.jdesktop.swingx.hyperlink.AbstractHyperlinkAction
target, VISITED_KEY
-
Fields inherited from class org.jdesktop.swingx.action.AbstractActionExt
GROUP, IS_STATE, LARGE_ICON
-
-
Constructor Summary
Constructors Constructor Description HyperlinkAction()
Instantiates a HyperlinkAction with action type BROWSE.HyperlinkAction(java.awt.Desktop.Action desktopAction)
Instantiates a HyperlinkAction with the given action type.HyperlinkAction(java.net.URI uri, java.awt.Desktop.Action desktopAction)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
static HyperlinkAction
createHyperlinkAction(java.net.URI uri)
Factory method to create and return a HyperlinkAction for the given uri.static HyperlinkAction
createHyperlinkAction(java.net.URI uri, java.awt.Desktop.Action type)
Creates and returns a HyperlinkAction with the given target and action type.private HyperlinkAction.URIVisitor
createURIVisitor()
java.awt.Desktop.Action
getDesktopAction()
private HyperlinkAction.URIVisitor
getURIVisitor()
protected void
installTarget()
hook for subclasses to update internal state after a new target has been set.private static boolean
isMailURI(java.net.URI uri)
private void
updateEnabled()
-
Methods inherited from class org.jdesktop.swingx.hyperlink.AbstractHyperlinkAction
getTarget, isVisited, itemStateChanged, setStateAction, setTarget, setVisited, uninstallTarget
-
Methods inherited from class org.jdesktop.swingx.action.AbstractActionExt
dispose, getAccelerator, getActionCommand, getGroup, getLargeIcon, getLongDescription, getMnemonic, getName, getShortDescription, getSmallIcon, isSelected, isStateAction, setAccelerator, setActionCommand, setGroup, setLargeIcon, setLongDescription, setMnemonic, setMnemonic, setName, setSelected, setShortDescription, setSmallIcon, setStateAction, toString
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
-
desktopAction
private java.awt.Desktop.Action desktopAction
-
visitor
private HyperlinkAction.URIVisitor visitor
-
-
Constructor Detail
-
HyperlinkAction
public HyperlinkAction()
Instantiates a HyperlinkAction with action type BROWSE.- Throws:
java.awt.HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
java.lang.UnsupportedOperationException
- if the current platform doesn't support Desktopjava.lang.IllegalArgumentException
- if unsupported action type
-
HyperlinkAction
public HyperlinkAction(java.awt.Desktop.Action desktopAction)
Instantiates a HyperlinkAction with the given action type.- Parameters:
desktopAction
- the type of desktop action this class should perform, must be BROWSE or MAIL- Throws:
java.awt.HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
java.lang.UnsupportedOperationException
- if the current platform doesn't support Desktopjava.lang.IllegalArgumentException
- if unsupported action type
-
HyperlinkAction
public HyperlinkAction(java.net.URI uri, java.awt.Desktop.Action desktopAction)
- Parameters:
uri
- the target uri, maybe null.desktopAction
- the type of desktop action this class should perform, must be BROWSE or MAIL- Throws:
java.awt.HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
java.lang.UnsupportedOperationException
- if the current platform doesn't support Desktopjava.lang.IllegalArgumentException
- if unsupported action type
-
-
Method Detail
-
createHyperlinkAction
public static HyperlinkAction createHyperlinkAction(java.net.URI uri)
Factory method to create and return a HyperlinkAction for the given uri. Tries to guess the appropriate type from the uri. If uri is not null and has a scheme of mailto, create one of type Mail. In all other cases, creates one for BROWSE.- Parameters:
uri
- to uri to create a HyperlinkAction for, maybe null.- Returns:
- a HyperlinkAction for the given URI.
- Throws:
java.awt.HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
java.lang.UnsupportedOperationException
- if the current platform doesn't support Desktop
-
createHyperlinkAction
public static HyperlinkAction createHyperlinkAction(java.net.URI uri, java.awt.Desktop.Action type)
Creates and returns a HyperlinkAction with the given target and action type.- Parameters:
uri
- the target uri, maybe null.desktopAction
- the type of desktop action this class should perform, must be BROWSE or MAIL- Returns:
- a HyperlinkAction
- Throws:
java.awt.HeadlessException
- ifGraphicsEnvironment.isHeadless()
returnstrue
java.lang.UnsupportedOperationException
- if the current platform doesn't support Desktopjava.lang.IllegalArgumentException
- if unsupported action type
-
isMailURI
private static boolean isMailURI(java.net.URI uri)
- Parameters:
uri
-- Returns:
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Implemented to perform the appropriate Desktop action if supported on the current target. Sets the visited property to true if the desktop action doesn't throw an exception or to false if it did. Does nothing if the action isn't supported.
-
getDesktopAction
public java.awt.Desktop.Action getDesktopAction()
- Returns:
-
installTarget
protected void installTarget()
Description copied from class:AbstractHyperlinkAction
hook for subclasses to update internal state after a new target has been set.Subclasses are free to decide the details. Here:
- the text property is set to target.toString or empty String if the target is null
- visited is set to false.
- Overrides:
installTarget
in classAbstractHyperlinkAction<java.net.URI>
-
updateEnabled
private void updateEnabled()
-
getURIVisitor
private HyperlinkAction.URIVisitor getURIVisitor()
- Returns:
-
createURIVisitor
private HyperlinkAction.URIVisitor createURIVisitor()
- Returns:
-
-