/*========================================================================= Program: FusionViewer Module: $RCSfile: HelpWindow.java,v $ Language: Java Date: $Date: 2007/02/02 19:27:57 $ Version: $Revision: 1.3 $ Copyright (c) Insightful Corporation. All rights reserved. See Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ package org.fusionviewer.ui; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Toolkit; import java.awt.Window; import java.io.File; import java.io.IOException; import javax.swing.BorderFactory; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import org.fusionviewer.io.Env; /**\class HelpWindow *\brief Window for showing HTML help files. */ public class HelpWindow extends JFrame implements HyperlinkListener { private static final int OFFSET = 25; private static final int WIDTH = 900; private JEditorPane m_helpComponent; public HelpWindow() { super(); getContentPane().setLayout(new BorderLayout()); setTitle("FusionViewer Help"); maximizeWindow(this); // Create HTML view in a ScrollPane try { m_helpComponent = new JEditorPane(new File(new File("Data" + File.separatorChar + "Help"), "index.html").toURL()); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(m_helpComponent); getContentPane().add(scrollPane); if (Env.isMac) { scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); } final int BORDER = 5; m_helpComponent.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER + 5, BORDER, BORDER + 5)); m_helpComponent.setEditable(false); m_helpComponent.addHyperlinkListener(this); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } /* * Maximize the main window to the largest square window that will fit on the main display */ private void maximizeWindow(Window w) { Toolkit toolkit = Toolkit.getDefaultToolkit(); GraphicsDevice mainDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); // Get dimensions of the main screen and insets to account for widgets like the Windows taskbar Dimension screenDim = toolkit.getScreenSize(); Insets insets = toolkit.getScreenInsets(mainDevice.getDefaultConfiguration()); // Size the window so that it is somewhat smaller than the main window and will not obscure it in // its default position and size w.setSize(Math.min(screenDim.width - (insets.left + insets.right) - OFFSET, WIDTH), screenDim.height - (insets.top + insets.bottom) - OFFSET * 2); w.setLocation(insets.left + OFFSET, insets.top + OFFSET); } public void hyperlinkUpdate(HyperlinkEvent e) { try { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) m_helpComponent.setPage(e.getURL()); } catch (IOException e1) { e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }