List of usage examples for javax.swing.text StyleContext DEFAULT_STYLE
String DEFAULT_STYLE
To view the source code for javax.swing.text StyleContext DEFAULT_STYLE.
Click Source Link
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Formats the text and displays it in a {@link JTextPane}. * /*from w ww .j a va2 s . c o m*/ * @param text The text to display. * @param foreground The foreground color. * @return See above. */ public static JTextPane buildTextPane(String text, Color foreground) { if (text == null) text = ""; StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_LEFT); if (foreground != null) StyleConstants.setForeground(style, foreground); try { document.insertString(document.getLength(), text, style); } catch (BadLocationException e) { } JTextPane textPane = new JTextPane(document); textPane.setOpaque(false); textPane.setEditable(false); textPane.setFocusable(false); return textPane; }
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:pl.otros.logview.gui.message.editor.MessageColorizerEditor.java
protected void refreshView() { LOGGER.info("refreshing view"); Style defaultStyle = textPane.getStyle(StyleContext.DEFAULT_STYLE); String text = textPane.getText(); textPane.getStyledDocument().setCharacterAttributes(0, text.length(), defaultStyle, true); try {//w w w . j a v a 2 s . c om PropertyPatternMessageColorizer propertyPatternMessageColorize = createMessageColorizer(); if (propertyPatternMessageColorize.colorizingNeeded(text)) { Collection<MessageFragmentStyle> colorize = propertyPatternMessageColorize.colorize(text); for (MessageFragmentStyle mfs : colorize) { textPane.getStyledDocument().setCharacterAttributes(mfs.getOffset(), mfs.getLength(), mfs.getStyle(), mfs.isReplace()); } } } catch (Exception e) { LOGGER.severe(String.format("Can't init PropertyPatternMessageColorizer:%s", e.getMessage())); statusObserver.updateStatus(String.format("Error: %s", e.getMessage()), StatusObserver.LEVEL_ERROR); } }
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 w w w. j a v a2 s.c om 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.SearchResultColorizer.java
@Override public Collection<MessageFragmentStyle> colorize(String textToColorize) throws BadLocationException { Collection<MessageFragmentStyle> list = new ArrayList<MessageFragmentStyle>(); if (StringUtils.isEmpty(searchString)) { return list; }/*from www .j a v a2 s .co m*/ StyleContext sc = new StyleContext(); Style searchStyle = sc.addStyle("searchResult", sc.getStyle(StyleContext.DEFAULT_STYLE)); StyleConstants.setBackground(searchStyle, color); if (searchMode.equals(SearchMode.STRING_CONTAINS)) { list.addAll(colorizeString(textToColorize, searchStyle, searchString)); } else if (searchMode.equals(SearchMode.REGEX)) { list.addAll(MessageColorizerUtils.colorizeRegex(searchStyle, textToColorize, Pattern.compile(searchString, Pattern.CASE_INSENSITIVE), 0)); } for (MessageFragmentStyle style : list) { style.setSearchResult(true); } return list; }
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 . j a 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>()); }
From source file:simplealbum.mvc.autocomplete.DController.java
void changeSeeker(Seeker seeker) { view.setTitle(seeker.getTitle());/*from w w w. j a v a 2 s. c o m*/ // jTextPane.setText(""); TODO model.emptyList(); model.setSeeker(seeker); request(); List<String> colors = seeker.getColors(); styles = new Style[colors.size()]; StyleContext sc = new StyleContext(); for (int i = 0; i < colors.size(); i++) { styles[i] = sc.addStyle((String) colors.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE)); StyleConstants.setForeground(styles[i], ColorUtils.getColorByName(colors.get(i))); StyleConstants.setBold(styles[i], true); } colorInputText(); filter = seeker.getFilter(); }
From source file:simplealbum.mvc.autocomplete.JTextPaneX.java
public JTextPaneX() { //Create the style array to show the colors // List<Object> colorList = CONFIGURATION.getList("ColorWord"); List<Object> colorList = null; styles = new Style[colorList.size()]; StyleContext sc = new StyleContext(); for (int i = 0; i < colorList.size(); i++) { styles[i] = sc.addStyle((String) colorList.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE)); StyleConstants.setForeground(styles[i], ColorUtils.getColorByName((String) colorList.get(i))); StyleConstants.setBold(styles[i], true); }//from w ww . j a v a 2 s.c o m //Get the document for adding a document listener dsd = (DefaultStyledDocument) getDocument(); dsd.addDocumentListener(new DocumentListenerTextPane()); //...and setting a document filter documentFilter = new MyDocumentFilter(); dsd.setDocumentFilter(documentFilter); }