use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class SheetController method createSheetPanel.
private JPanel createSheetPanel(String title, String message, JButton[] buttons) {
JPanel sheetPanel = new JPanel() {
@Override
protected void paintComponent(@NotNull Graphics g2d) {
final Graphics2D g = (Graphics2D) g2d.create();
super.paintComponent(g);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getSheetAlpha()));
g.setColor(new JBColor(Gray._230, UIUtil.getPanelBackground()));
Rectangle2D dialog = new Rectangle2D.Double(SHADOW_BORDER, 0, SHEET_WIDTH, SHEET_HEIGHT);
paintShadow(g);
// draw the sheet background
if (UIUtil.isUnderDarcula()) {
g.fillRoundRect((int) dialog.getX(), (int) dialog.getY() - 5, (int) dialog.getWidth(), (int) (5 + dialog.getHeight()), 5, 5);
} else {
//todo make bottom corners
g.fill(dialog);
}
paintShadowFromParent(g);
}
};
sheetPanel.setOpaque(false);
sheetPanel.setLayout(null);
JPanel ico = new JPanel() {
@Override
protected void paintComponent(@NotNull Graphics g) {
super.paintComponent(g);
myIcon.paintIcon(this, g, 0, 0);
}
};
JEditorPane headerLabel = new JEditorPane();
headerLabel.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
headerLabel.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
headerLabel.setEditable(false);
headerLabel.setContentType("text/html");
headerLabel.setSize(250, Short.MAX_VALUE);
headerLabel.setText(title);
headerLabel.setSize(250, headerLabel.getPreferredSize().height);
headerLabel.setOpaque(false);
headerLabel.setFocusable(false);
sheetPanel.add(headerLabel);
headerLabel.repaint();
messageTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
Font font = UIUtil.getLabelFont(UIUtil.FontSize.SMALL);
messageTextPane.setFont(font);
messageTextPane.setEditable(false);
messageTextPane.setContentType("text/html");
messageTextPane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent he) {
if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
URL url = he.getURL();
if (url != null) {
Desktop.getDesktop().browse(url.toURI());
} else {
LOG.warn("URL is null; HyperlinkEvent: " + he.toString());
}
} catch (IOException | URISyntaxException e) {
LOG.error(e);
}
}
}
}
});
FontMetrics fontMetrics = sheetPanel.getFontMetrics(font);
int widestWordWidth = 250;
String[] words = (message == null) ? ArrayUtil.EMPTY_STRING_ARRAY : message.split(SPACE_OR_LINE_SEPARATOR_PATTERN);
for (String word : words) {
widestWordWidth = Math.max(fontMetrics.stringWidth(word), widestWordWidth);
}
messageTextPane.setSize(widestWordWidth, Short.MAX_VALUE);
messageTextPane.setText(handleBreaks(message));
messageArea.setSize(widestWordWidth, messageTextPane.getPreferredSize().height);
SHEET_WIDTH = Math.max(LEFT_SHEET_OFFSET + widestWordWidth + RIGHT_OFFSET, SHEET_WIDTH);
messageTextPane.setSize(messageArea);
messageTextPane.setOpaque(false);
messageTextPane.setFocusable(false);
sheetPanel.add(messageTextPane);
messageTextPane.repaint();
ico.setOpaque(false);
ico.setSize(new Dimension(AllIcons.Logo_welcomeScreen.getIconWidth(), AllIcons.Logo_welcomeScreen.getIconHeight()));
ico.setLocation(LEFT_SHEET_PADDING, TOP_SHEET_PADDING);
sheetPanel.add(ico);
headerLabel.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING);
messageTextPane.setLocation(LEFT_SHEET_OFFSET, TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES);
SHEET_HEIGHT = TOP_SHEET_PADDING + headerLabel.getPreferredSize().height + GAP_BETWEEN_LINES + messageArea.height + GAP_BETWEEN_LINES;
if (myDoNotAskOption != null) {
layoutDoNotAskCheckbox(sheetPanel);
}
layoutWithAbsoluteLayout(buttons, sheetPanel);
int BOTTOM_SHEET_PADDING = 10;
SHEET_HEIGHT += BOTTOM_SHEET_PADDING;
if (SHEET_HEIGHT < SHEET_MINIMUM_HEIGHT) {
SHEET_HEIGHT = SHEET_MINIMUM_HEIGHT;
shiftButtonsToTheBottom(SHEET_MINIMUM_HEIGHT - SHEET_HEIGHT);
}
sheetPanel.setFocusCycleRoot(true);
recalculateShadow();
sheetPanel.setSize(SHEET_NC_WIDTH, SHEET_NC_HEIGHT);
return sheetPanel;
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class ApproveRemovedMappingsActivity method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
final Map<FileNameMatcher, Pair<FileType, Boolean>> map = ((FileTypeManagerImpl) FileTypeManager.getInstance()).getRemovedMappings();
if (!map.isEmpty()) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
for (Iterator<Map.Entry<FileNameMatcher, Pair<FileType, Boolean>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<FileNameMatcher, Pair<FileType, Boolean>> entry = iterator.next();
if (entry.getValue().getSecond()) {
continue;
}
final FileNameMatcher matcher = entry.getKey();
final FileType fileType = entry.getValue().getFirst();
Notification notification = new Notification("File type recognized", "File type recognized", "File extension " + matcher.getPresentableString() + " was reassigned to " + fileType.getName() + " <a href='revert'>Revert</a>", NotificationType.WARNING, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ApplicationManager.getApplication().runWriteAction(() -> {
FileTypeManager.getInstance().associate(PlainTextFileType.INSTANCE, matcher);
map.put(matcher, Pair.create(fileType, true));
});
notification.expire();
}
});
Notifications.Bus.notify(notification, project);
ApplicationManager.getApplication().runWriteAction(() -> FileTypeManager.getInstance().associate(fileType, matcher));
iterator.remove();
}
}
});
}
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class ExportTestResultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
LOG.assertTrue(project != null);
final ExportTestResultsConfiguration config = ExportTestResultsConfiguration.getInstance(project);
final String name = ExecutionBundle.message("export.test.results.filename", PathUtil.suggestFileName(myRunConfiguration.getName()));
String filename = name + "." + config.getExportFormat().getDefaultExtension();
boolean showDialog = true;
while (showDialog) {
final ExportTestResultsDialog d = new ExportTestResultsDialog(project, config, filename);
if (!d.showAndGet()) {
return;
}
filename = d.getFileName();
showDialog = getOutputFile(config, project, filename).exists() && Messages.showOkCancelDialog(project, ExecutionBundle.message("export.test.results.file.exists.message", filename), ExecutionBundle.message("export.test.results.file.exists.title"), Messages.getQuestionIcon()) != Messages.OK;
}
final String filename_ = filename;
ProgressManager.getInstance().run(new Task.Backgroundable(project, ExecutionBundle.message("export.test.results.task.name"), false, new PerformInBackgroundOption() {
@Override
public boolean shouldStartInBackground() {
return true;
}
@Override
public void processSentToBackground() {
}
}) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
final File outputFile = getOutputFile(config, project, filename_);
final String outputText;
try {
outputText = getOutputText(config);
if (outputText == null) {
return;
}
} catch (IOException | SAXException | TransformerException ex) {
LOG.warn(ex);
showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", ex.getMessage()), null);
return;
} catch (RuntimeException ex) {
ExportTestResultsConfiguration c = new ExportTestResultsConfiguration();
c.setExportFormat(ExportTestResultsConfiguration.ExportFormat.Xml);
c.setOpenResults(false);
try {
String xml = getOutputText(c);
LOG.error(LogMessageEx.createEvent("Failed to export test results", ExceptionUtil.getThrowableText(ex), null, null, new Attachment("dump.xml", xml)));
} catch (Throwable ignored) {
LOG.error("Failed to export test results", ex);
}
return;
}
final Ref<VirtualFile> result = new Ref<>();
final Ref<String> error = new Ref<>();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
result.set(ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
@Override
public VirtualFile compute() {
outputFile.getParentFile().mkdirs();
final VirtualFile parent = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(outputFile.getParentFile());
if (parent == null || !parent.isValid()) {
error.set(ExecutionBundle.message("failed.to.create.output.file", outputFile.getPath()));
return null;
}
try {
VirtualFile result = parent.findChild(outputFile.getName());
if (result == null) {
result = parent.createChildData(this, outputFile.getName());
}
VfsUtil.saveText(result, outputText);
return result;
} catch (IOException e) {
LOG.warn(e);
error.set(e.getMessage());
return null;
}
}
}));
}
});
if (!result.isNull()) {
if (config.isOpenResults()) {
openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
} else {
HyperlinkListener listener = new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
openEditorOrBrowser(result.get(), project, config.getExportFormat() == ExportTestResultsConfiguration.ExportFormat.Xml);
}
}
};
showBalloon(project, MessageType.INFO, ExecutionBundle.message("export.test.results.succeeded", outputFile.getName()), listener);
}
} else {
showBalloon(project, MessageType.ERROR, ExecutionBundle.message("export.test.results.failed", error.get()), null);
}
}
});
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class RenameProcessor method performRefactoring.
@Override
public void performRefactoring(@NotNull UsageInfo[] usages) {
List<Runnable> postRenameCallbacks = new ArrayList<>();
final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);
for (final PsiElement element : myAllRenames.keySet()) {
String newName = myAllRenames.get(element);
final RefactoringElementListener elementListener = getTransaction().getElementListener(element);
final RenamePsiElementProcessor renamePsiElementProcessor = RenamePsiElementProcessor.forElement(element);
Runnable postRenameCallback = renamePsiElementProcessor.getPostRenameCallback(element, newName, elementListener);
final Collection<UsageInfo> infos = classified.get(element);
try {
RenameUtil.doRename(element, newName, infos.toArray(new UsageInfo[infos.size()]), myProject, elementListener);
} catch (final IncorrectOperationException e) {
RenameUtil.showErrorMessage(e, element, myProject);
return;
}
if (postRenameCallback != null) {
postRenameCallbacks.add(postRenameCallback);
}
}
for (Runnable runnable : postRenameCallbacks) {
runnable.run();
}
List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<>();
for (UsageInfo usage : usages) {
if (usage instanceof NonCodeUsageInfo) {
nonCodeUsages.add((NonCodeUsageInfo) usage);
}
}
myNonCodeUsages = nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
if (!mySkippedUsages.isEmpty()) {
if (!ApplicationManager.getApplication().isUnitTestMode() && !ApplicationManager.getApplication().isHeadlessEnvironment()) {
ApplicationManager.getApplication().invokeLater(() -> {
final IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(myProject);
if (ideFrame != null) {
StatusBarEx statusBar = (StatusBarEx) ideFrame.getStatusBar();
HyperlinkListener listener = new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
return;
Messages.showMessageDialog("<html>Following usages were safely skipped:<br>" + StringUtil.join(mySkippedUsages, unresolvableCollisionUsageInfo -> unresolvableCollisionUsageInfo.getDescription(), "<br>") + "</html>", "Not All Usages Were Renamed", null);
}
};
statusBar.notifyProgressByBalloon(MessageType.WARNING, "<html><body>Unable to rename certain usages. <a href=\"\">Browse</a></body></html>", null, listener);
}
}, ModalityState.NON_MODAL);
}
}
}
use of javax.swing.event.HyperlinkEvent in project intellij-community by JetBrains.
the class GitRebaseProcess method notifySuccess.
private void notifySuccess(@NotNull Map<GitRepository, GitSuccessfulRebase> successful, final MultiMap<GitRepository, GitRebaseUtils.CommitInfo> skippedCommits) {
String rebasedBranch = getCommonCurrentBranchNameIfAllTheSame(myRebaseSpec.getAllRepositories());
List<SuccessType> successTypes = map(successful.values(), GitSuccessfulRebase::getSuccessType);
SuccessType commonType = getItemIfAllTheSame(successTypes, SuccessType.REBASED);
GitRebaseParams params = myRebaseSpec.getParams();
String baseBranch = params == null ? null : notNull(params.getNewBase(), params.getUpstream());
if ("HEAD".equals(baseBranch)) {
baseBranch = getItemIfAllTheSame(myRebaseSpec.getInitialBranchNames().values(), baseBranch);
}
String message = commonType.formatMessage(rebasedBranch, baseBranch, params != null && params.getBranch() != null);
message += mentionSkippedCommits(skippedCommits);
myNotifier.notifyMinorInfo("Rebase Successful", message, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
handlePossibleCommitLinks(e.getDescription(), skippedCommits);
}
});
}
Aggregations