tentative merge of EKIT_0_9H and custom patches
[old-projects.git] / ekit / com / hexidec / ekit / Ekit.java
... / ...
CommitLineData
1/*
2GNU Lesser General Public License
3
4Ekit - Java Swing HTML Editor & Viewer
5Copyright (C) 2000 Howard Kistler
6
7This library is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/
21
22package com.hexidec.ekit;
23
24import java.awt.BorderLayout;
25import java.awt.GridLayout;
26import java.awt.GridBagLayout;
27import java.awt.GridBagConstraints;
28import java.awt.event.WindowEvent;
29import java.awt.event.WindowListener;
30import java.io.File;
31import java.io.FileWriter;
32import java.net.MalformedURLException;
33import java.net.URL;
34import java.util.Vector;
35import java.io.FileWriter;
36import javax.swing.JFrame;
37import javax.swing.JPanel;
38import javax.swing.JToolBar;
39
40import com.hexidec.ekit.EkitCore;
41//import com.hexidec.ekit.EkitCoreSpell;
42
43/** Ekit
44 * App for editing and saving HTML in a Java text component
45 *
46 * @author Howard Kistler
47 * @version 0.9h
48 *
49 * REQUIREMENTS
50 * Java 2 (JDK 1.3 or 1.4)
51 * Swing Library
52 */
53
54public class Ekit extends JFrame implements WindowListener
55{
56 private EkitCore ekitCore;
57
58 private File currentFile = (File)null;
59
60 /** Master Constructor
61 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
62 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
63 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
64 * @param urlStyleSheet [URL] A URL reference to the CSS style sheet.
65 * @param includeToolBar [boolean] Specifies whether the app should include the toolbar.
66 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
67 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
68 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
69 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
70 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
71 * @param base64 [boolean] Specifies whether the raw document is Base64 encoded or not.
72 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
73 * @param useSpellChecker [boolean] Specifies whether to include the spellchecker or not.
74 * @param multiBar [boolean] Specifies whether to use multiple toolbars or one big toolbar.
75 */
76 public Ekit(String sDocument, String sStyleSheet, String sRawDocument, URL urlStyleSheet, boolean includeToolBar, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64, boolean debugMode, boolean useSpellChecker, boolean multiBar)
77 {
78 if(useSpellChecker)
79 {
80// ekitCore = new EkitCoreSpell(sDocument, sStyleSheet, sRawDocument, urlStyleSheet, includeToolBar, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, debugMode, true, multiBar);
81 }
82 else
83 {
84 ekitCore = new EkitCore(sDocument, sStyleSheet, sRawDocument, urlStyleSheet, includeToolBar, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, debugMode, false, multiBar);
85 }
86
87 ekitCore.setFrame(this);
88
89 /* Add the components to the app */
90 if(includeToolBar)
91 {
92 if(multiBar)
93 {
94 this.getContentPane().setLayout(new GridBagLayout());
95 GridBagConstraints gbc = new GridBagConstraints();
96 gbc.fill = GridBagConstraints.HORIZONTAL;
97 gbc.anchor = GridBagConstraints.NORTH;
98 gbc.gridheight = 1;
99 gbc.gridwidth = 1;
100 gbc.weightx = 1.0;
101 gbc.weighty = 0.0;
102 gbc.gridx = 1;
103
104 gbc.gridy = 1;
105 this.getContentPane().add(ekitCore.getToolBarMain(includeToolBar), gbc);
106
107 gbc.gridy = 2;
108 this.getContentPane().add(ekitCore.getToolBarFormat(includeToolBar), gbc);
109
110 gbc.gridy = 3;
111 this.getContentPane().add(ekitCore.getToolBarStyles(includeToolBar), gbc);
112
113 gbc.anchor = GridBagConstraints.SOUTH;
114 gbc.fill = GridBagConstraints.BOTH;
115 gbc.weighty = 1.0;
116 gbc.gridy = 4;
117 this.getContentPane().add(ekitCore, gbc);
118 }
119 else
120 {
121 this.getContentPane().setLayout(new BorderLayout());
122 this.getContentPane().add(ekitCore, BorderLayout.CENTER);
123 this.getContentPane().add(ekitCore.getToolBar(includeToolBar), BorderLayout.NORTH);
124 }
125 }
126 else
127 {
128 this.getContentPane().setLayout(new BorderLayout());
129 this.getContentPane().add(ekitCore, BorderLayout.CENTER);
130 }
131
132 this.setJMenuBar(ekitCore.getMenuBar());
133
134 this.addWindowListener(this);
135
136 this.updateTitle();
137 this.pack();
138 this.show();
139 }
140
141 public Ekit()
142 {
143 this(null, null, null, null, true, false, true, true, null, null, false, false, false, false);
144 }
145
146 /* WindowListener methods */
147 public void windowClosing(WindowEvent we)
148 {
149 this.dispose();
150 System.exit(0);
151 }
152 public void windowOpened(WindowEvent we) { ; }
153 public void windowClosed(WindowEvent we) { ; }
154 public void windowActivated(WindowEvent we) { ; }
155 public void windowDeactivated(WindowEvent we) { ; }
156 public void windowIconified(WindowEvent we) { ; }
157 public void windowDeiconified(WindowEvent we) { ; }
158
159 /** Convenience method for updating the application title bar
160 */
161 private void updateTitle()
162 {
163 this.setTitle(ekitCore.getAppName() + (currentFile == null ? "" : " - " + currentFile.getName()));
164 }
165
166 /** Usage method
167 */
168 public static void usage()
169 {
170 System.out.println("usage: com.hexidec.ekit.Ekit [-t|t+|T] [-s|S] [-m|M] [-x|X] [-b|B] [-v|V] [-fFILE] [-cCSS] [-rRAW] [-uURL] [-lLANG] [-d|D]");
171 System.out.println(" Each option contained in [] brackets is optional,");
172 System.out.println(" and can be one of the values separated be the | pipe.");
173 System.out.println(" Each option must be proceeded by a - hyphen.");
174 System.out.println(" The options are:");
175 System.out.println(" t|t+|T : -t = single toolbar, -t+ = multiple toolbars, -T = no toolbar");
176 System.out.println(" s|S : -s = show source window on startup, -S hide source window");
177 System.out.println(" m|M : -m = show icons on menus, -M no menu icons");
178 System.out.println(" x|X : -x = exclusive document/source windows, -X use split window");
179 System.out.println(" b|B : -b = use Base64 document encoding, -B use regular encoding");
180 System.out.println(" v|V : -v = include spell checker, -V omit spell checker");
181 System.out.println(" -fFILE : load HTML document on startup (replace FILE with file name)");
182 System.out.println(" -cCSS : load CSS stylesheet on startup (replace CSS with file name)");
183 System.out.println(" -rRAW : load raw document on startup (replace RAW with file name)");
184 System.out.println(" -uURL : load document at URL on startup (replace URL with file URL)");
185 System.out.println(" -lLANG : specify the starting language (defaults to your locale)");
186 System.out.println(" replace LANG with xx_XX format (i.e., US English is en_US)");
187 System.out.println(" -d|D : -d = DEBUG mode on, -D DEBUG mode off (developers only)");
188 System.out.println(" -h|H|? : print out this help information");
189 System.out.println(" ");
190 System.out.println("The defaults settings are equivalent to: -t -S -m -x -B -V -D");
191 System.out.println(" ");
192 System.out.println("For further information, read the README file.");
193 }
194
195 /** Main method
196 */
197 public static void main(String[] args)
198 {
199 if(args.length > 0)
200 {
201 String sDocument = null;
202 String sStyleSheet = null;
203 String sRawDocument = null;
204 URL urlStyleSheet = null;
205 boolean includeToolBar = true;
206 boolean includeViewSource = false;
207 boolean includeMenuIcons = true;
208 boolean modeExclusive = true;
209 String sLang = null;
210 String sCtry = null;
211 boolean base64 = false;
212 boolean debugOn = false;
213 boolean spellCheck = false;
214 boolean multibar = false;
215 for(int i = 0; i < args.length; i++)
216 {
217 if (args[i].equals("-h") || args[i].equals("-H") || args[i].equals("-?"))
218 {
219 usage();
220 System.exit(0);
221 }
222 else if(args[i].equals("-t")) { includeToolBar = true; }
223 else if(args[i].equals("-t+")) { includeToolBar = true; multibar = true; }
224 else if(args[i].equals("-T")) { includeToolBar = false; }
225 else if(args[i].equals("-s")) { includeViewSource = true; }
226 else if(args[i].equals("-S")) { includeViewSource = false; }
227 else if(args[i].equals("-m")) { includeMenuIcons = true; }
228 else if(args[i].equals("-M")) { includeMenuIcons = false; }
229 else if(args[i].equals("-x")) { modeExclusive = true; }
230 else if(args[i].equals("-X")) { modeExclusive = false; }
231 else if(args[i].equals("-b")) { base64 = true; }
232 else if(args[i].equals("-B")) { base64 = false; }
233 else if(args[i].startsWith("-f")) { sDocument = args[i].substring(2, args[i].length()); }
234 else if(args[i].startsWith("-c")) { sStyleSheet = args[i].substring(2, args[i].length()); }
235 else if(args[i].startsWith("-r")) { sRawDocument = args[i].substring(2, args[i].length()); }
236 else if(args[i].equals("-v")) { spellCheck = true; }
237 else if(args[i].equals("-V")) { spellCheck = false; }
238 else if(args[i].startsWith("-u"))
239 {
240 try
241 {
242 urlStyleSheet = new URL(args[i].substring(2, args[i].length()));
243 }
244 catch(MalformedURLException murle)
245 {
246 murle.printStackTrace(System.err);
247 }
248 }
249 else if(args[i].startsWith("-l"))
250 {
251 if(args[i].indexOf('_') > -1)
252 {
253 sLang = args[i].substring(2, args[i].indexOf('_'));
254 sCtry = args[i].substring(args[i].indexOf('_') + 1, args[i].length());
255 }
256 }
257 else if(args[i].equals("-d")) { debugOn = true; }
258 else if(args[i].equals("-D")) { debugOn = false; }
259 }
260 Ekit ekit = new Ekit(sDocument, sStyleSheet, sRawDocument, urlStyleSheet, includeToolBar, includeViewSource, includeMenuIcons, modeExclusive, sLang, sCtry, base64, debugOn, spellCheck, multibar);
261 }
262 else
263 {
264 Ekit ekit = new Ekit();
265 }
266 }
267
268}