Commit | Line | Data |
---|---|---|
c2da4d40 JL |
1 | /* |
2 | GNU Lesser General Public License | |
3 | ||
4 | EkitApplet - Java Swing HTML Editor & Viewer Applet | |
b6b7ed68 | 5 | Copyright (C) 2000 Howard Kistler |
c2da4d40 JL |
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; | |
b6b7ed68 JL |
25 | import java.awt.GridBagLayout; |
26 | import java.awt.GridBagConstraints; | |
c2da4d40 JL |
27 | import java.awt.Toolkit; |
28 | import java.awt.event.KeyEvent; | |
29 | import java.net.MalformedURLException; | |
30 | import java.net.URL; | |
31 | import java.util.Vector; | |
32 | import javax.swing.JApplet; | |
33 | import javax.swing.JLabel; | |
34 | ||
35 | import com.hexidec.ekit.EkitCore; | |
36 | ||
37 | /** EkitApplet | |
38 | * Applet for editing and saving HTML in a Java browser component | |
39 | * | |
40 | * @author Howard Kistler | |
41 | * @version 0.9e | |
42 | * | |
43 | * REQUIREMENTS | |
44 | * Java 2 (JDK 1.3 or 1.4) | |
45 | * Swing Library | |
46 | */ | |
47 | ||
48 | public class EkitApplet extends JApplet | |
49 | { | |
50 | /* Components */ | |
51 | EkitCore ekitCore; | |
52 | ||
c2da4d40 JL |
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; | |
b6b7ed68 | 80 | boolean showToolBarMulti = false; |
c2da4d40 | 81 | if(this.getParameter("TOOLBAR") != null) { showToolBar = this.getParameter("TOOLBAR").equalsIgnoreCase("true"); } |
b6b7ed68 | 82 | if(this.getParameter("TOOLBARMULTI") != null) { showToolBar = this.getParameter("TOOLBARMULTI").equalsIgnoreCase("true"); showToolBarMulti = this.getParameter("TOOLBARMULTI").equalsIgnoreCase("true"); } |
c2da4d40 JL |
83 | boolean showViewSource = ((this.getParameter("SOURCEVIEW") != null && this.getParameter("SOURCEVIEW").equalsIgnoreCase("true"))); |
84 | String sLanguage = this.getParameter("LANGCODE"); | |
85 | String sCountry = this.getParameter("LANGCOUNTRY"); | |
86 | boolean editModeExclusive = true; | |
87 | if(this.getParameter("EXCLUSIVE") != null) { editModeExclusive = this.getParameter("EXCLUSIVE").equalsIgnoreCase("true"); } | |
88 | boolean showMenuIcons = true; | |
89 | if(this.getParameter("MENUICONS") != null) { showMenuIcons = this.getParameter("MENUICONS").equalsIgnoreCase("true"); } | |
b6b7ed68 JL |
90 | boolean spellChecker = false; |
91 | if(this.getParameter("SPELLCHECK") != null) { spellChecker = this.getParameter("SPELLCHECK").equalsIgnoreCase("true"); } | |
c2da4d40 | 92 | |
b6b7ed68 JL |
93 | if(spellChecker) |
94 | { | |
95 | //ekitCore = new EkitCoreSpell(sRawDocument, urlCSS, showToolBar, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, showToolBarMulti, this.getParameter("BASEURL")); | |
96 | } | |
97 | else | |
98 | { | |
99 | ekitCore = new EkitCore(sRawDocument, urlCSS, showToolBar, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, false, showToolBarMulti, this.getParameter("BASEURL")); | |
100 | } | |
c2da4d40 JL |
101 | |
102 | /* Obtain image servlet information */ | |
103 | ekitCore.setServletURL(this.getParameter("SERVLETURL")); | |
104 | ekitCore.setImageDir(this.getParameter("IMAGEDIR")); | |
105 | ekitCore.setTreePilotSystemID(this.getParameter("SYSTEMID")); | |
106 | ||
107 | /* Add menus, based on whether or not they are requested (all are shown by default) */ | |
108 | Vector vcMenus = new Vector(); | |
109 | 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); } | |
110 | 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); } | |
111 | 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); } | |
112 | 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); } | |
113 | 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); } | |
114 | 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); } | |
115 | 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); } | |
116 | 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); } | |
117 | 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); } | |
118 | 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); } | |
119 | this.setJMenuBar(ekitCore.getCustomMenuBar(vcMenus)); | |
120 | ||
c2da4d40 | 121 | /* Add the components to the app */ |
c2da4d40 JL |
122 | if(showToolBar) |
123 | { | |
b6b7ed68 JL |
124 | if(showToolBarMulti) |
125 | { | |
126 | this.getContentPane().setLayout(new GridBagLayout()); | |
127 | GridBagConstraints gbc = new GridBagConstraints(); | |
128 | gbc.fill = GridBagConstraints.HORIZONTAL; | |
129 | gbc.anchor = GridBagConstraints.NORTH; | |
130 | gbc.gridheight = 1; | |
131 | gbc.gridwidth = 1; | |
132 | gbc.weightx = 1.0; | |
133 | gbc.weighty = 0.0; | |
134 | gbc.gridx = 1; | |
135 | ||
136 | gbc.gridy = 1; | |
137 | Vector vcTools = new Vector(); | |
138 | vcTools.add(EkitCore.KEY_TOOL_NEW); | |
139 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
140 | vcTools.add(EkitCore.KEY_TOOL_CUT); | |
141 | vcTools.add(EkitCore.KEY_TOOL_COPY); | |
142 | vcTools.add(EkitCore.KEY_TOOL_PASTE); | |
143 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
144 | vcTools.add(EkitCore.KEY_TOOL_CLEAR); | |
145 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
146 | vcTools.add(EkitCore.KEY_TOOL_ANCHOR); | |
147 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
148 | vcTools.add(EkitCore.KEY_TOOL_SOURCE); | |
149 | this.getContentPane().add(ekitCore.customizeToolBar(EkitCore.TOOLBAR_MAIN, vcTools, showToolBar), gbc); | |
150 | ||
151 | gbc.gridy = 2; | |
152 | this.getContentPane().add(ekitCore.getToolBarFormat(showToolBar), gbc); | |
153 | ||
154 | gbc.gridy = 3; | |
155 | this.getContentPane().add(ekitCore.getToolBarStyles(showToolBar), gbc); | |
156 | ||
157 | gbc.anchor = GridBagConstraints.CENTER; | |
158 | gbc.fill = GridBagConstraints.BOTH; | |
159 | gbc.weighty = 1.0; | |
160 | gbc.gridy = 4; | |
161 | this.getContentPane().add(ekitCore, gbc); | |
162 | } | |
163 | else | |
164 | { | |
165 | Vector vcTools = new Vector(); | |
166 | vcTools.add(EkitCore.KEY_TOOL_NEW); | |
167 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
168 | vcTools.add(EkitCore.KEY_TOOL_CUT); | |
169 | vcTools.add(EkitCore.KEY_TOOL_COPY); | |
170 | vcTools.add(EkitCore.KEY_TOOL_PASTE); | |
171 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
172 | vcTools.add(EkitCore.KEY_TOOL_BOLD); | |
173 | vcTools.add(EkitCore.KEY_TOOL_ITALIC); | |
174 | vcTools.add(EkitCore.KEY_TOOL_UNDERLINE); | |
175 | vcTools.add(EkitCore.KEY_TOOL_STRIKE); | |
176 | vcTools.add(EkitCore.KEY_TOOL_SUPER); | |
177 | vcTools.add(EkitCore.KEY_TOOL_SUB); | |
178 | vcTools.add(EkitCore.KEY_TOOL_ULIST); | |
179 | vcTools.add(EkitCore.KEY_TOOL_OLIST); | |
180 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
181 | vcTools.add(EkitCore.KEY_TOOL_CLEAR); | |
182 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
183 | vcTools.add(EkitCore.KEY_TOOL_ANCHOR); | |
184 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
185 | vcTools.add(EkitCore.KEY_TOOL_SOURCE); | |
186 | vcTools.add(EkitCore.KEY_TOOL_SEP); | |
187 | vcTools.add(EkitCore.KEY_TOOL_STYLES); | |
188 | ||
189 | this.getContentPane().setLayout(new BorderLayout()); | |
190 | this.getContentPane().add(ekitCore, BorderLayout.CENTER); | |
191 | this.getContentPane().add(ekitCore.customizeToolBar(EkitCore.TOOLBAR_MAIN, vcTools, showToolBar), BorderLayout.NORTH); | |
192 | } | |
c2da4d40 JL |
193 | } |
194 | } | |
195 | ||
196 | /* Applet methods */ | |
197 | public void start() { ; } | |
198 | public void stop() { ; } | |
199 | public void destroy() { ; } | |
200 | ||
201 | /** Method for passing back the document text to the applet's container. | |
202 | * This is the entire document, including the top-level HTML tags. | |
203 | */ | |
204 | public String getDocumentText() | |
205 | { | |
206 | return ekitCore.getDocumentText(); | |
207 | } | |
208 | ||
209 | /** Method for passing back the document body to the applet's container. | |
210 | * This is only the text contained within the BODY tags. | |
211 | */ | |
212 | public String getDocumentBody() | |
213 | { | |
214 | return ekitCore.getDocumentSubText("body"); | |
215 | } | |
216 | ||
217 | /** Method for setting the document manually. | |
218 | * Will need code in the web page to call this. | |
219 | */ | |
220 | public void setDocumentText(String text) | |
221 | { | |
222 | ekitCore.setDocumentText(text); | |
223 | } | |
224 | ||
225 | } |