Java Code Examples for javax.swing.plaf.basic.BasicHTML#isHTMLString()

The following examples show how to use javax.swing.plaf.basic.BasicHTML#isHTMLString() . 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 File: DarkTabbedPaneUIBridge.java    From darklaf with MIT License 6 votes vote down vote up
/**
 * Create html vector vector.
 *
 * @return the vector
 */
protected Vector<View> createHTMLVector() {
    Vector<View> htmlViews = new Vector<>();
    int count = tabPane.getTabCount();
    if (count > 0) {
        for (int i = 0; i < count; i++) {
            String title = tabPane.getTitleAt(i);
            if (BasicHTML.isHTMLString(title)) {
                htmlViews.addElement(BasicHTML.createHTMLView(tabPane, title));
            } else {
                htmlViews.addElement(null);
            }
        }
    }
    return htmlViews;
}
 
Example 2
Source File: TabbedPaneHandler.java    From darklaf with MIT License 6 votes vote down vote up
protected void updateHtmlViews(final int index, final boolean inserted) {
    String title = ui.tabPane.getTitleAt(index);
    boolean isHTML = BasicHTML.isHTMLString(title);
    if (isHTML) {
        if (ui.htmlViews == null) { // Initialize vector
            ui.htmlViews = ui.createHTMLVector();
        } else { // Vector already exists
            View v = BasicHTML.createHTMLView(ui.tabPane, title);
            setHtmlView(v, inserted, index);
        }
    } else { // Not HTML
        if (ui.htmlViews != null) { // Add placeholder
            setHtmlView(null, inserted, index);
        } // else nada!
    }
    ui.updateMnemonics();
}
 
Example 3
Source File: FlatLabelUI.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether text contains HTML headings and adds a special CSS rule to
 * re-calculate heading font sizes based on current component font size.
 */
static void updateHTMLRenderer( JComponent c, String text, boolean always ) {
	if( BasicHTML.isHTMLString( text ) &&
		c.getClientProperty( "html.disable" ) != Boolean.TRUE &&
		text.contains( "<h" ) &&
		(text.contains( "<h1" ) || text.contains( "<h2" ) || text.contains( "<h3" ) ||
		 text.contains( "<h4" ) || text.contains( "<h5" ) || text.contains( "<h6" )) )
	{
		int headIndex = text.indexOf( "<head>" );

		String style = "<style>BASE_SIZE " + c.getFont().getSize() + "</style>";
		if( headIndex < 0 )
			style = "<head>" + style + "</head>";

		int insertIndex = headIndex >= 0 ? (headIndex + "<head>".length()) : "<html>".length();
		text = text.substring( 0, insertIndex )
			+ style
			+ text.substring( insertIndex );
	} else if( !always )
		return; // not necessary to invoke BasicHTML.updateRenderer()

	BasicHTML.updateRenderer( c, text );
}
 
Example 4
Source File: TopComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Sets localized display name of this <code>TopComponent</code>.
 * @param displayName localized display name which is set
 * @since 4.13 */
public void setDisplayName(String displayName) {
    String old = this.displayName;

    if ((displayName == old) || ((displayName != null) && displayName.equals(old))) {
        return;
    }

    // warning if display name contains html tags
    if (BasicHTML.isHTMLString(displayName)) {
        Logger.getAnonymousLogger().warning(
            "Call of " + getClass().getName() + ".setDisplayName(\"" + displayName + "\")" +
            " shouldn't contain any HTML tags. Please use " + getClass().getName() + ".setHtmlDisplayName(String)" +
            "for such purpose. For details please see http://www.netbeans.org/issues/show_bug.cgi?id=66777.");
    }
    
    this.displayName = displayName;
    firePropertyChange("displayName", old, displayName); // NOI18N

    WindowManager.getDefault().topComponentDisplayNameChanged(this, displayName);
}
 
Example 5
Source File: CloseTabPaneUI.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
@Override
public void componentAdded(ContainerEvent e) {
	JTabbedPane tp = (JTabbedPane) e.getContainer();
	Component child = e.getChild();
	if (child instanceof UIResource) {
		return;
	}
	int index = tp.indexOfComponent(child);
	String title = tp.getTitleAt(index);
	boolean isHTML = BasicHTML.isHTMLString(title);
	if (isHTML) {
		if (htmlViews == null) { // Initialize vector
			htmlViews = createHTMLVector();
		}
		else { // Vector already exists
			View v = BasicHTML.createHTMLView(tp, title);
			htmlViews.insertElementAt(v, index);
		}
	}
	else { // Not HTML
		if (htmlViews != null) { // Add placeholder
			htmlViews.insertElementAt(null, index);
		} // else nada!
	}
}
 
