List of usage examples for javax.swing.event HyperlinkEvent getURL
public URL getURL()
From source file:org.yccheok.jstock.gui.Utils.java
public static void launchWebBrowser(javax.swing.event.HyperlinkEvent evt) { if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) { URL url = evt.getURL(); if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.BROWSE)) { if (url == null) { // www.yahoo.com considered an invalid URL. Hence, evt.getURL() returns null. String string = "http://" + evt.getDescription(); try { url = new URL(string); } catch (MalformedURLException ex) { return; }//from w ww . j a v a 2s . co m } try { desktop.browse(url.toURI()); } catch (URISyntaxException ex) { } catch (IOException ex) { } } } } }
From source file:pl.kotcrab.arget.gui.session.msg.TextMessage.java
public TextMessage(MsgType type, String text, boolean markAsRead) { super(type);/*from ww w .j a v a 2s .com*/ textPane = new JTextPane(); textPane.setAlignmentX(Component.LEFT_ALIGNMENT); textPane.setEditorKit(new WrapHTMLEditorKit()); textPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); textPane.setEditable(false); textPane.setBackground(null); textPane.setBorder(new EmptyBorder(3, 3, 0, 0)); textPane.setFont(textFont); textPane.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent hle) { if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) { if (DesktopUtils.openWebsite(hle.getURL()) == false) JOptionPane.showMessageDialog(null, "Invalid URL: " + hle.getURL(), "Error", JOptionPane.ERROR_MESSAGE); } } }); setText(text); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(textPane); DateFormat dateFormat = new SimpleDateFormat("[HH:mm] "); Date date = new Date(); String textToShow = dateFormat.format(date); if (markAsRead == false) textToShow += "*"; timeLabel = new JLabel(textToShow); timeLabel.setBorder(new EmptyBorder(0, 3, 3, 0)); timeLabel.setForeground(Color.GRAY); timeLabel.setFont(smallTextFont); add(timeLabel); }
From source file:processing.app.Editor.java
protected SketchTextArea createTextArea() throws IOException { final SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords()); textArea.requestFocusInWindow();/* ww w. j ava2s .co m*/ textArea.setMarkOccurrences(PreferencesData.getBoolean("editor.advanced")); textArea.setMarginLineEnabled(false); textArea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding")); textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias")); textArea.setTabsEmulated(PreferencesData.getBoolean("editor.tabs.expand")); textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size")); textArea.setEditorListener(new EditorListener(this)); textArea.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { try { platform.openURL(hyperlinkEvent.getURL().toExternalForm()); } catch (Exception e) { Base.showWarning(e.getMessage(), e.getMessage(), e); } } }); textArea.addCaretListener(new CaretListener() { @Override public void caretUpdate(CaretEvent e) { int lineStart = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getMark()); int lineEnd = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getDot()); lineStatus.set(lineStart, lineEnd); } }); ToolTipManager.sharedInstance().registerComponent(textArea); configurePopupMenu(textArea); return textArea; }
From source file:tvbrowser.ui.settings.channel.ChannelGroupInfoDialog.java
/** * Create the GUI//w w w .j a v a 2 s .c o m */ private void initGui() { UiUtilities.registerForClosing(this); JPanel panel = (JPanel) getContentPane(); panel.setBorder(Borders.DLU4_BORDER); panel.setLayout(new FormLayout("fill:default:grow, default", "fill:default:grow, 3dlu, default")); CellConstraints cc = new CellConstraints(); final JEditorPane infoPanel = new JEditorPane(); infoPanel.setEditorKit(new ExtendedHTMLEditorKit()); ExtendedHTMLDocument doc = (ExtendedHTMLDocument) infoPanel.getDocument(); infoPanel.setEditable(false); infoPanel.setText(generateHtml(doc)); infoPanel.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { URL url = evt.getURL(); if (url != null) { Launch.openURL(url.toString()); } } } }); final JScrollPane scrollPane = new JScrollPane(infoPanel); panel.add(scrollPane, cc.xyw(1, 1, 2)); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { infoPanel.scrollRectToVisible(new Rectangle(0, 0)); } }); panel.add(ok, cc.xy(2, 3)); setSize(500, 350); }
From source file:tvbrowser.ui.settings.PluginInfoDialog.java
/** * Create the GUI/*w w w . j a v a2 s .c om*/ */ private void initGui() { JPanel panel = (JPanel) getContentPane(); panel.setBorder(Borders.DLU4_BORDER); panel.setLayout(new FormLayout("fill:default:grow, default", "fill:default:grow, 3dlu, default")); CellConstraints cc = new CellConstraints(); JEditorPane infoPanel = new JEditorPane(); infoPanel.setEditorKit(new ExtendedHTMLEditorKit()); ExtendedHTMLDocument doc = (ExtendedHTMLDocument) infoPanel.getDocument(); infoPanel.setEditable(false); infoPanel.setText(generateHtml(doc)); infoPanel.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { URL url = evt.getURL(); if (url != null) { Launch.openURL(url.toString()); } } } }); panel.add(new JScrollPane(infoPanel), cc.xyw(1, 1, 2)); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { close(); } }); panel.add(ok, cc.xy(2, 3)); Settings.layoutWindow("pluginInfoDialog", this, new Dimension(700, 500)); UiUtilities.registerForClosing(this); }
From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java
public void showMessage(final String message) throws HeadlessException { final JPanel messagePanel = new JPanel(new GridBagLayout()); final JEditorPane textField = new JEditorPane(); textField.setContentType("text/html"); textField.setText(message);//w ww. ja v a 2 s . com textField.setEditable(false); textField.setBackground(null); textField.setBorder(null); textField.setEditable(false); textField.setForeground(UIManager.getColor("Label.foreground")); textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); textField.setFont(UIManager.getFont("Label.font")); textField.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (IOException e1) { // Ignore failure to launch URL } catch (URISyntaxException e1) { // Ignore failure to launch URL } } } } }); messagePanel.add(textField); textField.setAlignmentX(SwingConstants.CENTER); JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName, JOptionPane.INFORMATION_MESSAGE, icon); }
From source file:uk.sipperfly.ui.Exactly.java
private void aboutAreaHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_aboutAreaHyperlinkUpdate if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) { System.out.println(evt.getURL()); Desktop desktop = Desktop.getDesktop(); try {/*w w w . j a v a 2 s. c om*/ desktop.browse(evt.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:uk.sipperfly.ui.Exactly.java
private void authorAreaHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_authorAreaHyperlinkUpdate if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) { System.out.println(evt.getURL()); Desktop desktop = Desktop.getDesktop(); try {/*from www . j a va2s .c o m*/ desktop.browse(evt.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:uk.sipperfly.ui.Exactly.java
private void contactAreaHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_contactAreaHyperlinkUpdate if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) { System.out.println(evt.getURL()); Desktop desktop = Desktop.getDesktop(); try {/*from w ww.j av a2 s.c o m*/ desktop.browse(evt.getURL().toURI()); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:util.ui.UiUtilities.java
/** * Creates a Html EditorPane that holds a HTML-Help Text * * Links will be displayed and are clickable * * @param html/*w ww .j a v a 2 s . c om*/ * HTML-Text to display * @param background The color for the background. * @return EditorPane that holds a Help Text * @since 2.7.2 */ public static JEditorPane createHtmlHelpTextArea(String html, Color background) { return createHtmlHelpTextArea(html, new HyperlinkListener() { private String mTooltip; public void hyperlinkUpdate(HyperlinkEvent evt) { JEditorPane pane = (JEditorPane) evt.getSource(); if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { mTooltip = pane.getToolTipText(); pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); if (evt.getURL() != null) { pane.setToolTipText(evt.getURL().toExternalForm()); } } if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(Cursor.getDefaultCursor()); pane.setToolTipText(mTooltip); } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { URL url = evt.getURL(); if (url != null) { Launch.openURL(url.toString()); } } } }, background); }