uk.ac.leeds.ccg.awt
Class HyperComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--uk.ac.leeds.ccg.awt.HyperComponent
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.io.Serializable

public class HyperComponent
extends java.awt.Container
implements java.awt.event.MouseListener

This class supplies a wrapper that adds hyperlink functionality to a Component.

The class provides a Container including the Component, and implements the css 'a:hover' functionality as well as pushing out the url page or program when the component is clicked on.

Example use: public class Test extends Applet {
 
public void start () {
Label label = new Label ("Link");
label.setSize(50,100);
URL url = null;
try {
url = new URL("http://www.geog.leeds.ac.uk/");
} catch (MalformedURLException murle) {
murle.printStackTrace();
}
HyperComponent hc = new HyperComponent(label, url, new Color(255,0,255),this);
hc.setSize(label.getSize().width, label.getSize().height);
hc.setVisible(true);
add(hc);
}}

The original aim of the class was to open up javascript popup windows for a help system, but currently there don't seem to be any virtual machines that recognise 'javascript:' as a URL protocol. However, there is a neat workround suggested by James Macgill. Make a webpage that opens the popup window. Make a zero size frame in your website and call the webpage into the frame as a target using the HyperComponent.

Caveat: The layout of this component is a bit flaky in GridBags for some reason. If you find it's blank, try setting the added Component's size small - it may appear from behind the next cell down. For some reason it's skipping cells. If this happens, make the HyperComponent (which will associate the Component and the MouseListerer bits of the HyperComponent, and then add the original Component to the GridBag rather than the HyperComponent - it'll still work.

To do:

Version:
1.1
Author:
Andrew Evans
See Also:
Serialized Form

Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
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
HyperComponent(java.awt.Component hyperComponent, java.net.URL url, java.applet.Applet applet)
          Constructor that takes in a Component, the hypertext URL, and a reference to the Applet.
HyperComponent(java.awt.Component hyperComponent, java.net.URL url, java.awt.Color highlight, java.applet.Applet applet)
          Constructor that takes in a Component, the hypertext URL, a color for highlighting, and a reference to the Applet.
HyperComponent(java.awt.Component hyperComponent, java.net.URL url, java.lang.String target, java.applet.Applet applet)
          Constructor that takes in a Component, the hypertext URL, a frame/window target, and a reference to the Applet.
HyperComponent(java.awt.Component component, java.net.URL url, java.lang.String target, java.awt.Color highlight, java.applet.Applet applet)
          Constructor that takes in a Component, the hypertext URL, a frame/window target, a color for highlighting, and a reference to the Applet.
 
Method Summary
 void mouseClicked(java.awt.event.MouseEvent e)
          Outputs the result of the URL to the user in a target frame/window if supplied, or the applet window if not.
 void mouseEntered(java.awt.event.MouseEvent e)
          Highlights the component's foreground if a highlight color given.
 void mouseExited(java.awt.event.MouseEvent e)
          Un-highlights the component's foreground if a highlight color was given.
 void mousePressed(java.awt.event.MouseEvent e)
          Does nothing.
 void mouseReleased(java.awt.event.MouseEvent e)
          Does nothing.
 void paint(java.awt.Graphics g)
           
 void setColor(java.awt.Color highlight)
          Sets the Color of the a:hover highlighting.
 void setUnderline(boolean underline)
           
 void setUrl(java.net.URL url)
          Sets the URL to send the user to.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleContext, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HyperComponent

public HyperComponent(java.awt.Component component,
                      java.net.URL url,
                      java.lang.String target,
                      java.awt.Color highlight,
                      java.applet.Applet applet)
Constructor that takes in a Component, the hypertext URL, a frame/window target, a color for highlighting, and a reference to the Applet. Note that setting the URL to null switches off the hyperlinking behaviour.

HyperComponent

public HyperComponent(java.awt.Component hyperComponent,
                      java.net.URL url,
                      java.awt.Color highlight,
                      java.applet.Applet applet)
Constructor that takes in a Component, the hypertext URL, a color for highlighting, and a reference to the Applet.

The page is output into the Applet window/frame.


HyperComponent

public HyperComponent(java.awt.Component hyperComponent,
                      java.net.URL url,
                      java.lang.String target,
                      java.applet.Applet applet)
Constructor that takes in a Component, the hypertext URL, a frame/window target, and a reference to the Applet. There is no a:hover highlighting.

HyperComponent

public HyperComponent(java.awt.Component hyperComponent,
                      java.net.URL url,
                      java.applet.Applet applet)
Constructor that takes in a Component, the hypertext URL, and a reference to the Applet.

The page is output into the Applet window/frame.T here is no a:hover highlighting.

Method Detail

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Outputs the result of the URL to the user in a target frame/window if supplied, or the applet window if not.
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Highlights the component's foreground if a highlight color given.
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Un-highlights the component's foreground if a highlight color was given.
Specified by:
mouseExited in interface java.awt.event.MouseListener

setUrl

public void setUrl(java.net.URL url)
Sets the URL to send the user to.

setColor

public void setColor(java.awt.Color highlight)
Sets the Color of the a:hover highlighting.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Does nothing.
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Does nothing.
Specified by:
mouseReleased in interface java.awt.event.MouseListener

setUnderline

public void setUnderline(boolean underline)

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container