2 * (C) Copyright IBM Corp. 1998-2004. 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.demo;
\r
15 import java.awt.FileDialog;
\r
16 import java.awt.Frame;
\r
17 import java.awt.Toolkit;
\r
19 import java.io.File;
\r
21 import com.ibm.richtext.textlayout.attributes.AttributeMap;
\r
22 import com.ibm.richtext.textlayout.attributes.TextAttribute;
\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
28 public class CodeEdit extends EditApplication {
\r
30 static final String COPYRIGHT =
\r
31 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
33 protected final TextPanelSettings fSettings;
\r
35 public static synchronized void main(String[] args) {
\r
37 if (args.length > 0 && args[0].equals("-swing")) {
\r
38 new com.ibm.richtext.swingdemo.SwingCodeEdit(args,1);
\r
41 new CodeEdit(args, 0);
\r
45 protected CodeEdit(String[] args, int start) {
\r
47 super(Toolkit.getDefaultToolkit().getSystemClipboard(),
\r
48 TextDocument.PLAIN_TEXT);
\r
50 AttributeMap defaultStyle = new AttributeMap(TextAttribute.SIZE, new Float(12))
\r
51 .addAttribute(TextAttribute.FAMILY, "Monospaced");
\r
53 fSettings = TextPanel.getDefaultSettings();
\r
54 fSettings.setWraps(false);
\r
55 fSettings.addDefaultValues(defaultStyle);
\r
57 if (args.length == start) {
\r
61 boolean openedADocument = false;
\r
62 for (int i=start; i < args.length; i++) {
\r
64 File file = new File(args[i]);
\r
65 TextDocument document = null;
\r
66 Throwable error = null;
\r
68 document = TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
\r
70 catch(Exception e) {
\r
74 if (error != null) {
\r
75 error.printStackTrace();
\r
78 addDocument(document);
\r
79 openedADocument = true;
\r
82 if (!openedADocument) {
\r
88 protected DocumentWindow createDocumentWindow(TextDocument document) {
\r
90 return new AwtDocumentWindow(this,
\r
94 new SyntaxColorer(),
\r
100 protected static final int[] menus = { AwtMenuBuilder.EDIT,
\r
101 AwtMenuBuilder.BIDI,
\r
102 AwtMenuBuilder.ABOUT };
\r
104 public TextDocument openDocument(Frame dialogParent) {
\r
106 String title = ResourceUtils.getString(EditorResources.OPEN_TITLE);
\r
108 File file = AwtDocumentWindow.getFileFromDialog(null, title, dialogParent, FileDialog.LOAD);
\r
109 if (file != null) {
\r
111 return TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
\r
113 catch(Exception e) {
\r
114 System.out.print("");
\r