Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
HelpBox |
|
| 4.0;4 |
1 | /* $Id: HelpBox.java 17841 2010-01-12 19:17:52Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 2008 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.ui; | |
40 | ||
41 | import java.awt.BorderLayout; | |
42 | import java.awt.Dimension; | |
43 | import java.awt.Toolkit; | |
44 | import java.io.IOException; | |
45 | import java.net.MalformedURLException; | |
46 | import java.net.URL; | |
47 | ||
48 | import javax.swing.JEditorPane; | |
49 | import javax.swing.JFrame; | |
50 | import javax.swing.JScrollPane; | |
51 | import javax.swing.JTabbedPane; | |
52 | import javax.swing.event.HyperlinkEvent; | |
53 | import javax.swing.event.HyperlinkListener; | |
54 | ||
55 | import org.apache.log4j.Logger; | |
56 | import org.argouml.application.helpers.ApplicationVersion; | |
57 | ||
58 | /** | |
59 | * This is what you see after you activate the "Help->Help" menu-item. | |
60 | */ | |
61 | public class HelpBox extends JFrame implements HyperlinkListener { | |
62 | ||
63 | 0 | private static final Logger LOG = Logger.getLogger(HelpBox.class); |
64 | ||
65 | /** | |
66 | * A tabbed pane to display several pages simultaneously. | |
67 | */ | |
68 | 0 | private JTabbedPane tabs = new JTabbedPane(); |
69 | ||
70 | /** | |
71 | * The panes to display the various help pages. | |
72 | */ | |
73 | 0 | private JEditorPane[] panes = null; |
74 | ||
75 | /** | |
76 | * The names and URLs for the pages. | |
77 | */ | |
78 | 0 | private String pages[][] = {{"Manual", |
79 | ApplicationVersion.getOnlineManual() , | |
80 | "The ArgoUML online manual"}, | |
81 | {"Support", | |
82 | ApplicationVersion.getOnlineSupport(), | |
83 | "The ArgoUML support page" }}; | |
84 | ||
85 | ||
86 | /** | |
87 | * Class constructor. | |
88 | * | |
89 | * @param title the title of the help window. | |
90 | */ | |
91 | public HelpBox( String title) { | |
92 | 0 | super( title); |
93 | 0 | Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize(); |
94 | 0 | setLocation(scrSize.width / 2 - 400, scrSize.height / 2 - 300); |
95 | ||
96 | 0 | getContentPane().setLayout(new BorderLayout(0, 0)); |
97 | 0 | setSize( 800, 600); |
98 | ||
99 | 0 | panes = new JEditorPane [ pages.length]; |
100 | 0 | for ( int i = 0; i < pages.length; i++) { |
101 | 0 | panes[i] = new JEditorPane(); |
102 | 0 | panes[i].setEditable( false); |
103 | 0 | panes[i].setSize( 780, 580); |
104 | 0 | panes[i].addHyperlinkListener( this); |
105 | ||
106 | 0 | URL paneURL = null; |
107 | try { | |
108 | 0 | paneURL = new URL( pages[i][1]); |
109 | 0 | } catch ( MalformedURLException e) { |
110 | 0 | LOG.warn( pages[i][0] + " URL malformed: " + pages[i][1]); |
111 | 0 | } |
112 | ||
113 | 0 | if ( paneURL != null) { |
114 | try { | |
115 | 0 | panes[i].setPage( paneURL); |
116 | 0 | } catch ( IOException e) { |
117 | 0 | LOG.warn("Attempted to read a bad URL: " + paneURL); |
118 | 0 | } |
119 | } else { | |
120 | 0 | LOG.warn("Couldn't find " + pages[i][0]); |
121 | } | |
122 | ||
123 | // Put the current pane in a scroll pane. | |
124 | 0 | JScrollPane paneScrollPane = new JScrollPane( panes[i]); |
125 | 0 | paneScrollPane.setVerticalScrollBarPolicy( |
126 | JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | |
127 | 0 | paneScrollPane.setPreferredSize(new Dimension(800, 600)); |
128 | 0 | paneScrollPane.setMinimumSize(new Dimension(400, 300)); |
129 | ||
130 | 0 | tabs.addTab( pages[i][0], null, paneScrollPane, pages[i][2]); |
131 | } | |
132 | 0 | getContentPane().add( tabs, BorderLayout.CENTER); |
133 | 0 | } |
134 | ||
135 | public void hyperlinkUpdate(HyperlinkEvent event) { | |
136 | 0 | if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
137 | 0 | JEditorPane pane = (JEditorPane) event.getSource(); |
138 | try { | |
139 | 0 | pane.setPage(event.getURL()); |
140 | 0 | } catch (IOException ioe) { |
141 | 0 | LOG.warn( "Could not fetch requested URL"); |
142 | 0 | } |
143 | } | |
144 | 0 | } |
145 | ||
146 | /** | |
147 | * The UID. | |
148 | */ | |
149 | private static final long serialVersionUID = 0L; | |
150 | ||
151 | } |