From 1c946ebab13ac956aac87fc4291374d6973e894b Mon Sep 17 00:00:00 2001 From: dchandler Date: Sun, 13 Oct 2002 20:40:24 +0000 Subject: [PATCH] These classes contain the code that brings up the "About" and "Help" windows in SavantShell. It is now cleanly factored out because Jskad uses it too (for keyboard mapping descriptions. --- source/org/thdl/util/RTFPane.java | 68 +++++++++++++++++++++++++++ source/org/thdl/util/SimpleFrame.java | 53 +++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 source/org/thdl/util/RTFPane.java create mode 100644 source/org/thdl/util/SimpleFrame.java diff --git a/source/org/thdl/util/RTFPane.java b/source/org/thdl/util/RTFPane.java new file mode 100644 index 0000000..7d2e1a6 --- /dev/null +++ b/source/org/thdl/util/RTFPane.java @@ -0,0 +1,68 @@ +/* +The contents of this file are subject to the THDL Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the THDL web site +(http://www.thdl.org/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is the Tibetan and Himalayan Digital +Library (THDL). Portions created by the THDL are Copyright 2001 THDL. +All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +package org.thdl.util; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.swing.text.DefaultStyledDocument; +import javax.swing.text.rtf.RTFEditorKit; +import javax.swing.text.BadLocationException; + +/** An RTFPane is a JScrollPane displaying the contents of a rich text + file (an RTF file). */ +public class RTFPane extends JScrollPane { + /** the default RTF editor kit that each RTFPane instance uses */ + final private static RTFEditorKit rtfKit = new RTFEditorKit(); + + /** Creates a JScrollPane displaying the contents of the rich text + * file named rtfFileName (which should be a resource packaged in + * this application's JAR file). + * + * @throws IOException if the resource exists but cannot be read + * @throws BadLocationException if the RTF file is busted + * @throws FileNotFoundException if the resource could not be found. + * @param resourceHolder the class associated with the named resource + * @param rtfFileName the name of the resource that is the rich text file + */ + public RTFPane(Class resourceHolder, String rtfFileName) + throws IOException, BadLocationException, FileNotFoundException + { + super(); + InputStream in = resourceHolder.getResourceAsStream(rtfFileName); + if (in == null) { + throw new FileNotFoundException(rtfFileName); + } + DefaultStyledDocument doc = new DefaultStyledDocument(); + try { + rtfKit.read(in, doc, 0); + } catch (BadLocationException ioe) { + throw ioe; + } catch (IOException ioe) { + throw ioe; + } + + JTextPane pane = new JTextPane(doc); + pane.setEditable(false); + + setViewportView(pane); + } +} diff --git a/source/org/thdl/util/SimpleFrame.java b/source/org/thdl/util/SimpleFrame.java new file mode 100644 index 0000000..6e7715a --- /dev/null +++ b/source/org/thdl/util/SimpleFrame.java @@ -0,0 +1,53 @@ +/* +The contents of this file are subject to the THDL Open Community License +Version 1.0 (the "License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License on the THDL web site +(http://www.thdl.org/). + +Software distributed under the License is distributed on an "AS IS" basis, +WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific terms governing rights and limitations under the +License. + +The Initial Developer of this software is the Tibetan and Himalayan Digital +Library (THDL). Portions created by the THDL are Copyright 2001 THDL. +All Rights Reserved. + +Contributor(s): ______________________________________. +*/ + +package org.thdl.util; + +import javax.swing.JFrame; +import java.awt.Container; +import java.awt.Component; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +import org.thdl.util.RTFPane; + +/** An SimpleFrame is a top-level window displaying a JScrollPane. */ +public class SimpleFrame extends JFrame { + /** Creates a visible JFrame displaying the contents of the + * component comp. + * + * @param frameTitle the title (on the title bar) of the window + * @param rtfPane the */ + public SimpleFrame(String frameTitle, final Component comp) + { + super(frameTitle); + setSize(500,400); + Container c = getContentPane(); + c.addComponentListener(new ComponentAdapter() + { + public void componentResized(ComponentEvent e) + { + comp.setSize(e.getComponent().getSize()); + } + }); + comp.setSize(c.getSize()); + c.add(comp); + setLocation(100,100); + setVisible(true); + } +}