Java Code Examples for javax.swing.event.HyperlinkListener

The following are top voted examples for showing how to use javax.swing.event.HyperlinkListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: BrowserUtils.java   View source code 6 votes vote down vote up
public static HyperlinkListener createHyperlinkListener() {
    return new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent hlevt) {
            if (HyperlinkEvent.EventType.ACTIVATED == hlevt.getEventType()) {
                final URL url = hlevt.getURL();
                if (url != null) {
                    try {
                        openBrowser(url.toURI());
                    } catch (URISyntaxException e) {
                        LogManager.log(e);
                    }
                }
            }
        }
    };
}
 
Example 2
Project: incubator-netbeans   File: NotificationsManager.java   View source code 6 votes vote down vote up
public void setupPane(JTextPane pane, final File[] files, String fileNames, final File projectDir, final String url, final String revision) {
     String msg = revision == null
             ? NbBundle.getMessage(NotificationsManager.class, "MSG_NotificationBubble_DeleteDescription", fileNames, CMD_DIFF) //NOI18N
             : NbBundle.getMessage(NotificationsManager.class, "MSG_NotificationBubble_Description", fileNames, url, CMD_DIFF); //NOI18N
    pane.setText(msg);

    pane.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                if(CMD_DIFF.equals(e.getDescription())) {
                    Context ctx = new Context(files);
                    DiffAction.diff(ctx, Setup.DIFFTYPE_REMOTE, NbBundle.getMessage(NotificationsManager.class, "LBL_Remote_Changes", projectDir.getName()), false); //NOI18N
                } else if (revision != null) {
                    try {
                        SearchHistoryAction.openSearch(new SVNUrl(url), projectDir, Long.parseLong(revision));
                    } catch (MalformedURLException ex) {
                        LOG.log(Level.WARNING, null, ex);
                    }
                }
            }
        }
    });
}
 
Example 3
Project: incubator-netbeans   File: ShowNotifications.java   View source code 6 votes vote down vote up
private static JTextPane createInfoPanel(String notification) {
    JTextPane balloon = new JTextPane();
    balloon.setContentType("text/html");
    String text = getDetails(notification).replaceAll("(\r\n|\n|\r)", "<br>");
    balloon.setText(text);
    balloon.setOpaque(false);
    balloon.setEditable(false);
    balloon.setBorder(new EmptyBorder(0, 0, 0, 0));


    if (UIManager.getLookAndFeel().getID().equals("Nimbus")) {
        //#134837
        //http://forums.java.net/jive/thread.jspa?messageID=283882
        balloon.setBackground(new Color(0, 0, 0, 0));
    }

    balloon.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                URLDisplayer.getDefault().showURL(e.getURL());
            }
        }
    });
    return balloon;
}
 
Example 4
Project: rapidminer   File: FixedWidthEditorPane.java   View source code 6 votes vote down vote up
/**
 * Creates a pane with the given rootlessHTML as text with the given width.
 *
 * @param width
 *            the desired width
 * @param rootlessHTML
 *            the text, can contain hyperlinks that will be clickable
 */
public FixedWidthEditorPane(int width, String rootlessHTML) {
	super("text/html", "");
	this.width = width;
	this.rootlessHTML = rootlessHTML;
	updateLabel();

	setEditable(false);
	setFocusable(false);
	installDefaultStylesheet();
	addHyperlinkListener(new HyperlinkListener() {

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				RMUrlHandler.handleUrl(e.getDescription());
			}
		}
	});

}
 
Example 5
Project: jmt   File: HtmlPanel.java   View source code 6 votes vote down vote up
/**
 * Initialize this component
 */
private void init() {
	antiAliasing = false;
	// By default disable editing
	setEditable(false);
	setContentType("text/html");

	// Adds hyperlink listener
	this.addHyperlinkListener(new HyperlinkListener() {
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				// An hyperlink is activated
				if (getPage() != null && e.getURL().getPath() != null && e.getURL().getPath().equals(getPage().getPath())) {
					setURL(e.getURL());
				} else {
					// Open external links in default browser
					BrowserLauncher.openURL(e.getURL().toString());
				}
			}
		}
	});
}
 
Example 6
Project: QN-ACTR-Release   File: HtmlPanel.java   View source code 6 votes vote down vote up
/**
 * Initialize this component
 */
