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.platform.PlatformFactory;
040:
041: import javax.swing.event.HyperlinkListener;
042: import javax.swing.event.HyperlinkEvent;
043: import java.net.URL;
044: import java.net.MalformedURLException;
045:
046: /**
047: * The frame for displaying the HTML quick start files.
048: */
049: public class QuickStartFrame extends HelpFrame {
050: private static final String HELP_PATH = "/edu/rice/cs/drjava/docs/quickstart/";
051: protected static final URL INTRO_URL = HTMLFrame.class
052: .getResource(HELP_PATH + HOME_PAGE);
053:
054: public QuickStartFrame() {
055: super ("QuickStart Guide to DrJava", INTRO_URL,
056: QuickStartFrame.class.getResource(HELP_PATH
057: + CONTENTS_PAGE), ICON);
058: addHyperlinkListener(_linkListener);
059: }
060:
061: /**
062: * Shows the page selected by the hyperlink event.
063: * (theo) changed to anonymous inner class for encapsulation purposes
064: */
065: private HyperlinkListener _linkListener = new HyperlinkListener() {
066: public void hyperlinkUpdate(HyperlinkEvent event) {
067: if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
068: // Only follow links within the documentation
069: URL url = event.getURL();
070: String protocol = url.getProtocol();
071:
072: if ((!"file".equals(protocol))
073: && (!"jar".equals(protocol))) {
074: // try to open in the platform's web browser, since we can't
075: // view it effectively here if it isn't in the jar
076: // (we only handle file/jar protocols)
077: PlatformFactory.ONLY.openURL(url);
078: return;
079: }
080:
081: // perform path testing
082: String path = url.getPath();
083:
084: if (path.indexOf(HELP_PATH + CONTENTS_PAGE) >= 0) {
085: try {
086: url = new URL(url, HOME_PAGE); // redirect to home, not contents
087: } catch (MalformedURLException murle) {
088: }
089: } else if (path.indexOf(HELP_PATH) < 0) {
090: // not anywhere in the help section
091: return;
092: }
093: if (url.sameFile(_history.contents)) {
094: return; // we're already here!
095: }
096: jumpTo(url);
097: }
098: }
099: };
100:
101: }
|