wt.clients.dndMicroApplet
Class DnDMicroApplet

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byjava.applet.Applet
                  extended bywt.clients.dndMicroApplet.DnDMicroApplet
All Implemented Interfaces:
Accessible, DnDMicroAppletConstants, ImageObserver, MenuContainer, Serializable

public final class DnDMicroApplet
extends Applet
implements DnDMicroAppletConstants

Simple applet capable of drawing icons and serving as a drag source of file and string data and as a drop target of file and string data. It also can respond to double-clicks. See DnDMicroAppletConstants and HTTPParameterConstants for more information.

Supported API: true

Extendable: false

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.applet.Applet
Applet.AccessibleApplet
 
Nested classes inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  String baseURLParamString
          String rep of base url used to resolve relative URLs.
private  ImageIcon currentImageIcon
          Current main icon to be displayed by the applet.
private  ImageIcon dragOverIcon
          The "drag-over" icon to be drawn when the applet is being dragged over.
private  boolean encodingNeeded
          Whether JSOBject.call() args need special encoding (for Netscape 4.7x browsers)
private  ImageIcon glyphIcon
          The glyph icon to be drawn over the "main" icons.
private  String idString
          Identification string corresponding to ID_PARAM parameter value.
private  Component mainComponent
          This component is target of all drawing, events, etc, etc.
private  ImageIcon normalIcon
          The "normal" main icon, i.e.
private  boolean runningInMSIE
          Whether it appears that we're running inside Microsoft Internet Explorer
private  URL urlDragSource
          URL which provides data for drag source file list generation
private  boolean useJSObjectCallForVoidCalls
          Whether JSObject.call() should be used to call JavaScript functions in cases where the return value is not of interest.
 
Fields inherited from class java.applet.Applet
 
Fields inherited from class java.awt.Panel
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface wt.clients.dndMicroApplet.DnDMicroAppletConstants
BG_COLOR_PARAM, DOUBLE_CLICK_JS_PARAM, DOUBLE_CLICK_URL_PARAM, DOWNLOAD_FROM_DRAG_URL_PARAM, DRAG_DATA_FILE_NAME, DRAG_DATA_GET_STRING_JS_PARAM, DRAG_DATA_HAS_STRING_JS_PARAM, DRAG_DATA_STRING_PARAM, DRAG_DATA_URL_PARAM, DRAG_ICON_PARAM, DROP_POST_URL_PARAM, ENCODING_NEEDED, FILE_DROP_ACCEPT_DIRS_PARAM, FILE_DROP_JS_PARAM, FILE_DROP_URL_PARAM, ICON_GLYPH_PARAM, ICON_PARAM, ID_PARAM, JS_FILE_DELIM_PARAM, LOCALE_PARAM, RETURN_URL_PARAM, STRING_DROP_JS_PARAM, STRING_DROP_URL_PARAM, TOOL_TIP_TEXT_PARAM, URL_BASE_PARAM, USE_JSOBJECT_CALL_FOR_VOID_CALLS_PARAM
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DnDMicroApplet()
           
 
Method Summary
(package private)  Object callJavaScriptFunction(String functionName, Object[] args, boolean treatAsVoid)
          Call a JavaScript function of the given name in the current page with the given args.
private  Object callJavaScriptFunctionViaJSObject(String functionName, Object[] args)
          This routine calls the specified JavaScript function in the current page via JSObject and returns the JavaScript function's return value.
private  void callJavaScriptFunctionViaShowDoc(String functionName, Object[] args)
          Call JavaScript function in the current page via AppletContext.showDocument().
(package private)  void enterDragOverState()
          If the current icon is not already set to the drag-over icon, make it so and issue a repaint request.
private static String escapeJavaScriptStringArgForJSUrlCall(String str)
          Escape the incoming string for use as an argument to a JavaScript function call via a 'javascript:funcName(...)' URL.
(package private)  void exitDragOverState()
          If the current icon is not already set to the "normal" icon, make it so and issue a repaint request.
