Example usage for javax.swing.text StyleConstants setFontSize

List of usage examples for javax.swing.text StyleConstants setFontSize

Introduction

In this page you can find the example usage for javax.swing.text StyleConstants setFontSize.

Prototype

public static void setFontSize(MutableAttributeSet a, int s) 

Source Link

Document

Sets the font size attribute.

Usage

From source file:org.smart.migrate.ui.ImportThread.java

private void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);

    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);

    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);

    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);

    s = doc.addStyle("icon", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);

    s = doc.addStyle("info", regular);
    StyleConstants.setForeground(s, Color.blue);

    s = doc.addStyle("error", regular);
    StyleConstants.setForeground(s, Color.red);

    s = doc.addStyle("warning", regular);
    StyleConstants.setForeground(s, Color.orange);

    s = doc.addStyle("gray", regular);
    StyleConstants.setForeground(s, Color.gray);

    s = doc.addStyle("success", regular);
    StyleConstants.setForeground(s, Color.green);
}

From source file:org.thdl.tib.input.TibetanConverter.java

/** Reads from in, closes in, converts (or finds some/all
non-TM/TMW), writes the result to out, does not close out.
The action taken depends on ct, which must be one of a set
number of strings -- see the code.  Uses short error and
warning messages if shortMessages is true; gives no warnings
or many warnings depending on warningLevel.  Returns an
appropriate return code so that TibetanConverter's usage
message is honored. *///from   www  .  j a v a2 s .c  o  m
static int reallyConvert(InputStream in, PrintStream out, String ct, String warningLevel, boolean shortMessages,
        boolean colors) {
    if (UNI_TO_WYLIE_TEXT == ct || WYLIE_TO_ACIP_TEXT == ct || ACIP_TO_WYLIE_TEXT == ct) {
        try {
            /*String uniText;
            {
            // TODO(dchandler): use, here and elsewhere in the
            // codebase,
            // org.apache.commons.io.IOUtils.toString(InputStream,
            // encoding)
            StringBuffer s = new StringBuffer();
            char ch[] = new char[8192];
            BufferedReader bin
                = new BufferedReader(new InputStreamReader(in,
                                                           "UTF-8"));
            int amt;
            while (-1 != (amt = bin.read(ch))) {
                s.append(ch, 0, amt);
            }
            bin.close();
            uniText = s.toString();
            }
            StringBuffer errors = new StringBuffer();
            // TODO(dchandler): DLC: use human-friendly EWTS, not
            // computer-friendly!
            String ewtsText = Converter.convertToEwtsForComputers(uniText,
                                                              errors);
            // TODO(dchandler): is 51 the right choice?
            return (errors.length() > 0) ? 51 : 0;*/
            BasicTibetanTranscriptionConverter bc = null;
            if (UNI_TO_WYLIE_TEXT == ct)
                bc = new BasicTibetanTranscriptionConverter(
                        new BufferedReader(new InputStreamReader(in, "UTF16")), new PrintWriter(out));
            else
                bc = new BasicTibetanTranscriptionConverter(new BufferedReader(new InputStreamReader(in)),
                        new PrintWriter(out));
            bc.run(ct);
            return 0;
        } catch (IOException e) {
            // TODO(dchandler): print it?  where to?
            return 48;
        }
    } else if (ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct || WYLIE_TO_UNI_TEXT == ct || WYLIE_TO_TMW == ct) {
        try {
            ArrayList al = ((ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) ? (TTraits) ACIPTraits.instance()
                    : (TTraits) EWTSTraits.instance()).scanner().scanStream(
                            in, null,
                            ThdlOptions.getIntegerOption((ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct)
                                    ? "thdl.most.errors.a.tibetan.acip.document.can.have"
                                    : "thdl.most.errors.a.tibetan.ewts.document.can.have", 1000 - 1),
                            shortMessages, warningLevel);
            if (null == al)
                return 47;
            boolean embeddedWarnings = (warningLevel != "None");
            boolean hasWarnings[] = new boolean[] { false };
            if (ACIP_TO_UNI_TEXT == ct || WYLIE_TO_UNI_TEXT == ct) {
                if (!TConverter.convertToUnicodeText(
                        (WYLIE_TO_UNI_TEXT == ct) ? (TTraits) EWTSTraits.instance()
                                : (TTraits) ACIPTraits.instance(),
                        al, out, null, null, hasWarnings, embeddedWarnings, warningLevel, shortMessages))
                    return 46;
            } else {
                if (!TConverter.convertToTMW(
                        (WYLIE_TO_TMW == ct) ? (TTraits) EWTSTraits.instance()
                                : (TTraits) ACIPTraits.instance(),
                        al, out, null, null, hasWarnings, embeddedWarnings, warningLevel, shortMessages,
                        colors))
                    return 46;
            }
            if (embeddedWarnings && hasWarnings[0])
                return 45;
            else
                return 0;
        } catch (IOException e) {
            // TODO(dchandler): print it?  where to?
            return 48;
        }
    } else {
        TibetanDocument tdoc = new TibetanDocument();
        {
            SimpleAttributeSet ras = new SimpleAttributeSet();
            StyleConstants.setFontFamily(ras,
                    ThdlOptions.getStringOption("thdl.default.roman.font.face", "Serif"));
            StyleConstants.setFontSize(ras, ThdlOptions.getIntegerOption("thdl.default.roman.font.size", 14));
            tdoc.setRomanAttributeSet(ras);
        }
        try {
            // Read in the rtf file.
            if (debug)
                System.err.println("Start: reading in old RTF file");
            if (!ThdlOptions.getBooleanOption("thdl.do.not.fix.rtf.hex.escapes"))
                in = new RTFFixerInputStream(in);
            (new RTFEditorKit()).read(in, tdoc, 0);
            if (debug)
                System.err.println("End  : reading in old RTF file");
        } catch (Exception e) {
            out.println("TibetanConverter:\n" + rtfErrorMessage);
            return 3;
        }
        try {
            in.close();
        } catch (IOException e) {
            // silently ignore; we don't care about the input so much...
            ThdlDebug.noteIffyCode();
        }

        if (FIND_ALL_NON_TMW == ct) {
            // 0, -1 is the entire document.
            int exitCode = tdoc.findAllNonTMWCharacters(0, -1, out);
            if (out.checkError())
                exitCode = 41;
            return exitCode;
        } else if (FIND_SOME_NON_TMW == ct) {
            // 0, -1 is the entire document.
            int exitCode = tdoc.findSomeNonTMWCharacters(0, -1, out);
            if (out.checkError())
                exitCode = 41;
            return exitCode;
        } else if (FIND_SOME_NON_TM == ct) {
            // 0, -1 is the entire document.
            int exitCode = tdoc.findSomeNonTMCharacters(0, -1, out);
            if (out.checkError())
                exitCode = 41;
            return exitCode;
        } else if (FIND_ALL_NON_TM == ct) {
            // 0, -1 is the entire document.
            int exitCode = tdoc.findAllNonTMCharacters(0, -1, out);
            if (out.checkError())
                exitCode = 41;
            return exitCode;
        } else { // conversion {to Wylie or TM} mode
            // Fix curly braces in the entire document if the input is TMW:
            if (TM_TO_TMW != ct) {
                // DLC make me optional
                if (debug)
                    System.err.println("Start: solving curly brace problem");
                tdoc.replaceTahomaCurlyBracesAndBackslashes(0, -1);
                if (debug)
                    System.err.println("End  : solving curly brace problem");
            }

            int exitCode = 0;
            ThdlDebug.verify(((TMW_TO_TM == ct) ? 1 : 0) + ((TMW_TO_SAME_TMW == ct) ? 1 : 0)
                    + ((TMW_TO_UNI == ct) ? 1 : 0) + ((TM_TO_TMW == ct) ? 1 : 0) + ((TMW_TO_ACIP == ct) ? 1 : 0)
                    + ((TMW_TO_ACIP_TEXT == ct) ? 1 : 0) + ((TMW_TO_WYLIE == ct) ? 1 : 0)
                    + ((TMW_TO_WYLIE_TEXT == ct) ? 1 : 0) == 1);
            long numAttemptedReplacements[] = new long[] { 0 };
            if (TMW_TO_SAME_TMW == ct) {
                // Identity conversion for testing
                if (tdoc.identityTmwToTmwConversion(0, tdoc.getLength(), numAttemptedReplacements)) {
                    exitCode = 50;
                }
            } else if (TMW_TO_WYLIE == ct || TMW_TO_WYLIE_TEXT == ct) {
                // Convert to THDL Wylie:
                if (!tdoc.toWylie(0, tdoc.getLength(), numAttemptedReplacements)) {
                    exitCode = 44;
                }
            } else if (TMW_TO_ACIP == ct || TMW_TO_ACIP_TEXT == ct) {
                // Convert to ACIP:
                if (!tdoc.toACIP(0, tdoc.getLength(), numAttemptedReplacements)) {
                    exitCode = 49;
                }
            } else if (TMW_TO_UNI == ct) {
                StringBuffer errors = new StringBuffer();
                // Convert to Unicode:
                if (tdoc.convertToUnicode(0, tdoc.getLength(), errors,
                        ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
                        numAttemptedReplacements)) {
                    System.err.println(errors);
                    exitCode = 42;
                }
            } else if (TM_TO_TMW == ct) {
                StringBuffer errors = new StringBuffer();
                // Convert to TibetanMachineWeb:
                if (tdoc.convertToTMW(0, tdoc.getLength(), errors, numAttemptedReplacements)) {
                    System.err.println(errors);
                    exitCode = 42;
                }
            } else {
                ThdlDebug.verify(TMW_TO_TM == ct);
                StringBuffer errors = new StringBuffer();
                // Convert to TibetanMachine:
                if (tdoc.convertToTM(0, tdoc.getLength(), errors, numAttemptedReplacements)) {
                    System.err.println(errors);
                    exitCode = 42;
                }
            }

            // Write to standard output the result:
            if (TMW_TO_WYLIE_TEXT == ct || TMW_TO_ACIP_TEXT == ct) {
                try {
                    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
                    tdoc.writeTextOutput(bw);
                    bw.flush();
                } catch (IOException e) {
                    exitCode = 40;
                }
            } else {
                try {
                    tdoc.writeRTFOutputStream(out);
                } catch (IOException e) {
                    exitCode = 40;
                }
            }
            if (out.checkError())
                exitCode = 41;
            if (numAttemptedReplacements[0] < 1)
                exitCode = 43;

            return exitCode;
        }
    }
}

