psmith 2003/12/21 23:59:21 Modified: src/java/org/apache/log4j/chainsaw/help HelpManager.java Log: The HelpManager now uses the HelpLocator to find help resources for particular classes. This will eventually allow Chainsaw to use either remote Help urls (say, retrieved from the log4j website as the default) or be installed locally. Revision Changes Path 1.2 +134 -128 jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/HelpManager.java Index: HelpManager.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/help/HelpManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- HelpManager.java 19 Dec 2003 06:50:35 -0000 1.1 +++ HelpManager.java 22 Dec 2003 07:59:21 -0000 1.2 @@ -46,6 +46,7 @@ * Apache Software Foundation, please see <http://www.apache.org/>. * */ + package org.apache.log4j.chainsaw.help; import java.beans.PropertyChangeEvent; @@ -55,141 +56,146 @@ import org.apache.log4j.chainsaw.ChainsawConstants; + /** * Singleton help manager where objects can register to display * Help for something, an independant viewer can register to * be notified when the requested Help URL changes and can display * it appropriately. This class effectively decouples the help requester * from the help implementation (if any!) - * - * @author Pau Smith <[EMAIL PROTECTED]> + * + * @author Paul Smith <[EMAIL PROTECTED]> * */ public final class HelpManager { - - private URL helpURL; - private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this); - private static final HelpManager instance = new HelpManager(); - - - private HelpManager(){} - - /** - * @return - */ - public final URL getHelpURL() { - return helpURL; - } - - /** - * The current Help URL that should be displayed, and is - * a PropertyChangeListener supported property. - * - * This method ALWAYS fires property change events - * even if the value is the same (the oldvalue - * of the event will be null) - * @param helpURL - */ - public final void setHelpURL(URL helpURL) { - this.helpURL = helpURL; - firePropertyChange("helpURL", null, this.helpURL); - } - - /** - * @param listener - */ - public void addPropertyChangeListener(PropertyChangeListener listener) { - propertySupport.addPropertyChangeListener(listener); - } - - /** - * @param propertyName - * @param listener - */ - public synchronized void addPropertyChangeListener( - String propertyName, - PropertyChangeListener listener) { - propertySupport.addPropertyChangeListener(propertyName, listener); - } - - /** - * @param evt - */ - public void firePropertyChange(PropertyChangeEvent evt) { - propertySupport.firePropertyChange(evt); - } - - /** - * @param propertyName - * @param oldValue - * @param newValue - */ - public void firePropertyChange( - String propertyName, - boolean oldValue, - boolean newValue) { - propertySupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * @param propertyName - * @param oldValue - * @param newValue - */ - public void firePropertyChange( - String propertyName, - int oldValue, - int newValue) { - propertySupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * @param propertyName - * @param oldValue - * @param newValue - */ - public void firePropertyChange( - String propertyName, - Object oldValue, - Object newValue) { - propertySupport.firePropertyChange(propertyName, oldValue, newValue); - } - - /** - * @param listener - */ - public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { - propertySupport.removePropertyChangeListener(listener); - } - - /** - * @param propertyName - * @param listener - */ - public synchronized void removePropertyChangeListener( - String propertyName, - PropertyChangeListener listener) { - propertySupport.removePropertyChangeListener(propertyName, listener); - } - - /** - * - */ - public static HelpManager getInstance() { - return instance; - - } - - /** - * Given a class, and that it belongs within the org.apache.log4j project, - * sets the URL to the JavaDoc for that class. - * - * @param class1 - */ - public void showHelpForClass(Class class1) { - // TODO This needs to convert the FQN class name into a valid help URL. -// TODO Be also nice to be able to set a BaseHelpURL or something instead of hitting the Apache server. - setHelpURL(ChainsawConstants.WELCOME_URL); - } - + private static final HelpManager instance = new HelpManager(); + private HelpLocator helpLocator = new HelpLocator(); + private URL helpURL; + private final PropertyChangeSupport propertySupport = + new PropertyChangeSupport(this); + + private HelpManager() { + +// TODO setup all the base URLs in the default.properties and configure in ApplicationPreferenceModel + helpLocator.installClassloaderLocator(this.getClass().getClassLoader()); +// helpLocator.installLocator(new URL()); + } + + /** + * @return + */ + public final URL getHelpURL() { + return helpURL; + } + + /** + * The current Help URL that should be displayed, and is + * a PropertyChangeListener supported property. + * + * This method ALWAYS fires property change events + * even if the value is the same (the oldvalue + * of the event will be null) + * @param helpURL + */ + public final void setHelpURL(URL helpURL) { + this.helpURL = helpURL; + firePropertyChange("helpURL", null, this.helpURL); + } + + /** + * @param listener + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + propertySupport.addPropertyChangeListener(listener); + } + + /** + * @param propertyName + * @param listener + */ + public synchronized void addPropertyChangeListener( + String propertyName, PropertyChangeListener listener) { + propertySupport.addPropertyChangeListener(propertyName, listener); + } + + /** + * @param evt + */ + public void firePropertyChange(PropertyChangeEvent evt) { + propertySupport.firePropertyChange(evt); + } + + /** + * @param propertyName + * @param oldValue + * @param newValue + */ + public void firePropertyChange( + String propertyName, boolean oldValue, boolean newValue) { + propertySupport.firePropertyChange(propertyName, oldValue, newValue); + } + + /** + * @param propertyName + * @param oldValue + * @param newValue + */ + public void firePropertyChange( + String propertyName, int oldValue, int newValue) { + propertySupport.firePropertyChange(propertyName, oldValue, newValue); + } + + /** + * @param propertyName + * @param oldValue + * @param newValue + */ + public void firePropertyChange( + String propertyName, Object oldValue, Object newValue) { + propertySupport.firePropertyChange(propertyName, oldValue, newValue); + } + + /** + * @param listener + */ + public synchronized void removePropertyChangeListener( + PropertyChangeListener listener) { + propertySupport.removePropertyChangeListener(listener); + } + + /** + * @param propertyName + * @param listener + */ + public synchronized void removePropertyChangeListener( + String propertyName, PropertyChangeListener listener) { + propertySupport.removePropertyChangeListener(propertyName, listener); + } + + /** + * + */ + public static HelpManager getInstance() { + return instance; + } + + /** + * Given a class, and that it belongs within the org.apache.log4j project, + * sets the URL to the JavaDoc for that class. + * + * @param c + */ + public void showHelpForClass(Class c) { + String name = c.getName(); + name = name.replace('.', '/'); + + URL url = helpLocator.findResource(name); + + if (url != null) { + setHelpURL(url); + } else { + // TODO Create a resource not found url + setHelpURL(ChainsawConstants.WELCOME_URL); + } + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]