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:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java

public AddPanel(JDialog parentDialog, IEngine engine) {
    Arguments.assertNotNull("parentDialog", parentDialog);
    Arguments.assertNotNull("engine", engine);

    this.parentDialog = parentDialog;
    this.engine = engine;

    fileChooser = new FileChooser();

    encodingComboBox = new JComboBox();
    encodingAutoComboBox = new JComboBox(new String[] { resources.text("encoding_auto") });
    encodingAutoComboBox.setEnabled(false);

    encodingCardPanel = new CardPanel();
    encodingCardPanel.add(encodingComboBox);
    encodingCardPanel.add(encodingAutoComboBox);

    readerList = Components/* www.ja va 2  s. c  o  m*/
            .list(new StaticListModel<IDictionaryReader>(new ReaderLabelBuilder(), engine.getReaders()));
    readerList.setSelectedIndex(0);

    editorPane = Components.editorPane();
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                Browser.openUrl(e.getURL().toExternalForm());
            }
        }
    });

    continueButton = Buttons.continue1();
    continueButton.setDefaultCapable(true);

    closeButton = Buttons.cancel();

    JPanel buttonPanel = new JPanel(new GridLayout(1, 2, GAP5, GAP5));
    buttonPanel.add(continueButton);
    buttonPanel.add(closeButton);

    JPanel listReaderPanel = new JPanel(new BorderLayout());
    listReaderPanel.add(resources.label("reader"), BorderLayout.NORTH);
    listReaderPanel.add(new JScrollPane(readerList), BorderLayout.CENTER);

    readerList.setPreferredSize(new Dimension(50, 50));
    listReaderPanel.setPreferredSize(new Dimension(100, 100));

    JPanel descriptionReaderPanel = new JPanel(new BorderLayout());
    descriptionReaderPanel.add(resources.label("readerDescription"), BorderLayout.NORTH);
    descriptionReaderPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listReaderPanel, descriptionReaderPanel);
    splitPane.setContinuousLayout(true);
    splitPane.setDividerLocation(130);

    gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED, GAP5, TableLayout.FILL },
            { TableLayout.FILL, // 0: reader panel
                    GAP5, TableLayout.PREFERRED, // 2: file
                    GAP5, TableLayout.PREFERRED, // 4: encoding
                    GAP5 * 2, TableLayout.PREFERRED // 6: button panel
            } }));

    gui.add(splitPane, "0, 0, 2, 0");

    gui.add(resources.label("file"), "0, 2");
    gui.add(fileChooser.getGui(), "2, 2");

    gui.add(resources.label("encoding"), "0, 4");
    gui.add(encodingCardPanel.getGui(), "2, 4");

    gui.add(buttonPanel, "0, 6, 2, 6, right, center");

    Gaps.applyBorder7(gui);

    ActionBinder.bind(this);

    if (encodingComboBox.getModel().getSize() > 0) {
        encodingComboBox.setSelectedIndex(0);
    }

    // filters
    for (IDictionaryReader reader : engine.getReaders()) {
        fileChooser.getChooser().addChoosableFileFilter(reader.getFileFilter());
    }

    onReaderSelected();
    onFileFieldEdited();
}

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        try {/* ww w .j  a va2 s.  c o m*/
            URL url = e.getURL();
            if (url != null) {
                if (url.getPath().endsWith(".cer") || url.getPath().endsWith(".crt")) {
                    X509Certificate[] certs = downloadCert(url);
                    if (certs != null && certs.length > 0) {
                        DViewCertificate dViewCertificate = new DViewCertificate(this, MessageFormat
                                .format(res.getString("DViewExtensions.ViewCert.Title"), url.toString()), certs,
                                null, DViewCertificate.NONE);
                        dViewCertificate.setLocationRelativeTo(this);
                        dViewCertificate.setVisible(true);
                    }
                } else if (url.getPath().endsWith(".crl")) {
                    X509CRL crl = downloadCrl(url);
                    if (crl != null) {
                        DViewCrl dViewCrl = new DViewCrl(this, MessageFormat
                                .format(res.getString("DViewExtensions.ViewCrl.Title"), url.toString()),
                                ModalityType.DOCUMENT_MODAL, crl);
                        dViewCrl.setLocationRelativeTo(this);
                        dViewCrl.setVisible(true);
                    }
                } else {
                    Desktop.getDesktop().browse(url.toURI());
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:esmska.gui.AboutFrame.java

private void creditsButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_creditsButtonActionPerformed
    //show credits
    try {//from   ww  w.  jav a2 s .  c om
        logger.fine("Showing credits...");
        String credits = IOUtils.toString(getClass().getResourceAsStream(RES + "credits.html"), "UTF-8");
        String translators = l10n.getString("Translators");
        if ("translator-credits".equals(translators)) {
            //there are no translators mentioned
            translators = "";
        } else {
            translators = translators.replaceAll("\n", "<br>\n").replaceAll("\n  ", "\n&nbsp;&nbsp;");
            //add hyperlinks to the Launchpad URLs
            translators = translators.replaceAll("(https://[^<]*)", "<a href=\"$1\">$1</a>");
        }

        String document = MessageFormat.format(credits, l10n.getString("Credits.authors"),
                l10n.getString("Credits.contributors"), l10n.getString("Credits.graphics"),
                l10n.getString("Credits.sponsors"), l10n.getString("Credits.translators"), translators,
                Links.DONATORS, l10n.getString("Credits.moreDonators"),
                MessageFormat.format(l10n.getString("Credits.packagers"), Links.DOWNLOAD));

        JTextPane tp = new JTextPane();
        tp.setContentType("text/html; charset=UTF-8");
        tp.setText(document);
        tp.setEditable(false);
        tp.setPreferredSize(new Dimension(450, 400));
        tp.setCaretPosition(0);
        //make links clickable
        tp.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(final HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && Desktop.isDesktopSupported()) {
                    try {
                        logger.fine("Browsing URL: " + e.getURL());
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (Exception ex) {
                        logger.log(Level.SEVERE, "Can't browse hyperlink: " + e.getURL(), ex);
                    }
                }
            }
        });

        String option = l10n.getString("AboutFrame.Thank_you");
        JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE,
                JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option);
        JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.Credits"));
        dialog.setResizable(true);
        dialog.pack();
        dialog.setVisible(true);
    } catch (IOException e) {
        logger.log(Level.WARNING, "Could not show credits", e);
    }
}

