2 GNU Lesser General Public License
4 EkitCore - Base Java Swing HTML Editor & Viewer Class (Basic 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
;
118 * Main application class for editing and saving HTML in a Java text component
120 * @author Howard Kistler
124 * Java 2 (JDK 1.3 or 1.4)
128 public class EkitCore
extends JPanel
implements ActionListener
, KeyListener
, DocumentListener
131 private JSplitPane jspltDisplay
;
132 private JTextPane jtpMain
;
133 private ExtendedHTMLEditorKit htmlKit
;
134 private ExtendedHTMLDocument htmlDoc
;
135 private StyleSheet styleSheet
;
136 private JTextPane jtpSource
;
137 private JScrollPane jspSource
;
138 private JToolBar jToolBar
;
140 private JCheckBoxMenuItem jcbmiViewToolbar
;
141 private JCheckBoxMenuItem jcbmiViewSource
;
143 private JButtonNoFocus jbtnNewHTML
;
144 private JButtonNoFocus jbtnOpenHTML
;
145 private JButtonNoFocus jbtnSaveHTML
;
146 private JButtonNoFocus jbtnCut
;
147 private JButtonNoFocus jbtnCopy
;
148 private JButtonNoFocus jbtnPaste
;
149 private JButtonNoFocus jbtnBold
;
150 private JButtonNoFocus jbtnItalic
;
151 private JButtonNoFocus jbtnUnderline
;
152 private JButtonNoFocus jbtnStrike
;
153 private JButtonNoFocus jbtnSuperscript
;
154 private JButtonNoFocus jbtnSubscript
;
155 private JButtonNoFocus jbtnUList
;
156 private JButtonNoFocus jbtnOList
;
157 private JButtonNoFocus jbtnClearFormat
;
158 private JButtonNoFocus jbtnAnchor
;
159 private JToggleButtonNoFocus jtbtnViewSource
;
160 private JComboBoxNoFocus jcmbStyleSelector
;
162 private Frame frameHandler
;
164 private HTMLUtilities htmlUtilities
= new HTMLUtilities(this);
167 private StyledEditorKit
.BoldAction actionFontBold
;
168 private StyledEditorKit
.ItalicAction actionFontItalic
;
169 private StyledEditorKit
.UnderlineAction actionFontUnderline
;
170 private FormatAction actionFontStrike
;
171 private FormatAction actionFontSuperscript
;
172 private FormatAction actionFontSubscript
;
173 private ListAutomationAction actionListUnordered
;
174 private ListAutomationAction actionListOrdered
;
175 private CustomAction actionSelectFont
;
176 private CustomAction actionClearFormat
;
177 private CustomAction actionInsertAnchor
;
179 protected UndoManager undoMngr
;
180 protected UndoAction undoAction
;
181 protected RedoAction redoAction
;
184 private JMenuBar jMenuBar
;
185 private JMenu jMenuFile
;
186 private JMenu jMenuEdit
;
187 private JMenu jMenuView
;
188 private JMenu jMenuFont
;
189 private JMenu jMenuFormat
;
190 private JMenu jMenuInsert
;
191 private JMenu jMenuTable
;
192 private JMenu jMenuForms
;
193 private JMenu jMenuSearch
;
194 private JMenu jMenuHelp
;
195 private JMenu jMenuDebug
;
199 public static final String KEY_MENU_FILE
= "file";
200 public static final String KEY_MENU_EDIT
= "edit";
201 public static final String KEY_MENU_VIEW
= "view";
202 public static final String KEY_MENU_FONT
= "font";
203 public static final String KEY_MENU_FORMAT
= "format";
204 public static final String KEY_MENU_INSERT
= "insert";
205 public static final String KEY_MENU_TABLE
= "table";
206 public static final String KEY_MENU_FORMS
= "forms";
207 public static final String KEY_MENU_SEARCH
= "search";
208 public static final String KEY_MENU_TOOLS
= "tools";
209 public static final String KEY_MENU_HELP
= "help";
210 public static final String KEY_MENU_DEBUG
= "debug";
213 public static final String KEY_TOOL_SEP
= "separator";
214 public static final String KEY_TOOL_NEW
= "new";
215 public static final String KEY_TOOL_OPEN
= "open";
216 public static final String KEY_TOOL_SAVE
= "save";
217 public static final String KEY_TOOL_CUT
= "cut";
218 public static final String KEY_TOOL_COPY
= "copy";
219 public static final String KEY_TOOL_PASTE
= "paste";
220 public static final String KEY_TOOL_BOLD
= "bold";
221 public static final String KEY_TOOL_ITALIC
= "italic";
222 public static final String KEY_TOOL_UNDERLINE
= "underline";
223 public static final String KEY_TOOL_STRIKE
= "strike";
224 public static final String KEY_TOOL_SUPER
= "superscript";
225 public static final String KEY_TOOL_SUB
= "subscript";
226 public static final String KEY_TOOL_ULIST
= "ulist";
227 public static final String KEY_TOOL_OLIST
= "olist";
228 public static final String KEY_TOOL_CLEAR
= "clearformats";
229 public static final String KEY_TOOL_ANCHOR
= "anchor";
230 public static final String KEY_TOOL_SOURCE
= "viewsource";
231 public static final String KEY_TOOL_STYLES
= "styleselect";
233 // Menu & Tool Key Arrays
234 private static Hashtable htMenus
= new Hashtable();
235 private static Hashtable htTools
= new Hashtable();
237 private final String appName
= "Ekit";
238 private final String menuDialog
= "..."; /* text to append to a MenuItem label when menu item opens a dialog */
240 private final boolean useFormIndicator
= true
; /* Creates a highlighted background on a new FORM so that it may be more easily edited */
241 private final String clrFormIndicator
= "#cccccc";
243 // System Clipboard Settings
244 private java
.awt
.datatransfer
.Clipboard sysClipboard
;
245 private SecurityManager secManager
;
248 private int iSplitPos
= 0;
250 private boolean exclusiveEdit
= true
;
252 private String lastSearchFindTerm
= null
;
253 private String lastSearchReplaceTerm
= null
;
254 private boolean lastSearchCaseSetting
= false
;
255 private boolean lastSearchTopSetting
= false
;
257 private File currentFile
= null
;
259 private int indent
= 0;
260 private final int indentStep
= 4;
262 // File extensions for MutableFilter
263 private final String
[] extsHTML
= { "html", "htm", "shtml" };
264 private final String
[] extsCSS
= { "css" };
265 private final String
[] extsIMG
= { "gif", "jpg", "jpeg", "png" };
266 private final String
[] extsRTF
= { "rtf" };
267 private final String
[] extsB64
= { "b64" };
268 private final String
[] extsSer
= { "ser" };
270 /* Servlet Settings */
271 private String ServletURL
= null
;
272 private String TreePilotSystemID
= "";
273 private String ImageDir
= "";
274 private static ResourceBundle TreePilotProperties
;
276 /** Master Constructor
277 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
278 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
279 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
280 * @param urlStyleSheet [URL] A URL reference to the CSS style sheet.
281 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
282 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
283 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
284 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
285 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
286 * @param base64 [boolean] Specifies whether the raw document is Base64 encoded or not.
287 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
289 public EkitCore(String sDocument
, String sStyleSheet
, String sRawDocument
, URL urlStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
, boolean debugMode
)
293 exclusiveEdit
= editModeExclusive
;
295 frameHandler
= new Frame();
297 // Determine if system clipboard is available
298 secManager
= System
.getSecurityManager();
299 if(secManager
!= null
)
303 secManager
.checkSystemClipboardAccess();
304 sysClipboard
= Toolkit
.getDefaultToolkit().getSystemClipboard();
306 catch (SecurityException se
)
312 /* Localize for language */
313 Translatrix
.setBundleName("com.hexidec.ekit.LanguageResources");
314 Locale baseLocale
= (Locale
)null
;
315 if(sLanguage
!= null
&& sCountry
!= null
)
317 baseLocale
= new Locale(sLanguage
, sCountry
);
319 Translatrix
.setLocale(baseLocale
);
321 /* Load TreePilot properties */
324 TreePilotProperties
= ResourceBundle
.getBundle("com.hexidec.ekit.TreePilot");
326 catch(MissingResourceException mre
)
328 logException("MissingResourceException while loading treepilot file", mre
);
331 /* Create the editor kit, document, and stylesheet */
332 jtpMain
= new JTextPane();
333 htmlKit
= new ExtendedHTMLEditorKit();
334 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
335 styleSheet
= htmlDoc
.getStyleSheet();
336 htmlKit
.setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
338 /* Set up the text pane */
339 jtpMain
.setEditorKit(htmlKit
);
340 jtpMain
.setDocument(htmlDoc
);
341 jtpMain
.setMargin(new Insets(4, 4, 4, 4));
342 jtpMain
.addKeyListener(this);
344 /* Create the source text area */
345 jtpSource
= new JTextPane();
346 jtpSource
.setBackground(new Color(212, 212, 212));
347 jtpSource
.setSelectionColor(new Color(255, 192, 192));
348 jtpSource
.setText(jtpMain
.getText());
349 jtpSource
.getDocument().addDocumentListener(this);
351 /* Add CaretListener for tracking caret location events */
352 jtpMain
.addCaretListener(new CaretListener()
354 public void caretUpdate(CaretEvent ce
)
356 handleCaretPositionChange(ce
);
360 /* Set up the undo features */
361 undoMngr
= new UndoManager();
362 undoAction
= new UndoAction();
363 redoAction
= new RedoAction();
364 jtpMain
.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
366 /* Insert raw document, if exists */
367 if(sRawDocument
!= null
&& sRawDocument
.length() > 0)
371 jtpMain
.setText(Base64Codec
.decode(sRawDocument
));
375 jtpMain
.setText(sRawDocument
);
378 jtpMain
.setCaretPosition(0);
379 jtpMain
.getDocument().addDocumentListener(this);
381 /* Import CSS from reference, if exists */
382 if(urlStyleSheet
!= null
)
386 String currDocText
= jtpMain
.getText();
387 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
388 styleSheet
= htmlDoc
.getStyleSheet();
389 BufferedReader br
= new BufferedReader(new InputStreamReader(urlStyleSheet
.openStream()));
390 styleSheet
.loadRules(br
, urlStyleSheet
);
392 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
393 registerDocument(htmlDoc
);
394 jtpMain
.setText(currDocText
);
395 jtpSource
.setText(jtpMain
.getText());
399 e
.printStackTrace(System
.out
);
403 /* Preload the specified HTML document, if exists */
404 if(sDocument
!= null
)
406 File defHTML
= new File(sDocument
);
411 openDocument(defHTML
);
415 logException("Exception in preloading HTML document", e
);
420 /* Preload the specified CSS document, if exists */
421 if(sStyleSheet
!= null
)
423 File defCSS
= new File(sStyleSheet
);
428 openStyleSheet(defCSS
);
432 logException("Exception in preloading CSS stylesheet", e
);
437 /* Collect the actions that the JTextPane is naturally aware of */
438 Hashtable actions
= new Hashtable();
439 Action
[] actionsArray
= jtpMain
.getActions();
440 for(int i
= 0; i
< actionsArray
.length
; i
++)
442 Action a
= actionsArray
[i
];
443 actions
.put(a
.getValue(Action
.NAME
), a
);
446 /* Create shared actions */
447 actionFontBold
= new StyledEditorKit
.BoldAction();
448 actionFontItalic
= new StyledEditorKit
.ItalicAction();
449 actionFontUnderline
= new StyledEditorKit
.UnderlineAction();
450 actionFontStrike
= new FormatAction(this, Translatrix
.getTranslationString("FontStrike"), HTML
.Tag
.STRIKE
);
451 actionFontSuperscript
= new FormatAction(this, Translatrix
.getTranslationString("FontSuperscript"), HTML
.Tag
.SUP
);
452 actionFontSubscript
= new FormatAction(this, Translatrix
.getTranslationString("FontSubscript"), HTML
.Tag
.SUB
);
453 actionListUnordered
= new ListAutomationAction(this, Translatrix
.getTranslationString("ListUnordered"), HTML
.Tag
.UL
);
454 actionListOrdered
= new ListAutomationAction(this, Translatrix
.getTranslationString("ListOrdered"), HTML
.Tag
.OL
);
455 Hashtable customAttr
= new Hashtable();
456 customAttr
.put("face","");
457 actionSelectFont
= new CustomAction(this, Translatrix
.getTranslationString("FontSelect") + menuDialog
, HTML
.Tag
.FONT
, customAttr
);
458 actionClearFormat
= new CustomAction(this, Translatrix
.getTranslationString("FormatClear"), new HTML
.UnknownTag(""));
459 actionInsertAnchor
= new CustomAction(this, Translatrix
.getTranslationString("InsertAnchor") + menuDialog
, HTML
.Tag
.A
);
461 /* Build the menus */
463 jMenuFile
= new JMenu(Translatrix
.getTranslationString("File"));
464 htMenus
.put(KEY_MENU_FILE
, jMenuFile
);
465 JMenuItem jmiNew
= new JMenuItem(Translatrix
.getTranslationString("NewDocument")); jmiNew
.setActionCommand("newdoc"); jmiNew
.addActionListener(this); jmiNew
.setAccelerator(KeyStroke
.getKeyStroke('N', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiNew
.setIcon(getEkitIcon("New")); }; jMenuFile
.add(jmiNew
);
466 JMenuItem jmiOpenHTML
= new JMenuItem(Translatrix
.getTranslationString("OpenDocument") + menuDialog
); jmiOpenHTML
.setActionCommand("openhtml"); jmiOpenHTML
.addActionListener(this); jmiOpenHTML
.setAccelerator(KeyStroke
.getKeyStroke('O', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiOpenHTML
.setIcon(getEkitIcon("Open")); }; jMenuFile
.add(jmiOpenHTML
);
467 JMenuItem jmiOpenCSS
= new JMenuItem(Translatrix
.getTranslationString("OpenStyle") + menuDialog
); jmiOpenCSS
.setActionCommand("opencss"); jmiOpenCSS
.addActionListener(this); jMenuFile
.add(jmiOpenCSS
);
468 JMenuItem jmiOpenB64
= new JMenuItem(Translatrix
.getTranslationString("OpenBase64Document") + menuDialog
); jmiOpenB64
.setActionCommand("openb64"); jmiOpenB64
.addActionListener(this); jMenuFile
.add(jmiOpenB64
);
469 jMenuFile
.addSeparator();
470 JMenuItem jmiSave
= new JMenuItem(Translatrix
.getTranslationString("Save")); jmiSave
.setActionCommand("save"); jmiSave
.addActionListener(this); jmiSave
.setAccelerator(KeyStroke
.getKeyStroke('S', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiSave
.setIcon(getEkitIcon("Save")); }; jMenuFile
.add(jmiSave
);
471 JMenuItem jmiSaveAs
= new JMenuItem(Translatrix
.getTranslationString("SaveAs") + menuDialog
); jmiSaveAs
.setActionCommand("saveas"); jmiSaveAs
.addActionListener(this); jMenuFile
.add(jmiSaveAs
);
472 JMenuItem jmiSaveBody
= new JMenuItem(Translatrix
.getTranslationString("SaveBody") + menuDialog
); jmiSaveBody
.setActionCommand("savebody"); jmiSaveBody
.addActionListener(this); jMenuFile
.add(jmiSaveBody
);
473 JMenuItem jmiSaveRTF
= new JMenuItem(Translatrix
.getTranslationString("SaveRTF") + menuDialog
); jmiSaveRTF
.setActionCommand("savertf"); jmiSaveRTF
.addActionListener(this); jMenuFile
.add(jmiSaveRTF
);
474 JMenuItem jmiSaveB64
= new JMenuItem(Translatrix
.getTranslationString("SaveB64") + menuDialog
); jmiSaveB64
.setActionCommand("saveb64"); jmiSaveB64
.addActionListener(this); jMenuFile
.add(jmiSaveB64
);
475 jMenuFile
.addSeparator();
476 JMenuItem jmiSerialOut
= new JMenuItem(Translatrix
.getTranslationString("Serialize") + menuDialog
); jmiSerialOut
.setActionCommand("serialize"); jmiSerialOut
.addActionListener(this); jMenuFile
.add(jmiSerialOut
);
477 JMenuItem jmiSerialIn
= new JMenuItem(Translatrix
.getTranslationString("ReadFromSer") + menuDialog
); jmiSerialIn
.setActionCommand("readfromser"); jmiSerialIn
.addActionListener(this); jMenuFile
.add(jmiSerialIn
);
478 jMenuFile
.addSeparator();
479 JMenuItem jmiExit
= new JMenuItem(Translatrix
.getTranslationString("Exit")); jmiExit
.setActionCommand("exit"); jmiExit
.addActionListener(this); jMenuFile
.add(jmiExit
);
482 jMenuEdit
= new JMenu(Translatrix
.getTranslationString("Edit"));
483 htMenus
.put(KEY_MENU_EDIT
, jMenuEdit
);
484 if(sysClipboard
!= null
)
486 // System Clipboard versions of menu commands
487 JMenuItem jmiCut
= new JMenuItem(Translatrix
.getTranslationString("Cut")); jmiCut
.setActionCommand("textcut"); jmiCut
.addActionListener(this); jmiCut
.setAccelerator(KeyStroke
.getKeyStroke('X', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiCut
.setIcon(getEkitIcon("Cut")); } jMenuEdit
.add(jmiCut
);
488 JMenuItem jmiCopy
= new JMenuItem(Translatrix
.getTranslationString("Copy")); jmiCopy
.setActionCommand("textcopy"); jmiCopy
.addActionListener(this); jmiCopy
.setAccelerator(KeyStroke
.getKeyStroke('C', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiCopy
.setIcon(getEkitIcon("Copy")); } jMenuEdit
.add(jmiCopy
);
489 JMenuItem jmiPaste
= new JMenuItem(Translatrix
.getTranslationString("Paste")); jmiPaste
.setActionCommand("textpaste"); jmiPaste
.addActionListener(this); jmiPaste
.setAccelerator(KeyStroke
.getKeyStroke('V', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiPaste
.setIcon(getEkitIcon("Paste")); } jMenuEdit
.add(jmiPaste
);
493 // DefaultEditorKit versions of menu commands
494 JMenuItem jmiCut
= new JMenuItem(new DefaultEditorKit
.CutAction()); jmiCut
.setText(Translatrix
.getTranslationString("Cut")); jmiCut
.setAccelerator(KeyStroke
.getKeyStroke('X', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiCut
.setIcon(getEkitIcon("Cut")); } jMenuEdit
.add(jmiCut
);
495 JMenuItem jmiCopy
= new JMenuItem(new DefaultEditorKit
.CopyAction()); jmiCopy
.setText(Translatrix
.getTranslationString("Copy")); jmiCopy
.setAccelerator(KeyStroke
.getKeyStroke('C', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiCopy
.setIcon(getEkitIcon("Copy")); } jMenuEdit
.add(jmiCopy
);
496 JMenuItem jmiPaste
= new JMenuItem(new DefaultEditorKit
.PasteAction()); jmiPaste
.setText(Translatrix
.getTranslationString("Paste")); jmiPaste
.setAccelerator(KeyStroke
.getKeyStroke('V', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiPaste
.setIcon(getEkitIcon("Paste")); } jMenuEdit
.add(jmiPaste
);
498 jMenuEdit
.addSeparator();
499 JMenuItem jmiUndo
= new JMenuItem(undoAction
); jmiUndo
.setAccelerator(KeyStroke
.getKeyStroke('Z', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuEdit
.add(jmiUndo
);
500 JMenuItem jmiRedo
= new JMenuItem(redoAction
); jmiRedo
.setAccelerator(KeyStroke
.getKeyStroke('Y', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuEdit
.add(jmiRedo
);
501 jMenuEdit
.addSeparator();
502 JMenuItem jmiSelAll
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectAllAction
)); jmiSelAll
.setText(Translatrix
.getTranslationString("SelectAll")); jmiSelAll
.setAccelerator(KeyStroke
.getKeyStroke('A', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuEdit
.add(jmiSelAll
);
503 JMenuItem jmiSelPara
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectParagraphAction
)); jmiSelPara
.setText(Translatrix
.getTranslationString("SelectParagraph")); jMenuEdit
.add(jmiSelPara
);
504 JMenuItem jmiSelLine
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectLineAction
)); jmiSelLine
.setText(Translatrix
.getTranslationString("SelectLine")); jMenuEdit
.add(jmiSelLine
);
505 JMenuItem jmiSelWord
= new JMenuItem((Action
)actions
.get(DefaultEditorKit
.selectWordAction
)); jmiSelWord
.setText(Translatrix
.getTranslationString("SelectWord")); jMenuEdit
.add(jmiSelWord
);
508 jMenuView
= new JMenu(Translatrix
.getTranslationString("View"));
509 htMenus
.put(KEY_MENU_VIEW
, jMenuView
);
510 jcbmiViewToolbar
= new JCheckBoxMenuItem(Translatrix
.getTranslationString("ViewToolbar"), false
); jcbmiViewToolbar
.setActionCommand("toggletoolbar"); jcbmiViewToolbar
.addActionListener(this); jMenuView
.add(jcbmiViewToolbar
);
511 jcbmiViewSource
= new JCheckBoxMenuItem(Translatrix
.getTranslationString("ViewSource"), false
); jcbmiViewSource
.setActionCommand("viewsource"); jcbmiViewSource
.addActionListener(this); jMenuView
.add(jcbmiViewSource
);
514 jMenuFont
= new JMenu(Translatrix
.getTranslationString("Font"));
515 htMenus
.put(KEY_MENU_FONT
, jMenuFont
);
516 JMenuItem jmiBold
= new JMenuItem(actionFontBold
); jmiBold
.setText(Translatrix
.getTranslationString("FontBold")); jmiBold
.setAccelerator(KeyStroke
.getKeyStroke('B', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiBold
.setIcon(getEkitIcon("Bold")); } jMenuFont
.add(jmiBold
);
517 JMenuItem jmiItalic
= new JMenuItem(actionFontItalic
); jmiItalic
.setText(Translatrix
.getTranslationString("FontItalic")); jmiItalic
.setAccelerator(KeyStroke
.getKeyStroke('I', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiItalic
.setIcon(getEkitIcon("Italic")); } jMenuFont
.add(jmiItalic
);
518 JMenuItem jmiUnderline
= new JMenuItem(actionFontUnderline
); jmiUnderline
.setText(Translatrix
.getTranslationString("FontUnderline")); jmiUnderline
.setAccelerator(KeyStroke
.getKeyStroke('U', java
.awt
.Event
.CTRL_MASK
, false
)); if(showMenuIcons
) { jmiUnderline
.setIcon(getEkitIcon("Underline")); } jMenuFont
.add(jmiUnderline
);
519 JMenuItem jmiStrike
= new JMenuItem(actionFontStrike
); jmiStrike
.setText(Translatrix
.getTranslationString("FontStrike")); if(showMenuIcons
) { jmiStrike
.setIcon(getEkitIcon("Strike")); } jMenuFont
.add(jmiStrike
);
520 jMenuFont
.addSeparator();
521 jMenuFont
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatBig"), HTML
.Tag
.BIG
)));
522 jMenuFont
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatSmall"), HTML
.Tag
.SMALL
)));
523 JMenu jMenuFontSize
= new JMenu(Translatrix
.getTranslationString("FontSize"));
524 String fontSizeKey
= "size";
525 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"1");
526 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize1"), HTML
.Tag
.FONT
, customAttr
)));
527 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"2");
528 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize2"), HTML
.Tag
.FONT
, customAttr
)));
529 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"3");
530 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize3"), HTML
.Tag
.FONT
, customAttr
)));
531 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"4");
532 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize4"), HTML
.Tag
.FONT
, customAttr
)));
533 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"5");
534 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize5"), HTML
.Tag
.FONT
, customAttr
)));
535 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"6");
536 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize6"), HTML
.Tag
.FONT
, customAttr
)));
537 customAttr
= new Hashtable(); customAttr
.put(fontSizeKey
,"7");
538 jMenuFontSize
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("FontSize7"), HTML
.Tag
.FONT
, customAttr
)));
539 jMenuFont
.add(jMenuFontSize
);
540 jMenuFont
.addSeparator();
541 JMenuItem jmiSupscript
= new JMenuItem(actionFontSuperscript
); if(showMenuIcons
) { jmiSupscript
.setIcon(getEkitIcon("Super")); } jMenuFont
.add(jmiSupscript
);
542 JMenuItem jmiSubscript
= new JMenuItem(actionFontSubscript
); if(showMenuIcons
) { jmiSubscript
.setIcon(getEkitIcon("Sub")); } jMenuFont
.add(jmiSubscript
);
543 jMenuFont
.addSeparator();
544 JMenuItem jmiSerif
= new JMenuItem((Action
)actions
.get("font-family-Serif")); jmiSerif
.setText(Translatrix
.getTranslationString("FontSerif")); jMenuFont
.add(jmiSerif
);
545 JMenuItem jmiSansSerif
= new JMenuItem((Action
)actions
.get("font-family-SansSerif")); jmiSansSerif
.setText(Translatrix
.getTranslationString("FontSansserif")); jMenuFont
.add(jmiSansSerif
);
546 JMenuItem jmiMonospaced
= new JMenuItem((Action
)actions
.get("font-family-Monospaced")); jmiMonospaced
.setText(Translatrix
.getTranslationString("FontMonospaced")); jMenuFont
.add(jmiMonospaced
);
547 JMenuItem jmiSelectFont
= new JMenuItem(actionSelectFont
); jMenuFont
.add(jmiSelectFont
);
548 jMenuFont
.addSeparator();
549 JMenu jMenuFontColor
= new JMenu(Translatrix
.getTranslationString("Color"));
550 customAttr
= new Hashtable(); customAttr
.put("color","black");
551 jMenuFontColor
.add(new JMenuItem(new CustomAction(this, Translatrix
.getTranslationString("CustomColor") + menuDialog
, HTML
.Tag
.FONT
, customAttr
)));
552 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorAqua"), new Color( 0,255,255))));
553 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorBlack"), new Color( 0, 0, 0))));
554 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorBlue"), new Color( 0, 0,255))));
555 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorFuschia"), new Color(255, 0,255))));
556 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorGray"), new Color(128,128,128))));
557 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorGreen"), new Color( 0,128, 0))));
558 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorLime"), new Color( 0,255, 0))));
559 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorMaroon"), new Color(128, 0, 0))));
560 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorNavy"), new Color( 0, 0,128))));
561 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorOlive"), new Color(128,128, 0))));
562 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorPurple"), new Color(128, 0,128))));
563 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorRed"), new Color(255, 0, 0))));
564 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorSilver"), new Color(192,192,192))));
565 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorTeal"), new Color( 0,128,128))));
566 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorWhite"), new Color(255,255,255))));
567 jMenuFontColor
.add(new JMenuItem(new StyledEditorKit
.ForegroundAction(Translatrix
.getTranslationString("ColorYellow"), new Color(255,255, 0))));
568 jMenuFont
.add(jMenuFontColor
);
571 jMenuFormat
= new JMenu(Translatrix
.getTranslationString("Format"));
572 htMenus
.put(KEY_MENU_FORMAT
, jMenuFormat
);
573 JMenu jMenuFormatAlign
= new JMenu(Translatrix
.getTranslationString("Align"));
574 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignLeft"), StyleConstants
.ALIGN_LEFT
)));
575 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignCenter"), StyleConstants
.ALIGN_CENTER
)));
576 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignRight"), StyleConstants
.ALIGN_RIGHT
)));
577 jMenuFormatAlign
.add(new JMenuItem(new StyledEditorKit
.AlignmentAction(Translatrix
.getTranslationString("AlignJustified"), StyleConstants
.ALIGN_JUSTIFIED
)));
578 jMenuFormat
.add(jMenuFormatAlign
);
579 jMenuFormat
.addSeparator();
580 JMenu jMenuFormatHeading
= new JMenu(Translatrix
.getTranslationString("Heading"));
581 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading1"), HTML
.Tag
.H1
)));
582 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading2"), HTML
.Tag
.H2
)));
583 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading3"), HTML
.Tag
.H3
)));
584 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading4"), HTML
.Tag
.H4
)));
585 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading5"), HTML
.Tag
.H5
)));
586 jMenuFormatHeading
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("Heading6"), HTML
.Tag
.H6
)));
587 jMenuFormat
.add(jMenuFormatHeading
);
588 jMenuFormat
.addSeparator();
589 JMenuItem jmiUList
= new JMenuItem(actionListUnordered
); if(showMenuIcons
) { jmiUList
.setIcon(getEkitIcon("UList")); } jMenuFormat
.add(jmiUList
);
590 JMenuItem jmiOList
= new JMenuItem(actionListOrdered
); if(showMenuIcons
) { jmiOList
.setIcon(getEkitIcon("OList")); } jMenuFormat
.add(jmiOList
);
591 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("ListItem"), HTML
.Tag
.LI
)));
592 jMenuFormat
.addSeparator();
593 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatBlockquote"), HTML
.Tag
.BLOCKQUOTE
)));
594 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatPre"), HTML
.Tag
.PRE
)));
595 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatStrong"), HTML
.Tag
.STRONG
)));
596 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatEmphasis"), HTML
.Tag
.EM
)));
597 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatTT"), HTML
.Tag
.TT
)));
598 jMenuFormat
.add(new JMenuItem(new FormatAction(this, Translatrix
.getTranslationString("FormatSpan"), HTML
.Tag
.SPAN
)));
599 jMenuFormat
.addSeparator();
600 JMenuItem jmiClearStyles
= new JMenuItem(actionClearFormat
); if(showMenuIcons
) { jmiClearStyles
.setIcon(getEkitIcon("ClearFormat")); }; jMenuFormat
.add(jmiClearStyles
);
603 jMenuInsert
= new JMenu(Translatrix
.getTranslationString("Insert"));
604 htMenus
.put(KEY_MENU_INSERT
, jMenuInsert
);
605 jMenuInsert
.add(new JMenuItem(actionInsertAnchor
));
606 JMenuItem jmiBreak
= new JMenuItem(Translatrix
.getTranslationString("InsertBreak")); jmiBreak
.setActionCommand("insertbreak"); jmiBreak
.addActionListener(this); jmiBreak
.setAccelerator(KeyStroke
.getKeyStroke(KeyEvent
.VK_ENTER
, java
.awt
.Event
.SHIFT_MASK
, false
)); jMenuInsert
.add(jmiBreak
);
607 JMenuItem jmiNBSP
= new JMenuItem(Translatrix
.getTranslationString("InsertNBSP")); jmiNBSP
.setActionCommand("insertnbsp"); jmiNBSP
.addActionListener(this); jMenuInsert
.add(jmiNBSP
);
608 JMenuItem jmiHRule
= new JMenuItem((Action
)actions
.get("InsertHR")); jmiHRule
.setText(Translatrix
.getTranslationString("InsertHorizontalRule")); jMenuInsert
.add(jmiHRule
);
609 jMenuInsert
.addSeparator();
610 JMenuItem jmiImageLocal
= new JMenuItem(Translatrix
.getTranslationString("InsertLocalImage") + menuDialog
); jmiImageLocal
.setActionCommand("insertlocalimage"); jmiImageLocal
.addActionListener(this); jMenuInsert
.add(jmiImageLocal
);
611 JMenuItem jmiImageServer
= new JMenuItem(Translatrix
.getTranslationString("InsertServerImage") + menuDialog
); jmiImageServer
.setActionCommand("insertserverimage"); jmiImageServer
.addActionListener(this); jMenuInsert
.add(jmiImageServer
);
614 jMenuTable
= new JMenu(Translatrix
.getTranslationString("Table"));
615 htMenus
.put(KEY_MENU_TABLE
, jMenuTable
);
616 JMenuItem jmiTable
= new JMenuItem(Translatrix
.getTranslationString("InsertTable") + menuDialog
); jmiTable
.setActionCommand("inserttable"); jmiTable
.addActionListener(this); jMenuTable
.add(jmiTable
);
617 jMenuTable
.addSeparator();
618 JMenuItem jmiTableRow
= new JMenuItem(Translatrix
.getTranslationString("InsertTableRow")); jmiTableRow
.setActionCommand("inserttablerow"); jmiTableRow
.addActionListener(this); jMenuTable
.add(jmiTableRow
);
619 JMenuItem jmiTableCol
= new JMenuItem(Translatrix
.getTranslationString("InsertTableColumn")); jmiTableCol
.setActionCommand("inserttablecolumn"); jmiTableCol
.addActionListener(this); jMenuTable
.add(jmiTableCol
);
620 jMenuTable
.addSeparator();
621 JMenuItem jmiTableRowDel
= new JMenuItem(Translatrix
.getTranslationString("DeleteTableRow")); jmiTableRowDel
.setActionCommand("deletetablerow"); jmiTableRowDel
.addActionListener(this); jMenuTable
.add(jmiTableRowDel
);
622 JMenuItem jmiTableColDel
= new JMenuItem(Translatrix
.getTranslationString("DeleteTableColumn")); jmiTableColDel
.setActionCommand("deletetablecolumn"); jmiTableColDel
.addActionListener(this); jMenuTable
.add(jmiTableColDel
);
625 jMenuForms
= new JMenu(Translatrix
.getTranslationString("Forms"));
626 htMenus
.put(KEY_MENU_FORMS
, jMenuForms
);
627 JMenuItem jmiFormInsertForm
= new JMenuItem(Translatrix
.getTranslationString("FormInsertForm")); jmiFormInsertForm
.setActionCommand("insertform"); jmiFormInsertForm
.addActionListener(this); jMenuForms
.add(jmiFormInsertForm
);
628 jMenuForms
.addSeparator();
629 JMenuItem jmiFormTextfield
= new JMenuItem(Translatrix
.getTranslationString("FormTextfield")); jmiFormTextfield
.setActionCommand("inserttextfield"); jmiFormTextfield
.addActionListener(this); jMenuForms
.add(jmiFormTextfield
);
630 JMenuItem jmiFormTextarea
= new JMenuItem(Translatrix
.getTranslationString("FormTextarea")); jmiFormTextarea
.setActionCommand("inserttextarea"); jmiFormTextarea
.addActionListener(this); jMenuForms
.add(jmiFormTextarea
);
631 JMenuItem jmiFormCheckbox
= new JMenuItem(Translatrix
.getTranslationString("FormCheckbox")); jmiFormCheckbox
.setActionCommand("insertcheckbox"); jmiFormCheckbox
.addActionListener(this); jMenuForms
.add(jmiFormCheckbox
);
632 JMenuItem jmiFormRadio
= new JMenuItem(Translatrix
.getTranslationString("FormRadio")); jmiFormRadio
.setActionCommand("insertradiobutton"); jmiFormRadio
.addActionListener(this); jMenuForms
.add(jmiFormRadio
);
633 JMenuItem jmiFormPassword
= new JMenuItem(Translatrix
.getTranslationString("FormPassword")); jmiFormPassword
.setActionCommand("insertpassword"); jmiFormPassword
.addActionListener(this); jMenuForms
.add(jmiFormPassword
);
634 jMenuForms
.addSeparator();
635 JMenuItem jmiFormButton
= new JMenuItem(Translatrix
.getTranslationString("FormButton")); jmiFormButton
.setActionCommand("insertbutton"); jmiFormButton
.addActionListener(this); jMenuForms
.add(jmiFormButton
);
636 JMenuItem jmiFormButtonSubmit
= new JMenuItem(Translatrix
.getTranslationString("FormButtonSubmit")); jmiFormButtonSubmit
.setActionCommand("insertbuttonsubmit"); jmiFormButtonSubmit
.addActionListener(this); jMenuForms
.add(jmiFormButtonSubmit
);
637 JMenuItem jmiFormButtonReset
= new JMenuItem(Translatrix
.getTranslationString("FormButtonReset")); jmiFormButtonReset
.setActionCommand("insertbuttonreset"); jmiFormButtonReset
.addActionListener(this); jMenuForms
.add(jmiFormButtonReset
);
640 jMenuSearch
= new JMenu(Translatrix
.getTranslationString("Search"));
641 htMenus
.put(KEY_MENU_SEARCH
, jMenuSearch
);
642 JMenuItem jmiFind
= new JMenuItem(Translatrix
.getTranslationString("SearchFind")); jmiFind
.setActionCommand("find"); jmiFind
.addActionListener(this); jmiFind
.setAccelerator(KeyStroke
.getKeyStroke('F', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuSearch
.add(jmiFind
);
643 JMenuItem jmiFindAgain
= new JMenuItem(Translatrix
.getTranslationString("SearchFindAgain")); jmiFindAgain
.setActionCommand("findagain"); jmiFindAgain
.addActionListener(this); jmiFindAgain
.setAccelerator(KeyStroke
.getKeyStroke('G', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuSearch
.add(jmiFindAgain
);
644 JMenuItem jmiReplace
= new JMenuItem(Translatrix
.getTranslationString("SearchReplace")); jmiReplace
.setActionCommand("replace"); jmiReplace
.addActionListener(this); jmiReplace
.setAccelerator(KeyStroke
.getKeyStroke('R', java
.awt
.Event
.CTRL_MASK
, false
)); jMenuSearch
.add(jmiReplace
);
647 jMenuHelp
= new JMenu(Translatrix
.getTranslationString("Help"));
648 htMenus
.put(KEY_MENU_HELP
, jMenuHelp
);
649 JMenuItem jmiAbout
= new JMenuItem(Translatrix
.getTranslationString("About")); jmiAbout
.setActionCommand("helpabout"); jmiAbout
.addActionListener(this); jMenuHelp
.add(jmiAbout
);
652 jMenuDebug
= new JMenu(Translatrix
.getTranslationString("Debug"));
653 htMenus
.put(KEY_MENU_DEBUG
, jMenuDebug
);
654 JMenuItem jmiDesc
= new JMenuItem(Translatrix
.getTranslationString("DescribeDoc")); jmiDesc
.setActionCommand("describe"); jmiDesc
.addActionListener(this); jMenuDebug
.add(jmiDesc
);
655 JMenuItem jmiDescCSS
= new JMenuItem(Translatrix
.getTranslationString("DescribeCSS")); jmiDescCSS
.setActionCommand("describecss"); jmiDescCSS
.addActionListener(this); jMenuDebug
.add(jmiDescCSS
);
656 JMenuItem jmiTag
= new JMenuItem(Translatrix
.getTranslationString("WhatTags")); jmiTag
.setActionCommand("whattags"); jmiTag
.addActionListener(this); jMenuDebug
.add(jmiTag
);
658 /* Create menubar and add menus */
659 jMenuBar
= new JMenuBar();
660 jMenuBar
.add(jMenuFile
);
661 jMenuBar
.add(jMenuEdit
);
662 jMenuBar
.add(jMenuView
);
663 jMenuBar
.add(jMenuFont
);
664 jMenuBar
.add(jMenuFormat
);
665 jMenuBar
.add(jMenuSearch
);
666 jMenuBar
.add(jMenuInsert
);
667 jMenuBar
.add(jMenuTable
);
668 jMenuBar
.add(jMenuForms
);
669 jMenuBar
.add(jMenuHelp
);
672 jMenuBar
.add(jMenuDebug
);
675 /* Create the toolbar */
676 jToolBar
= new JToolBar(JToolBar
.HORIZONTAL
);
677 jToolBar
.setFloatable(false
);
678 jbtnNewHTML
= new JButtonNoFocus(getEkitIcon("New")); jbtnNewHTML
.setToolTipText(Translatrix
.getTranslationString("NewDocument")); jbtnNewHTML
.setActionCommand("newdoc"); jbtnNewHTML
.addActionListener(this); jToolBar
.add(jbtnNewHTML
); htTools
.put(KEY_TOOL_NEW
, jbtnNewHTML
);
679 jbtnOpenHTML
= new JButtonNoFocus(getEkitIcon("Open")); jbtnOpenHTML
.setToolTipText(Translatrix
.getTranslationString("OpenDocument")); jbtnOpenHTML
.setActionCommand("openhtml"); jbtnOpenHTML
.addActionListener(this); jToolBar
.add(jbtnOpenHTML
); htTools
.put(KEY_TOOL_OPEN
, jbtnOpenHTML
);
680 jbtnSaveHTML
= new JButtonNoFocus(getEkitIcon("Save")); jbtnSaveHTML
.setToolTipText(Translatrix
.getTranslationString("SaveDocument")); jbtnSaveHTML
.setActionCommand("saveas"); jbtnSaveHTML
.addActionListener(this); jToolBar
.add(jbtnSaveHTML
); htTools
.put(KEY_TOOL_SAVE
, jbtnSaveHTML
);
681 jToolBar
.add(new JToolBar
.Separator());
682 jbtnCut
= new JButtonNoFocus(new DefaultEditorKit
.CutAction()); jbtnCut
.setIcon(getEkitIcon("Cut")); jbtnCut
.setText(null
); jbtnCut
.setToolTipText(Translatrix
.getTranslationString("Cut")); jToolBar
.add(jbtnCut
); htTools
.put(KEY_TOOL_CUT
, jbtnCut
);
683 jbtnCopy
= new JButtonNoFocus(new DefaultEditorKit
.CopyAction()); jbtnCopy
.setIcon(getEkitIcon("Copy")); jbtnCopy
.setText(null
); jbtnCopy
.setToolTipText(Translatrix
.getTranslationString("Copy")); jToolBar
.add(jbtnCopy
); htTools
.put(KEY_TOOL_COPY
, jbtnCopy
);
684 jbtnPaste
= new JButtonNoFocus(new DefaultEditorKit
.PasteAction()); jbtnPaste
.setIcon(getEkitIcon("Paste")); jbtnPaste
.setText(null
); jbtnPaste
.setToolTipText(Translatrix
.getTranslationString("Paste")); jToolBar
.add(jbtnPaste
); htTools
.put(KEY_TOOL_PASTE
, jbtnPaste
);
685 jToolBar
.add(new JToolBar
.Separator());
686 jbtnBold
= new JButtonNoFocus(actionFontBold
); jbtnBold
.setIcon(getEkitIcon("Bold")); jbtnBold
.setText(null
); jbtnBold
.setToolTipText(Translatrix
.getTranslationString("FontBold")); jToolBar
.add(jbtnBold
); htTools
.put(KEY_TOOL_BOLD
, jbtnBold
);
687 jbtnItalic
= new JButtonNoFocus(actionFontItalic
); jbtnItalic
.setIcon(getEkitIcon("Italic")); jbtnItalic
.setText(null
); jbtnItalic
.setToolTipText(Translatrix
.getTranslationString("FontItalic")); jToolBar
.add(jbtnItalic
); htTools
.put(KEY_TOOL_ITALIC
, jbtnItalic
);
688 jbtnUnderline
= new JButtonNoFocus(actionFontUnderline
); jbtnUnderline
.setIcon(getEkitIcon("Underline")); jbtnUnderline
.setText(null
); jbtnUnderline
.setToolTipText(Translatrix
.getTranslationString("FontUnderline")); jToolBar
.add(jbtnUnderline
); htTools
.put(KEY_TOOL_UNDERLINE
, jbtnUnderline
);
689 jbtnStrike
= new JButtonNoFocus(actionFontStrike
); jbtnStrike
.setIcon(getEkitIcon("Strike")); jbtnStrike
.setText(null
); jbtnStrike
.setToolTipText(Translatrix
.getTranslationString("FontStrike")); jToolBar
.add(jbtnStrike
); htTools
.put(KEY_TOOL_STRIKE
, jbtnStrike
);
690 jbtnSuperscript
= new JButtonNoFocus(actionFontSuperscript
); jbtnSuperscript
.setIcon(getEkitIcon("Super")); jbtnSuperscript
.setText(null
); jbtnSuperscript
.setToolTipText(Translatrix
.getTranslationString("FontSuperscript")); jToolBar
.add(jbtnSuperscript
); htTools
.put(KEY_TOOL_SUPER
, jbtnSuperscript
);
691 jbtnSubscript
= new JButtonNoFocus(actionFontSubscript
); jbtnSubscript
.setIcon(getEkitIcon("Sub")); jbtnSubscript
.setText(null
); jbtnSubscript
.setToolTipText(Translatrix
.getTranslationString("FontSubscript")); jToolBar
.add(jbtnSubscript
); htTools
.put(KEY_TOOL_SUB
, jbtnSubscript
);
692 jbtnUList
= new JButtonNoFocus(actionListUnordered
); jbtnUList
.setIcon(getEkitIcon("UList")); jbtnUList
.setText(null
); jbtnUList
.setToolTipText(Translatrix
.getTranslationString("ListUnordered")); jToolBar
.add(jbtnUList
); htTools
.put(KEY_TOOL_ULIST
, jbtnUList
);
693 jbtnOList
= new JButtonNoFocus(actionListOrdered
); jbtnOList
.setIcon(getEkitIcon("OList")); jbtnOList
.setText(null
); jbtnOList
.setToolTipText(Translatrix
.getTranslationString("ListOrdered")); jToolBar
.add(jbtnOList
); htTools
.put(KEY_TOOL_OLIST
, jbtnOList
);
694 jbtnClearFormat
= new JButtonNoFocus(actionClearFormat
); jbtnClearFormat
.setIcon(getEkitIcon("ClearFormat")); jbtnClearFormat
.setText(null
); jbtnClearFormat
.setToolTipText(Translatrix
.getTranslationString("FormatClear")); jToolBar
.add(jbtnClearFormat
); htTools
.put(KEY_TOOL_CLEAR
, jbtnClearFormat
);
695 jToolBar
.add(new JToolBar
.Separator());
696 jbtnAnchor
= new JButtonNoFocus(actionInsertAnchor
); jbtnAnchor
.setIcon(getEkitIcon("Anchor")); jbtnAnchor
.setText(null
); jbtnAnchor
.setToolTipText(Translatrix
.getTranslationString("ToolAnchor")); jToolBar
.add(jbtnAnchor
); htTools
.put(KEY_TOOL_ANCHOR
, jbtnAnchor
);
697 jToolBar
.add(new JToolBar
.Separator());
698 jtbtnViewSource
= new JToggleButtonNoFocus(getEkitIcon("Source")); jtbtnViewSource
.setText(null
); jtbtnViewSource
.setToolTipText(Translatrix
.getTranslationString("ViewSource")); jtbtnViewSource
.setActionCommand("viewsource"); jtbtnViewSource
.addActionListener(this); jtbtnViewSource
.setPreferredSize(jbtnAnchor
.getPreferredSize()); jtbtnViewSource
.setMinimumSize(jbtnAnchor
.getMinimumSize()); jtbtnViewSource
.setMaximumSize(jbtnAnchor
.getMaximumSize()); jToolBar
.add(jtbtnViewSource
); htTools
.put(KEY_TOOL_SOURCE
, jtbtnViewSource
);
699 jToolBar
.add(new JToolBar
.Separator());
700 jcmbStyleSelector
= new JComboBoxNoFocus(); jToolBar
.add(jcmbStyleSelector
); jcmbStyleSelector
.setAction(new StylesAction(jcmbStyleSelector
)); htTools
.put(KEY_TOOL_STYLES
, jcmbStyleSelector
);
702 /* Create the scroll area for the text pane */
703 JScrollPane jspViewport
= new JScrollPane(jtpMain
);
704 jspViewport
.setVerticalScrollBarPolicy(JScrollPane
.VERTICAL_SCROLLBAR_ALWAYS
);
705 jspViewport
.setPreferredSize(new Dimension(400, 400));
706 jspViewport
.setMinimumSize(new Dimension(32, 32));
708 /* Create the scroll area for the source viewer */
709 jspSource
= new JScrollPane(jtpSource
);
710 jspSource
.setPreferredSize(new Dimension(400, 100));
711 jspSource
.setMinimumSize(new Dimension(32, 32));
713 jspltDisplay
= new JSplitPane(JSplitPane
.VERTICAL_SPLIT
);
714 jspltDisplay
.setTopComponent(jspViewport
);
717 jspltDisplay
.setBottomComponent(jspSource
);
721 jspltDisplay
.setBottomComponent(null
);
724 iSplitPos
= jspltDisplay
.getDividerLocation();
726 registerDocumentStyles();
728 /* Add the components to the app */
729 this.setLayout(new BorderLayout());
730 this.add(jspltDisplay
, BorderLayout
.CENTER
);
733 /** Common Constructor
734 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
735 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
736 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
737 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
738 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
739 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
740 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
742 public EkitCore(String sDocument
, String sStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
744 this(sDocument
, sStyleSheet
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
747 /** Default Language Constructor
748 * @param sDocument [String] A text or HTML document to load in the editor upon startup.
749 * @param sStyleSheet [String] A CSS stylesheet to load in the editor upon startup.
750 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
751 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
752 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
754 public EkitCore(String sDocument
, String sStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, boolean base64
)
756 this(sDocument
, sStyleSheet
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, base64
, false
);
759 /** Raw/Base64 Document & Style Sheet URL Constructor (Ideal for EkitApplet)
760 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
761 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
762 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
763 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
764 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
765 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
766 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
768 public EkitCore(String sRawDocument
, URL urlStyleSheet
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
770 this(null
, null
, sRawDocument
, urlStyleSheet
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
773 /** Document Constructor
774 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
775 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
776 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
777 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
778 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
779 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
781 public EkitCore(String sRawDocument
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
, boolean base64
)
783 this(null
, null
, sRawDocument
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, base64
, false
);
786 /** Default Language & Document Constructor
787 * @param sRawDocument [String] A document encoded as a String to load in the editor upon startup.
788 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
789 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
790 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
792 public EkitCore(String sRawDocument
, boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, boolean base64
)
794 this(null
, null
, sRawDocument
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, base64
, false
);
797 /** Flags & Language Constructor
798 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
799 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
800 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
801 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
802 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
804 public EkitCore(boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
, String sLanguage
, String sCountry
)
806 this(null
, null
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, sLanguage
, sCountry
, false
, false
);
809 /** Flags Constructor
810 * @param showViewSource [boolean] Specifies whether or not to show the View Source window on startup.
811 * @param showMenuIcons [boolean] Specifies whether or not to show icon pictures in menus.
812 * @param editModeExclusive [boolean] Specifies whether or not to use exclusive edit mode (recommended on).
814 public EkitCore(boolean showViewSource
, boolean showMenuIcons
, boolean editModeExclusive
)
816 this(null
, null
, null
, null
, showViewSource
, showMenuIcons
, editModeExclusive
, null
, null
, false
, false
);
819 /** Language & Debug Constructor
820 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
821 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
822 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
824 public EkitCore(String sLanguage
, String sCountry
, boolean debugMode
)
826 this(null
, null
, null
, null
, false
, true
, true
, sLanguage
, sCountry
, false
, debugMode
);
829 /** Language Constructor
830 * @param sLanguage [String] The language portion of the Internationalization Locale to run Ekit in.
831 * @param sCountry [String] The country portion of the Internationalization Locale to run Ekit in.
833 public EkitCore(String sLanguage
, String sCountry
)
835 this(null
, null
, null
, null
, false
, true
, true
, sLanguage
, sCountry
, false
, false
);
838 /** Debug Constructor
839 * @param debugMode [boolean] Specifies whether to show the Debug menu or not.
841 public EkitCore(boolean debugMode
)
843 this(null
, null
, null
, null
, false
, true
, true
, null
, null
, false
, debugMode
);
846 /** Empty Constructor
850 this(null
, null
, null
, null
, false
, true
, true
, null
, null
, false
, false
);
853 /* ActionListener method */
854 public void actionPerformed(ActionEvent ae
)
858 String command
= ae
.getActionCommand();
859 if(command
.equals("newdoc"))
861 SimpleInfoDialog sidAsk
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("AskNewDocument"), SimpleInfoDialog
.QUESTION
);
862 String decision
= sidAsk
.getDecisionValue();
863 if(decision
.equals(Translatrix
.getTranslationString("DialogAccept")))
865 if(styleSheet
!= null
)
867 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
871 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
873 jtpMain
.setText("<HTML><BODY></BODY></HTML>");
874 jtpSource
.setText(jtpMain
.getText());
875 registerDocument(htmlDoc
);
880 else if(command
.equals("openhtml"))
884 else if(command
.equals("opencss"))
886 openStyleSheet(null
);
888 else if(command
.equals("openb64"))
890 openDocumentBase64(null
);
892 else if(command
.equals("save"))
894 writeOut((HTMLDocument
)(jtpMain
.getDocument()), currentFile
);
897 else if(command
.equals("saveas"))
899 writeOut((HTMLDocument
)(jtpMain
.getDocument()), null
);
901 else if(command
.equals("savebody"))
903 writeOutFragment((HTMLDocument
)(jtpMain
.getDocument()),"body");
905 else if(command
.equals("savertf"))
907 writeOutRTF((StyledDocument
)(jtpMain
.getStyledDocument()));
909 else if(command
.equals("saveb64"))
911 writeOutBase64(jtpSource
.getText());
913 else if(command
.equals("textcut"))
915 if(jspSource
.isShowing() && jtpSource
.hasFocus())
924 else if(command
.equals("textcopy"))
926 if(jspSource
.isShowing() && jtpSource
.hasFocus())
935 else if(command
.equals("textpaste"))
937 if(jspSource
.isShowing() && jtpSource
.hasFocus())
946 else if(command
.equals("describe"))
948 System
.out
.println("------------DOCUMENT------------");
949 System
.out
.println("Content Type : " + jtpMain
.getContentType());
950 System
.out
.println("Editor Kit : " + jtpMain
.getEditorKit());
951 System
.out
.println("Doc Tree :");
952 System
.out
.println("");
953 describeDocument(jtpMain
.getStyledDocument());
954 System
.out
.println("--------------------------------");
955 System
.out
.println("");
957 else if(command
.equals("describecss"))
959 System
.out
.println("-----------STYLESHEET-----------");
960 System
.out
.println("Stylesheet Rules");
961 Enumeration rules
= styleSheet
.getStyleNames();
962 while(rules
.hasMoreElements())
964 String ruleName
= (String
)(rules
.nextElement());
965 Style styleRule
= styleSheet
.getStyle(ruleName
);
966 System
.out
.println(styleRule
.toString());
968 System
.out
.println("--------------------------------");
969 System
.out
.println("");
971 else if(command
.equals("whattags"))
973 System
.out
.println("Caret Position : " + jtpMain
.getCaretPosition());
974 AttributeSet attribSet
= jtpMain
.getCharacterAttributes();
975 Enumeration attribs
= attribSet
.getAttributeNames();
976 System
.out
.println("Attributes : ");
977 while(attribs
.hasMoreElements())
979 String attribName
= attribs
.nextElement().toString();
980 System
.out
.println(" " + attribName
+ " | " + attribSet
.getAttribute(attribName
));
983 else if(command
.equals("toggletoolbar"))
985 jToolBar
.setVisible(jcbmiViewToolbar
.isSelected());
987 else if(command
.equals("viewsource"))
989 toggleSourceWindow();
991 else if(command
.equals("serialize"))
993 serializeOut((HTMLDocument
)(jtpMain
.getDocument()));
995 else if(command
.equals("readfromser"))
999 else if(command
.equals("inserttable"))
1001 String
[] fieldNames
= { "rows", "cols", "border", "cellspacing", "cellpadding", "width" };
1002 String
[] fieldTypes
= { "text", "text", "text", "text", "text", "text" };
1003 insertTable((Hashtable
)null
, fieldNames
, fieldTypes
);
1005 else if(command
.equals("inserttablerow"))
1009 else if(command
.equals("inserttablecolumn"))
1011 insertTableColumn();
1013 else if(command
.equals("deletetablerow"))
1017 else if(command
.equals("deletetablecolumn"))
1019 deleteTableColumn();
1021 else if(command
.equals("insertbreak"))
1025 else if(command
.equals("insertlocalimage"))
1027 insertLocalImage(null
);
1029 else if(command
.equals("insertserverimage"))
1031 insertServerImage();
1033 else if(command
.equals("insertnbsp"))
1035 insertNonbreakingSpace();
1037 else if(command
.equals("insertform"))
1039 String
[] fieldNames
= { "name", "method", "enctype" };
1040 String
[] fieldTypes
= { "text", "combo", "text" };
1041 String
[] fieldValues
= { "", "POST,GET", "text" };
1042 insertFormElement(HTML
.Tag
.FORM
, "form", (Hashtable
)null
, fieldNames
, fieldTypes
, fieldValues
, true
);
1044 else if(command
.equals("inserttextfield"))
1046 Hashtable htAttribs
= new Hashtable();
1047 htAttribs
.put("type", "text");
1048 String
[] fieldNames
= { "name", "value", "size", "maxlength" };
1049 String
[] fieldTypes
= { "text", "text", "text", "text" };
1050 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1052 else if(command
.equals("inserttextarea"))
1054 String
[] fieldNames
= { "name", "rows", "cols" };
1055 String
[] fieldTypes
= { "text", "text", "text" };
1056 insertFormElement(HTML
.Tag
.TEXTAREA
, "textarea", (Hashtable
)null
, fieldNames
, fieldTypes
, true
);
1058 else if(command
.equals("insertcheckbox"))
1060 Hashtable htAttribs
= new Hashtable();
1061 htAttribs
.put("type", "checkbox");
1062 String
[] fieldNames
= { "name", "checked" };
1063 String
[] fieldTypes
= { "text", "bool" };
1064 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1066 else if(command
.equals("insertradiobutton"))
1068 Hashtable htAttribs
= new Hashtable();
1069 htAttribs
.put("type", "radio");
1070 String
[] fieldNames
= { "name", "checked" };
1071 String
[] fieldTypes
= { "text", "bool" };
1072 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1074 else if(command
.equals("insertpassword"))
1076 Hashtable htAttribs
= new Hashtable();
1077 htAttribs
.put("type", "password");
1078 String
[] fieldNames
= { "name", "value", "size", "maxlength" };
1079 String
[] fieldTypes
= { "text", "text", "text", "text" };
1080 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1082 else if(command
.equals("insertbutton"))
1084 Hashtable htAttribs
= new Hashtable();
1085 htAttribs
.put("type", "button");
1086 String
[] fieldNames
= { "name", "value" };
1087 String
[] fieldTypes
= { "text", "text" };
1088 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1090 else if(command
.equals("insertbuttonsubmit"))
1092 Hashtable htAttribs
= new Hashtable();
1093 htAttribs
.put("type", "submit");
1094 String
[] fieldNames
= { "name", "value" };
1095 String
[] fieldTypes
= { "text", "text" };
1096 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1098 else if(command
.equals("insertbuttonreset"))
1100 Hashtable htAttribs
= new Hashtable();
1101 htAttribs
.put("type", "reset");
1102 String
[] fieldNames
= { "name", "value" };
1103 String
[] fieldTypes
= { "text", "text" };
1104 insertFormElement(HTML
.Tag
.INPUT
, "input", htAttribs
, fieldNames
, fieldTypes
, false
);
1106 else if(command
.equals("find"))
1108 doSearch((String
)null
, (String
)null
, false
, lastSearchCaseSetting
, lastSearchTopSetting
);
1110 else if(command
.equals("findagain"))
1112 doSearch(lastSearchFindTerm
, (String
)null
, false
, lastSearchCaseSetting
, false
);
1114 else if(command
.equals("replace"))
1116 doSearch((String
)null
, (String
)null
, true
, lastSearchCaseSetting
, lastSearchTopSetting
);
1118 else if(command
.equals("exit"))
1122 else if(command
.equals("helpabout"))
1124 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("About"), true
, Translatrix
.getTranslationString("AboutMessage"), SimpleInfoDialog
.INFO
);
1127 catch(IOException ioe
)
1129 logException("IOException in actionPerformed method", ioe
);
1130 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1132 catch(BadLocationException ble
)
1134 logException("BadLocationException in actionPerformed method", ble
);
1135 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1137 catch(NumberFormatException nfe
)
1139 logException("NumberFormatException in actionPerformed method", nfe
);
1140 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorNumberFormatException"), SimpleInfoDialog
.ERROR
);
1142 catch(ClassNotFoundException cnfe
)
1144 logException("ClassNotFound Exception in actionPerformed method", cnfe
);
1145 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorClassNotFoundException "), SimpleInfoDialog
.ERROR
);
1147 catch(RuntimeException re
)
1149 logException("RuntimeException in actionPerformed method", re
);
1150 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorRuntimeException"), SimpleInfoDialog
.ERROR
);
1154 /* KeyListener methods */
1155 public void keyTyped(KeyEvent ke
)
1158 String selectedText
;
1159 int pos
= this.getCaretPosition();
1161 if(ke
.getKeyChar() == KeyEvent
.VK_BACK_SPACE
)
1167 if((selectedText
= jtpMain
.getSelectedText()) != null
)
1169 htmlUtilities
.delete();
1174 int sOffset
= htmlDoc
.getParagraphElement(pos
).getStartOffset();
1175 if(sOffset
== jtpMain
.getSelectionStart())
1177 boolean content
= true
;
1178 if(htmlUtilities
.checkParentsTag(HTML
.Tag
.LI
))
1180 elem
= htmlUtilities
.getListItemParent();
1182 int so
= elem
.getStartOffset();
1183 int eo
= elem
.getEndOffset();
1186 char[] temp
= jtpMain
.getText(so
, eo
- so
).toCharArray();
1187 for(int i
=0; i
< temp
.length
; i
++)
1189 if(!(new Character(temp
[i
])).isWhitespace(temp
[i
]))
1197 Element listElement
= elem
.getParentElement();
1198 htmlUtilities
.removeTag(elem
, true
);
1199 this.setCaretPosition(sOffset
- 1);
1204 jtpMain
.setCaretPosition(jtpMain
.getCaretPosition() - 1);
1205 jtpMain
.moveCaretPosition(jtpMain
.getCaretPosition() - 2);
1206 jtpMain
.replaceSelection("");
1210 else if(htmlUtilities
.checkParentsTag(HTML
.Tag
.TABLE
))
1212 jtpMain
.setCaretPosition(jtpMain
.getCaretPosition() - 1);
1217 jtpMain
.replaceSelection("");
1222 catch (BadLocationException ble
)
1224 logException("BadLocationException in keyTyped method", ble
);
1225 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1227 catch (IOException ioe
)
1229 logException("IOException in keyTyped method", ioe
);
1230 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1233 else if(ke
.getKeyChar() == KeyEvent
.VK_ENTER
)
1237 if(htmlUtilities
.checkParentsTag(HTML
.Tag
.UL
) == true
| htmlUtilities
.checkParentsTag(HTML
.Tag
.OL
) == true
)
1239 elem
= htmlUtilities
.getListItemParent();
1240 int so
= elem
.getStartOffset();
1241 int eo
= elem
.getEndOffset();
1242 char[] temp
= this.getTextPane().getText(so
,eo
-so
).toCharArray();
1243 boolean content
= false
;
1244 for(int i
=0;i
<temp
.length
;i
++)
1246 if(!(new Character(temp
[i
])).isWhitespace(temp
[i
]))
1254 int j
= temp
.length
;
1258 if(new Character(temp
[j
]).isLetterOrDigit(temp
[j
]))
1262 } while (end
== -1 && j
>= 0);
1267 if(!new Character(temp
[j
]).isSpaceChar(temp
[j
]))
1271 } while (repos
== -1 && j
< temp
.length
);
1277 if(elem
.getStartOffset() == elem
.getEndOffset() || !content
)
1279 manageListElement(elem
);
1283 if(this.getCaretPosition() + 1 == elem
.getEndOffset())
1285 insertListStyle(elem
);
1286 this.setCaretPosition(pos
- repos
);
1290 int caret
= this.getCaretPosition();
1291 String tempString
= this.getTextPane().getText(caret
, eo
- caret
);
1292 this.getTextPane().select(caret
, eo
- 1);
1293 this.getTextPane().replaceSelection("");
1294 htmlUtilities
.insertListElement(tempString
);
1295 Element newLi
= htmlUtilities
.getListItemParent();
1296 this.setCaretPosition(newLi
.getEndOffset() - 1);
1301 catch (BadLocationException ble
)
1303 logException("BadLocationException in keyTyped method", ble
);
1304 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1306 catch (IOException ioe
)
1308 logException("IOException in keyTyped method", ioe
);
1309 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorIOException"), SimpleInfoDialog
.ERROR
);
1313 public void keyPressed(KeyEvent e
) {}
1314 public void keyReleased(KeyEvent e
) {}
1316 public void insertListStyle(Element element
)
1317 throws BadLocationException
,IOException
1319 if(element
.getParentElement().getName() == "ol")
1321 actionListOrdered
.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1325 actionListUnordered
.actionPerformed(new ActionEvent(new Object(), 0, "newListPoint"));
1329 /* DocumentListener methods */
1330 public void changedUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1331 public void insertUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1332 public void removeUpdate(DocumentEvent de
) { handleDocumentChange(de
); }
1333 public void handleDocumentChange(DocumentEvent de
)
1337 if(jspSource
.isShowing())
1339 if(de
.getDocument() instanceof HTMLDocument
|| de
.getDocument() instanceof ExtendedHTMLDocument
)
1341 jtpSource
.getDocument().removeDocumentListener(this);
1342 jtpSource
.setText(jtpMain
.getText());
1343 jtpSource
.getDocument().addDocumentListener(this);
1345 else if(de
.getDocument() instanceof PlainDocument
|| de
.getDocument() instanceof DefaultStyledDocument
)
1347 jtpMain
.getDocument().removeDocumentListener(this);
1348 jtpMain
.setText(jtpSource
.getText());
1349 jtpMain
.getDocument().addDocumentListener(this);
1355 /** Method for setting a document as the current document for the text pane
1356 * and re-registering the controls and settings for it
1358 public void registerDocument(ExtendedHTMLDocument htmlDoc
)
1360 jtpMain
.setDocument(htmlDoc
);
1361 jtpMain
.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
1362 jtpMain
.getDocument().addDocumentListener(this);
1364 registerDocumentStyles();
1367 /** Method for locating the available CSS style for the document and adding
1368 * them to the styles selector
1370 public void registerDocumentStyles()
1372 if(jcmbStyleSelector
== null
|| htmlDoc
== null
)
1376 jcmbStyleSelector
.setEnabled(false
);
1377 jcmbStyleSelector
.removeAllItems();
1378 jcmbStyleSelector
.addItem(Translatrix
.getTranslationString("NoCSSStyle"));
1379 for(Enumeration e
= htmlDoc
.getStyleNames(); e
.hasMoreElements();)
1381 String name
= (String
) e
.nextElement();
1382 if(name
.length() > 0 && name
.charAt(0) == '.')
1384 jcmbStyleSelector
.addItem(name
.substring(1));
1387 jcmbStyleSelector
.setEnabled(true
);
1390 /** Method for inserting an HTML Table
1392 private void insertTable(Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
)
1393 throws IOException
, BadLocationException
, RuntimeException
, NumberFormatException
1395 int caretPos
= jtpMain
.getCaretPosition();
1396 StringBuffer compositeElement
= new StringBuffer("<TABLE");
1397 if(attribs
!= null
&& attribs
.size() > 0)
1399 Enumeration attribEntries
= attribs
.keys();
1400 while(attribEntries
.hasMoreElements())
1402 Object entryKey
= attribEntries
.nextElement();
1403 Object entryValue
= attribs
.get(entryKey
);
1404 if(entryValue
!= null
&& entryValue
!= "")
1406 compositeElement
.append(" " + entryKey
+ "=" + '"' + entryValue
+ '"');
1412 if(fieldNames
!= null
&& fieldNames
.length
> 0)
1414 PropertiesDialog propertiesDialog
= new PropertiesDialog(this.getFrame(), fieldNames
, fieldTypes
, Translatrix
.getTranslationString("FormDialogTitle"), true
);
1415 propertiesDialog
.show();
1416 String decision
= propertiesDialog
.getDecisionValue();
1417 if(decision
.equals(Translatrix
.getTranslationString("DialogCancel")))
1419 propertiesDialog
.dispose();
1420 propertiesDialog
= null
;
1425 for(int iter
= 0; iter
< fieldNames
.length
; iter
++)
1427 String fieldName
= fieldNames
[iter
];
1428 String propValue
= propertiesDialog
.getFieldValue(fieldName
);
1429 if(propValue
!= null
&& propValue
!= "" && propValue
.length() > 0)
1431 if(fieldName
.equals("rows"))
1433 rows
= Integer
.parseInt(propValue
);
1435 else if(fieldName
.equals("cols"))
1437 cols
= Integer
.parseInt(propValue
);
1441 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1446 propertiesDialog
.dispose();
1447 propertiesDialog
= null
;
1449 compositeElement
.append(">");
1450 for(int i
= 0; i
< rows
; i
++)
1452 compositeElement
.append("<TR>");
1453 for(int j
= 0; j
< cols
; j
++)
1455 compositeElement
.append("<TD></TD>");
1457 compositeElement
.append("</TR>");
1459 compositeElement
.append("</TABLE><P> <P>");
1460 htmlKit
.insertHTML(htmlDoc
, caretPos
, compositeElement
.toString(), 0, 0, HTML
.Tag
.TABLE
);
1461 jtpMain
.setCaretPosition(caretPos
+ 1);
1465 /** Method for inserting a row into an HTML Table
1467 private void insertTableRow()
1469 int caretPos
= jtpMain
.getCaretPosition();
1470 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1471 Element elementParent
= element
.getParentElement();
1472 int startPoint
= -1;
1473 int columnCount
= -1;
1474 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1476 if(elementParent
.getName().equals("tr"))
1478 startPoint
= elementParent
.getStartOffset();
1479 columnCount
= elementParent
.getElementCount();
1484 elementParent
= elementParent
.getParentElement();
1487 if(startPoint
> -1 && columnCount
> -1)
1489 jtpMain
.setCaretPosition(startPoint
);
1490 StringBuffer sRow
= new StringBuffer();
1491 sRow
.append("<TR>");
1492 for(int i
= 0; i
< columnCount
; i
++)
1494 sRow
.append("<TD></TD>");
1496 sRow
.append("</TR>");
1497 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableRow");
1498 new HTMLEditorKit
.InsertHTMLTextAction("insertTableRow", sRow
.toString(), HTML
.Tag
.TABLE
, HTML
.Tag
.TR
).actionPerformed(actionEvent
);
1500 jtpMain
.setCaretPosition(caretPos
);
1504 /** Method for inserting a column into an HTML Table
1506 private void insertTableColumn()
1508 int caretPos
= jtpMain
.getCaretPosition();
1509 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1510 Element elementParent
= element
.getParentElement();
1511 int startPoint
= -1;
1514 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1516 if(elementParent
.getName().equals("table"))
1518 startPoint
= elementParent
.getStartOffset();
1519 rowCount
= elementParent
.getElementCount();
1522 else if(elementParent
.getName().equals("tr"))
1524 int rowStart
= elementParent
.getStartOffset();
1525 int rowCells
= elementParent
.getElementCount();
1526 for(int i
= 0; i
< rowCells
; i
++)
1528 Element currentCell
= elementParent
.getElement(i
);
1529 if(jtpMain
.getCaretPosition() >= currentCell
.getStartOffset() && jtpMain
.getCaretPosition() <= currentCell
.getEndOffset())
1534 elementParent
= elementParent
.getParentElement();
1538 elementParent
= elementParent
.getParentElement();
1541 if(startPoint
> -1 && rowCount
> -1)
1543 jtpMain
.setCaretPosition(startPoint
);
1544 String sCell
= "<TD></TD>";
1545 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableCell");
1546 for(int i
= 0; i
< rowCount
; i
++)
1548 Element row
= elementParent
.getElement(i
);
1549 Element whichCell
= row
.getElement(cellOffset
);
1550 jtpMain
.setCaretPosition(whichCell
.getStartOffset());
1551 new HTMLEditorKit
.InsertHTMLTextAction("insertTableCell", sCell
, HTML
.Tag
.TR
, HTML
.Tag
.TD
, HTML
.Tag
.TH
, HTML
.Tag
.TD
).actionPerformed(actionEvent
);
1554 jtpMain
.setCaretPosition(caretPos
);
1558 /** Method for inserting a cell into an HTML Table
1560 private void insertTableCell()
1562 String sCell
= "<TD></TD>";
1563 ActionEvent actionEvent
= new ActionEvent(jtpMain
, 0, "insertTableCell");
1564 new HTMLEditorKit
.InsertHTMLTextAction("insertTableCell", sCell
, HTML
.Tag
.TR
, HTML
.Tag
.TD
, HTML
.Tag
.TH
, HTML
.Tag
.TD
).actionPerformed(actionEvent
);
1568 /** Method for deleting a row from an HTML Table
1570 private void deleteTableRow()
1571 throws BadLocationException
1573 int caretPos
= jtpMain
.getCaretPosition();
1574 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1575 Element elementParent
= element
.getParentElement();
1576 int startPoint
= -1;
1578 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1580 if(elementParent
.getName().equals("tr"))
1582 startPoint
= elementParent
.getStartOffset();
1583 endPoint
= elementParent
.getEndOffset();
1588 elementParent
= elementParent
.getParentElement();
1591 if(startPoint
> -1 && endPoint
> startPoint
)
1593 htmlDoc
.remove(startPoint
, endPoint
- startPoint
);
1594 jtpMain
.setDocument(htmlDoc
);
1595 registerDocument(htmlDoc
);
1597 if(caretPos
>= htmlDoc
.getLength())
1599 caretPos
= htmlDoc
.getLength() - 1;
1601 jtpMain
.setCaretPosition(caretPos
);
1605 /** Method for deleting a column from an HTML Table
1607 private void deleteTableColumn()
1608 throws BadLocationException
1610 int caretPos
= jtpMain
.getCaretPosition();
1611 Element element
= htmlDoc
.getCharacterElement(jtpMain
.getCaretPosition());
1612 Element elementParent
= element
.getParentElement();
1613 Element elementCell
= (Element
)null
;
1614 Element elementRow
= (Element
)null
;
1615 Element elementTable
= (Element
)null
;
1616 // Locate the table, row, and cell location of the cursor
1617 while(elementParent
!= null
&& !elementParent
.getName().equals("body"))
1619 if(elementParent
.getName().equals("td"))
1621 elementCell
= elementParent
;
1623 else if(elementParent
.getName().equals("tr"))
1625 elementRow
= elementParent
;
1627 else if(elementParent
.getName().equals("table"))
1629 elementTable
= elementParent
;
1631 elementParent
= elementParent
.getParentElement();
1633 int whichColumn
= -1;
1634 if(elementCell
!= null
&& elementRow
!= null
&& elementTable
!= null
)
1636 // Find the column the cursor is in
1637 for(int i
= 0; i
< elementRow
.getElementCount(); i
++)
1639 if(elementCell
== elementRow
.getElement(i
))
1644 if(whichColumn
> -1)
1646 // Iterate through the table rows, deleting cells from the indicated column
1647 for(int i
= 0; i
< elementTable
.getElementCount(); i
++)
1649 elementRow
= elementTable
.getElement(i
);
1650 elementCell
= (elementRow
.getElementCount() > whichColumn ? elementRow
.getElement(whichColumn
) : elementRow
.getElement(elementRow
.getElementCount() - 1));
1651 int columnCellStart
= elementCell
.getStartOffset();
1652 int columnCellEnd
= elementCell
.getEndOffset();
1653 htmlDoc
.remove(columnCellStart
, columnCellEnd
- columnCellStart
);
1655 jtpMain
.setDocument(htmlDoc
);
1656 registerDocument(htmlDoc
);
1658 if(caretPos
>= htmlDoc
.getLength())
1660 caretPos
= htmlDoc
.getLength() - 1;
1662 jtpMain
.setCaretPosition(caretPos
);
1667 /** Method for inserting a break (BR) element
1669 private void insertBreak()
1670 throws IOException
, BadLocationException
, RuntimeException
1672 int caretPos
= jtpMain
.getCaretPosition();
1673 htmlKit
.insertHTML(htmlDoc
, caretPos
, "<BR>", 0, 0, HTML
.Tag
.BR
);
1674 jtpMain
.setCaretPosition(caretPos
+ 1);
1677 /** Method for inserting a non-breaking space ( )
1679 private void insertNonbreakingSpace()
1680 throws IOException
, BadLocationException
, RuntimeException
1682 int caretPos
= jtpMain
.getCaretPosition();
1683 htmlDoc
.insertString(caretPos
, "\240", jtpMain
.getInputAttributes());
1684 jtpMain
.setCaretPosition(caretPos
+ 1);
1687 /** Method for inserting a form element
1689 private void insertFormElement(HTML
.Tag baseTag
, String baseElement
, Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
, String
[] fieldValues
, boolean hasClosingTag
)
1690 throws IOException
, BadLocationException
, RuntimeException
1692 int caretPos
= jtpMain
.getCaretPosition();
1693 StringBuffer compositeElement
= new StringBuffer("<" + baseElement
);
1694 if(attribs
!= null
&& attribs
.size() > 0)
1696 Enumeration attribEntries
= attribs
.keys();
1697 while(attribEntries
.hasMoreElements())
1699 Object entryKey
= attribEntries
.nextElement();
1700 Object entryValue
= attribs
.get(entryKey
);
1701 if(entryValue
!= null
&& entryValue
!= "")
1703 compositeElement
.append(" " + entryKey
+ "=" + '"' + entryValue
+ '"');
1707 if(fieldNames
!= null
&& fieldNames
.length
> 0)
1709 PropertiesDialog propertiesDialog
= new PropertiesDialog(this.getFrame(), fieldNames
, fieldTypes
, fieldValues
, Translatrix
.getTranslationString("FormDialogTitle"), true
);
1710 propertiesDialog
.show();
1711 String decision
= propertiesDialog
.getDecisionValue();
1712 if(decision
.equals(Translatrix
.getTranslationString("DialogCancel")))
1714 propertiesDialog
.dispose();
1715 propertiesDialog
= null
;
1720 for(int iter
= 0; iter
< fieldNames
.length
; iter
++)
1722 String fieldName
= fieldNames
[iter
];
1723 String propValue
= propertiesDialog
.getFieldValue(fieldName
);
1724 if(propValue
!= null
&& propValue
.length() > 0)
1726 if(fieldName
.equals("checked"))
1728 if(propValue
.equals("true"))
1730 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1735 compositeElement
.append(" " + fieldName
+ "=" + '"' + propValue
+ '"');
1740 propertiesDialog
.dispose();
1741 propertiesDialog
= null
;
1743 // --- Convenience for editing, this makes the FORM visible
1744 if(useFormIndicator
&& baseElement
.equals("form"))
1746 compositeElement
.append(" bgcolor=" + '"' + clrFormIndicator
+ '"');
1749 compositeElement
.append(">");
1752 compositeElement
.append("</" + baseElement
+ ">");
1754 if(baseTag
== HTML
.Tag
.FORM
)
1756 compositeElement
.append("<P> </P>");
1758 htmlKit
.insertHTML(htmlDoc
, caretPos
, compositeElement
.toString(), 0, 0, baseTag
);
1759 // jtpMain.setCaretPosition(caretPos + 1);
1763 /** Alternate method call for inserting a form element
1765 private void insertFormElement(HTML
.Tag baseTag
, String baseElement
, Hashtable attribs
, String
[] fieldNames
, String
[] fieldTypes
, boolean hasClosingTag
)
1766 throws IOException
, BadLocationException
, RuntimeException
1768 insertFormElement(baseTag
, baseElement
, attribs
, fieldNames
, fieldTypes
, new String
[fieldNames
.length
], hasClosingTag
);
1771 /** Method that handles initial list insertion and deletion
1773 public void manageListElement(Element element
)
1775 Element h
= htmlUtilities
.getListItemParent();
1776 Element listElement
= h
.getParentElement();
1779 htmlUtilities
.removeTag(h
, true
);
1783 /** Method to initiate a find/replace operation
1785 private void doSearch(String searchFindTerm
, String searchReplaceTerm
, boolean bIsFindReplace
, boolean bCaseSensitive
, boolean bStartAtTop
)
1787 boolean bReplaceAll
= false
;
1788 JTextPane searchPane
= jtpMain
;
1789 if(jspSource
.isShowing() || jtpSource
.hasFocus())
1791 searchPane
= jtpSource
;
1793 if(searchFindTerm
== null
|| (bIsFindReplace
&& searchReplaceTerm
== null
))
1795 SearchDialog sdSearchInput
= new SearchDialog(this.getFrame(), Translatrix
.getTranslationString("SearchDialogTitle"), true
, bIsFindReplace
, bCaseSensitive
, bStartAtTop
);
1796 searchFindTerm
= sdSearchInput
.getFindTerm();
1797 searchReplaceTerm
= sdSearchInput
.getReplaceTerm();
1798 bCaseSensitive
= sdSearchInput
.getCaseSensitive();
1799 bStartAtTop
= sdSearchInput
.getStartAtTop();
1800 bReplaceAll
= sdSearchInput
.getReplaceAll();
1802 if(searchFindTerm
!= null
&& (!bIsFindReplace
|| searchReplaceTerm
!= null
))
1806 int results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, 0);
1812 findOffset
= findOffset
+ searchReplaceTerm
.length();
1813 results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, findOffset
);
1818 SimpleInfoDialog sidWarn
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("ErrorNoOccurencesFound") + ":\n" + searchFindTerm
, SimpleInfoDialog
.WARNING
);
1823 int results
= findText(searchFindTerm
, searchReplaceTerm
, bCaseSensitive
, (bStartAtTop ?
0 : searchPane
.getCaretPosition()));
1826 SimpleInfoDialog sidWarn
= new SimpleInfoDialog(this.getFrame(), "", true
, Translatrix
.getTranslationString("ErrorNoMatchFound") + ":\n" + searchFindTerm
, SimpleInfoDialog
.WARNING
);
1829 lastSearchFindTerm
= new String(searchFindTerm
);
1830 if(searchReplaceTerm
!= null
)
1832 lastSearchReplaceTerm
= new String(searchReplaceTerm
);
1836 lastSearchReplaceTerm
= (String
)null
;
1838 lastSearchCaseSetting
= bCaseSensitive
;
1839 lastSearchTopSetting
= bStartAtTop
;
1843 /** Method for finding (and optionally replacing) a string in the text
1845 private int findText(String findTerm
, String replaceTerm
, boolean bCaseSenstive
, int iOffset
)
1847 JTextPane jtpFindSource
;
1848 if(jspSource
.isShowing() || jtpSource
.hasFocus())
1850 jtpFindSource
= jtpSource
;
1854 jtpFindSource
= jtpMain
;
1856 int searchPlace
= -1;
1859 Document baseDocument
= jtpFindSource
.getDocument();
1862 baseDocument
.getText(0, baseDocument
.getLength()).indexOf(findTerm
, iOffset
) :
1863 baseDocument
.getText(0, baseDocument
.getLength()).toLowerCase().indexOf(findTerm
.toLowerCase(), iOffset
)
1865 if(searchPlace
> -1)
1867 if(replaceTerm
!= null
)
1869 AttributeSet attribs
= null
;
1870 if(baseDocument
instanceof HTMLDocument
)
1872 Element element
= ((HTMLDocument
)baseDocument
).getCharacterElement(searchPlace
);
1873 attribs
= element
.getAttributes();
1875 baseDocument
.remove(searchPlace
, findTerm
.length());
1876 baseDocument
.insertString(searchPlace
, replaceTerm
, attribs
);
1877 jtpFindSource
.setCaretPosition(searchPlace
+ replaceTerm
.length());
1878 jtpFindSource
.requestFocus();
1879 jtpFindSource
.select(searchPlace
, searchPlace
+ replaceTerm
.length());
1883 jtpFindSource
.setCaretPosition(searchPlace
+ findTerm
.length());
1884 jtpFindSource
.requestFocus();
1885 jtpFindSource
.select(searchPlace
, searchPlace
+ findTerm
.length());
1889 catch(BadLocationException ble
)
1891 logException("BadLocationException in actionPerformed method", ble
);
1892 SimpleInfoDialog sidAbout
= new SimpleInfoDialog(this.getFrame(), Translatrix
.getTranslationString("Error"), true
, Translatrix
.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog
.ERROR
);
1897 /** Method for inserting an image from a file
1899 private void insertLocalImage(File whatImage
)
1900 throws IOException
, BadLocationException
, RuntimeException
1902 if(whatImage
== null
)
1904 whatImage
= getImageFromChooser(".", extsIMG
, Translatrix
.getTranslationString("FiletypeIMG"));
1906 if(whatImage
!= null
)
1908 int caretPos
= jtpMain
.getCaretPosition();
1909 htmlKit
.insertHTML(htmlDoc
, caretPos
, "<IMG SRC=\"" + whatImage
+ "\">", 0, 0, HTML
.Tag
.IMG
);
1910 jtpMain
.setCaretPosition(caretPos
+ 1);
1915 /** Method for inserting an image from a server
1917 private void insertServerImage()
1918 throws BadLocationException
1920 if(ServletURL
!= null
)
1924 URL theServlet
= new URL(ServletURL
+ "?GetImages=" + TreePilotSystemID
+ "&ImageExtensions=" + TreePilotProperties
.getString("ValidImageExtensions"));
1925 URLConnection conn
= theServlet
.openConnection();
1926 ObjectInputStream
in = new ObjectInputStream(conn
.getInputStream());
1927 String
[] imageList
= (String
[]) in.readObject();
1928 int caretPos
= jtpMain
.getCaretPosition();
1929 ImageDialog imageDialog
= new ImageDialog(this, ImageDir
+ TreePilotSystemID
, imageList
, "Image Chooser", true
);
1930 String selectedImage
= imageDialog
.getSelectedImage();
1931 imageDialog
.dispose();
1932 if(selectedImage
!= null
&& !selectedImage
.equals(""))
1934 htmlKit
.insertHTML(htmlDoc
, caretPos
, selectedImage
, 0, 0, HTML
.Tag
.IMG
);
1935 jtpMain
.setCaretPosition(caretPos
+ 1);
1937 jtpMain
.requestFocus();
1940 catch (MalformedURLException mue
)
1942 System
.err
.println("MalFormedURLException during insertImage " + mue
);
1944 catch (IOException ie
)
1946 System
.err
.println("IOException during insertImage " + ie
);
1948 catch (ClassNotFoundException cnfe
)
1950 System
.err
.println("ClassNotFoundException during insertImage" + cnfe
);
1955 /** Method for inserting an image
1957 public String
insertFile()
1959 String selectedFile
= null
;
1960 if(ServletURL
!= null
)
1964 URL theServlet
= new URL(ServletURL
+ "?GetFiles=" + TreePilotSystemID
+ "&FileExtensions=" + TreePilotProperties
.getString("ValidFileExtensions"));
1965 URLConnection conn
= theServlet
.openConnection();
1966 ObjectInputStream
in = new ObjectInputStream(conn
.getInputStream());
1967 String
[] fileList
= (String
[]) in.readObject();
1968 FileDialog fileDialog
= new FileDialog(this, ImageDir
+ TreePilotSystemID
, fileList
, "File Chooser", true
);
1969 selectedFile
= fileDialog
.getSelectedFile();
1970 fileDialog
.dispose();
1973 catch (MalformedURLException mue
)
1975 System
.err
.println("MalFormedURLException during insertFile " + mue
);
1977 catch (IOException ie
)
1979 System
.err
.println("IOException during insertFile " + ie
);
1981 catch (ClassNotFoundException cnfe
)
1983 System
.err
.println("ClassNotFoundException during insertFile" + cnfe
);
1986 return selectedFile
;
1989 /** Method for saving text as a complete HTML document
1991 private void writeOut(HTMLDocument doc
, File whatFile
)
1992 throws IOException
, BadLocationException
1994 if(whatFile
== null
)
1996 whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
1998 if(whatFile
!= null
)
2000 FileWriter fw
= new FileWriter(whatFile
);
2001 htmlKit
.write(fw
, doc
, 0, doc
.getLength());
2004 currentFile
= whatFile
;
2010 /** Method for saving text as an HTML fragment
2012 private void writeOutFragment(HTMLDocument doc
, String containingTag
)
2013 throws IOException
, BadLocationException
2015 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
2016 if(whatFile
!= null
)
2018 FileWriter fw
= new FileWriter(whatFile
);
2019 // Element eleBody = locateElementInDocument((StyledDocument)doc, containingTag);
2020 // htmlKit.write(fw, doc, eleBody.getStartOffset(), eleBody.getEndOffset());
2021 String docTextCase
= jtpSource
.getText().toLowerCase();
2022 int tagStart
= docTextCase
.indexOf("<" + containingTag
.toLowerCase());
2023 int tagStartClose
= docTextCase
.indexOf(">", tagStart
) + 1;
2024 String closeTag
= "</" + containingTag
.toLowerCase() + ">";
2025 int tagEndOpen
= docTextCase
.indexOf(closeTag
);
2026 if(tagStartClose
< 0) { tagStartClose
= 0; }
2027 if(tagEndOpen
< 0 || tagEndOpen
> docTextCase
.length()) { tagEndOpen
= docTextCase
.length(); }
2028 String bodyText
= jtpSource
.getText().substring(tagStartClose
, tagEndOpen
);
2029 fw
.write(bodyText
, 0, bodyText
.length());
2036 /** Method for saving text as an RTF document
2038 private void writeOutRTF(StyledDocument doc
)
2039 throws IOException
, BadLocationException
2041 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsRTF
, Translatrix
.getTranslationString("FiletypeRTF"));
2042 if(whatFile
!= null
)
2044 FileOutputStream fos
= new FileOutputStream(whatFile
);
2045 RTFEditorKit rtfKit
= new RTFEditorKit();
2046 rtfKit
.write(fos
, doc
, 0, doc
.getLength());
2053 /** Method for saving text as a Base64 encoded document
2055 private void writeOutBase64(String text
)
2056 throws IOException
, BadLocationException
2058 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsB64
, Translatrix
.getTranslationString("FiletypeB64"));
2059 if(whatFile
!= null
)
2061 String base64text
= Base64Codec
.encode(text
);
2062 FileWriter fw
= new FileWriter(whatFile
);
2063 fw
.write(base64text
, 0, base64text
.length());
2070 /** Method to invoke loading HTML into the app
2072 private void openDocument(File whatFile
)
2073 throws IOException
, BadLocationException
2075 if(whatFile
== null
)
2077 whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsHTML
, Translatrix
.getTranslationString("FiletypeHTML"));
2079 if(whatFile
!= null
)
2083 loadDocument(whatFile
, null
);
2085 catch(ChangedCharSetException ccse
)
2087 String charsetType
= ccse
.getCharSetSpec().toLowerCase();
2088 int pos
= charsetType
.indexOf("charset");
2093 while(pos
< charsetType
.length() && charsetType
.charAt(pos
) != '=')
2097 pos
++; // Places file cursor past the equals sign (=)
2098 String whatEncoding
= charsetType
.substring(pos
).trim();
2099 loadDocument(whatFile
, whatEncoding
);
2105 /** Method for loading HTML document into the app, including document encoding setting
2107 private void loadDocument(File whatFile
, String whatEncoding
)
2108 throws IOException
, BadLocationException
2111 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
2114 if(whatEncoding
== null
)
2116 r
= new InputStreamReader(new FileInputStream(whatFile
));
2120 r
= new InputStreamReader(new FileInputStream(whatFile
), whatEncoding
);
2121 htmlDoc
.putProperty("IgnoreCharsetDirective", new Boolean(true
));
2123 htmlKit
.read(r
, htmlDoc
, 0);
2125 registerDocument(htmlDoc
);
2126 jtpSource
.setText(jtpMain
.getText());
2127 currentFile
= whatFile
;
2139 /** Method for loading a Base64 encoded document
2141 private void openDocumentBase64(File whatFile
)
2142 throws IOException
, BadLocationException
2144 if(whatFile
== null
)
2146 whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsB64
, Translatrix
.getTranslationString("FiletypeB64"));
2148 if(whatFile
!= null
)
2150 FileReader fr
= new FileReader(whatFile
);
2152 StringBuffer encodedText
= new StringBuffer();
2155 while((nextChar
= fr
.read()) != -1)
2157 encodedText
.append((char)nextChar
);
2160 jtpSource
.setText(Base64Codec
.decode(encodedText
.toString()));
2161 jtpMain
.setText(jtpSource
.getText());
2162 registerDocument((ExtendedHTMLDocument
)(jtpMain
.getDocument()));
2174 /** Method for loading a Stylesheet into the app
2176 private void openStyleSheet(File fileCSS
)
2181 fileCSS
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsCSS
, Translatrix
.getTranslationString("FiletypeCSS"));
2185 String currDocText
= jtpMain
.getText();
2186 htmlDoc
= (ExtendedHTMLDocument
)(htmlKit
.createDefaultDocument());
2187 styleSheet
= htmlDoc
.getStyleSheet();
2188 URL cssUrl
= fileCSS
.toURL();
2189 InputStream is
= cssUrl
.openStream();
2190 BufferedReader br
= new BufferedReader(new InputStreamReader(is
));
2191 styleSheet
.loadRules(br
, cssUrl
);
2193 htmlDoc
= new ExtendedHTMLDocument(styleSheet
);
2194 registerDocument(htmlDoc
);
2195 jtpMain
.setText(currDocText
);
2196 jtpSource
.setText(jtpMain
.getText());
2201 /** Method for serializing the document out to a file
2203 public void serializeOut(HTMLDocument doc
)
2206 File whatFile
= getFileFromChooser(".", JFileChooser
.SAVE_DIALOG
, extsSer
, Translatrix
.getTranslationString("FiletypeSer"));
2207 if(whatFile
!= null
)
2209 ObjectOutputStream oos
= new ObjectOutputStream(new FileOutputStream(whatFile
));
2210 oos
.writeObject(doc
);
2217 /** Method for reading in a serialized document from a file
2219 public void serializeIn()
2220 throws IOException
, ClassNotFoundException
2222 File whatFile
= getFileFromChooser(".", JFileChooser
.OPEN_DIALOG
, extsSer
, Translatrix
.getTranslationString("FiletypeSer"));
2223 if(whatFile
!= null
)
2225 ObjectInputStream ois
= new ObjectInputStream(new FileInputStream(whatFile
));
2226 htmlDoc
= (ExtendedHTMLDocument
)(ois
.readObject());
2228 registerDocument(htmlDoc
);
2234 /** Method for obtaining a File for input/output using a JFileChooser dialog
2236 private File
getFileFromChooser(String startDir
, int dialogType
, String
[] exts
, String desc
)
2238 JFileChooser jfileDialog
= new JFileChooser(startDir
);
2239 jfileDialog
.setDialogType(dialogType
);
2240 jfileDialog
.setFileFilter(new MutableFilter(exts
, desc
));
2241 int optionSelected
= JFileChooser
.CANCEL_OPTION
;
2242 if(dialogType
== JFileChooser
.OPEN_DIALOG
)
2244 optionSelected
= jfileDialog
.showOpenDialog(this);
2246 else if(dialogType
== JFileChooser
.SAVE_DIALOG
)
2248 optionSelected
= jfileDialog
.showSaveDialog(this);
2250 else // default to an OPEN_DIALOG
2252 optionSelected
= jfileDialog
.showOpenDialog(this);
2254 if(optionSelected
== JFileChooser
.APPROVE_OPTION
)
2256 return jfileDialog
.getSelectedFile();
2261 /** Method for obtaining an Image for input using a custom JFileChooser dialog
2263 private File
getImageFromChooser(String startDir
, String
[] exts
, String desc
)
2265 ImageFileChooser jImageDialog
= new ImageFileChooser(startDir
);
2266 jImageDialog
.setDialogType(JFileChooser
.CUSTOM_DIALOG
);
2267 jImageDialog
.setFileFilter(new MutableFilter(exts
, desc
));
2268 jImageDialog
.setDialogTitle(Translatrix
.getTranslationString("ImageDialogTitle"));
2269 int optionSelected
= JFileChooser
.CANCEL_OPTION
;
2270 optionSelected
= jImageDialog
.showDialog(this, Translatrix
.getTranslationString("Insert"));
2271 if(optionSelected
== JFileChooser
.APPROVE_OPTION
)
2273 return jImageDialog
.getSelectedFile();
2278 /** Method for describing the node hierarchy of the document
2280 private void describeDocument(StyledDocument doc
)
2282 Element
[] elements
= doc
.getRootElements();
2283 for(int i
= 0; i
< elements
.length
; i
++)
2285 indent
= indentStep
;
2286 for(int j
= 0; j
< indent
; j
++) { System
.out
.print(" "); }
2287 System
.out
.print(elements
[i
]);
2288 traverseElement(elements
[i
]);
2289 System
.out
.println("");
2293 /** Traverses nodes for the describing method
2295 private void traverseElement(Element element
)
2297 indent
+= indentStep
;
2298 for(int i
= 0; i
< element
.getElementCount(); i
++)
2300 for(int j
= 0; j
< indent
; j
++) { System
.out
.print(" "); }
2301 System
.out
.print(element
.getElement(i
));
2302 traverseElement(element
.getElement(i
));
2304 indent
-= indentStep
;
2307 /** Method to locate a node element by name
2309 private Element
locateElementInDocument(StyledDocument doc
, String elementName
)
2311 Element
[] elements
= doc
.getRootElements();
2312 for(int i
= 0; i
< elements
.length
; i
++)
2314 if(elements
[i
].getName().equalsIgnoreCase(elementName
))
2320 Element rtnElement
= locateChildElementInDocument(elements
[i
], elementName
);
2321 if(rtnElement
!= null
)
2327 return (Element
)null
;
2330 /** Traverses nodes for the locating method
2332 private Element
locateChildElementInDocument(Element element
, String elementName
)
2334 for(int i
= 0; i
< element
.getElementCount(); i
++)
2336 if(element
.getElement(i
).getName().equalsIgnoreCase(elementName
))
2338 return element
.getElement(i
);
2341 return (Element
)null
;
2344 /** Convenience method for obtaining the WYSIWYG JTextPane
2346 public JTextPane
getTextPane()
2351 /** Convenience method for obtaining the Source JTextPane
2353 public JTextPane
getSourcePane()
2358 /** Convenience method for obtaining the application as a Frame
2360 public Frame
getFrame()
2362 return frameHandler
;
2365 /** Convenience method for setting the parent Frame
2367 public void setFrame(Frame parentFrame
)
2369 frameHandler
= parentFrame
;
2372 /** Convenience method for obtaining the pre-generated menu bar
2374 public JMenuBar
getMenuBar()
2379 /** Convenience method for obtaining a custom menu bar
2381 public JMenuBar
getCustomMenuBar(Vector vcMenus
)
2383 jMenuBar
= new JMenuBar();
2384 for(int i
= 0; i
< vcMenus
.size(); i
++)
2386 String menuToAdd
= ((String
)(vcMenus
.elementAt(i
))).toLowerCase();
2387 if(htMenus
.containsKey(menuToAdd
))
2389 jMenuBar
.add((JMenu
)(htMenus
.get(menuToAdd
)));
2395 /** Convenience method for obtaining the pre-generated toolbar
2397 public JToolBar
getToolBar(boolean isShowing
)
2399 jcbmiViewToolbar
.setState(isShowing
);
2403 /** Convenience method for obtaining the pre-generated toolbar
2405 public JToolBar
getCustomToolBar(Vector vcTools
, boolean isShowing
)
2407 jcbmiViewToolbar
.setState(isShowing
);
2408 jToolBar
= new JToolBar(JToolBar
.HORIZONTAL
);
2409 jToolBar
.setFloatable(false
);
2410 for(int i
= 0; i
< vcTools
.size(); i
++)
2412 String toolToAdd
= ((String
)(vcTools
.elementAt(i
))).toLowerCase();
2413 if(toolToAdd
.equals(KEY_TOOL_SEP
))
2415 jToolBar
.add(new JToolBar
.Separator());
2417 else if(htTools
.containsKey(toolToAdd
))
2419 if(htTools
.get(toolToAdd
) instanceof JButtonNoFocus
)
2421 jToolBar
.add((JButtonNoFocus
)(htTools
.get(toolToAdd
)));
2423 else if(htTools
.get(toolToAdd
) instanceof JToggleButtonNoFocus
)
2425 jToolBar
.add((JToggleButtonNoFocus
)(htTools
.get(toolToAdd
)));
2427 else if(htTools
.get(toolToAdd
) instanceof JComboBoxNoFocus
)
2429 jToolBar
.add((JComboBoxNoFocus
)(htTools
.get(toolToAdd
)));
2433 jToolBar
.add((JComponent
)(htTools
.get(toolToAdd
)));
2440 /** Convenience method for obtaining the current file handle
2442 public File
getCurrentFile()
2447 /** Convenience method for obtaining the application name
2449 public String
getAppName()
2454 /** Convenience method for obtaining the document text
2456 public String
getDocumentText()
2458 return jtpMain
.getText();
2461 /** Convenience method for obtaining the document text
2462 * contained within a tag pair
2464 public String
getDocumentSubText(String tagBlock
)
2466 return getSubText(tagBlock
);
2469 /** Method for extracting the text within a tag
2471 private String
getSubText(String containingTag
)
2473 jtpSource
.setText(jtpMain
.getText());
2474 String docTextCase
= jtpSource
.getText().toLowerCase();
2475 int tagStart
= docTextCase
.indexOf("<" + containingTag
.toLowerCase());
2476 int tagStartClose
= docTextCase
.indexOf(">", tagStart
) + 1;
2477 String closeTag
= "</" + containingTag
.toLowerCase() + ">";
2478 int tagEndOpen
= docTextCase
.indexOf(closeTag
);
2479 if(tagStartClose
< 0) { tagStartClose
= 0; }
2480 if(tagEndOpen
< 0 || tagEndOpen
> docTextCase
.length()) { tagEndOpen
= docTextCase
.length(); }
2481 return jtpSource
.getText().substring(tagStartClose
, tagEndOpen
);
2484 /** Convenience method for obtaining the document text
2485 * contained within the BODY tags (a common request)
2487 public String
getDocumentBody()
2489 return getSubText("body");
2492 /** Convenience method for setting the document text
2494 public void setDocumentText(String sText
)
2496 jtpMain
.setText(sText
);
2497 ((HTMLEditorKit
)(jtpMain
.getEditorKit())).setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
2498 jtpSource
.setText(jtpMain
.getText());
2499 ((HTMLEditorKit
)(jtpSource
.getEditorKit())).setDefaultCursor(new Cursor(Cursor
.TEXT_CURSOR
));
2502 /** Convenience method for obtaining the document text
2504 private void updateTitle()
2506 frameHandler
.setTitle(appName
+ (currentFile
== null ?
"" : " - " + currentFile
.getName()));
2509 /** Convenience method for clearing out the UndoManager
2511 public void purgeUndos()
2513 if(undoMngr
!= null
)
2515 undoMngr
.discardAllEdits();
2516 undoAction
.updateUndoState();
2517 redoAction
.updateRedoState();
2521 /** Convenience method for refreshing and displaying changes
2523 public void refreshOnUpdate()
2525 jtpMain
.setText(jtpMain
.getText());
2526 jtpSource
.setText(jtpMain
.getText());
2531 /** Convenience method for deallocating the app resources
2533 public void dispose()
2535 frameHandler
.dispose();
2539 /** Convenience method for fetching icon images from jar file
2541 private ImageIcon
getEkitIcon(String iconName
)
2543 return new ImageIcon(Toolkit
.getDefaultToolkit().getImage(getClass().getResource("icons/" + iconName
+ "HK.gif")));
2546 /** Convenience method for outputting exceptions
2548 private void logException(String internalMessage
, Exception e
)
2550 System
.err
.println(internalMessage
);
2551 e
.printStackTrace(System
.err
);
2554 /** Convenience method for toggling source window visibility
2556 private void toggleSourceWindow()
2558 if(!(jspSource
.isShowing()))
2560 jtpSource
.setText(jtpMain
.getText());
2561 jspltDisplay
.setRightComponent(jspSource
);
2564 jspltDisplay
.setDividerLocation(0);
2565 jspltDisplay
.setEnabled(false
);
2569 jspltDisplay
.setDividerLocation(iSplitPos
);
2570 jspltDisplay
.setEnabled(true
);
2575 jtpMain
.setText(jtpSource
.getText());
2576 iSplitPos
= jspltDisplay
.getDividerLocation();
2577 jspltDisplay
.remove(jspSource
);
2578 jtpMain
.requestFocus();
2581 jcbmiViewSource
.setSelected(jspSource
.isShowing());
2582 jtbtnViewSource
.setSelected(jspSource
.isShowing());
2585 /** Searches the specified element for CLASS attribute setting
2587 private String
findStyle(Element element
)
2589 AttributeSet
as = element
.getAttributes();
2594 Object val
= as.getAttribute(HTML
.Attribute
.CLASS
);
2595 if(val
!= null
&& (val
instanceof String
))
2599 for(Enumeration e
= as.getAttributeNames(); e
.hasMoreElements();)
2601 Object key
= e
.nextElement();
2602 if(key
instanceof HTML
.Tag
)
2604 AttributeSet eas
= (AttributeSet
)(as.getAttribute(key
));
2607 val
= eas
.getAttribute(HTML
.Attribute
.CLASS
);
2619 /** Handles caret tracking and related events, such as displaying the current style
2620 * of the text under the caret
2622 private void handleCaretPositionChange(CaretEvent ce
)
2624 int caretPos
= ce
.getDot();
2625 Element element
= htmlDoc
.getCharacterElement(caretPos
);
2627 ---- TAG EXPLICATOR CODE -------------------------------------------
2628 javax.swing.text.ElementIterator ei = new javax.swing.text.ElementIterator(htmlDoc);
2630 while((ele = ei.next()) != null)
2632 System.out.println("ELEMENT : " + ele.getName());
2634 System.out.println("ELEMENT:" + element.getName());
2635 Element elementParent = element.getParentElement();
2636 System.out.println("ATTRS:");
2637 AttributeSet attribs = elementParent.getAttributes();
2638 for(Enumeration eAttrs = attribs.getAttributeNames(); eAttrs.hasMoreElements();)
2640 System.out.println(" " + eAttrs.nextElement().toString());
2642 while(elementParent != null && !elementParent.getName().equals("body"))
2644 String parentName = elementParent.getName();
2645 System.out.println("PARENT:" + parentName);
2646 System.out.println("ATTRS:");
2647 attribs = elementParent.getAttributes();
2648 for(Enumeration eAttr = attribs.getAttributeNames(); eAttr.hasMoreElements();)
2650 System.out.println(" " + eAttr.nextElement().toString());
2652 elementParent = elementParent.getParentElement();
2654 ---- END -------------------------------------------
2660 String style
= null
;
2661 Vector vcStyles
= new Vector();
2662 while(element
!= null
)
2666 style
= findStyle(element
);
2668 vcStyles
.add(element
);
2669 element
= element
.getParentElement();
2671 int stylefound
= -1;
2674 for(int i
= 0; i
< jcmbStyleSelector
.getItemCount(); i
++)
2676 String
in = (String
)(jcmbStyleSelector
.getItemAt(i
));
2677 if(in.equalsIgnoreCase(style
))
2686 Action ac
= jcmbStyleSelector
.getAction();
2687 ac
.setEnabled(false
);
2688 jcmbStyleSelector
.setSelectedIndex(stylefound
);
2689 ac
.setEnabled(true
);
2693 jcmbStyleSelector
.setSelectedIndex(0);
2697 /** Server-side image handling methods
2699 protected void setServletURL(String url
)
2704 protected void setImageDir(String sysDir
)
2709 public void setTreePilotSystemID(String theSystem
)
2711 TreePilotSystemID
= theSystem
;
2716 public ExtendedHTMLDocument
getExtendedHtmlDoc()
2718 return (ExtendedHTMLDocument
)htmlDoc
;
2721 public int getCaretPosition()
2723 return jtpMain
.getCaretPosition();
2726 public void setCaretPosition(int newPositon
)
2734 jtpMain
.setCaretPosition(newPositon
);
2736 catch (IllegalArgumentException iae
)
2741 } while(!end
&& newPositon
>= 0);
2744 /* Inner Classes --------------------------------------------- */
2746 /** Class for implementing Undo as an autonomous action
2748 class UndoAction
extends AbstractAction
2752 super(Translatrix
.getTranslationString("Undo"));
2756 public void actionPerformed(ActionEvent e
)
2762 catch(CannotUndoException ex
)
2764 ex
.printStackTrace();
2767 redoAction
.updateRedoState();
2770 protected void updateUndoState()
2772 if(undoMngr
.canUndo())
2775 putValue(Action
.NAME
, undoMngr
.getUndoPresentationName());
2780 putValue(Action
.NAME
, Translatrix
.getTranslationString("Undo"));
2785 /** Class for implementing Redo as an autonomous action
2787 class RedoAction
extends AbstractAction
2791 super(Translatrix
.getTranslationString("Redo"));
2795 public void actionPerformed(ActionEvent e
)
2801 catch(CannotUndoException ex
)
2803 ex
.printStackTrace();
2806 undoAction
.updateUndoState();
2809 protected void updateRedoState()
2811 if(undoMngr
.canRedo())
2814 putValue(Action
.NAME
, undoMngr
.getRedoPresentationName());
2819 putValue(Action
.NAME
, Translatrix
.getTranslationString("Redo"));
2824 /** Class for implementing the Undo listener to handle the Undo and Redo actions
2826 class CustomUndoableEditListener
implements UndoableEditListener
2828 public void undoableEditHappened(UndoableEditEvent uee
)
2830 undoMngr
.addEdit(uee
.getEdit());
2831 undoAction
.updateUndoState();
2832 redoAction
.updateRedoState();