Java Code Examples for javax.swing.event.HyperlinkListener

The following examples show how to use javax.swing.event.HyperlinkListener. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ghidra   Source File: GHelpHTMLEditorKit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void install(JEditorPane c) {
	super.install(c);

	delegateListeners = c.getHyperlinkListeners();
	for (HyperlinkListener listener : delegateListeners) {
		c.removeHyperlinkListener(listener);
	}

	resolverHyperlinkListener = new ResolverHyperlinkListener();
	c.addHyperlinkListener(resolverHyperlinkListener);

	// add a listener to report trace information
	c.addPropertyChangeListener(new PropertyChangeListener() {
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			String propertyName = evt.getPropertyName();
			if ("page".equals(propertyName)) {
				Msg.trace(this, "Page loaded: " + evt.getNewValue());
			}
		}
	});
}
 
Example 2
Source Project: ghidra   Source File: GHelpHTMLEditorKit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {

	if (delegateListeners == null) {
		return;
	}

	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
		Msg.trace(this, "Link activated: " + e.getURL());
		e = validateURL(e);
		Msg.trace(this, "Validated event: " + e.getURL());
	}

	for (HyperlinkListener listener : delegateListeners) {
		listener.hyperlinkUpdate(e);
	}
}
 
Example 3
Source Project: LiMe   Source File: LiMeUserAgreementFrame.java    License: MIT License 6 votes vote down vote up
private HyperlinkListener createHyperLinkListener() {
    return e -> {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (e instanceof HTMLFrameHyperlinkEvent) {
                ((HTMLDocument) htmlPane.getDocument()).processHTMLFrameHyperlinkEvent(
                        (HTMLFrameHyperlinkEvent) e);
            } else {
                try {
                    htmlPane.setPage(e.getURL());
                } catch (IOException ioe) {
                    System.out.println("IOE: " + ioe);
                }
            }
        }
    };
}
 
Example 4
Source Project: netbeans   Source File: BrowserUtils.java    License: Apache License 2.0 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 5
Source Project: netbeans   Source File: ShowNotifications.java    License: Apache License 2.0 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 6
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 7
Source Project: ramus   Source File: Navigator.java    License: GNU General Public License v3.0 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 8
Source Project: scelight   Source File: Browser.java    License: Apache License 2.0 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 9
/**
 * 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 10
Source Project: consulo   Source File: DiffUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void showSuccessPopup(@Nonnull String message,
                                    @Nonnull RelativePoint point,
                                    @Nonnull Disposable disposable,
                                    @Nullable Runnable hyperlinkHandler) {
  HyperlinkListener listener = null;
  if (hyperlinkHandler != null) {
    listener = new HyperlinkAdapter() {
      @Override
      protected void hyperlinkActivated(HyperlinkEvent e) {
        hyperlinkHandler.run();
      }
    };
  }

  Color bgColor = MessageType.INFO.getPopupBackground();

  Balloon balloon = JBPopupFactory.getInstance()
          .createHtmlTextBalloonBuilder(message, null, bgColor, listener)
          .setAnimationCycle(200)
          .createBalloon();
  balloon.show(point, Balloon.Position.below);
  Disposer.register(disposable, balloon);
}
 
Example 11
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 12
Source Project: WorldGrower   Source File: CreditsDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void addCreditsPane() throws IOException {
	String creditsText = getCreditsTextAsHtml();
	
	JTextPane textPane = JTextPaneFactory.createHmtlJTextPane(imageInfoReader); 
	textPane.setEditable(false);
	textPane.setText(creditsText);
	
	textPane.addHyperlinkListener(new HyperlinkListener() {
		
		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				try {
					openWebPage(e.getURL().toURI());
				} catch (URISyntaxException e1) {
					 throw new IllegalStateException("Problem opening " + e.getURL().toString(), e1);
				}
			}
		}
	});
	
	JScrollPane scrollPane = new JScrollPane(textPane);
	scrollPane.setBounds(15, 15, 668, 720);
	addComponent(scrollPane);
}
 
Example 13
Source Project: mzmine2   Source File: ResultsTextPane.java    License: GNU General Public License v2.0 6 votes vote down vote up
public ResultsTextPane(StyledDocument doc) {
  super(doc);
  createStyles();
  setEditorKit(JTextPane.createEditorKitForContentType("text/html"));
  setEditable(false);
  addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        if (Desktop.isDesktopSupported()) {
          try {
            Desktop.getDesktop().browse(e.getURL().toURI());
          } catch (IOException | URISyntaxException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
  });
}
 
Example 14
Source Project: sc2gears   Source File: GuiUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an editor pane.
 * 
 * <p>The returned editor pane is set to be non-editable, handles hyperlinks (opens them in the default browser),
 * and removes the CTRL+SHIFT+O hotkey which is used by Sc2gears (it is associated with opening last replay).</p>
 * 
 * @return the created editor pane
 */