From source file:com.microsoft.alm.plugin.idea.git.ui.branch.CreateBranchModel.java

public boolean doBranchCreate(@NotNull final ServerContext context, final ProgressIndicator progressIndicator) {
    logger.info("CreateBranchModel.doBranchCreate");
    // call server to create branch
    boolean hasNotifiedUser = false; //keep track of notifications because of recursive call
    String errorMessage = StringUtils.EMPTY;
    try {//from w w  w  . j a  v a 2 s . co m
        // ref update will create a new ref when no existing ref is found (we check for existing)
        final GitRefUpdate gitRefUpdate = new GitRefUpdate();
        gitRefUpdate.setName(REFS_PREFIX + getBranchName().replaceFirst(ORIGIN_PREFIX, StringUtils.EMPTY));
        gitRefUpdate.setOldObjectId(BASE_HASH); // since branch is new the last commit hash is all 0's
        gitRefUpdate.setNewObjectId(
                GeneralGitHelper.getLastCommitHash(project, gitRepository, selectedRemoteBranch)); // TODO: get the latest commit from server b/c the latest local commit could be incorrect
        gitRefUpdate.setRepositoryId(context.getGitRepository().getId());

        logger.info("CreateBranchModel.createBranch sending create ref call to server");
        final List<GitRefUpdateResult> results = context.getGitHttpClient().updateRefs(
                Arrays.asList(gitRefUpdate), context.getGitRepository().getId(),
                context.getTeamProjectReference().getId().toString());

        // check returned results
        if (results.size() < 1 || !results.get(0).getSuccess()) {
            errorMessage = results.size() > 0 ? results.get(0).getCustomMessage()
                    : TfPluginBundle.KEY_CREATE_BRANCH_ERRORS_UNEXPECTED_SERVER_ERROR;
        } else {
            // Get the repository object for this project
            final GitRepository gitRepository = TfGitHelper.getTfGitRepository(project);
            if (gitRepository != null) {
                // Create a progressIndicator if one was not passed in
                // Fetch server changes so we can checkout here if we want to
                logger.info("Fetching latest from server so that the new branch is available to checkout");
                final GitFetcher fetcher = new GitFetcher(project, getProgressIndicator(progressIndicator),
                        true);
                final GitFetchResult fetchResult = fetcher.fetch(gitRepository);
                if (fetchResult.isSuccess() && this.checkoutBranch) {
                    logger.info("Checking out new branch: " + branchName);
                    // Creating a branch using the brancher has to start on the UI thread (it will background the work itself)
                    IdeaHelper.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            logger.info("Finishing: Checking out new branch: " + branchName);
                            final String remoteBranchName = TfGitHelper
                                    .getRemoteBranchName(selectedRemoteBranch.getRemote(), branchName);
                            final GitBrancher brancher = ServiceManager.getService(project, GitBrancher.class);
                            // Checkout a new branch from the remote branch that was created on the server and fetched above
                            brancher.checkoutNewBranchStartingFrom(branchName, remoteBranchName,
                                    Collections.singletonList(gitRepository), null);
                        }
                    });
                }
            } else {
                logger.warn(
                        "Could not fetch branch from server. Unable to retrieve the git repo object from the project.");
            }

        }
    } catch (Throwable t) {
        if (AuthHelper.isNotAuthorizedError(t)) {
            final ServerContext newContext = ServerContextManager.getInstance()
                    .updateAuthenticationInfo(context.getGitRepository().getRemoteUrl());
            if (newContext != null) {
                //retry creating the branch with new context and authentication info
                hasNotifiedUser = doBranchCreate(newContext, progressIndicator);
            } else {
                //user cancelled login, don't retry
                errorMessage = t.getMessage();
            }
        } else {
            errorMessage = t.getMessage();
        }
    }

    if (!hasNotifiedUser) {
        // alert user to success or error in creating the branch
        if (StringUtils.isEmpty(errorMessage)) {
            logger.info("Create branch succeeded");
            setBranchWasCreated(true);

            // create user notification
            final String branchLink = String.format(UrlHelper.SHORT_HTTP_LINK_FORMATTER,
                    UrlHelper.getBranchURI(context.getUri(), getBranchName()), getBranchName());
            VcsNotifier.getInstance(project)
                    .notifyImportantInfo(
                            TfPluginBundle.message(TfPluginBundle.KEY_CREATE_BRANCH_DIALOG_SUCCESSFUL_TITLE),
                            TfPluginBundle.message(
                                    TfPluginBundle.KEY_CREATE_BRANCH_DIALOG_SUCCESSFUL_DESCRIPTION, branchLink),
                            new NotificationListener() {
                                @Override
                                public void hyperlinkUpdate(@NotNull Notification notification,
                                        @NotNull HyperlinkEvent hyperlinkEvent) {
                                    BrowserUtil.browse(hyperlinkEvent.getURL());
                                }
                            });
        } else {
            logger.warn("Create branch failed", errorMessage);
            VcsNotifier.getInstance(project).notifyError(
                    TfPluginBundle.message(TfPluginBundle.KEY_CREATE_BRANCH_DIALOG_FAILED_TITLE),
                    TfPluginBundle.message(TfPluginBundle.KEY_CREATE_BRANCH_ERRORS_BRANCH_CREATE_FAILED,
                            errorMessage));
        }

        // Add Telemetry for the create call along with it's success/failure
        TfsTelemetryHelper.getInstance().sendEvent(CREATE_BRANCH_ACTION,
                new TfsTelemetryHelper.PropertyMapBuilder().currentOrActiveContext(context)
                        .actionName(CREATE_BRANCH_ACTION).success(StringUtils.isEmpty(errorMessage))
                        .message(errorMessage).build());

        hasNotifiedUser = true;
    }
    return hasNotifiedUser;
}

