use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class ChatPane method onWhisper.
public void onWhisper(MessageWrapper m) {
SimpleAttributeSet senderSet, receiverSet;
String sender = m.getLocal().getSender();
String receiver = (String) m.getLocal().getExtra();
print(m, "\n" + getTime(), GUIMain.norm);
User senderUser = Settings.channelManager.getUser(sender, true);
User receiverUser = Settings.channelManager.getUser(receiver, true);
senderSet = getUserSet(senderUser);
receiverSet = getUserSet(receiverUser);
//name stuff
print(m, " ", GUIMain.norm);
FaceManager.handleNameFaces(sender, senderSet);
FaceManager.handleNameFaces(receiverUser.getNick(), receiverSet);
print(m, senderUser.getDisplayName(), senderSet);
print(m, " (whisper)-> ", GUIMain.norm);
print(m, receiverUser.getDisplayName(), receiverSet);
print(m, ": ", GUIMain.norm);
printMessage(m, m.getLocal().getContent(), GUIMain.norm, senderUser);
}
use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class ChatPane method getUserSet.
private SimpleAttributeSet getUserSet(User u) {
SimpleAttributeSet user = new SimpleAttributeSet();
StyleConstants.setFontFamily(user, Settings.font.getValue().getFamily());
StyleConstants.setFontSize(user, Settings.font.getValue().getSize());
StyleConstants.setForeground(user, Utils.getColorFromUser(u));
user.addAttribute(HTML.Attribute.NAME, determineName(u));
return user;
}
use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class FaceManager method insertFaceMetadata.
private static void insertFaceMetadata(Face f, Map<Integer, Integer> ranges, Map<Integer, SimpleAttributeSet> rangeStyles, String regex, String object) {
boolean isFFZ = f instanceof FrankerFaceZ;
Pattern p = Pattern.compile(isFFZ ? f.getRegex() : regex);
Matcher m = p.matcher(object);
while (m.find() && !GUIMain.shutDown) {
int start = m.start();
int end = m.end() - 1;
if (!Utils.inRanges(start, ranges) && !Utils.inRanges(end, ranges)) {
ranges.put(start, end);
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute("faceinfo", f);
attrs.addAttribute(isFFZ ? "channel" : "regex", isFFZ ? regex : m.group());
insertFace(attrs, f.getFilePath());
attrs.addAttribute("start", start);
rangeStyles.put(start, attrs);
}
}
}
use of javax.swing.text.SimpleAttributeSet in project intellij-community by JetBrains.
the class UnusedDeclarationPresentation method getCustomPreviewPanel.
@Override
public JComponent getCustomPreviewPanel(RefEntity entity) {
final Project project = entity.getRefManager().getProject();
JEditorPane htmlView = new JEditorPane() {
@Override
public String getToolTipText(MouseEvent evt) {
int pos = viewToModel(evt.getPoint());
if (pos >= 0) {
HTMLDocument hdoc = (HTMLDocument) getDocument();
javax.swing.text.Element e = hdoc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
SimpleAttributeSet value = (SimpleAttributeSet) a.getAttribute(HTML.Tag.A);
if (value != null) {
String objectPackage = (String) value.getAttribute("qualifiedname");
if (objectPackage != null) {
return objectPackage;
}
}
}
return null;
}
};
htmlView.setContentType(UIUtil.HTML_MIME);
htmlView.setEditable(false);
htmlView.setOpaque(false);
htmlView.setBackground(UIUtil.getLabelBackground());
htmlView.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
URL url = e.getURL();
if (url == null) {
return;
}
@NonNls String ref = url.getRef();
int offset = Integer.parseInt(ref);
String fileURL = url.toExternalForm();
fileURL = fileURL.substring(0, fileURL.indexOf('#'));
VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
if (vFile == null) {
vFile = VfsUtil.findFileByURL(url);
}
if (vFile != null) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, offset);
FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
}
});
final StyleSheet css = ((HTMLEditorKit) htmlView.getEditorKit()).getStyleSheet();
css.addRule("p.problem-description-group {text-indent: " + JBUI.scale(9) + "px;font-weight:bold;}");
css.addRule("div.problem-description {margin-left: " + JBUI.scale(9) + "px;}");
css.addRule("ul {margin-left:" + JBUI.scale(10) + "px;text-indent: 0}");
css.addRule("code {font-family:" + UIUtil.getLabelFont().getFamily() + "}");
final StringBuffer buf = new StringBuffer();
getComposer().compose(buf, entity, false);
final String text = buf.toString();
SingleInspectionProfilePanel.readHTML(htmlView, SingleInspectionProfilePanel.toHTML(htmlView, text, false));
return ScrollPaneFactory.createScrollPane(htmlView, true);
}
use of javax.swing.text.SimpleAttributeSet in project intellij-community by JetBrains.
the class EditableNotificationMessageElement method updateStyle.
protected void updateStyle(@NotNull JEditorPane editorPane, @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();
}
}
Aggregations