use of javax.swing.event.HyperlinkEvent in project processing by processing.
the class DetailPanel method addPaneComponents.
/**
* Create the widgets for the header panel which is visible when the
* library panel is not clicked.
*/
private void addPaneComponents() {
setLayout(new BorderLayout());
descriptionPane = new JTextPane();
descriptionPane.setInheritsPopupMenu(true);
// why would this ever be true?
descriptionPane.setEditable(false);
Insets margin = descriptionPane.getMargin();
margin.bottom = 0;
descriptionPane.setMargin(margin);
descriptionPane.setContentType("text/html");
setTextStyle(descriptionPane, "0.95em");
descriptionPane.setOpaque(false);
if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
descriptionPane.setBackground(new Color(0, 0, 0, 0));
}
descriptionPane.setBorder(new EmptyBorder(4, 7, 7, 7));
descriptionPane.setHighlighter(null);
descriptionPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// adding/removing the listener repeatedly
if (isSelected()) {
if (enableHyperlinks && e.getURL() != null) {
Platform.openURL(e.getURL().toString());
}
}
}
}
});
add(descriptionPane, BorderLayout.CENTER);
JPanel updateBox = new JPanel();
updateBox.setLayout(new BorderLayout());
notificationLabel = new JLabel();
notificationLabel.setInheritsPopupMenu(true);
notificationLabel.setVisible(false);
notificationLabel.setOpaque(false);
notificationLabel.setFont(ManagerFrame.SMALL_PLAIN);
{
updateButton = new JButton("Update");
updateButton.setInheritsPopupMenu(true);
Dimension dim = new Dimension(BUTTON_WIDTH, updateButton.getPreferredSize().height);
updateButton.setMinimumSize(dim);
updateButton.setPreferredSize(dim);
updateButton.setOpaque(false);
updateButton.setVisible(false);
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
update();
}
});
}
updateBox.add(updateButton, BorderLayout.EAST);
updateBox.add(notificationLabel, BorderLayout.WEST);
updateBox.setBorder(new EmptyBorder(4, 7, 7, 7));
updateBox.setOpaque(false);
add(updateBox, BorderLayout.SOUTH);
JPanel rightPane = new JPanel();
rightPane.setInheritsPopupMenu(true);
rightPane.setOpaque(false);
rightPane.setLayout(new BoxLayout(rightPane, BoxLayout.Y_AXIS));
rightPane.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
add(rightPane, BorderLayout.EAST);
barButtonCardLayout = new CardLayout();
barButtonCardPane.setLayout(barButtonCardLayout);
barButtonCardPane.setInheritsPopupMenu(true);
barButtonCardPane.setOpaque(false);
barButtonCardPane.setMinimumSize(new Dimension(BUTTON_WIDTH, 1));
{
installProgressBar = new JProgressBar();
installProgressBar.setInheritsPopupMenu(true);
installProgressBar.setStringPainted(true);
resetInstallProgressBarState();
Dimension dim = new Dimension(BUTTON_WIDTH, installProgressBar.getPreferredSize().height);
installProgressBar.setPreferredSize(dim);
installProgressBar.setMaximumSize(dim);
installProgressBar.setMinimumSize(dim);
installProgressBar.setOpaque(false);
installProgressBar.setAlignmentX(CENTER_ALIGNMENT);
}
installRemoveButton = new JButton(" ");
installRemoveButton.setInheritsPopupMenu(true);
installRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String mode = installRemoveButton.getText();
if (mode.equals(installText)) {
install();
} else if (mode.equals(removeText)) {
remove();
} else if (mode.equals(undoText)) {
undo();
}
}
});
Dimension installButtonDimensions = installRemoveButton.getPreferredSize();
installButtonDimensions.width = BUTTON_WIDTH;
installRemoveButton.setPreferredSize(installButtonDimensions);
installRemoveButton.setMaximumSize(installButtonDimensions);
installRemoveButton.setMinimumSize(installButtonDimensions);
installRemoveButton.setOpaque(false);
installRemoveButton.setAlignmentX(CENTER_ALIGNMENT);
JPanel barPane = new JPanel();
barPane.setOpaque(false);
JPanel buttonPane = new JPanel();
buttonPane.setOpaque(false);
buttonPane.add(installRemoveButton);
barButtonCardPane.add(buttonPane, BUTTON_CONSTRAINT);
barButtonCardPane.add(barPane, PROGRESS_BAR_CONSTRAINT);
barButtonCardLayout.show(barButtonCardPane, BUTTON_CONSTRAINT);
rightPane.add(barButtonCardPane);
// Set the minimum size of this pane to be the sum of the height of the
// progress bar and install button
Dimension dim = new Dimension(BUTTON_WIDTH, installRemoveButton.getPreferredSize().height);
rightPane.setMinimumSize(dim);
rightPane.setPreferredSize(dim);
}
use of javax.swing.event.HyperlinkEvent in project ideavim by JetBrains.
the class VimShortcutKeyAction method notifyAboutShortcutConflict.
private void notifyAboutShortcutConflict(@NotNull final KeyStroke keyStroke) {
VimPlugin.getKey().getSavedShortcutConflicts().put(keyStroke, ShortcutOwner.VIM);
final String message = String.format("Using the <b>%s</b> shortcut for Vim emulation.<br/>" + "You can redefine it as an <a href='#ide'>IDE shortcut</a> or " + "configure its handler in <a href='#settings'>Vim Emulation</a> settings.", KeymapUtil.getShortcutText(new KeyboardShortcut(keyStroke, null)));
final NotificationListener listener = new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
final String description = e.getDescription();
if ("#ide".equals(description)) {
VimPlugin.getKey().getSavedShortcutConflicts().put(keyStroke, ShortcutOwner.IDE);
notification.expire();
} else if ("#settings".equals(description)) {
ShowSettingsUtil.getInstance().editConfigurable((Project) null, new VimEmulationConfigurable());
}
}
};
final Notification notification = new Notification(VimPlugin.IDEAVIM_NOTIFICATION_ID, VimPlugin.IDEAVIM_NOTIFICATION_TITLE, message, NotificationType.INFORMATION, listener);
notification.notify(null);
}
use of javax.swing.event.HyperlinkEvent in project azure-tools-for-java by Microsoft.
the class SparkSubmissionToolWindowProcessor method initialize.
public void initialize() {
ApplicationManager.getApplication().assertIsDispatchThread();
UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
@Override
public void uiSettingsChanged(UISettings uiSettings) {
synchronized (this) {
for (IHtmlElement htmlElement : cachedInfo) {
htmlElement.ChangeTheme();
}
setToolWindowText(parserHtmlElementList(cachedInfo));
}
}
}, ApplicationManager.getApplication());
fontFace = jEditorPanel.getFont().getFamily();
JPanel jPanel = new JPanel();
jPanel.setLayout(new GridBagLayout());
jEditorPanel.setMargin(new Insets(0, 10, 0, 0));
JBScrollPane scrollPane = new JBScrollPane(jEditorPanel);
stopButton = new JButton(PluginUtil.getIcon(CommonConst.StopIconPath));
stopButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.StopDisableIconPath));
stopButton.setEnabled(false);
stopButton.setToolTipText("stop execution of current application");
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DefaultLoader.getIdeHelper().executeOnPooledThread(new Runnable() {
@Override
public void run() {
if (clusterDetail != null) {
AppInsightsClient.create(HDInsightBundle.message("SparkSubmissionStopButtionClickEvent"), null);
try {
HttpResponse deleteResponse = SparkBatchSubmission.getInstance().killBatchJob(SparkSubmitHelper.getLivyConnectionURL(clusterDetail), batchId);
if (deleteResponse.getCode() == 201 || deleteResponse.getCode() == 200) {
jobStatusManager.setJobKilled();
setInfo("========================Stop application successfully=======================");
} else {
setError(String.format("Error : Failed to stop spark application. error code : %d, reason : %s.", deleteResponse.getCode(), deleteResponse.getContent()));
}
} catch (IOException exception) {
setError("Error : Failed to stop spark application. exception : " + exception.toString());
}
}
}
});
}
});
openSparkUIButton = new JButton(PluginUtil.getIcon(CommonConst.OpenSparkUIIconPath));
openSparkUIButton.setDisabledIcon(PluginUtil.getIcon(CommonConst.OpenSparkUIDisableIconPath));
openSparkUIButton.setEnabled(false);
openSparkUIButton.setToolTipText("open the corresponding Spark UI page");
openSparkUIButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
try {
if (jobStatusManager.isApplicationGenerated()) {
String connectionURL = clusterDetail.getConnectionUrl();
String sparkApplicationUrl = clusterDetail.isEmulator() ? String.format(yarnRunningUIEmulatorUrlFormat, ((EmulatorClusterDetail) clusterDetail).getSparkHistoryEndpoint(), jobStatusManager.getApplicationId()) : String.format(yarnRunningUIUrlFormat, connectionURL, jobStatusManager.getApplicationId());
Desktop.getDesktop().browse(new URI(sparkApplicationUrl));
}
} catch (Exception browseException) {
DefaultLoader.getUIHelper().showError("Failed to browse spark application yarn url", "Spark Submission");
}
}
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
buttonPanel.add(stopButton);
buttonPanel.add(openSparkUIButton);
GridBagConstraints c00 = new GridBagConstraints();
c00.fill = GridBagConstraints.VERTICAL;
c00.weighty = 1;
c00.gridx = 0;
c00.gridy = 0;
jPanel.add(buttonPanel, c00);
GridBagConstraints c10 = new GridBagConstraints();
c10.fill = GridBagConstraints.BOTH;
c10.weightx = 1;
c10.weighty = 1;
c10.gridx = 1;
c10.gridy = 0;
jPanel.add(scrollPane, c10);
toolWindow.getComponent().add(jPanel);
jEditorPanel.setEditable(false);
jEditorPanel.setOpaque(false);
jEditorPanel.setEditorKit(JEditorPane.createEditorKitForContentType("text/html"));
jEditorPanel.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported()) {
try {
String protocol = e.getURL().getProtocol();
if (protocol.equals("https") || protocol.equals("http")) {
Desktop.getDesktop().browse(e.getURL().toURI());
} else if (protocol.equals("file")) {
String path = e.getURL().getFile();
File localFile = new File(path);
File parentFile = localFile.getParentFile();
if (parentFile.exists() && parentFile.isDirectory()) {
Desktop.getDesktop().open(parentFile);
}
}
} catch (Exception exception) {
DefaultLoader.getUIHelper().showError(exception.getMessage(), "Open Local Folder Error");
}
}
}
}
});
PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if (ApplicationManager.getApplication().isDispatchThread()) {
changeSupportHandler(evt);
} else {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
changeSupportHandler(evt);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
private void changeSupportHandler(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals("toolWindowText")) {
jEditorPanel.setText(evt.getNewValue().toString());
} else if (evt.getPropertyName().equals("isStopButtonEnable")) {
stopButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
} else if (evt.getPropertyName().equals("isBrowserButtonEnable")) {
openSparkUIButton.setEnabled(Boolean.parseBoolean(evt.getNewValue().toString()));
}
}
};
jEditorPanel.addPropertyChangeListener(propertyChangeListener);
changeSupport = new PropertyChangeSupport(jEditorPanel);
changeSupport.addPropertyChangeListener(propertyChangeListener);
}
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();
}
Aggregations