Search in sources :

Example 46 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project processdash by dtuma.

the class TaskScheduleDialog method displayErrorDialog.

protected void displayErrorDialog(Map errors) {
    if (errors == null || errors.size() == 0)
        return;
    String[] footer = EVMetrics.isWarningOnly(errors) ? null : resources.getStrings("Error_Dialog.Foot");
    ErrorReporter err = new ErrorReporter(resources.getString("Error_Dialog.Title"), resources.getStrings("Error_Dialog.Head"), footer);
    Iterator i = errors.keySet().iterator();
    while (i.hasNext()) {
        err.logError(//
        StringUtils.findAndReplace(//
        (String) i.next(), "\n#", "\n#http://ignored/"));
    }
    err.setHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                String url = e.getURL().getFile();
                int pos = url.lastIndexOf('/');
                String helpSet = url.substring(0, pos);
                String topic = url.substring(pos + 1);
                String helpUri = helpSet + "/frame.html?" + topic;
                Browser.launch(helpUri);
            }
        }
    });
    err.done();
}
Also used : ErrorReporter(net.sourceforge.processdash.ui.lib.ErrorReporter) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) Iterator(java.util.Iterator)

Example 47 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project JWildfire by thargor6.

the class HelpInternalFrame method getHelpPane.

JTextPane getHelpPane() {
    if (helpPane == null) {
        helpPane = new JTextPane();
        helpPane.setBackground(SystemColor.menu);
        helpPane.setFont(Prefs.getPrefs().getFont("SansSerif", Font.PLAIN, 14));
        helpPane.addHyperlinkListener(new HyperlinkListener() {

            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    try {
                        java.awt.Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
        helpPane.setEditable(false);
    }
    return helpPane;
}
Also used : JTextPane(javax.swing.JTextPane) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 48 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project freeplane by freeplane.

the class SurveyRunner method runServey.

public void runServey(String id, String title, String question, String surveyUrl) {
    if (!freeplaneSurveyProperties.mayAskUserToFillSurvey(surveyId))
        return;
    this.surveyId = id;
    freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEYS);
    final JButton go = new JButton("With pleasure");
    go.setToolTipText("Thank you so much!");
    final JButton notInterested = new JButton("Not interested");
    notInterested.setToolTipText("We shall not repeat this question, but may be ask you another one.");
    final JButton remindMeLater = new JButton("Remind me later");
    remindMeLater.setToolTipText("The same question can be repeated some days later.");
    final JButton never = new JButton("Don't ask me anything again");
    never.setToolTipText("We are sorry! We shall never ask you any question like this again.");
    final JButton[] options = new JButton[] { go, notInterested, remindMeLater, never };
    final OptionButtonListener optionButtonListener = new OptionButtonListener();
    for (JButton button : options) button.addActionListener(optionButtonListener);
    final List<Image> iconImages = UITools.getFrame().getIconImages();
    final JEditorPane messageComponent = new JEditorPane("text/html", question);
    messageComponent.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    messageComponent.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    final URL url = e.getURL();
                    openSurvey(url);
                } catch (Exception ex) {
                }
                userVisitedVotingLink = true;
                SwingUtilities.getWindowAncestor(messageComponent).setVisible(false);
            }
        }
    });
    messageComponent.setEditable(false);
    messageComponent.addHierarchyListener(new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if (messageComponent.isShowing()) {
                messageComponent.removeHierarchyListener(this);
                final Window window = SwingUtilities.getWindowAncestor(messageComponent);
                if (window instanceof JDialog)
                    ((JDialog) window).setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                window.setIconImages(iconImages);
            }
        }
    });
    final int userDecision = JOptionPane.showOptionDialog(UITools.getCurrentFrame(), messageComponent, title, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, remindMeLater);
    switch(userDecision) {
        case JOptionPane.CLOSED_OPTION:
            if (userVisitedVotingLink)
                freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
            break;
        default:
            switch(Options.values()[userDecision]) {
                case GO_OPTION:
                    try {
                        freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
                        final URL survey = new URL(surveyUrl);
                        openSurvey(survey);
                    } catch (Exception e) {
                    }
                    break;
                case NOT_INTERESTED_OPTION:
                    freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
                    break;
                case REMIND_ME_LATER_OPTION:
                    freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEY_REMINDERS);
                    freeplaneSurveyProperties.activateRemindMeLater();
                    break;
                case NEVER_OPTION:
                    freeplaneSurveyProperties.setNeverShowSurvey();
                    break;
            }
    }
}
Also used : Window(java.awt.Window) HyperlinkEvent(javax.swing.event.HyperlinkEvent) JButton(javax.swing.JButton) Image(java.awt.Image) URL(java.net.URL) HierarchyListener(java.awt.event.HierarchyListener) HyperlinkListener(javax.swing.event.HyperlinkListener) HierarchyEvent(java.awt.event.HierarchyEvent) JEditorPane(javax.swing.JEditorPane) JDialog(javax.swing.JDialog)

Example 49 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project Galacticraft by micdoodle8.

the class CodeChickenCorePlugin method versionCheck.

