2 * (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.swingui;
\r
15 import com.ibm.richtext.textpanel.MTextPanel;
\r
16 import com.ibm.richtext.textpanel.JTextPanel;
\r
17 import com.ibm.richtext.styledtext.MConstText;
\r
19 import java.awt.BorderLayout;
\r
20 import java.awt.Toolkit;
\r
21 import java.awt.datatransfer.Clipboard;
\r
23 import java.awt.event.WindowAdapter;
\r
24 import java.awt.event.WindowEvent;
\r
26 import javax.swing.JFrame;
\r
27 import javax.swing.JMenuBar;
\r
28 import javax.swing.UIManager;
\r
30 import java.awt.Container;
\r
33 * JTextFrame is a JFrame containing an editable JTextPanel, a set of standard
\r
34 * menus, and a JTabRuler. This class can be used as-is, but is
\r
35 * primarily intended to be a simple example of how to use the other classes
\r
37 * @see com.ibm.richtext.textpanel.JTextPanel
\r
38 * @see SwingMenuBuilder
\r
41 public final class JTextFrame extends JFrame {
\r
46 private static final long serialVersionUID = -1026126723995559230L;
\r
47 //static final String COPYRIGHT =
\r
48 // "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
49 private JTextPanel fTextPanel;
\r
52 * Create a new JTextFrame with no text, no title,
\r
53 * and a private clipboard.
\r
55 public JTextFrame() {
\r
58 init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
\r
62 * Create a new JTextFrame with no text and the given title.
\r
63 * The JTextPanel will use a private clipboard.
\r
64 * @param title the title of this Frame
\r
66 public JTextFrame(String title) {
\r
69 init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
\r
73 * Create a new JTextFrame with the given text and title, whose
\r
74 * TextPanel will use the given clipboard.
\r
75 * @param text the initial text in the TextPanel. If null the
\r
76 * TextPanel will initially be empty
\r
77 * @param title the title of this Frame
\r
78 * @param clipboard the Clipboard which the TextPanel will use.
\r
79 * If null the TextPanel will use a private Clipboard
\r
81 public JTextFrame(MConstText text,
\r
83 Clipboard clipboard) {
\r
86 init(text, clipboard);
\r
89 private void init(MConstText text, Clipboard clipboard) {
\r
91 fTextPanel = new JTextPanel(text, clipboard);
\r
93 JTabRuler tabRuler = new JTabRuler(14, 10, fTextPanel);
\r
97 Container contentPane = getContentPane();
\r
98 contentPane.setLayout(new BorderLayout());
\r
99 contentPane.add(fTextPanel, "Center");
\r
100 contentPane.add(tabRuler, "North");
\r
104 private void createMenus() {
\r
106 JMenuBar menuBar = new JMenuBar();
\r
108 SwingMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);
\r
110 setJMenuBar(menuBar);
\r
114 * Return the MTextPanel in this frame.
\r
116 public MTextPanel getTextPanel() {
\r
121 public static void main(String[] args) {
\r
123 String laf = UIManager.getSystemLookAndFeelClassName();
\r
124 if (args.length == 1) {
\r
125 if (args[0].equals("cp")) {
\r
126 laf = UIManager.getCrossPlatformLookAndFeelClassName();
\r
131 UIManager.setLookAndFeel(laf);
\r
133 catch(Throwable th) {
\r
134 th.printStackTrace();
\r
136 JTextFrame frame = new JTextFrame();
\r
137 frame.addWindowListener(new WindowAdapter() {
\r
138 public void windowClosing(WindowEvent e) {
\r
142 frame.setSize(550, 700);
\r