Example usage for javax.swing.text Style toString

List of usage examples for javax.swing.text Style toString

Introduction

In this page you can find the example usage for javax.swing.text Style toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.hexidec.ekit.EkitCore.java

public void actionPerformed(ActionEvent ae) {
    try {/*  ww  w  .  j a v a 2  s  .c om*/
        String command = ae.getActionCommand();
        if (command.equals(CMD_DOC_NEW) || command.equals(CMD_DOC_NEW_STYLED)) {
            SimpleInfoDialog sidAsk = new SimpleInfoDialog(this.getWindow(), "", true,
                    Translatrix.getTranslationString("AskNewDocument"), SimpleInfoDialog.QUESTION);
            String decision = sidAsk.getDecisionValue();
            if (decision.equals(Translatrix.getTranslationString("DialogAccept"))) {
                if (styleSheet != null && command.equals(CMD_DOC_NEW_STYLED)) {
                    htmlDoc = new ExtendedHTMLDocument(styleSheet);
                } else {
                    htmlDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
                    htmlDoc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
                    htmlDoc.setPreservesUnknownTags(preserveUnknownTags);
                }
                registerDocument(htmlDoc);
                jtpSource.setText(jtpMain.getText());
                currentFile = null;
                updateTitle();
            }
        } else if (command.equals(CMD_DOC_OPEN_HTML)) {
            openDocument(null);
        } else if (command.equals(CMD_DOC_OPEN_CSS)) {
            openStyleSheet(null);
        } else if (command.equals(CMD_DOC_SAVE)) {
            writeOut((HTMLDocument) (jtpMain.getDocument()), currentFile);
            updateTitle();
        } else if (command.equals(CMD_DOC_SAVE_AS)) {
            writeOut((HTMLDocument) (jtpMain.getDocument()), null);
        } else if (command.equals(CMD_DOC_SAVE_BODY)) {
            writeOutFragment((HTMLDocument) (jtpMain.getDocument()), "body");
        } else if (command.equals(CMD_DOC_SAVE_RTF)) {
            writeOutRTF((StyledDocument) (jtpMain.getStyledDocument()));
        } else if (command.equals(CMD_CLIP_CUT)) {
            if (sourceWindowActive && jtpSource.hasFocus()) {
                jtpSource.cut();
            } else {
                jtpMain.cut();
            }
        } else if (command.equals(CMD_CLIP_COPY)) {
            if (sourceWindowActive && jtpSource.hasFocus()) {
                jtpSource.copy();
            } else {
                jtpMain.copy();
            }
        } else if (command.equals(CMD_CLIP_PASTE)) {
            if (!jspSource.isShowing()) {
                jtpMain.paste();
            }
        } else if (command.equals(CMD_CLIP_PASTE_PLAIN)) {
            if (!jspSource.isShowing()) {
                try {
                    if (sysClipboard != null) {
                        jtpMain.getDocument().insertString(jtpMain.getCaretPosition(),
                                sysClipboard.getData(dfPlainText).toString(), (AttributeSet) null);
                    } else {
                        jtpMain.getDocument()
                                .insertString(
                                        jtpMain.getCaretPosition(), Toolkit.getDefaultToolkit()
                                                .getSystemClipboard().getData(dfPlainText).toString(),
                                        (AttributeSet) null);
                    }
                    refreshOnUpdate();
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }
        } else if (command.equals(CMD_DOC_PRINT)) {
            DocumentRenderer dr = new DocumentRenderer();
            dr.print(htmlDoc);

        } else if (command.equals(CMD_DEBUG_DESCRIBE_DOC)) {
            log.debug("------------DOCUMENT------------");
            log.debug("Content Type : " + jtpMain.getContentType());
            log.debug("Editor Kit   : " + jtpMain.getEditorKit());
            log.debug("Doc Tree     :");
            log.debug("");
            describeDocument(jtpMain.getStyledDocument());
            log.debug("--------------------------------");
            log.debug("");
        } else if (command.equals(CMD_DEBUG_DESCRIBE_CSS)) {
            log.debug("-----------STYLESHEET-----------");
            log.debug("Stylesheet Rules");
            Enumeration rules = styleSheet.getStyleNames();
            while (rules.hasMoreElements()) {
                String ruleName = (String) (rules.nextElement());
                Style styleRule = styleSheet.getStyle(ruleName);
                log.debug(styleRule.toString());
            }
            log.debug("--------------------------------");
            log.debug("");
        } else if (command.equals(CMD_DEBUG_CURRENT_TAGS)) {
            log.debug("Caret Position : " + jtpMain.getCaretPosition());
            AttributeSet attribSet = jtpMain.getCharacterAttributes();
            Enumeration attribs = attribSet.getAttributeNames();
            log.debug("Attributes     : ");
            while (attribs.hasMoreElements()) {
                String attribName = attribs.nextElement().toString();
                log.debug("                 " + attribName + " | " + attribSet.getAttribute(attribName));
            }
        } else if (command.equals(CMD_TOGGLE_TOOLBAR_SINGLE)) {
            jToolBar.setVisible(jcbmiViewToolbar.isSelected());
        } else if (command.equals(CMD_TOGGLE_TOOLBAR_MAIN)) {
            jToolBarMain.setVisible(jcbmiViewToolbarMain.isSelected());
        } else if (command.equals(CMD_TOGGLE_TOOLBAR_FORMAT)) {
            jToolBarFormat.setVisible(jcbmiViewToolbarFormat.isSelected());
        } else if (command.equals(CMD_TOGGLE_TOOLBAR_STYLES)) {
            jToolBarStyles.setVisible(jcbmiViewToolbarStyles.isSelected());
        } else if (command.equals(CMD_TOGGLE_SOURCE_VIEW)) {
            toggleSourceWindow();
        } else if (command.equals(CMD_DOC_SERIALIZE_OUT)) {
            serializeOut((HTMLDocument) (jtpMain.getDocument()));
        } else if (command.equals(CMD_DOC_SERIALIZE_IN)) {
            serializeIn();
        } else if (command.equals(CMD_TABLE_INSERT)) {
            tableCtl.insertTable();
        } else if (command.equals(CMD_TABLE_DELETE)) {
            tableCtl.deleteTable();
        } else if (command.equals(CMD_TABLE_EDIT)) {
            tableCtl.editTable();
        } else if (command.equals(CMD_TABLE_CELL_EDIT)) {
            tableCtl.editCell();
        } else if (command.equals(CMD_TABLE_ROW_INSERT)) {
            tableCtl.insertTableRow(false);
        } else if (command.equals(CMD_TABLE_ROW_INSERT_AFTER)) {
            tableCtl.insertTableRow(true);
        } else if (command.equals(CMD_TABLE_COLUMN_INSERT)) {
            tableCtl.insertTableColumn(false);
        } else if (command.equals(CMD_TABLE_COLUMN_INSERT_AFTER)) {
            tableCtl.insertTableColumn(true);
        } else if (command.equals(CMD_TABLE_ROW_DELETE)) {
            tableCtl.deleteTableRow();
        } else if (command.equals(CMD_TABLE_COLUMN_DELETE)) {
            tableCtl.deleteTableColumn();
        } else if (command.equals(CMD_TABLE_COLUMN_FORMAT)) {
            tableCtl.formatTableColumn();
        } else if (command.equals(CMD_INSERT_BREAK)) {
            insertBreak();
        } else if (command.equals(CMD_INSERT_NBSP)) {
            insertNonbreakingSpace();
        } else if (command.equals(CMD_INSERT_HR)) {
            insertHR();
        } else if (command.equals(CMD_INSERT_IMAGE_LOCAL)) {
            insertLocalImage(null);
        } else if (command.equals(CMD_INSERT_IMAGE_URL)) {
            insertURLImage();
        } else if (command.equals(CMD_INSERT_UNICODE_CHAR)) {
            insertUnicode(UnicodeDialog.UNICODE_BASE);
        } else if (command.equals(CMD_INSERT_UNICODE_MATH)) {
            insertUnicode(UnicodeDialog.UNICODE_MATH);
        } else if (command.equals(CMD_INSERT_UNICODE_DRAW)) {
            insertUnicode(UnicodeDialog.UNICODE_DRAW);
        } else if (command.equals(CMD_INSERT_UNICODE_DING)) {
            insertUnicode(UnicodeDialog.UNICODE_DING);
        } else if (command.equals(CMD_INSERT_UNICODE_SIGS)) {
            insertUnicode(UnicodeDialog.UNICODE_SIGS);
        } else if (command.equals(CMD_INSERT_UNICODE_SPEC)) {
            insertUnicode(UnicodeDialog.UNICODE_SPEC);
        } else if (command.equals(CMD_FORM_INSERT)) {
            String[] fieldNames = { "name", "method", "enctype" };
            String[] fieldTypes = { "text", "combo", "text" };
            String[] fieldValues = { "", "POST,GET", "text" };
            insertFormElement(HTML.Tag.FORM, "form", (Hashtable) null, fieldNames, fieldTypes, fieldValues,
                    true);
        } else if (command.equals(CMD_FORM_TEXTFIELD)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "text");
            String[] fieldNames = { "name", "value", "size", "maxlength" };
            String[] fieldTypes = { "text", "text", "text", "text" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_TEXTAREA)) {
            String[] fieldNames = { "name", "rows", "cols" };
            String[] fieldTypes = { "text", "text", "text" };
            insertFormElement(HTML.Tag.TEXTAREA, "textarea", (Hashtable) null, fieldNames, fieldTypes, true);
        } else if (command.equals(CMD_FORM_CHECKBOX)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "checkbox");
            String[] fieldNames = { "name", "checked" };
            String[] fieldTypes = { "text", "bool" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_RADIO)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "radio");
            String[] fieldNames = { "name", "checked" };
            String[] fieldTypes = { "text", "bool" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_PASSWORD)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "password");
            String[] fieldNames = { "name", "value", "size", "maxlength" };
            String[] fieldTypes = { "text", "text", "text", "text" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_BUTTON)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "button");
            String[] fieldNames = { "name", "value" };
            String[] fieldTypes = { "text", "text" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_SUBMIT)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "submit");
            String[] fieldNames = { "name", "value" };
            String[] fieldTypes = { "text", "text" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_FORM_RESET)) {
            Hashtable<String, String> htAttribs = new Hashtable<String, String>();
            htAttribs.put("type", "reset");
            String[] fieldNames = { "name", "value" };
            String[] fieldTypes = { "text", "text" };
            insertFormElement(HTML.Tag.INPUT, "input", htAttribs, fieldNames, fieldTypes, false);
        } else if (command.equals(CMD_SEARCH_FIND)) {
            doSearch((String) null, (String) null, false, lastSearchCaseSetting, lastSearchTopSetting);
        } else if (command.equals(CMD_SEARCH_FIND_AGAIN)) {
            doSearch(lastSearchFindTerm, (String) null, false, lastSearchCaseSetting, false);
        } else if (command.equals(CMD_SEARCH_REPLACE)) {
            doSearch((String) null, (String) null, true, lastSearchCaseSetting, lastSearchTopSetting);
        } else if (command.equals(CMD_EXIT)) {
            this.dispose();
        } else if (command.equals(CMD_HELP_ABOUT)) {
            new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("About"), true,
                    Translatrix.getTranslationString("AboutMessage"), SimpleInfoDialog.INFO);
        } else if (command.equals(CMD_ENTER_PARAGRAPH)) {
            setEnterKeyIsBreak(false);
        } else if (command.equals(CMD_ENTER_BREAK)) {
            setEnterKeyIsBreak(true);
        } else if (command.equals(CMD_SPELLCHECK)) {
            checkDocumentSpelling(jtpMain.getDocument());
        } else if (command.equals(CMD_MAXIMIZE)) {
            if (maximizeHandler != null) {
                if (maximized) {
                    maximizeHandler.minimize();
                    jbtnMaximize.setToolTipText(Translatrix.getTranslationString("Maximize"));
                } else {
                    maximizeHandler.maximize();
                    jbtnMaximize.setToolTipText(Translatrix.getTranslationString("Restore"));
                }
                maximized = !maximized;
            }
        }
    } catch (IOException ioe) {
        logException("IOException in actionPerformed method", ioe);
        new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
    } catch (BadLocationException ble) {
        logException("BadLocationException in actionPerformed method", ble);
        new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
    } catch (NumberFormatException nfe) {
        logException("NumberFormatException in actionPerformed method", nfe);
        new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                Translatrix.getTranslationString("ErrorNumberFormatException"), SimpleInfoDialog.ERROR);
    } catch (ClassNotFoundException cnfe) {
        logException("ClassNotFound Exception in actionPerformed method", cnfe);
        new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                Translatrix.getTranslationString("ErrorClassNotFoundException "), SimpleInfoDialog.ERROR);
    } catch (RuntimeException re) {
        logException("RuntimeException in actionPerformed method", re);
        new SimpleInfoDialog(this.getWindow(), Translatrix.getTranslationString("Error"), true,
                Translatrix.getTranslationString("ErrorRuntimeException"), SimpleInfoDialog.ERROR);
    }
}