public static JEditorPane createEditorPane() {
	final JEditorPane editorPane = new JEditorPane();
	
	editorPane.setEditable( false );
	
	editorPane.addHyperlinkListener( new HyperlinkListener() {
		@Override
		public void hyperlinkUpdate( final HyperlinkEvent event ) {
			if ( event.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
				GeneralUtils.showURLInBrowser( event.getURL().toExternalForm() );
		}
	} );
	
	// Remove CTRL+SHIFT+O
	Object actionKey;
	editorPane.getInputMap( JComponent.WHEN_FOCUSED ).put( KeyStroke.getKeyStroke( KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK ), actionKey = new Object() );
	editorPane.getActionMap().put( actionKey, null );
	
	return editorPane;
}
 
Example 15
/**
 * Turns HTML into a clickable dialog text component.
 * @param html String of valid HTML.
 * @return a JTextComponent with the HTML inside.
 */
public JTextComponent createHyperlinkListenableJEditorPane(String html) {
	final JEditorPane bottomText = new JEditorPane();
	bottomText.setContentType("text/html");
	bottomText.setEditable(false);
	bottomText.setText(html);
	bottomText.setOpaque(false);
	final HyperlinkListener hyperlinkListener = new HyperlinkListener() {
		public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
			if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
				if (Desktop.isDesktopSupported()) {
					try {
						Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI());
					} catch (IOException | URISyntaxException exception) {
						// Auto-generated catch block
						exception.printStackTrace();
					}
				}

			}
		}
	};
	bottomText.addHyperlinkListener(hyperlinkListener);
	return bottomText;
}
 
Example 16
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 17
static JScrollPane createHtmlPane(String html, HyperlinkListener hyperlinkListener) {
  JEditorPane htmlPane = UIUtil.createHtmlPane(html, hyperlinkListener);
  htmlPane.setBackground(Color.YELLOW);
  htmlPane.setBorder(BorderFactory.createEmptyBorder());
  Dimension htmlSize = htmlPane.getPreferredSize();

  final JScrollPane scrollPane = new JScrollPane(htmlPane);
  scrollPane.setAutoscrolls(false);
  scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
  scrollPane.setBorder(BorderFactory.createEmptyBorder());
  scrollPane.setPreferredSize(new Dimension(Math.min(400, htmlSize.width + 50), Math.min(300, htmlSize.height + 50)));
  SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
      scrollPane.getVerticalScrollBar().setValue(0);
    }
  });
  return scrollPane;
}
 
