]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/swingui/JTextFrame.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / swingui / JTextFrame.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.swingui;\r
14 \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
18 \r
19 import java.awt.BorderLayout;\r
20 import java.awt.Toolkit;\r
21 import java.awt.datatransfer.Clipboard;\r
22 \r
23 import java.awt.event.WindowAdapter;\r
24 import java.awt.event.WindowEvent;\r
25 \r
26 import javax.swing.JFrame;\r
27 import javax.swing.JMenuBar;\r
28 import javax.swing.UIManager;\r
29 \r
30 import java.awt.Container;\r
31 \r
32 /**\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
36  * in this package.\r
37  * @see com.ibm.richtext.textpanel.JTextPanel\r
38  * @see SwingMenuBuilder\r
39  * @see JTabRuler\r
40  */\r
41 public final class JTextFrame extends JFrame {\r
42 \r
43     /**\r
44      * For serialization\r
45      */\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
50 \r
51     /**\r
52      * Create a new JTextFrame with no text, no title, \r
53      * and a private clipboard.\r
54      */\r
55     public JTextFrame() {\r
56         \r
57         super();\r
58         init(null, Toolkit.getDefaultToolkit().getSystemClipboard());\r
59     }\r
60     \r
61     /**\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
65      */\r
66     public JTextFrame(String title) {\r
67         \r
68         super(title);\r
69         init(null, Toolkit.getDefaultToolkit().getSystemClipboard());\r
70     }\r
71     \r
72     /**\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
80      */\r
81     public JTextFrame(MConstText text,\r
82                      String title,\r
83                      Clipboard clipboard) {\r
84 \r
85         super(title);\r
86         init(text, clipboard);\r
87     }\r
88 \r
89     private void init(MConstText text, Clipboard clipboard) {\r
90         \r
91         fTextPanel = new JTextPanel(text, clipboard);\r
92 \r
93         JTabRuler tabRuler = new JTabRuler(14, 10, fTextPanel);\r
94 \r
95         createMenus();\r
96 \r
97         Container contentPane = getContentPane();\r
98         contentPane.setLayout(new BorderLayout());\r
99         contentPane.add(fTextPanel, "Center");\r
100         contentPane.add(tabRuler, "North");\r
101         pack();\r
102     }\r
103 \r
104     private void createMenus() {\r
105 \r
106         JMenuBar menuBar = new JMenuBar();\r
107 \r
108         SwingMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);\r
109         \r
110         setJMenuBar(menuBar);\r
111     }\r
112 \r
113     /**\r
114      * Return the MTextPanel in this frame.\r
115      */\r
116     public MTextPanel getTextPanel() {\r
117 \r
118         return fTextPanel;\r
119     }\r
120     \r
121     public static void main(String[] args) {\r
122         \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
127             }\r
128         }\r
129                 \r
130         try {\r
131             UIManager.setLookAndFeel(laf);\r
132         }\r
133         catch(Throwable th) {\r
134             th.printStackTrace();\r
135         }\r
136         JTextFrame frame = new JTextFrame();\r
137         frame.addWindowListener(new WindowAdapter() {\r
138             public void windowClosing(WindowEvent e) {\r
139                 System.exit(0);\r
140             }\r
141         });\r
142         frame.setSize(550, 700);\r
143         frame.show();\r
144     }\r
145 }\r