Multivalent API

multivalent.std.span
Class HyperlinkSpan

java.lang.Object
  extended by multivalent.VObject
      extended by multivalent.Behavior
          extended by multivalent.Span
              extended by multivalent.std.span.HyperlinkSpan
All Implemented Interfaces:
ContextListener, EventListener, java.util.EventListener

public class HyperlinkSpan
extends Span

This is the familiar point-to-point link. Note that it's not built in -- you can add new link types easily.

Elaborately commented to serve as a simple example of translating Multivalent protocols into Java methods; also see ClipProvenance.

Version:
$Revision: 1.9 $ $Date: 2003/03/05 08:42:07 $
See Also:
ActionSpan, ScriptSpan

Field Summary
static java.lang.String ATTR_URI
           
static java.lang.String MSG_COPY_LINK
          Copy link URI to clipboard.
static byte STATE_ACTIVE
          Link state.
static byte STATE_HOVER
          Link state.
static byte STATE_LINK
          Link state.
static byte STATE_VISITED
          Link state.
protected  java.lang.Object target_
          Target of link can be given as a String or URL.
 
Fields inherited from class multivalent.Span
GI_END, GI_START, MSG_DELETE, MSG_EDIT, MSG_MORPH, MSG_UNATTACHED, pend, pstart
 
Fields inherited from class multivalent.Behavior
ATTR_BEHAVIOR, name_
 
Fields inherited from class multivalent.VObject
attr_
 
Fields inherited from interface multivalent.ContextListener
LITTLE, LOT, PRIORITY_LENS, PRIORITY_MAX, PRIORITY_MIN, PRIORITY_SELECTION, PRIORITY_SPAN, PRIORITY_STRUCT, SOME
 
Constructor Summary
HyperlinkSpan()
           
 
Method Summary
 boolean appearance(Context cx, boolean all)
          Spans are ContextListener's, which are behaviors that compose together to determine the Context display properties at every point in the document.
 void event(java.awt.AWTEvent e)
          Once we set the grab, subsequent events go directly to here, not to eventBefore/eventAfter.
 boolean eventAfter(java.awt.AWTEvent e, java.awt.Point rel, Node n)
          On a mouse button down, directly receive all furture low-level events by setting a grab in Browser, until a mouse button up.
 int getPriority()
          Prefer for style sheet to set appearance.
 byte getState()
          Run-of-the-mill field getter.
 java.lang.Object getTarget()
          Run-of-the-mill field getter.
 java.net.URI getURI()
          Run-of-the-mill field getter.
 void go()
          Override this for special action when hyperlink is clicked.
 void restore(ESISNode n, java.util.Map<java.lang.String,java.lang.Object> attr, Layer layer)
          Restore almost always invokes its superclass, which when it chains up to Behavior sets the behavior's attributes and adds it to the passed layer.
 ESISNode save()
          Stuff instance state into attributes; if save buffer not null, write out corresponding XML.
 boolean semanticEventAfter(SemanticEvent se, java.lang.String msg)
          Catch "copyLink" sent in semanticEventBefore.
 boolean semanticEventBefore(SemanticEvent se, java.lang.String msg)
          Add to the DOCPOPUP menu--the menu that pops up when the alternative mouse button is clicked over some part of the document (as opposed to the menubar) and the click is not short-circuited out by some behavior.
 void setMessage(java.lang.String msg)
          Message to show when mouse hovers over link.
 void setSeen(boolean seen)
          Run-of-the-mill field setter.
protected  void setState(byte state)
          Run-of-the-mill field setter.
 void setTarget(java.lang.Object o)
          Sets target that isn't String or URI or URL.
 void setURI(java.lang.String txt)
          Computes full, canonical URL from a relative specification.
 java.lang.String toString()
          Subclasses should extend to check any attributes they add.
 
Methods inherited from class multivalent.Span
buildAfter, checkRep, close, closeAll, contains, contains, destroy, getEnd, getStart, isSet, markDirty, move, move, move, moveq, moveq, moveq, moveqSwap, open, repaint, repaint, stretch
 
Methods inherited from class multivalent.Behavior
buildBefore, clipboardAfter, clipboardBefore, createUI, eventBefore, formatAfter, formatBefore, getBrowser, getDocument, getInstance, getInstance, getLayer, getLogger, getName, getPreference, getRoot, isEditable, paintAfter, paintBefore, putPreference, redo, restoreChildren, setName, undo
 
Methods inherited from class multivalent.VObject
attrEntrySetIterator, attrKeysIterator, clearAttributes, getAttr, getAttr, getAttributes, getGlobal, getValue, hasAttributes, putAttr, removeAttr, setAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTR_URI

public static final java.lang.String ATTR_URI
See Also:
Constant Field Values

STATE_LINK

public static final byte STATE_LINK
Link state.

See Also:
Constant Field Values

STATE_VISITED

public static final byte STATE_VISITED
Link state.

See Also:
Constant Field Values

STATE_HOVER

public static final byte STATE_HOVER
Link state.

See Also:
Constant Field Values

STATE_ACTIVE

public static final byte STATE_ACTIVE
Link state.

See Also:
Constant Field Values

MSG_COPY_LINK