private void init() {
	antiAliasing = false;
	// By default disable editing
	setEditable(false);
	setContentType("text/html");

	// Adds hyperlink listener
	this.addHyperlinkListener(new HyperlinkListener() {
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				// An hyperlink is activated
				if (getPage() != null && e.getURL().getPath() != null && e.getURL().getPath().equals(getPage().getPath())) {
					setURL(e.getURL());
				} else {
					// Open external links in default browser
					BareBonesBrowserLaunch.openURL(e.getURL().toString());
				}
			}
		}
	});
}
 
Example 7
Project: gate-core   File: JTextPaneTableCellRenderer.java   View source code 6 votes vote down vote up
public JTextPaneTableCellRenderer() {
  textPane.setContentType("text/html");
  textPane.setEditable(false);
  textPane.setOpaque(true);
  textPane.setBorder(null);

  textPane.setForeground(UIManager.getColor("Table.selectionForeground"));
  textPane.setBackground(UIManager.getColor("Table.selectionBackground"));

  Font font = UIManager.getFont("Label.font");
  String bodyRule =
      "body { font-family: " + font.getFamily() + "; " + "font-size: "
          + font.getSize() + "pt; "
          + (font.isBold() ? "font-weight: bold;" : "") + "}";
  ((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule);

  textPane.addHyperlinkListener(new HyperlinkListener() {

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
          MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager");
    }
  });
}
 
Example 8
Project: ramus   File: Navigator.java   View source code 6 votes vote down vote up
@Override
public JComponent createComponent() {
    pane.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == EventType.ACTIVATED) {
                location = e.getURL().toExternalForm();
                openLocation();
            }
        }
    });

    pane.setEditable(false);

    scrollPane = new JScrollPane();
    scrollPane.setViewportView(this.pane);
    return scrollPane;
}
 
Example 9
Project: nativehtml   File: SwingTextComponent.java   View source code 6 votes vote down vote up
public SwingTextComponent(final Document document)  {
  //super("text/html");
	this.document = document;
	
	configureEditor(this);
	addHyperlinkListener(new HyperlinkListener() {
         
         @Override
         public void hyperlinkUpdate(HyperlinkEvent event) {
           if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
             RequestHandler requestHandler = document.getRequestHandler();
             if (requestHandler != null) {
               try {
                 requestHandler.openLink(event.getURL().toURI());
               } catch (URISyntaxException e) {
                 e.printStackTrace();
               }
             }
           }
         }
       });
}
 
Example 10
Project: terrier-desktop   File: HelpDialog.java   View source code 6 votes vote down vote up
/**
 * This method initializes jTextPane	
 * 	
 * @return javax.swing.JTextPane	
 */    
private JTextPane getJTextPane() {
	if (jTextPane == null) {
		jTextPane = new JTextPane();
		jTextPane.setContentType("text/html");
		jTextPane.setText(helpText);
		jTextPane.addHyperlinkListener(new HyperlinkListener() {
			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
					try{
						FileOpener opener = new MultiOSFileOpener();
						opener.open(e.getURL().toString());
					}catch (Exception ex) {
						logger.error("", ex);
					}
				}
			}
		});
		jTextPane.setEditable(false);			
	}
	return jTextPane;
}
 
Example 11
Project: intellij-ce-playground   File: SceneBuilderEditor.java   View source code 6 votes vote down vote up
private void createErrorPage() {
  myErrorLabel.setOpaque(false);

  myErrorLabel.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      initSceneBuilder(true);
    }
  });

  myErrorStack = new JTextArea(50, 20);
  myErrorStack.setEditable(false);

  myErrorPanel.add(myErrorLabel, BorderLayout.NORTH);
  myErrorPanel.add(ScrollPaneFactory.createScrollPane(myErrorStack), BorderLayout.CENTER);
  myPanel.add(myErrorPanel);
}
 
Example 12
Project: 4Space-5   File: DepLoader.java   View source code 6 votes vote down vote up
@Override
public void showErrorDialog(String name, String url) {
    JEditorPane ep = new JEditorPane("text/html",
            "<html>" +
                    owner + " was unable to download required library " + name +
                    "<br>Check your internet connection and try restarting or download it manually from" +
                    "<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
                    "</html>");

    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
                    Desktop.getDesktop().browse(event.getURL().toURI());
            } catch (Exception e) {
            }
        }
    });

    JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
}
 
