/** * Returns an instance of Renderer which may be used as a table/tree/list cell renderer. * This method must be called on the AWT event thread. If you <strong>know</strong> you will * be passing it legal HTML (legal as documented here), call {@link Renderer#setHtml setHtml(true)} on the * result of this call <strong>after calling getNNNCellRenderer</strong> to provide this hint. * * @return A cell renderer that can render HTML. */ public static final Renderer createRenderer() { return new HtmlRendererImpl(); }
/** Generic code to set properties appropriately from any of the renderer * fetching methods */ private void configureFrom(Object value, JComponent target, boolean selected, boolean leadSelection) { if (value == null) { value = ""; } setText((value == null) ? "" : value.toString()); setSelected(selected); if (selected) { setParentFocused(checkFocused(target)); } else { setParentFocused(false); } setEnabled(target.isEnabled()); setLeadSelection(leadSelection); setFont(target.getFont()); }
public void setHtml(boolean val) { Boolean wasHtml = html; String txt = getText(); html = val ? Boolean.TRUE : Boolean.FALSE; if (swingRendering && (html != wasHtml)) { //Ensure label UI gets updated and builds its little document tree... firePropertyChange("text", txt, getText()); //NOI18N } }
public Component getTableCellRendererComponent( JTable table, Object value, boolean selected, boolean leadSelection, int row, int column ) { reset(); configureFrom(value, table, selected, leadSelection); type = Type.TABLE; if (swingRendering && selected) { setBackground(table.getSelectionBackground()); setForeground(table.getSelectionForeground()); setOpaque(true); } return this; }
static Color getBackgroundFor(HtmlRendererImpl r) { if (r.isOpaque()) { return r.getBackground(); } if (r.isSelected() && !r.isParentFocused() && !isGTK() && !isNimbus()) { return getUnfocusedSelectionBackground(); } Color result = null; if (r.isSelected()) { switch (r.getType()) { case LIST: result = UIManager.getColor("List.selectionBackground"); //NOI18N if (result == null) { //GTK //plaf library guarantees this one: result = UIManager.getColor("Tree.selectionBackground"); //NOI18N } //System.err.println(" now " + result); break; case TABLE: result = UIManager.getColor("Table.selectionBackground"); //NOI18N break; case TREE: return UIManager.getColor("Tree.selectionBackground"); //NOI18N } return (result == null) ? r.getBackground() : result; } return null; }
/** * Overridden for the case that we're running with the lightweight html renderer disabled, to convert * any less-than-legal html to legal html for purposes of Swing's html rendering. * * @return The text - unless the renderer is disabled, this just return super.getText() */ public @Override String getText() { String result = super.getText(); if (swingRendering && Boolean.TRUE.equals(html)) { //Standard swing rendering needs an opening HTML tag to function, so make sure there is //one if we're not using HtmlLabelUI result = ensureHtmlTags(result); } else if (swingRendering && (html == null)) { //Cannot call isHtml() here, it will create an endless loop, so manually check the HTML status html = checkHtml(super.getText()); if (Boolean.TRUE.equals(html)) { result = ensureHtmlTags(result); } } return result; }
public @Override Insets getInsets(Insets insets) { Insets result; //Call getBorder(), not just read the field - if swingRendering, the border will be constructed, and the //insets are what will make the indent property work; HtmlLabelUI doesn't need this, it just reads the //insets property, but BasicLabelUI and its ilk do Border b = getBorder(); if (b == null) { result = EMPTY_INSETS; } else { //workaround for open jdk bug, see issue #192388 try { result = b.getBorderInsets(this); } catch( NullPointerException e ) { Logger.getLogger(HtmlRendererImpl.class.getName()).log(Level.FINE, null, e); result = EMPTY_INSETS; } } if( null != insets ) { insets.set( result.top, result.left, result.bottom, result.right); return insets; } return result; }
public @Override void setBorder(Border b) { Border old = border; border = b; if (swingRendering) { firePropertyChange("border", old, b); } }
/** * Converts our extended html syntax (allowing UIManager color keys and omitting opening html tags * into standard html. Only called if the lightweight html renderer is disabled and we're running with * a standard JLabel UI * * @param s The string that is the text of the label * @return The same string converted to standard HTML Swing's rendering infrastructure will know what to do * with */ private String ensureHtmlTags(String s) { s = ensureLegalFontColorTags(s); if (!s.startsWith("<HTML") && !s.startsWith("<html")) { //NOI18N s = "<html>" + s + "</html>"; //NOI18N } return s; }
String converted = convertToStandardColor(colorString); sb.replace(bangIdx, colorEnd, converted); s = sb.toString();
public Insets getInsets() { Insets result; //Call getBorder(), not just read the field - if swingRendering, the border will be constructed, and the //insets are what will make the indent property work; HtmlLabelUI doesn't need this, it just reads the //insets property, but BasicLabelUI and its ilk do Border b = getBorder(); if (b == null) { result = EMPTY_INSETS; } else { result = b.getBorderInsets(this); } return result; }
public Component getTreeCellRendererComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean leadSelection ) { reset(); configureFrom(value, tree, selected, leadSelection); type = Type.TREE; if (swingRendering && selected) { if (HtmlLabelUI.isGTK()) { setBackground(HtmlLabelUI.getBackgroundFor(this)); setForeground(HtmlLabelUI.getForegroundFor(this)); } setOpaque(true); } return this; }
static Color getBackgroundFor (HtmlRendererImpl r) { if (r.isOpaque()) { return r.getBackground(); if (r.isSelected() && !r.isParentFocused() && !isGTK()) { return getUnfocusedSelectionBackground(); if (r.isSelected()) { switch (r.getType()) { case HtmlRendererImpl.TYPE_LIST : result = UIManager.getColor ("List.selectionBackground"); //NOI18N return UIManager.getColor ("Tree.selectionBackground"); //NOI18N return result == null ? r.getBackground() : result;
public void setHtml (boolean val) { Boolean wasHtml = html; String txt = getText(); html = val ? Boolean.TRUE : Boolean.FALSE; if (swingRendering && html != wasHtml) { //Ensure label UI gets updated and builds its little document tree... firePropertyChange ("text", txt, getText()); //NOI18N } }
/** * Overridden for the case that we're running with the lightweight html renderer disabled, to convert * any less-than-legal html to legal html for purposes of Swing's html rendering. * * @return The text - unless the renderer is disabled, this just return super.getText() */ public String getText() { String result = super.getText(); if (swingRendering && Boolean.TRUE.equals(html)) { //Standard swing rendering needs an opening HTML tag to function, so make sure there is //one if we're not using HtmlLabelUI result = ensureHtmlTags (result); } else if (swingRendering && html == null) { //Cannot call isHtml() here, it will create an endless loop, so manually check the HTML status html = checkHtml (super.getText()); if (Boolean.TRUE.equals(html)) { result = ensureHtmlTags (result); } } return result; }
public void setBorder (Border b) { Border old = border; border = b; if (swingRendering) { firePropertyChange ("border", old, b); } }
/** * Converts our extended html syntax (allowing UIManager color keys and omitting opening html tags * into standard html. Only called if the lightweight html renderer is disabled and we're running with * a standard JLabel UI * * @param s The string that is the text of the label * @return The same string converted to standard HTML Swing's rendering infrastructure will know what to do * with */ private String ensureHtmlTags (String s) { s = ensureLegalFontColorTags(s); if (!s.startsWith("<HTML") && !s.startsWith("<html")) { //NOI18N s = "<html>" + s + "</html>"; //NOI18N } return s; }
String converted = convertToStandardColor (colorString); sb.replace(bangIdx, colorEnd, converted); s = sb.toString();
public Insets getInsets() { Insets result; //Call getBorder(), not just read the field - if swingRendering, the border will be constructed, and the //insets are what will make the indent property work; HtmlLabelUI doesn't need this, it just reads the //insets property, but BasicLabelUI and its ilk do Border b = getBorder(); if (b == null) { result = EMPTY_INSETS; } else { result = b.getBorderInsets(this); } return result; }