From source file:MiniBrowser.java

public void hyperlinkUpdate(HyperlinkEvent event) {
    HyperlinkEvent.EventType eventType = event.getEventType();
    if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
        if (event instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent linkEvent = (HTMLFrameHyperlinkEvent) event;
            HTMLDocument document = (HTMLDocument) displayEditorPane.getDocument();
            document.processHTMLFrameHyperlinkEvent(linkEvent);
        } else {/*from w w w. j a  v  a  2  s .co  m*/
            showPage(event.getURL(), true);
        }
    }
}

From source file:jamel.gui.JamelWindow.java

/**
 * Returns the info panel./*from  w w  w  .ja v  a  2  s. c o m*/
 * @return the info panel.
 */
private Component getInfoPanel() {
    final JEditorPane editorPane = new JEditorPane("text/html", "<center>" + this.infoString + "</center>");
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
                try {
                    java.awt.Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null,
                            "<html>" + "Error.<br>" + "Cause: " + e.toString() + ".<br>"
                                    + "Please see server.log for more details.</html>",
                            "Warning", JOptionPane.WARNING_MESSAGE);
                }
        }
    });
    editorPane.setEditable(false);
    final JScrollPane scrollPane = new JScrollPane(editorPane);
    return scrollPane;
}

From source file:dk.dma.epd.common.prototype.gui.notification.MsiNmNotificationPanel.java

