001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.cleverphl.gui;
025:
026: import jacareto.cleverphl.CleverPHL;
027: import jacareto.cleverphl.session.Session;
028: import jacareto.cleverphl.session.SessionListEvent;
029: import jacareto.cleverphl.session.SessionListListener;
030: import jacareto.comp.Components;
031:
032: import java.awt.event.WindowEvent;
033: import java.awt.event.WindowListener;
034:
035: import java.net.URL;
036:
037: import javax.help.DefaultHelpBroker;
038: import javax.help.HelpBroker;
039: import javax.help.HelpSet;
040: import javax.help.HelpSetException;
041: import javax.help.WindowPresentation;
042:
043: import javax.swing.JCheckBoxMenuItem;
044: import javax.swing.JFrame;
045: import javax.swing.JPanel;
046:
047: /**
048: * <p>
049: * The HelpFrame shows the Jacareto help.
050: * </p>
051: *
052: * @author Christian Spannagel
053: */
054: public class HelpFrame extends CleverPHLFrame implements
055: WindowListener, SessionListListener {
056: /** The help broker instance. */
057: private HelpBroker helpBroker;
058:
059: /** The default help window which should be ignored by all components instances. */
060: private JFrame defaultHelpWindow;
061:
062: /**
063: * Default constructor
064: *
065: * @param cleverPHL The CleverPHL instance
066: */
067: public HelpFrame(CleverPHL cleverPHL) {
068: super (cleverPHL, "CleverPHL.HelpFrame",
069: "CleverPHL.Menu.ViewHelp");
070: setTitle(cleverPHL.getLanguage().getString(
071: "CleverPHL.HelpFrame.Title"));
072: addWindowListener(this );
073: cleverPHL.getSessionList().addSessionListListener(this );
074: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
075: loadHelpFile();
076: }
077:
078: /**
079: * Loads the help file.
080: */
081: private void loadHelpFile() {
082: String helpHS = "JacaretoHelp.hs";
083: HelpSet hs = null;
084: ClassLoader cl = helpHS.getClass().getClassLoader();
085:
086: URL hsURL = HelpSet.findHelpSet(cl, helpHS);
087:
088: try {
089: hs = new HelpSet(null, hsURL);
090: } catch (HelpSetException ee) {
091: cleverPHL
092: .getLogger()
093: .error(
094: cleverPHL
095: .getLanguage()
096: .getString(
097: "CleverPHL.HelpFrame.Error.HelpSetNotFound"),
098: ee);
099:
100: return;
101: }
102:
103: helpBroker = hs.createHelpBroker();
104: helpBroker.initPresentation();
105:
106: WindowPresentation presentation = ((DefaultHelpBroker) helpBroker)
107: .getWindowPresentation();
108: defaultHelpWindow = (JFrame) presentation.getHelpWindow();
109: ((DefaultHelpBroker) helpBroker).setActivationWindow(this );
110: setContentPane(defaultHelpWindow.getContentPane());
111: defaultHelpWindow.setContentPane(new JPanel());
112: validate();
113: }
114:
115: /**
116: * Invoked when the session list has changed.
117: *
118: * @param event the session list event
119: */
120: public void sessionListChanged(SessionListEvent event) {
121: Session session = event.getSession();
122: Components components = session.getComponents();
123: int ID = event.getID();
124:
125: if (ID == SessionListEvent.SESSION_ADDED) {
126: components.addTree(defaultHelpWindow, false, false);
127: }
128: }
129:
130: /**
131: * Does nothing.
132: *
133: * @param w DOCUMENT ME!
134: */
135: public void windowActivated(WindowEvent w) {
136: }
137:
138: /**
139: * Does nothing.
140: *
141: * @param w DOCUMENT ME!
142: */
143: public void windowClosed(WindowEvent w) {
144: }
145:
146: /**
147: * Does nothing.
148: *
149: * @param w DOCUMENT ME!
150: */
151: public void windowDeactivated(WindowEvent w) {
152: }
153:
154: /**
155: * Does nothing.
156: *
157: * @param w DOCUMENT ME!
158: */
159: public void windowDeiconified(WindowEvent w) {
160: }
161:
162: /**
163: * Does nothing.
164: *
165: * @param w DOCUMENT ME!
166: */
167: public void windowIconified(WindowEvent w) {
168: }
169:
170: /**
171: * Does nothing.
172: *
173: * @param w DOCUMENT ME!
174: */
175: public void windowOpened(WindowEvent w) {
176: }
177:
178: /**
179: * Exits the system.
180: *
181: * @param w DOCUMENT ME!
182: */
183: public void windowClosing(WindowEvent w) {
184: close();
185: }
186:
187: /**
188: * Closes the frame.
189: */
190: public void close() {
191: setVisible(false);
192:
193: JCheckBoxMenuItem item = ((JCheckBoxMenuItem) cleverPHL
194: .getMainFrame().getCleverPHLMenuBar().getMenuItem(
195: "CleverPHL.Menu.ViewHelp"));
196: item.setSelected(false);
197: }
198: }
|