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
20 import java.io.StreamCorruptedException;
\r
21 import com.ibm.richtext.textpanel.TextPanel;
\r
24 * EditDemo is the main class for a simple, multiple-document
\r
25 * styled text editor, built with the classes in the textpanel
\r
26 * and textframe packages.
\r
28 * To run EditDemo, type:
\r
30 * java com.ibm.richtext.demo.EditDemo [file1] [file2] [...]
\r
31 * </pre></blockquote>
\r
32 * where the filenames are files saved with this demo.
\r
34 public class EditDemo extends EditApplication {
\r
36 static final String COPYRIGHT =
\r
37 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
39 public static synchronized void main(String[] args) {
\r
41 if (args.length > 0 && args[0].equals("-swing")) {
\r
42 new com.ibm.richtext.swingdemo.SwingEditDemo(args,1);
\r
45 new EditDemo(args, 0);
\r
49 protected EditDemo(String[] args, int start) {
\r
51 super(Toolkit.getDefaultToolkit().getSystemClipboard(),
\r
52 TextDocument.STYLED_TEXT);
\r
54 if (args.length == start) {
\r
58 boolean openedADocument = false;
\r
59 for (int i=start; i < args.length; i++) {
\r
61 File file = new File(args[i]);
\r
62 TextDocument document = getDocumentFromFile(file);
\r
64 if (document != null) {
\r
65 addDocument(document);
\r
66 openedADocument = true;
\r
69 if (!openedADocument) {
\r
75 public static TextDocument getDocumentFromFile(File file) {
\r
77 Exception exception = null;
\r
80 return TextDocument.createFromFile(file, TextDocument.STYLED_TEXT);
\r
82 catch(StreamCorruptedException e) {
\r
84 return TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
\r
86 catch(Exception e2) {
\r
90 catch(Exception e) {
\r
94 System.err.println("Exception opening file.");
\r
95 exception.printStackTrace();
\r
100 protected DocumentWindow createDocumentWindow(TextDocument document) {
\r
102 return new AwtDocumentWindow(this,
\r
104 TextPanel.getDefaultSettings(),
\r
112 public TextDocument openDocument(Frame dialogParent) {
\r
114 String title = ResourceUtils.getString(EditorResources.OPEN_TITLE);
\r
115 File file = AwtDocumentWindow.getFileFromDialog(null,
\r
119 if (file != null) {
\r
120 return getDocumentFromFile(file);
\r