Initial revision
[old-projects.git] / ekit / com / hexidec / ekit / Ekit.java
CommitLineData
c2da4d40
JL
1/*
2GNU Lesser General Public License
3
4Ekit - Java Swing HTML Editor & Viewer
5Copyright (C) 2000-2003 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.event.WindowEvent;
26import java.awt.event.WindowListener;
27import java.io.File;
28import java.net.MalformedURLException;
29import java.net.URL;
30import java.io.FileWriter;
31import javax.swing.JFrame;
32
33import com.hexidec.ekit.EkitCore;
34
35/** Ekit
36 * App for editing and saving HTML in a Java text 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
46public class Ekit extends JFrame implements WindowListener
47{
48 private EkitCore ekitCore;
49
50 private File currentFile = (File)null;
51
52 /** Master Constructor
53 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
54 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
55 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
56 * @param urlStyleSheet [URL] A URL reference to the CSS style sheet.
57 * @param showToolBar [boolean] Specifies whether the app should include the toolbar.
58 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
59 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
60 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
61 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
62 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
63 * @param base64 [boolean] Specifies whether the raw document is Base64 encoded or not.
64 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
65 */
66 public Ekit(String sDocument, String sStyleSheet, String sRawDocument, URL urlStyleSheet, boolean showToolBar, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64, boolean debugMode)
67 {
68 ekitCore = new EkitCore(sDocument, sStyleSheet, sRawDocument, urlStyleSheet, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, debugMode);
69
70 ekitCore.setFrame(this);
71
72 /* Add the components to the app */
73 this.getContentPane().setLayout(new BorderLayout());
74 this.getContentPane().add(ekitCore, BorderLayout.CENTER);
75 if(showToolBar)
76 {
77 this.getContentPane().add(ekitCore.getToolBar(showToolBar), BorderLayout.NORTH);
78 }
79
80 this.setJMenuBar(ekitCore.getMenuBar());
81
82 this.addWindowListener(this);
83
84 this.updateTitle();
85 this.pack();
86 this.show();
87 }
88
89 public Ekit()
90 {
91 this(null, null, null, null, true, false, true, true, null, null, false, false);
92 }
93
94 /* WindowListener methods */
95 public void windowClosing(WindowEvent we)
96 {
97 this.dispose();
98 System.exit(0);
99 }
100 public void windowOpened(WindowEvent we) { ; }
101 public void windowClosed(WindowEvent we) { ; }
102 public void windowActivated(WindowEvent we) { ; }
103 public void windowDeactivated(WindowEvent we) { ; }
104 public void windowIconified(WindowEvent we) { ; }
105 public void windowDeiconified(WindowEvent we) { ; }
106
107 /** Convenience method for updating the application title bar
108 */
109 private void updateTitle()
110 {
111 this.setTitle(ekitCore.getAppName() + (currentFile == null ? "" : " - " + currentFile.getName()));
112 }
113
114 /** Main method
115 */
116 public static void main(String[] args)
117 {
118 if(args.length > 0)
119 {
120 String sDocument = null;
121 String sStyleSheet = null;
122 String sRawDocument = null;
123 URL urlStyleSheet = null;
124 boolean includeToolBar = true;
125 boolean includeViewSource = false;
126 boolean includeMenuIcons = true;
127 boolean modeExclusive = true;
128 String sLang = null;
129 String sCtry = null;
130 boolean base64 = false;
131 boolean debugOn = false;
132 for(int i = 0; i < args.length; i++)
133 {
134 if (args[i].equals("-t")) { includeToolBar = true; }
135 else if(args[i].equals("-T")) { includeToolBar = false; }
136 else if(args[i].equals("-s")) { includeViewSource = true; }
137 else if(args[i].equals("-S")) { includeViewSource = false; }
138 else if(args[i].equals("-m")) { includeMenuIcons = true; }
139 else if(args[i].equals("-M")) { includeMenuIcons = false; }
140 else if(args[i].equals("-x")) { modeExclusive = true; }
141 else if(args[i].equals("-X")) { modeExclusive = false; }
142 else if(args[i].equals("-b")) { base64 = true; }
143 else if(args[i].equals("-B")) { base64 = false; }
144 else if(args[i].startsWith("-f")) { sDocument = args[i].substring(2, args[i].length()); }
145 else if(args[i].startsWith("-c")) { sStyleSheet = args[i].substring(2, args[i].length()); }
146 else if(args[i].startsWith("-r")) { sRawDocument = args[i].substring(2, args[i].length()); }
147 else if(args[i].startsWith("-u"))
148 {
149 try
150 {
151 urlStyleSheet = new URL(args[i].substring(2, args[i].length()));
152 }
153 catch(MalformedURLException murle)
154 {
155 murle.printStackTrace(System.err);
156 }
157 }
158 else if(args[i].startsWith("-l"))
159 {
160 if(args[i].indexOf('_') > -1)
161 {
162 sLang = args[i].substring(2, args[i].indexOf('_'));
163 sCtry = args[i].substring(args[i].indexOf('_') + 1, args[i].length());
164 }
165 }
166 else if(args[i].equals("-d")) { debugOn = true; }
167 else if(args[i].equals("-D")) { debugOn = false; }
168 }
169 Ekit ekit = new Ekit(sDocument, sStyleSheet, sRawDocument, urlStyleSheet, includeToolBar, includeViewSource, includeMenuIcons, modeExclusive, sLang, sCtry, base64, debugOn);
170 }
171 else
172 {
173 Ekit ekit = new Ekit();
174 }
175 }
176
177}