Creating a GUI to define links

With methods to apply links as explained in previous chapter, a new dialog is required to allow for convenient link creation and manipulation. New class LinkDialog is the central place to allow for link entries of all kind.

Class LinkDialog

Class LinkDialog has a collection of components for all relevant link attributes. It can be used to set a new link or to view and manipulate an existing link.

As several dialogs of application SimplyHTML have been explained in earlier stages already, we only look at some additional 'specialties' of class LinkDialog here. LinkDialog establishes a central ActionListener to handle changes to any of its components. If the link type combo box changes for instance, the buttons to select a local file or link anchor are enabled or disabled accordingly.

Switching of relative and absolute paths

If the link type is set to 'relative' or to 'local', the link address is switched between absolute ( file:/C:/Data/aFile.htm) or relative ( ../../aDir/aFile.htm) notation with the help of methods resolveRelativePath and getRelativePath of class Util.

Selection of local files and link anchors

A link type of 'local ' allows to use a JFileChooser dialog to browse for a local file. Link types ' local' and 'relative ' as well allow to define a link anchor with respective browse button.

Link address and link anchor can be typed directly into respective text fields too.

Image selection

By selecting 'show link as image', the dialog switches to display an image panel with a browse button to set an image from the repository. In the LinkDialog any selected image is only shown with the width and height selected in the ImageDialog. These settings can only be changed by using the ImageDialog through respective browse button.

Returning link settings

Once all link attributes are set with class LinkDialog, methods getLinkText, getHref, getStyleName, getLinkImage and getLinkImageSize can be used to find out the user settings.