Java Code Examples for javax.swing.text.StyleConstants#setItalic()

The following examples show how to use javax.swing.text.StyleConstants#setItalic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeaGlassTextPaneUI.java    From seaglass with Apache License 2.0 7 votes vote down vote up
/**
 * 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());
    }
}
 
Example 2
Source File: OurConsole.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) {


        fontName = AlloyGraphics.matchBestFontName(fontName);

        MutableAttributeSet s = new SimpleAttributeSet();
        StyleConstants.setFontFamily(s, fontName);
        StyleConstants.setFontSize(s, fontSize);
        StyleConstants.setLineSpacing(s, -0.2f);
        StyleConstants.setBold(s, boldness);
        StyleConstants.setItalic(s, italic);
        StyleConstants.setForeground(s, color);
        StyleConstants.setLeftIndent(s, leftIndent);
        StyleConstants.setStrikeThrough(s, strike);
        return s;
    }
 
Example 3
Source File: AboutDialog.java    From Spade with GNU General Public License v3.0 6 votes vote down vote up
public static 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);
	StyleConstants.setBold(s, true);
}
 
Example 4
Source File: StackTraceColorizer.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
protected Collection<MessageFragmentStyle> colorizeStackTraceRegex(final Style style, String text, Pattern regex, int group) {
  ArrayList<MessageFragmentStyle> list = new ArrayList<>();
  Matcher matcher = regex.matcher(text);
  Style styleToUse = style;
  while (matcher.find()) {
    LocationInfo locationInfo = LocationInfo.parse(matcher.group(0));
    if (locationInfo != null) {
      String name = styleToUse.getName();
      Style newStyle = styleContext.addStyle(name + "-" + locationInfo.toString(), styleToUse);
      newStyle.addAttribute(STYLE_ATTRIBUTE_LOCATION_INFO, locationInfo);
      StyleConstants.setForeground(newStyle, StyleConstants.getForeground(styleToUse));
      StyleConstants.setBold(newStyle, StyleConstants.isBold(styleToUse));
      StyleConstants.setItalic(newStyle, StyleConstants.isItalic(styleToUse));
      styleToUse = newStyle;
    }
    int start = matcher.start(group);
    int end = matcher.end(group);
    if (end - start > 0) {
      MessageFragmentStyle messageFragmentStyle = new MessageFragmentStyle(start, end - start, styleToUse, false);
      list.add(messageFragmentStyle);
    }
  }
  return list;
}
 
Example 5
Source File: JConsole.java    From beanshell with Apache License 2.0 6 votes vote down vote up
private AttributeSet setStyle(
    String fontFamilyName,
    int size,
    Color color,
    boolean bold,
    boolean italic,
    boolean underline
    )
{
    MutableAttributeSet attr = new SimpleAttributeSet();
    if (color!=null)
        StyleConstants.setForeground(attr, color);
    if (fontFamilyName!=null)
        StyleConstants.setFontFamily(attr, fontFamilyName);
    if (size!=-1)
        StyleConstants.setFontSize(attr, size);
    StyleConstants.setBold(attr, bold);
    StyleConstants.setItalic(attr, italic);
    StyleConstants.setUnderline(attr, underline);

    setStyle(attr);

    return getStyle();
}
 
Example 6
Source File: StackTraceColorizer.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
protected void initStyles() {
  styleContext = new StyleContext();
  Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
  StyleConstants.setFontFamily(defaultStyle, "courier");
  styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle);

  StyleConstants.setBackground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_BACKGROUND));
  StyleConstants.setForeground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FOREGROUND));
  stylePackage = styleContext.addStyle("stylePackage", styleStackTrace);
  styleClass = styleContext.addStyle("styleClass", stylePackage);
  StyleConstants.setForeground(styleClass, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_CLASS));
  StyleConstants.setBold(styleClass, true);
  styleMethod = styleContext.addStyle("styleMethod", styleStackTrace);
  StyleConstants.setForeground(styleMethod, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_METHOD));
  StyleConstants.setItalic(styleMethod, true);
  StyleConstants.setBold(styleMethod, true);
  styleFile = styleContext.addStyle("styleFile", styleStackTrace);
  StyleConstants.setForeground(styleFile, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FLE));
  StyleConstants.setUnderline(styleFile, true);

  styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle);
  StyleConstants.setForeground(styleCodeComment, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_COMMENT));
  StyleConstants.setItalic(styleCodeComment, true);
}
 
Example 7
Source File: JConsole.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private AttributeSet setStyle(
		String fontFamilyName,
		int size,
		Color color,
		boolean bold,
		boolean italic,
		boolean underline
		)
{
	final MutableAttributeSet attr = new SimpleAttributeSet();
	if (color != null)
		StyleConstants.setForeground(attr, color);
	if (fontFamilyName != null)
		StyleConstants.setFontFamily(attr, fontFamilyName);
	if (size != -1)
		StyleConstants.setFontSize(attr, size);
	StyleConstants.setBold(attr, bold);
	StyleConstants.setItalic(attr, italic);
	StyleConstants.setUnderline(attr, underline);

	setStyle(attr);

	return getStyle();
}
 
Example 8
Source File: MagicTextPane.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public void updateTextWithIcons() {

		textPane.setText(textPane.getText().replaceAll("(?m)^[ \t]*\r?\n", ""));
		Pattern p = Pattern.compile(CardsPatterns.MANA_PATTERN.getPattern());
		Matcher m = p.matcher(textPane.getText());

		String text = textPane.getText();
		StyleContext context = new StyleContext();
		StyledDocument document = new DefaultStyledDocument(context);

		Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE);

		Style italic = context.addStyle("italicStyle", labelStyle);
		StyleConstants.setItalic(italic, true);

		int cumule = 0;
		try {
			document.insertString(0, text, null);
			while (m.find()) {
				Image ic = manaPanel.getManaSymbol(m.group());

				int width = 15;
				if (m.group().equals("{100}"))
					width = 30;

				JLabel label = new JLabel(new ImageIcon(ic.getScaledInstance(width, 15, Image.SCALE_DEFAULT)));
				label.setAlignmentY(SwingConstants.TOP);

				StyleConstants.setComponent(labelStyle, label);

				document.remove(m.start() + cumule, (m.end() - m.start()));
				document.insertString(m.start() + cumule, m.group(), labelStyle);
			}

			textPane.setDocument(document);
		} catch (BadLocationException e) {
			textPane.setText(text);
		}
	}
 
Example 9
Source File: DefenseCalculationSettingsPanel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form AttackSourcePanel
 */
