]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/demo/FileMenuManager.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / demo / FileMenuManager.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.event.ActionListener;\r
16 import java.awt.event.ActionEvent;\r
17 \r
18 /**\r
19  * This class creates a File menu and manages user interactions\r
20  * with the menu.\r
21  */\r
22 public abstract class FileMenuManager implements ActionListener {\r
23 \r
24     static final String COPYRIGHT =\r
25                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
26     private EditApplication fApplication;\r
27     private DocumentWindow fDocumentWindow;\r
28     private Object fNew, fNewWindow, fOpen, fSave;\r
29     private Object fSaveAsStyled, fSaveAsText, fClose, fPrint, fExit;\r
30 \r
31     protected FileMenuManager(EditApplication application, \r
32                               DocumentWindow document) {\r
33 \r
34         fApplication = application;\r
35         fDocumentWindow = document;\r
36     }\r
37     \r
38     protected final void createItems(boolean supportStyledFormat,\r
39                                      boolean supportPlainFormat) {\r
40         \r
41         if (!supportStyledFormat && !supportPlainFormat) {\r
42             throw new IllegalArgumentException("Must support at least one format.");\r
43         }\r
44         \r
45         fNew = addMenuItem(EditorResources.NEW);\r
46         fNewWindow = addMenuItem(EditorResources.NEW_WINDOW);\r
47         \r
48         addSeparator();\r
49 \r
50         fOpen = addMenuItem(EditorResources.OPEN);\r
51 \r
52         fSave = addMenuItem(EditorResources.SAVE);\r
53         \r
54         if (supportStyledFormat) {\r
55             if (supportPlainFormat) {\r
56                 fSaveAsStyled = addMenuItem(EditorResources.SAVE_AS_STYLED);\r
57                 fSaveAsText = addMenuItem(EditorResources.SAVE_AS_TEXT);\r
58             }\r
59             else {\r
60                 fSaveAsStyled = addMenuItem(EditorResources.SAVE_AS);\r
61             }\r
62         }\r
63         else {\r
64             fSaveAsText = addMenuItem(EditorResources.SAVE_AS);\r
65         }\r
66         \r
67         addSeparator();\r
68         fClose = addMenuItem(EditorResources.CLOSE);\r
69         addSeparator();\r
70         fPrint = addMenuItem(EditorResources.PRINT);\r
71         addSeparator();\r
72         fExit = addMenuItem(EditorResources.EXIT);\r
73     }\r
74     \r
75     protected abstract Object addMenuItem(String key);\r
76 \r
77     protected abstract void addSeparator();\r
78     \r
79     public final void actionPerformed(ActionEvent event) {\r
80 \r
81         Object source = event.getSource();\r
82 \r
83         if (source == fNew) {\r
84             fDocumentWindow.doNew();\r
85         }\r
86         else if (source == fNewWindow) {\r
87             fApplication.doNewWindow();\r
88         }\r
89         else if (source == fOpen) {\r
90             fDocumentWindow.doOpen();\r
91         }\r
92         else if (source == fClose) {\r
93             fDocumentWindow.doClose();\r
94         }\r
95         else if (source == fSave) {\r
96             fDocumentWindow.doSave();\r
97         }\r
98         else if (source == fSaveAsStyled) {\r
99             fDocumentWindow.doSaveAs(TextDocument.STYLED_TEXT);\r
100         }\r
101         else if (source == fSaveAsText) {\r
102             fDocumentWindow.doSaveAs(TextDocument.PLAIN_TEXT);\r
103         }\r
104         else if (source == fPrint) {\r
105             fDocumentWindow.doPrint();\r
106         }\r
107         else if (source == fExit) {\r
108             fApplication.doExit();\r
109         }\r
110         else {\r
111             throw new Error("Unknown event source: " + source);\r
112         }\r
113     }\r
114 }