Example 6
Source File: CloseTabPaneUI.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
private Vector<View> createHTMLVector() {
	Vector<View> htmlViews = new Vector<View>();
	int count = tabPane.getTabCount();
	if (count > 0) {
		for (int i = 0; i < count; i++) {
			String title = tabPane.getTitleAt(i);
			if (BasicHTML.isHTMLString(title)) {
				htmlViews.addElement(BasicHTML.createHTMLView(tabPane, title));
			}
			else {
				htmlViews.addElement(null);
			}
		}
	}
	return htmlViews;
}
 
Example 7
Source File: DesktopAlertImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public JTextPane configureMessagePaneUi(@Nonnull JTextPane messageComponent, @Nullable String message, @Nullable UIUtil.FontSize fontSize) {
  UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
  messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
  if (BasicHTML.isHTMLString(message)) {
    HTMLEditorKit editorKit = new HTMLEditorKit();
    Font font = UIUtil.getLabelFont(fixedFontSize);
    editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
    messageComponent.setEditorKit(editorKit);
    messageComponent.setContentType(UIUtil.HTML_MIME);
  }
  messageComponent.setText(message);
  messageComponent.setEditable(false);
  if (messageComponent.getCaret() != null) {
    messageComponent.setCaretPosition(0);
  }

  messageComponent.setBackground(UIUtil.getOptionPaneBackground());
  messageComponent.setForeground(UIUtil.getLabelForeground());
  return messageComponent;
}
 
Example 8
Source File: FlatOptionPaneUI.java    From FlatLaf with Apache License 2.0 5 votes vote down vote up
@Override
protected void addMessageComponents( Container container, GridBagConstraints cons, Object msg, int maxll,
	boolean internallyCreated )
{
	// set message padding
	if( messagePadding > 0 )
		cons.insets.bottom = UIScale.scale( messagePadding );

	// disable line wrapping for HTML
	if( msg instanceof String && BasicHTML.isHTMLString( (String) msg ) )
		maxll = Integer.MAX_VALUE;

	super.addMessageComponents( container, cons, msg, maxll, internallyCreated );
}
 
Example 9
Source File: HTMLUtilities.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given text is HTML.  For this to be true, the text must begin with
 * the &lt;HTML&gt; tag.
 *
 * @param text the text to check
 * @return true if the given text is HTML
 */
public static boolean isHTML(String text) {
	if (text == null) {
		return false;
	}

	String testText = text.trim();
	return BasicHTML.isHTMLString(testText);
}
 
Example 10
Source File: DefaultSeparateContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Actually sets title for the frame
 */
@Override
public void updateTitle(String title) {
    // extract HTML from text - Output window (and soon others) uses it
    if (BasicHTML.isHTMLString(title)) {
        char[] c = title.toCharArray();
        StringBuffer sb = new StringBuffer(title.length());
        boolean inTag = false;
        for (int i=0; i < c.length; i++) {
            if (inTag && c[i] == '>') { //NOI18N
                inTag = false;
                continue;
            }
            if (!inTag && c[i] == '<') { //NOI18N
                inTag = true;
                continue;
            }
            if (!inTag) {
                sb.append(c[i]);
            }
        }
        //XXX, would be nicer to support the full complement of entities...
        title = sb.toString().replace("&nbsp;", " "); //NOI18N
    }
    String completeTitle = MessageFormat.format(
            NbBundle.getMessage(DefaultSeparateContainer.class, "CTL_SeparateEditorTitle"),
            title);
    setTitle(completeTitle);
}
 
