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