Example 13
Project: CodeChickenCore   File: DepLoader.java   View source code 6 votes vote down vote up
@Override
public void displayYellingData() {
    StringBuilder builder = new StringBuilder();
    builder.append("<html>");
    for (String data : yellingData) {
        builder.append("<br>");
        builder.append(data);
    }
    builder.append("</html>");
    JEditorPane ep = new JEditorPane("text/html", builder.toString());
    ep.setAutoscrolls(true);
    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                    Desktop.getDesktop().browse(event.getURL().toURI());
                }
            } catch (Exception ignored) {
            }
        }
    });
    JOptionPane.showMessageDialog(null, ep, "DepLoader is Deprecated!", -1);
}
 
Example 14
Project: CodeChickenCore   File: DepLoader.java   View source code 6 votes vote down vote up
@Override
public void showErrorDialog(String name, String url) {
    JEditorPane ep = new JEditorPane("text/html", "<html>" + owner + " was unable to download required library " + name + "<br>Check your internet connection and try restarting or download it manually from" + "<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" + "</html>");

    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                    Desktop.getDesktop().browse(event.getURL().toURI());
                }
            } catch (Exception e) {
            }
        }
    });

    JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
}
 
Example 15
Project: PhET   File: SoftwareAgreementManager.java   View source code 6 votes vote down vote up
public MessagePane( final JDialog owner, final SessionMessage sessionMessage ) {
    super( "" );

    // insert our own hyperlink descriptions into the message, so translators can't mess them up
    Object[] args = { LINK_SHOW_STATISTICS_DETAILS, LINK_SHOW_SOFTWARE_AGREEMENT };
    String htmlFragment = MessageFormat.format( MESSAGE_PATTERN, args );
    setText( HTMLUtils.createStyledHTMLFromFragment( htmlFragment ) );

    addHyperlinkListener( new HyperlinkListener() {
        public void hyperlinkUpdate( HyperlinkEvent e ) {
            if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
                if ( e.getDescription().equals( LINK_SHOW_STATISTICS_DETAILS ) ) {
                    showStatisticsDetails( owner, sessionMessage );
                }
                else if ( e.getDescription().equals( LINK_SHOW_SOFTWARE_AGREEMENT ) ) {
                    showSoftwareAgreement( owner );
                }
                else {
                    System.err.println( "SoftwareAgreementManager.MessagePane.hyperlinkUpdate: unsupported hyperlink, description=" + e.getDescription() );
                }
            }
        }
    } );
    setBackground( new JPanel().getBackground() );//see #1275
}
 
Example 16
Project: PhET   File: PrivacyPreferencesPanel.java   View source code 6 votes vote down vote up
public DescriptionPane( final SessionMessage sessionMessage ) {
    super( "" );

    // insert our own hyperlink descriptions into the message, so translators can't mess them up
    Object[] args = { LINK_SHOW_STATISTICS_DETAILS };
    String htmlFragment = MessageFormat.format( DESCRIPTION_PATTERN, args );
    setText( HTMLUtils.createStyledHTMLFromFragment( htmlFragment ) );

    addHyperlinkListener( new HyperlinkListener() {
        public void hyperlinkUpdate( HyperlinkEvent e ) {
            if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
                if ( e.getDescription().equals( LINK_SHOW_STATISTICS_DETAILS ) ) {
                    showStatisticsDetails( SwingUtilities.getWindowAncestor( DescriptionPane.this ), sessionMessage );
                }
                else {
                    System.err.println( "PrivacyPreferencesPanel.DescriptionPane.hyperlinkUpdate: unsupported hyperlink, description=" + e.getDescription() );
                }
            }
        }
    } );
    setBackground( new JPanel().getBackground() );
}
 
Example 17
Project: PhET   File: InitializationDialog.java   View source code 6 votes vote down vote up
private void showHelp( String helpText ) {
    
    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKit( new HTMLEditorKit() );
    editorPane.setText( helpText );
    editorPane.setEditable( false );
    editorPane.setBackground( new JLabel().getBackground() );
    editorPane.setFont( new JLabel().getFont() );
    editorPane.addHyperlinkListener( new HyperlinkListener() {
        public void hyperlinkUpdate( HyperlinkEvent e ) {
            if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
                PhetServiceManager.showWebPage( e.getURL() );
            }
        }
    } );
    
    JOptionPane.showMessageDialog( this, editorPane, TUStrings.HELP_TITLE, JOptionPane.INFORMATION_MESSAGE );
}
 