public static void versionCheck(String reqVersion, String mod) {
    String mcVersion = (String) FMLInjectionData.data()[4];
    if (!VersionParser.parseRange(reqVersion).containsVersion(new DefaultArtifactVersion(mcVersion))) {
        String err = "This version of " + mod + " does not support minecraft version " + mcVersion;
        logger.error(err);
        JEditorPane ep = new JEditorPane("text/html", "<html>" + err + "<br>Remove it from your coremods folder and check <a href=\"http://www.minecraftforum.net/topic/909223-\">here</a> for updates" + "</html>");
        ep.setEditable(false);
        ep.setOpaque(false);
        ep.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent event) {
                try {
                    if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                        Desktop.getDesktop().browse(event.getURL().toURI());
                    }
                } catch (Exception ignored) {
                }
            }
        });
        JOptionPane.showMessageDialog(null, ep, "Fatal error", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) DefaultArtifactVersion(net.minecraftforge.fml.common.versioning.DefaultArtifactVersion)

Example 50 with HyperlinkListener

use of javax.swing.event.HyperlinkListener in project UniversalMediaServer by UniversalMediaServer.

the class LanguageSelection method buildComponent.

private JComponent buildComponent() {
    // UIManager manages to get the background color wrong for text
    // components on OS X, so we apply the color manually
    Color backgroundColor = UIManager.getColor("Panel.background");
    rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));
    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    selectionPanelBorder.setTitle(" ");
    selectionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(selectionPanelBorder, BorderFactory.createEmptyBorder(10, 5, 10, 5))));
    selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.PAGE_AXIS));
    descriptionText.setEditable(false);
    descriptionText.setBackground(backgroundColor);
    descriptionText.setFocusable(false);
    descriptionText.setLineWrap(true);
    descriptionText.setWrapStyleWord(true);
    descriptionText.setBorder(BorderFactory.createEmptyBorder(5, 15, 10, 15));
    selectionPanel.add(descriptionText);
    jLanguage = new JComboBox<>(keyedModel);
    jLanguage.setEditable(false);
    jLanguage.setPreferredSize(new Dimension(50, jLanguage.getPreferredSize().height));
    jLanguage.addActionListener(new LanguageComboBoxActionListener());
    languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.PAGE_AXIS));
    languagePanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    languagePanel.add(jLanguage);
    selectionPanel.add(languagePanel);
    warningText.setEditable(false);
    warningText.setFocusable(false);
    warningText.setBackground(backgroundColor);
    warningText.setFont(warningText.getFont().deriveFont(Font.BOLD));
    warningText.setLineWrap(true);
    warningText.setWrapStyleWord(true);
    warningText.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 15));
    selectionPanel.add(warningText);
    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    infoTextBorder.setTitle(" ");
    infoText.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(infoTextBorder, BorderFactory.createEmptyBorder(15, 20, 20, 20))));
    infoText.setEditable(false);
    infoText.setFocusable(false);
    infoText.setBackground(backgroundColor);
    infoText.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    // This exercise is to avoid using the default shared StyleSheet with padding
    CustomHTMLEditorKit editorKit = new CustomHTMLEditorKit();
    StyleSheet styleSheet = new StyleSheet();
    styleSheet.addRule("a { color: #0000EE; text-decoration:underline; }");
    editorKit.setStyleSheet(styleSheet);
    infoText.setEditorKit(editorKit);
    infoText.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                boolean error = false;
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI(e.getDescription()));
                    } catch (IOException | URISyntaxException ex) {
                        LOGGER.error("Language selection failed to open translation page hyperlink: ", ex.getMessage());
                        LOGGER.trace("", ex);
                        error = true;
                    }
                } else {
                    LOGGER.warn("Desktop is not supported, the clicked translation page link can't be opened");
                    error = true;
                }
                if (error) {
                    JOptionPane.showOptionDialog(dialog, String.format(buildString("LanguageSelection.6", true), PMS.CROWDIN_LINK), buildString("Dialog.Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, null, null);
                }
            }
        }
    });
    rootPanel.add(selectionPanel);
    rootPanel.add(infoText);
    applyButton.addActionListener(new ApplyButtonActionListener());
    applyButton.setActionCommand("apply");
    selectButton.addActionListener(new SelectButtonActionListener());
    selectButton.setActionCommand("select");
    return rootPanel;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Color(java.awt.Color) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) URI(java.net.URI) StyleSheet(javax.swing.text.html.StyleSheet) HyperlinkListener(javax.swing.event.HyperlinkListener) CustomHTMLEditorKit(net.pms.newgui.components.CustomHTMLEditorKit)

Aggregations

HyperlinkListener (javax.swing.event.HyperlinkListener)59 HyperlinkEvent (javax.swing.event.HyperlinkEvent)57 JEditorPane (javax.swing.JEditorPane)15 URL (java.net.URL)11 JScrollPane (javax.swing.JScrollPane)9 JPanel (javax.swing.JPanel)8 JTextPane (javax.swing.JTextPane)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 Dimension (java.awt.Dimension)6 IOException (java.io.IOException)6 NotNull (org.jetbrains.annotations.NotNull)6 HyperlinkLabel (com.intellij.ui.HyperlinkLabel)5 URI (java.net.URI)5 HTMLDocument (javax.swing.text.html.HTMLDocument)5 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)5 Project (com.intellij.openapi.project.Project)4 BorderLayout (java.awt.BorderLayout)4 ActionEvent (java.awt.event.ActionEvent)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 MouseEvent (java.awt.event.MouseEvent)3