/** * Append prompt to textpane, measure prompt the first time is used. * @param isAddingPrompt Should we measure prompt length? */ public void displayPrompt(boolean isAddingPrompt) { StyleConstants.setUnderline(this.style, true); this.appendPrompt("jsql", Color.LIGHT_GRAY, isAddingPrompt); StyleConstants.setUnderline(this.style, false); this.appendPrompt(" " + this.labelShell, Color.LIGHT_GRAY, isAddingPrompt); this.appendPrompt("[", new Color(50, 191, 50), isAddingPrompt); this.appendPrompt(this.host, new Color(191, 191, 25), isAddingPrompt); this.appendPrompt("]", new Color(50, 191, 50), isAddingPrompt); this.appendPrompt(" >", new Color(191, 100, 100), isAddingPrompt); this.appendPrompt(" ", Color.LIGHT_GRAY, isAddingPrompt); }
StyleConstants.setBold(set, random.nextBoolean()); StyleConstants.setItalic(set, random.nextBoolean()); StyleConstants.setUnderline(set, random.nextBoolean());
public final void setUnderline(boolean status) { flush(); StyleConstants.setUnderline(currentAttributes,status); }
/** * Make a link style for the given URL. * * @param url * @return */ public MutableAttributeSet url(String url) { SimpleAttributeSet urlStyle = new SimpleAttributeSet(); StyleConstants.setUnderline(urlStyle, true); urlStyle.addAttribute(HTML.Attribute.HREF, url); return urlStyle; }
/** * Make a link style for the given URL. * * @param url * @param baseStyle * @return */ public MutableAttributeSet url(String url, AttributeSet baseStyle) { SimpleAttributeSet urlStyle = new SimpleAttributeSet(baseStyle); StyleConstants.setUnderline(urlStyle, true); urlStyle.addAttribute(HTML.Attribute.HREF, url); return urlStyle; }
public static AttributeSet createAttributeSet(Color foregroundColor, Color backgroundColor, Boolean bold, Boolean italic, Boolean strikethrough, Boolean underline) { MutableAttributeSet r = (MutableAttributeSet) createAttributeSet(foregroundColor, backgroundColor, bold, italic); if (strikethrough != null) { StyleConstants.setStrikeThrough(r, strikethrough); } if (underline != null) { StyleConstants.setUnderline(r, underline); } return r; } }
@Override public void run() { int startPos = findURLPos(text, 0); if (startPos != -1) { StyleConstants.setUnderline(urlAttr, true); final StyledDocument doc = (StyledDocument) fb.getDocument(); while (startPos != -1) { // The text always ends with \n, so the url either stops at the first space or the first \n int stopPos = text.indexOf(" ", startPos); if (stopPos == -1) { stopPos = text.indexOf("\n", startPos); } urlAttr.addAttribute(URL_ATTRIBUTE, text.substring(startPos, stopPos)); doc.setCharacterAttributes(offset + startPos, stopPos - startPos, urlAttr, false); startPos = findURLPos(text, stopPos); } } } });
/** * Inserts a network address into the current document. * * @param address - the address to insert( ex. \superpc\etc\file\ OR http://localhost/ ) * @throws BadLocationException if the location is not available for insertion. */ public void insertAddress( Document doc, String address ) throws BadLocationException { // Create a new style, based on the style used for generic text, for the address. final MutableAttributeSet addressStyle = new SimpleAttributeSet( getMessageStyle().copyAttributes() ); StyleConstants.setForeground( addressStyle, (Color) UIManager.get( "Address.foreground" ) ); StyleConstants.setUnderline( addressStyle, true ); addressStyle.addAttribute( "link", address ); doc.insertString( doc.getLength(), address, addressStyle ); }
/** * Inserts a link into the current document. * * @param link - the link to insert( ex. http://www.javasoft.com ) * @throws BadLocationException if the location is not available for insertion. */ public void insertLink( Document doc, String link ) throws BadLocationException { // Create a new style, based on the style used for generic text, for the link. final MutableAttributeSet linkStyle = new SimpleAttributeSet( getMessageStyle().copyAttributes() ); StyleConstants.setForeground( linkStyle, (Color) UIManager.get( "Link.foreground" ) ); StyleConstants.setUnderline( linkStyle, true ); linkStyle.addAttribute( "link", link ); doc.insertString( doc.getLength(), link, linkStyle ); }
private void createStyles() { createStyle( "PLAIN", Color.BLACK, false, "PLAIN" ); final Style comment = createStyle( "COMMENT", Color.GRAY, false, "COMMENT" ); StyleConstants.setItalic( comment, true ); final Style error = createStyle( "ERROR", Color.RED, false, "ERROR" ); StyleConstants.setUnderline( error, true ); createStyle( "PIPE_BIT", Color.BLUE, false, "PIPE_BIT" ); createStyle( "BOLD_PIPE_BIT", Color.BLUE, "BOLD_PIPE_BIT" ); createStyle( "PARAMETER", Color.YELLOW, "PARAMETER" ); createStyle( "LOAD", Color.MAGENTA, "load" ); createStyle( "PACKAGE", Color.YELLOW.darker(), "package" ); createStyle( "SET", Color.ORANGE.darker(), "set", "cli" ); createStyle( "READER", Color.GREEN.darker().darker(), "reader", "readFiles" ); createStyle( "ADD", Color.CYAN.darker().darker(), "add", "addLogged", "addDescription", "addLast" ); createStyle( "WRITE_XMI", Color.BLUE.darker(), "writeXmis", "collectCuis", "collectEntities" ); }
public MutableAttributeSet replacement(String text, String replacement) { SimpleAttributeSet style = new SimpleAttributeSet(standard()); StyleConstants.setUnderline(style, true); style.addAttribute(Attribute.IS_REPLACEMENT, true); style.addAttribute(Attribute.REPLACEMENT_FOR, text); style.addAttribute(Attribute.REPLACED_WITH, replacement); return style; }
@Override public void run() { StyledDocument doc = pane.getStyledDocument(); Style hlStyle = doc.addStyle("regularBlue-findtype", defStyle); // NOI18N hlStyle.addAttribute(HyperlinkSupport.TYPE_ATTRIBUTE, new TypeLink()); StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor()); StyleConstants.setUnderline(hlStyle, true); List<Integer> l = Collections.emptyList(); try { l = getHighlightOffsets(doc.getText(0, doc.getLength())); } catch (BadLocationException ex) { Support.LOG.log(Level.SEVERE, null, ex); } List<Highlight> highlights = new ArrayList<Highlight>(l.size()); for (int i = 0; i < l.size(); i++) { highlights.add(new Highlight(l.get(i), l.get(++i))); } pane.putClientProperty(HIGHLIGHTS_PROPERTY, highlights); pane.removeMouseMotionListener(FindTypesSupport.this); pane.addMouseMotionListener(FindTypesSupport.this); pane.removeMouseListener(FindTypesSupport.this); pane.addMouseListener(FindTypesSupport.this); } });
/** * Generate an attribute set for links. * * @param action * the action to perform * @return the attribute set */ public static SimpleAttributeSet getActionStyle(ActionListener action) { SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setForeground(style, Color.blue); StyleConstants.setUnderline(style, true); StyleConstants.setFontFamily(style, FONT); StyleConstants.setFontSize(style, FONT_SIZE); style.addAttribute(ACTION_ATTRIBUTE, action); return style; }
protected AttributeSet getStyle() { final MutableAttributeSet style = new SimpleAttributeSet(); StyleConstants.setFontFamily( style, "Dialog" ); StyleConstants.setFontSize( style, SettingsManager.getLocalPreferences().getChatRoomFontSize() ); StyleConstants.setForeground( style, textColor ); StyleConstants.setBold( style, bold ); StyleConstants.setItalic( style, italic ); StyleConstants.setUnderline( style, underline ); StyleConstants.setStrikeThrough( style, strikeThrough ); return style; }
@Override public void run() { Style defStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); final Style hlStyle = doc.addStyle("regularBlue-link", defStyle); // NOI18N hlStyle.addAttribute(LINK_ATTRIBUTE, link); StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor()); StyleConstants.setUnderline(hlStyle, true); for (int i=0; i<pos.length; i+=2) { int off = pos[i]; int length = pos[i+1]-pos[i]; doc.setCharacterAttributes(off, length, hlStyle, true); } pane.removeMouseListener(mouseListener); pane.addMouseListener(mouseListener); } });
@Override public void run() { Style defStyle = StyleContext.getDefaultStyleContext() .getStyle(StyleContext.DEFAULT_STYLE); final Style hlStyle = doc.addStyle("regularBlue-url", defStyle); //NOI18N hlStyle.addAttribute(HyperlinkSupport.URL_ATTRIBUTE, new UrlAction()); StyleConstants.setForeground(hlStyle, UIUtils.getLinkColor()); StyleConstants.setUnderline(hlStyle, true); for (int i = 0; i < boundaries.length; i+=2) { doc.setCharacterAttributes(boundaries[i], boundaries[i + 1] - boundaries[i], hlStyle, true); } pane.removeMouseListener(getUrlMouseListener()); pane.addMouseListener(getUrlMouseListener()); } });
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_REGULAR, baseStyle ); StyleConstants.setFontFamily( regularStyle, Font.MONOSPACED ); StyleConstants.setFontSize( regularStyle, 12 ); Style hyperStyle = result.addStyle( STYLE_HYPERLINK, regularStyle ); StyleConstants.setForeground( hyperStyle, COLOR_HYPER ); StyleConstants.setUnderline( hyperStyle, true ); Style titleStyle = result.addStyle( STYLE_TITLE, baseStyle ); StyleConstants.setFontFamily( titleStyle, Font.SANS_SERIF ); StyleConstants.setFontSize( titleStyle, 24 ); StyleConstants.setBold( titleStyle, true ); return result; } }
Object underline = font.getAttributes().get(TextAttribute.UNDERLINE); boolean canUnderline = underline instanceof Integer && (Integer) underline != -1; StyleConstants.setUnderline(attr, canUnderline); getStyle("default").addAttributes(attr);
public String getStyle(StyleData styleData) { String styleName = styleData.getStyleName(); Style style = document.getStyle(styleName); if (style == null) { Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); style = document.addStyle(styleName, defaultStyle); } if(styleData.fontFamily != null) { StyleConstants.setFontFamily(style, styleData.fontFamily); } if(styleData.fontSize > 0) { StyleConstants.setFontSize(style, styleData.fontSize); } if(styleData.color != null) { StyleConstants.setForeground(style, styleData.color); } if(styleData.bgColor != null) { StyleConstants.setBackground(style, styleData.bgColor); } StyleConstants.setBold(style, styleData.bold); StyleConstants.setItalic(style, styleData.italic); StyleConstants.setUnderline(style, styleData.underline); StyleConstants.setStrikeThrough(style, styleData.strikeThrough); StyleConstants.setSubscript(style, styleData.subscript); StyleConstants.setSuperscript(style, styleData.superscript); return styleName; }
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); }