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.event.ActionListener;
\r
16 import java.awt.event.ActionEvent;
\r
19 * This class creates a File menu and manages user interactions
\r
22 public abstract class FileMenuManager implements ActionListener {
\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
31 protected FileMenuManager(EditApplication application,
\r
32 DocumentWindow document) {
\r
34 fApplication = application;
\r
35 fDocumentWindow = document;
\r
38 protected final void createItems(boolean supportStyledFormat,
\r
39 boolean supportPlainFormat) {
\r
41 if (!supportStyledFormat && !supportPlainFormat) {
\r
42 throw new IllegalArgumentException("Must support at least one format.");
\r
45 fNew = addMenuItem(EditorResources.NEW);
\r
46 fNewWindow = addMenuItem(EditorResources.NEW_WINDOW);
\r
50 fOpen = addMenuItem(EditorResources.OPEN);
\r
52 fSave = addMenuItem(EditorResources.SAVE);
\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
60 fSaveAsStyled = addMenuItem(EditorResources.SAVE_AS);
\r
64 fSaveAsText = addMenuItem(EditorResources.SAVE_AS);
\r
68 fClose = addMenuItem(EditorResources.CLOSE);
\r
70 fPrint = addMenuItem(EditorResources.PRINT);
\r
72 fExit = addMenuItem(EditorResources.EXIT);
\r
75 protected abstract Object addMenuItem(String key);
\r
77 protected abstract void addSeparator();
\r
79 public final void actionPerformed(ActionEvent event) {
\r
81 Object source = event.getSource();
\r
83 if (source == fNew) {
\r
84 fDocumentWindow.doNew();
\r
86 else if (source == fNewWindow) {
\r
87 fApplication.doNewWindow();
\r
89 else if (source == fOpen) {
\r
90 fDocumentWindow.doOpen();
\r
92 else if (source == fClose) {
\r
93 fDocumentWindow.doClose();
\r
95 else if (source == fSave) {
\r
96 fDocumentWindow.doSave();
\r
98 else if (source == fSaveAsStyled) {
\r
99 fDocumentWindow.doSaveAs(TextDocument.STYLED_TEXT);
\r
101 else if (source == fSaveAsText) {
\r
102 fDocumentWindow.doSaveAs(TextDocument.PLAIN_TEXT);
\r
104 else if (source == fPrint) {
\r
105 fDocumentWindow.doPrint();
\r
107 else if (source == fExit) {
\r
108 fApplication.doExit();
\r
111 throw new Error("Unknown event source: " + source);
\r