DefenseCalculationSettingsPanel() {
    initComponents();
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    jInfoTextPane.setText(GENERAL_INFO);
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    dateFormat = new SimpleDateFormat("HH:mm:ss");
}
 
Example 10
Source File: RetimerCalculationPanel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form AttackSourcePanel
 */
RetimerCalculationPanel() {
    initComponents();
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    jInfoTextPane.setText(GENERAL_INFO);
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    dateFormat = new SimpleDateFormat("HH:mm:ss");
    retimes = new LinkedList<>();
}
 
Example 11
Source File: AttackCalculationPanel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form AttackSourcePanel
 */
AttackCalculationPanel() {
    initComponents();
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    jInfoTextPane.setText(GENERAL_INFO);
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    dateFormat = new SimpleDateFormat("HH:mm:ss");
}
 
Example 12
Source File: SupportRefillCalculationPanel.java    From dsworkbench with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form AttackSourcePanel
 */
SupportRefillCalculationPanel() {
    initComponents();
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    jInfoTextPane.setText(GENERAL_INFO);
    StyledDocument doc = (StyledDocument) jTextPane1.getDocument();
    Style defaultStyle = doc.addStyle("Default", null);
    StyleConstants.setItalic(defaultStyle, true);
    StyleConstants.setFontFamily(defaultStyle, "SansSerif");
    dateFormat = new SimpleDateFormat("HH:mm:ss");
}
 
Example 13
Source File: MWPaneFormatter.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Modify the italic attribute of a style.
 * 
 * @param style Style to be modified.
 * @param config Configuration.
 * @param configStyle Configuration of the style.
 */
private static void formatStyleItalic(
    Style style, Configuration config,
    ConfigurationValueStyle.StyleProperties configStyle) {
  StyleConstants.setItalic(
      style,
      configStyle.getItalic());
}
 
Example 14
Source File: CommentPanel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
  createComponents();
  layoutComponents();
  setupKeyMap();
  StyleConstants.setBold(bold, true);
  StyleConstants.setItalic(italic, true);
  setSize(300, 200);
  loadHistory();
  setupListeners();
}
 
Example 15
Source File: ChatMessagePanel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
private void init() {
  createComponents();
  layoutComponents();
  StyleConstants.setBold(bold, true);
  StyleConstants.setItalic(italic, true);
  setSize(300, 200);
}
 