From source file:org.zephyrsoft.sdb2.presenter.SongView.java

private Style addStyle(String styleName, boolean italic, boolean bold, String fontFamily, int fontSize) {
    Style style = document.addStyle(styleName, DEFAULT_STYLE);
    StyleConstants.setItalic(style, italic);
    StyleConstants.setBold(style, bold);
    StyleConstants.setFontFamily(style, fontFamily);
    StyleConstants.setFontSize(style, fontSize);
    return style;
}

From source file:pl.otros.logview.gui.message.pattern.StyleProperties.java

public static Style getStyle(StyleContext styleContext, DataConfiguration styleConfig, String styleName,
        int group) {
    Style style = styleContext.addStyle(styleName, styleContext.getStyle(StyleContext.DEFAULT_STYLE));

    String groupSuffix = "." + group;
    if (group <= 0) {
        groupSuffix = "";
    }//from   ww  w.  ja v  a  2s . c  o  m

    String fontFamily = styleConfig.getString(PROP_FONT_FAMILY + groupSuffix, "");
    if (fontFamily.trim().length() > 0) {
        StyleConstants.setFontFamily(style, styleConfig.getString(PROP_FONT_FAMILY + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_SIZE + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setFontSize(style, styleConfig.getInt(PROP_FONT_SIZE + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_BOLD + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setBold(style, styleConfig.getBoolean(PROP_FONT_BOLD + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_ITALIC + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setItalic(style, styleConfig.getBoolean(PROP_FONT_ITALIC + groupSuffix));
    }

    if (styleConfig.getString(PROP_FONT_UNDERLINE + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setUnderline(style, styleConfig.getBoolean(PROP_FONT_UNDERLINE + groupSuffix));
    }

    if (styleConfig.getString(PROP_BACKGROUND + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setBackground(style, styleConfig.getColor(PROP_BACKGROUND + groupSuffix));
    }

    if (styleConfig.getString(PROP_FOREGROUND + groupSuffix, "").trim().length() > 0) {
        StyleConstants.setForeground(style, styleConfig.getColor(PROP_FOREGROUND + groupSuffix));
    }
    return style;
}

From source file:pl.otros.logview.gui.message.update.LogDataFormatter.java

public LogDataFormatter(LogData logData, //
        DateFormat dateFormat, //
        MessageUpdateUtils messageUtils, //
        PluginableElementsContainer<MessageColorizer> colorizersContainer, //
        PluginableElementsContainer<MessageFormatter> formattersContainer, //
        CancelStatus cancelStatus, int maximumMessageSize) {
    this.ld = logData;
    this.dateFormat = dateFormat;
    this.messageUtils = messageUtils;
    this.colorizersContainer = colorizersContainer;
    this.formattersContainer = formattersContainer;
    this.cancelStatus = cancelStatus;
    this.maximumMessageSize = maximumMessageSize;

    sc = new StyleContext();
    defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
    mainStyle = sc.addStyle("MainStyle", defaultStyle);
    StyleConstants.setFontSize(mainStyle, 12);
    StyleConstants.setForeground(mainStyle, Color.BLACK);

    classMethodStyle = sc.addStyle("classMethod", null);
    StyleConstants.setFontFamily(classMethodStyle, "monospaced");
    StyleConstants.setForeground(classMethodStyle, Color.BLUE);
    boldArialStyle = sc.addStyle("note", mainStyle);
    StyleConstants.setFontFamily(boldArialStyle, "arial");
    StyleConstants.setBold(boldArialStyle, true);

    propertyNameStyle = sc.addStyle("propertyValue", classMethodStyle);
    StyleConstants.setForeground(propertyNameStyle, new Color(0, 0, 128));

    propertyValueStyle = sc.addStyle("propertyValue", classMethodStyle);
    StyleConstants.setForeground(propertyNameStyle, new Color(0, 128, 0));

}

From source file:pl.otros.logview.gui.MessageDetailListener.java

public MessageDetailListener(JTable table, JTextPane logDetailTextArea, LogDataTableModel dataTableModel,
        SimpleDateFormat dateFormat, PluginableElementsContainer<MessageFormatter> formattersContainer,
        PluginableElementsContainer<MessageColorizer> colorizersContainer) {
    super();//  w  w w  .ja  va 2  s.  c om
    this.table = table;
    this.logDetailTextArea = logDetailTextArea;
    this.dataTableModel = dataTableModel;
    this.dateFormat = dateFormat;
    this.formattersContainer = formattersContainer;
    this.colorizersContainer = colorizersContainer;

    sc = new StyleContext();
    defaultStyle = sc.getStyle(StyleContext.DEFAULT_STYLE);
    mainStyle = sc.addStyle("MainStyle", defaultStyle);
    StyleConstants.setFontSize(mainStyle, 12);
    StyleConstants.setForeground(mainStyle, Color.BLACK);

    classMethodStyle = sc.addStyle("classMethod", null);
    StyleConstants.setFontFamily(classMethodStyle, "monospaced");
    StyleConstants.setForeground(classMethodStyle, Color.BLUE);
    noteStyle = sc.addStyle("note", mainStyle);
    StyleConstants.setFontFamily(noteStyle, "arial");
    StyleConstants.setBold(noteStyle, true);

    formattersContainer.addListener(new PluginableElementEventListenerImplementation<MessageFormatter>());
    colorizersContainer.addListener(new PluginableElementEventListenerImplementation<MessageColorizer>());
}