Example 11
Source File: MultiSelectDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 5 votes vote down vote up
@NotNull
public static JTextPane configureMessagePaneUi(JTextPane messageComponent,
                                               String message,
                                               final boolean addBrowserHyperlinkListener) {
    messageComponent.setFont(UIUtil.getLabelFont());
    if (BasicHTML.isHTMLString(message)) {
        final HTMLEditorKit editorKit = new HTMLEditorKit();
        editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(UIUtil.getLabelFont(), UIUtil.getLabelForeground()));
        messageComponent.setEditorKit(editorKit);
        messageComponent.setContentType(UIUtil.HTML_MIME);
        if (addBrowserHyperlinkListener) {
            messageComponent.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
        }
    }
    messageComponent.setText(message);
    messageComponent.setEditable(false);
    if (messageComponent.getCaret() != null) {
        messageComponent.setCaretPosition(0);
    }

    if (UIUtil.isUnderNimbusLookAndFeel()) {
        messageComponent.setOpaque(false);
        messageComponent.setBackground(UIUtil.TRANSPARENT_COLOR);
    } else {
        messageComponent.setBackground(UIUtil.getOptionPaneBackground());
    }

    messageComponent.setForeground(UIUtil.getLabelForeground());
    return messageComponent;
}
 
Example 12
Source File: Messages.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JTextPane configureMessagePaneUi(@Nonnull JTextPane messageComponent, @Nullable String message, @Nullable UIUtil.FontSize fontSize) {
  UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
  messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
  if (BasicHTML.isHTMLString(message)) {
    HTMLEditorKit editorKit = new HTMLEditorKit();
    Font font = UIUtil.getLabelFont(fixedFontSize);
    editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
    messageComponent.setEditorKit(editorKit);
    messageComponent.setContentType(UIUtil.HTML_MIME);
  }
  messageComponent.setText(message);
  messageComponent.setEditable(false);
  if (messageComponent.getCaret() != null) {
    messageComponent.setCaretPosition(0);
  }

  if (UIUtil.isUnderNimbusLookAndFeel()) {
    messageComponent.setOpaque(false);
    messageComponent.setBackground(UIUtil.TRANSPARENT_COLOR);
  }
  else {
    messageComponent.setBackground(UIUtil.getOptionPaneBackground());
  }

  messageComponent.setForeground(UIUtil.getLabelForeground());
  return messageComponent;
}
 
Example 13
Source File: Messages.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected JComponent createTextComponent() {
  JComponent textComponent;
  if (BasicHTML.isHTMLString(myMessage)) {
    textComponent = createMessageComponent(myMessage);
  }
  else {
    JLabel textLabel = new JLabel(myMessage);
    textLabel.setUI(new MultiLineLabelUI());
    textComponent = textLabel;
  }
  textComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
  return textComponent;
}
 
Example 14
Source File: HoverHyperlinkLabel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setText(String text) {
  if (BasicHTML.isHTMLString(getText())) { // if is currently showing string as html
    super.setText(underlineTextInHtml(text));
  }
  else {
    super.setText(text);
  }
  myOriginalText = text;
}
 
Example 15
Source File: DarculaUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isMultiLineHTML(@Nullable String text) {
  if (text != null) {
    text = text.toLowerCase(Locale.getDefault());
    return BasicHTML.isHTMLString(text) && (text.contains("<br>") || text.contains("<br/>"));
  }
  return false;
}
 
Example 16
Source File: BundleEditPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Overrides superclass method. */
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    
    if (value == null) {
        return this;
    }
    
    PropertiesTableModel.StringPair sp = (PropertiesTableModel.StringPair)value;                        
    
    setFont(settings.getFont());
    
    if(hasFocus) {
        setBorder(UIManager.getBorder("Table.focusCellHighlightBorder") ); // NOI18N
    } else {
        setBorder(noFocusBorder);
    }
    
    String text = null;
    
    if(sp.getValue() != null) {
        text = sp.getValue();
    }
    
    // XXX Ugly hack to prevent problems showing 'html-ed' labels.
    if(BasicHTML.isHTMLString(text)) { // NOI18N
        text = " " + text; // NOI18N
    }
    
    setValue(text == null ? "" : text); // NOI18N
    
    // Set background color.
    if (sp.isKeyType()) {
        setBackground(settings.getKeyBackground());
    } else {
        if (sp.getValue() != null) {
            setBackground(settings.getValueBackground());
        } else {
            setBackground(settings.getShadowColor());
        }
    }
    
    // Set foregound color.
    if (sp.isKeyType()) {
        setForeground(settings.getKeyColor());
    } else {
        setForeground(settings.getValueColor());
    }
    
    // Optimization to avoid painting background if is the same like table's.
    Color back = getBackground();
    boolean colorMatch = (back != null) && (back.equals(table.getBackground()) ) && table.isOpaque();
    setOpaque(!colorMatch);
    
    return this;
}