Example usage for javax.swing.event HyperlinkEvent getDescription

List of usage examples for javax.swing.event HyperlinkEvent getDescription

Introduction

In this page you can find the example usage for javax.swing.event HyperlinkEvent getDescription.

Prototype

public String getDescription() 

Source Link

Document

Get the description of the link as a string.

Usage

From source file:FileTableHTML.java

public static void main(String[] args) throws IOException {
    // Get the name of the directory to display
    String dirname = (args.length > 0) ? args[0] : System.getProperty("user.home");

    // Create something to display it in.
    final JEditorPane editor = new JEditorPane();
    editor.setEditable(false); // we're browsing not editing
    editor.setContentType("text/html"); // must specify HTML text
    editor.setText(makeHTMLTable(dirname)); // specify the text to display

    // Set up the JEditorPane to handle clicks on hyperlinks
    editor.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            // Handle clicks; ignore mouseovers and other link-related events
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                // Get the HREF of the link and display it.
                editor.setText(makeHTMLTable(e.getDescription()));
            }//from w  w  w. j a  v a2 s.co  m
        }
    });

    // Put the JEditorPane in a scrolling window and display it.
    JFrame frame = new JFrame("FileTableHTML");
    frame.getContentPane().add(new JScrollPane(editor));
    frame.setSize(650, 500);
    frame.setVisible(true);
}

From source file:net.andydvorak.intellij.lessc.ui.notifier.NotificationListenerImpl.java

private static boolean isIgnoreEvent(@NotNull HyperlinkEvent event) {
    final String description = event.getDescription();
    return "ignore".equals(description) || "dismiss".equals(description);
}

From source file:net.andydvorak.intellij.lessc.ui.notifier.NotificationListenerImpl.java

private static boolean isViewFileEvent(@NotNull HyperlinkEvent event) {
    final String description = StringUtils.defaultString(event.getDescription());
    return "file".equals(description) || description.endsWith(".less") || description.endsWith(".css");
}

From source file:net.andydvorak.intellij.lessc.ui.notifier.NotificationListenerImpl.java

private void handleViewFileEvent(@NotNull final Notification notification,
        @NotNull final HyperlinkEvent event) {
    final String eventDescription = event.getDescription(); // retrieves the "href" attribute of the hyperlink
    final String curFilePath = StringUtils.defaultString(this.filePath, eventDescription);
    final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(curFilePath);
    openFileInEditor(notification, file);
}

From source file:net.sf.jabref.help.HelpContent.java

public HelpContent(JabRefPreferences prefs_) {
    super();//from w w  w  .  j  a va  2s. c  o  m
    pane = new JScrollPane(this, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setDoubleBuffered(true);
    prefs = prefs_;
    history = new Stack<URL>();
    forw = new Stack<URL>();
    setEditorKitForContentType("text/html", new MyEditorKit());
    setContentType("text/html");
    setText("");
    setEditable(false);

    // Handles Anchors
    final HyperlinkListener hyperLinkListener = new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getDescription().startsWith("#")) {
                scrollToReference(e.getDescription().substring(1));
            }
        }
    };
    addHyperlinkListener(hyperLinkListener);
}

From source file:net.sf.jabref.gui.help.HelpContent.java

public HelpContent(JabRefPreferences prefs_) {
    super();//  w w  w  . ja v a 2s  .c o m
    pane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setDoubleBuffered(true);
    prefs = prefs_;
    history = new Stack<>();
    forw = new Stack<>();
    setEditorKitForContentType("text/html", new MyEditorKit());
    setContentType("text/html");
    setText("");
    setEditable(false);

    addHyperlinkListener(new HyperlinkListener() {

        private boolean lastStatusUpdateWasALink = false;

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            String link = e.getDescription();
            if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                // show the link in the status bar - similar to Firefox behavior
                JabRef.jrf.setStatus(link);
                lastStatusUpdateWasALink = true;
            } else {
                if (lastStatusUpdateWasALink) {
                    // remove the link from the status bar
                    JabRef.jrf.setStatus("");
                    lastStatusUpdateWasALink = false;
                }
            }
        }
    });
}

From source file:net.sf.jabref.HelpContent.java