Example 18
Project: scelight   File: Browser.java   View source code 6 votes vote down vote up
/**
 * Creates a new {@link Browser}.
 */
public Browser() {
	setEditable( false );
	setContentType( "text/html" );
	
	addHyperlinkListener( new HyperlinkListener() {
		@Override
		public void hyperlinkUpdate( final HyperlinkEvent event ) {
			if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED ) {
				if ( event.getURL() != null )
					LEnv.UTILS_IMPL.get().showURLInBrowser( event.getURL() );
			} else if ( event.getEventType() == HyperlinkEvent.EventType.ENTERED ) {
				if ( event.getURL() != null )
					setToolTipText( LUtils.urlToolTip( event.getURL() ) );
			} else if ( event.getEventType() == HyperlinkEvent.EventType.EXITED )
				setToolTipText( null );
		}
	} );
}
 
Example 19
Project: eva2   File: HtmlDemo.java   View source code 6 votes vote down vote up
/**
 *
 */
public HyperlinkListener createHyperLinkListener() {
    return e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (e instanceof HTMLFrameHyperlinkEvent) {
                ((HTMLDocument) htmlEditorPane.getDocument()).processHTMLFrameHyperlinkEvent(
                        (HTMLFrameHyperlinkEvent) e);
            } else {
                try {
                    htmlEditorPane.setPage(e.getURL());
                } catch (IOException ioe) {
                    System.out.println("IOE: " + ioe);
                }
            }
        }
    };
}
 
Example 20
Project: safe-java   File: UiUtil.java   View source code 6 votes vote down vote up
public static JEditorPane createLinkEnabledEditorPane(final Component parent,
                                                      String text) {
    JEditorPane pane = createEditorPane(text);
    HyperlinkListener linkListener = new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                URL url = e.getURL();
                if (!openBrowser(e.getURL())) {
                    JOptionPane.showMessageDialog(parent,
                                                  "An error occurred while opening the URL: " + url.toString(),
                                                  "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    };
    pane.addHyperlinkListener(linkListener);
    return pane;
}
 
Example 21
Project: littleluck   File: EditorPaneDemo.java   View source code 6 votes vote down vote up
private HyperlinkListener createHyperLinkListener() {
    return new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e instanceof HTMLFrameHyperlinkEvent) {
                    ((HTMLDocument) html.getDocument()).processHTMLFrameHyperlinkEvent(
                            (HTMLFrameHyperlinkEvent) e);
                } else {
                    try {
                        html.setPage(e.getURL());
                    } catch (IOException ioe) {
                        System.out.println("IOE: " + ioe);
                    }
                }
            }
        }
    };
}
 
Example 22
Project: SweetHome3D   File: HomePane.java   View source code 6 votes vote down vote up
/**
 * Returns a component able to display message with active links.
 */
private JComponent createEditorPane(String message)
{
	// Use an uneditable editor pane to let user select text in dialog
	JEditorPane messagePane = new JEditorPane("text/html", message);
	messagePane.setEditable(false);
	if (SwingTools.getResolutionScale() != 1)
	{
		messagePane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
	}
	// Add a listener that displays hyperlinks content in browser
	messagePane.addHyperlinkListener(new HyperlinkListener()
	{
		public void hyperlinkUpdate(HyperlinkEvent ev)
		{
			if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
			{
				SwingTools.showDocumentInBrowser(ev.getURL());
			}
		}
	});
	return messagePane;
}
 
Example 23
Project: T.E.C.H   File: DepLoader.java   View source code 6 votes vote down vote up
@Override
public void showErrorDialog(String name, String url) {
    JEditorPane ep = new JEditorPane("text/html", "<html>" +
            owner + " was unable to download required library " + name +
            "<br>Check your internet connection and try restarting or download it manually from" +
            "<br><a href=\"" + url + "\">" + url + "</a> and put it in your mods folder" +
            "</html>");

    ep.setEditable(false);
    ep.setOpaque(false);
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent event) {
            try {
                if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                    Desktop.getDesktop().browse(event.getURL().toURI());
                }
            } catch (Exception e) {
            }
        }
    });

    JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE);
}
 
Example 24
Project: cloud-meter   File: HtmlPane.java   View source code 6 votes vote down vote up
public HtmlPane() {
    this.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                String ref = e.getURL().getRef();
                if (ref != null) {
                    log.debug("reference to scroll to = '" + ref + "'");
                    if (ref.length() > 0) {
                        scrollToReference(ref);
                    } else { // href="#"
                        scrollRectToVisible(new Rectangle(1,1,1,1));
                    }
                }
            }
        }
    });
}
 
