001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.ui;
038:
039: import edu.rice.cs.drjava.CodeStatus;
040: import edu.rice.cs.drjava.platform.PlatformFactory;
041:
042: import javax.swing.event.HyperlinkListener;
043: import javax.swing.event.HyperlinkEvent;
044: import java.net.URL;
045: import java.net.MalformedURLException;
046:
047: /**
048: * The frame for displaying the HTML help files.
049: * @version $Id: HelpFrame.java 4255 2007-08-28 19:17:37Z mgricken $
050: */
051: public class HelpFrame extends HTMLFrame {
052: private static final String HELP_PATH = "/edu/rice/cs/drjava/docs/user/";
053: protected static final String CONTENTS_PAGE = "index.html";
054: protected static final String HOME_PAGE = "intro.html";
055: private static final URL INTRO_URL = HTMLFrame.class
056: .getResource(HELP_PATH + HOME_PAGE);
057: protected static final String ICON = "DrJavaHelp.png";
058:
059: public HelpFrame() {
060: super ("Help on using DrJava", INTRO_URL, HelpFrame.class
061: .getResource(HELP_PATH + CONTENTS_PAGE), ICON);
062: addHyperlinkListener(_linkListener);
063:
064: }
065:
066: /**
067: * Used by subclass QuickStartFrame to instantiate fields of frame.
068: */
069: public HelpFrame(String frameName, URL introUrl, URL indexUrl,
070: String iconString) {
071: super (frameName, introUrl, indexUrl, iconString);
072: }
073:
074: protected String getErrorText(URL url) {
075: // The help files are made available by running "ant docs"
076: return "The Help files are currently unavailable.";
077: }
078:
079: /** Shows the page selected by the hyperlink event. Changed to anonymous inner class for
080: * encapsulation purposes */
081: private HyperlinkListener _linkListener = new HyperlinkListener() {
082: public void hyperlinkUpdate(HyperlinkEvent event) {
083: if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
084: // Only follow links within the documentation
085: URL url = event.getURL();
086: String protocol = url.getProtocol();
087:
088: if (!"file".equals(protocol) && !"jar".equals(protocol)) {
089: // try to open in the platform's web browser, since we can't
090: // view it effectively here if it isn't in the jar
091: // (we only handle file/jar protocols)
092: PlatformFactory.ONLY.openURL(url);
093: return;
094: }
095:
096: // perform path testing
097: String path = url.getPath();
098:
099: if (path.indexOf(HELP_PATH + CONTENTS_PAGE) >= 0) {
100: try {
101: url = new URL(url, HOME_PAGE);
102: } // redirect to home, not content
103: catch (MalformedURLException murle) {
104: /* do nothing */
105: }
106: } else if (path.indexOf(HELP_PATH) < 0)
107: return; // not anywhere in the help section
108:
109: if (url.sameFile(_history.contents))
110: return; // we're already here!
111: jumpTo(url);
112: }
113: }
114: };
115: }
|