Example usage for javax.swing.event HyperlinkEvent getURL

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

Introduction

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

Prototype

public URL getURL() 

Source Link

Document

Gets the URL that the link refers to.

Usage

From source file:de.mendelson.comm.as2.client.HTMLPanel.java

/**Listen to be a HyperlinkListener*/
@Override//from  w w w  . j av a  2s.  c o m
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            URI uri = new URI(e.getURL().toExternalForm());
            Desktop.getDesktop().browse(uri);
        } catch (Exception ex) {
            //nop
        }
    }
    if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
        jEditorPane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    }
    if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
        jEditorPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:SimpleHelp.java

/**
 * Notification of a change relative to a hyperlink. From:
 * java.swing.event.HyperlinkListener/*from w w  w  . j  a va 2  s .co  m*/
 */
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        URL target = e.getURL();
        // System.out.println("linkto: " + target);

        // Get the help panel's cursor and the wait cursor
        Cursor oldCursor = help.getCursor();
        Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        help.setCursor(waitCursor);

        // Now arrange for the page to get loaded asynchronously,
        // and the cursor to be set back to what it was.
        SwingUtilities.invokeLater(new PageLoader(target, oldCursor));
    }
}

From source file:com.igormaznitsa.zxpoly.ui.AboutDialog.java

public AboutDialog(final java.awt.Frame parent) {
    super(parent, true);
    initComponents();/*from  w w  w.j a  va  2  s.  c om*/

    this.editorPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception ex) {
                }
            } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                editorPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                editorPane.setCursor(Cursor.getDefaultCursor());
            }
        }
    });

    this.editorPane.setContentType("text/html");
    try {
        final String htmlText = IOUtils.toString(openAboutResource("index.html"), "UTF-8");
        this.editorPane.setText(htmlText);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    setLocationRelativeTo(parent);
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Called when something is happened on a hyperlink in the page browser.
 * This is the {@code HyperlinkListener} method.
 */// www.j  a  va2  s  .  c o m
public void hyperlinkUpdate(HyperlinkEvent e) {
    URL url = e.getURL();
    EventType type = e.getEventType();

    if (type == EventType.ENTERED) {
        messageArea.setText("Go to " + url);
    } else if (type == EventType.EXITED) {
        messageArea.setText(defaultMessage);
    } else if (type == EventType.ACTIVATED) {
        setPage(url);
        messageArea.setText(defaultMessage);
    }
}

From source file:EditorPaneTest.java

public EditorPaneFrame() {
    setTitle("EditorPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final Stack<String> urlStack = new Stack<String>();
    final JEditorPane editorPane = new JEditorPane();
    final JTextField url = new JTextField(30);

    // set up hyperlink listener

    editorPane.setEditable(false);// w  w w  .j av a2  s . c om
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    // remember URL for back button
                    urlStack.push(event.getURL().toString());
                    // show URL in text field
                    url.setText(event.getURL().toString());
                    editorPane.setPage(event.getURL());
                } catch (IOException e) {
                    editorPane.setText("Exception: " + e);
                }
            }
        }
    });

    // set up checkbox for toggling edit mode

    final JCheckBox editable = new JCheckBox();
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            editorPane.setEditable(editable.isSelected());
        }
    });

    // set up load button for loading URL

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    };

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(listener);
    url.addActionListener(listener);

    // set up back button and button action

    JButton backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (urlStack.size() <= 1)
                return;
            try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    });

    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    // put all control components in a panel

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    add(panel, BorderLayout.SOUTH);
}

From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.VcsWorkItemsModel.java