Example 25
Project: intellij-ce-playground   File: EditableNotificationMessageElement.java   View source code 6 votes vote down vote up
private MyCellEditor() {
  editorComponent = installJep(new MyJEditorPane(EditableNotificationMessageElement.this));

  HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener();
  editorComponent.addHyperlinkListener(hyperlinkListener);
  editorComponent.addMouseListener(new PopupHandler() {
    @Override
    public void invokePopup(Component comp, int x, int y) {
      if (myTree == null) return;

      final TreePath path = myTree.getLeadSelectionPath();
      if (path == null) {
        return;
      }
      DefaultActionGroup group = new DefaultActionGroup();
      group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
      group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));

      ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
      menu.getComponent().show(comp, x, y);
    }
  });
}
 
Example 26
Project: intellij-ce-playground   File: TipUIUtil.java   View source code 6 votes vote down vote up
@NotNull
public static JEditorPane createTipBrowser() {
  JEditorPane browser = new JEditorPane();
  browser.setEditable(false);
  browser.setBackground(UIUtil.getTextFieldBackground());
  browser.addHyperlinkListener(
    new HyperlinkListener() {
      public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
          BrowserUtil.browse(e.getURL());
        }
      }
    }
  );
  URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
  final StyleSheet styleSheet = UIUtil.loadStyleSheet(resource);
  HTMLEditorKit kit = new HTMLEditorKit() {
    @Override
    public StyleSheet getStyleSheet() {
      return styleSheet != null ? styleSheet : super.getStyleSheet();
    }
  };
  browser.setEditorKit(kit);
  return browser;
}
 
Example 27
Project: intellij-ce-playground   File: NotificationsUtil.java   View source code 6 votes vote down vote up
@Nullable
public static HyperlinkListener wrapListener(@NotNull final Notification notification) {
  final NotificationListener listener = notification.getListener();
  if (listener == null) return null;

  return new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        final NotificationListener listener1 = notification.getListener();
        if (listener1 != null) {
          listener1.hyperlinkUpdate(notification, e);
        }
      }
    }
  };
}
 
Example 28
Project: intellij-ce-playground   File: MessageTreeNode.java   View source code 6 votes vote down vote up
public static MessageTreeNode createInfoMessage(XDebuggerTree tree, @NotNull String message, @Nullable HyperlinkListener hyperlinkListener) {
  Matcher matcher = MessageTreeNodeWithLinks.HREF_PATTERN.matcher(message);
  if (hyperlinkListener == null || !matcher.find()) {
    return new MessageTreeNode(tree, null, message, SimpleTextAttributes.REGULAR_ATTRIBUTES,
                               XDebuggerUIConstants.INFORMATION_MESSAGE_ICON);
  }

  List<Object> objects = new ArrayList<Object>();
  int prev = 0;
  do {
    if (matcher.start() != prev) {
      objects.add(message.substring(prev, matcher.start()));
    }
    objects.add(new HyperlinkListenerDelegator(matcher.group(2), matcher.group(1), hyperlinkListener));
    prev = matcher.end();
  }
  while (matcher.find());

  if (prev < message.length()) {
    objects.add(message.substring(prev));
  }
  return new MessageTreeNodeWithLinks(tree, objects);
}
 
Example 29
Project: intellij-ce-playground   File: Browser.java   View source code 6 votes vote down vote up
public Browser(@NotNull InspectionResultsView view) {
  super(new BorderLayout());
  myView = view;

  myCurrentEntity = null;
  myCurrentDescriptor = null;

  myHTMLViewer = new JEditorPane(UIUtil.HTML_MIME, InspectionsBundle.message("inspection.offline.view.empty.browser.text"));
  myHTMLViewer.setEditable(false);
  myHyperLinkListener = new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      Browser.this.hyperlinkUpdate(e);
    }
  };
  myHTMLViewer.addHyperlinkListener(myHyperLinkListener);

  final JScrollPane pane = ScrollPaneFactory.createScrollPane(myHTMLViewer);
  pane.setBorder(null);
  add(pane, BorderLayout.CENTER);
  setupStyle();
}
 