private  String getBaseURLString()
          Returns the 'baseURLParamString' data member computed in init().
private  boolean getBooleanFromParam(String paramName, boolean defaultValue)
          Get a boolean from an applet parameter.
private  URL getCurrentPageURL()
          Try to set get URL for current browser page from (current) window.location.href via JSObject
private  Component getToolTipDelegate(String tooltipText)
          Get tool tip delegate component.
private  URL getURLFromParam(String paramName)
          Get a URL from an applet parameter using getBaseURLString() to resolve relative URLs.
 void init()
          Initializes everything necessary for this applet to draw itself, handle drag-and-drop events, and handle double-clicks -- as specified by the applet parameters.
private  void initGraphicsData()
          Initialize everything necessary to draw the applet from the applet's parameters.
(package private)  boolean isRunningInMSIE()
          Whether the applet is running in Microsoft Internet Explorer.
 void paint(Graphics g)
          Draw icon(s), glyph icon on top.
private  void setupDoubleClick()
          Set up a double-click handler on the applet if and as indicated by the applet parameters.
private  void setupDragSource()
          Set up the applet as a drag source if and as indicated by the applet parameters.
private  void setupDropTarget()
          Set up the applet as a drop target if and as indicated by the applet parameters.
private  void setupLocale()
          Set up locale of component based on LOCALE_PARAM.
(package private)  void showDocumentInCurrentWindow(URL url)
          Centralized handling for calling AppletContext.showDocument( URL url ), which, by nature, replaces the current page with the response from 'url'.
private static String unicodeToAscii(String in_str)
          Returns a string in the form of '\\uxxxx.' Same as wt.httpgw.EncodingConverter.unicodeToAscii method Written by Jason Drake
(package private)  boolean willCallJavaScriptViaJSObject(boolean treatAsVoid)
          Determines whether JavaScript function will be call via JSObject (when the result is true) or via showDocument() on a 'javascript:' URL (when the result is false).
 
Methods inherited from class java.applet.Applet
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, 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

mainComponent

private Component mainComponent
This component is target of all drawing, events, etc, etc.


baseURLParamString

private String baseURLParamString
String rep of base url used to resolve relative URLs.


idString

private String idString
Identification string corresponding to ID_PARAM parameter value.


currentImageIcon

private ImageIcon currentImageIcon
Current main icon to be displayed by the applet.


normalIcon

private ImageIcon normalIcon
The "normal" main icon, i.e. for when the applet is not being dragged over.


glyphIcon

private ImageIcon glyphIcon
The glyph icon to be drawn over the "main" icons.


dragOverIcon

private ImageIcon dragOverIcon
The "drag-over" icon to be drawn when the applet is being dragged over.


urlDragSource

private URL urlDragSource
URL which provides data for drag source file list generation


encodingNeeded

private boolean encodingNeeded
Whether JSOBject.call() args need special encoding (for Netscape 4.7x browsers)


useJSObjectCallForVoidCalls

private boolean useJSObjectCallForVoidCalls
Whether JSObject.call() should be used to call JavaScript functions in cases where the return value is not of interest.


runningInMSIE

private boolean runningInMSIE
Whether it appears that we're running inside Microsoft Internet Explorer

Constructor Detail

DnDMicroApplet

public DnDMicroApplet()
Method Detail

init

public void init()
Initializes everything necessary for this applet to draw itself, handle drag-and-drop events, and handle double-clicks -- as specified by the applet parameters.

Supported API: false


paint

public void paint(Graphics g)
Draw icon(s), glyph icon on top.

Supported API: false


enterDragOverState

void enterDragOverState()
If the current icon is not already set to the drag-over icon, make it so and issue a repaint request.


exitDragOverState

void exitDragOverState()
If the current icon is not already set to the "normal" icon, make it so and issue a repaint request.


showDocumentInCurrentWindow

void showDocumentInCurrentWindow(URL url)
Centralized handling for calling AppletContext.showDocument( URL url ), which, by nature, replaces the current page with the response from 'url'. This routine is a place holder for any funny workarounds we might have to do with various browser and/or plug-in combinations (i.e. to ease any maintenance in this area).