public void createBranch() {
    if (!isTeamServicesRepository() || repositoryContext.getType() != RepositoryContext.Type.GIT) {
        logger.debug("createBranch: cannot associate a work item with a branch in a non-TF Git repo");
        return;/*  w  w w.  j a  v  a  2s .  com*/
    }

    final ServerContext context = ServerContextManager.getInstance().get(repositoryContext.getUrl());
    final WorkItem workItem = viewForModel.getSelectedWorkItems().get(0); // TODO: associate multiple work items with a branch

    // call the Create Branch dialog and get the branch name from the user
    final CreateBranchController controller = new CreateBranchController(project,
            String.format(DEFAULT_BRANCH_NAME_PATTERN, workItem.getId()), VcsHelper.getGitRepository(project));

    if (controller.showModalDialog()) {
        final String branchName = controller.getBranchName();
        try {
            //TODO should this be an IntelliJ background task so we can provide progress information? (if so we should pass the progress indicator to createBranch and create association)
            OperationExecutor.getInstance().submitOperationTask(new Runnable() {
                @Override
                public void run() {
                    // do branch creation
                    final boolean wasBranchCreated = controller.createBranch(context);

                    // check if branch creation succeeded before associating the work item to it
                    boolean wasWorkItemAssociated = false;
                    if (wasBranchCreated) {
                        wasWorkItemAssociated = createWorkItemBranchAssociation(context, branchName,
                                workItem.getId());

                        logger.info(
                                "Work item association " + (wasWorkItemAssociated ? "succeeded" : "failed"));
                        final String notificationMsg = TfPluginBundle.message(
                                wasWorkItemAssociated
                                        ? TfPluginBundle.KEY_WIT_ASSOCIATION_SUCCESSFUL_DESCRIPTION
                                        : TfPluginBundle.KEY_WIT_ASSOCIATION_FAILED_DESCRIPTION,
                                UrlHelper.getSpecificWorkItemURI(context.getTeamProjectURI(), workItem.getId()),
                                workItem.getId(), UrlHelper.getBranchURI(context.getUri(), branchName),
                                branchName);

                        VcsNotifier.getInstance(project).notifyImportantInfo(
                                TfPluginBundle.message(wasWorkItemAssociated
                                        ? TfPluginBundle.KEY_WIT_ASSOCIATION_SUCCESSFUL_TITLE
                                        : TfPluginBundle.KEY_WIT_ASSOCIATION_FAILED_TITLE),
                                notificationMsg, new NotificationListener() {
                                    @Override
                                    public void hyperlinkUpdate(@NotNull Notification notification,
                                            @NotNull HyperlinkEvent hyperlinkEvent) {
                                        BrowserUtil.browse(hyperlinkEvent.getURL());
                                    }
                                });
                    }

                    TfsTelemetryHelper.getInstance().sendEvent(ASSOCIATE_WORK_ITEM_ACTION,
                            new TfsTelemetryHelper.PropertyMapBuilder().currentOrActiveContext(context)
                                    .actionName(ASSOCIATE_WORK_ITEM_ACTION).success(wasWorkItemAssociated)
                                    .build());

                    // Update the work items tab and any other listener to WorkItemChanged events
                    EventContextHelper.triggerWorkItemChanged(EventContextHelper.SENDER_ASSOCIATE_BRANCH,
                            project);
                }
            });
        } catch (Exception e) {
            logger.error("Failed to create a branch and associate it with a work item", e);
        }
    }
}

From source file:eu.delving.sip.frames.OutputFrame.java

public OutputFrame(final SipModel sipModel) {
    super(Which.OUTPUT, sipModel, "Output");
    htmlPanel = new HtmlPanel("Link Checks").addHyperlinkListener(new HyperlinkListener() {
        @Override/*  ww  w . j  ava  2  s  . c  o  m*/
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                SwingHelper.launchURL(e.getURL().toString());
        }
    });
    sipModel.getRecordCompileModel().setEnabled(false);
    sipModel.getRecordCompileModel().addListener(new MappingCompileModel.Listener() {
        @Override
        public void stateChanged(CompileState state) {
        }

        @Override
        public void codeCompiled(MappingCompileModel.Type type, String code) {
        }

        @Override
        public void mappingComplete(MappingResult mappingResult) {
            try {
                LinkCheckExtractor extractor = new LinkCheckExtractor(
                        mappingResult.getRecDefTree().getRecDef().fieldMarkers,
                        new XPathContext(mappingResult.getRecDefTree().getRecDef().namespaces));
                final List<String> checkLines = extractor.getChecks(mappingResult);
                DataSet dataSet = sipModel.getDataSetModel().getDataSet();
                String prefix = sipModel.getMappingModel().getPrefix();
                final LinkChecker linkChecker = new LinkChecker(httpClient);
                ResultLinkChecks checks = new ResultLinkChecks(dataSet, prefix, linkChecker);
                Work.DataSetPrefixWork work = checks.checkLinks(mappingResult.getLocalId(), checkLines,
                        sipModel.getFeedback(), new Swing() {
                            @Override
                            public void run() {
                                StringBuilder out = new StringBuilder();
                                ResultLinkChecks.validLinesToHTML(checkLines, linkChecker, out);
                                htmlPanel.setHtml(out.toString());
                            }
                        });
                if (work != null) {
                    sipModel.exec(work);
                }
            } catch (XPathExpressionException e) {
                sipModel.getFeedback().alert("XPath problem", e);
            }
        }
    });
}

From source file:com.ixora.common.ui.ShowExceptionDialog.java

/**
 * @param e/*w ww . jav a2  s.  c  o  m*/
 */
private void handleHyperlinkActivated(HyperlinkEvent e) {
    try {
        if (internalError) {
            handleSendError(e.getURL());
        } else if (requiresHtmlRenderer) {
            Utils.launchBrowser(e.getURL());
        }
    } catch (Throwable ex) {
        logger.error(ex);
    }
}

From source file:net.sf.taverna.t2.workbench.ui.credentialmanager.WarnUserAboutJCEPolicyDialog.java

