2 GNU Lesser General Public License
4 EkitCore - Base Java Swing HTML Editor & Viewer Class (Spellcheck Version)
5 Copyright (C) 2000-2003 Howard Kistler
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.
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.
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
22 package com
.hexidec
.ekit
;
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
;
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
;
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
;
112 import com
.hexidec
.ekit
.action
.*;
113 import com
.hexidec
.ekit
.component
.*;
114 import com
.hexidec
.util
.Base64Codec
;
115 import com
.hexidec
.util
.Translatrix
;
117 import com
.swabunga
.spell
.engine
.*;
118 import com
.swabunga
.spell
.event
.*;
119 import com
.swabunga
.spell
.swing
.*;
122 * Main application class for editing and saving HTML in a Java text component
124 * @author Howard Kistler
128 * Java 2 (JDK 1.3 or 1.4)
132 public class EkitCore
extends JPanel
implements ActionListener
, KeyListener
, DocumentListener
, SpellCheckListener
135 private JSplitPane jspltDisplay
;
136 private JTextPane jtpMain
;
137 private ExtendedHTMLEditorKit htmlKit
;
138 private ExtendedHTMLDocument htmlDoc
;
139 private StyleSheet styleSheet
;
140 private JTextPane jtpSource
;
141 private JScrollPane jspSource
;
142 private JToolBar jToolBar
;
144 private JCheckBoxMenuItem jcbmiViewToolbar
;
145 private JCheckBoxMenuItem jcbmiViewSource
;
147 private JButtonNoFocus jbtnNewHTML
;
148 private JButtonNoFocus jbtnOpenHTML
;
149 private JButtonNoFocus jbtnSaveHTML
;
150 private JButtonNoFocus jbtnCut
;
151 private JButtonNoFocus jbtnCopy
;
152 private JButtonNoFocus jbtnPaste
;
153 private JButtonNoFocus jbtnBold
;
154 private JButtonNoFocus jbtnItalic
;
155 private JButtonNoFocus jbtnUnderline
;
156 private JButtonNoFocus jbtnStrike
;
157 private JButtonNoFocus jbtnSuperscript
;
158 private JButtonNoFocus jbtnSubscript
;
159 private JButtonNoFocus jbtnUList
;
160 private JButtonNoFocus jbtnOList
;
161 private JButtonNoFocus jbtnClearFormat
;
162 private JButtonNoFocus jbtnAnchor
;
163 private JToggleButtonNoFocus jtbtnViewSource
;
164 private JComboBoxNoFocus jcmbStyleSelector
;
166 private Frame frameHandler
;
168 private HTMLUtilities htmlUtilities
= new HTMLUtilities(this);
171 private StyledEditorKit
.BoldAction actionFontBold
;
172 private StyledEditorKit
.ItalicAction actionFontItalic
;
173 private StyledEditorKit
.UnderlineAction actionFontUnderline
;
174 private FormatAction actionFontStrike
;
175 private FormatAction actionFontSuperscript
;
176 private FormatAction actionFontSubscript
;
177 private ListAutomationAction actionListUnordered
;
178 private ListAutomationAction actionListOrdered
;
179 private CustomAction actionSelectFont
;
180 private CustomAction actionClearFormat
;
181 private CustomAction actionInsertAnchor
;
183 protected UndoManager undoMngr
;
184 protected UndoAction undoAction
;
185 protected RedoAction redoAction
;
188 private JMenuBar jMenuBar
;
189 private JMenu jMenuFile
;
190 private JMenu jMenuEdit
;
191 private JMenu jMenuView
;
192 private JMenu jMenuFont
;
193 private JMenu jMenuFormat
;
194 private JMenu jMenuInsert
;
195 private JMenu jMenuTable
;
196 private JMenu jMenuForms
;
197 private JMenu jMenuSearch
;
198 private JMenu jMenuTools
;
199 private JMenu jMenuHelp
;
200 private JMenu jMenuDebug
;
204 public static final String KEY_MENU_FILE
= "file";
205 public static final String KEY_MENU_EDIT
= "edit";
206 public static final String KEY_MENU_VIEW
= "view";
207 public static final String KEY_MENU_FONT
= "font";
208 public static final String KEY_MENU_FORMAT
= "format";
209 public static final String KEY_MENU_INSERT
= "insert";
210 public static final String KEY_MENU_TABLE
= "table";
211 public static final String KEY_MENU_FORMS
= "forms";
212 public static final String KEY_MENU_SEARCH
= "search";
213 public static final String KEY_MENU_TOOLS
= "tools";
214 public static final String KEY_MENU_HELP
= "help";
215 public static final String KEY_MENU_DEBUG
= "debug";
218 public static final String KEY_TOOL_SEP
= "separator";
219 public static final String KEY_TOOL_NEW
= "new";
220 public static final String KEY_TOOL_OPEN
= "open";
221 public static final String KEY_TOOL_SAVE
= "save";
222 public static final String KEY_TOOL_CUT
= "cut";
223 public static final String KEY_TOOL_COPY
= "copy";
224 public static final String KEY_TOOL_PASTE
= "paste";
225 public static final String KEY_TOOL_BOLD
= "bold";
226 public static final String KEY_TOOL_ITALIC
= "italic";
227 public static final String KEY_TOOL_UNDERLINE
= "underline";
228 public static final String KEY_TOOL_STRIKE
= "strike";
229 public static final String KEY_TOOL_SUPER
= "superscript";
230 public static final String KEY_TOOL_SUB
= "subscript";
231 public static final String KEY_TOOL_ULIST
= "ulist";
232 public static final String KEY_TOOL_OLIST
= "olist";
233 public static final String KEY_TOOL_CLEAR
= "clearformats";
234 public static final String KEY_TOOL_ANCHOR
= "anchor";
235 public static final String KEY_TOOL_SOURCE
= "viewsource";
236 public static final String KEY_TOOL_STYLES
= "styleselect";
238 // Menu & Tool Key Arrays
239 private static Hashtable htMenus
= new Hashtable();
240 private static Hashtable htTools
= new Hashtable();
242 private final String appName
= "Ekit";
243 private final String menuDialog
= "..."; /* text to append to a MenuItem label when menu item opens a dialog */
245 private final boolean useFormIndicator
= true
; /* Creates a highlighted background on a new FORM so that it may be more easily edited */
246 private final String clrFormIndicator
= "#cccccc";
248 // System Clipboard Settings
249 private java
.awt
.datatransfer
.Clipboard sysClipboard
;
250 private SecurityManager secManager
;
253 private int iSplitPos
= 0;
255 private boolean exclusiveEdit
= true
;
257 private String lastSearchFindTerm
= null
;
258 private String lastSearchReplaceTerm
= null
;
259 private boolean lastSearchCaseSetting
= false
;
260 private boolean lastSearchTopSetting
= false
;
262 private File currentFile
= null
;
264 private int indent
= 0;
265 private final int indentStep
= 4;
267 // File extensions for MutableFilter
268 private final String
[] extsHTML
= { "html", "htm", "shtml" };
269 private final String
[] extsCSS
= { "css" };
270 private final String
[] extsIMG
= { "gif", "jpg", "jpeg", "png" };
271 private final String
[] extsRTF
= { "rtf" };
272 private final String
[] extsB64
= { "b64" };
273 private final String
[] extsSer
= { "ser" };
275 /* Spell Checker Settings */
276 private static String dictFile
;
277 private SpellChecker spellCheck
= null
;
278 private JSpellDialog spellDialog
;
280 /* Servlet Settings */
281 private String ServletURL
= null
;
282 private String TreePilotSystemID
= "";
283 private String ImageDir
= "";
284 private static ResourceBundle TreePilotProperties
;
286 /** Master Constructor
287 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
288 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
289 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
290 * @param urlStyleSheet [URL] A URL reference to the CSS style sheet.
291 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
292 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
293 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
294 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
295 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
296 * @param base64 [boolean] Specifies whether the raw document is Base64 encoded or not.
297 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
299 public EkitCore(String sDocument
, String sStyleSheet
, String sRawDocument
, URL urlStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
, boolean debugMode
)
303 exclusiveEdit
= editModeExclusive
;
305 frameHandler
= new Frame();
307 // Determine if system clipboard is available
308 secManager
= System
.getSecurityManager();
309 if(secManager
!= null
)
313 secManager
.checkSystemClipboardAccess();
314 sysClipboard
= Toolkit
.getDefaultToolkit().getSystemClipboard();
316 catch (SecurityException se
)
322 /* Localize for language */
323 Translatrix
.setBundleName("com.hexidec.ekit.LanguageResources");
324 Locale baseLocale
= (Locale
)null
;
325 if(sLanguage
!= null
&& sCountry
!= null
)
327 baseLocale
= new Locale(sLanguage
, sCountry
);
329 Translatrix
.setLocale(baseLocale
);
331 /* Load TreePilot properties */
334 TreePilotProperties
= ResourceBundle
.getBundle("com.hexidec.ekit.TreePilot");
336 catch(MissingResourceException mre
)
338 logException("MissingResourceException while loading treepilot file", mre
);
341 /* Create the editor kit, document, and stylesheet */
342 jtpMain
= new JTextPane();
343 htmlKit
= new ExtendedHTMLEditorKit();
344 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
345 styleSheet
= htmlDoc
.getStyleSheet();
346 htmlKit
.setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
348 /* Set up the text pane */
349 jtpMain
.setEditorKit(htmlKit
);
350 jtpMain
.setDocument(htmlDoc
);
351 jtpMain
.setMargin(new Insets(4, 4, 4, 4));
352 jtpMain
.addKeyListener(this);
354 /* Create the source text area */
355 jtpSource
= new JTextPane();
356 jtpSource
.setBackground(new Color(212, 212, 212));
357 jtpSource
.setSelectionColor(new Color(255, 192, 192));
358 jtpSource
.setText(jtpMain
.getText());
359 jtpSource
.getDocument().addDocumentListener(this);
361 /* Add CaretListener for tracking caret location events */
362 jtpMain
.addCaretListener(new CaretListener()
364 public void caretUpdate(CaretEvent ce
)
366 handleCaretPositionChange(ce
);
370 /* Set up the undo features */
371 undoMngr
= new UndoManager();
372 undoAction
= new UndoAction();
373 redoAction
= new RedoAction();
374 jtpMain
.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
376 /* Insert raw document, if exists */
377 if(sRawDocument
!= null
&& sRawDocument
.length() > 0)
381 jtpMain
.setText(Base64Codec
.decode(sRawDocument
));
385 jtpMain
.setText(sRawDocument
);
388 jtpMain
.setCaretPosition(0);
389 jtpMain
.getDocument().addDocumentListener(this);
391 /* Import CSS from reference, if exists */
392 if(urlStyleSheet
!= null
)
396 String currDocText
= jtpMain
.getText();
397 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
398 styleSheet
= htmlDoc
.getStyleSheet();
399 BufferedReader br
= new BufferedReader(new InputStreamReader(urlStyleSheet
.openStream()));
400 styleSheet
.loadRules(br
, urlStyleSheet
);
402 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
403 registerDocument(htmlDoc
);
404 jtpMain
.setText(currDocText
);
405 jtpSource
.setText(jtpMain
.getText());
409 e
.printStackTrace(System
.out
);
413 /* Preload the specified HTML document, if exists */
414 if(sDocument
!= null
)
416 File defHTML
= new File(sDocument
);
421 openDocument(defHTML
);
425 logException("Exception in preloading HTML document", e
);
430 /* Preload the specified CSS document, if exists */
431 if(sStyleSheet
!= null
)
433 File defCSS
= new File(sStyleSheet
);
438 openStyleSheet(defCSS
);
442 logException("Exception in preloading CSS stylesheet", e
);
447 /* Collect the actions that the JTextPane is naturally aware of */
448 Hashtable actions
= new Hashtable();
449 Action
[] actionsArray
= jtpMain
.getActions();
450 for(int i
= 0; i
< actionsArray
.length
; i
++)
452 Action a
= actionsArray
[i
];
453 actions
.put(a
.getValue(Action
.NAME
), a
);
456 /* Create shared actions */
457 actionFontBold
= new StyledEditorKit
.BoldAction();
458 actionFontItalic
= new StyledEditorKit
.ItalicAction();
459 actionFontUnderline
= new StyledEditorKit
.UnderlineAction();
460 actionFontStrike
= new FormatAction(this, Translatrix
.getTranslationString("FontStrike"), HTML
.Tag
.STRIKE
);
461 actionFontSuperscript
= new FormatAction(this, Translatrix
.getTranslationString("FontSuperscript"), HTML
.Tag
.SUP
);
462 actionFontSubscript
= new FormatAction(this, Translatrix
.getTranslationString("FontSubscript"), HTML
.Tag
.SUB
);
463 actionListUnordered
= new ListAutomationAction(this, Translatrix
.getTranslationString("ListUnordered"), HTML
.Tag
.UL
);
464 actionListOrdered
= new ListAutomationAction(this, Translatrix
.getTranslationString("ListOrdered"), HTML
.Tag
.OL
);
465 Hashtable customAttr
= new Hashtable();
466 customAttr
.put("face","");
467 actionSelectFont
= new CustomAction(this, Translatrix
.getTranslationString("FontSelect") + menuDialog
, HTML
.Tag
.FONT
, customAttr
);
468 actionClearFormat
= new CustomAction(this, Translatrix
.getTranslationString("FormatClear"), new HTML
.UnknownTag(""));
469 actionInsertAnchor
= new CustomAction(this, Translatrix
.getTranslationString("InsertAnchor") + menuDialog
, HTML
.Tag
.A
);
471 /* Build the menus */
473 jMenuFile
= new JMenu(Translatrix
.getTranslationString("File"));
474 htMenus
.put(KEY_MENU_FILE
, jMenuFile
);
475 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
);
476 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
);
477 JMenuItem jmiOpenCSS
= new JMenuItem(Translatrix
.getTranslationString("OpenStyle") + menuDialog
); jmiOpenCSS
.setActionCommand("opencss"); jmiOpenCSS
.addActionListener(this); jMenuFile
.add(jmiOpenCSS
);
478 JMenuItem jmiOpenB64
= new JMenuItem(Translatrix
.getTranslationString("OpenBase64Document") + menuDialog
); jmiOpenB64
.setActionCommand("openb64"); jmiOpenB64
.addActionListener(this); jMenuFile
.add(jmiOpenB64
);
479 jMenuFile
.addSeparator();
480 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
);
481 JMenuItem jmiSaveAs
= new JMenuItem(Translatrix
.getTranslationString("SaveAs") + menuDialog
); jmiSaveAs
.setActionCommand("saveas"); jmiSaveAs
.addActionListener(this); jMenuFile
.add(jmiSaveAs
);
482 JMenuItem jmiSaveBody
= new JMenuItem(Translatrix
.getTranslationString("SaveBody") + menuDialog
); jmiSaveBody
.setActionCommand("savebody"); jmiSaveBody
.addActionListener(this); jMenuFile
.add(jmiSaveBody
);
483 JMenuItem jmiSaveRTF
= new JMenuItem(Translatrix
.getTranslationString("SaveRTF") + menuDialog
); jmiSaveRTF
.setActionCommand("savertf"); jmiSaveRTF
.addActionListener(this); jMenuFile
.add(jmiSaveRTF
);
484 JMenuItem jmiSaveB64
= new JMenuItem(Translatrix
.getTranslationString("SaveB64") + menuDialog
); jmiSaveB64
.setActionCommand("saveb64"); jmiSaveB64
.addActionListener(this); jMenuFile
.add(jmiSaveB64
);
485 jMenuFile
.addSeparator();
486 JMenuItem jmiSerialOut
= new JMenuItem(Translatrix
.getTranslationString("Serialize") + menuDialog
); jmiSerialOut
.setActionCommand("serialize"); jmiSerialOut
.addActionListener(this); jMenuFile
.add(jmiSerialOut
);
487 JMenuItem jmiSerialIn
= new JMenuItem(Translatrix
.getTranslationString("ReadFromSer") + menuDialog
); jmiSerialIn
.setActionCommand("readfromser"); jmiSerialIn
.addActionListener(this); jMenuFile
.add(jmiSerialIn
);
488 jMenuFile
.addSeparator();
489 JMenuItem jmiExit
= new JMenuItem(Translatrix
.getTranslationString("Exit")); jmiExit
.setActionCommand("exit"); jmiExit
.addActionListener(this); jMenuFile
.add(jmiExit
);
492 jMenuEdit
= new JMenu(Translatrix
.getTranslationString("Edit"));
493 htMenus
.put(KEY_MENU_EDIT
, jMenuEdit
);
494 if(sysClipboard
!= null
)
496 // System Clipboard versions of menu commands
497 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
);
498 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
);
499 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
);
503 // DefaultEditorKit versions of menu commands
504 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
);
505 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
);
506 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
);
508 jMenuEdit
.addSeparator();
509 JMenuItem jmiUndo
= new JMenuItem(undoAction
); jmiUndo
.setAccelerator(KeyStroke
.getKeyStroke('Z', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuEdit
.add(jmiUndo
);
510 JMenuItem jmiRedo
= new JMenuItem(redoAction
); jmiRedo
.setAccelerator(KeyStroke
.getKeyStroke('Y', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuEdit
.add(jmiRedo
);
511 jMenuEdit
.addSeparator();
512 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
);
513 JMenuItem jmiSelPara
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectParagraphAction
)); jmiSelPara
.setText(Translatrix
.getTranslationString("SelectParagraph")); jMenuEdit
.add(jmiSelPara
);
514 JMenuItem jmiSelLine
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectLineAction
)); jmiSelLine
.setText(Translatrix
.getTranslationString("SelectLine")); jMenuEdit
.add(jmiSelLine
);
515 JMenuItem jmiSelWord
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectWordAction
)); jmiSelWord
.setText(Translatrix
.getTranslationString("SelectWord")); jMenuEdit
.add(jmiSelWord
);
518 jMenuView
= new JMenu(Translatrix
.getTranslationString("View"));
519 htMenus
.put(KEY_MENU_VIEW
, jMenuView
);
520 jcbmiViewToolbar
= new JCheckBoxMenuItem(Translatrix
.getTranslationString("ViewToolbar"), false
); jcbmiViewToolbar
.setActionCommand("toggletoolbar"); jcbmiViewToolbar
.addActionListener(this); jMenuView
.add(jcbmiViewToolbar
);
521 jcbmiViewSource
= new JCheckBoxMenuItem(Translatrix
.getTranslationString("ViewSource"), false
); jcbmiViewSource
.setActionCommand("viewsource"); jcbmiViewSource
.addActionListener(this); jMenuView
.add(jcbmiViewSource
);
524 jMenuFont
= new JMenu(Translatrix
.getTranslationString("Font"));
525 htMenus
.put(KEY_MENU_FONT
, jMenuFont
);
526 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
);
527 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
);
528 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
);
529 JMenuItem jmiStrike
= new JMenuItem(actionFontStrike
); jmiStrike
.setText(Translatrix
.getTranslationString("FontStrike")); if(showMenuIcons
) { jmiStrike
.setIcon(getEkitIcon("Strike")); } jMenuFont
.add(jmiStrike
);
530 jMenuFont
.addSeparator();
531 jMenuFont
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatBig"), HTML
.Tag
.BIG
)));
532 jMenuFont
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatSmall"), HTML
.Tag
.SMALL
)));
533 JMenu jMenuFontSize
= new JMenu(Translatrix
.getTranslationString("FontSize"));
534 String fontSizeKey
= "size";
535 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"1");
536 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize1"), HTML
.Tag
.FONT
, customAttr
)));
537 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"2");
538 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize2"), HTML
.Tag
.FONT
, customAttr
)));
539 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"3");
540 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize3"), HTML
.Tag
.FONT
, customAttr
)));
541 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"4");
542 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize4"), HTML
.Tag
.FONT
, customAttr
)));
543 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"5");
544 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize5"), HTML
.Tag
.FONT
, customAttr
)));
545 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"6");
546 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize6"), HTML
.Tag
.FONT
, customAttr
)));
547 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"7");
548 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize7"), HTML
.Tag
.FONT
, customAttr
)));
549 jMenuFont
.add(jMenuFontSize
);
550 jMenuFont
.addSeparator();
551 JMenuItem jmiSupscript
= new JMenuItem(actionFontSuperscript
); if(showMenuIcons
) { jmiSupscript
.setIcon(getEkitIcon("Super")); } jMenuFont
.add(jmiSupscript
);
552 JMenuItem jmiSubscript
= new JMenuItem(actionFontSubscript
); if(showMenuIcons
) { jmiSubscript
.setIcon(getEkitIcon("Sub")); } jMenuFont
.add(jmiSubscript
);
553 jMenuFont
.addSeparator();
554 JMenuItem jmiSerif
= new JMenuItem((Action
)actions
.get("font-family-Serif")); jmiSerif
.setText(Translatrix
.getTranslationString("FontSerif")); jMenuFont
.add(jmiSerif
);
555 JMenuItem jmiSansSerif
= new JMenuItem((Action
)actions
.get("font-family-SansSerif")); jmiSansSerif
.setText(Translatrix
.getTranslationString("FontSansserif")); jMenuFont
.add(jmiSansSerif
);
556 JMenuItem jmiMonospaced
= new JMenuItem((Action
)actions
.get("font-family-Monospaced")); jmiMonospaced
.setText(Translatrix
.getTranslationString("FontMonospaced")); jMenuFont
.add(jmiMonospaced
);
557 JMenuItem jmiSelectFont
= new JMenuItem(actionSelectFont
); jMenuFont
.add(jmiSelectFont
);
558 jMenuFont
.addSeparator();
559 JMenu jMenuFontColor
= new JMenu(Translatrix
.getTranslationString("Color"));
560 customAttr
= new Hashtable(); customAttr
.put("color","black");
561 jMenuFontColor
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("CustomColor") + menuDialog
, HTML
.Tag
.FONT
, customAttr
)));
562 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorAqua"), new Color( 0,255,255))));
563 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorBlack"), new Color( 0, 0, 0))));
564 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorBlue"), new Color( 0, 0,255))));
565 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorFuschia"), new Color(255, 0,255))));
566 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorGray"), new Color(128,128,128))));
567 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorGreen"), new Color( 0,128, 0))));
568 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorLime"), new Color( 0,255, 0))));
569 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorMaroon"), new Color(128, 0, 0))));
570 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorNavy"), new Color( 0, 0,128))));
571 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorOlive"), new Color(128,128, 0))));
572 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorPurple"), new Color(128, 0,128))));
573 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorRed"), new Color(255, 0, 0))));
574 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorSilver"), new Color(192,192,192))));
575 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorTeal"), new Color( 0,128,128))));
576 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorWhite"), new Color(255,255,255))));
577 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorYellow"), new Color(255,255, 0))));
578 jMenuFont
.add(jMenuFontColor
);
581 jMenuFormat
= new JMenu(Translatrix
.getTranslationString("Format"));
582 htMenus
.put(KEY_MENU_FORMAT
, jMenuFormat
);
583 JMenu jMenuFormatAlign
= new JMenu(Translatrix
.getTranslationString("Align"));
584 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignLeft"), StyleConstants
.ALIGN_LEFT
)));
585 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignCenter"), StyleConstants
.ALIGN_CENTER
)));
586 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignRight"), StyleConstants
.ALIGN_RIGHT
)));
587 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignJustified"), StyleConstants
.ALIGN_JUSTIFIED
)));
588 jMenuFormat
.add(jMenuFormatAlign
);
589 jMenuFormat
.addSeparator();
590 JMenu jMenuFormatHeading
= new JMenu(Translatrix
.getTranslationString("Heading"));
591 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading1"), HTML
.Tag
.H1
)));
592 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading2"), HTML
.Tag
.H2
)));
593 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading3"), HTML
.Tag
.H3
)));
594 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading4"), HTML
.Tag
.H4
)));
595 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading5"), HTML
.Tag
.H5
)));
596 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading6"), HTML
.Tag
.H6
)));
597 jMenuFormat
.add(jMenuFormatHeading
);
598 jMenuFormat
.addSeparator();
599 JMenuItem jmiUList
= new JMenuItem(actionListUnordered
); if(showMenuIcons
) { jmiUList
.setIcon(getEkitIcon("UList")); } jMenuFormat
.add(jmiUList
);
600 JMenuItem jmiOList
= new JMenuItem(actionListOrdered
); if(showMenuIcons
) { jmiOList
.setIcon(getEkitIcon("OList")); } jMenuFormat
.add(jmiOList
);
601 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("ListItem"), HTML
.Tag
.LI
)));
602 jMenuFormat
.addSeparator();
603 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatBlockquote"), HTML
.Tag
.BLOCKQUOTE
)));
604 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatPre"), HTML
.Tag
.PRE
)));
605 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatStrong"), HTML
.Tag
.STRONG
)));
606 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatEmphasis"), HTML
.Tag
.EM
)));
607 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatTT"), HTML
.Tag
.TT
)));
608 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatSpan"), HTML
.Tag
.SPAN
)));
609 jMenuFormat
.addSeparator();
610 JMenuItem jmiClearStyles
= new JMenuItem(actionClearFormat
); if(showMenuIcons
) { jmiClearStyles
.setIcon(getEkitIcon("ClearFormat")); }; jMenuFormat
.add(jmiClearStyles
);
613 jMenuInsert
= new JMenu(Translatrix
.getTranslationString("Insert"));
614 htMenus
.put(KEY_MENU_INSERT
, jMenuInsert
);
615 jMenuInsert
.add(new JMenuItem(actionInsertAnchor
));
616 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
);
617 JMenuItem jmiNBSP
= new JMenuItem(Translatrix
.getTranslationString("InsertNBSP")); jmiNBSP
.setActionCommand("insertnbsp"); jmiNBSP
.addActionListener(this); jMenuInsert
.add(jmiNBSP
);
618 JMenuItem jmiHRule
= new JMenuItem((Action
)actions
.get("InsertHR")); jmiHRule
.setText(Translatrix
.getTranslationString("InsertHorizontalRule")); jMenuInsert
.add(jmiHRule
);
619 jMenuInsert
.addSeparator();
620 JMenuItem jmiImageLocal
= new JMenuItem(Translatrix
.getTranslationString("InsertLocalImage") + menuDialog
); jmiImageLocal
.setActionCommand("insertlocalimage"); jmiImageLocal
.addActionListener(this); jMenuInsert
.add(jmiImageLocal
);
621 JMenuItem jmiImageServer
= new JMenuItem(Translatrix
.getTranslationString("InsertServerImage") + menuDialog
); jmiImageServer
.setActionCommand("insertserverimage"); jmiImageServer
.addActionListener(this); jMenuInsert
.add(jmiImageServer
);
624 jMenuTable
= new JMenu(Translatrix
.getTranslationString("Table"));
625 htMenus
.put(KEY_MENU_TABLE
, jMenuTable
);
626 JMenuItem jmiTable
= new JMenuItem(Translatrix
.getTranslationString("InsertTable") + menuDialog
); jmiTable
.setActionCommand("inserttable"); jmiTable
.addActionListener(this); jMenuTable
.add(jmiTable
);
627 jMenuTable
.addSeparator();
628 JMenuItem jmiTableRow
= new JMenuItem(Translatrix
.getTranslationString("InsertTableRow")); jmiTableRow
.setActionCommand("inserttablerow"); jmiTableRow
.addActionListener(this); jMenuTable
.add(jmiTableRow
);
629 JMenuItem jmiTableCol
= new JMenuItem(Translatrix
.getTranslationString("InsertTableColumn")); jmiTableCol
.setActionCommand("inserttablecolumn"); jmiTableCol
.addActionListener(this); jMenuTable
.add(jmiTableCol
);
630 jMenuTable
.addSeparator();
631 JMenuItem jmiTableRowDel
= new JMenuItem(Translatrix
.getTranslationString("DeleteTableRow")); jmiTableRowDel
.setActionCommand("deletetablerow"); jmiTableRowDel
.addActionListener(this); jMenuTable
.add(jmiTableRowDel
);
632 JMenuItem jmiTableColDel
= new JMenuItem(Translatrix
.getTranslationString("DeleteTableColumn")); jmiTableColDel
.setActionCommand("deletetablecolumn"); jmiTableColDel
.addActionListener(this); jMenuTable
.add(jmiTableColDel
);
635 jMenuForms
= new JMenu(Translatrix
.getTranslationString("Forms"));
636 htMenus
.put(KEY_MENU_FORMS
, jMenuForms
);
637 JMenuItem jmiFormInsertForm
= new JMenuItem(Translatrix
.getTranslationString("FormInsertForm")); jmiFormInsertForm
.setActionCommand("insertform"); jmiFormInsertForm
.addActionListener(this); jMenuForms
.add(jmiFormInsertForm
);
638 jMenuForms
.addSeparator();
639 JMenuItem jmiFormTextfield
= new JMenuItem(Translatrix
.getTranslationString("FormTextfield")); jmiFormTextfield
.setActionCommand("inserttextfield"); jmiFormTextfield
.addActionListener(this); jMenuForms
.add(jmiFormTextfield
);
640 JMenuItem jmiFormTextarea
= new JMenuItem(Translatrix
.getTranslationString("FormTextarea")); jmiFormTextarea
.setActionCommand("inserttextarea"); jmiFormTextarea
.addActionListener(this); jMenuForms
.add(jmiFormTextarea
);
641 JMenuItem jmiFormCheckbox
= new JMenuItem(Translatrix
.getTranslationString("FormCheckbox")); jmiFormCheckbox
.setActionCommand("insertcheckbox"); jmiFormCheckbox
.addActionListener(this); jMenuForms
.add(jmiFormCheckbox
);
642 JMenuItem jmiFormRadio
= new JMenuItem(Translatrix
.getTranslationString("FormRadio")); jmiFormRadio
.setActionCommand("insertradiobutton"); jmiFormRadio
.addActionListener(this); jMenuForms
.add(jmiFormRadio
);
643 JMenuItem jmiFormPassword
= new JMenuItem(Translatrix
.getTranslationString("FormPassword")); jmiFormPassword
.setActionCommand("insertpassword"); jmiFormPassword
.addActionListener(this); jMenuForms
.add(jmiFormPassword
);
644 jMenuForms
.addSeparator();
645 JMenuItem jmiFormButton
= new JMenuItem(Translatrix
.getTranslationString("FormButton")); jmiFormButton
.setActionCommand("insertbutton"); jmiFormButton
.addActionListener(this); jMenuForms
.add(jmiFormButton
);
646 JMenuItem jmiFormButtonSubmit
= new JMenuItem(Translatrix
.getTranslationString("FormButtonSubmit")); jmiFormButtonSubmit
.setActionCommand("insertbuttonsubmit"); jmiFormButtonSubmit
.addActionListener(this); jMenuForms
.add(jmiFormButtonSubmit
);
647 JMenuItem jmiFormButtonReset
= new JMenuItem(Translatrix
.getTranslationString("FormButtonReset")); jmiFormButtonReset
.setActionCommand("insertbuttonreset"); jmiFormButtonReset
.addActionListener(this); jMenuForms
.add(jmiFormButtonReset
);
650 jMenuSearch
= new JMenu(Translatrix
.getTranslationString("Search"));
651 htMenus
.put(KEY_MENU_SEARCH
, jMenuSearch
);
652 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
);
653 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
);
654 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
);
657 jMenuTools
= new JMenu(Translatrix
.getTranslationString("Tools"));
658 htMenus
.put(KEY_MENU_TOOLS
, jMenuTools
);
659 JMenuItem jmiSpellcheck
= new JMenuItem(Translatrix
.getTranslationString("ToolSpellcheck")); jmiSpellcheck
.setActionCommand("spellcheck"); jmiSpellcheck
.addActionListener(this); jMenuTools
.add(jmiSpellcheck
);
662 jMenuHelp
= new JMenu(Translatrix
.getTranslationString("Help"));
663 htMenus
.put(KEY_MENU_HELP
, jMenuHelp
);
664 JMenuItem jmiAbout
= new JMenuItem(Translatrix
.getTranslationString("About")); jmiAbout
.setActionCommand("helpabout"); jmiAbout
.addActionListener(this); jMenuHelp
.add(jmiAbout
);
667 jMenuDebug
= new JMenu(Translatrix
.getTranslationString("Debug"));
668 htMenus
.put(KEY_MENU_DEBUG
, jMenuDebug
);
669 JMenuItem jmiDesc
= new JMenuItem(Translatrix
.getTranslationString("DescribeDoc")); jmiDesc
.setActionCommand("describe"); jmiDesc
.addActionListener(this); jMenuDebug
.add(jmiDesc
);
670 JMenuItem jmiDescCSS
= new JMenuItem(Translatrix
.getTranslationString("DescribeCSS")); jmiDescCSS
.setActionCommand("describecss"); jmiDescCSS
.addActionListener(this); jMenuDebug
.add(jmiDescCSS
);
671 JMenuItem jmiTag
= new JMenuItem(Translatrix
.getTranslationString("WhatTags")); jmiTag
.setActionCommand("whattags"); jmiTag
.addActionListener(this); jMenuDebug
.add(jmiTag
);
673 /* Create menubar and add menus */
674 jMenuBar
= new JMenuBar();
675 jMenuBar
.add(jMenuFile
);
676 jMenuBar
.add(jMenuEdit
);
677 jMenuBar
.add(jMenuView
);
678 jMenuBar
.add(jMenuFont
);
679 jMenuBar
.add(jMenuFormat
);
680 jMenuBar
.add(jMenuSearch
);
681 jMenuBar
.add(jMenuInsert
);
682 jMenuBar
.add(jMenuTable
);
683 jMenuBar
.add(jMenuForms
);
684 jMenuBar
.add(jMenuTools
);
685 jMenuBar
.add(jMenuHelp
);
688 jMenuBar
.add(jMenuDebug
);
691 /* Create the toolbar */
692 jToolBar
= new JToolBar(JToolBar
.HORIZONTAL
);
693 jToolBar
.setFloatable(false
);
694 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
);
695 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
);
696 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
);
697 jToolBar
.add(new JToolBar
.Separator());
698 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
);
699 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
);
700 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
);
701 jToolBar
.add(new JToolBar
.Separator());
702 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
);
703 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
);
704 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
);
705 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
);
706 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
);
707 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
);
708 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
);
709 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
);
710 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
);
711 jToolBar
.add(new JToolBar
.Separator());
712 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
);
713 jToolBar
.add(new JToolBar
.Separator());
714 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
);
715 jToolBar
.add(new JToolBar
.Separator());
716 jcmbStyleSelector
= new JComboBoxNoFocus(); jToolBar
.add(jcmbStyleSelector
); jcmbStyleSelector
.setAction(new StylesAction(jcmbStyleSelector
)); htTools
.put(KEY_TOOL_STYLES
, jcmbStyleSelector
);
718 /* Create the scroll area for the text pane */
719 JScrollPane jspViewport
= new JScrollPane(jtpMain
);
720 jspViewport
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_ALWAYS
);
721 jspViewport
.setPreferredSize(new Dimension(400, 400));
722 jspViewport
.setMinimumSize(new Dimension(32, 32));
724 /* Create the scroll area for the source viewer */
725 jspSource
= new JScrollPane(jtpSource
);
726 jspSource
.setPreferredSize(new Dimension(400, 100));
727 jspSource
.setMinimumSize(new Dimension(32, 32));
729 jspltDisplay
= new JSplitPane(JSplitPane
.VERTICAL_SPLIT
);
730 jspltDisplay
.setTopComponent(jspViewport
);
733 jspltDisplay
.setBottomComponent(jspSource
);
737 jspltDisplay
.setBottomComponent(null
);
740 iSplitPos
= jspltDisplay
.getDividerLocation();
742 registerDocumentStyles();
744 /* Create spell checker */
747 dictFile
= Translatrix
.getTranslationString("DictionaryFile");
748 SpellDictionary dictionary
= new SpellDictionary(dictFile
); // uses my custom loader in SpellDictionary
749 spellCheck
= new SpellChecker(dictionary
);
750 spellCheck
.addSpellCheckListener(this);
756 spellDialog
= new JSpellDialog(this.getFrame(), Translatrix
.getTranslationString("ToolSpellcheckDialog"), true
);
758 /* Add the components to the app */
759 this.setLayout(new BorderLayout());
760 this.add(jspltDisplay
, BorderLayout
.CENTER
);
763 /** Common Constructor
764 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
765 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
766 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
767 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
768 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
769 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
770 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
772 public EkitCore(String sDocument
, String sStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
774 this(sDocument
, sStyleSheet
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
777 /** Default Language Constructor
778 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
779 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
780 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
781 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
782 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
784 public EkitCore(String sDocument
, String sStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, boolean base64
)
786 this(sDocument
, sStyleSheet
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, base64
, false
);
789 /** Raw/Base64 Document & Style Sheet URL Constructor (Ideal for EkitApplet)
790 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
791 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
792 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
793 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
794 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
795 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
796 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
798 public EkitCore(String sRawDocument
, URL urlStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
800 this(null
, null
, sRawDocument
, urlStyleSheet
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
803 /** Document Constructor
804 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
805 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
806 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
807 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
808 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
809 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
811 public EkitCore(String sRawDocument
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
813 this(null
, null
, sRawDocument
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
816 /** Default Language & Document Constructor
817 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
818 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
819 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
820 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
822 public EkitCore(String sRawDocument
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, boolean base64
)
824 this(null
, null
, sRawDocument
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, base64
, false
);
827 /** Flags & Language Constructor
828 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
829 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
830 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
831 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
832 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
834 public EkitCore(boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
)
836 this(null
, null
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, false
, false
);
839 /** Flags Constructor
840 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
841 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
842 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
844 public EkitCore(boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
)
846 this(null
, null
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, false
, false
);
849 /** Language & Debug Constructor
850 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
851 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
852 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
854 public EkitCore(String sLanguage
, String sCountry
, boolean debugMode
)
856 this(null
, null
, null
, null
, false
, true
, true
, sLanguage
, sCountry
, false
, debugMode
);
859 /** Language Constructor
860 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
861 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
863 public EkitCore(String sLanguage
, String sCountry
)
865 this(null
, null
, null
, null
, false
, true
, true
, sLanguage
, sCountry
, false
, false
);
868 /** Debug Constructor
869 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
871 public EkitCore(boolean debugMode
)
873 this(null
, null
, null
, null
, false
, true
, true
, null
, null
, false
, debugMode
);
876 /** Empty Constructor
880 this(null
, null
, null
, null
, false
, true
, true
, null
, null
, false
, false
);
883 /* ActionListener method */
884 public void actionPerformed(ActionEvent ae
)
888 String command
= ae
.getActionCommand();
889 if(command
.equals("newdoc"))
891 SimpleInfoDialog sidAsk
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("AskNewDocument"), SimpleInfoDialog
.QUESTION
);
892 String decision
= sidAsk
.getDecisionValue();
893 if(decision
.equals(Translatrix
.getTranslationString("DialogAccept")))
895 if(styleSheet
!= null
)
897 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
901 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
903 jtpMain
.setText("<HTML><BODY></BODY></HTML>");
904 jtpSource
.setText(jtpMain
.getText());
905 registerDocument(htmlDoc
);
910 else if(command
.equals("openhtml"))
914 else if(command
.equals("opencss"))
916 openStyleSheet(null
);
918 else if(command
.equals("openb64"))
920 openDocumentBase64(null
);
922 else if(command
.equals("save"))
924 writeOut((HTMLDocument
)(jtpMain
.getDocument()), currentFile
);
927 else if(command
.equals("saveas"))
929 writeOut((HTMLDocument
)(jtpMain
.getDocument()), null
);
931 else if(command
.equals("savebody"))
933 writeOutFragment((HTMLDocument
)(jtpMain
.getDocument()),"body");
935 else if(command
.equals("savertf"))
937 writeOutRTF((StyledDocument
)(jtpMain
.getStyledDocument()));
939 else if(command
.equals("saveb64"))
941 writeOutBase64(jtpSource
.getText());
943 else if(command
.equals("textcut"))
945 if(jspSource
.isShowing() && jtpSource
.hasFocus())
954 else if(command
.equals("textcopy"))
956 if(jspSource
.isShowing() && jtpSource
.hasFocus())
965 else if(command
.equals("textpaste"))
967 if(jspSource
.isShowing() && jtpSource
.hasFocus())
976 else if(command
.equals("describe"))
978 System
.out
.println("------------DOCUMENT------------");
979 System
.out
.println("Content Type : " + jtpMain
.getContentType());
980 System
.out
.println("Editor Kit : " + jtpMain
.getEditorKit());
981 System
.out
.println("Doc Tree :");
982 System
.out
.println("");
983 describeDocument(jtpMain
.getStyledDocument());
984 System
.out
.println("--------------------------------");
985 System
.out
.println("");
987 else if(command
.equals("describecss"))
989 System
.out
.println("-----------STYLESHEET-----------");
990 System
.out
.println("Stylesheet Rules");
991 Enumeration rules
= styleSheet
.getStyleNames();
992 while(rules
.hasMoreElements())
994 String ruleName
= (String
)(rules
.nextElement());
995 Style styleRule
= styleSheet
.getStyle(ruleName
);
996 System
.out
.println(styleRule
.toString());
998 System
.out
.println("--------------------------------");
999 System
.out
.println("");
1001 else if(command
.equals("whattags"))
1003 System
.out
.println("Caret Position : " + jtpMain
.getCaretPosition());
1004 AttributeSet attribSet
= jtpMain
.getCharacterAttributes();
1005 Enumeration attribs
= attribSet
.getAttributeNames();
1006 System
.out
.println("Attributes : ");
1007 while(attribs
.hasMoreElements())
1009 String attribName
= attribs
.nextElement().toString();
1010 System
.out
.println(" " + attribName
+ " | " + attribSet
.getAttribute(attribName
));
1013 else if(command
.equals("toggletoolbar"))
1015 jToolBar
.setVisible(jcbmiViewToolbar
.isSelected());
1017 else if(command
.equals("viewsource"))
1019 toggleSourceWindow();
1021 else if(command
.equals("serialize"))
1023 serializeOut((HTMLDocument
)(jtpMain
.getDocument()));
1025 else if(command
.equals("readfromser"))
1029 else if(command
.equals("inserttable"))
1031 String
[] fieldNames
= { "rows", "cols", "border", "cellspacing", "cellpadding", "width" };
1032 String
[] fieldTypes
= { "text", "text", "text", "text", "text", "text" };
1033 insertTable((Hashtable
)null
, fieldNames
, fieldTypes
);
1035 else if(command
.equals("inserttablerow"))
1039 else if(command
.equals("inserttablecolumn"))
1041 insertTableColumn();
1043 else if(command
.equals("deletetablerow"))
1047 else if(command
.equals("deletetablecolumn"))
1049 deleteTableColumn();
1051 else if(command
.equals("insertbreak"))
1055 else if(command
.equals("insertlocalimage"))
1057 insertLocalImage(null
);
1059 else if(command
.equals("insertserverimage"))
1061 insertServerImage();
1063 else if(command
.equals("insertnbsp"))
1065 insertNonbreakingSpace();
1067 else if(command
.equals("insertform"))
1069 String
[] fieldNames
= { "name", "method", "enctype" };
1070 String
[] fieldTypes
= { "text", "combo", "text" };
1071 String
[] fieldValues
= { "", "POST,GET", "text" };
1072 insertFormElement(HTML
.Tag
.FORM
, "form", (Hashtable
)null
, fieldNames
, fieldTypes
, fieldValues
, true
);
1074 else if(command
.equals("inserttextfield"))
1076 Hashtable htAttribs
= new Hashtable();
1077 htAttribs
.put("type", "text");
1078 String
[] fieldNames
= { "name", "value", "size", "maxlength" };
1079 String
[] fieldTypes
= { "text", "text", "text", "text" };
1080 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1082 else if(command
.equals("inserttextarea"))
1084 String
[] fieldNames
= { "name", "rows", "cols" };
1085 String
[] fieldTypes
= { "text", "text", "text" };
1086 insertFormElement(HTML
.Tag
.TEXTAREA
, "textarea", (Hashtable
)null
, fieldNames
, fieldTypes
, true
);
1088 else if(command
.equals("insertcheckbox"))
1090 Hashtable htAttribs
= new Hashtable();
1091 htAttribs
.put("type", "checkbox");
1092 String
[] fieldNames
= { "name", "checked" };
1093 String
[] fieldTypes
= { "text", "bool" };
1094 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1096 else if(command
.equals("insertradiobutton"))
1098 Hashtable htAttribs
= new Hashtable();
1099 htAttribs
.put("type", "radio");
1100 String
[] fieldNames
= { "name", "checked" };
1101 String
[] fieldTypes
= { "text", "bool" };
1102 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1104 else if(command
.equals("insertpassword"))
1106 Hashtable htAttribs
= new Hashtable();
1107 htAttribs
.put("type", "password");
1108 String
[] fieldNames
= { "name", "value", "size", "maxlength" };
1109 String
[] fieldTypes
= { "text", "text", "text", "text" };
1110 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1112 else if(command
.equals("insertbutton"))
1114 Hashtable htAttribs
= new Hashtable();
1115 htAttribs
.put("type", "button");
1116 String
[] fieldNames
= { "name", "value" };
1117 String
[] fieldTypes
= { "text", "text" };
1118 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1120 else if(command
.equals("insertbuttonsubmit"))
1122 Hashtable htAttribs
= new Hashtable();
1123 htAttribs
.put("type", "submit");
1124 String
[] fieldNames
= { "name", "value" };
1125 String
[] fieldTypes
= { "text", "text" };
1126 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1128 else if(command
.equals("insertbuttonreset"))
1130 Hashtable htAttribs
= new Hashtable();
1131 htAttribs
.put("type", "reset");
1132 String
[] fieldNames
= { "name", "value" };
1133 String
[] fieldTypes
= { "text", "text" };
1134 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1136 else if(command
.equals("find"))
1138 doSearch((String
)null
, (String
)null
, false
, lastSearchCaseSetting
, lastSearchTopSetting
);
1140 else if(command
.equals("findagain"))
1142 doSearch(lastSearchFindTerm
, (String
)null
, false
, lastSearchCaseSetting
, false
);
1144 else if(command
.equals("replace"))
1146 doSearch((String
)null
, (String
)null
, true
, lastSearchCaseSetting
, lastSearchTopSetting
);
1148 else if(command
.equals("exit"))
1152 else if(command
.equals("helpabout"))
1154 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("About"), true
, Translatrix
.getTranslationString("AboutMessage"), SimpleInfoDialog
.INFO
);
1156 else if(command
.equals("spellcheck"))
1158 spellCheck
.checkSpelling(new DocumentWordTokenizer(jtpMain
.getDocument()));
1161 catch(IOException ioe
)
1163 logException("IOException in actionPerformed method", ioe
);
1164 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1166 catch(BadLocationException ble
)
1168 logException("BadLocationException in actionPerformed method", ble
);
1169 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1171 catch(NumberFormatException nfe
)
1173 logException("NumberFormatException in actionPerformed method", nfe
);
1174 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorNumberFormatException"), SimpleInfoDialog
.ERROR
);
1176 catch(ClassNotFoundException cnfe
)
1178 logException("ClassNotFound Exception in actionPerformed method", cnfe
);
1179 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorClassNotFoundException "), SimpleInfoDialog
.ERROR
);
1181 catch(RuntimeException re
)
1183 logException("RuntimeException in actionPerformed method", re
);
1184 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorRuntimeException"), SimpleInfoDialog
.ERROR
);
1188 /* KeyListener methods */
1189 public void keyTyped(KeyEvent ke
)
1192 String selectedText
;
1193 int pos
= this.getCaretPosition();
1195 if(ke
.getKeyChar() == KeyEvent
.VK_BACK_SPACE
)
1201 if((selectedText
= jtpMain
.getSelectedText()) != null
)
1203 htmlUtilities
.delete();
1208 int sOffset
= htmlDoc
.getParagraphElement(pos
).getStartOffset();
1209 if(sOffset
== jtpMain
.getSelectionStart())
1211 boolean content
= true
;
1212 if(htmlUtilities
.checkParentsTag(HTML
.Tag
.LI
))
1214 elem
= htmlUtilities
.getListItemParent();
1216 int so
= elem
.getStartOffset();
1217 int eo
= elem
.getEndOffset();
1220 char[] temp
= jtpMain
.getText(so
, eo
- so
).toCharArray();
1221 for(int i
=0; i
< temp
.length
; i
++)
1223 if(!(new Character(temp
[i
])).isWhitespace(temp
[i
]))
1231 Element listElement
= elem
.getParentElement();
1232 htmlUtilities
.removeTag(elem
, true
);
1233 this.setCaretPosition(sOffset
- 1);
1238 jtpMain
.setCaretPosition(jtpMain
.getCaretPosition() - 1);
1239 jtpMain
.moveCaretPosition(jtpMain
.getCaretPosition() - 2);
1240 jtpMain
.replaceSelection("");
1244 else if(htmlUtilities
.checkParentsTag(HTML
.Tag
.TABLE
))
1246 jtpMain
.setCaretPosition(jtpMain
.getCaretPosition() - 1);
1251 jtpMain
.replaceSelection("");
1256 catch (BadLocationException ble
)
1258 logException("BadLocationException in keyTyped method", ble
);
1259 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1261 catch (IOException ioe
)
1263 logException("IOException in keyTyped method", ioe
);
1264 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1267 else if(ke
.getKeyChar() == KeyEvent
.VK_ENTER
)
1271 if(htmlUtilities
.checkParentsTag(HTML
.Tag
.UL
) == true
| htmlUtilities
.checkParentsTag(HTML
.Tag
.OL
) == true
)
1273 elem
= htmlUtilities
.getListItemParent();
1274 int so
= elem
.getStartOffset();
1275 int eo
= elem
.getEndOffset();
1276 char[] temp
= this.getTextPane().getText(so
,eo
-so
).toCharArray();
1277 boolean content
= false
;
1278 for(int i
=0;i
<temp
.length
;i
++)
1280 if(!(new Character(temp
[i
])).isWhitespace(temp
[i
]))
1288 int j
= temp
.length
;
1292 if(new Character(temp
[j
]).isLetterOrDigit(temp
[j
]))
1296 } while (end
== -1 && j
>= 0);
1301 if(!new Character(temp
[j
]).isSpaceChar(temp
[j
]))
1305 } while (repos
== -1 && j
< temp
.length
);
1311 if(elem
.getStartOffset() == elem
.getEndOffset() || !content
)
1313 manageListElement(elem
);
1317 if(this.getCaretPosition() + 1 == elem
.getEndOffset())
1319 insertListStyle(elem
);
1320 this.setCaretPosition(pos
- repos
);
1324 int caret
= this.getCaretPosition();
1325 String tempString
= this.getTextPane().getText(caret
, eo
- caret
);
1326 this.getTextPane().select(caret
, eo
- 1);
1327 this.getTextPane().replaceSelection("");
1328 htmlUtilities
.insertListElement(tempString
);
1329 Element newLi
= htmlUtilities
.getListItemParent();
1330 this.setCaretPosition(newLi
.getEndOffset() - 1);
1335 catch (BadLocationException ble
)
1337 logException("BadLocationException in keyTyped method", ble
);
1338 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1340 catch (IOException ioe
)
1342 logException("IOException in keyTyped method", ioe
);
1343 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1347 public void keyPressed(KeyEvent e
) {}
1348 public void keyReleased(KeyEvent e
) {}
1350 public void insertListStyle(Element element
)
1351 throws BadLocationException
,IOException
1353 if(element
.getParentElement().getName() == "ol")
1355 actionListOrdered
.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1359 actionListUnordered
.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1363 /* DocumentListener methods */
1364 public void changedUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1365 public void insertUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1366 public void removeUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1367 public void handleDocumentChange(DocumentEvent de
)
1371 if(jspSource
.isShowing())
1373 if(de
.getDocument() instanceof HTMLDocument
|| de
.getDocument() instanceof ExtendedHTMLDocument
)
1375 jtpSource
.getDocument().removeDocumentListener(this);
1376 jtpSource
.setText(jtpMain
.getText());
1377 jtpSource
.getDocument().addDocumentListener(this);
1379 else if(de
.getDocument() instanceof PlainDocument
|| de
.getDocument() instanceof DefaultStyledDocument
)
1381 jtpMain
.getDocument().removeDocumentListener(this);
1382 jtpMain
.setText(jtpSource
.getText());
1383 jtpMain
.getDocument().addDocumentListener(this);
1389 /* SpellCheckListener methods */
1390 public void spellingError(SpellCheckEvent event
)
1392 spellDialog
.show(event
);
1395 /** Method for setting a document as the current document for the text pane
1396 * and re-registering the controls and settings for it
1398 public void registerDocument(ExtendedHTMLDocument htmlDoc
)
1400 jtpMain
.setDocument(htmlDoc
);
1401 jtpMain
.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
1402 jtpMain
.getDocument().addDocumentListener(this);
1404 registerDocumentStyles();
1407 /** Method for locating the available CSS style for the document and adding
1408 * them to the styles selector
1410 public void registerDocumentStyles()
1412 if(jcmbStyleSelector
== null
|| htmlDoc
== null
)
1416 jcmbStyleSelector
.setEnabled(false
);
1417 jcmbStyleSelector
.removeAllItems();
1418 jcmbStyleSelector
.addItem(Translatrix
.getTranslationString("NoCSSStyle"));
1419 for(Enumeration e
= htmlDoc
.getStyleNames(); e
.hasMoreElements();)
1421 String name
= (String
) e
.nextElement();
1422 if(name
.length() > 0 && name
.charAt(0) == '.')
1424 jcmbStyleSelector
.addItem(name
.substring(1));
1427 jcmbStyleSelector
.setEnabled(true
);
1430 /** Method for inserting an HTML Table
1432 private void insertTable(Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
)
1433 throws IOException
, BadLocationException
, RuntimeException
, NumberFormatException
1435 int caretPos
= jtpMain
.getCaretPosition();
1436 StringBuffer compositeElement
= new StringBuffer("<TABLE");
1437 if(attribs
!= null
&& attribs
.size() > 0)
1439 Enumeration attribEntries
= attribs
.keys();
1440 while(attribEntries
.hasMoreElements())
1442 Object entryKey
= attribEntries
.nextElement();
1443 Object entryValue
= attribs
.get(entryKey
);
1444 if(entryValue
!= null
&& entryValue
!= "")
1446 compositeElement
.append(" " + entryKey
+ "=" + '"' + entryValue
+ '"');
1452 if(fieldNames
!= null
&& fieldNames
.length
> 0)
1454 PropertiesDialog propertiesDialog
= new PropertiesDialog(this.getFrame(), fieldNames
, fieldTypes
, Translatrix
.getTranslationString("FormDialogTitle"), true
);
1455 propertiesDialog
.show();
1456 String decision
= propertiesDialog
.getDecisionValue();
1457 if(decision
.equals(Translatrix
.getTranslationString("DialogCancel")))
1459 propertiesDialog
.dispose();
1460 propertiesDialog
= null
;
1465 for(int iter
= 0; iter
< fieldNames
.length
; iter
++)
1467 String fieldName
= fieldNames
[iter
];
1468 String propValue
= propertiesDialog
.getFieldValue(fieldName
);
1469 if(propValue
!= null
&& propValue
!= "" && propValue
.length() > 0)
1471 if(fieldName
.equals("rows"))
1473 rows
= Integer
.parseInt(propValue
);
1475 else if(fieldName
.equals("cols"))
1477 cols
= Integer
.parseInt(propValue
);
1481 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1486 propertiesDialog
.dispose();
1487 propertiesDialog
= null
;
1489 compositeElement
.append(">");
1490 for(int i
= 0; i
< rows
; i
++)
1492 compositeElement
.append("<TR>");
1493 for(int j
= 0; j
< cols
; j
++)
1495 compositeElement
.append("<TD></TD>");
1497 compositeElement
.append("</TR>");
1499 compositeElement
.append("</TABLE><P> <P>");
1500 htmlKit
.insertHTML(htmlDoc
, caretPos
, compositeElement
.toString(), 0, 0, HTML
.Tag
.TABLE
);
1501 jtpMain
.setCaretPosition(caretPos
+ 1);
1505 /** Method for inserting a row into an HTML Table
1507 private void insertTableRow()
1509 int caretPos
= jtpMain
.getCaretPosition();
1510 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1511 Element elementParent
= element
.getParentElement();
1512 int startPoint
= -1;
1513 int columnCount
= -1;
1514 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1516 if(elementParent
.getName().equals("tr"))
1518 startPoint
= elementParent
.getStartOffset();
1519 columnCount
= elementParent
.getElementCount();
1524 elementParent
= elementParent
.getParentElement();
1527 if(startPoint
> -1 && columnCount
> -1)
1529 jtpMain
.setCaretPosition(startPoint
);
1530 StringBuffer sRow
= new StringBuffer();
1531 sRow
.append("<TR>");
1532 for(int i
= 0; i
< columnCount
; i
++)
1534 sRow
.append("<TD></TD>");
1536 sRow
.append("</TR>");
1537 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableRow");
1538 new HTMLEditorKit
.InsertHTMLTextAction("insertTableRow", sRow
.toString(), HTML
.Tag
.TABLE
, HTML
.Tag
.TR
).actionPerformed(actionEvent
);
1540 jtpMain
.setCaretPosition(caretPos
);
1544 /** Method for inserting a column into an HTML Table
1546 private void insertTableColumn()
1548 int caretPos
= jtpMain
.getCaretPosition();
1549 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1550 Element elementParent
= element
.getParentElement();
1551 int startPoint
= -1;
1554 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1556 if(elementParent
.getName().equals("table"))
1558 startPoint
= elementParent
.getStartOffset();
1559 rowCount
= elementParent
.getElementCount();
1562 else if(elementParent
.getName().equals("tr"))
1564 int rowStart
= elementParent
.getStartOffset();
1565 int rowCells
= elementParent
.getElementCount();
1566 for(int i
= 0; i
< rowCells
; i
++)
1568 Element currentCell
= elementParent
.getElement(i
);
1569 if(jtpMain
.getCaretPosition() >= currentCell
.getStartOffset() && jtpMain
.getCaretPosition() <= currentCell
.getEndOffset())
1574 elementParent
= elementParent
.getParentElement();
1578 elementParent
= elementParent
.getParentElement();
1581 if(startPoint
> -1 && rowCount
> -1)
1583 jtpMain
.setCaretPosition(startPoint
);
1584 String sCell
= "<TD></TD>";
1585 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableCell");
1586 for(int i
= 0; i
< rowCount
; i
++)
1588 Element row
= elementParent
.getElement(i
);
1589 Element whichCell
= row
.getElement(cellOffset
);
1590 jtpMain
.setCaretPosition(whichCell
.getStartOffset());
1591 new HTMLEditorKit
.InsertHTMLTextAction("insertTableCell", sCell
, HTML
.Tag
.TR
, HTML
.Tag
.TD
, HTML
.Tag
.TH
, HTML
.Tag
.TD
).actionPerformed(actionEvent
);
1594 jtpMain
.setCaretPosition(caretPos
);
1598 /** Method for inserting a cell into an HTML Table
1600 private void insertTableCell()
1602 String sCell
= "<TD></TD>";
1603 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableCell");
1604 new HTMLEditorKit
.InsertHTMLTextAction("insertTableCell", sCell
, HTML
.Tag
.TR
, HTML
.Tag
.TD
, HTML
.Tag
.TH
, HTML
.Tag
.TD
).actionPerformed(actionEvent
);
1608 /** Method for deleting a row from an HTML Table
1610 private void deleteTableRow()
1611 throws BadLocationException
1613 int caretPos
= jtpMain
.getCaretPosition();
1614 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1615 Element elementParent
= element
.getParentElement();
1616 int startPoint
= -1;
1618 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1620 if(elementParent
.getName().equals("tr"))
1622 startPoint
= elementParent
.getStartOffset();
1623 endPoint
= elementParent
.getEndOffset();
1628 elementParent
= elementParent
.getParentElement();
1631 if(startPoint
> -1 && endPoint
> startPoint
)
1633 htmlDoc
.remove(startPoint
, endPoint
- startPoint
);
1634 jtpMain
.setDocument(htmlDoc
);
1635 registerDocument(htmlDoc
);
1637 if(caretPos
>= htmlDoc
.getLength())
1639 caretPos
= htmlDoc
.getLength() - 1;
1641 jtpMain
.setCaretPosition(caretPos
);
1645 /** Method for deleting a column from an HTML Table
1647 private void deleteTableColumn()
1648 throws BadLocationException
1650 int caretPos
= jtpMain
.getCaretPosition();
1651 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1652 Element elementParent
= element
.getParentElement();
1653 Element elementCell
= (Element
)null
;
1654 Element elementRow
= (Element
)null
;
1655 Element elementTable
= (Element
)null
;
1656 // Locate the table, row, and cell location of the cursor
1657 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1659 if(elementParent
.getName().equals("td"))
1661 elementCell
= elementParent
;
1663 else if(elementParent
.getName().equals("tr"))
1665 elementRow
= elementParent
;
1667 else if(elementParent
.getName().equals("table"))
1669 elementTable
= elementParent
;
1671 elementParent
= elementParent
.getParentElement();
1673 int whichColumn
= -1;
1674 if(elementCell
!= null
&& elementRow
!= null
&& elementTable
!= null
)
1676 // Find the column the cursor is in
1677 for(int i
= 0; i
< elementRow
.getElementCount(); i
++)
1679 if(elementCell
== elementRow
.getElement(i
))
1684 if(whichColumn
> -1)
1686 // Iterate through the table rows, deleting cells from the indicated column
1687 for(int i
= 0; i
< elementTable
.getElementCount(); i
++)
1689 elementRow
= elementTable
.getElement(i
);
1690 elementCell
= (elementRow
.getElementCount() > whichColumn ? elementRow
.getElement(whichColumn
) : elementRow
.getElement(elementRow
.getElementCount() - 1));
1691 int columnCellStart
= elementCell
.getStartOffset();
1692 int columnCellEnd
= elementCell
.getEndOffset();
1693 htmlDoc
.remove(columnCellStart
, columnCellEnd
- columnCellStart
);
1695 jtpMain
.setDocument(htmlDoc
);
1696 registerDocument(htmlDoc
);
1698 if(caretPos
>= htmlDoc
.getLength())
1700 caretPos
= htmlDoc
.getLength() - 1;
1702 jtpMain
.setCaretPosition(caretPos
);
1707 /** Method for inserting a break (BR) element
1709 private void insertBreak()
1710 throws IOException
, BadLocationException
, RuntimeException
1712 int caretPos
= jtpMain
.getCaretPosition();
1713 htmlKit
.insertHTML(htmlDoc
, caretPos
, "<BR>", 0, 0, HTML
.Tag
.BR
);
1714 jtpMain
.setCaretPosition(caretPos
+ 1);
1717 /** Method for inserting a non-breaking space ( )
1719 private void insertNonbreakingSpace()
1720 throws IOException
, BadLocationException
, RuntimeException
1722 int caretPos
= jtpMain
.getCaretPosition();
1723 htmlDoc
.insertString(caretPos
, "\240", jtpMain
.getInputAttributes());
1724 jtpMain
.setCaretPosition(caretPos
+ 1);
1727 /** Method for inserting a form element
1729 private void insertFormElement(HTML
.Tag baseTag
, String baseElement
, Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
, String
[] fieldValues
, boolean hasClosingTag
)
1730 throws IOException
, BadLocationException
, RuntimeException
1732 int caretPos
= jtpMain
.getCaretPosition();
1733 StringBuffer compositeElement
= new StringBuffer("<" + baseElement
);
1734 if(attribs
!= null
&& attribs
.size() > 0)
1736 Enumeration attribEntries
= attribs
.keys();
1737 while(attribEntries
.hasMoreElements())
1739 Object entryKey
= attribEntries
.nextElement();
1740 Object entryValue
= attribs
.get(entryKey
);
1741 if(entryValue
!= null
&& entryValue
!= "")
1743 compositeElement
.append(" " + entryKey
+ "=" + '"' + entryValue
+ '"');
1747 if(fieldNames
!= null
&& fieldNames
.length
> 0)
1749 PropertiesDialog propertiesDialog
= new PropertiesDialog(this.getFrame(), fieldNames
, fieldTypes
, fieldValues
, Translatrix
.getTranslationString("FormDialogTitle"), true
);
1750 propertiesDialog
.show();
1751 String decision
= propertiesDialog
.getDecisionValue();
1752 if(decision
.equals(Translatrix
.getTranslationString("DialogCancel")))
1754 propertiesDialog
.dispose();
1755 propertiesDialog
= null
;
1760 for(int iter
= 0; iter
< fieldNames
.length
; iter
++)
1762 String fieldName
= fieldNames
[iter
];
1763 String propValue
= propertiesDialog
.getFieldValue(fieldName
);
1764 if(propValue
!= null
&& propValue
.length() > 0)
1766 if(fieldName
.equals("checked"))
1768 if(propValue
.equals("true"))
1770 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1775 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1780 propertiesDialog
.dispose();
1781 propertiesDialog
= null
;
1783 // --- Convenience for editing, this makes the FORM visible
1784 if(useFormIndicator
&& baseElement
.equals("form"))
1786 compositeElement
.append(" bgcolor=" + '"' + clrFormIndicator
+ '"');
1789 compositeElement
.append(">");
1792 compositeElement
.append("</" + baseElement
+ ">");
1794 if(baseTag
== HTML
.Tag
.FORM
)
1796 compositeElement
.append("<P> </P>");
1798 htmlKit
.insertHTML(htmlDoc
, caretPos
, compositeElement
.toString(), 0, 0, baseTag
);
1799 // jtpMain.setCaretPosition(caretPos + 1);
1803 /** Alternate method call for inserting a form element
1805 private void insertFormElement(HTML
.Tag baseTag
, String baseElement
, Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
, boolean hasClosingTag
)
1806 throws IOException
, BadLocationException
, RuntimeException
1808 insertFormElement(baseTag
, baseElement
, attribs
, fieldNames
, fieldTypes
, new String
[fieldNames
.length
], hasClosingTag
);
1811 /** Method that handles initial list insertion and deletion
1813 public void manageListElement(Element element
)
1815 Element h
= htmlUtilities
.getListItemParent();
1816 Element listElement
= h
.getParentElement();
1819 htmlUtilities
.removeTag(h
, true
);
1823 /** Method to initiate a find/replace operation
1825 private void doSearch(String searchFindTerm
, String searchReplaceTerm
, boolean bIsFindReplace
, boolean bCaseSensitive
, boolean bStartAtTop
)
1827 boolean bReplaceAll
= false
;
1828 JTextPane searchPane
= jtpMain
;
1829 if(jspSource
.isShowing() || jtpSource
.hasFocus())
1831 searchPane
= jtpSource
;
1833 if(searchFindTerm
== null
|| (bIsFindReplace
&& searchReplaceTerm
== null
))
1835 SearchDialog sdSearchInput
= new SearchDialog(this.getFrame(), Translatrix
.getTranslationString("SearchDialogTitle"), true
, bIsFindReplace
, bCaseSensitive
, bStartAtTop
);
1836 searchFindTerm
= sdSearchInput
.getFindTerm();
1837 searchReplaceTerm
= sdSearchInput
.getReplaceTerm();
1838 bCaseSensitive
= sdSearchInput
.getCaseSensitive();
1839 bStartAtTop
= sdSearchInput
.getStartAtTop();
1840 bReplaceAll
= sdSearchInput
.getReplaceAll();
1842 if(searchFindTerm
!= null
&& (!bIsFindReplace
|| searchReplaceTerm
!= null
))
1846 int results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, 0);
1852 findOffset
= findOffset
+ searchReplaceTerm
.length();
1853 results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, findOffset
);
1858 SimpleInfoDialog sidWarn
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("ErrorNoOccurencesFound") + ":\n" + searchFindTerm
, SimpleInfoDialog
.WARNING
);
1863 int results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, (bStartAtTop ?
0 : searchPane
.getCaretPosition()));
1866 SimpleInfoDialog sidWarn
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("ErrorNoMatchFound") + ":\n" + searchFindTerm
, SimpleInfoDialog
.WARNING
);
1869 lastSearchFindTerm
= new String(searchFindTerm
);
1870 if(searchReplaceTerm
!= null
)
1872 lastSearchReplaceTerm
= new String(searchReplaceTerm
);
1876 lastSearchReplaceTerm
= (String
)null
;
1878 lastSearchCaseSetting
= bCaseSensitive
;
1879 lastSearchTopSetting
= bStartAtTop
;
1883 /** Method for finding (and optionally replacing) a string in the text
1885 private int findText(String findTerm
, String replaceTerm
, boolean bCaseSenstive
, int iOffset
)
1887 JTextPane jtpFindSource
;
1888 if(jspSource
.isShowing() || jtpSource
.hasFocus())
1890 jtpFindSource
= jtpSource
;
1894 jtpFindSource
= jtpMain
;
1896 int searchPlace
= -1;
1899 Document baseDocument
= jtpFindSource
.getDocument();
1902 baseDocument
.getText(0, baseDocument
.getLength()).indexOf(findTerm
, iOffset
) :
1903 baseDocument
.getText(0, baseDocument
.getLength()).toLowerCase().indexOf(findTerm
.toLowerCase(), iOffset
)
1905 if(searchPlace
> -1)
1907 if(replaceTerm
!= null
)
1909 AttributeSet attribs
= null
;
1910 if(baseDocument
instanceof HTMLDocument
)
1912 Element element
= ((HTMLDocument
)baseDocument
).getCharacterElement(searchPlace
);
1913 attribs
= element
.getAttributes();
1915 baseDocument
.remove(searchPlace
, findTerm
.length());
1916 baseDocument
.insertString(searchPlace
, replaceTerm
, attribs
);
1917 jtpFindSource
.setCaretPosition(searchPlace
+ replaceTerm
.length());
1918 jtpFindSource
.requestFocus();
1919 jtpFindSource
.select(searchPlace
, searchPlace
+ replaceTerm
.length());
1923 jtpFindSource
.setCaretPosition(searchPlace
+ findTerm
.length());
1924 jtpFindSource
.requestFocus();
1925 jtpFindSource
.select(searchPlace
, searchPlace
+ findTerm
.length());
1929 catch(BadLocationException ble
)
1931 logException("BadLocationException in actionPerformed method", ble
);
1932 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1937 /** Method for inserting an image from a file
1939 private void insertLocalImage(File whatImage
)
1940 throws IOException
, BadLocationException
, RuntimeException
1942 if(whatImage
== null
)
1944 whatImage
= getImageFromChooser(".", extsIMG
, Translatrix
.getTranslationString("FiletypeIMG"));
1946 if(whatImage
!= null
)
1948 int caretPos
= jtpMain
.getCaretPosition();
1949 htmlKit
.insertHTML(htmlDoc
, caretPos
, "<IMG SRC=\"" + whatImage
+ "\">", 0, 0, HTML
.Tag
.IMG
);
1950 jtpMain
.setCaretPosition(caretPos
+ 1);
1955 /** Method for inserting an image from a server
1957 private void insertServerImage()
1958 throws BadLocationException
1960 if(ServletURL
!= null
)
1964 URL theServlet
= new URL(ServletURL
+ "?GetImages=" + TreePilotSystemID
+ "&ImageExtensions=" + TreePilotProperties
.getString("ValidImageExtensions"));
1965 URLConnection conn
= theServlet
.openConnection();
1966 ObjectInputStream
in = new ObjectInputStream(conn
.getInputStream());
1967 String
[] imageList
= (String
[]) in.readObject();
1968 int caretPos
= jtpMain
.getCaretPosition();
1969 ImageDialog imageDialog
= new ImageDialog(this, ImageDir
+ TreePilotSystemID
, imageList
, "Image Chooser", true
);
1970 String selectedImage
= imageDialog
.getSelectedImage();
1971 imageDialog
.dispose();
1972 if(selectedImage
!= null
&& !selectedImage
.equals(""))
1974 htmlKit
.insertHTML(htmlDoc
, caretPos
, selectedImage
, 0, 0, HTML
.Tag
.IMG
);
1975 jtpMain
.setCaretPosition(caretPos
+ 1);
1977 jtpMain
.requestFocus();
1980 catch (MalformedURLException mue
)
1982 System
.err
.println("MalFormedURLException during insertImage " + mue
);
1984 catch (IOException ie
)
1986 System
.err
.println("IOException during insertImage " + ie
);
1988 catch (ClassNotFoundException cnfe
)
1990 System
.err
.println("ClassNotFoundException during insertImage" + cnfe
);
1995 /** Method for inserting an image
1997 public String
insertFile()
1999 String selectedFile
= null
;
2000 if(ServletURL
!= null
)
2004 URL theServlet
= new URL(ServletURL
+ "?GetFiles=" + TreePilotSystemID
+ "&FileExtensions=" + TreePilotProperties
.getString("ValidFileExtensions"));
2005 URLConnection conn
= theServlet
.openConnection();
2006 ObjectInputStream
in = new ObjectInputStream(conn
.getInputStream());
2007 String
[] fileList
= (String
[]) in.readObject();
2008 FileDialog fileDialog
= new FileDialog(this, ImageDir
+ TreePilotSystemID
, fileList
, "File Chooser", true
);
2009 selectedFile
= fileDialog
.getSelectedFile();
2010 fileDialog
.dispose();
2013 catch (MalformedURLException mue
)
2015 System
.err
.println("MalFormedURLException during insertFile " + mue
);
2017 catch (IOException ie
)
2019 System
.err
.println("IOException during insertFile " + ie
);
2021 catch (ClassNotFoundException cnfe
)
2023 System
.err
.println("ClassNotFoundException during insertFile" + cnfe
);
2026 return selectedFile
;
2029 /** Method for saving text as a complete HTML document
2031 private void writeOut(HTMLDocument doc
, File whatFile
)
2032 throws IOException
, BadLocationException
2034 if(whatFile
== null
)
2036 whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
2038 if(whatFile
!= null
)
2040 FileWriter fw
= new FileWriter(whatFile
);
2041 htmlKit
.write(fw
, doc
, 0, doc
.getLength());
2044 currentFile
= whatFile
;
2050 /** Method for saving text as an HTML fragment
2052 private void writeOutFragment(HTMLDocument doc
, String containingTag
)
2053 throws IOException
, BadLocationException
2055 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
2056 if(whatFile
!= null
)
2058 FileWriter fw
= new FileWriter(whatFile
);
2059 // Element eleBody = locateElementInDocument((StyledDocument)doc, containingTag);
2060 // htmlKit.write(fw, doc, eleBody.getStartOffset(), eleBody.getEndOffset());
2061 String docTextCase
= jtpSource
.getText().toLowerCase();
2062 int tagStart
= docTextCase
.indexOf("<" + containingTag
.toLowerCase());
2063 int tagStartClose
= docTextCase
.indexOf(">", tagStart
) + 1;
2064 String closeTag
= "</" + containingTag
.toLowerCase() + ">";
2065 int tagEndOpen
= docTextCase
.indexOf(closeTag
);
2066 if(tagStartClose
< 0) { tagStartClose
= 0; }
2067 if(tagEndOpen
< 0 || tagEndOpen
> docTextCase
.length()) { tagEndOpen
= docTextCase
.length(); }
2068 String bodyText
= jtpSource
.getText().substring(tagStartClose
, tagEndOpen
);
2069 fw
.write(bodyText
, 0, bodyText
.length());
2076 /** Method for saving text as an RTF document
2078 private void writeOutRTF(StyledDocument doc
)
2079 throws IOException
, BadLocationException
2081 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsRTF
, Translatrix
.getTranslationString("FiletypeRTF"));
2082 if(whatFile
!= null
)
2084 FileOutputStream fos
= new FileOutputStream(whatFile
);
2085 RTFEditorKit rtfKit
= new RTFEditorKit();
2086 rtfKit
.write(fos
, doc
, 0, doc
.getLength());
2093 /** Method for saving text as a Base64 encoded document
2095 private void writeOutBase64(String text
)
2096 throws IOException
, BadLocationException
2098 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsB64
, Translatrix
.getTranslationString("FiletypeB64"));
2099 if(whatFile
!= null
)
2101 String base64text
= Base64Codec
.encode(text
);
2102 FileWriter fw
= new FileWriter(whatFile
);
2103 fw
.write(base64text
, 0, base64text
.length());
2110 /** Method to invoke loading HTML into the app
2112 private void openDocument(File whatFile
)
2113 throws IOException
, BadLocationException
2115 if(whatFile
== null
)
2117 whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
2119 if(whatFile
!= null
)
2123 loadDocument(whatFile
, null
);
2125 catch(ChangedCharSetException ccse
)
2127 String charsetType
= ccse
.getCharSetSpec().toLowerCase();
2128 int pos
= charsetType
.indexOf("charset");
2133 while(pos
< charsetType
.length() && charsetType
.charAt(pos
) != '=')
2137 pos
++; // Places file cursor past the equals sign (=)
2138 String whatEncoding
= charsetType
.substring(pos
).trim();
2139 loadDocument(whatFile
, whatEncoding
);
2145 /** Method for loading HTML document into the app, including document encoding setting
2147 private void loadDocument(File whatFile
, String whatEncoding
)
2148 throws IOException
, BadLocationException
2151 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
2154 if(whatEncoding
== null
)
2156 r
= new InputStreamReader(new FileInputStream(whatFile
));
2160 r
= new InputStreamReader(new FileInputStream(whatFile
), whatEncoding
);
2161 htmlDoc
.putProperty("IgnoreCharsetDirective", new Boolean(true
));
2163 htmlKit
.read(r
, htmlDoc
, 0);
2165 registerDocument(htmlDoc
);
2166 jtpSource
.setText(jtpMain
.getText());
2167 currentFile
= whatFile
;
2179 /** Method for loading a Base64 encoded document
2181 private void openDocumentBase64(File whatFile
)
2182 throws IOException
, BadLocationException
2184 if(whatFile
== null
)
2186 whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsB64
, Translatrix
.getTranslationString("FiletypeB64"));
2188 if(whatFile
!= null
)
2190 FileReader fr
= new FileReader(whatFile
);
2192 StringBuffer encodedText
= new StringBuffer();
2195 while((nextChar
= fr
.read()) != -1)
2197 encodedText
.append((char)nextChar
);
2200 jtpSource
.setText(Base64Codec
.decode(encodedText
.toString()));
2201 jtpMain
.setText(jtpSource
.getText());
2202 registerDocument((ExtendedHTMLDocument
)(jtpMain
.getDocument()));
2214 /** Method for loading a Stylesheet into the app
2216 private void openStyleSheet(File fileCSS
)
2221 fileCSS
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsCSS
, Translatrix
.getTranslationString("FiletypeCSS"));
2225 String currDocText
= jtpMain
.getText();
2226 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
2227 styleSheet
= htmlDoc
.getStyleSheet();
2228 URL cssUrl
= fileCSS
.toURL();
2229 InputStream is
= cssUrl
.openStream();
2230 BufferedReader br
= new BufferedReader(new InputStreamReader(is
));
2231 styleSheet
.loadRules(br
, cssUrl
);
2233 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
2234 registerDocument(htmlDoc
);
2235 jtpMain
.setText(currDocText
);
2236 jtpSource
.setText(jtpMain
.getText());
2241 /** Method for serializing the document out to a file
2243 public void serializeOut(HTMLDocument doc
)
2246 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsSer
, Translatrix
.getTranslationString("FiletypeSer"));
2247 if(whatFile
!= null
)
2249 ObjectOutputStream oos
= new ObjectOutputStream(new FileOutputStream(whatFile
));
2250 oos
.writeObject(doc
);
2257 /** Method for reading in a serialized document from a file
2259 public void serializeIn()
2260 throws IOException
, ClassNotFoundException
2262 File whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsSer
, Translatrix
.getTranslationString("FiletypeSer"));
2263 if(whatFile
!= null
)
2265 ObjectInputStream ois
= new ObjectInputStream(new FileInputStream(whatFile
));
2266 htmlDoc
= (ExtendedHTMLDocument
)(ois
.readObject());
2268 registerDocument(htmlDoc
);
2274 /** Method for obtaining a File for input/output using a JFileChooser dialog
2276 private File
getFileFromChooser(String startDir
, int dialogType
, String
[] exts
, String desc
)
2278 JFileChooser jfileDialog
= new JFileChooser(startDir
);
2279 jfileDialog
.setDialogType(dialogType
);
2280 jfileDialog
.setFileFilter(new MutableFilter(exts
, desc
));
2281 int optionSelected
= JFileChooser
.CANCEL_OPTION
;
2282 if(dialogType
== JFileChooser
.OPEN_DIALOG
)
2284 optionSelected
= jfileDialog
.showOpenDialog(this);
2286 else if(dialogType
== JFileChooser
.SAVE_DIALOG
)
2288 optionSelected
= jfileDialog
.showSaveDialog(this);
2290 else // default to an OPEN_DIALOG
2292 optionSelected
= jfileDialog
.showOpenDialog(this);
2294 if(optionSelected
== JFileChooser
.APPROVE_OPTION
)
2296 return jfileDialog
.getSelectedFile();
2301 /** Method for obtaining an Image for input using a custom JFileChooser dialog
2303 private File
getImageFromChooser(String startDir
, String
[] exts
, String desc
)
2305 ImageFileChooser jImageDialog
= new ImageFileChooser(startDir
);
2306 jImageDialog
.setDialogType(JFileChooser
.CUSTOM_DIALOG
);
2307 jImageDialog
.setFileFilter(new MutableFilter(exts
, desc
));
2308 jImageDialog
.setDialogTitle(Translatrix
.getTranslationString("ImageDialogTitle"));
2309 int optionSelected
= JFileChooser
.CANCEL_OPTION
;
2310 optionSelected
= jImageDialog
.showDialog(this, Translatrix
.getTranslationString("Insert"));
2311 if(optionSelected
== JFileChooser
.APPROVE_OPTION
)
2313 return jImageDialog
.getSelectedFile();
2318 /** Method for describing the node hierarchy of the document
2320 private void describeDocument(StyledDocument doc
)
2322 Element
[] elements
= doc
.getRootElements();
2323 for(int i
= 0; i
< elements
.length
; i
++)
2325 indent
= indentStep
;
2326 for(int j
= 0; j
< indent
; j
++) { System
.out
.print(" "); }
2327 System
.out
.print(elements
[i
]);
2328 traverseElement(elements
[i
]);
2329 System
.out
.println("");
2333 /** Traverses nodes for the describing method
2335 private void traverseElement(Element element
)
2337 indent
+= indentStep
;
2338 for(int i
= 0; i
< element
.getElementCount(); i
++)
2340 for(int j
= 0; j
< indent
; j
++) { System
.out
.print(" "); }
2341 System
.out
.print(element
.getElement(i
));
2342 traverseElement(element
.getElement(i
));
2344 indent
-= indentStep
;
2347 /** Method to locate a node element by name
2349 private Element
locateElementInDocument(StyledDocument doc
, String elementName
)
2351 Element
[] elements
= doc
.getRootElements();
2352 for(int i
= 0; i
< elements
.length
; i
++)
2354 if(elements
[i
].getName().equalsIgnoreCase(elementName
))
2360 Element rtnElement
= locateChildElementInDocument(elements
[i
], elementName
);
2361 if(rtnElement
!= null
)
2367 return (Element
)null
;
2370 /** Traverses nodes for the locating method
2372 private Element
locateChildElementInDocument(Element element
, String elementName
)
2374 for(int i
= 0; i
< element
.getElementCount(); i
++)
2376 if(element
.getElement(i
).getName().equalsIgnoreCase(elementName
))
2378 return element
.getElement(i
);
2381 return (Element
)null
;
2384 /** Convenience method for obtaining the WYSIWYG JTextPane
2386 public JTextPane
getTextPane()
2391 /** Convenience method for obtaining the Source JTextPane
2393 public JTextPane
getSourcePane()
2398 /** Convenience method for obtaining the application as a Frame
2400 public Frame
getFrame()
2402 return frameHandler
;
2405 /** Convenience method for setting the parent Frame
2407 public void setFrame(Frame parentFrame
)
2409 frameHandler
= parentFrame
;
2412 /** Convenience method for obtaining the pre-generated menu bar
2414 public JMenuBar
getMenuBar()
2419 /** Convenience method for obtaining a custom menu bar
2421 public JMenuBar
getCustomMenuBar(Vector vcMenus
)
2423 jMenuBar
= new JMenuBar();
2424 for(int i
= 0; i
< vcMenus
.size(); i
++)
2426 String menuToAdd
= ((String
)(vcMenus
.elementAt(i
))).toLowerCase();
2427 if(htMenus
.containsKey(menuToAdd
))
2429 jMenuBar
.add((JMenu
)(htMenus
.get(menuToAdd
)));
2435 /** Convenience method for obtaining the pre-generated toolbar
2437 public JToolBar
getToolBar(boolean isShowing
)
2439 jcbmiViewToolbar
.setState(isShowing
);
2443 /** Convenience method for obtaining the pre-generated toolbar
2445 public JToolBar
getCustomToolBar(Vector vcTools
, boolean isShowing
)
2447 jcbmiViewToolbar
.setState(isShowing
);
2448 jToolBar
= new JToolBar(JToolBar
.HORIZONTAL
);
2449 jToolBar
.setFloatable(false
);
2450 for(int i
= 0; i
< vcTools
.size(); i
++)
2452 String toolToAdd
= ((String
)(vcTools
.elementAt(i
))).toLowerCase();
2453 if(toolToAdd
.equals(KEY_TOOL_SEP
))
2455 jToolBar
.add(new JToolBar
.Separator());
2457 else if(htTools
.containsKey(toolToAdd
))
2459 if(htTools
.get(toolToAdd
) instanceof JButtonNoFocus
)
2461 jToolBar
.add((JButtonNoFocus
)(htTools
.get(toolToAdd
)));
2463 else if(htTools
.get(toolToAdd
) instanceof JToggleButtonNoFocus
)
2465 jToolBar
.add((JToggleButtonNoFocus
)(htTools
.get(toolToAdd
)));
2467 else if(htTools
.get(toolToAdd
) instanceof JComboBoxNoFocus
)
2469 jToolBar
.add((JComboBoxNoFocus
)(htTools
.get(toolToAdd
)));
2473 jToolBar
.add((JComponent
)(htTools
.get(toolToAdd
)));
2480 /** Convenience method for obtaining the current file handle
2482 public File
getCurrentFile()
2487 /** Convenience method for obtaining the application name
2489 public String
getAppName()
2494 /** Convenience method for obtaining the document text
2496 public String
getDocumentText()
2498 return jtpMain
.getText();
2501 /** Convenience method for obtaining the document text
2502 * contained within a tag pair
2504 public String
getDocumentSubText(String tagBlock
)
2506 return getSubText(tagBlock
);
2509 /** Method for extracting the text within a tag
2511 private String
getSubText(String containingTag
)
2513 jtpSource
.setText(jtpMain
.getText());
2514 String docTextCase
= jtpSource
.getText().toLowerCase();
2515 int tagStart
= docTextCase
.indexOf("<" + containingTag
.toLowerCase());
2516 int tagStartClose
= docTextCase
.indexOf(">", tagStart
) + 1;
2517 String closeTag
= "</" + containingTag
.toLowerCase() + ">";
2518 int tagEndOpen
= docTextCase
.indexOf(closeTag
);
2519 if(tagStartClose
< 0) { tagStartClose
= 0; }
2520 if(tagEndOpen
< 0 || tagEndOpen
> docTextCase
.length()) { tagEndOpen
= docTextCase
.length(); }
2521 return jtpSource
.getText().substring(tagStartClose
, tagEndOpen
);
2524 /** Convenience method for obtaining the document text
2525 * contained within the BODY tags (a common request)
2527 public String
getDocumentBody()
2529 return getSubText("body");
2532 /** Convenience method for setting the document text
2534 public void setDocumentText(String sText
)
2536 jtpMain
.setText(sText
);
2537 ((HTMLEditorKit
)(jtpMain
.getEditorKit())).setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
2538 jtpSource
.setText(jtpMain
.getText());
2539 ((HTMLEditorKit
)(jtpSource
.getEditorKit())).setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
2542 /** Convenience method for obtaining the document text
2544 private void updateTitle()
2546 frameHandler
.setTitle(appName
+ (currentFile
== null ?
"" : " - " + currentFile
.getName()));
2549 /** Convenience method for clearing out the UndoManager
2551 public void purgeUndos()
2553 if(undoMngr
!= null
)
2555 undoMngr
.discardAllEdits();
2556 undoAction
.updateUndoState();
2557 redoAction
.updateRedoState();
2561 /** Convenience method for refreshing and displaying changes
2563 public void refreshOnUpdate()
2565 jtpMain
.setText(jtpMain
.getText());
2566 jtpSource
.setText(jtpMain
.getText());
2571 /** Convenience method for deallocating the app resources
2573 public void dispose()
2575 frameHandler
.dispose();
2576 spellCheck
.dispose();
2582 /** Convenience method for fetching icon images from jar file
2584 private ImageIcon
getEkitIcon(String iconName
)
2586 return new ImageIcon(Toolkit
.getDefaultToolkit().getImage(getClass().getResource("icons/" + iconName
+ "HK.gif")));
2589 /** Convenience method for outputting exceptions
2591 private void logException(String internalMessage
, Exception e
)
2593 System
.err
.println(internalMessage
);
2594 e
.printStackTrace(System
.err
);
2597 /** Convenience method for toggling source window visibility
2599 private void toggleSourceWindow()
2601 if(!(jspSource
.isShowing()))
2603 jtpSource
.setText(jtpMain
.getText());
2604 jspltDisplay
.setRightComponent(jspSource
);
2607 jspltDisplay
.setDividerLocation(0);
2608 jspltDisplay
.setEnabled(false
);
2612 jspltDisplay
.setDividerLocation(iSplitPos
);
2613 jspltDisplay
.setEnabled(true
);
2618 jtpMain
.setText(jtpSource
.getText());
2619 iSplitPos
= jspltDisplay
.getDividerLocation();
2620 jspltDisplay
.remove(jspSource
);
2621 jtpMain
.requestFocus();
2624 jcbmiViewSource
.setSelected(jspSource
.isShowing());
2625 jtbtnViewSource
.setSelected(jspSource
.isShowing());
2628 /** Searches the specified element for CLASS attribute setting
2630 private String
findStyle(Element element
)
2632 AttributeSet
as = element
.getAttributes();
2637 Object val
= as.getAttribute(HTML
.Attribute
.CLASS
);
2638 if(val
!= null
&& (val
instanceof String
))
2642 for(Enumeration e
= as.getAttributeNames(); e
.hasMoreElements();)
2644 Object key
= e
.nextElement();
2645 if(key
instanceof HTML
.Tag
)
2647 AttributeSet eas
= (AttributeSet
)(as.getAttribute(key
));
2650 val
= eas
.getAttribute(HTML
.Attribute
.CLASS
);
2662 /** Handles caret tracking and related events, such as displaying the current style
2663 * of the text under the caret
2665 private void handleCaretPositionChange(CaretEvent ce
)
2667 int caretPos
= ce
.getDot();
2668 Element element
= htmlDoc
.getCharacterElement(caretPos
);
2670 ---- TAG EXPLICATOR CODE -------------------------------------------
2671 javax.swing.text.ElementIterator ei = new javax.swing.text.ElementIterator(htmlDoc);
2673 while((ele = ei.next()) != null)
2675 System.out.println("ELEMENT : " + ele.getName());
2677 System.out.println("ELEMENT:" + element.getName());
2678 Element elementParent = element.getParentElement();
2679 System.out.println("ATTRS:");
2680 AttributeSet attribs = elementParent.getAttributes();
2681 for(Enumeration eAttrs = attribs.getAttributeNames(); eAttrs.hasMoreElements();)
2683 System.out.println(" " + eAttrs.nextElement().toString());
2685 while(elementParent != null && !elementParent.getName().equals("body"))
2687 String parentName = elementParent.getName();
2688 System.out.println("PARENT:" + parentName);
2689 System.out.println("ATTRS:");
2690 attribs = elementParent.getAttributes();
2691 for(Enumeration eAttr = attribs.getAttributeNames(); eAttr.hasMoreElements();)
2693 System.out.println(" " + eAttr.nextElement().toString());
2695 elementParent = elementParent.getParentElement();
2697 ---- END -------------------------------------------
2703 String style
= null
;
2704 Vector vcStyles
= new Vector();
2705 while(element
!= null
)
2709 style
= findStyle(element
);
2711 vcStyles
.add(element
);
2712 element
= element
.getParentElement();
2714 int stylefound
= -1;
2717 for(int i
= 0; i
< jcmbStyleSelector
.getItemCount(); i
++)
2719 String
in = (String
)(jcmbStyleSelector
.getItemAt(i
));
2720 if(in.equalsIgnoreCase(style
))
2729 Action ac
= jcmbStyleSelector
.getAction();
2730 ac
.setEnabled(false
);
2731 jcmbStyleSelector
.setSelectedIndex(stylefound
);
2732 ac
.setEnabled(true
);
2736 jcmbStyleSelector
.setSelectedIndex(0);
2740 /** Server-side image handling methods
2742 protected void setServletURL(String url
)
2747 protected void setImageDir(String sysDir
)
2752 public void setTreePilotSystemID(String theSystem
)
2754 TreePilotSystemID
= theSystem
;
2759 public ExtendedHTMLDocument
getExtendedHtmlDoc()
2761 return (ExtendedHTMLDocument
)htmlDoc
;
2764 public int getCaretPosition()
2766 return jtpMain
.getCaretPosition();
2769 public void setCaretPosition(int newPositon
)
2777 jtpMain
.setCaretPosition(newPositon
);
2779 catch (IllegalArgumentException iae
)
2784 } while(!end
&& newPositon
>= 0);
2787 /* Inner Classes --------------------------------------------- */
2789 /** Class for implementing Undo as an autonomous action
2791 class UndoAction
extends AbstractAction
2795 super(Translatrix
.getTranslationString("Undo"));
2799 public void actionPerformed(ActionEvent e
)
2805 catch(CannotUndoException ex
)
2807 ex
.printStackTrace();
2810 redoAction
.updateRedoState();
2813 protected void updateUndoState()
2815 if(undoMngr
.canUndo())
2818 putValue(Action
.NAME
, undoMngr
.getUndoPresentationName());
2823 putValue(Action
.NAME
, Translatrix
.getTranslationString("Undo"));
2828 /** Class for implementing Redo as an autonomous action
2830 class RedoAction
extends AbstractAction
2834 super(Translatrix
.getTranslationString("Redo"));
2838 public void actionPerformed(ActionEvent e
)
2844 catch(CannotUndoException ex
)
2846 ex
.printStackTrace();
2849 undoAction
.updateUndoState();
2852 protected void updateRedoState()
2854 if(undoMngr
.canRedo())
2857 putValue(Action
.NAME
, undoMngr
.getRedoPresentationName());
2862 putValue(Action
.NAME
, Translatrix
.getTranslationString("Redo"));
2867 /** Class for implementing the Undo listener to handle the Undo and Redo actions
2869 class CustomUndoableEditListener
implements UndoableEditListener
2871 public void undoableEditHappened(UndoableEditEvent uee
)
2873 undoMngr
.addEdit(uee
.getEdit());
2874 undoAction
.updateUndoState();
2875 redoAction
.updateRedoState();