public HelpContent(JabRefPreferences prefs_) {
    super();/*from  ww  w .j av  a 2s  . co m*/
    pane = new JScrollPane(this, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    pane.setDoubleBuffered(true);
    prefs = prefs_;
    history = new Stack<URL>();
    forw = new Stack<URL>();
    setEditorKitForContentType("text/html", new MyEditorKit());
    setContentType("text/html");
    setText("");
    setEditable(false);

    // Handles Anchors
    final HyperlinkListener hyperLinkListener = new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getDescription().startsWith("#")) {
                scrollToReference(e.getDescription().substring(1));
            }
        }
    };
    addHyperlinkListener(hyperLinkListener);
}

From source file:com.hp.alm.ali.idea.content.settings.SettingsPanel.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        if (hyperlinkEvent.getDescription().equals("project")) {
            ShowSettingsUtil.getInstance().showSettingsDialog(prj, AliProjectConfigurable.DISPLAY_NAME);
        } else {//  w w  w  . ja  v  a 2 s .  com
            ShowSettingsUtil.getInstance().showSettingsDialog(null, AliConfigurable.DISPLAY_NAME);
        }
    }
}

From source file:com.android.tools.swing.ui.NavigationComponent.java

public NavigationComponent() {
    setEditable(false);/*w w w  .  j  a  v a2  s  . c o m*/
    setContentType(ContentType.TEXT_HTML.getMimeType());
    putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    // Disable links decoration.
    ((HTMLDocument) getDocument()).getStyleSheet().addRule("a { text-decoration:none; }");

    addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
                return;
            }

            int idx = Integer.parseInt(e.getDescription());
            final T item = myItemStack.get(idx);

            for (final ItemListener<T> listener : myItemListeners) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        listener.itemSelected(item);
                    }
                });
            }
        }
    });
}

From source file:com.microsoft.alm.plugin.idea.tfvc.core.TFSVcs.java

private void checkCommandLineVersion() {
    if (hasVersionBeenVerified) {
        // No need to check the version again if we have already checked it once this session
        logger.info("Skipping the attempt to check the version of the TF command line.");
        return;//from   w ww  . ja  va2 s  .  co  m
    }

    hasVersionBeenVerified = true;

    // We want to start a background thread to check the version, but that can only be done
    // form the UI thread.
    IdeaHelper.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            final SettableFuture<String> versionMessage = SettableFuture.create();
            (new Task.Backgroundable(getProject(),
                    TfPluginBundle.message(TfPluginBundle.KEY_TFVC_TF_VERSION_WARNING_PROGRESS), false,
                    PerformInBackgroundOption.ALWAYS_BACKGROUND) {
                public void run(@NotNull final ProgressIndicator indicator) {
                    try {
                        logger.info("Attempting to check the version of the TF command line.");
                        TfTool.checkVersion();
                        versionMessage.set(StringUtils.EMPTY);
                    } catch (final ToolException ex) {
                        final String error = LocalizationServiceImpl.getInstance().getExceptionMessage(ex);
                        logger.warn(error);
                        versionMessage.set(error);
                    } catch (final Throwable t) {
                        // Don't let unknown errors bubble out here
                        logger.warn("Unexpected error when checking the version of the command line.", t);
                    }
                }

                public void onSuccess() {
                    try {
                        final String error = versionMessage.get();
                        if (StringUtils.isNotEmpty(error)) {
                            logger.info("Notifying the user of the min version problem.");
                            // Notify the user that they should upgrade their version of the TF command line
                            VcsNotifier.getInstance(getProject()).notifyImportantWarning(
                                    TfPluginBundle.message(TfPluginBundle.KEY_TFVC_TF_VERSION_WARNING_TITLE),
                                    error, new NotificationListener.Adapter() {

                                        @Override
                                        protected void hyperlinkActivated(@NotNull Notification notification,
                                                @NotNull HyperlinkEvent hyperlinkEvent) {
                                            if (SETTINGS_URL_EVENT.equals(hyperlinkEvent.getDescription())) {
                                                ShowSettingsUtil.getInstance().showSettingsDialog(myProject,
                                                        getConfigurable().getDisplayName());
                                            } else if (HELP_URL_EVENT.equals(hyperlinkEvent.getDescription())) {
                                                BrowserUtil.browse(TFVC_ONLINE_HELP_URL);
                                            } else {
                                                logger.warn("Unknown hyperlinkEvent triggered: "
                                                        + hyperlinkEvent.getDescription());
                                            }
                                        }
                                    });
                        }
                    } catch (Exception e) {
                        logger.warn("Failed to warn user about min version of TF command line.", e);
                    }
                }
            }).queue();
        }
    });
}