Java 类javax.swing.text.Style 实例源码

项目:incubator-netbeans    文件:VCSHyperlinkSupport.java   
public static IssueLinker create(VCSHyperlinkProvider hp, Style issueHyperlinkStyle, File root, StyledDocument sd, String text) {
    int[] spans = hp.getSpans(text);
    if (spans == null) {
        return null;
    }
    if(spans.length % 2 != 0) {
        // XXX more info and log only _ONCE_
        LOG.warning("Hyperlink provider " + hp.getClass().getName() + " returns wrong spans");
        return null;
    }
    if(spans.length > 0) {
        IssueLinker l = new IssueLinker(hp, issueHyperlinkStyle, root, sd, text, spans);
        return l;
    }
    return null;
}
项目:incubator-netbeans    文件:VCSHyperlinkSupport.java   
@Override
public void insertString(StyledDocument sd, Style style) throws BadLocationException {
    if(style == null) {
        style = authorStyle;
    }
    sd.insertString(sd.getLength(), author, style);

    String iconStyleName = AUTHOR_ICON_STYLE + author;
    Style iconStyle = sd.getStyle(iconStyleName);
    if(iconStyle == null) {
        iconStyle = sd.addStyle(iconStyleName, null);
        StyleConstants.setIcon(iconStyle, kenaiUser.getIcon());
    }
    sd.insertString(sd.getLength(), " ", style);
    sd.insertString(sd.getLength(), " ", iconStyle);
}
项目:incubator-netbeans    文件:SummaryCellRenderer.java   
private void addDate (JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {

            LogEntry entry = item.getUserData();
            StyledDocument sd = pane.getStyledDocument();
            // clear document
            clearSD(pane, sd);

            Style selectedStyle = createSelectedStyle(pane);
            Style normalStyle = createNormalStyle(pane);
            Style style;
            if (selected) {
                style = selectedStyle;
            } else {
                style = normalStyle;
            }

            // add date
            sd.insertString(sd.getLength(), entry.getDate(), style);
        }
项目:org.alloytools.alloy    文件:SwingLogPanel.java   
/** Write a horizontal separator into the log window. */
public void logDivider() {
    if (log == null)
        return;
    clearError();
    StyledDocument doc = log.getStyledDocument();
    Style dividerStyle = doc.addStyle("bar", styleRegular);
    JPanel jpanel = new JPanel();
    jpanel.setBackground(Color.LIGHT_GRAY);
    jpanel.setPreferredSize(new Dimension(300, 1)); // 300 is arbitrary,
                                                    // since it will
                                                    // auto-stretch
    StyleConstants.setComponent(dividerStyle, jpanel);
    reallyLog(".", dividerStyle); // Any character would do; "." will be
                                    // replaced by the JPanel
    reallyLog("\n\n", styleRegular);
    log.setCaretPosition(doc.getLength());
    lastSize = doc.getLength();
}
项目:org.alloytools.alloy    文件:SwingLogPanel.java   
private void reallyLog(String text, Style style) {
    if (log == null || text.length() == 0)
        return;
    int i = text.lastIndexOf('\n'), j = text.lastIndexOf('\r');
    if (i >= 0 && i < j) {
        i = j;
    }
    StyledDocument doc = log.getStyledDocument();
    try {
        if (i < 0) {
            doc.insertString(doc.getLength(), text, style);
        } else {
            // Performs intelligent caret positioning
            doc.insertString(doc.getLength(), text.substring(0, i + 1), style);
            log.setCaretPosition(doc.getLength());
            if (i < text.length() - 1) {
                doc.insertString(doc.getLength(), text.substring(i + 1), style);
            }
        }
    } catch (BadLocationException e) {
        // Harmless
    }
    if (style != styleRed) {
        lastSize = doc.getLength();
    }
}
项目:org.alloytools.alloy    文件:SwingLogPanel.java   
/** Set the font name. */
public void setFontName(String fontName) {
    if (log == null)
        return;
    this.fontName = fontName;
    log.setFont(new Font(fontName, Font.PLAIN, fontSize));
    StyleConstants.setFontFamily(styleRegular, fontName);
    StyleConstants.setFontFamily(styleBold, fontName);
    StyleConstants.setFontFamily(styleRed, fontName);
    StyleConstants.setFontSize(styleRegular, fontSize);
    StyleConstants.setFontSize(styleBold, fontSize);
    StyleConstants.setFontSize(styleRed, fontSize);
    // Changes all existing text
    StyledDocument doc = log.getStyledDocument();
    Style temp = doc.addStyle("temp", null);
    StyleConstants.setFontFamily(temp, fontName);
    StyleConstants.setFontSize(temp, fontSize);
    doc.setCharacterAttributes(0, doc.getLength(), temp, false);
    // Changes all existing hyperlinks
    Font newFont = new Font(fontName, Font.BOLD, fontSize);
    for (JLabel link : links) {
        link.setFont(newFont);
    }
}
项目:gate-core    文件:LogArea.java   
/**
 * Try and recover from a BadLocationException thrown when inserting a string
 * into the log area. This method must only be called on the AWT event
 * handling thread.
 */
private void handleBadLocationException(BadLocationException e,
    String textToInsert, Style style) {
  originalErr.println("BadLocationException encountered when writing to "
      + "the log area: " + e);
  originalErr.println("trying to recover...");

  Document newDocument = new DefaultStyledDocument();
  try {
    StringBuilder sb = new StringBuilder();
    sb.append("An error occurred when trying to write a message to the log area.  The log\n");
    sb.append("has been cleared to try and recover from this problem.\n\n");
    sb.append(textToInsert);

    newDocument.insertString(0, sb.toString(), style);
  } catch(BadLocationException e2) {
    // oh dear, all bets are off now...
    e2.printStackTrace(originalErr);
    return;
  }
  // replace the log area's document with the new one
  setDocument(newDocument);
}
项目:Tarski    文件:SwingLogPanel.java   
private void reallyLog(String text, Style style) {
    if (log==null || text.length()==0) return;
    int i=text.lastIndexOf('\n'), j=text.lastIndexOf('\r');
    if (i>=0 && i<j) { i=j; }
    StyledDocument doc=log.getStyledDocument();
    try {
        if (i<0) {
            doc.insertString(doc.getLength(), text, style);
        } else {
            // Performs intelligent caret positioning
            doc.insertString(doc.getLength(), text.substring(0,i+1), style);
            log.setCaretPosition(doc.getLength());
            if (i<text.length()-1) {
                doc.insertString(doc.getLength(), text.substring(i+1), style);
            }
        }
    } catch (BadLocationException e) {
        // Harmless
    }
    if (style!=styleRed) { lastSize=doc.getLength(); }
}
项目:Tarski    文件:SwingLogPanel.java   
/** Set the font name. */
public void setFontName(String fontName) {
    if (log==null) return;
    this.fontName = fontName;
    log.setFont(new Font(fontName, Font.PLAIN, fontSize));
    StyleConstants.setFontFamily(styleRegular, fontName);
    StyleConstants.setFontFamily(styleBold, fontName);
    StyleConstants.setFontFamily(styleRed, fontName);
    StyleConstants.setFontSize(styleRegular, fontSize);
    StyleConstants.setFontSize(styleBold, fontSize);
    StyleConstants.setFontSize(styleRed, fontSize);
    // Changes all existing text
    StyledDocument doc=log.getStyledDocument();
    Style temp=doc.addStyle("temp", null);
    StyleConstants.setFontFamily(temp, fontName);
    StyleConstants.setFontSize(temp, fontSize);
    doc.setCharacterAttributes(0, doc.getLength(), temp, false);
    // Changes all existing hyperlinks
    Font newFont = new Font(fontName, Font.BOLD, fontSize);
    for(JLabel link: links) { link.setFont(newFont); }
}
项目:openjdk-jdk10    文件:JViewPortBackingStoreImageTest.java   
static void addParagraph(Paragraph p) {
    try {
        Style s = null;
        for (int i = 0; i < p.data.length; i++) {
            AttributedContent run = p.data[i];
            s = contentAttributes.get(run.attr);
            doc.insertString(doc.getLength(), run.content, s);
        }

        Style ls = styles.getStyle(p.logical);
        doc.setLogicalStyle(doc.getLength() - 1, ls);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
项目:emuRox    文件:DebuggerWindow.java   
private JTextPane getCodeArea(){
    final StyleContext sc = new StyleContext();
    final DefaultStyledDocument doc = new DefaultStyledDocument(sc);

    final JTextPane codeArea = new JTextPane(doc);
    codeArea.setBackground(new Color(0x25401C));
    codeArea.setCaretColor(new Color(0xD1E8CE));

    final Style bodyStyle = sc.addStyle("body", null);
    bodyStyle.addAttribute(StyleConstants.Foreground, new Color(0x789C6C));
    bodyStyle.addAttribute(StyleConstants.FontSize, 13);
    bodyStyle.addAttribute(StyleConstants.FontFamily, "monospaced");
    bodyStyle.addAttribute(StyleConstants.Bold, true);

    doc.setLogicalStyle(0, bodyStyle);

    return codeArea;
}
项目:LiveBeans    文件:ServerGUI.java   
private void appendToConsole(String message, Style style)
{
    StyledDocument paneDocument = txtServerConsole.getStyledDocument();
    Integer documentLength = paneDocument.getLength();

    try
    {
        paneDocument.insertString(documentLength, message, style);
    }
    catch (BadLocationException ex)
    {
        // The system will attempt to update the log
        // if it fails to update the log, I sense an
        // infinite loop somewhere...
        System.out.println("[SERVER-WARNING] Failed to update log.\r\n\tError: " + ex.getMessage());
    }
}
项目:jdk8u_jdk    文件:JViewPortBackingStoreImageTest.java   
static void addParagraph(Paragraph p) {
    try {
        Style s = null;
        for (int i = 0; i < p.data.length; i++) {
            AttributedContent run = p.data[i];
            s = contentAttributes.get(run.attr);
            doc.insertString(doc.getLength(), run.content, s);
        }

        Style ls = styles.getStyle(p.logical);
        doc.setLogicalStyle(doc.getLength() - 1, ls);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}
项目:sdk    文件:DocFormatter.java   
private void makeStyles(StyledDocument doc) {
    Style s1 = doc.addStyle("regular", regStyle);
    StyleConstants.setFontFamily(s1, "SansSerif");
    Style s2 = doc.addStyle("bold", s1);       
    StyleConstants.setBold(s2, true);
    Style icon = doc.addStyle("input", s1);
    StyleConstants.setAlignment(icon, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(icon, 8);
    StyleConstants.setIcon(icon, Icons.in);
    Style icon2 = doc.addStyle("output", s1);
    StyleConstants.setAlignment(icon2, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(icon2, 8);
    StyleConstants.setIcon(icon2, Icons.out);


}
项目:OpenUHS    文件:UHSTextArea.java   
/**
 * Returns a default-populated StyleContext for UHSTextAreas.
 *
 * <p>Changes to a style will immediately affect existing
 * components using its descendants only. The style itself
 * will not update for some reason.</p>
 *
 * <blockquote><pre>
 * @{code
 * Java's default
 * - base
 * - - regular
 * - - - visitable
 * - - - link
 * - - - hyper
 * - - - monospaced
 * }
 * </pre></blockquote>
 */
private static StyleContext getDefaultStyleContext() {
    StyleContext result = new StyleContext();
    Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE );
        Style baseStyle = result.addStyle( "base", defaultStyle );
            Style regularStyle = result.addStyle( STYLE_NAME_REGULAR, baseStyle );

                Style visitableStyle = result.addStyle( STYLE_NAME_VISITABLE, regularStyle );
                    StyleConstants.setForeground( visitableStyle, VISITABLE_COLOR );

                Style linkStyle = result.addStyle( STYLE_NAME_LINK, regularStyle );
                    StyleConstants.setForeground( linkStyle, LINK_COLOR );

                Style hyperStyle = result.addStyle( STYLE_NAME_HYPERLINK, regularStyle );
                    StyleConstants.setForeground( hyperStyle, HYPER_COLOR );
                    StyleConstants.setUnderline( hyperStyle, true );

                Style monospacedStyle = result.addStyle( STYLE_NAME_MONOSPACED, regularStyle );
                    StyleConstants.setFontFamily( monospacedStyle, "Monospaced" );

    return result;
}
项目:javify    文件:MinimalHTMLWriter.java   
/**
 * Write the styles used.
 */
protected void writeStyles() throws IOException
{
  if(doc instanceof DefaultStyledDocument)
    {
      Enumeration<?> styles = ((DefaultStyledDocument)doc).getStyleNames();
      while(styles.hasMoreElements())
        writeStyle(doc.getStyle((String)styles.nextElement()));
    }
  else
    { // What else to do here?
      Style s = doc.getStyle("default");
      if(s != null)
        writeStyle( s );
    }
}
项目:repo.kmeanspp.silhouette_score    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:IpTweet    文件:ChatScreen.java   
public void receivedMessage(ChatMessage message) {
    if (!isActive())
        toFront();
    insertHeader(message.getSender(), MessageOperation.RECEIVING_MESSAGE);
    int length = document.getLength();
    StringBuffer strBfr = new StringBuffer();
    strBfr.append(message.getText());

    final Style cwStyle = sc.addStyle("ConstantWidth", null);
    StyleConstants.setForeground(cwStyle, ChatConstant.RECEIVED_MSG_COLOR);
    try {
        logWriter.log(strBfr.toString());
        document.insertString(length, strBfr.toString(), cwStyle);
        scrollToLast();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
项目:IpTweet    文件:ChatScreen.java   
public void groupJoinLeftMessage(User user, boolean isJoined) {
    int length = document.getLength();
    StringBuffer strBfr = new StringBuffer();
    if (isJoined)
        strBfr.append(user.getDisplayName() + " joined conversation."
                + NEW_LINE);
    else
        strBfr.append(user.getDisplayName() + " left conversation."
                + NEW_LINE);
    final Style cwStyle = sc.addStyle("ConstantWidth", null);
    StyleConstants.setFontFamily(cwStyle, "Sylfaen");

    StyleConstants
            .setForeground(cwStyle, ChatConstant.GROUP_LEFT_MSG_COLOR);
    try {
        document.insertString(length, strBfr.toString(), cwStyle);
        scrollToLast();
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
项目:IpTweet    文件:Participants.java   
public void setUsers(User[] users){
    textPane.removeAll();
    StringBuilder sb = new StringBuilder();
    final Style cwStyle = new StyleContext().addStyle("ConstantWidth", null);
    StyleConstants.setBold(cwStyle, true);
    boolean firstUser = true;
    for(User user: users){
        if(firstUser){
            firstUser = false;
        }
        else{
            sb.append(", ");
        }
        sb.append(user.getDisplayName());
    }
    try {
        textPane.getDocument().insertString(textPane.getDocument().getLength(), "Participants: ", cwStyle);
        StyleConstants.setBold(cwStyle, false);
        textPane.getDocument().insertString(textPane.getDocument().getLength(), sb.toString(), cwStyle);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
项目:intellij-ce-playground    文件:NotificationMessageElement.java   
protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
  if (value instanceof LoadingNode) {
    StyleConstants.setForeground(style, JBColor.GRAY);
  }
  else {
    if (selected) {
      StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
    }
    else {
      StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
    }
  }

  if (UIUtil.isUnderGTKLookAndFeel() ||
      UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus ||
      tree != null && tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
    editorPane.setOpaque(false);
  }
  else {
    editorPane.setOpaque(selected && hasFocus);
  }

  htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
项目:intellij-ce-playground    文件:Browser.java   
private void setupStyle() {
  Document document = myHTMLViewer.getDocument();
  if (!(document instanceof StyledDocument)) {
    return;
  }

  StyledDocument styledDocument = (StyledDocument)document;

  EditorColorsManager colorsManager = EditorColorsManager.getInstance();
  EditorColorsScheme scheme = colorsManager.getGlobalScheme();

  Style style = styledDocument.addStyle("active", null);
  StyleConstants.setFontFamily(style, scheme.getEditorFontName());
  StyleConstants.setFontSize(style, scheme.getEditorFontSize());
  styledDocument.setCharacterAttributes(0, document.getLength(), style, false);
}
项目:seaglass    文件:SeaGlassTextPaneUI.java   
/**
 * Update the font in the default style of the document.
 *
 * @param font the new font to use or null to remove the font attribute
 *             from the document's style
 */
private void updateFont(Font font) {
    StyledDocument doc = (StyledDocument)getComponent().getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);

    if (style == null) {
        return;
    }

    if (font == null) {
        style.removeAttribute(StyleConstants.FontFamily);
        style.removeAttribute(StyleConstants.FontSize);
        style.removeAttribute(StyleConstants.Bold);
        style.removeAttribute(StyleConstants.Italic);
    } else {
        StyleConstants.setFontFamily(style, font.getName());
        StyleConstants.setFontSize(style, font.getSize());
        StyleConstants.setBold(style, font.isBold());
        StyleConstants.setItalic(style, font.isItalic());
    }
}
项目:binnavi    文件:BaseTypeTableCellRenderer.java   
private static void renderArray(
    final TypeInstance instance, final StyledDocument document, final boolean renderData) {
  final Style arrayStyle = createDeclarationStyle(document);
  try {
    document.remove(0, document.getLength());
    final BaseType baseType = instance.getBaseType();
    appendString(document, baseType.getName(), arrayStyle);
    if (renderData) {
      appendString(document,
          renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()),
          createDataStyle(document));
    }
  } catch (final BadLocationException exception) {
    CUtilityFunctions.logException(exception);
  }
}
项目:binnavi    文件:BaseTypeTableCellRenderer.java   
private static void renderAtomic(
    final TypeInstance instance, final StyledDocument document, final boolean renderData) {
  final Style atomicStyle = createDeclarationStyle(document);
  try {
    document.remove(0, document.getLength());
    final BaseType baseType = instance.getBaseType();
    appendString(document, baseType.getName(), atomicStyle);
    if (renderData) {
      appendString(document,
          renderInstanceData(baseType, instance.getAddress().getOffset(), instance.getSection()),
          createDataStyle(document));
    }
  } catch (final BadLocationException exception) {
    CUtilityFunctions.logException(exception);
  }
}
项目:climate-tray    文件:ClimateTrayLogController.java   
@Override
public void messageAdded(MessageBuffer messageBuffer, Message message)
{
    Style style;

    switch (message.getSeverity())
    {
        case DEBUG:
            style = debugStyle;
            break;
        case ERROR:
            style = errorStyle;
            break;
        case INFO:
            style = infoStyle;
            break;
        case WARN:
            style = warnStyle;
            break;
        default:
            throw new UnsupportedOperationException("Severity not supported: " + message.getSeverity());
    }

    append(debugStyle, String.format("%1$tH:%1$tM:%1$tS.%1$tL ", message.getTimestamp()));
    append(style, message.getCombinedMessage() + "\n");
}
项目:humo    文件:HighlighterParserListener.java   
public void startParsingLoop(StringBuilder sourcecode, int first, int current, int last, char currentChar)
   {
try
{
    if (debugDelegator.isVisible())
    {
    StyledDocument doc= currentFrame.getDocument();
    //      highlightCurlys(sourcecode, lastCurrent, doc, current - lastCurrent);
    Style style= doc.getStyle(TextViewHelper.FETCH_STYLE);
    doc.setCharacterAttributes(current, last - current, style, false);
    }
}
catch (Exception e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}
   }
项目:deck-editor-java    文件:Card.java   
/**
 * Add the Oracle text of all of this Card's faces to the given document, separated
 * by a separator on its own line.
 *
 * @param document document to add text to
 * @param printed  whether to use printed or Oracle data for a card
 */
public void formatDocument(StyledDocument document, boolean printed)
{
    Style textStyle = document.getStyle("text");
    try
    {
        for (int f = 0; f < faces; f++)
        {
            formatDocument(document, printed, f);
            if (f < faces - 1)
                document.insertString(document.getLength(), "\n" + TEXT_SEPARATOR + "\n", textStyle);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
项目:jvm-stm    文件:MinimalHTMLWriter.java   
/**
  * Write the styles used.
  */
 protected void writeStyles() throws IOException
 {
   if(doc instanceof DefaultStyledDocument)
     {
Enumeration styles = ((DefaultStyledDocument)doc).getStyleNames();
while(styles.hasMoreElements())
  writeStyle(doc.getStyle((String)styles.nextElement()));
     }
   else
     { // What else to do here?
Style s = doc.getStyle("default");
if(s != null)
  writeStyle( s );
     }
 }
项目:dipGame    文件:JTextPaneAppend.java   
public void append2(String s, Color color, Boolean bold){
    StyledDocument doc = super.getStyledDocument();
    SimpleAttributeSet sa = new SimpleAttributeSet();
    StyleConstants.setAlignment(sa, StyleConstants.ALIGN_JUSTIFIED);
    StyleConstants.setLeftIndent(sa, 5);
    StyleConstants.setRightIndent(sa, 5);
    Style style = doc.addStyle("name", null);
    StyleConstants.setForeground(style, color);
    StyleConstants.setBold(style, bold);
    try {
        doc.insertString(doc.getLength(), s, style);
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    doc.setParagraphAttributes(0, doc.getLength(), sa, false);
}
项目:dsworkbench    文件:AlgorithmLogPanel.java   
/** Creates new form AlgorithmLogPanel */
public AlgorithmLogPanel() {
    initComponents();
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();

    // Create a style object and then set the style attributes
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    Style infoStyle = doc.addStyle("Info", null);
    StyleConstants.setItalic(infoStyle, true);
    StyleConstants.setFontFamily(infoStyle, "SansSerif");
    StyleConstants.setForeground(infoStyle, Color.LIGHT_GRAY);
    Style errorStyle = doc.addStyle("Error", null);
    StyleConstants.setFontFamily(errorStyle, "SansSerif");
    StyleConstants.setForeground(errorStyle, Color.RED);
    dateFormat = new SimpleDateFormat("HH:mm:ss");
}
项目:WorldGrower    文件:JTextPaneUtils.java   
public static void appendIconAndText(JTextPane textPane, Image image, String message) {
    StyledDocument document = (StyledDocument)textPane.getDocument();
    image = StatusMessageImageConverter.convertImage(image);

       try {
        JLabel jl  = JLabelFactory.createJLabel("<html>" + message + "</html>", image);
        jl.setHorizontalAlignment(SwingConstants.LEFT);

        String styleName = "style"+message;
        Style textStyle = document.addStyle(styleName, null);
        StyleConstants.setComponent(textStyle, jl);

        document.insertString(document.getLength(), " ", document.getStyle(styleName));
    } catch (BadLocationException e) {
        throw new IllegalStateException(e);
    }
}
项目:WorldGrower    文件:JTextPaneUtils.java   
public static void appendIcon(JTextPane textPane, Image image) {
    StyledDocument document = (StyledDocument)textPane.getDocument();
    image = StatusMessageImageConverter.convertImage(image);

       try {
        JLabel jl  = JLabelFactory.createJLabel(image);
        jl.setHorizontalAlignment(SwingConstants.LEFT);

        String styleName = "style"+image.toString();
        Style textStyle = document.addStyle(styleName, null);
        StyleConstants.setComponent(textStyle, jl);

        document.insertString(document.getLength(), " ", document.getStyle(styleName));
    } catch (BadLocationException e) {
        throw new IllegalStateException(e);
    }
}
项目:WorldGrower    文件:JTextPaneUtils.java   
public static void appendTextUsingLabel(JTextPane textPane, String message) {
    StyledDocument document = (StyledDocument)textPane.getDocument();

       try {
        JLabel jl  = JLabelFactory.createJLabel(message);
        jl.setHorizontalAlignment(SwingConstants.LEFT);

        String styleName = "style"+message;
        Style textStyle = document.addStyle(styleName, null);
        StyleConstants.setComponent(textStyle, jl);

        document.insertString(document.getLength(), " ", document.getStyle(styleName));
    } catch (BadLocationException e) {
        throw new IllegalStateException(e);
    }
}
项目:groovy    文件:ConsoleSupport.java   
protected void addStylesToDocument(JTextPane outputArea) {
    StyledDocument doc = outputArea.getStyledDocument();

    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

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

    promptStyle = doc.addStyle("prompt", regular);
    StyleConstants.setForeground(promptStyle, Color.BLUE);

    commandStyle = doc.addStyle("command", regular);
    StyleConstants.setForeground(commandStyle, Color.MAGENTA);

    outputStyle = doc.addStyle("output", regular);
    StyleConstants.setBold(outputStyle, true);
}
项目:dipGame    文件:WhiteTextArea.java   
public void append(String s, Color color, Boolean bold) {
    try {
        StyledDocument doc = (StyledDocument) text.getDocument();
        Style style = doc.addStyle("name", null);
        StyleConstants.setForeground(style, color);
        StyleConstants.setBold(style, bold);
        doc.insertString(doc.getLength(), s, style);

        // Determine whether the scrollbar is currently at the very bottom
        // position.
        JScrollBar vbar = scrollpane.getVerticalScrollBar();
        boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar
                .getMaximum());

        // append to the JTextArea (that's wrapped in a JScrollPane named
        // 'scrollPane'
        // now scroll if we were already at the bottom.
        if (autoScroll) {
            text.setCaretPosition(text.getDocument().getLength());
        }
    } catch (BadLocationException exc) {
        exc.printStackTrace();
    }
}
项目:autoweka    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:umple    文件:ReaderToTextPane.java   
/**
 * Sets up the thread.
 *
 * @param input     the Reader to monitor
 * @param output    the TextArea to send output to
 * @param color the color to use
 */
public ReaderToTextPane(Reader input, JTextPane output, Color color) {
  StyledDocument      doc;
  Style               style;

  setDaemon(true);

  m_Color  = color;
  m_Input  = new LineNumberReader(input);
  m_Output = output;

  doc   = m_Output.getStyledDocument();
  style = StyleContext.getDefaultStyleContext()
                      .getStyle(StyleContext.DEFAULT_STYLE);
  style = doc.addStyle(getStyleName(), style);
  StyleConstants.setFontFamily(style, "monospaced");
  StyleConstants.setForeground(style, m_Color);
}
项目:jarman    文件:ExploreFileDlg.java   
/**
 * Add styles to the document.
 * 
 * @param doc the StyledDocument to add styles to
 */
protected void addStylesToDocument(final StyledDocument doc)
{
  //Initialize some styles.
  Style def = StyleContext.getDefaultStyleContext().
                  getStyle(StyleContext.DEFAULT_STYLE);

  Style regular = doc.addStyle("regular", def);
  StyleConstants.setFontFamily(def, "SansSerif");
  StyleConstants.setFontSize(def, 12);
  StyleConstants.setLineSpacing(def, 2.0f);

  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, 14);
}
项目:dipGame    文件:TextBox.java   
public void append(String s, Color color, Boolean bold) {
    try {
        StyledDocument doc = super.getStyledDocument();
        SimpleAttributeSet sa = new SimpleAttributeSet();
        StyleConstants.setAlignment(sa, StyleConstants.ALIGN_JUSTIFIED);
        StyleConstants.setLeftIndent(sa, 10);
        StyleConstants.setRightIndent(sa, 10);
        StyleConstants.setSpaceAbove(sa, 5);
        StyleConstants.setSpaceBelow(sa, 5);
        Style style = doc.addStyle("name", null);
        StyleConstants.setForeground(style, color);
        StyleConstants.setBold(style, bold);
        doc.insertString(doc.getLength(), s, style);
        doc.setParagraphAttributes(0, doc.getLength(), sa, false);
    } catch (BadLocationException exc) {
        exc.printStackTrace();
    }
}