callJavaScriptFunction

Object callJavaScriptFunction(String functionName,
                              Object[] args,
                              boolean treatAsVoid)
Call a JavaScript function of the given name in the current page with the given args. If 'treatAsVoid' is true, then this method may use means of calling the specified function which do not provide a return value, otherwise it will assume the return value is important.


willCallJavaScriptViaJSObject

boolean willCallJavaScriptViaJSObject(boolean treatAsVoid)
Determines whether JavaScript function will be call via JSObject (when the result is true) or via showDocument() on a 'javascript:' URL (when the result is false). 'treatAsVoid' should have the same value as has been or will be passed to callJavaScriptFunction().


isRunningInMSIE

boolean isRunningInMSIE()
Whether the applet is running in Microsoft Internet Explorer.


callJavaScriptFunctionViaShowDoc

private void callJavaScriptFunctionViaShowDoc(String functionName,
                                              Object[] args)
Call JavaScript function in the current page via AppletContext.showDocument(). Note this does not allow us to obtain the return value.


escapeJavaScriptStringArgForJSUrlCall

private static String escapeJavaScriptStringArgForJSUrlCall(String str)
Escape the incoming string for use as an argument to a JavaScript function call via a 'javascript:funcName(...)' URL. Note that surrounding quoting is included in this (i.e. the caller should not quote the result).


callJavaScriptFunctionViaJSObject

private Object callJavaScriptFunctionViaJSObject(String functionName,
                                                 Object[] args)
This routine calls the specified JavaScript function in the current page via JSObject and returns the JavaScript function's return value.


initGraphicsData

private void initGraphicsData()
Initialize everything necessary to draw the applet from the applet's parameters.


getToolTipDelegate

private Component getToolTipDelegate(String tooltipText)
Get tool tip delegate component. If called, event listeners should be connected to it rather than to the applet itself as the tool tip delegate component will be on top of the applet.

Done in a separate method in the hope that the JIT, etc, will not fully load DelegateJComponent unless/until this method is called thus eliminating load overhead of DelegateJComponent's JComponent ancestry wherever possible.


setupDropTarget

private void setupDropTarget()
Set up the applet as a drop target if and as indicated by the applet parameters.


setupDragSource

private void setupDragSource()
Set up the applet as a drag source if and as indicated by the applet parameters. [As side-effects, this routine also configures the applet's locale - since the only localization is currently in the drag handling code - and the 'urlDragSource' field for use by setupDoubleClick().]


setupDoubleClick

private void setupDoubleClick()
Set up a double-click handler on the applet if and as indicated by the applet parameters.

Note that if DOUBLE_CLICK_JS_PARAM and DOUBLE_CLICK_URL_PARAM are not set, this routine will use the 'urlDragSource' field as the double click URL as well.


setupLocale

private void setupLocale()
Set up locale of component based on LOCALE_PARAM.


getCurrentPageURL

private URL getCurrentPageURL()
                       throws Exception
Try to set get URL for current browser page from (current) window.location.href via JSObject

Throws:
Exception

getBooleanFromParam

private boolean getBooleanFromParam(String paramName,
                                    boolean defaultValue)
Get a boolean from an applet parameter. If the given parameter does not exist, 'defaultValue' will be returned.


getURLFromParam

private URL getURLFromParam(String paramName)
Get a URL from an applet parameter using getBaseURLString() to resolve relative URLs. If the parameter does not exist or cannot be resolved as a URL, then 'null' is returned rather than throwing an exception.


getBaseURLString

private String getBaseURLString()
Returns the 'baseURLParamString' data member computed in init(). Exists mainly as a placeholder to allow for something more elaborate.


unicodeToAscii

private static String unicodeToAscii(String in_str)
Returns a string in the form of '\\uxxxx.' Same as wt.httpgw.EncodingConverter.unicodeToAscii method Written by Jason Drake