Example 18
Source Project: CodeChickenCore   Source File: DepLoader.java    License: MIT License 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 19
Source Project: consulo   Source File: Browser.java    License: Apache License 2.0 6 votes vote down vote up
public Browser(@Nonnull 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 20
Source Project: WirelessRedstone   Source File: DepLoader.java    License: MIT License 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 21
Source Project: Darcula   Source File: EditorPaneDemo.java    License: Apache License 2.0 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
Source Project: ghidra   Source File: HyperlinkComponent.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add a listener that will be called whenever hyperlink updates happen (hover, activate, etc).
 * 
 * @param anchorName The value in the <code>href</code> attribute of the anchor tag.
 * @param listener The listener to be called when the anchor(s) with a matching <code>href</code> is
 *        manipulated by the user.
 */
public void addHyperlinkListener(String anchorName, HyperlinkListener listener) {
	List<HyperlinkListener> list = hyperlinkListeners.get(anchorName);
	if (list == null) {
		list = new ArrayList<HyperlinkListener>();
		hyperlinkListeners.put(anchorName, list);
	}

	list.add(listener);
}
 
Example 23
Source Project: consulo   Source File: SearchForUsagesRunnable.java    License: Apache License 2.0 5 votes vote down vote up
private static void notifyByFindBalloon(@javax.annotation.Nullable final HyperlinkListener listener,
                                        @Nonnull final MessageType info,
                                        @Nonnull FindUsagesProcessPresentation processPresentation,
                                        @Nonnull final Project project,
                                        @Nonnull final List<String> lines) {
  com.intellij.usageView.UsageViewManager.getInstance(project); // in case tool window not registered

  final Collection<VirtualFile> largeFiles = processPresentation.getLargeFiles();
  List<String> resultLines = new ArrayList<>(lines);
  HyperlinkListener resultListener = listener;
  if (!largeFiles.isEmpty()) {
    String shortMessage = "(<a href='" + LARGE_FILES_HREF_TARGET + "'>" + UsageViewBundle.message("large.files.were.ignored", largeFiles.size()) + "</a>)";

    resultLines.add(shortMessage);
    resultListener = addHrefHandling(resultListener, LARGE_FILES_HREF_TARGET, () -> {
      String detailedMessage = detailedLargeFilesMessage(largeFiles);
      List<String> strings = new ArrayList<>(lines);
      strings.add(detailedMessage);
      //noinspection SSBasedInspection
      ToolWindowManager.getInstance(project).notifyByBalloon(ToolWindowId.FIND, info, wrapInHtml(strings), AllIcons.Actions.Find, listener);
    });
  }

  Runnable searchIncludingProjectFileUsages = processPresentation.searchIncludingProjectFileUsages();
  if (searchIncludingProjectFileUsages != null) {
    resultLines
            .add("Occurrences in project configuration files are skipped. " + "<a href='" + SHOW_PROJECT_FILE_OCCURRENCES_HREF_TARGET + "'>Include them</a>");
    resultListener = addHrefHandling(resultListener, SHOW_PROJECT_FILE_OCCURRENCES_HREF_TARGET, searchIncludingProjectFileUsages);
  }

  //noinspection SSBasedInspection
  ToolWindowManager.getInstance(project).notifyByBalloon(ToolWindowId.FIND, info, wrapInHtml(resultLines), AllIcons.Actions.Find, resultListener);
}
 
Example 24
Source Project: FancyBing   Source File: AboutDialog.java    License: GNU General Public License v3.0 5 votes vote down vote up
private JPanel createPanel(String text)
{
    JPanel panel = new JPanel(new GridLayout(1, 1));
    JEditorPane editorPane = new JEditorPane();
    editorPane.setBorder(GuiUtil.createEmptyBorder());
    editorPane.setEditable(false);
    if (Platform.isMac())
    {
        editorPane.setForeground(UIManager.getColor("Label.foreground"));
        editorPane.setBackground(UIManager.getColor("Label.background"));
    }
    else
    {
        editorPane.setForeground(Color.black);
        editorPane.setBackground(Color.white);
    }
    panel.add(editorPane);
    EditorKit editorKit =
        JEditorPane.createEditorKitForContentType("text/html");
    editorPane.setEditorKit(editorKit);
    editorPane.setText(text);
    editorPane.addHyperlinkListener(new HyperlinkListener()
        {
            public void hyperlinkUpdate(HyperlinkEvent event)
            {
                HyperlinkEvent.EventType type = event.getEventType();
                if (type == HyperlinkEvent.EventType.ACTIVATED)
                {
                    URL url = event.getURL();
                    if (! Platform.openInExternalBrowser(url))
                        m_messageDialogs.showError(null,
                                                   i18n("MSG_ABOUT_OPEN_URL_FAIL"),
                                                   "", false);
                }
            }
        });
    return panel;
}
 
Example 25
Source Project: consulo   Source File: PopupFactoryImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder createHtmlTextBalloonBuilder(@Nonnull final String htmlContent, @Nullable final Icon icon, Color textColor, final Color fillColor, @Nullable final HyperlinkListener listener) {
  JEditorPane text = IdeTooltipManager.initPane(htmlContent, new HintHint().setTextFg(textColor).setAwtTooltip(true), null);

  if (listener != null) {
    text.addHyperlinkListener(listener);
  }
  text.setEditable(false);
  NonOpaquePanel.setTransparent(text);
  text.setBorder(null);


  JLabel label = new JLabel();
  final JPanel content = new NonOpaquePanel(new BorderLayout((int)(label.getIconTextGap() * 1.5), (int)(label.getIconTextGap() * 1.5)));

  final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout());
  JScrollPane scrolledText = ScrollPaneFactory.createScrollPane(text, true);
  scrolledText.setBackground(fillColor);
  scrolledText.getViewport().setBackground(fillColor);
  textWrapper.add(scrolledText);
  content.add(textWrapper, BorderLayout.CENTER);
  if (icon != null) {
    final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
    north.add(new JLabel(icon), BorderLayout.NORTH);
    content.add(north, BorderLayout.WEST);
  }

  content.setBorder(JBUI.Borders.empty(2, 4));

  final BalloonBuilder builder = createBalloonBuilder(content);

  builder.setFillColor(fillColor);

  return builder;
}
 
