]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/awtui/TextFrame.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / awtui / TextFrame.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2007.  All Rights Reserved.\r
3  *\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
12  */\r
13 package com.ibm.richtext.awtui;\r
14 \r
15 import com.ibm.richtext.textpanel.MTextPanel;\r
16 import com.ibm.richtext.textpanel.TextPanel;\r
17 import com.ibm.richtext.styledtext.MConstText;\r
18 \r
19 import java.awt.BorderLayout;\r
20 import java.awt.Frame;\r
21 import java.awt.MenuBar;\r
22 import java.awt.Toolkit;\r
23 \r
24 import java.awt.datatransfer.Clipboard;\r
25 \r
26 import java.awt.event.WindowAdapter;\r
27 import java.awt.event.WindowEvent;\r
28 \r
29 /**\r
30  * TextFrame is a Frame containing an editable TextPanel, a set of standard\r
31  * menus, and a TabRuler.  This class can be used as-is, but is\r
32  * primarily intended to be a simple example of how to use the other classes\r
33  * in this package.\r
34  * @see com.ibm.richtext.textpanel.TextPanel\r
35  * @see AwtMenuBuilder\r
36  * @see TabRuler\r
37  */\r
38 public final class TextFrame extends Frame {\r
39 \r
40     /**\r
41      * For serialization\r
42      */\r
43     private static final long serialVersionUID = 8436822743736641732L;\r
44     //static final String COPYRIGHT =\r
45     //            "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
46     private TextPanel fTextPanel;\r
47 \r
48     /**\r
49      * Create a new TextFrame with no text and no title.\r
50      */\r
51     public TextFrame() {\r
52         \r
53         super();\r
54         init(null, Toolkit.getDefaultToolkit().getSystemClipboard());\r
55     }\r
56     \r
57     /**\r
58      * Create a new TextFrame with no text and the given title.\r
59      * @param title the title of this Frame\r
60      */\r
61     public TextFrame(String title) {\r
62         \r
63         super(title);\r
64         init(null, Toolkit.getDefaultToolkit().getSystemClipboard());\r
65     }\r
66     \r
67     /**\r
68      * Create a new TextFrame with the given text and title, whose\r
69      * TextPanel will use the given clipboard.\r
70      * @param text the initial text in the TextPanel.  If null the\r
71      *      TextPanel will initially be empty\r
72      * @param title the title of this Frame\r
73      * @param clipboard the Clipboard which the TextPanel will use.\r
74      *      If null the TextPanel will use a private Clipboard\r
75      */\r
76     public TextFrame(MConstText text,\r
77                      String title,\r
78                      Clipboard clipboard) {\r
79 \r
80         super(title);\r
81         init(text, clipboard);\r
82     }\r
83 \r
84     private void init(MConstText text, Clipboard clipboard) {\r
85         \r
86         fTextPanel = new TextPanel(text, clipboard);\r
87 \r
88         TabRuler tabRuler = new TabRuler(14, 10, fTextPanel);\r
89 \r
90         createMenus();\r
91 \r
92         setLayout(new BorderLayout());\r
93         add(fTextPanel, "Center");\r
94         add(tabRuler, "North");\r
95         pack();\r
96     }\r
97 \r
98     private void createMenus() {\r
99 \r
100         MenuBar menuBar = new MenuBar();\r
101 \r
102         AwtMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);\r
103 \r
104         setMenuBar(menuBar);\r
105     }\r
106 \r
107     /**\r
108      * Return the MTextPanel in this frame.\r
109      */\r
110     public MTextPanel getTextPanel() {\r
111 \r
112         return fTextPanel;\r
113     }\r
114     \r
115     public static void main(String[] args) {\r
116         \r
117         TextFrame frame = new TextFrame();\r
118         frame.addWindowListener(new WindowAdapter() {\r
119             public void windowClosing(WindowEvent e) {\r
120                 System.exit(0);\r
121             }\r
122         });\r
123         frame.setSize(550, 700);\r
124         frame.show();\r
125     }\r
126 }