private void initComponents() {
    // Base font for all components on the form
    Font baseFont = new JLabel("base font").getFont().deriveFont(11f);

    // Message saying that updates are available
    JPanel messagePanel = new JPanel(new BorderLayout());
    messagePanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10), new EtchedBorder(LOWERED)));

    JEditorPane message = new JEditorPane();
    message.setEditable(false);/* w  w  w. j  a  v a 2 s.com*/
    message.setBackground(this.getBackground());
    message.setFocusable(false);
    HTMLEditorKit kit = new HTMLEditorKit();
    message.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    //styleSheet.addRule("body {font-family:"+baseFont.getFamily()+"; font-size:"+baseFont.getSize()+";}"); // base font looks bigger when rendered as HTML
    styleSheet.addRule("body {font-family:" + baseFont.getFamily() + "; font-size:10px;}");
    Document doc = kit.createDefaultDocument();
    message.setDocument(doc);
    message.setText(
            "<html><body>In order for Taverna's security features to function properly - you need to install<br>"
                    + "'Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy'. <br><br>"
                    + "If you do not already have it, for <b>Java 6</b> you can get it from:<br>"
                    + "<a href=\"http://www.oracle.com/technetwork/java/javase/downloads/index.html\">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br<br>"
                    + "Installation instructions are contained in the bundle you download." + "</body><html>");
    message.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent he) {
            HyperlinkEvent.EventType type = he.getEventType();
            if (type == ACTIVATED)
                // Open a Web browser
                try {
                    getDesktop().browse(he.getURL().toURI());
                    //                  BrowserLauncher launcher = new BrowserLauncher();
                    //                  launcher.openURLinBrowser(he.getURL().toString());
                } catch (Exception ex) {
                    logger.error("Failed to launch browser to fetch JCE " + he.getURL());
                }
        }
    });
    message.setBorder(new EmptyBorder(5, 5, 5, 5));
    messagePanel.add(message, CENTER);

    doNotWarnMeAgainCheckBox = new JCheckBox("Do not warn me again");
    doNotWarnMeAgainCheckBox.setFont(baseFont.deriveFont(12f));
    messagePanel.add(doNotWarnMeAgainCheckBox, SOUTH);

    // Buttons
    JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JButton okButton = new JButton("OK");
    okButton.setFont(baseFont);
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            okPressed();
        }
    });

    buttonsPanel.add(okButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(messagePanel, CENTER);
    getContentPane().add(buttonsPanel, SOUTH);

    pack();
    setResizable(false);
    // Center the dialog on the screen (we do not have the parent)
    Dimension dimension = getToolkit().getScreenSize();
    Rectangle abounds = getBounds();
    setLocation((dimension.width - abounds.width) / 2, (dimension.height - abounds.height) / 2);
    setSize(getPreferredSize());
}

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

@Nullable
public List<VcsException> commit(final List<Change> changes, final String preparedComment,
        @NotNull NullableFunction<Object, Object> parametersHolder, Set<String> feedback) {
    final List<VcsException> errors = new ArrayList<VcsException>();

    // set progress bar status
    final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
    TFSProgressUtil.setProgressText(progressIndicator,
            TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_STATUS));

    // find files that are to be checked in
    final List<String> files = new ArrayList<String>();
    for (final Change change : changes) {
        String path = null;// w  w  w .ja va 2 s  .  c o m
        final ContentRevision beforeRevision = change.getBeforeRevision();
        final ContentRevision afterRevision = change.getAfterRevision();
        if (afterRevision != null) {
            path = afterRevision.getFile().getPath();
        } else if (beforeRevision != null) {
            path = beforeRevision.getFile().getPath();
        }
        if (path != null) {
            files.add(path);
        }
    }

    try {
        final ServerContext context = myVcs.getServerContext(true);
        final List<Integer> workItemIds = VcsHelper.getWorkItemIdsFromMessage(preparedComment);
        final String changesetNumber = CommandUtils.checkinFiles(context, files, preparedComment, workItemIds);

        // notify user of success
        final String changesetLink = String.format(UrlHelper.SHORT_HTTP_LINK_FORMATTER,
                UrlHelper.getTfvcChangesetURI(context.getUri().toString(), changesetNumber),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_LINK_TEXT, changesetNumber));
        VcsNotifier.getInstance(myVcs.getProject()).notifyImportantInfo(
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_TITLE),
                TfPluginBundle.message(TfPluginBundle.KEY_TFVC_CHECKIN_SUCCESSFUL_MSG, changesetLink),
                new NotificationListener() {
                    @Override
                    public void hyperlinkUpdate(@NotNull Notification notification,
                            @NotNull HyperlinkEvent hyperlinkEvent) {
                        BrowserUtil.browse(hyperlinkEvent.getURL());
                    }
                });
    } catch (Exception e) {
        // no notification needs to be done by us for errors, IntelliJ handles that
        logger.warn("Error during checkin", e);
        if (e instanceof TeamServicesException) {
            // get localized message in the case of TeamServicesException otherwise the key will print out instead of the error
            errors.add(new VcsException(LocalizationServiceImpl.getInstance().getExceptionMessage(e)));
        } else {
            errors.add(new VcsException(e));
        }
    }

    return errors;
}