Example 26
Source Project: SmartIM   Source File: IMChatConsole.java    License: Apache License 2.0 5 votes vote down vote up
protected void initHistoryWidget() {
    HTMLEditorKit kit = new HTMLEditorKit() {
        @Override
        public ViewFactory getViewFactory() {
            return new WrapHTMLFactory();
        }
    };
    final StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("body {text-align: left;}");
    styleSheet.addRule(".my {font-size: 1 em; font-style: italic; float: left;}");
    styleSheet.addRule("div.error {color: red;}");
    styleSheet.addRule("img {max-width: 100%; display: block;}");
    styleSheet.addRule(".sender {display: inline; float: left;}");
    styleSheet.addRule(".content {display: inline-block; white-space: pre-warp; padding-left: 4px;}");
    styleSheet.addRule(".br {height: 1px; line-height: 1px; min-height: 1px;}");
    RestUtils.loadStyleAsync(styleSheet);
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    String initText = String.format("<html><head></head><body>%s</body></html>", imPanel.getWelcome());
    historyWidget.setContentType("text/html");
    historyWidget.setEditorKit(kit);
    historyWidget.setDocument(doc);
    historyWidget.setText(initText);
    historyWidget.setEditable(false);
    historyWidget.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                String desc = e.getDescription();
                if (!StringUtils.isEmpty(desc)) {
                    hyperlinkActivated(desc);
                }
            }
        }
    });
}
 
Example 27
Source Project: netbeans   Source File: NbPanel.java    License: Apache License 2.0 5 votes vote down vote up
private HyperlinkListener getHyperlinkListener() {
    if (hyperlinkListener == null) {
        hyperlinkListener = BrowserUtils.createHyperlinkListener();
    }
    
    return hyperlinkListener;
}
 
Example 28
Source Project: netbeans   Source File: SwingBrowserImpl.java    License: Apache License 2.0 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 29
Source Project: netbeans   Source File: NetworkErrorPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    String text = infoTextPane.getText();
    infoTextPane.setText(text.replace("%FAILED_REQUESTS%", joinRequests(failedRequests))); // NOI18N
    // listeners
    infoTextPane.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                HtmlBrowser.URLDisplayer.getDefault().showURL(e.getURL());
            }
        }
    });
}
 
Example 30
Source Project: netbeans   Source File: HyperlinkOperation.java    License: Apache License 2.0 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);
    }
}