List of usage examples for javax.swing JTextPane addHyperlinkListener
public synchronized void addHyperlinkListener(HyperlinkListener listener)
From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java
public static JTextPane createTextPane(final Project project, String value, boolean editable, boolean navigation) { JTextPane desc = new JTextPane(); desc.addHyperlinkListener(new NavigationListener(project)); enableCapability(desc, project, value, editable, navigation); return desc;// ww w. j a v a 2 s . co m }
From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.AbstractTextAnnotationRenderer.java
private void configureViewer(JTextPane viewerPane) { viewerPane.setContentType("text/html"); kit = new HTMLEditorKit(); viewerPane.setEditorKitForContentType("text/html", kit); viewerPane.setEditable(false);/*from ww w. java 2 s . co m*/ disableViewer(); setViewerText(""); viewerPane.addHyperlinkListener(new TextAnnotationPreviewHyperlinkListener(getConceptPanel(), viewerPane)); }
From source file:esmska.gui.AboutFrame.java
private void creditsButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_creditsButtonActionPerformed //show credits try {/*w ww. j a v a 2 s . c o m*/ 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 "); //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.hp.alm.ali.idea.content.settings.SettingsPanel.java
public SettingsPanel(final Project prj, Color bgColor) { this.prj = prj; this.projectConf = prj.getComponent(AliProjectConfiguration.class); previewAndConnection = new JPanel(new GridBagLayout()); previewAndConnection.setOpaque(false); GridBagConstraints c2 = new GridBagConstraints(); c2.gridx = 0;/*from w w w . j a v a 2 s.c o m*/ c2.gridy = 1; c2.gridwidth = 2; c2.weighty = 1; c2.fill = GridBagConstraints.VERTICAL; JPanel filler = new JPanel(); filler.setOpaque(false); previewAndConnection.add(filler, c2); passwordPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); passwordPanel.setBackground(bgColor); JLabel label = new JLabel("Password"); label.setFont(label.getFont().deriveFont(Font.BOLD)); passwordPanel.add(label); final JPasswordField password = new JPasswordField(24); passwordPanel.add(password); JButton connect = new JButton("Login"); passwordPanel.add(connect); final JLabel message = new JLabel(); passwordPanel.add(message); ActionListener connectionAction = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { try { checkConnection(projectConf.getLocation(), projectConf.getDomain(), projectConf.getProject(), projectConf.getUsername(), password.getText()); } catch (AuthenticationFailed e) { message.setText(e.getMessage()); return; } projectConf.ALM_PASSWORD = password.getText(); projectConf.fireChanged(); } }; password.addActionListener(connectionAction); connect.addActionListener(connectionAction); restService = prj.getComponent(RestService.class); restService.addServerTypeListener(this); location = createTextPane(bgColor); domain = createTextPane(bgColor); project = createTextPane(bgColor); username = createTextPane(bgColor); final JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(bgColor); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); final JTextPane textPane = new JTextPane(); textPane.setEditorKit(new HTMLEditorKit()); textPane.setText( "<html><body>HP ALM integration can be configured on <a href=\"ide\">IDE</a> and overridden on <a href=\"project\">project</a> level.</body></html>"); textPane.setEditable(false); textPane.addHyperlinkListener(this); textPane.setBackground(bgColor); textPane.setCaret(new NonAdjustingCaret()); panel.add(textPane, BorderLayout.CENTER); JPanel content = new JPanel(new BorderLayout()); content.setBackground(bgColor); content.add(panel, BorderLayout.NORTH); content.add(previewAndConnection, BorderLayout.WEST); preview = new JPanel(new GridBagLayout()) { public Dimension getPreferredSize() { Dimension dim = super.getPreferredSize(); // make enough room for the connection status message dim.width = Math.max(dim.width, 300); return dim; } public Dimension getMinimumSize() { return getPreferredSize(); } }; connectedTo(restService.getServerTypeIfAvailable()); preview.setBackground(bgColor); final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.anchor = GridBagConstraints.WEST; preview.add(location, c); c.gridwidth = 1; c.gridy++; preview.add(domain, c); c.gridy++; preview.add(project, c); c.gridy++; preview.add(username, c); c.gridx++; c.gridy--; c.gridheight = 2; c.weightx = 0; c.anchor = GridBagConstraints.SOUTHEAST; final LinkLabel reload = new LinkLabel("Reload", IconLoader.getIcon("/actions/sync.png")); reload.setListener(new LinkListener() { public void linkSelected(LinkLabel linkLabel, Object o) { projectConf.fireChanged(); } }, null); preview.add(reload, c); JPanel previewNorth = new JPanel(new BorderLayout()); previewNorth.setBackground(bgColor); previewNorth.add(preview, BorderLayout.NORTH); addToGridBagPanel(0, 0, previewAndConnection, previewNorth); setBackground(bgColor); setLayout(new BorderLayout()); add(content, BorderLayout.CENTER); onChanged(); ApplicationManager.getApplication().getComponent(AliConfiguration.class).addListener(this); projectConf.addListener(this); }
From source file:esmska.gui.AboutFrame.java
private void licenseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_licenseButtonActionPerformed //show licence try {//from w ww .ja va 2 s .co m logger.fine("Showing license..."); String license = IOUtils.toString(getClass().getResourceAsStream(RES + "license.txt"), "UTF-8"); final String agpl = IOUtils.toString(getClass().getResourceAsStream(RES + "gnu-agpl.txt"), "UTF-8"); license = MiscUtils.escapeHtml(license); license = license.replaceAll("GNU Affero General Public License", "<a href=\"agpl\">GNU Affero General Public License</a>"); final JTextPane tp = new JTextPane(); tp.setContentType("text/html; charset=UTF-8"); tp.setText("<html><pre>" + license + "</pre></html>"); tp.setEditable(false); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); tp.setPreferredSize(new Dimension((int) d.getWidth() / 2, (int) d.getHeight() / 2)); //reasonable size tp.setCaretPosition(0); //make links clickable tp.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { logger.fine("Showing GNU AGPL..."); tp.setText(null); tp.setContentType("text/plain"); tp.setText(agpl); tp.setCaretPosition(0); } } }); String option = l10n.getString("AboutFrame.Acknowledge"); 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.License")); dialog.setResizable(true); dialog.pack(); dialog.setVisible(true); } catch (IOException ex) { logger.log(Level.WARNING, "Could not show license", ex); } }
From source file:org.echocat.velma.dialogs.AboutDialog.java
protected void createIntroduction(@Nonnull Resources resources) { final URL iconUrl = resources.getIconUrl(48); final StringBuilder body = new StringBuilder(); body.append("<html>"); body.append("<head><style>" + "td { margin-right: 10px; }" + "</style></head>"); body.append("<body style='font-family: sans; font-size: 1em'><table><tr>"); body.append("<td valign='top'><img src='").append(iconUrl).append("' /></td>"); body.append("<td valign='top'>"); body.append("<h2>").append(escapeHtml4(resources.getApplicationName())); final String version = resources.getVersion(); if (!isEmpty(version)) { body.append("<br/><span style='font-size: 0.6em'>") .append(resources.formatEscaped("versionText", version)).append("</span>"); }/*w w w . j a va 2 s . c om*/ body.append("</h2>"); body.append("<p>Copyright 2011-2012 <a href='https://echocat.org'>echocat</a></p>"); body.append("<p><a href='http://mozilla.org/MPL/2.0/'>") .append(resources.formatEscaped("licensedUnder", "MPL 2.0")).append("</a></p>"); body.append("<p><table cellpadding='0' cellspacing='0'>"); body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "echocat")) .append(":</td><td><a href='https://echocat.org'>echocat.org</a></td></tr>"); body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "Velma")) .append(":</td><td><a href='https://velma.echocat.org'>velma.echocat.org</a></td></tr>"); body.append("</table></p>"); body.append("<h4>").append(resources.formatEscaped("developers")) .append("</h4><table cellpadding='0' cellspacing='0'>"); body.append( "<tr><td>Gregor Noczinski</td><td><a href='mailto:gregor@noczinski.eu'>gregor@noczinski.eu</a></td><td><a href='https://github.com/blaubaer'>github.com/blaubaer</a></td></tr>"); body.append("</table>"); body.append("</td>"); body.append("</tr></table></body></html>"); final JTextPane text = new JTextPane(); text.setMargin(new Insets(0, 0, 0, 0)); text.setContentType("text/html"); text.setText(body.toString()); text.setFont(new Font(DIALOG, PLAIN, 12)); text.setBackground(new Color(255, 255, 255, 0)); text.setEditable(false); text.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == ACTIVATED && isDesktopSupported()) { final Desktop desktop = getDesktop(); if (desktop.isSupported(BROWSE)) { try { desktop.browse(e.getURL().toURI()); } catch (IOException | URISyntaxException exception) { LOG.error("Could not open " + e.getURL() + " because of an exception.", exception); } } else { LOG.error("Could not open " + e.getURL() + " because browse is not supported by desktop."); } } repaint(); } }); text.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { repaint(); } @Override public void mousePressed(MouseEvent e) { repaint(); } @Override public void mouseReleased(MouseEvent e) { repaint(); } @Override public void mouseEntered(MouseEvent e) { repaint(); } @Override public void mouseExited(MouseEvent e) { repaint(); } }); add(text, new CC().spanX(2).growX().minWidth("10px")); }
From source file:org.languagetool.gui.ResultArea.java
ResultArea(final ResourceBundle messages, final LanguageToolSupport ltSupport, final JTextPane statusPane) { this.messages = messages; this.ltSupport = ltSupport; this.statusPane = statusPane; statusPane.setContentType("text/html"); statusPane.setText(Main.HTML_GREY_FONT_START + messages.getString("resultAreaText") + Main.HTML_FONT_END); statusPane.setEditable(false);/*from w w w . j a v a 2 s .c om*/ statusPane.addHyperlinkListener(new MyHyperlinkListener()); statusPane.setTransferHandler(new RetainLineBreakTransferHandler()); ltSupport.addLanguageToolListener(new LanguageToolListener() { @Override public void languageToolEventOccurred(LanguageToolEvent event) { if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) { final Language lang = ltSupport.getLanguage(); final String langName; if (lang.isExternal()) { langName = lang.getTranslatedName(messages) + Main.EXTERNAL_LANGUAGE_SUFFIX; } else { langName = lang.getTranslatedName(messages); } final String startCheckText = Main.HTML_GREY_FONT_START + Tools.makeTexti18n(messages, "startChecking", langName) + "..." + Main.HTML_FONT_END; statusPane.setText(startCheckText); setStartText(startCheckText); if (event.getCaller() == marker) { statusPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); } } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) { inputText = event.getSource().getTextComponent().getText(); setRuleMatches(event.getSource().getMatches()); if (event.getCaller() == marker || event.getCaller() == null) { displayResult(); if (event.getCaller() == marker) { statusPane.setCursor(Cursor.getDefaultCursor()); } } } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED || event.getType() == LanguageToolEvent.Type.RULE_ENABLED) { inputText = event.getSource().getTextComponent().getText(); setRuleMatches(event.getSource().getMatches()); displayResult(); } } }); }
From source file:org.languagetool.gui.Tools.java
static void addHyperlinkListener(JTextPane pane) { pane.addHyperlinkListener(new HyperlinkListener() { @Override/*from w ww .jav a 2 s . c o m*/ public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { Tools.openURL(e.getURL()); } } }); }
From source file:tufts.vue.ui.InspectorPane.java
private static JComponent buildSummary(final Resource r, final MetaMap data) { final JTextPane htmlText = new JTextPane(); htmlText.setEditable(false);//from w ww .j a va2 s .c o m htmlText.setContentType("text/html"); htmlText.setName("description:" + r); htmlText.addHyperlinkListener(DefaultHyperlinkListener); //final MetaMap data = (node == null ? null : node.getRawData()); final String desc = findProperty(r, data, "descriptionSummary", "Description", "Summary"); final String summary; if (desc != null || r == null) { summary = buildSummaryWithDescription(r, data, desc); if (summary == null || summary.length() == 0) return null; //htmlText.setText("No Description");// todo: should just hide panel else htmlText.setText(summary); if (DEBUG.DATA && data != null) data.put("$reformatted", "[" + summary + "]"); } else { //if (r != null) { //------------------------------------------------------------------ // No description was found: build a summary from just the Resource //------------------------------------------------------------------ summary = buildSummaryFromResource(r); htmlText.setText(summary); if (DEBUG.DATA) r.setProperty("~reformatted", summary); } //else return null; // This must be done last. Why this doesn't work up front I don't know: there // must be some other way... GUI.setDocumentFont(htmlText, GUI.ContentFace); return htmlText; // if (loader != null) { // // this not actually helping, other than we get to see "Loading..." before it hangs. // final Thread _loader = loader; // GUI.invokeAfterAWT(new Runnable() { public void run() { // _loader.start(); // }}); // } }