public static final java.lang.String MSG_COPY_LINK
Copy link URI to clipboard.

"copyLink".

See Also:
Constant Field Values

target_

protected java.lang.Object target_
Target of link can be given as a String or URL.

Constructor Detail

HyperlinkSpan

public HyperlinkSpan()
Method Detail

setSeen

public void setSeen(boolean seen)
Run-of-the-mill field setter.


setState

protected void setState(byte state)
Run-of-the-mill field setter. Checks seen_ flag to see if link seen before.


getState

public byte getState()
Run-of-the-mill field getter.


getTarget

public java.lang.Object getTarget()
Run-of-the-mill field getter.


getURI

public java.net.URI getURI()
Run-of-the-mill field getter. Same as getTarget, but more convenient if target type known to be URL.


setTarget

public void setTarget(java.lang.Object o)
Sets target that isn't String or URI or URL.


setMessage

public void setMessage(java.lang.String msg)
Message to show when mouse hovers over link.


setURI

public void setURI(java.lang.String txt)
Computes full, canonical URL from a relative specification. The canonical URL is used in the table of links already seen.


appearance

public boolean appearance(Context cx,
                          boolean all)
Spans are ContextListener's, which are behaviors that compose together to determine the Context display properties at every point in the document. For instance, a document will usually determine the font family, size, style, and foreground and background colors, among many other properties, of a piece of text with a combination of ContextListeners reporesenting the influence of style sheet settings, built-in span settings, and perhaps lenses. Here, the generic hyperlink hardcodes the action of coloring the text and gives it an underline, choosing either blue or red. The HTML media adaptor overrides this method to have no action, as the hyperlink appearance is dictated entirely by style sheets, either one linked to the particular web page or failing that the default HTML style sheet.

Specified by:
appearance in interface ContextListener
Overrides:
appearance in class Span
all - all attributes or exclude those that are not inherited

getPriority

public int getPriority()
Prefer for style sheet to set appearance.

Specified by:
getPriority in interface ContextListener
Overrides:
getPriority in class Span

restore

public void restore(ESISNode n,
                    java.util.Map<java.lang.String,java.lang.Object> attr,
                    Layer layer)
Restore almost always invokes its superclass, which when it chains up to Behavior sets the behavior's attributes and adds it to the passed layer. Many behaviors also set default parameters and set fields from attributes in the attribute hash table that all behaviors have. See Behavior's superclass, VObject, to examine the various attribute accessor methods.

Overrides:
restore in class Span
See Also:
RobustLocation

save

public ESISNode save()
Description copied from class: Span
Stuff instance state into attributes; if save buffer not null, write out corresponding XML. Subclass should override if have interesting content (can stuff content into attr then super.save()). If span is not attached to tree at save time, its old attachment points are retained. This way, spans that can't be attached presently can be tried again without degradation.

Overrides:
save in class Span

eventAfter

public boolean eventAfter(java.awt.AWTEvent e,
                          java.awt.Point rel,
                          Node n)
On a mouse button down, directly receive all furture low-level events by setting a grab in Browser, until a mouse button up. Also, take the synthesized events (that is, generated by a multivalent.* class as opposed to a java.* class) corresponding to entering and exiting the span, at which time change the cursor and perhaps the colors to indicate that the link is active. As a Span, the hyperlink receives low-level events in the region of the document it spans without additional registering. This is eventAfter rather than eventBefore because the rule of thumb is to build in before so it's available to other behaviors, and to take action in after if some other behavior hasn't short-circuited you.

Overrides:
eventAfter in class Behavior

event

public void event(java.awt.AWTEvent e)
Once we set the grab, subsequent events go directly to here, not to eventBefore/eventAfter.

Specified by:
event in interface EventListener
Overrides:
event in class Span

go

public void go()
Override this for special action when hyperlink is clicked. Defaults to sending Document.MSG_OPEN semantic event to target_. If target is a SemanticEvent, then it is fired.


semanticEventBefore

public boolean semanticEventBefore(SemanticEvent se,
                                   java.lang.String msg)
Add to the DOCPOPUP menu--the menu that pops up when the alternative mouse button is clicked over some part of the document (as opposed to the menubar) and the click is not short-circuited out by some behavior. Similarly to ClipProvenance, add Span.MSG_EDIT if the span is in an editable layer (e.g., if link comes from the HTML sent by a random server, it isn't editable, whereas link annotations you added are), "copyLink", "open in new window", and "open in shared window".

Overrides:
semanticEventBefore in class Span

semanticEventAfter

public boolean semanticEventAfter(SemanticEvent se,
                                  java.lang.String msg)
Catch "copyLink" sent in semanticEventBefore. The pair of Document.MSG_OPEN are handled by another behavior. Many subclasses have various parameters or attributes, such as URL here or annotation text elsewhere, and the Span class supports editing by catching Span.MSG_EDIT and throwing up an associated HTML document with a FORM in a note window. When that window is closed, it sends SystemEvents.MSG_FORM_DATA. semantic event with the name-value pairs of the form as a parameter.

Overrides:
semanticEventAfter in class Span

toString

public java.lang.String toString()
Description copied from class: Span
Subclasses should extend to check any attributes they add.

Overrides:
toString in class Span

Multivalent API