Example 30
Project: intellij-ce-playground   File: EnvironmentVariablesTextFieldWithBrowseButton.java   View source code 6 votes vote down vote up
protected MyEnvironmentVariablesDialog() {
  super(EnvironmentVariablesTextFieldWithBrowseButton.this, true);
  myEnvVariablesTable = new EnvVariablesTable();
  myEnvVariablesTable.setValues(convertToVariables(myData.getEnvs(), false));

  myUseDefaultCb.setSelected(isPassParentEnvs());
  myWholePanel.add(myEnvVariablesTable.getComponent(), BorderLayout.CENTER);
  JPanel useDefaultPanel = new JPanel(new BorderLayout());
  useDefaultPanel.add(myUseDefaultCb, BorderLayout.CENTER);
  HyperlinkLabel showLink = new HyperlinkLabel(ExecutionBundle.message("env.vars.show.system"));
  useDefaultPanel.add(showLink, BorderLayout.EAST);
  showLink.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        showParentEnvironmentDialog(MyEnvironmentVariablesDialog.this.getWindow());
      }
    }
  });

  myWholePanel.add(useDefaultPanel, BorderLayout.SOUTH);
  setTitle(ExecutionBundle.message("environment.variables.dialog.title"));
  init();
}
 
Example 31
Project: intellij-ce-playground   File: PyStudyExecutor.java   View source code 6 votes vote down vote up
public void showNoSdkNotification(@NotNull final Project project) {
  final String text = "<html>No Python interpreter configured for the project<br><a href=\"\">Configure interpreter</a></html>";
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().
    createHtmlTextBalloonBuilder(text, null,
                                 MessageType.WARNING.getPopupBackground(),
                                 new HyperlinkListener() {
                                   @Override
                                   public void hyperlinkUpdate(HyperlinkEvent event) {
                                     if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                                       ApplicationManager.getApplication()
                                         .invokeLater(new Runnable() {
                                           @Override
                                           public void run() {
                                             ShowSettingsUtil.getInstance().showSettingsDialog(project, "Project Interpreter");
                                           }
                                         });
                                     }
                                   }
                                 });
  balloonBuilder.setHideOnLinkClick(true);
  final Balloon balloon = balloonBuilder.createBalloon();
  StudyUtils.showCheckPopUp(project, balloon);
}
 
Example 32
Project: intellij-ce-playground   File: ServicePanelBuilder.java   View source code 6 votes vote down vote up
public HyperlinkLabel addLink(@NotNull String text, @NotNull final URI uri) {
  HyperlinkLabel linkLabel = new HyperlinkLabel(text);
  linkLabel.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      try {
        Desktop.getDesktop().browse(uri);
      }
      catch (IOException e1) {
        // Don't care
      }
    }
  });
  addComponent(linkLabel);
  return linkLabel;
}
 
Example 33
Project: intellij-ce-playground   File: LabelWithEditLink.java   View source code 6 votes vote down vote up
public LabelWithEditLink() {
  setLayout(new BorderLayout());
  myCardPanel.add(EDIT, myEditField);
  myCardPanel.add(DISPLAY, myContentLabel);
  myCardPanel.revalidate();
  myCardPanel.repaint();
  myCardLayout.show(myCardPanel, DISPLAY);

  add(myCardPanel, BorderLayout.CENTER);
  add(myEditLabel, BorderLayout.EAST);

  myContentLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
  myEditLabel.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
        toggleEdit();
      }
    }
  });
  myContentLabel.setForeground(JBColor.gray);
  setFont(UIUtil.getLabelFont());
  myEditLabel.setHtmlText(EDIT_TEXT);
}
 
Example 34
Project: intellij-ce-playground   File: Selections.java   View source code 6 votes vote down vote up
private static void configureHyperLinkLabelForClassName(final RenderingParameters renderingParameters,
                                                        HyperlinkLabel link,
                                                        @Nullable final String className) {
  link.setOpaque(false);
  if (className == null) {
    return;
  }
  link.setHyperlinkText(className.substring(1 + className.lastIndexOf('.')));
  link.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
      PsiClass psiClass = NavigationEditorUtils.getPsiClass(renderingParameters.configuration.getModule(), className);
      if (psiClass != null) {
        AndroidRootComponent.launchEditor(renderingParameters, psiClass.getContainingFile(), false);
      }
    }
  });
}
 
