use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class EventLog method formatForLog.
public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
DocumentImpl logDoc = new DocumentImpl("", true);
AtomicBoolean showMore = new AtomicBoolean(false);
Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
List<RangeMarker> lineSeparators = new ArrayList<>();
String title = notification.getTitle();
String subtitle = notification.getSubtitle();
if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
title += " (" + subtitle + ")";
}
title = truncateLongString(showMore, title);
String content = truncateLongString(showMore, notification.getContent());
RangeMarker afterTitle = null;
boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
if (StringUtil.isNotEmpty(title)) {
if (StringUtil.isNotEmpty(content)) {
appendText(logDoc, ": ");
afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
}
}
int titleLength = logDoc.getTextLength();
hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
List<AnAction> actions = notification.getActions();
if (!actions.isEmpty()) {
String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {
private int index;
@Override
public String fun(AnAction action) {
return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
}
}, isLongLine(actions) ? "<br>" : " ") + "</p>";
Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
}
});
if (title.length() > 0 || content.length() > 0) {
lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
}
hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
}
String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
for (RangeMarker marker : links.keySet()) {
if (!marker.isValid()) {
showMore.set(true);
continue;
}
list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
}
if (showMore.get()) {
String sb = "show balloon";
if (!logDoc.getText().endsWith(" ")) {
appendText(logDoc, " ");
}
appendText(logDoc, "(" + sb + ")");
list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
}
return new LogEntry(logDoc.getText(), status, list, titleLength);
}
use of javax.swing.event.HyperlinkEvent 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.event.HyperlinkEvent in project intellij-community by JetBrains.
the class FileInEditorProcessor method processCode.
public void processCode() {
if (myShouldOptimizeImports) {
myProcessor = new OptimizeImportsProcessor(myProject, myFile);
}
if (myProcessChangesTextOnly && !FormatChangedTextUtil.hasChanges(myFile)) {
myNoChangesDetected = true;
}
myProcessor = mixWithReformatProcessor(myProcessor);
if (myShouldRearrangeCode) {
myProcessor = mixWithRearrangeProcessor(myProcessor);
}
if (shouldNotify()) {
myProcessor.setCollectInfo(true);
myProcessor.setPostRunnable(() -> {
String message = prepareMessage();
if (!myEditor.isDisposed() && myEditor.getComponent().isShowing()) {
HyperlinkListener hyperlinkListener = new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
AnAction action = ActionManager.getInstance().getAction("ShowReformatFileDialog");
DataManager manager = DataManager.getInstance();
if (manager != null) {
DataContext context = manager.getDataContext(myEditor.getContentComponent());
action.actionPerformed(AnActionEvent.createFromAnAction(action, null, "", context));
}
}
};
showHint(myEditor, message, hyperlinkListener);
}
});
}
myProcessor.run();
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class DvcsBranchPopup method notifyAboutSyncedBranches.
private void notifyAboutSyncedBranches() {
String description = "You have several " + myVcs.getDisplayName() + " roots in the project and they all are checked out at the same branch. " + "We've enabled synchronous branch control for the project. <br/>" + "If you wish to control branches in different roots separately, " + "you may <a href='settings'>disable</a> the setting.";
NotificationListener listener = new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myVcs.getConfigurable().getDisplayName());
if (myVcsSettings.getSyncSetting() == DvcsSyncSettings.Value.DONT_SYNC) {
notification.expire();
}
}
}
};
VcsNotifier.getInstance(myProject).notifyImportantInfo("Synchronous branch control enabled", description, listener);
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class IntentionDescriptionPanel method setupPoweredByPanel.
private void setupPoweredByPanel(final IntentionActionMetaData actionMetaData) {
PluginId pluginId = actionMetaData == null ? null : actionMetaData.getPluginId();
JComponent owner;
if (pluginId == null) {
@NonNls String label = XmlStringUtil.wrapInHtml("<b>" + ApplicationNamesInfo.getInstance().getFullProductName() + "</b>");
owner = new JLabel(label);
} else {
final IdeaPluginDescriptor pluginDescriptor = PluginManager.getPlugin(pluginId);
HyperlinkLabel label = new HyperlinkLabel(CodeInsightBundle.message("powered.by.plugin", pluginDescriptor.getName()));
label.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
final PluginManagerConfigurable pluginConfigurable = new PluginManagerConfigurable(PluginManagerUISettings.getInstance());
final Project project = ProjectManager.getInstance().getDefaultProject();
util.editConfigurable(project, pluginConfigurable, () -> pluginConfigurable.select(pluginDescriptor));
}
});
owner = label;
}
//myPoweredByContainer.setVisible(true);
myPoweredByPanel.removeAll();
myPoweredByPanel.add(owner, BorderLayout.CENTER);
}
Aggregations