List of usage examples for javax.swing.event HyperlinkEvent getDescription
public String getDescription()
From source file:net.pms.newgui.LanguageSelection.java
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);//from w w w. j a va 2s. c o m 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; }
From source file:com.urswolfer.intellij.plugin.gerrit.rest.GerritUtil.java
public void showAddGitRepositoryNotification(final Project project) { NotificationBuilder notification = new NotificationBuilder(project, "Insufficient dependencies for Gerrit plugin", "Please configure a Git repository.<br/><a href='vcs'>Open Settings</a>") .listener(new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (event.getDescription().equals("vcs")) { ShowSettingsUtil.getInstance().showSettingsDialog(project, ActionsBundle.message("group.VcsGroup.text")); }//from w w w.j a v a 2 s . c o m } } }); notificationService.notifyWarning(notification); }
From source file:net.minelord.gui.panes.IRCPane.java
public void startClient(final String nick) { IRCLog = new ArrayList<String>(); SwingUtilities.invokeLater(new Runnable() { @Override//from w w w.j a va 2s .c o m public void run() { text = new JEditorPane("text/html", "<HTML>"); text.setEditable(false); kit = new HTMLEditorKit(); text.setEditorKit(kit); client.connect("irc.liberty-unleashed.co.uk", "#moomoohk", nick, instance); scroller = new JScrollPane(text); text.setEditable(false); connect(); scroller.setBounds(20, 20, 810, 250); add(scroller); input = new JTextField(); input.setBounds(20, 270, 810, 30); Color bgColor = Color.gray.darker().darker(); UIDefaults defaults = new UIDefaults(); defaults.put("EditorPane[Enabled].backgroundPainter", bgColor); text.putClientProperty("Nimbus.Overrides", defaults); text.putClientProperty("Nimbus.Overrides.InheritDefaults", true); text.setBackground(bgColor); input.setBackground(Color.gray); input.setForeground(Color.gray.darker().darker().darker()); input.setEnabled(false); text.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (event.getDescription().charAt(0) == '#') { String[] params = { event.getDescription() }; IRCCommand.getCommand("/join").execute(client, params); } else OSUtils.browse(event.getURL().toString()); } } }); text.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent paramFocusEvent) { } @Override public void focusGained(FocusEvent paramFocusEvent) { input.requestFocus(); } }); scroller.setViewportView(text); add(input); input.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == 10) { if (input.getText().length() > 0) { lastCommandSelector = lastCommands.size(); lastCommands.add(input.getText()); } sendMessage(input.getText()); input.setText(""); } if (arg0.getKeyCode() == 27) input.setText(""); if (arg0.getKeyCode() == 17) { int before = input.getText().length(); if (input.getText().charAt(0) == '/') { input.setText(completeNick(input.getText())); input.select( input.getText().length() - completeNick(input.getText()).length() + before, input.getText().length()); } else { input.setText(completeCommand(input.getText())); input.select(input.getText().length() - completeCommand(input.getText()).length() + before, input.getText().length()); } } if (arg0.getKeyCode() == 38) if (lastCommandSelector > 0) { lastCommandSelector--; input.setText(lastCommands.get(lastCommandSelector)); } if (arg0.getKeyCode() == 40) if (lastCommandSelector < lastCommands.size()) { lastCommandSelector++; if (lastCommandSelector == lastCommands.size()) input.setText(""); if (lastCommandSelector < lastCommands.size()) input.setText(lastCommands.get(lastCommandSelector)); return; } } @Override public void keyPressed(KeyEvent arg0) { } }); } }); }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatConversationPanel.java
/** * Opens a link in the default browser when clicked and shows link url in a * popup on mouseover./* w ww .j ava 2 s. c o m*/ * * @param e The HyperlinkEvent. */ public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) { String href = e.getDescription(); this.isCurrentHrefImg = e.getSourceElement().getName().equals("img"); this.currentHref = href; } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) { this.currentHref = ""; this.isCurrentHrefImg = false; } }
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();// ww w.jav a 2 s . c om 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; } } try { desktop.browse(url.toURI()); } catch (URISyntaxException ex) { } catch (IOException ex) { } } } } }
From source file:pl.kotcrab.arget.gui.MainWindow.java
private void createAndShowGUI() { setTitle(App.APP_NAME);//from ww w.j a v a 2 s . c o m setBounds(100, 100, 800, 700); setMinimumSize(new Dimension(500, 250)); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setIconImage(App.loadImage("/data/icon/icon.png")); sessionWindowManager = new SessionWindowManager(this); if (profile.mainWindowBounds != null && GraphicsUtils.isRectangleDisplayableOnScreen(profile.mainWindowBounds)) setBounds(profile.mainWindowBounds); createMenuBars(); contactsPanel = new ContactsPanel(profile, this); statusPane = new JTextPane(); statusPane.setBorder(new EmptyBorder(1, 3, 2, 0)); statusPane.setContentType("text/html"); statusPane.setBackground(null); statusPane.setHighlighter(null); statusPane.setEditable(false); statusPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); statusPane.setFont(new Font("Tahoma", Font.PLAIN, 13)); statusPane.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) { String desc = e.getDescription(); if (desc.startsWith("version-mismatch")) { desc = desc.substring(desc.indexOf("://") + 3); String[] versionInfo = desc.split("!"); new VersionMismatchDialog(MainWindow.instance, versionInfo[0], Integer.valueOf(versionInfo[1])); } } } }); JPanel bottomPanel = new JPanel(new BorderLayout(0, 0)); getContentPane().add(bottomPanel, BorderLayout.SOUTH); scrollLockToggle = new WebToggleButton(); scrollLockToggle.setToolTipText("Scroll lock"); scrollLockToggle.setRolloverDecoratedOnly(true); scrollLockToggle.setDrawFocus(false); scrollLockToggle.setIcon(App.loadImageIcon("/data/scrolllock.png")); scrollLockToggle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { postScrollLockUpdate(); } }); bottomPanel.add(statusPane); bottomPanel.add(scrollLockToggle, BorderLayout.EAST); splitPane = new JSplitPane(); splitPane.setBorder(new BottomSplitPaneBorder()); splitPane.setResizeWeight(0); splitPane.setContinuousLayout(true); splitPane.setOneTouchExpandable(true); getContentPane().add(splitPane, BorderLayout.CENTER); homePanel = new HomePanel(profile.fileName); logPanel = new LoggerPanel(); errorStatusPanel = new ErrorStatusPanel(); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(contactsPanel, BorderLayout.CENTER); leftPanel.add(errorStatusPanel, BorderLayout.SOUTH); splitPane.setLeftComponent(leftPanel); splitPane.setRightComponent(null); setCenterScreenTo(homePanel); addWindowFocusListener(new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { instance.validate(); instance.revalidate(); instance.repaint(); getCenterScreen().onShow(); } @Override public void windowLostFocus(WindowEvent e) { getCenterScreen().onHide(); } }); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent evt) { ExitCleaner.forceExit(); } }); setVisible(true); }