Import of Ekit 0.9h
[old-projects.git] / ekit / com / hexidec / ekit / EkitCore_Basic.java
1 /*
2 GNU Lesser General Public License
3
4 EkitCore - Base Java Swing HTML Editor & Viewer Class (Basic Version)
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.Color;
26 import java.awt.Cursor;
27 import java.awt.Dimension;
28 import java.awt.Frame;
29 import java.awt.Graphics;
30 import java.awt.Image;
31 import java.awt.Insets;
32 import java.awt.Toolkit;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.awt.event.KeyEvent;
36 import java.awt.event.KeyListener;
37 import java.io.BufferedReader;
38 import java.io.File;
39 import java.io.FileInputStream;
40 import java.io.FileOutputStream;
41 import java.io.FileReader;
42 import java.io.FileWriter;
43 import java.io.InputStream;
44 import java.io.InputStreamReader;
45 import java.io.IOException;
46 import java.io.ObjectInputStream;
47 import java.io.ObjectOutputStream;
48 import java.io.Reader;
49 import java.net.URL;
50 import java.net.URLConnection;
51 import java.net.MalformedURLException;
52 import java.util.Enumeration;
53 import java.util.Hashtable;
54 import java.util.Locale;
55 import java.util.MissingResourceException;
56 import java.util.ResourceBundle;
57 import java.util.Vector;
58 import javax.swing.AbstractAction;
59 import javax.swing.Action;
60 import javax.swing.Icon;
61 import javax.swing.ImageIcon;
62 import javax.swing.JButton;
63 import javax.swing.JCheckBox;
64 import javax.swing.JCheckBoxMenuItem;
65 import javax.swing.JComboBox;
66 import javax.swing.JComponent;
67 import javax.swing.JDialog;
68 import javax.swing.JEditorPane;
69 import javax.swing.JFileChooser;
70 import javax.swing.JFrame;
71 import javax.swing.JMenu;
72 import javax.swing.JMenuBar;
73 import javax.swing.JMenuItem;
74 import javax.swing.JOptionPane;
75 import javax.swing.JPanel;
76 import javax.swing.JScrollPane;
77 import javax.swing.JSplitPane;
78 import javax.swing.JTextField;
79 import javax.swing.JTextPane;
80 import javax.swing.JToggleButton;
81 import javax.swing.JToolBar;
82 import javax.swing.KeyStroke;
83 import javax.swing.event.CaretEvent;
84 import javax.swing.event.CaretListener;
85 import javax.swing.event.DocumentEvent;
86 import javax.swing.event.DocumentListener;
87 import javax.swing.event.UndoableEditEvent;
88 import javax.swing.event.UndoableEditListener;
89 import javax.swing.filechooser.FileFilter;
90 import javax.swing.text.AttributeSet;
91 import javax.swing.text.BadLocationException;
92 import javax.swing.text.ChangedCharSetException;
93 import javax.swing.text.DefaultEditorKit;
94 import javax.swing.text.DefaultStyledDocument;
95 import javax.swing.text.Document;
96 import javax.swing.text.Element;
97 import javax.swing.text.PlainDocument;
98 import javax.swing.text.Position;
99 import javax.swing.text.Style;
100 import javax.swing.text.StyleConstants;
101 import javax.swing.text.StyledDocument;
102 import javax.swing.text.StyledEditorKit;
103 import javax.swing.text.StyledEditorKit.FontSizeAction;
104 import javax.swing.text.html.HTML;
105 import javax.swing.text.html.HTMLDocument;
106 import javax.swing.text.html.HTMLEditorKit;
107 import javax.swing.text.html.StyleSheet;
108 import javax.swing.text.rtf.RTFEditorKit;
109 import javax.swing.undo.UndoManager;
110 import javax.swing.undo.CannotUndoException;
111
112 import com.hexidec.ekit.action.*;
113 import com.hexidec.ekit.component.*;
114 import com.hexidec.util.Base64Codec;
115 import com.hexidec.util.Translatrix;
116
117 /** EkitCore
118 * Main application class for editing and saving HTML in a Java text component
119 *
120 * @author Howard Kistler
121 * @version 0.9g
122 *
123 * REQUIREMENTS
124 * Java 2 (JDK 1.3 or 1.4)
125 * Swing Library
126 */
127
128 public class EkitCore extends JPanel implements ActionListener, KeyListener, DocumentListener
129 {
130 /* Components */
131 private JSplitPane jspltDisplay;
132 private JTextPane jtpMain;
133 private ExtendedHTMLEditorKit htmlKit;
134 private ExtendedHTMLDocument htmlDoc;
135 private StyleSheet styleSheet;
136 private JTextPane jtpSource;
137 private JScrollPane jspSource;
138 private JToolBar jToolBar;
139
140 private JCheckBoxMenuItem jcbmiViewToolbar;
141 private JCheckBoxMenuItem jcbmiViewSource;
142
143 private JButtonNoFocus jbtnNewHTML;
144 private JButtonNoFocus jbtnOpenHTML;
145 private JButtonNoFocus jbtnSaveHTML;
146 private JButtonNoFocus jbtnCut;
147 private JButtonNoFocus jbtnCopy;
148 private JButtonNoFocus jbtnPaste;
149 private JButtonNoFocus jbtnBold;
150 private JButtonNoFocus jbtnItalic;
151 private JButtonNoFocus jbtnUnderline;
152 private JButtonNoFocus jbtnStrike;
153 private JButtonNoFocus jbtnSuperscript;
154 private JButtonNoFocus jbtnSubscript;
155 private JButtonNoFocus jbtnUList;
156 private JButtonNoFocus jbtnOList;
157 private JButtonNoFocus jbtnClearFormat;
158 private JButtonNoFocus jbtnAnchor;
159 private JToggleButtonNoFocus jtbtnViewSource;
160 private JComboBoxNoFocus jcmbStyleSelector;
161
162 private Frame frameHandler;
163
164 private HTMLUtilities htmlUtilities = new HTMLUtilities(this);
165
166 /* Actions */
167 private StyledEditorKit.BoldAction actionFontBold;
168 private StyledEditorKit.ItalicAction actionFontItalic;
169 private StyledEditorKit.UnderlineAction actionFontUnderline;
170 private FormatAction actionFontStrike;
171 private FormatAction actionFontSuperscript;
172 private FormatAction actionFontSubscript;
173 private ListAutomationAction actionListUnordered;
174 private ListAutomationAction actionListOrdered;
175 private CustomAction actionSelectFont;
176 private CustomAction actionClearFormat;
177 private CustomAction actionInsertAnchor;
178
179 protected UndoManager undoMngr;
180 protected UndoAction undoAction;
181 protected RedoAction redoAction;
182
183 /* Menus */
184 private JMenuBar jMenuBar;
185 private JMenu jMenuFile;
186 private JMenu jMenuEdit;
187 private JMenu jMenuView;
188 private JMenu jMenuFont;
189 private JMenu jMenuFormat;
190 private JMenu jMenuInsert;
191 private JMenu jMenuTable;
192 private JMenu jMenuForms;
193 private JMenu jMenuSearch;
194 private JMenu jMenuHelp;
195 private JMenu jMenuDebug;
196
197 /* Constants */
198 // Menu Keys
199 public static final String KEY_MENU_FILE = "file";
200 public static final String KEY_MENU_EDIT = "edit";
201 public static final String KEY_MENU_VIEW = "view";
202 public static final String KEY_MENU_FONT = "font";
203 public static final String KEY_MENU_FORMAT = "format";
204 public static final String KEY_MENU_INSERT = "insert";
205 public static final String KEY_MENU_TABLE = "table";
206 public static final String KEY_MENU_FORMS = "forms";
207 public static final String KEY_MENU_SEARCH = "search";
208 public static final String KEY_MENU_TOOLS = "tools";
209 public static final String KEY_MENU_HELP = "help";
210 public static final String KEY_MENU_DEBUG = "debug";
211
212 // Tool Keys
213 public static final String KEY_TOOL_SEP = "separator";
214 public static final String KEY_TOOL_NEW = "new";
215 public static final String KEY_TOOL_OPEN = "open";
216 public static final String KEY_TOOL_SAVE = "save";
217 public static final String KEY_TOOL_CUT = "cut";
218 public static final String KEY_TOOL_COPY = "copy";
219 public static final String KEY_TOOL_PASTE = "paste";
220 public static final String KEY_TOOL_BOLD = "bold";
221 public static final String KEY_TOOL_ITALIC = "italic";
222 public static final String KEY_TOOL_UNDERLINE = "underline";
223 public static final String KEY_TOOL_STRIKE = "strike";
224 public static final String KEY_TOOL_SUPER = "superscript";
225 public static final String KEY_TOOL_SUB = "subscript";
226 public static final String KEY_TOOL_ULIST = "ulist";
227 public static final String KEY_TOOL_OLIST = "olist";
228 public static final String KEY_TOOL_CLEAR = "clearformats";
229 public static final String KEY_TOOL_ANCHOR = "anchor";
230 public static final String KEY_TOOL_SOURCE = "viewsource";
231 public static final String KEY_TOOL_STYLES = "styleselect";
232
233 // Menu & Tool Key Arrays
234 private static Hashtable htMenus = new Hashtable();
235 private static Hashtable htTools = new Hashtable();
236
237 private final String appName = "Ekit";
238 private final String menuDialog = "..."; /* text to append to a MenuItem label when menu item opens a dialog */
239
240 private final boolean useFormIndicator = true; /* Creates a highlighted background on a new FORM so that it may be more easily edited */
241 private final String clrFormIndicator = "#cccccc";
242
243 // System Clipboard Settings
244 private java.awt.datatransfer.Clipboard sysClipboard;
245 private SecurityManager secManager;
246
247 /* Variables */
248 private int iSplitPos = 0;
249
250 private boolean exclusiveEdit = true;
251
252 private String lastSearchFindTerm = null;
253 private String lastSearchReplaceTerm = null;
254 private boolean lastSearchCaseSetting = false;
255 private boolean lastSearchTopSetting = false;
256
257 private File currentFile = null;
258
259 private int indent = 0;
260 private final int indentStep = 4;
261
262 // File extensions for MutableFilter
263 private final String[] extsHTML = { "html", "htm", "shtml" };
264 private final String[] extsCSS = { "css" };
265 private final String[] extsIMG = { "gif", "jpg", "jpeg", "png" };
266 private final String[] extsRTF = { "rtf" };
267 private final String[] extsB64 = { "b64" };
268 private final String[] extsSer = { "ser" };
269
270 /* Servlet Settings */
271 private String ServletURL = null;
272 private String TreePilotSystemID = "";
273 private String ImageDir = "";
274 private static ResourceBundle TreePilotProperties;
275
276 /** Master Constructor
277 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
278 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
279 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
280 * @param urlStyleSheet [URL] A URL reference to the CSS style sheet.
281 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
282 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
283 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
284 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
285 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
286 * @param base64 [boolean] Specifies whether the raw document is Base64 encoded or not.
287 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
288 */
289 public EkitCore(String sDocument, String sStyleSheet, String sRawDocument, URL urlStyleSheet, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64, boolean debugMode)
290 {
291 super();
292
293 exclusiveEdit = editModeExclusive;
294
295 frameHandler = new Frame();
296
297 // Determine if system clipboard is available
298 secManager = System.getSecurityManager();
299 if(secManager != null)
300 {
301 try
302 {
303 secManager.checkSystemClipboardAccess();
304 sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
305 }
306 catch (SecurityException se)
307 {
308 sysClipboard = null;
309 }
310 }
311
312 /* Localize for language */
313 Translatrix.setBundleName("com.hexidec.ekit.LanguageResources");
314 Locale baseLocale = (Locale)null;
315 if(sLanguage != null && sCountry != null)
316 {
317 baseLocale = new Locale(sLanguage, sCountry);
318 }
319 Translatrix.setLocale(baseLocale);
320
321 /* Load TreePilot properties */
322 try
323 {
324 TreePilotProperties = ResourceBundle.getBundle("com.hexidec.ekit.TreePilot");
325 }
326 catch(MissingResourceException mre)
327 {
328 logException("MissingResourceException while loading treepilot file", mre);
329 }
330
331 /* Create the editor kit, document, and stylesheet */
332 jtpMain = new JTextPane();
333 htmlKit = new ExtendedHTMLEditorKit();
334 htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
335 styleSheet = htmlDoc.getStyleSheet();
336 htmlKit.setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR));
337
338 /* Set up the text pane */
339 jtpMain.setEditorKit(htmlKit);
340 jtpMain.setDocument(htmlDoc);
341 jtpMain.setMargin(new Insets(4, 4, 4, 4));
342 jtpMain.addKeyListener(this);
343
344 /* Create the source text area */
345 jtpSource = new JTextPane();
346 jtpSource.setBackground(new Color(212, 212, 212));
347 jtpSource.setSelectionColor(new Color(255, 192, 192));
348 jtpSource.setText(jtpMain.getText());
349 jtpSource.getDocument().addDocumentListener(this);
350
351 /* Add CaretListener for tracking caret location events */
352 jtpMain.addCaretListener(new CaretListener()
353 {
354 public void caretUpdate(CaretEvent ce)
355 {
356 handleCaretPositionChange(ce);
357 }
358 });
359
360 /* Set up the undo features */
361 undoMngr = new UndoManager();
362 undoAction = new UndoAction();
363 redoAction = new RedoAction();
364 jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
365
366 /* Insert raw document, if exists */
367 if(sRawDocument != null && sRawDocument.length() > 0)
368 {
369 if(base64)
370 {
371 jtpMain.setText(Base64Codec.decode(sRawDocument));
372 }
373 else
374 {
375 jtpMain.setText(sRawDocument);
376 }
377 }
378 jtpMain.setCaretPosition(0);
379 jtpMain.getDocument().addDocumentListener(this);
380
381 /* Import CSS from reference, if exists */
382 if(urlStyleSheet != null)
383 {
384 try
385 {
386 String currDocText = jtpMain.getText();
387 htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
388 styleSheet = htmlDoc.getStyleSheet();
389 BufferedReader br = new BufferedReader(new InputStreamReader(urlStyleSheet.openStream()));
390 styleSheet.loadRules(br, urlStyleSheet);
391 br.close();
392 htmlDoc = new ExtendedHTMLDocument(styleSheet);
393 registerDocument(htmlDoc);
394 jtpMain.setText(currDocText);
395 jtpSource.setText(jtpMain.getText());
396 }
397 catch(Exception e)
398 {
399 e.printStackTrace(System.out);
400 }
401 }
402
403 /* Preload the specified HTML document, if exists */
404 if(sDocument != null)
405 {
406 File defHTML = new File(sDocument);
407 if(defHTML.exists())
408 {
409 try
410 {
411 openDocument(defHTML);
412 }
413 catch(Exception e)
414 {
415 logException("Exception in preloading HTML document", e);
416 }
417 }
418 }
419
420 /* Preload the specified CSS document, if exists */
421 if(sStyleSheet != null)
422 {
423 File defCSS = new File(sStyleSheet);
424 if(defCSS.exists())
425 {
426 try
427 {
428 openStyleSheet(defCSS);
429 }
430 catch(Exception e)
431 {
432 logException("Exception in preloading CSS stylesheet", e);
433 }
434 }
435 }
436
437 /* Collect the actions that the JTextPane is naturally aware of */
438 Hashtable actions = new Hashtable();
439 Action[] actionsArray = jtpMain.getActions();
440 for(int i = 0; i < actionsArray.length; i++)
441 {
442 Action a = actionsArray[i];
443 actions.put(a.getValue(Action.NAME), a);
444 }
445
446 /* Create shared actions */
447 actionFontBold = new StyledEditorKit.BoldAction();
448 actionFontItalic = new StyledEditorKit.ItalicAction();
449 actionFontUnderline = new StyledEditorKit.UnderlineAction();
450 actionFontStrike = new FormatAction(this, Translatrix.getTranslationString("FontStrike"), HTML.Tag.STRIKE);
451 actionFontSuperscript = new FormatAction(this, Translatrix.getTranslationString("FontSuperscript"), HTML.Tag.SUP);
452 actionFontSubscript = new FormatAction(this, Translatrix.getTranslationString("FontSubscript"), HTML.Tag.SUB);
453 actionListUnordered = new ListAutomationAction(this, Translatrix.getTranslationString("ListUnordered"), HTML.Tag.UL);
454 actionListOrdered = new ListAutomationAction(this, Translatrix.getTranslationString("ListOrdered"), HTML.Tag.OL);
455 Hashtable customAttr = new Hashtable();
456 customAttr.put("face","");
457 actionSelectFont = new CustomAction(this, Translatrix.getTranslationString("FontSelect") + menuDialog, HTML.Tag.FONT, customAttr);
458 actionClearFormat = new CustomAction(this, Translatrix.getTranslationString("FormatClear"), new HTML.UnknownTag(""));
459 actionInsertAnchor = new CustomAction(this, Translatrix.getTranslationString("InsertAnchor") + menuDialog, HTML.Tag.A);
460
461 /* Build the menus */
462 /* FILE Menu */
463 jMenuFile = new JMenu(Translatrix.getTranslationString("File"));
464 htMenus.put(KEY_MENU_FILE, jMenuFile);
465 JMenuItem jmiNew = new JMenuItem(Translatrix.getTranslationString("NewDocument")); jmiNew.setActionCommand("newdoc"); jmiNew.addActionListener(this); jmiNew.setAccelerator(KeyStroke.getKeyStroke('N', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiNew.setIcon(getEkitIcon("New")); }; jMenuFile.add(jmiNew);
466 JMenuItem jmiOpenHTML = new JMenuItem(Translatrix.getTranslationString("OpenDocument") + menuDialog); jmiOpenHTML.setActionCommand("openhtml"); jmiOpenHTML.addActionListener(this); jmiOpenHTML.setAccelerator(KeyStroke.getKeyStroke('O', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiOpenHTML.setIcon(getEkitIcon("Open")); }; jMenuFile.add(jmiOpenHTML);
467 JMenuItem jmiOpenCSS = new JMenuItem(Translatrix.getTranslationString("OpenStyle") + menuDialog); jmiOpenCSS.setActionCommand("opencss"); jmiOpenCSS.addActionListener(this); jMenuFile.add(jmiOpenCSS);
468 JMenuItem jmiOpenB64 = new JMenuItem(Translatrix.getTranslationString("OpenBase64Document") + menuDialog); jmiOpenB64.setActionCommand("openb64"); jmiOpenB64.addActionListener(this); jMenuFile.add(jmiOpenB64);
469 jMenuFile.addSeparator();
470 JMenuItem jmiSave = new JMenuItem(Translatrix.getTranslationString("Save")); jmiSave.setActionCommand("save"); jmiSave.addActionListener(this); jmiSave.setAccelerator(KeyStroke.getKeyStroke('S', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiSave.setIcon(getEkitIcon("Save")); }; jMenuFile.add(jmiSave);
471 JMenuItem jmiSaveAs = new JMenuItem(Translatrix.getTranslationString("SaveAs") + menuDialog); jmiSaveAs.setActionCommand("saveas"); jmiSaveAs.addActionListener(this); jMenuFile.add(jmiSaveAs);
472 JMenuItem jmiSaveBody = new JMenuItem(Translatrix.getTranslationString("SaveBody") + menuDialog); jmiSaveBody.setActionCommand("savebody"); jmiSaveBody.addActionListener(this); jMenuFile.add(jmiSaveBody);
473 JMenuItem jmiSaveRTF = new JMenuItem(Translatrix.getTranslationString("SaveRTF") + menuDialog); jmiSaveRTF.setActionCommand("savertf"); jmiSaveRTF.addActionListener(this); jMenuFile.add(jmiSaveRTF);
474 JMenuItem jmiSaveB64 = new JMenuItem(Translatrix.getTranslationString("SaveB64") + menuDialog); jmiSaveB64.setActionCommand("saveb64"); jmiSaveB64.addActionListener(this); jMenuFile.add(jmiSaveB64);
475 jMenuFile.addSeparator();
476 JMenuItem jmiSerialOut = new JMenuItem(Translatrix.getTranslationString("Serialize") + menuDialog); jmiSerialOut.setActionCommand("serialize"); jmiSerialOut.addActionListener(this); jMenuFile.add(jmiSerialOut);
477 JMenuItem jmiSerialIn = new JMenuItem(Translatrix.getTranslationString("ReadFromSer") + menuDialog); jmiSerialIn.setActionCommand("readfromser"); jmiSerialIn.addActionListener(this); jMenuFile.add(jmiSerialIn);
478 jMenuFile.addSeparator();
479 JMenuItem jmiExit = new JMenuItem(Translatrix.getTranslationString("Exit")); jmiExit.setActionCommand("exit"); jmiExit.addActionListener(this); jMenuFile.add(jmiExit);
480
481 /* EDIT Menu */
482 jMenuEdit = new JMenu(Translatrix.getTranslationString("Edit"));
483 htMenus.put(KEY_MENU_EDIT, jMenuEdit);
484 if(sysClipboard != null)
485 {
486 // System Clipboard versions of menu commands
487 JMenuItem jmiCut = new JMenuItem(Translatrix.getTranslationString("Cut")); jmiCut.setActionCommand("textcut"); jmiCut.addActionListener(this); jmiCut.setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiCut.setIcon(getEkitIcon("Cut")); } jMenuEdit.add(jmiCut);
488 JMenuItem jmiCopy = new JMenuItem(Translatrix.getTranslationString("Copy")); jmiCopy.setActionCommand("textcopy"); jmiCopy.addActionListener(this); jmiCopy.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiCopy.setIcon(getEkitIcon("Copy")); } jMenuEdit.add(jmiCopy);
489 JMenuItem jmiPaste = new JMenuItem(Translatrix.getTranslationString("Paste")); jmiPaste.setActionCommand("textpaste"); jmiPaste.addActionListener(this); jmiPaste.setAccelerator(KeyStroke.getKeyStroke('V', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiPaste.setIcon(getEkitIcon("Paste")); } jMenuEdit.add(jmiPaste);
490 }
491 else
492 {
493 // DefaultEditorKit versions of menu commands
494 JMenuItem jmiCut = new JMenuItem(new DefaultEditorKit.CutAction()); jmiCut.setText(Translatrix.getTranslationString("Cut")); jmiCut.setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiCut.setIcon(getEkitIcon("Cut")); } jMenuEdit.add(jmiCut);
495 JMenuItem jmiCopy = new JMenuItem(new DefaultEditorKit.CopyAction()); jmiCopy.setText(Translatrix.getTranslationString("Copy")); jmiCopy.setAccelerator(KeyStroke.getKeyStroke('C', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiCopy.setIcon(getEkitIcon("Copy")); } jMenuEdit.add(jmiCopy);
496 JMenuItem jmiPaste = new JMenuItem(new DefaultEditorKit.PasteAction()); jmiPaste.setText(Translatrix.getTranslationString("Paste")); jmiPaste.setAccelerator(KeyStroke.getKeyStroke('V', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiPaste.setIcon(getEkitIcon("Paste")); } jMenuEdit.add(jmiPaste);
497 }
498 jMenuEdit.addSeparator();
499 JMenuItem jmiUndo = new JMenuItem(undoAction); jmiUndo.setAccelerator(KeyStroke.getKeyStroke('Z', java.awt.Event.CTRL_MASK, false)); jMenuEdit.add(jmiUndo);
500 JMenuItem jmiRedo = new JMenuItem(redoAction); jmiRedo.setAccelerator(KeyStroke.getKeyStroke('Y', java.awt.Event.CTRL_MASK, false)); jMenuEdit.add(jmiRedo);
501 jMenuEdit.addSeparator();
502 JMenuItem jmiSelAll = new JMenuItem((Action)actions.get(DefaultEditorKit.selectAllAction)); jmiSelAll.setText(Translatrix.getTranslationString("SelectAll")); jmiSelAll.setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK, false)); jMenuEdit.add(jmiSelAll);
503 JMenuItem jmiSelPara = new JMenuItem((Action)actions.get(DefaultEditorKit.selectParagraphAction)); jmiSelPara.setText(Translatrix.getTranslationString("SelectParagraph")); jMenuEdit.add(jmiSelPara);
504 JMenuItem jmiSelLine = new JMenuItem((Action)actions.get(DefaultEditorKit.selectLineAction)); jmiSelLine.setText(Translatrix.getTranslationString("SelectLine")); jMenuEdit.add(jmiSelLine);
505 JMenuItem jmiSelWord = new JMenuItem((Action)actions.get(DefaultEditorKit.selectWordAction)); jmiSelWord.setText(Translatrix.getTranslationString("SelectWord")); jMenuEdit.add(jmiSelWord);
506
507 /* VIEW Menu */
508 jMenuView = new JMenu(Translatrix.getTranslationString("View"));
509 htMenus.put(KEY_MENU_VIEW, jMenuView);
510 jcbmiViewToolbar = new JCheckBoxMenuItem(Translatrix.getTranslationString("ViewToolbar"), false); jcbmiViewToolbar.setActionCommand("toggletoolbar"); jcbmiViewToolbar.addActionListener(this); jMenuView.add(jcbmiViewToolbar);
511 jcbmiViewSource = new JCheckBoxMenuItem(Translatrix.getTranslationString("ViewSource"), false); jcbmiViewSource.setActionCommand("viewsource"); jcbmiViewSource.addActionListener(this); jMenuView.add(jcbmiViewSource);
512
513 /* FONT Menu */
514 jMenuFont = new JMenu(Translatrix.getTranslationString("Font"));
515 htMenus.put(KEY_MENU_FONT, jMenuFont);
516 JMenuItem jmiBold = new JMenuItem(actionFontBold); jmiBold.setText(Translatrix.getTranslationString("FontBold")); jmiBold.setAccelerator(KeyStroke.getKeyStroke('B', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiBold.setIcon(getEkitIcon("Bold")); } jMenuFont.add(jmiBold);
517 JMenuItem jmiItalic = new JMenuItem(actionFontItalic); jmiItalic.setText(Translatrix.getTranslationString("FontItalic")); jmiItalic.setAccelerator(KeyStroke.getKeyStroke('I', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiItalic.setIcon(getEkitIcon("Italic")); } jMenuFont.add(jmiItalic);
518 JMenuItem jmiUnderline = new JMenuItem(actionFontUnderline); jmiUnderline.setText(Translatrix.getTranslationString("FontUnderline")); jmiUnderline.setAccelerator(KeyStroke.getKeyStroke('U', java.awt.Event.CTRL_MASK, false)); if(showMenuIcons) { jmiUnderline.setIcon(getEkitIcon("Underline")); } jMenuFont.add(jmiUnderline);
519 JMenuItem jmiStrike = new JMenuItem(actionFontStrike); jmiStrike.setText(Translatrix.getTranslationString("FontStrike")); if(showMenuIcons) { jmiStrike.setIcon(getEkitIcon("Strike")); } jMenuFont.add(jmiStrike);
520 jMenuFont.addSeparator();
521 jMenuFont.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatBig"), HTML.Tag.BIG)));
522 jMenuFont.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatSmall"), HTML.Tag.SMALL)));
523 JMenu jMenuFontSize = new JMenu(Translatrix.getTranslationString("FontSize"));
524 String fontSizeKey = "size";
525 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"1");
526 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize1"), HTML.Tag.FONT, customAttr)));
527 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"2");
528 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize2"), HTML.Tag.FONT, customAttr)));
529 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"3");
530 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize3"), HTML.Tag.FONT, customAttr)));
531 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"4");
532 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize4"), HTML.Tag.FONT, customAttr)));
533 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"5");
534 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize5"), HTML.Tag.FONT, customAttr)));
535 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"6");
536 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize6"), HTML.Tag.FONT, customAttr)));
537 customAttr = new Hashtable(); customAttr.put(fontSizeKey,"7");
538 jMenuFontSize.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("FontSize7"), HTML.Tag.FONT, customAttr)));
539 jMenuFont.add(jMenuFontSize);
540 jMenuFont.addSeparator();
541 JMenuItem jmiSupscript = new JMenuItem(actionFontSuperscript); if(showMenuIcons) { jmiSupscript.setIcon(getEkitIcon("Super")); } jMenuFont.add(jmiSupscript);
542 JMenuItem jmiSubscript = new JMenuItem(actionFontSubscript); if(showMenuIcons) { jmiSubscript.setIcon(getEkitIcon("Sub")); } jMenuFont.add(jmiSubscript);
543 jMenuFont.addSeparator();
544 JMenuItem jmiSerif = new JMenuItem((Action)actions.get("font-family-Serif")); jmiSerif.setText(Translatrix.getTranslationString("FontSerif")); jMenuFont.add(jmiSerif);
545 JMenuItem jmiSansSerif = new JMenuItem((Action)actions.get("font-family-SansSerif")); jmiSansSerif.setText(Translatrix.getTranslationString("FontSansserif")); jMenuFont.add(jmiSansSerif);
546 JMenuItem jmiMonospaced = new JMenuItem((Action)actions.get("font-family-Monospaced")); jmiMonospaced.setText(Translatrix.getTranslationString("FontMonospaced")); jMenuFont.add(jmiMonospaced);
547 JMenuItem jmiSelectFont = new JMenuItem(actionSelectFont); jMenuFont.add(jmiSelectFont);
548 jMenuFont.addSeparator();
549 JMenu jMenuFontColor = new JMenu(Translatrix.getTranslationString("Color"));
550 customAttr = new Hashtable(); customAttr.put("color","black");
551 jMenuFontColor.add(new JMenuItem(new CustomAction(this, Translatrix.getTranslationString("CustomColor") + menuDialog, HTML.Tag.FONT, customAttr)));
552 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorAqua"), new Color( 0,255,255))));
553 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorBlack"), new Color( 0, 0, 0))));
554 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorBlue"), new Color( 0, 0,255))));
555 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorFuschia"), new Color(255, 0,255))));
556 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorGray"), new Color(128,128,128))));
557 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorGreen"), new Color( 0,128, 0))));
558 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorLime"), new Color( 0,255, 0))));
559 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorMaroon"), new Color(128, 0, 0))));
560 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorNavy"), new Color( 0, 0,128))));
561 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorOlive"), new Color(128,128, 0))));
562 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorPurple"), new Color(128, 0,128))));
563 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorRed"), new Color(255, 0, 0))));
564 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorSilver"), new Color(192,192,192))));
565 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorTeal"), new Color( 0,128,128))));
566 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorWhite"), new Color(255,255,255))));
567 jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(Translatrix.getTranslationString("ColorYellow"), new Color(255,255, 0))));
568 jMenuFont.add(jMenuFontColor);
569
570 /* FORMAT Menu */
571 jMenuFormat = new JMenu(Translatrix.getTranslationString("Format"));
572 htMenus.put(KEY_MENU_FORMAT, jMenuFormat);
573 JMenu jMenuFormatAlign = new JMenu(Translatrix.getTranslationString("Align"));
574 jMenuFormatAlign.add(new JMenuItem(new StyledEditorKit.AlignmentAction(Translatrix.getTranslationString("AlignLeft"), StyleConstants.ALIGN_LEFT)));
575 jMenuFormatAlign.add(new JMenuItem(new StyledEditorKit.AlignmentAction(Translatrix.getTranslationString("AlignCenter"), StyleConstants.ALIGN_CENTER)));
576 jMenuFormatAlign.add(new JMenuItem(new StyledEditorKit.AlignmentAction(Translatrix.getTranslationString("AlignRight"), StyleConstants.ALIGN_RIGHT)));
577 jMenuFormatAlign.add(new JMenuItem(new StyledEditorKit.AlignmentAction(Translatrix.getTranslationString("AlignJustified"), StyleConstants.ALIGN_JUSTIFIED)));
578 jMenuFormat.add(jMenuFormatAlign);
579 jMenuFormat.addSeparator();
580 JMenu jMenuFormatHeading = new JMenu(Translatrix.getTranslationString("Heading"));
581 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading1"), HTML.Tag.H1)));
582 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading2"), HTML.Tag.H2)));
583 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading3"), HTML.Tag.H3)));
584 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading4"), HTML.Tag.H4)));
585 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading5"), HTML.Tag.H5)));
586 jMenuFormatHeading.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading6"), HTML.Tag.H6)));
587 jMenuFormat.add(jMenuFormatHeading);
588 jMenuFormat.addSeparator();
589 JMenuItem jmiUList = new JMenuItem(actionListUnordered); if(showMenuIcons) { jmiUList.setIcon(getEkitIcon("UList")); } jMenuFormat.add(jmiUList);
590 JMenuItem jmiOList = new JMenuItem(actionListOrdered); if(showMenuIcons) { jmiOList.setIcon(getEkitIcon("OList")); } jMenuFormat.add(jmiOList);
591 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("ListItem"), HTML.Tag.LI)));
592 jMenuFormat.addSeparator();
593 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatBlockquote"), HTML.Tag.BLOCKQUOTE)));
594 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatPre"), HTML.Tag.PRE)));
595 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatStrong"), HTML.Tag.STRONG)));
596 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatEmphasis"), HTML.Tag.EM)));
597 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatTT"), HTML.Tag.TT)));
598 jMenuFormat.add(new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatSpan"), HTML.Tag.SPAN)));
599 jMenuFormat.addSeparator();
600 JMenuItem jmiClearStyles = new JMenuItem(actionClearFormat); if(showMenuIcons) { jmiClearStyles.setIcon(getEkitIcon("ClearFormat")); }; jMenuFormat.add(jmiClearStyles);
601
602 /* INSERT Menu */
603 jMenuInsert = new JMenu(Translatrix.getTranslationString("Insert"));
604 htMenus.put(KEY_MENU_INSERT, jMenuInsert);
605 jMenuInsert.add(new JMenuItem(actionInsertAnchor));
606 JMenuItem jmiBreak = new JMenuItem(Translatrix.getTranslationString("InsertBreak")); jmiBreak.setActionCommand("insertbreak"); jmiBreak.addActionListener(this); jmiBreak.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, java.awt.Event.SHIFT_MASK, false)); jMenuInsert.add(jmiBreak);
607 JMenuItem jmiNBSP = new JMenuItem(Translatrix.getTranslationString("InsertNBSP")); jmiNBSP.setActionCommand("insertnbsp"); jmiNBSP.addActionListener(this); jMenuInsert.add(jmiNBSP);
608 JMenuItem jmiHRule = new JMenuItem((Action)actions.get("InsertHR")); jmiHRule.setText(Translatrix.getTranslationString("InsertHorizontalRule")); jMenuInsert.add(jmiHRule);
609 jMenuInsert.addSeparator();
610 JMenuItem jmiImageLocal = new JMenuItem(Translatrix.getTranslationString("InsertLocalImage") + menuDialog); jmiImageLocal.setActionCommand("insertlocalimage"); jmiImageLocal.addActionListener(this); jMenuInsert.add(jmiImageLocal);
611 JMenuItem jmiImageServer = new JMenuItem(Translatrix.getTranslationString("InsertServerImage") + menuDialog); jmiImageServer.setActionCommand("insertserverimage"); jmiImageServer.addActionListener(this); jMenuInsert.add(jmiImageServer);
612
613 /* TABLE Menu */
614 jMenuTable = new JMenu(Translatrix.getTranslationString("Table"));
615 htMenus.put(KEY_MENU_TABLE, jMenuTable);
616 JMenuItem jmiTable = new JMenuItem(Translatrix.getTranslationString("InsertTable") + menuDialog); jmiTable.setActionCommand("inserttable"); jmiTable.addActionListener(this); jMenuTable.add(jmiTable);
617 jMenuTable.addSeparator();
618 JMenuItem jmiTableRow = new JMenuItem(Translatrix.getTranslationString("InsertTableRow")); jmiTableRow.setActionCommand("inserttablerow"); jmiTableRow.addActionListener(this); jMenuTable.add(jmiTableRow);
619 JMenuItem jmiTableCol = new JMenuItem(Translatrix.getTranslationString("InsertTableColumn")); jmiTableCol.setActionCommand("inserttablecolumn"); jmiTableCol.addActionListener(this); jMenuTable.add(jmiTableCol);
620 jMenuTable.addSeparator();
621 JMenuItem jmiTableRowDel = new JMenuItem(Translatrix.getTranslationString("DeleteTableRow")); jmiTableRowDel.setActionCommand("deletetablerow"); jmiTableRowDel.addActionListener(this); jMenuTable.add(jmiTableRowDel);
622 JMenuItem jmiTableColDel = new JMenuItem(Translatrix.getTranslationString("DeleteTableColumn")); jmiTableColDel.setActionCommand("deletetablecolumn"); jmiTableColDel.addActionListener(this); jMenuTable.add(jmiTableColDel);
623
624 /* FORMS Menu */
625 jMenuForms = new JMenu(Translatrix.getTranslationString("Forms"));
626 htMenus.put(KEY_MENU_FORMS, jMenuForms);
627 JMenuItem jmiFormInsertForm = new JMenuItem(Translatrix.getTranslationString("FormInsertForm")); jmiFormInsertForm.setActionCommand("insertform"); jmiFormInsertForm.addActionListener(this); jMenuForms.add(jmiFormInsertForm);
628 jMenuForms.addSeparator();
629 JMenuItem jmiFormTextfield = new JMenuItem(Translatrix.getTranslationString("FormTextfield")); jmiFormTextfield.setActionCommand("inserttextfield"); jmiFormTextfield.addActionListener(this); jMenuForms.add(jmiFormTextfield);
630 JMenuItem jmiFormTextarea = new JMenuItem(Translatrix.getTranslationString("FormTextarea")); jmiFormTextarea.setActionCommand("inserttextarea"); jmiFormTextarea.addActionListener(this); jMenuForms.add(jmiFormTextarea);
631 JMenuItem jmiFormCheckbox = new JMenuItem(Translatrix.getTranslationString("FormCheckbox")); jmiFormCheckbox.setActionCommand("insertcheckbox"); jmiFormCheckbox.addActionListener(this); jMenuForms.add(jmiFormCheckbox);
632 JMenuItem jmiFormRadio = new JMenuItem(Translatrix.getTranslationString("FormRadio")); jmiFormRadio.setActionCommand("insertradiobutton"); jmiFormRadio.addActionListener(this); jMenuForms.add(jmiFormRadio);
633 JMenuItem jmiFormPassword = new JMenuItem(Translatrix.getTranslationString("FormPassword")); jmiFormPassword.setActionCommand("insertpassword"); jmiFormPassword.addActionListener(this); jMenuForms.add(jmiFormPassword);
634 jMenuForms.addSeparator();
635 JMenuItem jmiFormButton = new JMenuItem(Translatrix.getTranslationString("FormButton")); jmiFormButton.setActionCommand("insertbutton"); jmiFormButton.addActionListener(this); jMenuForms.add(jmiFormButton);
636 JMenuItem jmiFormButtonSubmit = new JMenuItem(Translatrix.getTranslationString("FormButtonSubmit")); jmiFormButtonSubmit.setActionCommand("insertbuttonsubmit"); jmiFormButtonSubmit.addActionListener(this); jMenuForms.add(jmiFormButtonSubmit);
637 JMenuItem jmiFormButtonReset = new JMenuItem(Translatrix.getTranslationString("FormButtonReset")); jmiFormButtonReset.setActionCommand("insertbuttonreset"); jmiFormButtonReset.addActionListener(this); jMenuForms.add(jmiFormButtonReset);
638
639 /* SEARCH Menu */
640 jMenuSearch = new JMenu(Translatrix.getTranslationString("Search"));
641 htMenus.put(KEY_MENU_SEARCH, jMenuSearch);
642 JMenuItem jmiFind = new JMenuItem(Translatrix.getTranslationString("SearchFind")); jmiFind.setActionCommand("find"); jmiFind.addActionListener(this); jmiFind.setAccelerator(KeyStroke.getKeyStroke('F', java.awt.Event.CTRL_MASK, false)); jMenuSearch.add(jmiFind);
643 JMenuItem jmiFindAgain = new JMenuItem(Translatrix.getTranslationString("SearchFindAgain")); jmiFindAgain.setActionCommand("findagain"); jmiFindAgain.addActionListener(this); jmiFindAgain.setAccelerator(KeyStroke.getKeyStroke('G', java.awt.Event.CTRL_MASK, false)); jMenuSearch.add(jmiFindAgain);
644 JMenuItem jmiReplace = new JMenuItem(Translatrix.getTranslationString("SearchReplace")); jmiReplace.setActionCommand("replace"); jmiReplace.addActionListener(this); jmiReplace.setAccelerator(KeyStroke.getKeyStroke('R', java.awt.Event.CTRL_MASK, false)); jMenuSearch.add(jmiReplace);
645
646 /* HELP Menu */
647 jMenuHelp = new JMenu(Translatrix.getTranslationString("Help"));
648 htMenus.put(KEY_MENU_HELP, jMenuHelp);
649 JMenuItem jmiAbout = new JMenuItem(Translatrix.getTranslationString("About")); jmiAbout.setActionCommand("helpabout"); jmiAbout.addActionListener(this); jMenuHelp.add(jmiAbout);
650
651 /* DEBUG Menu */
652 jMenuDebug = new JMenu(Translatrix.getTranslationString("Debug"));
653 htMenus.put(KEY_MENU_DEBUG, jMenuDebug);
654 JMenuItem jmiDesc = new JMenuItem(Translatrix.getTranslationString("DescribeDoc")); jmiDesc.setActionCommand("describe"); jmiDesc.addActionListener(this); jMenuDebug.add(jmiDesc);
655 JMenuItem jmiDescCSS = new JMenuItem(Translatrix.getTranslationString("DescribeCSS")); jmiDescCSS.setActionCommand("describecss"); jmiDescCSS.addActionListener(this); jMenuDebug.add(jmiDescCSS);
656 JMenuItem jmiTag = new JMenuItem(Translatrix.getTranslationString("WhatTags")); jmiTag.setActionCommand("whattags"); jmiTag.addActionListener(this); jMenuDebug.add(jmiTag);
657
658 /* Create menubar and add menus */
659 jMenuBar = new JMenuBar();
660 jMenuBar.add(jMenuFile);
661 jMenuBar.add(jMenuEdit);
662 jMenuBar.add(jMenuView);
663 jMenuBar.add(jMenuFont);
664 jMenuBar.add(jMenuFormat);
665 jMenuBar.add(jMenuSearch);
666 jMenuBar.add(jMenuInsert);
667 jMenuBar.add(jMenuTable);
668 jMenuBar.add(jMenuForms);
669 jMenuBar.add(jMenuHelp);
670 if(debugMode)
671 {
672 jMenuBar.add(jMenuDebug);
673 }
674
675 /* Create the toolbar */
676 jToolBar = new JToolBar(JToolBar.HORIZONTAL);
677 jToolBar.setFloatable(false);
678 jbtnNewHTML = new JButtonNoFocus(getEkitIcon("New")); jbtnNewHTML.setToolTipText(Translatrix.getTranslationString("NewDocument")); jbtnNewHTML.setActionCommand("newdoc"); jbtnNewHTML.addActionListener(this); jToolBar.add(jbtnNewHTML); htTools.put(KEY_TOOL_NEW, jbtnNewHTML);
679 jbtnOpenHTML = new JButtonNoFocus(getEkitIcon("Open")); jbtnOpenHTML.setToolTipText(Translatrix.getTranslationString("OpenDocument")); jbtnOpenHTML.setActionCommand("openhtml"); jbtnOpenHTML.addActionListener(this); jToolBar.add(jbtnOpenHTML); htTools.put(KEY_TOOL_OPEN, jbtnOpenHTML);
680 jbtnSaveHTML = new JButtonNoFocus(getEkitIcon("Save")); jbtnSaveHTML.setToolTipText(Translatrix.getTranslationString("SaveDocument")); jbtnSaveHTML.setActionCommand("saveas"); jbtnSaveHTML.addActionListener(this); jToolBar.add(jbtnSaveHTML); htTools.put(KEY_TOOL_SAVE, jbtnSaveHTML);
681 jToolBar.add(new JToolBar.Separator());
682 jbtnCut = new JButtonNoFocus(new DefaultEditorKit.CutAction()); jbtnCut.setIcon(getEkitIcon("Cut")); jbtnCut.setText(null); jbtnCut.setToolTipText(Translatrix.getTranslationString("Cut")); jToolBar.add(jbtnCut); htTools.put(KEY_TOOL_CUT, jbtnCut);
683 jbtnCopy = new JButtonNoFocus(new DefaultEditorKit.CopyAction()); jbtnCopy.setIcon(getEkitIcon("Copy")); jbtnCopy.setText(null); jbtnCopy.setToolTipText(Translatrix.getTranslationString("Copy")); jToolBar.add(jbtnCopy); htTools.put(KEY_TOOL_COPY, jbtnCopy);
684 jbtnPaste = new JButtonNoFocus(new DefaultEditorKit.PasteAction()); jbtnPaste.setIcon(getEkitIcon("Paste")); jbtnPaste.setText(null); jbtnPaste.setToolTipText(Translatrix.getTranslationString("Paste")); jToolBar.add(jbtnPaste); htTools.put(KEY_TOOL_PASTE, jbtnPaste);
685 jToolBar.add(new JToolBar.Separator());
686 jbtnBold = new JButtonNoFocus(actionFontBold); jbtnBold.setIcon(getEkitIcon("Bold")); jbtnBold.setText(null); jbtnBold.setToolTipText(Translatrix.getTranslationString("FontBold")); jToolBar.add(jbtnBold); htTools.put(KEY_TOOL_BOLD, jbtnBold);
687 jbtnItalic = new JButtonNoFocus(actionFontItalic); jbtnItalic.setIcon(getEkitIcon("Italic")); jbtnItalic.setText(null); jbtnItalic.setToolTipText(Translatrix.getTranslationString("FontItalic")); jToolBar.add(jbtnItalic); htTools.put(KEY_TOOL_ITALIC, jbtnItalic);
688 jbtnUnderline = new JButtonNoFocus(actionFontUnderline); jbtnUnderline.setIcon(getEkitIcon("Underline")); jbtnUnderline.setText(null); jbtnUnderline.setToolTipText(Translatrix.getTranslationString("FontUnderline")); jToolBar.add(jbtnUnderline); htTools.put(KEY_TOOL_UNDERLINE, jbtnUnderline);
689 jbtnStrike = new JButtonNoFocus(actionFontStrike); jbtnStrike.setIcon(getEkitIcon("Strike")); jbtnStrike.setText(null); jbtnStrike.setToolTipText(Translatrix.getTranslationString("FontStrike")); jToolBar.add(jbtnStrike); htTools.put(KEY_TOOL_STRIKE, jbtnStrike);
690 jbtnSuperscript = new JButtonNoFocus(actionFontSuperscript); jbtnSuperscript.setIcon(getEkitIcon("Super")); jbtnSuperscript.setText(null); jbtnSuperscript.setToolTipText(Translatrix.getTranslationString("FontSuperscript")); jToolBar.add(jbtnSuperscript); htTools.put(KEY_TOOL_SUPER, jbtnSuperscript);
691 jbtnSubscript = new JButtonNoFocus(actionFontSubscript); jbtnSubscript.setIcon(getEkitIcon("Sub")); jbtnSubscript.setText(null); jbtnSubscript.setToolTipText(Translatrix.getTranslationString("FontSubscript")); jToolBar.add(jbtnSubscript); htTools.put(KEY_TOOL_SUB, jbtnSubscript);
692 jbtnUList = new JButtonNoFocus(actionListUnordered); jbtnUList.setIcon(getEkitIcon("UList")); jbtnUList.setText(null); jbtnUList.setToolTipText(Translatrix.getTranslationString("ListUnordered")); jToolBar.add(jbtnUList); htTools.put(KEY_TOOL_ULIST, jbtnUList);
693 jbtnOList = new JButtonNoFocus(actionListOrdered); jbtnOList.setIcon(getEkitIcon("OList")); jbtnOList.setText(null); jbtnOList.setToolTipText(Translatrix.getTranslationString("ListOrdered")); jToolBar.add(jbtnOList); htTools.put(KEY_TOOL_OLIST, jbtnOList);
694 jbtnClearFormat = new JButtonNoFocus(actionClearFormat); jbtnClearFormat.setIcon(getEkitIcon("ClearFormat")); jbtnClearFormat.setText(null); jbtnClearFormat.setToolTipText(Translatrix.getTranslationString("FormatClear")); jToolBar.add(jbtnClearFormat); htTools.put(KEY_TOOL_CLEAR, jbtnClearFormat);
695 jToolBar.add(new JToolBar.Separator());
696 jbtnAnchor = new JButtonNoFocus(actionInsertAnchor); jbtnAnchor.setIcon(getEkitIcon("Anchor")); jbtnAnchor.setText(null); jbtnAnchor.setToolTipText(Translatrix.getTranslationString("ToolAnchor")); jToolBar.add(jbtnAnchor); htTools.put(KEY_TOOL_ANCHOR, jbtnAnchor);
697 jToolBar.add(new JToolBar.Separator());
698 jtbtnViewSource = new JToggleButtonNoFocus(getEkitIcon("Source")); jtbtnViewSource.setText(null); jtbtnViewSource.setToolTipText(Translatrix.getTranslationString("ViewSource")); jtbtnViewSource.setActionCommand("viewsource"); jtbtnViewSource.addActionListener(this); jtbtnViewSource.setPreferredSize(jbtnAnchor.getPreferredSize()); jtbtnViewSource.setMinimumSize(jbtnAnchor.getMinimumSize()); jtbtnViewSource.setMaximumSize(jbtnAnchor.getMaximumSize()); jToolBar.add(jtbtnViewSource); htTools.put(KEY_TOOL_SOURCE, jtbtnViewSource);
699 jToolBar.add(new JToolBar.Separator());
700 jcmbStyleSelector = new JComboBoxNoFocus(); jToolBar.add(jcmbStyleSelector); jcmbStyleSelector.setAction(new StylesAction(jcmbStyleSelector)); htTools.put(KEY_TOOL_STYLES, jcmbStyleSelector);
701
702 /* Create the scroll area for the text pane */
703 JScrollPane jspViewport = new JScrollPane(jtpMain);
704 jspViewport.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
705 jspViewport.setPreferredSize(new Dimension(400, 400));
706 jspViewport.setMinimumSize(new Dimension(32, 32));
707
708 /* Create the scroll area for the source viewer */
709 jspSource = new JScrollPane(jtpSource);
710 jspSource.setPreferredSize(new Dimension(400, 100));
711 jspSource.setMinimumSize(new Dimension(32, 32));
712
713 jspltDisplay = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
714 jspltDisplay.setTopComponent(jspViewport);
715 if(showViewSource)
716 {
717 jspltDisplay.setBottomComponent(jspSource);
718 }
719 else
720 {
721 jspltDisplay.setBottomComponent(null);
722 }
723
724 iSplitPos = jspltDisplay.getDividerLocation();
725
726 registerDocumentStyles();
727
728 /* Add the components to the app */
729 this.setLayout(new BorderLayout());
730 this.add(jspltDisplay, BorderLayout.CENTER);
731 }
732
733 /** Common Constructor
734 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
735 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
736 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
737 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
738 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
739 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
740 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
741 */
742 public EkitCore(String sDocument, String sStyleSheet, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64)
743 {
744 this(sDocument, sStyleSheet, null, null, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, false);
745 }
746
747 /** Default Language Constructor
748 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
749 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
750 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
751 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
752 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
753 */
754 public EkitCore(String sDocument, String sStyleSheet, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, boolean base64)
755 {
756 this(sDocument, sStyleSheet, null, null, showViewSource, showMenuIcons, editModeExclusive, null, null, base64, false);
757 }
758
759 /** Raw/Base64 Document & Style Sheet URL Constructor (Ideal for EkitApplet)
760 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
761 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
762 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
763 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
764 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
765 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
766 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
767 */
768 public EkitCore(String sRawDocument, URL urlStyleSheet, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64)
769 {
770 this(null, null, sRawDocument, urlStyleSheet, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, false);
771 }
772
773 /** Document Constructor
774 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
775 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
776 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
777 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
778 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
779 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
780 */
781 public EkitCore(String sRawDocument, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry, boolean base64)
782 {
783 this(null, null, sRawDocument, null, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, base64, false);
784 }
785
786 /** Default Language & Document Constructor
787 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
788 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
789 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
790 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
791 */
792 public EkitCore(String sRawDocument, boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, boolean base64)
793 {
794 this(null, null, sRawDocument, null, showViewSource, showMenuIcons, editModeExclusive, null, null, base64, false);
795 }
796
797 /** Flags & Language Constructor
798 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
799 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
800 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
801 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
802 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
803 */
804 public EkitCore(boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive, String sLanguage, String sCountry)
805 {
806 this(null, null, null, null, showViewSource, showMenuIcons, editModeExclusive, sLanguage, sCountry, false, false);
807 }
808
809 /** Flags Constructor
810 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
811 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
812 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
813 */
814 public EkitCore(boolean showViewSource, boolean showMenuIcons, boolean editModeExclusive)
815 {
816 this(null, null, null, null, showViewSource, showMenuIcons, editModeExclusive, null, null, false, false);
817 }
818
819 /** Language & Debug Constructor
820 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
821 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
822 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
823 */
824 public EkitCore(String sLanguage, String sCountry, boolean debugMode)
825 {
826 this(null, null, null, null, false, true, true, sLanguage, sCountry, false, debugMode);
827 }
828
829 /** Language Constructor
830 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
831 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
832 */
833 public EkitCore(String sLanguage, String sCountry)
834 {
835 this(null, null, null, null, false, true, true, sLanguage, sCountry, false, false);
836 }
837
838 /** Debug Constructor
839 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
840 */
841 public EkitCore(boolean debugMode)
842 {
843 this(null, null, null, null, false, true, true, null, null, false, debugMode);
844 }
845
846 /** Empty Constructor
847 */
848 public EkitCore()
849 {
850 this(null, null, null, null, false, true, true, null, null, false, false);
851 }
852
853 /* ActionListener method */
854 public void actionPerformed(ActionEvent ae)
855 {
856 try
857 {
858 String command = ae.getActionCommand();
859 if(command.equals("newdoc"))
860 {
861 SimpleInfoDialog sidAsk = new SimpleInfoDialog(this.getFrame(), "", true, Translatrix.getTranslationString("AskNewDocument"), SimpleInfoDialog.QUESTION);
862 String decision = sidAsk.getDecisionValue();
863 if(decision.equals(Translatrix.getTranslationString("DialogAccept")))
864 {
865 if(styleSheet != null)
866 {
867 htmlDoc = new ExtendedHTMLDocument(styleSheet);
868 }
869 else
870 {
871 htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
872 }
873 jtpMain.setText("<HTML><BODY></BODY></HTML>");
874 jtpSource.setText(jtpMain.getText());
875 registerDocument(htmlDoc);
876 currentFile = null;
877 updateTitle();
878 }
879 }
880 else if(command.equals("openhtml"))
881 {
882 openDocument(null);
883 }
884 else if(command.equals("opencss"))
885 {
886 openStyleSheet(null);
887 }
888 else if(command.equals("openb64"))
889 {
890 openDocumentBase64(null);
891 }
892 else if(command.equals("save"))
893 {
894 writeOut((HTMLDocument)(jtpMain.getDocument()), currentFile);
895 updateTitle();
896 }
897 else if(command.equals("saveas"))
898 {
899 writeOut((HTMLDocument)(jtpMain.getDocument()), null);
900 }
901 else if(command.equals("savebody"))
902 {
903 writeOutFragment((HTMLDocument)(jtpMain.getDocument()),"body");
904 }
905 else if(command.equals("savertf"))
906 {
907 writeOutRTF((StyledDocument)(jtpMain.getStyledDocument()));
908 }
909 else if(command.equals("saveb64"))
910 {
911 writeOutBase64(jtpSource.getText());
912 }
913 else if(command.equals("textcut"))
914 {
915 if(jspSource.isShowing() && jtpSource.hasFocus())
916 {
917 jtpSource.cut();
918 }
919 else
920 {
921 jtpMain.cut();
922 }
923 }
924 else if(command.equals("textcopy"))
925 {
926 if(jspSource.isShowing() && jtpSource.hasFocus())
927 {
928 jtpSource.copy();
929 }
930 else
931 {
932 jtpMain.copy();
933 }
934 }
935 else if(command.equals("textpaste"))
936 {
937 if(jspSource.isShowing() && jtpSource.hasFocus())
938 {
939 jtpSource.paste();
940 }
941 else
942 {
943 jtpMain.paste();
944 }
945 }
946 else if(command.equals("describe"))
947 {
948 System.out.println("------------DOCUMENT------------");
949 System.out.println("Content Type : " + jtpMain.getContentType());
950 System.out.println("Editor Kit : " + jtpMain.getEditorKit());
951 System.out.println("Doc Tree :");
952 System.out.println("");
953 describeDocument(jtpMain.getStyledDocument());
954 System.out.println("--------------------------------");
955 System.out.println("");
956 }
957 else if(command.equals("describecss"))
958 {
959 System.out.println("-----------STYLESHEET-----------");
960 System.out.println("Stylesheet Rules");
961 Enumeration rules = styleSheet.getStyleNames();
962 while(rules.hasMoreElements())
963 {
964 String ruleName = (String)(rules.nextElement());
965 Style styleRule = styleSheet.getStyle(ruleName);
966 System.out.println(styleRule.toString());
967 }
968 System.out.println("--------------------------------");
969 System.out.println("");
970 }
971 else if(command.equals("whattags"))
972 {
973 System.out.println("Caret Position : " + jtpMain.getCaretPosition());
974 AttributeSet attribSet = jtpMain.getCharacterAttributes();
975 Enumeration attribs = attribSet.getAttributeNames();
976 System.out.println("Attributes : ");
977 while(attribs.hasMoreElements())
978 {
979 String attribName = attribs.nextElement().toString();
980 System.out.println(" " + attribName + " | " + attribSet.getAttribute(attribName));
981 }
982 }
983 else if(command.equals("toggletoolbar"))
984 {
985 jToolBar.setVisible(jcbmiViewToolbar.isSelected());
986 }
987 else if(command.equals("viewsource"))
988 {
989 toggleSourceWindow();
990 }
991 else if(command.equals("serialize"))
992 {
993 serializeOut((HTMLDocument)(jtpMain.getDocument()));
994 }
995 else if(command.equals("readfromser"))
996 {
997 serializeIn();
998 }
999 else if(command.equals("inserttable"))
1000 {
1001 String[] fieldNames = { "rows", "cols", "border", "cellspacing", "cellpadding", "width" };
1002 String[] fieldTypes = { "text", "text", "text", "text", "text", "text" };
1003 insertTable((Hashtable)null, fieldNames, fieldTypes);
1004 }
1005 else if(command.equals("inserttablerow"))
1006 {
1007 insertTableRow();
1008 }
1009 else if(command.equals("inserttablecolumn"))
1010 {
1011 insertTableColumn();
1012 }
1013 else if(command.equals("deletetablerow"))
1014 {
1015 deleteTableRow();
1016 }
1017 else if(command.equals("deletetablecolumn"))
1018 {
1019 deleteTableColumn();
1020 }
1021 else if(command.equals("insertbreak"))
1022 {
1023 insertBreak();
1024 }
1025 else if(command.equals("insertlocalimage"))
1026 {
1027 insertLocalImage(null);
1028 }
1029 else if(command.equals("insertserverimage"))
1030 {
1031 insertServerImage();
1032 }
1033 else if(command.equals("insertnbsp"))
1034 {
1035 insertNonbreakingSpace();
1036 }
1037 else if(command.equals("insertform"))
1038 {
1039 String[] fieldNames = { "name", "method", "enctype" };
1040 String[] fieldTypes = { "text", "combo", "text" };
1041 String[] fieldValues = { "", "POST,GET", "text" };
1042 insertFormElement(HTML.Tag.FORM, "form", (Hashtable)null, fieldNames, fieldTypes, fieldValues, true);
1043 }
1044 else if(command.equals("inserttextfield"))
1045 {
1046 Hashtable htAttribs = new Hashtable();
1047 htAttribs.put("type", "text");
1048 String[] fieldNames = { "name", "value", "size", "maxlength" };
1049 String[] fieldTypes = { "text", "text", "text", "text" };
1050 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1051 }
1052 else if(command.equals("inserttextarea"))
1053 {
1054 String[] fieldNames = { "name", "rows", "cols" };
1055 String[] fieldTypes = { "text", "text", "text" };
1056 insertFormElement(HTML.Tag.TEXTAREA, "textarea", (Hashtable)null, fieldNames, fieldTypes, true);
1057 }
1058 else if(command.equals("insertcheckbox"))
1059 {
1060 Hashtable htAttribs = new Hashtable();
1061 htAttribs.put("type", "checkbox");
1062 String[] fieldNames = { "name", "checked" };
1063 String[] fieldTypes = { "text", "bool" };
1064 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1065 }
1066 else if(command.equals("insertradiobutton"))
1067 {
1068 Hashtable htAttribs = new Hashtable();
1069 htAttribs.put("type", "radio");
1070 String[] fieldNames = { "name", "checked" };
1071 String[] fieldTypes = { "text", "bool" };
1072 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1073 }
1074 else if(command.equals("insertpassword"))
1075 {
1076 Hashtable htAttribs = new Hashtable();
1077 htAttribs.put("type", "password");
1078 String[] fieldNames = { "name", "value", "size", "maxlength" };
1079 String[] fieldTypes = { "text", "text", "text", "text" };
1080 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1081 }
1082 else if(command.equals("insertbutton"))
1083 {
1084 Hashtable htAttribs = new Hashtable();
1085 htAttribs.put("type", "button");
1086 String[] fieldNames = { "name", "value" };
1087 String[] fieldTypes = { "text", "text" };
1088 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1089 }
1090 else if(command.equals("insertbuttonsubmit"))
1091 {
1092 Hashtable htAttribs = new Hashtable();
1093 htAttribs.put("type", "submit");
1094 String[] fieldNames = { "name", "value" };
1095 String[] fieldTypes = { "text", "text" };
1096 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1097 }
1098 else if(command.equals("insertbuttonreset"))
1099 {
1100 Hashtable htAttribs = new Hashtable();
1101 htAttribs.put("type", "reset");
1102 String[] fieldNames = { "name", "value" };
1103 String[] fieldTypes = { "text", "text" };
1104 insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
1105 }
1106 else if(command.equals("find"))
1107 {
1108 doSearch((String)null, (String)null, false, lastSearchCaseSetting, lastSearchTopSetting);
1109 }
1110 else if(command.equals("findagain"))
1111 {
1112 doSearch(lastSearchFindTerm, (String)null, false, lastSearchCaseSetting, false);
1113 }
1114 else if(command.equals("replace"))
1115 {
1116 doSearch((String)null, (String)null, true, lastSearchCaseSetting, lastSearchTopSetting);
1117 }
1118 else if(command.equals("exit"))
1119 {
1120 this.dispose();
1121 }
1122 else if(command.equals("helpabout"))
1123 {
1124 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("About"), true, Translatrix.getTranslationString("AboutMessage"), SimpleInfoDialog.INFO);
1125 }
1126 }
1127 catch(IOException ioe)
1128 {
1129 logException("IOException in actionPerformed method", ioe);
1130 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
1131 }
1132 catch(BadLocationException ble)
1133 {
1134 logException("BadLocationException in actionPerformed method", ble);
1135 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
1136 }
1137 catch(NumberFormatException nfe)
1138 {
1139 logException("NumberFormatException in actionPerformed method", nfe);
1140 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorNumberFormatException"), SimpleInfoDialog.ERROR);
1141 }
1142 catch(ClassNotFoundException cnfe)
1143 {
1144 logException("ClassNotFound Exception in actionPerformed method", cnfe);
1145 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorClassNotFoundException "), SimpleInfoDialog.ERROR);
1146 }
1147 catch(RuntimeException re)
1148 {
1149 logException("RuntimeException in actionPerformed method", re);
1150 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorRuntimeException"), SimpleInfoDialog.ERROR);
1151 }
1152 }
1153
1154 /* KeyListener methods */
1155 public void keyTyped(KeyEvent ke)
1156 {
1157 Element elem;
1158 String selectedText;
1159 int pos = this.getCaretPosition();
1160 int repos = -1;
1161 if(ke.getKeyChar() == KeyEvent.VK_BACK_SPACE)
1162 {
1163 try
1164 {
1165 if(pos > 0)
1166 {
1167 if((selectedText = jtpMain.getSelectedText()) != null)
1168 {
1169 htmlUtilities.delete();
1170 return;
1171 }
1172 else
1173 {
1174 int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset();
1175 if(sOffset == jtpMain.getSelectionStart())
1176 {
1177 boolean content = true;
1178 if(htmlUtilities.checkParentsTag(HTML.Tag.LI))
1179 {
1180 elem = htmlUtilities.getListItemParent();
1181 content = false;
1182 int so = elem.getStartOffset();
1183 int eo = elem.getEndOffset();
1184 if(so + 1 < eo)
1185 {
1186 char[] temp = jtpMain.getText(so, eo - so).toCharArray();
1187 for(int i=0; i < temp.length; i++)
1188 {
1189 if(!(new Character(temp[i])).isWhitespace(temp[i]))
1190 {
1191 content = true;
1192 }
1193 }
1194 }
1195 if(!content)
1196 {
1197 Element listElement = elem.getParentElement();
1198 htmlUtilities.removeTag(elem, true);
1199 this.setCaretPosition(sOffset - 1);
1200 return;
1201 }
1202 else
1203 {
1204 jtpMain.setCaretPosition(jtpMain.getCaretPosition() - 1);
1205 jtpMain.moveCaretPosition(jtpMain.getCaretPosition() - 2);
1206 jtpMain.replaceSelection("");
1207 return;
1208 }
1209 }
1210 else if(htmlUtilities.checkParentsTag(HTML.Tag.TABLE))
1211 {
1212 jtpMain.setCaretPosition(jtpMain.getCaretPosition() - 1);
1213 ke.consume();
1214 return;
1215 }
1216 }
1217 jtpMain.replaceSelection("");
1218 return;
1219 }
1220 }
1221 }
1222 catch (BadLocationException ble)
1223 {
1224 logException("BadLocationException in keyTyped method", ble);
1225 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
1226 }
1227 catch (IOException ioe)
1228 {
1229 logException("IOException in keyTyped method", ioe);
1230 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
1231 }
1232 }
1233 else if(ke.getKeyChar() == KeyEvent.VK_ENTER)
1234 {
1235 try
1236 {
1237 if(htmlUtilities.checkParentsTag(HTML.Tag.UL) == true | htmlUtilities.checkParentsTag(HTML.Tag.OL) == true)
1238 {
1239 elem = htmlUtilities.getListItemParent();
1240 int so = elem.getStartOffset();
1241 int eo = elem.getEndOffset();
1242 char[] temp = this.getTextPane().getText(so,eo-so).toCharArray();
1243 boolean content = false;
1244 for(int i=0;i<temp.length;i++)
1245 {
1246 if(!(new Character(temp[i])).isWhitespace(temp[i]))
1247 {
1248 content = true;
1249 }
1250 }
1251 if(content)
1252 {
1253 int end = -1;
1254 int j = temp.length;
1255 do
1256 {
1257 j--;
1258 if(new Character(temp[j]).isLetterOrDigit(temp[j]))
1259 {
1260 end = j;
1261 }
1262 } while (end == -1 && j >= 0);
1263 j = end;
1264 do
1265 {
1266 j++;
1267 if(!new Character(temp[j]).isSpaceChar(temp[j]))
1268 {
1269 repos = j - end -1;
1270 }
1271 } while (repos == -1 && j < temp.length);
1272 if(repos == -1)
1273 {
1274 repos = 0;
1275 }
1276 }
1277 if(elem.getStartOffset() == elem.getEndOffset() || !content)
1278 {
1279 manageListElement(elem);
1280 }
1281 else
1282 {
1283 if(this.getCaretPosition() + 1 == elem.getEndOffset())
1284 {
1285 insertListStyle(elem);
1286 this.setCaretPosition(pos - repos);
1287 }
1288 else
1289 {
1290 int caret = this.getCaretPosition();
1291 String tempString = this.getTextPane().getText(caret, eo - caret);
1292 this.getTextPane().select(caret, eo - 1);
1293 this.getTextPane().replaceSelection("");
1294 htmlUtilities.insertListElement(tempString);
1295 Element newLi = htmlUtilities.getListItemParent();
1296 this.setCaretPosition(newLi.getEndOffset() - 1);
1297 }
1298 }
1299 }
1300 }
1301 catch (BadLocationException ble)
1302 {
1303 logException("BadLocationException in keyTyped method", ble);
1304 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
1305 }
1306 catch (IOException ioe)
1307 {
1308 logException("IOException in keyTyped method", ioe);
1309 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
1310 }
1311 }
1312 }
1313 public void keyPressed(KeyEvent e) {}
1314 public void keyReleased(KeyEvent e) {}
1315
1316 public void insertListStyle(Element element)
1317 throws BadLocationException,IOException
1318 {
1319 if(element.getParentElement().getName() == "ol")
1320 {
1321 actionListOrdered.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1322 }
1323 else
1324 {
1325 actionListUnordered.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1326 }
1327 }
1328
1329 /* DocumentListener methods */
1330 public void changedUpdate(DocumentEvent de) { handleDocumentChange(de); }
1331 public void insertUpdate(DocumentEvent de) { handleDocumentChange(de); }
1332 public void removeUpdate(DocumentEvent de) { handleDocumentChange(de); }
1333 public void handleDocumentChange(DocumentEvent de)
1334 {
1335 if(!exclusiveEdit)
1336 {
1337 if(jspSource.isShowing())
1338 {
1339 if(de.getDocument() instanceof HTMLDocument || de.getDocument() instanceof ExtendedHTMLDocument)
1340 {
1341 jtpSource.getDocument().removeDocumentListener(this);
1342 jtpSource.setText(jtpMain.getText());
1343 jtpSource.getDocument().addDocumentListener(this);
1344 }
1345 else if(de.getDocument() instanceof PlainDocument || de.getDocument() instanceof DefaultStyledDocument)
1346 {
1347 jtpMain.getDocument().removeDocumentListener(this);
1348 jtpMain.setText(jtpSource.getText());
1349 jtpMain.getDocument().addDocumentListener(this);
1350 }
1351 }
1352 }
1353 }
1354
1355 /** Method for setting a document as the current document for the text pane
1356 * and re-registering the controls and settings for it
1357 */
1358 public void registerDocument(ExtendedHTMLDocument htmlDoc)
1359 {
1360 jtpMain.setDocument(htmlDoc);
1361 jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
1362 jtpMain.getDocument().addDocumentListener(this);
1363 purgeUndos();
1364 registerDocumentStyles();
1365 }
1366
1367 /** Method for locating the available CSS style for the document and adding
1368 * them to the styles selector
1369 */
1370 public void registerDocumentStyles()
1371 {
1372 if(jcmbStyleSelector == null || htmlDoc == null)
1373 {
1374 return;
1375 }
1376 jcmbStyleSelector.setEnabled(false);
1377 jcmbStyleSelector.removeAllItems();
1378 jcmbStyleSelector.addItem(Translatrix.getTranslationString("NoCSSStyle"));
1379 for(Enumeration e = htmlDoc.getStyleNames(); e.hasMoreElements();)
1380 {
1381 String name = (String) e.nextElement();
1382 if(name.length() > 0 && name.charAt(0) == '.')
1383 {
1384 jcmbStyleSelector.addItem(name.substring(1));
1385 }
1386 }
1387 jcmbStyleSelector.setEnabled(true);
1388 }
1389
1390 /** Method for inserting an HTML Table
1391 */
1392 private void insertTable(Hashtable attribs, String[] fieldNames, String[] fieldTypes)
1393 throws IOException, BadLocationException, RuntimeException, NumberFormatException
1394 {
1395 int caretPos = jtpMain.getCaretPosition();
1396 StringBuffer compositeElement = new StringBuffer("<TABLE");
1397 if(attribs != null && attribs.size() > 0)
1398 {
1399 Enumeration attribEntries = attribs.keys();
1400 while(attribEntries.hasMoreElements())
1401 {
1402 Object entryKey = attribEntries.nextElement();
1403 Object entryValue = attribs.get(entryKey);
1404 if(entryValue != null && entryValue != "")
1405 {
1406 compositeElement.append(" " + entryKey + "=" + '"' + entryValue + '"');
1407 }
1408 }
1409 }
1410 int rows = 0;
1411 int cols = 0;
1412 if(fieldNames != null && fieldNames.length > 0)
1413 {
1414 PropertiesDialog propertiesDialog = new PropertiesDialog(this.getFrame(), fieldNames, fieldTypes, Translatrix.getTranslationString("FormDialogTitle"), true);
1415 propertiesDialog.show();
1416 String decision = propertiesDialog.getDecisionValue();
1417 if(decision.equals(Translatrix.getTranslationString("DialogCancel")))
1418 {
1419 propertiesDialog.dispose();
1420 propertiesDialog = null;
1421 return;
1422 }
1423 else
1424 {
1425 for(int iter = 0; iter < fieldNames.length; iter++)
1426 {
1427 String fieldName = fieldNames[iter];
1428 String propValue = propertiesDialog.getFieldValue(fieldName);
1429 if(propValue != null && propValue != "" && propValue.length() > 0)
1430 {
1431 if(fieldName.equals("rows"))
1432 {
1433 rows = Integer.parseInt(propValue);
1434 }
1435 else if(fieldName.equals("cols"))
1436 {
1437 cols = Integer.parseInt(propValue);
1438 }
1439 else
1440 {
1441 compositeElement.append(" " + fieldName + "=" + '"' + propValue + '"');
1442 }
1443 }
1444 }
1445 }
1446 propertiesDialog.dispose();
1447 propertiesDialog = null;
1448 }
1449 compositeElement.append(">");
1450 for(int i = 0; i < rows; i++)
1451 {
1452 compositeElement.append("<TR>");
1453 for(int j = 0; j < cols; j++)
1454 {
1455 compositeElement.append("<TD></TD>");
1456 }
1457 compositeElement.append("</TR>");
1458 }
1459 compositeElement.append("</TABLE><P>&nbsp;<P>");
1460 htmlKit.insertHTML(htmlDoc, caretPos, compositeElement.toString(), 0, 0, HTML.Tag.TABLE);
1461 jtpMain.setCaretPosition(caretPos + 1);
1462 refreshOnUpdate();
1463 }
1464
1465 /** Method for inserting a row into an HTML Table
1466 */
1467 private void insertTableRow()
1468 {
1469 int caretPos = jtpMain.getCaretPosition();
1470 Element element = htmlDoc.getCharacterElement(jtpMain.getCaretPosition());
1471 Element elementParent = element.getParentElement();
1472 int startPoint = -1;
1473 int columnCount = -1;
1474 while(elementParent != null && !elementParent.getName().equals("body"))
1475 {
1476 if(elementParent.getName().equals("tr"))
1477 {
1478 startPoint = elementParent.getStartOffset();
1479 columnCount = elementParent.getElementCount();
1480 break;
1481 }
1482 else
1483 {
1484 elementParent = elementParent.getParentElement();
1485 }
1486 }
1487 if(startPoint > -1 && columnCount > -1)
1488 {
1489 jtpMain.setCaretPosition(startPoint);
1490 StringBuffer sRow = new StringBuffer();
1491 sRow.append("<TR>");
1492 for(int i = 0; i < columnCount; i++)
1493 {
1494 sRow.append("<TD></TD>");
1495 }
1496 sRow.append("</TR>");
1497 ActionEvent actionEvent = new ActionEvent(jtpMain, 0, "insertTableRow");
1498 new HTMLEditorKit.InsertHTMLTextAction("insertTableRow", sRow.toString(), HTML.Tag.TABLE, HTML.Tag.TR).actionPerformed(actionEvent);
1499 refreshOnUpdate();
1500 jtpMain.setCaretPosition(caretPos);
1501 }
1502 }
1503
1504 /** Method for inserting a column into an HTML Table
1505 */
1506 private void insertTableColumn()
1507 {
1508 int caretPos = jtpMain.getCaretPosition();
1509 Element element = htmlDoc.getCharacterElement(jtpMain.getCaretPosition());
1510 Element elementParent = element.getParentElement();
1511 int startPoint = -1;
1512 int rowCount = -1;
1513 int cellOffset = 0;
1514 while(elementParent != null && !elementParent.getName().equals("body"))
1515 {
1516 if(elementParent.getName().equals("table"))
1517 {
1518 startPoint = elementParent.getStartOffset();
1519 rowCount = elementParent.getElementCount();
1520 break;
1521 }
1522 else if(elementParent.getName().equals("tr"))
1523 {
1524 int rowStart = elementParent.getStartOffset();
1525 int rowCells = elementParent.getElementCount();
1526 for(int i = 0; i < rowCells; i++)
1527 {
1528 Element currentCell = elementParent.getElement(i);
1529 if(jtpMain.getCaretPosition() >= currentCell.getStartOffset() && jtpMain.getCaretPosition() <= currentCell.getEndOffset())
1530 {
1531 cellOffset = i;
1532 }
1533 }
1534 elementParent = elementParent.getParentElement();
1535 }
1536 else
1537 {
1538 elementParent = elementParent.getParentElement();
1539 }
1540 }
1541 if(startPoint > -1 && rowCount > -1)
1542 {
1543 jtpMain.setCaretPosition(startPoint);
1544 String sCell = "<TD></TD>";
1545 ActionEvent actionEvent = new ActionEvent(jtpMain, 0, "insertTableCell");
1546 for(int i = 0; i < rowCount; i++)
1547 {
1548 Element row = elementParent.getElement(i);
1549 Element whichCell = row.getElement(cellOffset);
1550 jtpMain.setCaretPosition(whichCell.getStartOffset());
1551 new HTMLEditorKit.InsertHTMLTextAction("insertTableCell", sCell, HTML.Tag.TR, HTML.Tag.TD, HTML.Tag.TH, HTML.Tag.TD).actionPerformed(actionEvent);
1552 }
1553 refreshOnUpdate();
1554 jtpMain.setCaretPosition(caretPos);
1555 }
1556 }
1557
1558 /** Method for inserting a cell into an HTML Table
1559 */
1560 private void insertTableCell()
1561 {
1562 String sCell = "<TD></TD>";
1563 ActionEvent actionEvent = new ActionEvent(jtpMain, 0, "insertTableCell");
1564 new HTMLEditorKit.InsertHTMLTextAction("insertTableCell", sCell, HTML.Tag.TR, HTML.Tag.TD, HTML.Tag.TH, HTML.Tag.TD).actionPerformed(actionEvent);
1565 refreshOnUpdate();
1566 }
1567
1568 /** Method for deleting a row from an HTML Table
1569 */
1570 private void deleteTableRow()
1571 throws BadLocationException
1572 {
1573 int caretPos = jtpMain.getCaretPosition();
1574 Element element = htmlDoc.getCharacterElement(jtpMain.getCaretPosition());
1575 Element elementParent = element.getParentElement();
1576 int startPoint = -1;
1577 int endPoint = -1;
1578 while(elementParent != null && !elementParent.getName().equals("body"))
1579 {
1580 if(elementParent.getName().equals("tr"))
1581 {
1582 startPoint = elementParent.getStartOffset();
1583 endPoint = elementParent.getEndOffset();
1584 break;
1585 }
1586 else
1587 {
1588 elementParent = elementParent.getParentElement();
1589 }
1590 }
1591 if(startPoint > -1 && endPoint > startPoint)
1592 {
1593 htmlDoc.remove(startPoint, endPoint - startPoint);
1594 jtpMain.setDocument(htmlDoc);
1595 registerDocument(htmlDoc);
1596 refreshOnUpdate();
1597 if(caretPos >= htmlDoc.getLength())
1598 {
1599 caretPos = htmlDoc.getLength() - 1;
1600 }
1601 jtpMain.setCaretPosition(caretPos);
1602 }
1603 }
1604
1605 /** Method for deleting a column from an HTML Table
1606 */
1607 private void deleteTableColumn()
1608 throws BadLocationException
1609 {
1610 int caretPos = jtpMain.getCaretPosition();
1611 Element element = htmlDoc.getCharacterElement(jtpMain.getCaretPosition());
1612 Element elementParent = element.getParentElement();
1613 Element elementCell = (Element)null;
1614 Element elementRow = (Element)null;
1615 Element elementTable = (Element)null;
1616 // Locate the table, row, and cell location of the cursor
1617 while(elementParent != null && !elementParent.getName().equals("body"))
1618 {
1619 if(elementParent.getName().equals("td"))
1620 {
1621 elementCell = elementParent;
1622 }
1623 else if(elementParent.getName().equals("tr"))
1624 {
1625 elementRow = elementParent;
1626 }
1627 else if(elementParent.getName().equals("table"))
1628 {
1629 elementTable = elementParent;
1630 }
1631 elementParent = elementParent.getParentElement();
1632 }
1633 int whichColumn = -1;
1634 if(elementCell != null && elementRow != null && elementTable != null)
1635 {
1636 // Find the column the cursor is in
1637 for(int i = 0; i < elementRow.getElementCount(); i++)
1638 {
1639 if(elementCell == elementRow.getElement(i))
1640 {
1641 whichColumn = i;
1642 }
1643 }
1644 if(whichColumn > -1)
1645 {
1646 // Iterate through the table rows, deleting cells from the indicated column
1647 for(int i = 0; i < elementTable.getElementCount(); i++)
1648 {
1649 elementRow = elementTable.getElement(i);
1650 elementCell = (elementRow.getElementCount() > whichColumn ? elementRow.getElement(whichColumn) : elementRow.getElement(elementRow.getElementCount() - 1));
1651 int columnCellStart = elementCell.getStartOffset();
1652 int columnCellEnd = elementCell.getEndOffset();
1653 htmlDoc.remove(columnCellStart, columnCellEnd - columnCellStart);
1654 }
1655 jtpMain.setDocument(htmlDoc);
1656 registerDocument(htmlDoc);
1657 refreshOnUpdate();
1658 if(caretPos >= htmlDoc.getLength())
1659 {
1660 caretPos = htmlDoc.getLength() - 1;
1661 }
1662 jtpMain.setCaretPosition(caretPos);
1663 }
1664 }
1665 }
1666
1667 /** Method for inserting a break (BR) element
1668 */
1669 private void insertBreak()
1670 throws IOException, BadLocationException, RuntimeException
1671 {
1672 int caretPos = jtpMain.getCaretPosition();
1673 htmlKit.insertHTML(htmlDoc, caretPos, "<BR>", 0, 0, HTML.Tag.BR);
1674 jtpMain.setCaretPosition(caretPos + 1);
1675 }
1676
1677 /** Method for inserting a non-breaking space (&nbsp;)
1678 */
1679 private void insertNonbreakingSpace()
1680 throws IOException, BadLocationException, RuntimeException
1681 {
1682 int caretPos = jtpMain.getCaretPosition();
1683 htmlDoc.insertString(caretPos, "\240", jtpMain.getInputAttributes());
1684 jtpMain.setCaretPosition(caretPos + 1);
1685 }
1686
1687 /** Method for inserting a form element
1688 */
1689 private void insertFormElement(HTML.Tag baseTag, String baseElement, Hashtable attribs, String[] fieldNames, String[] fieldTypes, String[] fieldValues, boolean hasClosingTag)
1690 throws IOException, BadLocationException, RuntimeException
1691 {
1692 int caretPos = jtpMain.getCaretPosition();
1693 StringBuffer compositeElement = new StringBuffer("<" + baseElement);
1694 if(attribs != null && attribs.size() > 0)
1695 {
1696 Enumeration attribEntries = attribs.keys();
1697 while(attribEntries.hasMoreElements())
1698 {
1699 Object entryKey = attribEntries.nextElement();
1700 Object entryValue = attribs.get(entryKey);
1701 if(entryValue != null && entryValue != "")
1702 {
1703 compositeElement.append(" " + entryKey + "=" + '"' + entryValue + '"');
1704 }
1705 }
1706 }
1707 if(fieldNames != null && fieldNames.length > 0)
1708 {
1709 PropertiesDialog propertiesDialog = new PropertiesDialog(this.getFrame(), fieldNames, fieldTypes, fieldValues, Translatrix.getTranslationString("FormDialogTitle"), true);
1710 propertiesDialog.show();
1711 String decision = propertiesDialog.getDecisionValue();
1712 if(decision.equals(Translatrix.getTranslationString("DialogCancel")))
1713 {
1714 propertiesDialog.dispose();
1715 propertiesDialog = null;
1716 return;
1717 }
1718 else
1719 {
1720 for(int iter = 0; iter < fieldNames.length; iter++)
1721 {
1722 String fieldName = fieldNames[iter];
1723 String propValue = propertiesDialog.getFieldValue(fieldName);
1724 if(propValue != null && propValue.length() > 0)
1725 {
1726 if(fieldName.equals("checked"))
1727 {
1728 if(propValue.equals("true"))
1729 {
1730 compositeElement.append(" " + fieldName + "=" + '"' + propValue + '"');
1731 }
1732 }
1733 else
1734 {
1735 compositeElement.append(" " + fieldName + "=" + '"' + propValue + '"');
1736 }
1737 }
1738 }
1739 }
1740 propertiesDialog.dispose();
1741 propertiesDialog = null;
1742 }
1743 // --- Convenience for editing, this makes the FORM visible
1744 if(useFormIndicator && baseElement.equals("form"))
1745 {
1746 compositeElement.append(" bgcolor=" + '"' + clrFormIndicator + '"');
1747 }
1748 // --- END
1749 compositeElement.append(">");
1750 if(hasClosingTag)
1751 {
1752 compositeElement.append("</" + baseElement + ">");
1753 }
1754 if(baseTag == HTML.Tag.FORM)
1755 {
1756 compositeElement.append("<P>&nbsp;</P>");
1757 }
1758 htmlKit.insertHTML(htmlDoc, caretPos, compositeElement.toString(), 0, 0, baseTag);
1759 // jtpMain.setCaretPosition(caretPos + 1);
1760 refreshOnUpdate();
1761 }
1762
1763 /** Alternate method call for inserting a form element
1764 */
1765 private void insertFormElement(HTML.Tag baseTag, String baseElement, Hashtable attribs, String[] fieldNames, String[] fieldTypes, boolean hasClosingTag)
1766 throws IOException, BadLocationException, RuntimeException
1767 {
1768 insertFormElement(baseTag, baseElement, attribs, fieldNames, fieldTypes, new String[fieldNames.length], hasClosingTag);
1769 }
1770
1771 /** Method that handles initial list insertion and deletion
1772 */
1773 public void manageListElement(Element element)
1774 {
1775 Element h = htmlUtilities.getListItemParent();
1776 Element listElement = h.getParentElement();
1777 if(h != null)
1778 {
1779 htmlUtilities.removeTag(h, true);
1780 }
1781 }
1782
1783 /** Method to initiate a find/replace operation
1784 */
1785 private void doSearch(String searchFindTerm, String searchReplaceTerm, boolean bIsFindReplace, boolean bCaseSensitive, boolean bStartAtTop)
1786 {
1787 boolean bReplaceAll = false;
1788 JTextPane searchPane = jtpMain;
1789 if(jspSource.isShowing() || jtpSource.hasFocus())
1790 {
1791 searchPane = jtpSource;
1792 }
1793 if(searchFindTerm == null || (bIsFindReplace && searchReplaceTerm == null))
1794 {
1795 SearchDialog sdSearchInput = new SearchDialog(this.getFrame(), Translatrix.getTranslationString("SearchDialogTitle"), true, bIsFindReplace, bCaseSensitive, bStartAtTop);
1796 searchFindTerm = sdSearchInput.getFindTerm();
1797 searchReplaceTerm = sdSearchInput.getReplaceTerm();
1798 bCaseSensitive = sdSearchInput.getCaseSensitive();
1799 bStartAtTop = sdSearchInput.getStartAtTop();
1800 bReplaceAll = sdSearchInput.getReplaceAll();
1801 }
1802 if(searchFindTerm != null && (!bIsFindReplace || searchReplaceTerm != null))
1803 {
1804 if(bReplaceAll)
1805 {
1806 int results = findText(searchFindTerm, searchReplaceTerm, bCaseSensitive, 0);
1807 int findOffset = 0;
1808 if(results > -1)
1809 {
1810 while(results > -1)
1811 {
1812 findOffset = findOffset + searchReplaceTerm.length();
1813 results = findText(searchFindTerm, searchReplaceTerm, bCaseSensitive, findOffset);
1814 }
1815 }
1816 else
1817 {
1818 SimpleInfoDialog sidWarn = new SimpleInfoDialog(this.getFrame(), "", true, Translatrix.getTranslationString("ErrorNoOccurencesFound") + ":\n" + searchFindTerm, SimpleInfoDialog.WARNING);
1819 }
1820 }
1821 else
1822 {
1823 int results = findText(searchFindTerm, searchReplaceTerm, bCaseSensitive, (bStartAtTop ? 0 : searchPane.getCaretPosition()));
1824 if(results == -1)
1825 {
1826 SimpleInfoDialog sidWarn = new SimpleInfoDialog(this.getFrame(), "", true, Translatrix.getTranslationString("ErrorNoMatchFound") + ":\n" + searchFindTerm, SimpleInfoDialog.WARNING);
1827 }
1828 }
1829 lastSearchFindTerm = new String(searchFindTerm);
1830 if(searchReplaceTerm != null)
1831 {
1832 lastSearchReplaceTerm = new String(searchReplaceTerm);
1833 }
1834 else
1835 {
1836 lastSearchReplaceTerm = (String)null;
1837 }
1838 lastSearchCaseSetting = bCaseSensitive;
1839 lastSearchTopSetting = bStartAtTop;
1840 }
1841 }
1842
1843 /** Method for finding (and optionally replacing) a string in the text
1844 */
1845 private int findText(String findTerm, String replaceTerm, boolean bCaseSenstive, int iOffset)
1846 {
1847 JTextPane jtpFindSource;
1848 if(jspSource.isShowing() || jtpSource.hasFocus())
1849 {
1850 jtpFindSource = jtpSource;
1851 }
1852 else
1853 {
1854 jtpFindSource = jtpMain;
1855 }
1856 int searchPlace = -1;
1857 try
1858 {
1859 Document baseDocument = jtpFindSource.getDocument();
1860 searchPlace =
1861 (bCaseSenstive ?
1862 baseDocument.getText(0, baseDocument.getLength()).indexOf(findTerm, iOffset) :
1863 baseDocument.getText(0, baseDocument.getLength()).toLowerCase().indexOf(findTerm.toLowerCase(), iOffset)
1864 );
1865 if(searchPlace > -1)
1866 {
1867 if(replaceTerm != null)
1868 {
1869 AttributeSet attribs = null;
1870 if(baseDocument instanceof HTMLDocument)
1871 {
1872 Element element = ((HTMLDocument)baseDocument).getCharacterElement(searchPlace);
1873 attribs = element.getAttributes();
1874 }
1875 baseDocument.remove(searchPlace, findTerm.length());
1876 baseDocument.insertString(searchPlace, replaceTerm, attribs);
1877 jtpFindSource.setCaretPosition(searchPlace + replaceTerm.length());
1878 jtpFindSource.requestFocus();
1879 jtpFindSource.select(searchPlace, searchPlace + replaceTerm.length());
1880 }
1881 else
1882 {
1883 jtpFindSource.setCaretPosition(searchPlace + findTerm.length());
1884 jtpFindSource.requestFocus();
1885 jtpFindSource.select(searchPlace, searchPlace + findTerm.length());
1886 }
1887 }
1888 }
1889 catch(BadLocationException ble)
1890 {
1891 logException("BadLocationException in actionPerformed method", ble);
1892 SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
1893 }
1894 return searchPlace;
1895 }
1896
1897 /** Method for inserting an image from a file
1898 */
1899 private void insertLocalImage(File whatImage)
1900 throws IOException, BadLocationException, RuntimeException
1901 {
1902 if(whatImage == null)
1903 {
1904 whatImage = getImageFromChooser(".", extsIMG, Translatrix.getTranslationString("FiletypeIMG"));
1905 }
1906 if(whatImage != null)
1907 {
1908 int caretPos = jtpMain.getCaretPosition();
1909 htmlKit.insertHTML(htmlDoc, caretPos, "<IMG SRC=\"" + whatImage + "\">", 0, 0, HTML.Tag.IMG);
1910 jtpMain.setCaretPosition(caretPos + 1);
1911 refreshOnUpdate();
1912 }
1913 }
1914
1915 /** Method for inserting an image from a server
1916 */
1917 private void insertServerImage()
1918 throws BadLocationException
1919 {
1920 if(ServletURL != null)
1921 {
1922 try
1923 {
1924 URL theServlet = new URL(ServletURL + "?GetImages=" + TreePilotSystemID + "&ImageExtensions=" + TreePilotProperties.getString("ValidImageExtensions"));
1925 URLConnection conn = theServlet.openConnection();
1926 ObjectInputStream in = new ObjectInputStream(conn.getInputStream());
1927 String[] imageList = (String[]) in.readObject();
1928 int caretPos = jtpMain.getCaretPosition();
1929 ImageDialog imageDialog = new ImageDialog(this, ImageDir + TreePilotSystemID, imageList, "Image Chooser", true);
1930 String selectedImage = imageDialog.getSelectedImage();
1931 imageDialog.dispose();
1932 if(selectedImage != null && !selectedImage.equals(""))
1933 {
1934 htmlKit.insertHTML(htmlDoc, caretPos, selectedImage, 0, 0, HTML.Tag.IMG);
1935 jtpMain.setCaretPosition(caretPos + 1);
1936 }
1937 jtpMain.requestFocus();
1938 in.close();
1939 }
1940 catch (MalformedURLException mue)
1941 {
1942 System.err.println("MalFormedURLException during insertImage " + mue);
1943 }
1944 catch (IOException ie)
1945 {
1946 System.err.println("IOException during insertImage " + ie);
1947 }
1948 catch (ClassNotFoundException cnfe)
1949 {
1950 System.err.println("ClassNotFoundException during insertImage" + cnfe);
1951 }
1952 }
1953 }
1954
1955 /** Method for inserting an image
1956 */
1957 public String insertFile()
1958 {
1959 String selectedFile = null;
1960 if(ServletURL != null)
1961 {
1962 try
1963 {
1964 URL theServlet = new URL(ServletURL + "?GetFiles=" + TreePilotSystemID + "&FileExtensions=" + TreePilotProperties.getString("ValidFileExtensions"));
1965 URLConnection conn = theServlet.openConnection();
1966 ObjectInputStream in = new ObjectInputStream(conn.getInputStream());
1967 String[] fileList = (String[]) in.readObject();
1968 FileDialog fileDialog = new FileDialog(this, ImageDir + TreePilotSystemID, fileList, "File Chooser", true);
1969 selectedFile = fileDialog.getSelectedFile();
1970 fileDialog.dispose();
1971 in.close();
1972 }
1973 catch (MalformedURLException mue)
1974 {
1975 System.err.println("MalFormedURLException during insertFile " + mue);
1976 }
1977 catch (IOException ie)
1978 {
1979 System.err.println("IOException during insertFile " + ie);
1980 }
1981 catch (ClassNotFoundException cnfe)
1982 {
1983 System.err.println("ClassNotFoundException during insertFile" + cnfe);
1984 }
1985 }
1986 return selectedFile;
1987 }
1988
1989 /** Method for saving text as a complete HTML document
1990 */
1991 private void writeOut(HTMLDocument doc, File whatFile)
1992 throws IOException, BadLocationException
1993 {
1994 if(whatFile == null)
1995 {
1996 whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsHTML, Translatrix.getTranslationString("FiletypeHTML"));
1997 }
1998 if(whatFile != null)
1999 {
2000 FileWriter fw = new FileWriter(whatFile);
2001 htmlKit.write(fw, doc, 0, doc.getLength());
2002 fw.flush();
2003 fw.close();
2004 currentFile = whatFile;
2005 updateTitle();
2006 }
2007 refreshOnUpdate();
2008 }
2009
2010 /** Method for saving text as an HTML fragment
2011 */
2012 private void writeOutFragment(HTMLDocument doc, String containingTag)
2013 throws IOException, BadLocationException
2014 {
2015 File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsHTML, Translatrix.getTranslationString("FiletypeHTML"));
2016 if(whatFile != null)
2017 {
2018 FileWriter fw = new FileWriter(whatFile);
2019 // Element eleBody = locateElementInDocument((StyledDocument)doc, containingTag);
2020 // htmlKit.write(fw, doc, eleBody.getStartOffset(), eleBody.getEndOffset());
2021 String docTextCase = jtpSource.getText().toLowerCase();
2022 int tagStart = docTextCase.indexOf("<" + containingTag.toLowerCase());
2023 int tagStartClose = docTextCase.indexOf(">", tagStart) + 1;
2024 String closeTag = "</" + containingTag.toLowerCase() + ">";
2025 int tagEndOpen = docTextCase.indexOf(closeTag);
2026 if(tagStartClose < 0) { tagStartClose = 0; }
2027 if(tagEndOpen < 0 || tagEndOpen > docTextCase.length()) { tagEndOpen = docTextCase.length(); }
2028 String bodyText = jtpSource.getText().substring(tagStartClose, tagEndOpen);
2029 fw.write(bodyText, 0, bodyText.length());
2030 fw.flush();
2031 fw.close();
2032 }
2033 refreshOnUpdate();
2034 }
2035
2036 /** Method for saving text as an RTF document
2037 */
2038 private void writeOutRTF(StyledDocument doc)
2039 throws IOException, BadLocationException
2040 {
2041 File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsRTF, Translatrix.getTranslationString("FiletypeRTF"));
2042 if(whatFile != null)
2043 {
2044 FileOutputStream fos = new FileOutputStream(whatFile);
2045 RTFEditorKit rtfKit = new RTFEditorKit();
2046 rtfKit.write(fos, doc, 0, doc.getLength());
2047 fos.flush();
2048 fos.close();
2049 }
2050 refreshOnUpdate();
2051 }
2052
2053 /** Method for saving text as a Base64 encoded document
2054 */
2055 private void writeOutBase64(String text)
2056 throws IOException, BadLocationException
2057 {
2058 File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsB64, Translatrix.getTranslationString("FiletypeB64"));
2059 if(whatFile != null)
2060 {
2061 String base64text = Base64Codec.encode(text);
2062 FileWriter fw = new FileWriter(whatFile);
2063 fw.write(base64text, 0, base64text.length());
2064 fw.flush();
2065 fw.close();
2066 }
2067 refreshOnUpdate();
2068 }
2069
2070 /** Method to invoke loading HTML into the app
2071 */
2072 private void openDocument(File whatFile)
2073 throws IOException, BadLocationException
2074 {
2075 if(whatFile == null)
2076 {
2077 whatFile = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsHTML, Translatrix.getTranslationString("FiletypeHTML"));
2078 }
2079 if(whatFile != null)
2080 {
2081 try
2082 {
2083 loadDocument(whatFile, null);
2084 }
2085 catch(ChangedCharSetException ccse)
2086 {
2087 String charsetType = ccse.getCharSetSpec().toLowerCase();
2088 int pos = charsetType.indexOf("charset");
2089 if(pos == -1)
2090 {
2091 throw ccse;
2092 }
2093 while(pos < charsetType.length() && charsetType.charAt(pos) != '=')
2094 {
2095 pos++;
2096 }
2097 pos++; // Places file cursor past the equals sign (=)
2098 String whatEncoding = charsetType.substring(pos).trim();
2099 loadDocument(whatFile, whatEncoding);
2100 }
2101 }
2102 refreshOnUpdate();
2103 }
2104
2105 /** Method for loading HTML document into the app, including document encoding setting
2106 */
2107 private void loadDocument(File whatFile, String whatEncoding)
2108 throws IOException, BadLocationException
2109 {
2110 Reader r = null;
2111 htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
2112 try
2113 {
2114 if(whatEncoding == null)
2115 {
2116 r = new InputStreamReader(new FileInputStream(whatFile));
2117 }
2118 else
2119 {
2120 r = new InputStreamReader(new FileInputStream(whatFile), whatEncoding);
2121 htmlDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
2122 }
2123 htmlKit.read(r, htmlDoc, 0);
2124 r.close();
2125 registerDocument(htmlDoc);
2126 jtpSource.setText(jtpMain.getText());
2127 currentFile = whatFile;
2128 updateTitle();
2129 }
2130 finally
2131 {
2132 if(r != null)
2133 {
2134 r.close();
2135 }
2136 }
2137 }
2138
2139 /** Method for loading a Base64 encoded document
2140 */
2141 private void openDocumentBase64(File whatFile)
2142 throws IOException, BadLocationException
2143 {
2144 if(whatFile == null)
2145 {
2146 whatFile = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsB64, Translatrix.getTranslationString("FiletypeB64"));
2147 }
2148 if(whatFile != null)
2149 {
2150 FileReader fr = new FileReader(whatFile);
2151 int nextChar = 0;
2152 StringBuffer encodedText = new StringBuffer();
2153 try
2154 {
2155 while((nextChar = fr.read()) != -1)
2156 {
2157 encodedText.append((char)nextChar);
2158 }
2159 fr.close();
2160 jtpSource.setText(Base64Codec.decode(encodedText.toString()));
2161 jtpMain.setText(jtpSource.getText());
2162 registerDocument((ExtendedHTMLDocument)(jtpMain.getDocument()));
2163 }
2164 finally
2165 {
2166 if(fr != null)
2167 {
2168 fr.close();
2169 }
2170 }
2171 }
2172 }
2173
2174 /** Method for loading a Stylesheet into the app
2175 */
2176 private void openStyleSheet(File fileCSS)
2177 throws IOException
2178 {
2179 if(fileCSS == null)
2180 {
2181 fileCSS = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsCSS, Translatrix.getTranslationString("FiletypeCSS"));
2182 }
2183 if(fileCSS != null)
2184 {
2185 String currDocText = jtpMain.getText();
2186 htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
2187 styleSheet = htmlDoc.getStyleSheet();
2188 URL cssUrl = fileCSS.toURL();
2189 InputStream is = cssUrl.openStream();
2190 BufferedReader br = new BufferedReader(new InputStreamReader(is));
2191 styleSheet.loadRules(br, cssUrl);
2192 br.close();
2193 htmlDoc = new ExtendedHTMLDocument(styleSheet);
2194 registerDocument(htmlDoc);
2195 jtpMain.setText(currDocText);
2196 jtpSource.setText(jtpMain.getText());
2197 }
2198 refreshOnUpdate();
2199 }
2200
2201 /** Method for serializing the document out to a file
2202 */
2203 public void serializeOut(HTMLDocument doc)
2204 throws IOException
2205 {
2206 File whatFile = getFileFromChooser(".", JFileChooser.SAVE_DIALOG, extsSer, Translatrix.getTranslationString("FiletypeSer"));
2207 if(whatFile != null)
2208 {
2209 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(whatFile));
2210 oos.writeObject(doc);
2211 oos.flush();
2212 oos.close();
2213 }
2214 refreshOnUpdate();
2215 }
2216
2217 /** Method for reading in a serialized document from a file
2218 */
2219 public void serializeIn()
2220 throws IOException, ClassNotFoundException
2221 {
2222 File whatFile = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsSer, Translatrix.getTranslationString("FiletypeSer"));
2223 if(whatFile != null)
2224 {
2225 ObjectInputStream ois = new ObjectInputStream(new FileInputStream(whatFile));
2226 htmlDoc = (ExtendedHTMLDocument)(ois.readObject());
2227 ois.close();
2228 registerDocument(htmlDoc);
2229 validate();
2230 }
2231 refreshOnUpdate();
2232 }
2233
2234 /** Method for obtaining a File for input/output using a JFileChooser dialog
2235 */
2236 private File getFileFromChooser(String startDir, int dialogType, String[] exts, String desc)
2237 {
2238 JFileChooser jfileDialog = new JFileChooser(startDir);
2239 jfileDialog.setDialogType(dialogType);
2240 jfileDialog.setFileFilter(new MutableFilter(exts, desc));
2241 int optionSelected = JFileChooser.CANCEL_OPTION;
2242 if(dialogType == JFileChooser.OPEN_DIALOG)
2243 {
2244 optionSelected = jfileDialog.showOpenDialog(this);
2245 }
2246 else if(dialogType == JFileChooser.SAVE_DIALOG)
2247 {
2248 optionSelected = jfileDialog.showSaveDialog(this);
2249 }
2250 else // default to an OPEN_DIALOG
2251 {
2252 optionSelected = jfileDialog.showOpenDialog(this);
2253 }
2254 if(optionSelected == JFileChooser.APPROVE_OPTION)
2255 {
2256 return jfileDialog.getSelectedFile();
2257 }
2258 return (File)null;
2259 }
2260
2261 /** Method for obtaining an Image for input using a custom JFileChooser dialog
2262 */
2263 private File getImageFromChooser(String startDir, String[] exts, String desc)
2264 {
2265 ImageFileChooser jImageDialog = new ImageFileChooser(startDir);
2266 jImageDialog.setDialogType(JFileChooser.CUSTOM_DIALOG);
2267 jImageDialog.setFileFilter(new MutableFilter(exts, desc));
2268 jImageDialog.setDialogTitle(Translatrix.getTranslationString("ImageDialogTitle"));
2269 int optionSelected = JFileChooser.CANCEL_OPTION;
2270 optionSelected = jImageDialog.showDialog(this, Translatrix.getTranslationString("Insert"));
2271 if(optionSelected == JFileChooser.APPROVE_OPTION)
2272 {
2273 return jImageDialog.getSelectedFile();
2274 }
2275 return (File)null;
2276 }
2277
2278 /** Method for describing the node hierarchy of the document
2279 */
2280 private void describeDocument(StyledDocument doc)
2281 {
2282 Element[] elements = doc.getRootElements();
2283 for(int i = 0; i < elements.length; i++)
2284 {
2285 indent = indentStep;
2286 for(int j = 0; j < indent; j++) { System.out.print(" "); }
2287 System.out.print(elements[i]);
2288 traverseElement(elements[i]);
2289 System.out.println("");
2290 }
2291 }
2292
2293 /** Traverses nodes for the describing method
2294 */
2295 private void traverseElement(Element element)
2296 {
2297 indent += indentStep;
2298 for(int i = 0; i < element.getElementCount(); i++)
2299 {
2300 for(int j = 0; j < indent; j++) { System.out.print(" "); }
2301 System.out.print(element.getElement(i));
2302 traverseElement(element.getElement(i));
2303 }
2304 indent -= indentStep;
2305 }
2306
2307 /** Method to locate a node element by name
2308 */
2309 private Element locateElementInDocument(StyledDocument doc, String elementName)
2310 {
2311 Element[] elements = doc.getRootElements();
2312 for(int i = 0; i < elements.length; i++)
2313 {
2314 if(elements[i].getName().equalsIgnoreCase(elementName))
2315 {
2316 return elements[i];
2317 }
2318 else
2319 {
2320 Element rtnElement = locateChildElementInDocument(elements[i], elementName);
2321 if(rtnElement != null)
2322 {
2323 return rtnElement;
2324 }
2325 }
2326 }
2327 return (Element)null;
2328 }
2329
2330 /** Traverses nodes for the locating method
2331 */
2332 private Element locateChildElementInDocument(Element element, String elementName)
2333 {
2334 for(int i = 0; i < element.getElementCount(); i++)
2335 {
2336 if(element.getElement(i).getName().equalsIgnoreCase(elementName))
2337 {
2338 return element.getElement(i);
2339 }
2340 }
2341 return (Element)null;
2342 }
2343
2344 /** Convenience method for obtaining the WYSIWYG JTextPane
2345 */
2346 public JTextPane getTextPane()
2347 {
2348 return jtpMain;
2349 }
2350
2351 /** Convenience method for obtaining the Source JTextPane
2352 */
2353 public JTextPane getSourcePane()
2354 {
2355 return jtpSource;
2356 }
2357
2358 /** Convenience method for obtaining the application as a Frame
2359 */
2360 public Frame getFrame()
2361 {
2362 return frameHandler;
2363 }
2364
2365 /** Convenience method for setting the parent Frame
2366 */
2367 public void setFrame(Frame parentFrame)
2368 {
2369 frameHandler = parentFrame;
2370 }
2371
2372 /** Convenience method for obtaining the pre-generated menu bar
2373 */
2374 public JMenuBar getMenuBar()
2375 {
2376 return jMenuBar;
2377 }
2378
2379 /** Convenience method for obtaining a custom menu bar
2380 */
2381 public JMenuBar getCustomMenuBar(Vector vcMenus)
2382 {
2383 jMenuBar = new JMenuBar();
2384 for(int i = 0; i < vcMenus.size(); i++)
2385 {
2386 String menuToAdd = ((String)(vcMenus.elementAt(i))).toLowerCase();
2387 if(htMenus.containsKey(menuToAdd))
2388 {
2389 jMenuBar.add((JMenu)(htMenus.get(menuToAdd)));
2390 }
2391 }
2392 return jMenuBar;
2393 }
2394
2395 /** Convenience method for obtaining the pre-generated toolbar
2396 */
2397 public JToolBar getToolBar(boolean isShowing)
2398 {
2399 jcbmiViewToolbar.setState(isShowing);
2400 return jToolBar;
2401 }
2402
2403 /** Convenience method for obtaining the pre-generated toolbar
2404 */
2405 public JToolBar getCustomToolBar(Vector vcTools, boolean isShowing)
2406 {
2407 jcbmiViewToolbar.setState(isShowing);
2408 jToolBar = new JToolBar(JToolBar.HORIZONTAL);
2409 jToolBar.setFloatable(false);
2410 for(int i = 0; i < vcTools.size(); i++)
2411 {
2412 String toolToAdd = ((String)(vcTools.elementAt(i))).toLowerCase();
2413 if(toolToAdd.equals(KEY_TOOL_SEP))
2414 {
2415 jToolBar.add(new JToolBar.Separator());
2416 }
2417 else if(htTools.containsKey(toolToAdd))
2418 {
2419 if(htTools.get(toolToAdd) instanceof JButtonNoFocus)
2420 {
2421 jToolBar.add((JButtonNoFocus)(htTools.get(toolToAdd)));
2422 }
2423 else if(htTools.get(toolToAdd) instanceof JToggleButtonNoFocus)
2424 {
2425 jToolBar.add((JToggleButtonNoFocus)(htTools.get(toolToAdd)));
2426 }
2427 else if(htTools.get(toolToAdd) instanceof JComboBoxNoFocus)
2428 {
2429 jToolBar.add((JComboBoxNoFocus)(htTools.get(toolToAdd)));
2430 }
2431 else
2432 {
2433 jToolBar.add((JComponent)(htTools.get(toolToAdd)));
2434 }
2435 }
2436 }
2437 return jToolBar;
2438 }
2439
2440 /** Convenience method for obtaining the current file handle
2441 */
2442 public File getCurrentFile()
2443 {
2444 return currentFile;
2445 }
2446
2447 /** Convenience method for obtaining the application name
2448 */
2449 public String getAppName()
2450 {
2451 return appName;
2452 }
2453
2454 /** Convenience method for obtaining the document text
2455 */
2456 public String getDocumentText()
2457 {
2458 return jtpMain.getText();
2459 }
2460
2461 /** Convenience method for obtaining the document text
2462 * contained within a tag pair
2463 */
2464 public String getDocumentSubText(String tagBlock)
2465 {
2466 return getSubText(tagBlock);
2467 }
2468
2469 /** Method for extracting the text within a tag
2470 */
2471 private String getSubText(String containingTag)
2472 {
2473 jtpSource.setText(jtpMain.getText());
2474 String docTextCase = jtpSource.getText().toLowerCase();
2475 int tagStart = docTextCase.indexOf("<" + containingTag.toLowerCase());
2476 int tagStartClose = docTextCase.indexOf(">", tagStart) + 1;
2477 String closeTag = "</" + containingTag.toLowerCase() + ">";
2478 int tagEndOpen = docTextCase.indexOf(closeTag);
2479 if(tagStartClose < 0) { tagStartClose = 0; }
2480 if(tagEndOpen < 0 || tagEndOpen > docTextCase.length()) { tagEndOpen = docTextCase.length(); }
2481 return jtpSource.getText().substring(tagStartClose, tagEndOpen);
2482 }
2483
2484 /** Convenience method for obtaining the document text
2485 * contained within the BODY tags (a common request)
2486 */
2487 public String getDocumentBody()
2488 {
2489 return getSubText("body");
2490 }
2491
2492 /** Convenience method for setting the document text
2493 */
2494 public void setDocumentText(String sText)
2495 {
2496 jtpMain.setText(sText);
2497 ((HTMLEditorKit)(jtpMain.getEditorKit())).setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR));
2498 jtpSource.setText(jtpMain.getText());
2499 ((HTMLEditorKit)(jtpSource.getEditorKit())).setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR));
2500 }
2501
2502 /** Convenience method for obtaining the document text
2503 */
2504 private void updateTitle()
2505 {
2506 frameHandler.setTitle(appName + (currentFile == null ? "" : " - " + currentFile.getName()));
2507 }
2508
2509 /** Convenience method for clearing out the UndoManager
2510 */
2511 public void purgeUndos()
2512 {
2513 if(undoMngr != null)
2514 {
2515 undoMngr.discardAllEdits();
2516 undoAction.updateUndoState();
2517 redoAction.updateRedoState();
2518 }
2519 }
2520
2521 /** Convenience method for refreshing and displaying changes
2522 */
2523 public void refreshOnUpdate()
2524 {
2525 jtpMain.setText(jtpMain.getText());
2526 jtpSource.setText(jtpMain.getText());
2527 purgeUndos();
2528 this.repaint();
2529 }
2530
2531 /** Convenience method for deallocating the app resources
2532 */
2533 public void dispose()
2534 {
2535 frameHandler.dispose();
2536 System.exit(0);
2537 }
2538
2539 /** Convenience method for fetching icon images from jar file
2540 */
2541 private ImageIcon getEkitIcon(String iconName)
2542 {
2543 return new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("icons/" + iconName + "HK.gif")));
2544 }
2545
2546 /** Convenience method for outputting exceptions
2547 */
2548 private void logException(String internalMessage, Exception e)
2549 {
2550 System.err.println(internalMessage);
2551 e.printStackTrace(System.err);
2552 }
2553
2554 /** Convenience method for toggling source window visibility
2555 */
2556 private void toggleSourceWindow()
2557 {
2558 if(!(jspSource.isShowing()))
2559 {
2560 jtpSource.setText(jtpMain.getText());
2561 jspltDisplay.setRightComponent(jspSource);
2562 if(exclusiveEdit)
2563 {
2564 jspltDisplay.setDividerLocation(0);
2565 jspltDisplay.setEnabled(false);
2566 }
2567 else
2568 {
2569 jspltDisplay.setDividerLocation(iSplitPos);
2570 jspltDisplay.setEnabled(true);
2571 }
2572 }
2573 else
2574 {
2575 jtpMain.setText(jtpSource.getText());
2576 iSplitPos = jspltDisplay.getDividerLocation();
2577 jspltDisplay.remove(jspSource);
2578 jtpMain.requestFocus();
2579 }
2580 this.validate();
2581 jcbmiViewSource.setSelected(jspSource.isShowing());
2582 jtbtnViewSource.setSelected(jspSource.isShowing());
2583 }
2584
2585 /** Searches the specified element for CLASS attribute setting
2586 */
2587 private String findStyle(Element element)
2588 {
2589 AttributeSet as = element.getAttributes();
2590 if(as == null)
2591 {
2592 return null;
2593 }
2594 Object val = as.getAttribute(HTML.Attribute.CLASS);
2595 if(val != null && (val instanceof String))
2596 {
2597 return (String)val;
2598 }
2599 for(Enumeration e = as.getAttributeNames(); e.hasMoreElements();)
2600 {
2601 Object key = e.nextElement();
2602 if(key instanceof HTML.Tag)
2603 {
2604 AttributeSet eas = (AttributeSet)(as.getAttribute(key));
2605 if(eas != null)
2606 {
2607 val = eas.getAttribute(HTML.Attribute.CLASS);
2608 if(val != null)
2609 {
2610 return (String)val;
2611 }
2612 }
2613 }
2614
2615 }
2616 return null;
2617 }
2618
2619 /** Handles caret tracking and related events, such as displaying the current style
2620 * of the text under the caret
2621 */
2622 private void handleCaretPositionChange(CaretEvent ce)
2623 {
2624 int caretPos = ce.getDot();
2625 Element element = htmlDoc.getCharacterElement(caretPos);
2626 /*
2627 ---- TAG EXPLICATOR CODE -------------------------------------------
2628 javax.swing.text.ElementIterator ei = new javax.swing.text.ElementIterator(htmlDoc);
2629 Element ele;
2630 while((ele = ei.next()) != null)
2631 {
2632 System.out.println("ELEMENT : " + ele.getName());
2633 }
2634 System.out.println("ELEMENT:" + element.getName());
2635 Element elementParent = element.getParentElement();
2636 System.out.println("ATTRS:");
2637 AttributeSet attribs = elementParent.getAttributes();
2638 for(Enumeration eAttrs = attribs.getAttributeNames(); eAttrs.hasMoreElements();)
2639 {
2640 System.out.println(" " + eAttrs.nextElement().toString());
2641 }
2642 while(elementParent != null && !elementParent.getName().equals("body"))
2643 {
2644 String parentName = elementParent.getName();
2645 System.out.println("PARENT:" + parentName);
2646 System.out.println("ATTRS:");
2647 attribs = elementParent.getAttributes();
2648 for(Enumeration eAttr = attribs.getAttributeNames(); eAttr.hasMoreElements();)
2649 {
2650 System.out.println(" " + eAttr.nextElement().toString());
2651 }
2652 elementParent = elementParent.getParentElement();
2653 }
2654 ---- END -------------------------------------------
2655 */
2656 if(element == null)
2657 {
2658 return;
2659 }
2660 String style = null;
2661 Vector vcStyles = new Vector();
2662 while(element != null)
2663 {
2664 if(style == null)
2665 {
2666 style = findStyle(element);
2667 }
2668 vcStyles.add(element);
2669 element = element.getParentElement();
2670 }
2671 int stylefound = -1;
2672 if(style != null)
2673 {
2674 for(int i = 0; i < jcmbStyleSelector.getItemCount(); i++)
2675 {
2676 String in = (String)(jcmbStyleSelector.getItemAt(i));
2677 if(in.equalsIgnoreCase(style))
2678 {
2679 stylefound = i;
2680 break;
2681 }
2682 }
2683 }
2684 if(stylefound > -1)
2685 {
2686 Action ac = jcmbStyleSelector.getAction();
2687 ac.setEnabled(false);
2688 jcmbStyleSelector.setSelectedIndex(stylefound);
2689 ac.setEnabled(true);
2690 }
2691 else
2692 {
2693 jcmbStyleSelector.setSelectedIndex(0);
2694 }
2695 }
2696
2697 /** Server-side image handling methods
2698 */
2699 protected void setServletURL(String url)
2700 {
2701 ServletURL = url;
2702 }
2703
2704 protected void setImageDir(String sysDir)
2705 {
2706 ImageDir = sysDir;
2707 }
2708
2709 public void setTreePilotSystemID(String theSystem)
2710 {
2711 TreePilotSystemID = theSystem;
2712 }
2713
2714 /** Utility methods
2715 */
2716 public ExtendedHTMLDocument getExtendedHtmlDoc()
2717 {
2718 return (ExtendedHTMLDocument)htmlDoc;
2719 }
2720
2721 public int getCaretPosition()
2722 {
2723 return jtpMain.getCaretPosition();
2724 }
2725
2726 public void setCaretPosition(int newPositon)
2727 {
2728 boolean end = true;
2729 do
2730 {
2731 end = true;
2732 try
2733 {
2734 jtpMain.setCaretPosition(newPositon);
2735 }
2736 catch (IllegalArgumentException iae)
2737 {
2738 end = false;
2739 newPositon--;
2740 }
2741 } while(!end && newPositon >= 0);
2742 }
2743
2744 /* Inner Classes --------------------------------------------- */
2745
2746 /** Class for implementing Undo as an autonomous action
2747 */
2748 class UndoAction extends AbstractAction
2749 {
2750 public UndoAction()
2751 {
2752 super(Translatrix.getTranslationString("Undo"));
2753 setEnabled(false);
2754 }
2755
2756 public void actionPerformed(ActionEvent e)
2757 {
2758 try
2759 {
2760 undoMngr.undo();
2761 }
2762 catch(CannotUndoException ex)
2763 {
2764 ex.printStackTrace();
2765 }
2766 updateUndoState();
2767 redoAction.updateRedoState();
2768 }
2769
2770 protected void updateUndoState()
2771 {
2772 if(undoMngr.canUndo())
2773 {
2774 setEnabled(true);
2775 putValue(Action.NAME, undoMngr.getUndoPresentationName());
2776 }
2777 else
2778 {
2779 setEnabled(false);
2780 putValue(Action.NAME, Translatrix.getTranslationString("Undo"));
2781 }
2782 }
2783 }
2784
2785 /** Class for implementing Redo as an autonomous action
2786 */
2787 class RedoAction extends AbstractAction
2788 {
2789 public RedoAction()
2790 {
2791 super(Translatrix.getTranslationString("Redo"));
2792 setEnabled(false);
2793 }
2794
2795 public void actionPerformed(ActionEvent e)
2796 {
2797 try
2798 {
2799 undoMngr.redo();
2800 }
2801 catch(CannotUndoException ex)
2802 {
2803 ex.printStackTrace();
2804 }
2805 updateRedoState();
2806 undoAction.updateUndoState();
2807 }
2808
2809 protected void updateRedoState()
2810 {
2811 if(undoMngr.canRedo())
2812 {
2813 setEnabled(true);
2814 putValue(Action.NAME, undoMngr.getRedoPresentationName());
2815 }
2816 else
2817 {
2818 setEnabled(false);
2819 putValue(Action.NAME, Translatrix.getTranslationString("Redo"));
2820 }
2821 }
2822 }
2823
2824 /** Class for implementing the Undo listener to handle the Undo and Redo actions
2825 */
2826 class CustomUndoableEditListener implements UndoableEditListener
2827 {
2828 public void undoableEditHappened(UndoableEditEvent uee)
2829 {
2830 undoMngr.addEdit(uee.getEdit());
2831 undoAction.updateUndoState();
2832 redoAction.updateRedoState();
2833 }
2834 }
2835
2836 }