javax.swing.text.html.ImageView#javax.swing.event.HyperlinkListener源码实例Demo

下面列出了javax.swing.text.html.ImageView#javax.swing.event.HyperlinkListener 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: GHelpHTMLEditorKit.java
@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());
			}
		}
	});
}
 
源代码2 项目: ghidra   文件: GHelpHTMLEditorKit.java
@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);
	}
}
 
源代码3 项目: LiMe   文件: LiMeUserAgreementFrame.java
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);
                }
            }
        }
    };
}
 
源代码4 项目: netbeans   文件: BrowserUtils.java
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);
                    }
                }
            }
        }
    };
}
 
源代码5 项目: netbeans   文件: ShowNotifications.java
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;
}
 
源代码6 项目: gate-core   文件: JTextPaneTableCellRenderer.java
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");
    }
  });
}
 
源代码7 项目: ramus   文件: Navigator.java
@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;
}
 
源代码8 项目: scelight   文件: Browser.java
/**
 * 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 );
		}
	} );
}
 
源代码9 项目: rapidminer-studio   文件: FixedWidthEditorPane.java
/**
 * 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());
			}
		}
	});

}
 
源代码10 项目: consulo   文件: DiffUtil.java
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);
}
 
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();
}
 
源代码12 项目: WorldGrower   文件: CreditsDialog.java
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);
}
 
源代码13 项目: mzmine2   文件: ResultsTextPane.java
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();
          }
        }
      }
    }
  });
}
 
源代码14 项目: sc2gears   文件: GuiUtils.java
/**
 * 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;
}
 
源代码15 项目: Robot-Overlord-App   文件: HTMLDialogBox.java
/**
 * 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;
}
 
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);
    }
  });
}
 
源代码17 项目: ganttproject   文件: NotificationComponent.java
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;
}
 
源代码18 项目: CodeChickenCore   文件: DepLoader.java
@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);
}
 
源代码19 项目: consulo   文件: Browser.java
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();
}
 
源代码20 项目: WirelessRedstone   文件: DepLoader.java
@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);
}
 
源代码21 项目: Darcula   文件: EditorPaneDemo.java
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);
                    }
                }
            }
        }
    };
}
 
源代码22 项目: ghidra   文件: HyperlinkComponent.java
/**
 * 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);
}
 
源代码23 项目: consulo   文件: SearchForUsagesRunnable.java
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);
}
 
源代码24 项目: FancyBing   文件: AboutDialog.java
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;
}
 
源代码25 项目: consulo   文件: PopupFactoryImpl.java
@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;
}
 
源代码26 项目: SmartIM   文件: IMChatConsole.java
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);
                }
            }
        }
    });
}
 
源代码27 项目: netbeans   文件: NbPanel.java
private HyperlinkListener getHyperlinkListener() {
    if (hyperlinkListener == null) {
        hyperlinkListener = BrowserUtils.createHyperlinkListener();
    }
    
    return hyperlinkListener;
}
 
源代码28 项目: netbeans   文件: SwingBrowserImpl.java
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));
}
 
源代码29 项目: netbeans   文件: NetworkErrorPanel.java
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());
            }
        }
    });
}
 
源代码30 项目: netbeans   文件: HyperlinkOperation.java
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);
    }
}