]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/demo/CodeEdit.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / demo / CodeEdit.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  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.demo;\r
14 \r
15 import java.awt.FileDialog;\r
16 import java.awt.Frame;\r
17 import java.awt.Toolkit;\r
18 \r
19 import java.io.File;\r
20 \r
21 import com.ibm.richtext.textlayout.attributes.AttributeMap;\r
22 import com.ibm.richtext.textlayout.attributes.TextAttribute;\r
23 \r
24 import com.ibm.richtext.textpanel.TextPanel;\r
25 import com.ibm.richtext.textpanel.TextPanelSettings;\r
26 import com.ibm.richtext.awtui.AwtMenuBuilder;\r
27 \r
28 public class CodeEdit extends EditApplication {\r
29     \r
30     static final String COPYRIGHT =\r
31                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
32     \r
33     protected final TextPanelSettings fSettings;\r
34     \r
35     public static synchronized void main(String[] args) {\r
36 \r
37         if (args.length > 0 && args[0].equals("-swing")) {\r
38             new com.ibm.richtext.swingdemo.SwingCodeEdit(args,1);\r
39         }\r
40         else {\r
41             new CodeEdit(args, 0);\r
42         }\r
43     }\r
44 \r
45     protected CodeEdit(String[] args, int start) {\r
46 \r
47         super(Toolkit.getDefaultToolkit().getSystemClipboard(),\r
48               TextDocument.PLAIN_TEXT);\r
49 \r
50         AttributeMap defaultStyle = new AttributeMap(TextAttribute.SIZE, new Float(12))\r
51                                        .addAttribute(TextAttribute.FAMILY, "Monospaced");\r
52                                        \r
53         fSettings = TextPanel.getDefaultSettings();\r
54         fSettings.setWraps(false);\r
55         fSettings.addDefaultValues(defaultStyle);\r
56         \r
57         if (args.length == start) {\r
58             doNewWindow();\r
59         }\r
60         else {\r
61             boolean openedADocument = false;\r
62             for (int i=start; i < args.length; i++) {\r
63 \r
64                 File file = new File(args[i]);\r
65                 TextDocument document = null;\r
66                 Throwable error = null;\r
67                 try {\r
68                     document = TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);\r
69                 }\r
70                 catch(Exception e) {\r
71                     error = e;\r
72                 }\r
73                 \r
74                 if (error != null) {\r
75                     error.printStackTrace();\r
76                 }\r
77                 else {\r
78                     addDocument(document);\r
79                     openedADocument = true;\r
80                 }\r
81             }\r
82             if (!openedADocument) {\r
83                 quit();\r
84             }\r
85         }\r
86     }\r
87     \r
88     protected DocumentWindow createDocumentWindow(TextDocument document) {\r
89 \r
90         return new AwtDocumentWindow(this, \r
91                                   document,\r
92                                   fSettings,\r
93                                   false,\r
94                                   new SyntaxColorer(),\r
95                                   false,\r
96                                   true,\r
97                                   menus);\r
98     }\r
99     \r
100     protected static final int[] menus = { AwtMenuBuilder.EDIT, \r
101                                            AwtMenuBuilder.BIDI,\r
102                                            AwtMenuBuilder.ABOUT };\r
103 \r
104     public TextDocument openDocument(Frame dialogParent) {\r
105     \r
106         String title = ResourceUtils.getString(EditorResources.OPEN_TITLE);\r
107         \r
108         File file = AwtDocumentWindow.getFileFromDialog(null, title, dialogParent, FileDialog.LOAD);\r
109         if (file != null) {\r
110             try {\r
111                 return TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);\r
112             }\r
113             catch(Exception e) {\r
114                 System.out.print("");\r
115             }\r
116         }\r
117         return null;\r
118     }\r
119 }