94009704dfd692f3b3f1446e85f2db413bc17612
[old-projects.git] / ekit / com / hexidec / ekit / EkitApplet.java
1 /*
2 GNU Lesser General Public License
3
4 EkitApplet - Java Swing HTML Editor & Viewer Applet
5 Copyright (C) 2000-2003 Howard Kistler
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 package com.hexidec.ekit;
23
24 import java.awt.BorderLayout;
25 import java.awt.Toolkit;
26 import java.awt.event.KeyEvent;
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 import java.util.Vector;
30 import javax.swing.JApplet;
31 import javax.swing.JLabel;
32
33 import com.hexidec.ekit.EkitCore;
34
35 /** EkitApplet
36 * Applet for editing and saving HTML in a Java browser component
37 *
38 * @author Howard Kistler
39 * @version 0.9e
40 *
41 * REQUIREMENTS
42 * Java 2 (JDK 1.3 or 1.4)
43 * Swing Library
44 */
45
46 public class EkitApplet extends JApplet
47 {
48 /* Components */
49 EkitCore ekitCore;
50
51 private JLabel jlblStatus;
52
53 /** Constructor
54 */
55 public EkitApplet()
56 {
57 getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
58 }
59
60 /** Applet Init
61 */
62 public void init()
63 {
64 String sRawDocument = this.getParameter("DOCUMENT");
65 String sStyleSheetRef = this.getParameter("STYLESHEET");
66 boolean base64 = ((this.getParameter("BASE64") != null) && this.getParameter("BASE64").equalsIgnoreCase("true"));
67 URL urlCSS = (URL)null;
68 try
69 {
70 if(sStyleSheetRef != null && sStyleSheetRef.length() > 0)
71 {
72 urlCSS = new URL(this.getCodeBase(), sStyleSheetRef);
73 }
74 }
75 catch(MalformedURLException murle)
76 {
77 murle.printStackTrace(System.err);
78 }
79 boolean showToolBar = true;
80 if(this.getParameter("TOOLBAR") != null) { showToolBar = this.getParameter("TOOLBAR").equalsIgnoreCase("true"); }
81 boolean showViewSource = ((this.getParameter("SOURCEVIEW") != null && this.getParameter("SOURCEVIEW").equalsIgnoreCase("true")));
82 String sLanguage = this.getParameter("LANGCODE");
83 String sCountry = this.getParameter("LANGCOUNTRY");
84 boolean editModeExclusive = true;
85 if(this.getParameter("EXCLUSIVE") != null) { editModeExclusive = this.getParameter("EXCLUSIVE").equalsIgnoreCase("true"); }
86 boolean showMenuIcons = true;
87 if(this.getParameter("MENUICONS") != null) { showMenuIcons = this.getParameter("MENUICONS").equalsIgnoreCase("true"); }
88
89 ekitCore = new EkitCore(sRawDocument, urlCSS, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64);
90
91 /* Obtain image servlet information */
92 ekitCore.setServletURL(this.getParameter("SERVLETURL"));
93 ekitCore.setImageDir(this.getParameter("IMAGEDIR"));
94 ekitCore.setTreePilotSystemID(this.getParameter("SYSTEMID"));
95
96 /* Add menus, based on whether or not they are requested (all are shown by default) */
97 Vector vcMenus = new Vector();
98 if(this.getParameter("MENU_EDIT") != null) { if(this.getParameter("MENU_EDIT").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_EDIT); } } else { vcMenus.add(EkitCore.KEY_MENU_EDIT); }
99 if(this.getParameter("MENU_VIEW") != null) { if(this.getParameter("MENU_VIEW").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_VIEW); } } else { vcMenus.add(EkitCore.KEY_MENU_VIEW); }
100 if(this.getParameter("MENU_FONT") != null) { if(this.getParameter("MENU_FONT").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_FONT); } } else { vcMenus.add(EkitCore.KEY_MENU_FONT); }
101 if(this.getParameter("MENU_FORMAT") != null) { if(this.getParameter("MENU_FORMAT").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_FORMAT); } } else { vcMenus.add(EkitCore.KEY_MENU_FORMAT); }
102 if(this.getParameter("MENU_INSERT") != null) { if(this.getParameter("MENU_INSERT").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_INSERT); } } else { vcMenus.add(EkitCore.KEY_MENU_INSERT); }
103 if(this.getParameter("MENU_TABLE") != null) { if(this.getParameter("MENU_TABLE").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_TABLE); } } else { vcMenus.add(EkitCore.KEY_MENU_TABLE); }
104 if(this.getParameter("MENU_FORMS") != null) { if(this.getParameter("MENU_FORMS").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_FORMS); } } else { vcMenus.add(EkitCore.KEY_MENU_FORMS); }
105 if(this.getParameter("MENU_SEARCH") != null) { if(this.getParameter("MENU_SEARCH").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_SEARCH); } } else { vcMenus.add(EkitCore.KEY_MENU_SEARCH); }
106 if(this.getParameter("MENU_TOOLS") != null) { if(this.getParameter("MENU_TOOLS").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_TOOLS); } } else { vcMenus.add(EkitCore.KEY_MENU_TOOLS); }
107 if(this.getParameter("MENU_HELP") != null) { if(this.getParameter("MENU_HELP").equalsIgnoreCase("true")) { vcMenus.add(EkitCore.KEY_MENU_HELP); } } else { vcMenus.add(EkitCore.KEY_MENU_HELP); }
108 this.setJMenuBar(ekitCore.getCustomMenuBar(vcMenus));
109
110 jlblStatus = new JLabel();
111
112 /* Add the components to the app */
113 this.getContentPane().setLayout(new BorderLayout());
114 this.getContentPane().add(ekitCore, BorderLayout.CENTER);
115 this.getContentPane().add(jlblStatus, BorderLayout.SOUTH);
116 if(showToolBar)
117 {
118 Vector vcTools = new Vector();
119 vcTools.add(EkitCore.KEY_TOOL_NEW);
120 vcTools.add(EkitCore.KEY_TOOL_SEP);
121 vcTools.add(EkitCore.KEY_TOOL_CUT);
122 vcTools.add(EkitCore.KEY_TOOL_COPY);
123 vcTools.add(EkitCore.KEY_TOOL_PASTE);
124 vcTools.add(EkitCore.KEY_TOOL_SEP);
125 vcTools.add(EkitCore.KEY_TOOL_BOLD);
126 vcTools.add(EkitCore.KEY_TOOL_ITALIC);
127 vcTools.add(EkitCore.KEY_TOOL_UNDERLINE);
128 vcTools.add(EkitCore.KEY_TOOL_STRIKE);
129 vcTools.add(EkitCore.KEY_TOOL_SUPER);
130 vcTools.add(EkitCore.KEY_TOOL_SUB);
131 vcTools.add(EkitCore.KEY_TOOL_ULIST);
132 vcTools.add(EkitCore.KEY_TOOL_OLIST);
133 vcTools.add(EkitCore.KEY_TOOL_SEP);
134 vcTools.add(EkitCore.KEY_TOOL_CLEAR);
135 vcTools.add(EkitCore.KEY_TOOL_SEP);
136 vcTools.add(EkitCore.KEY_TOOL_ANCHOR);
137 vcTools.add(EkitCore.KEY_TOOL_SEP);
138 vcTools.add(EkitCore.KEY_TOOL_SOURCE);
139 vcTools.add(EkitCore.KEY_TOOL_SEP);
140 vcTools.add(EkitCore.KEY_TOOL_STYLES);
141 this.getContentPane().add(ekitCore.getCustomToolBar(vcTools, showToolBar), BorderLayout.NORTH);
142 }
143 }
144
145 /* Applet methods */
146 public void start() { ; }
147 public void stop() { ; }
148 public void destroy() { ; }
149
150 /** Method for passing back the document text to the applet's container.
151 * This is the entire document, including the top-level HTML tags.
152 */
153 public String getDocumentText()
154 {
155 return ekitCore.getDocumentText();
156 }
157
158 /** Method for passing back the document body to the applet's container.
159 * This is only the text contained within the BODY tags.
160 */
161 public String getDocumentBody()
162 {
163 return ekitCore.getDocumentSubText("body");
164 }
165
166 /** Method for setting the document manually.
167 * Will need code in the web page to call this.
168 */
169 public void setDocumentText(String text)
170 {
171 ekitCore.setDocumentText(text);
172 }
173
174 }