cox.jmatt.java.MathTools.demo
Class URLLoaderPanel

java.lang.Object
  extended by cox.jmatt.java.MathTools.demo.URLLoaderPanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class URLLoaderPanel
extends java.lang.Object
implements java.awt.event.ActionListener

This class wraps a simple GUI around an URLClassLoader. It provides a TextArea to list URLs, machinery to fetch these URLs as either an URL[] array or as a fully-instantiated ClassLoader, and a way to pick single URLs from a file or to load a list of them.

Originally a part of ScriptPanel, URLLoaderPanel was factored out to provide independent support to other classes that might need an URLClassLoader. In GUI construction this class fetches two Components from the CapCom Shelf: the Forward and Back buttons to flip among ScriptPanel's CardLayout. If this class is added to another application any Component can be added in their place. Simply CapCom.storeObject() these components prior to instantiation, using the keys URL_PANEL_EAST and URL_PANEL_WEST. URLLoaderPanel removes these from the Shelf so using more than one requires storing these items more than once!

URLLoaderPanel can be constructed with zero arguments but the URL panel will not have Buttons to pick a file URL or load a list of them. These functions require a FileDialog which requires instantiation around a Dialog or a Frame.

When the [Check URLs] button is clicked, the getURLS() method is called. Doing so parses the URLs individually, so any malformed URLs are reported at Error level and then ignored: the other URLs are still parsed and added to the array. The getURLClassLoader() method also performs this check. Any time getURLS() is called, it reports bad URLs at Error level and gives Info on how many were successfully loaded. Clicking the [Set MTCL] button creates a ClassLoader and sends it to CapCom.setMathClassLoader(). ScriptPanel does this automatically, the button is provided for subclasses or user-created apps that do not rely on ScriptPanel to do such things.

The URLClassLoader is constructed using the URL[]-array constructor with nothing else. If more complexity is desired, subclass and add it or modify the ClassLoader after it has been created. Or call getURLS() and create your own!


Field Summary
static java.lang.String URL_PANEL_EAST
          Key used to store the EAST component on The Shelf.
static java.lang.String URL_PANEL_WEST
          Key used to store the WEST component on The Shelf.
 
Constructor Summary
URLLoaderPanel()
          Default constructor.
URLLoaderPanel(java.awt.Dialog pParent)
          Constructor around a Dialog.
URLLoaderPanel(java.awt.Frame pParent)
          Constructor around a Frame.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
           
 void addURL(java.lang.String pURL)
          Add an URL to the list.
protected  java.awt.Panel getEastPanel()
          This is the Panel placed at BorderLayout.EAST.
 java.lang.ClassLoader getURLClassLoader()
          Create an URLClassLoader around the URLs listed.
 java.net.URL[] getURLS()
          This method attempts to parse the URLs in the URL ClassLoader area into an URL[] array.
protected  java.awt.Panel getWestPanel()
          This is the Panel placed at BorderLayout.WEST.
 void loadURLList()
          Load a list of URLs into the TextArea.
 void pickURL()
          Pick an URL using a FileDialog.
 void setMathClassLoader()
          Call this method to create an URLClassLoader and send it to CapCom.
 java.awt.Panel standardGUI()
          The Standard GUI builds the URLLoaderPanel's GUI per standard layout: title, URL List area, and buttons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_PANEL_EAST

public static final java.lang.String URL_PANEL_EAST
Key used to store the EAST component on The Shelf.

See Also:
Constant Field Values

URL_PANEL_WEST

public static final java.lang.String URL_PANEL_WEST
Key used to store the WEST component on The Shelf.

See Also:
Constant Field Values
Constructor Detail

URLLoaderPanel

public URLLoaderPanel()
Default constructor. If this constructor is used the [Load URL list] and [Add file URL] buttons will not be added to the GUI.


URLLoaderPanel

public URLLoaderPanel(java.awt.Frame pParent)
Constructor around a Frame. This enables the FileDialog and [Load...] and [Add...] buttons.


URLLoaderPanel

public URLLoaderPanel(java.awt.Dialog pParent)
Constructor around a Dialog. This enables the FileDialog and [Load...] and [Add...] buttons.

Method Detail

standardGUI

public final java.awt.Panel standardGUI()

The Standard GUI builds the URLLoaderPanel's GUI per standard layout: title, URL List area, and buttons. This method does check CapCom's Shelf for components to add to the WEST and EAST parts of its BorderLayout. During construction, it checks the using the URL_PANEL_ keys and, if it receives a Component, adds it to the appropriate spot. URLLoaderPanel uses these with ScriptPanel to acquire the card Forward and Back buttons. If Components are found on the Shelf, they are removed.

Note: To instantiate and get the GUI in one fell swoop use the construct '(new URLLoaderPanel(?)).standardGUI();'.


getEastPanel

protected java.awt.Panel getEastPanel()
This is the Panel placed at BorderLayout.EAST. Override to customize URLLoaderPanel's GUI. The default implementation looks for the back button, [<<|], on CapCom's Shelf. If it is found, it is wrapped in a Panel and added.


getWestPanel

protected java.awt.Panel getWestPanel()
This is the Panel placed at BorderLayout.WEST. The default implementation tries to remove key URL_PANEL_WEST from the CapCom shelf. If a Component is found, it is added. Subclasses can use this method to customize the standard GUI.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aev)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

addURL

public void addURL(java.lang.String pURL)
Add an URL to the list. If pURL is null or empty it is ignored.


pickURL

public void pickURL()
Pick an URL using a FileDialog. If this class was not constructed around a Frame or Dialog, this method does nothing.


loadURLList

public void loadURLList()
Load a list of URLs into the TextArea. If this class has no parent, this method does nothing.


getURLS

public final java.net.URL[] getURLS()
This method attempts to parse the URLs in the URL ClassLoader area into an URL[] array. Any errors are reported at the Error level. The URLs are parsed individually and any valid ones go into the array. If the URL Panel TextArea is empty this method returns null. If all the URLs are bad, it returns an empty array.

Returns:
An array of valid URLs.

getURLClassLoader

public java.lang.ClassLoader getURLClassLoader()
Create an URLClassLoader around the URLs listed. If anyting goes wrong it is reported at Error level and null is returned.


setMathClassLoader

public void setMathClassLoader()
Call this method to create an URLClassLoader and send it to CapCom. ScriptPanel does this automatically. If no ClassLoader is created, the ClassLoader set is null.