Example 16
Source File: SyntaxDocument.java    From binnavi with Apache License 2.0 5 votes vote down vote up
public SyntaxDocument(final boolean addBraces) {
  doc = this;

  m_addBraces = addBraces;

  rootElement = doc.getDefaultRootElement();
  putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n");

  StyleConstants.setForeground(normal, Color.black);
  StyleConstants.setFontSize(normal, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(comment, Color.gray);
  StyleConstants.setItalic(comment, true);
  StyleConstants.setFontSize(comment, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(keyword, Color.blue.darker());
  StyleConstants.setFontSize(keyword, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(quote, Color.red);
  StyleConstants.setFontSize(quote, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(type, Color.PINK.darker());
  StyleConstants.setFontSize(type, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(number, Color.green.darker());
  StyleConstants.setFontSize(number, DEFAULT_FONT_SIZE);

  StyleConstants.setForeground(constant, Color.red.darker().darker());
  StyleConstants.setFontSize(constant, DEFAULT_FONT_SIZE);
}
 
Example 17
Source File: JViewPortBackingStoreImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void createStyles() {
    styles = new StyleContext();
    doc = new DefaultStyledDocument(styles);
    contentAttributes = new HashMap<>();

    // no attributes defined
    Style s = styles.addStyle(null, null);
    contentAttributes.put("none", s);

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

    Style heading = styles.addStyle("heading", def);
    StyleConstants.setFontFamily(heading, "SansSerif");
    StyleConstants.setBold(heading, true);
    StyleConstants.setAlignment(heading, StyleConstants.ALIGN_CENTER);
    StyleConstants.setSpaceAbove(heading, 10);
    StyleConstants.setSpaceBelow(heading, 10);
    StyleConstants.setFontSize(heading, 18);

    // Title
    Style sty = styles.addStyle("title", heading);
    StyleConstants.setFontSize(sty, 32);

    // author
    sty = styles.addStyle("author", heading);
    StyleConstants.setItalic(sty, true);
    StyleConstants.setSpaceBelow(sty, 25);
}
 
Example 18
Source File: EditableNotificationMessageElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void updateStyle(@Nonnull JEditorPane editorPane, @javax.annotation.Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
  super.updateStyle(editorPane, tree, value, selected, hasFocus);

  final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
  final Style linkStyle = htmlDocument.getStyleSheet().getStyle(LINK_STYLE);
  StyleConstants.setForeground(linkStyle, IdeTooltipManager.getInstance().getLinkForeground(false));
  StyleConstants.setItalic(linkStyle, true);
  HTMLDocument.Iterator iterator = htmlDocument.getIterator(HTML.Tag.A);
  while (iterator.isValid()) {
    boolean disabledLink = false;
    final AttributeSet attributes = iterator.getAttributes();
    if (attributes instanceof SimpleAttributeSet) {
      final Object attribute = attributes.getAttribute(HTML.Attribute.HREF);
      if (attribute instanceof String && disabledLinks.containsKey(attribute)) {
        disabledLink = true;
        //TODO [Vlad] add support for disabled link text update
        ////final String linkText = disabledLinks.get(attribute);
        //if (linkText != null) {
        //}
        ((SimpleAttributeSet)attributes).removeAttribute(HTML.Attribute.HREF);
      }
      if (attribute == null) {
        disabledLink = true;
      }
    }
    if (!disabledLink) {
      htmlDocument.setCharacterAttributes(
              iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset(), linkStyle, false);
    }
    iterator.next();
  }
}
 
Example 19
Source File: GroovyFilter.java    From groovy with Apache License 2.0 4 votes vote down vote up
private void init() {
    StyleContext styleContext = StyleContext.getDefaultStyleContext();
    Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);

    Style comment = styleContext.addStyle(COMMENT, defaultStyle);
    StyleConstants.setForeground(comment, COMMENT_COLOR);
    StyleConstants.setItalic(comment, true);

    Style quotes = styleContext.addStyle(QUOTES, defaultStyle);
    StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker());

    Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle);
    StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker());

    Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle);
    StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker());

    Style digit = styleContext.addStyle(DIGIT, defaultStyle);
    StyleConstants.setForeground(digit, Color.RED.darker());

    Style operation = styleContext.addStyle(OPERATION, defaultStyle);
    StyleConstants.setBold(operation, true);

    Style ident = styleContext.addStyle(IDENT, defaultStyle);

    Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle);
    StyleConstants.setBold(reservedWords, true);
    StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker());

    Style leftParens = styleContext.addStyle(IDENT, defaultStyle);

    getRootNode().putStyle(SLASH_STAR_COMMENT, comment);
    getRootNode().putStyle(SLASH_SLASH_COMMENT, comment);
    getRootNode().putStyle(QUOTES, quotes);
    getRootNode().putStyle(SINGLE_QUOTES, charQuotes);
    getRootNode().putStyle(SLASHY_QUOTES, slashyQuotes);

    getRootNode().putStyle(new String[] {
        HEX_INTEGER_LITERAL,
        OCTAL_INTEGER_LITERAL,
        BINARY_INTEGER_LITERAL,
        DECIMAL_FLOATING_POINT_LITERAL,
        HEXADECIMAL_FLOATING_POINT_LITERAL,
        DECIMAL_INTEGER_LITERAL,
    }, digit);

    getRootNode().putStyle(OPERATION, operation);
    StructuredSyntaxDocumentFilter.LexerNode node = createLexerNode();
    node.putStyle(RESERVED_WORDS, reservedWords);
    node.putStyle(LEFT_PARENS, leftParens);
    getRootNode().putChild(OPERATION, node);

    getRootNode().putStyle(IDENT, ident);
    node = createLexerNode();
    node.putStyle(RESERVED_WORDS, reservedWords);
    getRootNode().putChild(IDENT, node);
}
 
Example 20
Source File: StyleProperties.java    From otroslogviewer with Apache License 2.0 4 votes vote down vote up
public static Style getStyle(Theme.Type themeType,StyleContext styleContext, DataConfiguration styleConfig, String styleName, int group) {
  Style style = styleContext.addStyle(styleName, styleContext.getStyle(StyleContext.DEFAULT_STYLE));

  final String groupSuffix;
  if (group <= 0) {
    groupSuffix = "";
  } else {
    groupSuffix = "." + group;
  }

  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));
  }

  String theme;
  if (themeType.equals(Theme.Type.Light)) {
    theme = "light";
  } else {
    theme = "dark";
  }

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

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

  return style;
}