/**
 * {@inheritDoc}/*from  w w  w .ja  va2 s . c om*/
 */
@Override
public void hyperlinkUpdate(HyperlinkEvent hle) {
    if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
        try {
            URL url = hle.getURL();
            if (url.getHost().equals("msinm") && url.getPath().length() > 1) {
                String msinmId = url.getPath().substring(1);

                for (MsiNmNotification notification : notificationPanel.getNotifications()) {
                    if (notification.getSeriesId().equals(msinmId)) {
                        EPD.getInstance().getNotificationCenter().openNotification(NotificationType.MSI_NM,
                                notification.getId(), false);
                        return;
                    }
                    Toolkit.getDefaultToolkit().beep();
                }
            } else {
                Desktop desktop = Desktop.getDesktop();
                desktop.browse(new URI(hle.getURL().toString()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}

From source file:com.ln.gui.Main.java

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        URL url = e.getURL();
        String u = url.toString();
        try {/*w  w w  .  j a va 2 s  . c o  m*/
            java.awt.Desktop.getDesktop().browse(java.net.URI.create(u));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.ui.pullrequest.CreatePullRequestModel.java

private void notifySuccess(final Project project, final String title, final String message) {
    VcsNotifier.getInstance(project).notifyImportantInfo(title, message, new NotificationListener() {
        @Override//  w  ww. ja va  2s  .  co  m
        public void hyperlinkUpdate(@NotNull final Notification n, @NotNull final HyperlinkEvent e) {
            BrowserUtil.browse(e.getURL());
        }
    });
}

From source file:fxts.stations.ui.help.HelpPane.java

/**
 * Inits all components./*from  w  ww  .  java 2  s.  c om*/
 */
private void initComponents() {
    //creates history
    mHistory = new HelpContentHistory();
    //Create the text area for contents
    mTabbedPane = new JTabbedPane();

    //creates content tree
    mContentTree = new ContentTree("fxts/stations/trader/resources/help/contents.xml");
    mContentTree.addListener(this);

    //Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(mContentTree.getTree());
    mTabbedPane.addTab(mResMan.getString("IDS_HELP_CONTENTS", "Contents"), treeView);

    //xxx workaround for bug #6424509, memory leak
    JEditorPane.registerEditorKitForContentType("text/html", WeakHTMLEditorKit.class.getName());
    //creates the text area for the showing of the help.
    mHtmlPage = new JEditorPane();
    mHtmlPage.setEditable(false);
    mHtmlPage.putClientProperty("charset", "UTF-16");
    mHtmlPage.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent aEvent) {
            if (aEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    onSelectContentByHyperlink(aEvent.getURL());
                    mHtmlPage.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                } catch (Exception e) {
                    mLogger.error("Hiperlink not processed!");
                    e.printStackTrace();
                }
            }
        }
    });
    JScrollPane scrollPane = new JScrollPane(mHtmlPage);

    //creates a split pane for the change log and the text area.
    mSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mTabbedPane, scrollPane);
    mSplitPane.setOneTouchExpandable(true);

    //Creates the toolbar area.
    JToolBar toolbar = UIManager.getInst().createToolBar();
    toolbar.setFloatable(false);

    //creates label with left arrow
    UIManager uiMan = UIManager.getInst();
    mBackButton = uiMan.createButton(null, "ID_HELP_LEFT_ARROW", "ID_HELP_LEFT_ARROW_DESC",
            "ID_HELP_LEFT_ARROW_DESC");
    mBackButton.setEnabled(false);
    mBackButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (mHistory.hasBackStep()) {
                mIsHistorycalStep = true;
                onSelectContent(mHistory.back());
                mBackButton.setEnabled(mHistory.hasBackStep());
                mForwardButton.setEnabled(mHistory.hasForwardStep());
            }
        }
    });
    toolbar.add(mBackButton);

    //creates label with right arrow
    mForwardButton = uiMan.createButton(null, "ID_HELP_RIGHT_ARROW", "ID_HELP_RIGHT_ARROW_DESC",
            "ID_HELP_RIGHT_ARROW_DESC");
    mForwardButton.setEnabled(false);
    mForwardButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (mHistory.hasForwardStep()) {
                mIsHistorycalStep = true;
                onSelectContent(mHistory.forward());
                mBackButton.setEnabled(mHistory.hasBackStep());
                mForwardButton.setEnabled(mHistory.hasForwardStep());
            }
        }
    });
    toolbar.add(mForwardButton);

    //creates label with up arrow
    mUpButton = uiMan.createButton(null, "ID_HELP_UP_ARROW", "ID_HELP_UP_ARROW_DESC", "ID_HELP_UP_ARROW_DESC");
    mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
    mUpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            mContentsBrowsing = true;
            onSelectContent(mContentTree.getIterator().previous());
            mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
            mDownButton.setEnabled(mContentTree.getIterator().hasNext());
        }
    });
    toolbar.add(mUpButton);

    //creates label with down arrow
    mDownButton = uiMan.createButton(null, "ID_HELP_DOWN_ARROW", "ID_HELP_DOWN_ARROW_DESC",
            "ID_HELP_DOWN_ARROW_DESC");
    mDownButton.setEnabled(mContentTree.getIterator().hasNext());
    mDownButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            mContentsBrowsing = true;
            onSelectContent(mContentTree.getIterator().next());
            mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
            mDownButton.setEnabled(mContentTree.getIterator().hasNext());
        }
    });
    toolbar.add(mDownButton);

    //sets layout
    setLayout(new BorderLayout());

    //add the components to the frame.
    add(mSplitPane, BorderLayout.CENTER);
    add(toolbar, BorderLayout.NORTH);

    //sets first page
    onSelectContent(mContentTree.getIterator().toBegin());
}