Example 35
Project: intellij-ce-playground   File: Selections.java   View source code 6 votes vote down vote up
private static void configureHyperlinkForXMLFile(final RenderingParameters renderingParameters,
                                                 HyperlinkLabel link,
                                                 @Nullable final String linkText,
                                                 @Nullable final String xmlFileName,
                                                 final boolean isMenu) {
  link.setOpaque(false);
  link.setHyperlinkText(linkText == null ? "" : linkText);
  link.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
      PsiFile layoutXmlFile =
        NavigationView.getLayoutXmlFile(isMenu, xmlFileName, renderingParameters.configuration, renderingParameters.project);
      AndroidRootComponent.launchEditor(renderingParameters, layoutXmlFile, false);
    }
  });
}
 
Example 36
Project: incubator-netbeans   File: HyperlinkOperation.java   View source code 5 votes vote down vote up
public CharSequence getValue(JTextComponent component, Document document, Object attributeKey, int startOffset, int endOffset) {
    try {
        String tooltipText = provider.getTooltipText(document, offset, type);
        HyperlinkListener hl = (HyperlinkListener)document.getProperty(HYPERLINK_LISTENER);
        return hl != null ? new TooltipInfo(tooltipText, hl) : tooltipText;
    } finally {
        document.putProperty(HYPERLINK_LISTENER, null);
    }
}
 
Example 37
Project: incubator-netbeans   File: ProblemComponent.java   View source code 5 votes vote down vote up
/**
 * Creates new form ProblemComponent 
 */
public ProblemComponent(Problem problem, RefactoringUI ui, boolean single) {
    initComponents();
    this.ui = ui;
    icon.setIcon(problem.isFatal()?ErrorPanel.getFatalErrorIcon():ErrorPanel.getNonfatalErrorIcon());
    problemDescription.setText(problem.getMessage());
    this.problem = problem;
    this.details = problem.getDetails();
    //setLightBackground();
    if (!single && details != null) {
        org.openide.awt.Mnemonics.setLocalizedText(showDetails, details.getDetailsHint());
        showDetails.setPreferredSize(new Dimension((int) buttonWidth, (int) showDetails.getMinimumSize().getHeight()));
    } else {
        showDetails.setVisible(false);
    }
    
    problemDescription.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (IOException | URISyntaxException ex) {
                    LOGGER.log(Level.INFO, "Desktop.browse failed: ", ex); // NOI18N
                }
            }
        }
    });
}
 
Example 38
Project: incubator-netbeans   File: SwingBrowserImpl.java   View source code 5 votes vote down vote up
private SwingBrowser() {
    setEditable(false);
    addHyperlinkListener(
        new HyperlinkListener() {
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    if (e instanceof HTMLFrameHyperlinkEvent) {
                        HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
                        HTMLDocument doc = (HTMLDocument) getDocument();
                        URL old = getURL();
                        doc.processHTMLFrameHyperlinkEvent(evt);
                        pcs.firePropertyChange(PROP_URL, old, e.getURL());
                    } else {
                        try {
                            SwingBrowserImpl.this.setURL(e.getURL());
                        } catch (Exception ex) {
                            LOG.log(Level.WARNING, null, ex);
                        }
                    }
                }
            }
        }
    );

    //when up/down arrow keys are pressed, ensure the whole browser content 
    //scrolls up/down instead of moving the caret position only
    ActionMap actionMap = getActionMap();
    actionMap.put(DefaultEditorKit.upAction, new ScrollAction(-1));
    actionMap.put(DefaultEditorKit.downAction, new ScrollAction(1));
}
 
Example 39
Project: rapidminer   File: LinkButton.java   View source code 5 votes vote down vote up
private void makeHyperLinkListener(final Action action) {
	actionLinkListener = new HyperlinkListener() {

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == EventType.ACTIVATED) {
				action.actionPerformed(
						new ActionEvent(LinkButton.this, ActionEvent.ACTION_PERFORMED, e.getDescription()));
			}
		}
	};
	addHyperlinkListener(actionLinkListener);
}
 
Example 40
Project: rapidminer   File: AbstractLinkButton.java   View source code 5 votes vote down vote up
/**
 * Creates the hyperlink listener for the given action.
 *
 * @param action
 */
private void makeHyperLinkListener(final Action action) {

	actionLinkListener = new HyperlinkListener() {

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == EventType.ACTIVATED) {
				action.actionPerformed(new ActionEvent(AbstractLinkButton.this, ActionEvent.ACTION_PERFORMED, e
						.getDescription()));
			}
		}
	};
	addHyperlinkListener(actionLinkListener);
}