@Override public JComponent createContentPanel() { JPanel panel = new JPanel(new BorderLayout()); if (message instanceof Component) { panel.add((Component) message, BorderLayout.CENTER); } else { StyledLabel styledLabel = new StyledLabel(message.toString()); styledLabel.setLineWrap(true); panel.add(styledLabel, BorderLayout.CENTER); } panel.setBorder(Borders.DIALOG_CONTENT_BORDER); return panel; }
public StyledLabel configure(StyledLabel label) { label.setText(buffer.toString()); int size = ranges.size(); for (int i = 0; i < size; i++) { label.addStyleRange((StyleRange) ranges.get(i)); } return label; }
/** * Clears all the old StyleRanges and adds a list of StyleRanges into this <code>StyledLabel</code>. * * @param styleRanges set the StyleRanges. */ public synchronized void setStyleRanges(StyleRange[] styleRanges) { internalGetStyleRanges().clear(); addStyleRanges(styleRanges); }
/** * Removes the StyleRange. * * @param styleRange the StyleRange to be removed. */ public synchronized void clearStyleRange(StyleRange styleRange) { if (internalGetStyleRanges().remove(styleRange)) { firePropertyChange(PROPERTY_STYLE_RANGE, styleRange, null); } }
private int internalPaintStyledText(StyledLabel label, Graphics g, int textX, int textY, int paintWidth) { int labelHeight = label.getHeight(); if (labelHeight <= 0) { labelHeight = Integer.MAX_VALUE; Insets insets = label.getInsets(); if (insets != null) { labelHeight -= insets.top + insets.bottom; if (label.getIcon() != null) { int horizontalTextPosition = label.getHorizontalTextPosition(); if ((horizontalTextPosition == SwingConstants.TRAILING && label.getComponentOrientation().isLeftToRight()) ||(horizontalTextPosition == SwingConstants.LEADING && !label.getComponentOrientation().isLeftToRight())) { horizontalTextPosition = SwingConstants.RIGHT; leftMostX += label.getIcon().getIconWidth() + label.getIconTextGap(); int endX = paintWidth + startX; int x = startX; int mnemonicIndex = label.getDisplayedMnemonicIndex(); if (UIManager.getLookAndFeel() instanceof WindowsLookAndFeel && WindowsLookAndFeel.isMnemonicHidden()) { int mneIndex = 0; Font font = getFont(label); FontMetrics fm = label.getFontMetrics(font); FontMetrics fm2; FontMetrics nextFm2 = null; int maxRowHeight = fm.getHeight(); int minStartY = fm.getAscent();
int horizontalTextPosition = label.getHorizontalTextPosition(); int horizontalAlignment = label.getHorizontalAlignment(); if ((horizontalTextPosition == SwingConstants.TRAILING && !label.getComponentOrientation().isLeftToRight()) ||(horizontalTextPosition == SwingConstants.LEADING && label.getComponentOrientation().isLeftToRight())) { horizontalTextPosition = SwingConstants.LEFT; if ((horizontalTextPosition == SwingConstants.LEADING && !label.getComponentOrientation().isLeftToRight()) ||(horizontalTextPosition == SwingConstants.TRAILING && label.getComponentOrientation().isLeftToRight())) { horizontalTextPosition = SwingConstants.RIGHT; if ((horizontalAlignment == SwingConstants.TRAILING && !label.getComponentOrientation().isLeftToRight()) ||(horizontalAlignment == SwingConstants.LEADING && label.getComponentOrientation().isLeftToRight())) { horizontalAlignment = SwingConstants.LEFT; if ((horizontalAlignment == SwingConstants.LEADING && !label.getComponentOrientation().isLeftToRight()) ||(horizontalAlignment == SwingConstants.TRAILING && label.getComponentOrientation().isLeftToRight())) { horizontalAlignment = SwingConstants.RIGHT; Insets insets = label.getInsets(); int textX = leftAlignmentX; int paintWidth = thisLineEndX - leftAlignmentX; if (horizontalAlignment == RIGHT) { paintWidth = thisLineEndX - textX; textX = label.getWidth() - paintWidth; if (insets != null) { textX -= insets.right; if (label.getIcon() != null && horizontalTextPosition == SwingConstants.LEFT) { textX -= label.getIcon().getIconWidth() + label.getIconTextGap(); if (horizontalTextPosition == SwingConstants.RIGHT && label.getIcon() != null) { leftMostX += label.getIcon().getIconWidth() + label.getIconTextGap();
FontMetrics fm = label.getFontMetrics(font); FontMetrics fm2; int defaultFontSize = font.getSize(); boolean lineWrap = label.isLineWrap() || (label.getText() != null && (label.getText().contains("\r") || label.getText().contains("\n"))); synchronized (_styledTexts) { StyledText[] texts = _styledTexts.toArray(new StyledText[_styledTexts.size()]); if (style != null && ((style.getFontStyle() != -1 && font.getStyle() != style.getFontStyle()) || font.getSize() != size)) { font = FontUtils.getCachedDerivedFont(font, style.getFontStyle() == -1 ? font.getStyle() : style.getFontStyle(), size); fm2 = label.getFontMetrics(font); styleHeight = fm2.getHeight(); width = 0; naturalRowCount++; if (label.getMaxRows() > 0 && naturalRowCount > label.getMaxRows()) { break; fm2 = label.getFontMetrics(font); width += fm2.stringWidth(s); if (lineWrap && label.getPreferredWidth() <= 0 && label.getRows() > 0) { maxWidth = getMaximumWidth(label, maxWidth, naturalRowCount, label.getRows()); int preferredWidth = label.getPreferredWidth(); if (preferredWidth > 0 && label.getInsets() != null) { preferredWidth -= label.getInsets().left + label.getInsets().right; if (label.getIcon() != null && label.getHorizontalTextPosition() != SwingConstants.CENTER) { preferredWidth -= label.getIcon().getIconWidth() + label.getIconTextGap();
label.setLineWrap(true); label.setRows(defaultRows); label.setMaxRows(maxRows); label.setMinRows(minRows); label.setPreferredWidth(preferredWidth); if (defaultRows == 1 && maxRows == 1 && minRows == 1) { label.setLineWrap(false);
private static void setStyledText(StyledLabel label, char[] text, StyledLabelBuilder builder) { StringBuffer labelText = new StringBuffer(text.length); boolean escaped = false; label.clearStyleRanges(); label.setLineWrap(false); int endOfText = text.length; for (int j = text.length - 1; j >= 0; j--) { labelText.append(result.text); if (result.text.length() > 0) { label.addStyleRange(new StyleRange( realIndex, result.text.length(), result.fontStyle, result.fontColor, result.backgroundColor, label.setText(labelText.toString());
private int getMaximumWidth(StyledLabel label, int maxWidth, int naturalRowCount, int limitedRows) { int textWidth = label.getWidth() - label.getInsets().left - label.getInsets().right; if (label.getIcon() != null) { textWidth -= label.getIcon().getIconWidth() + label.getIconTextGap(); int nextRowStartIndex = 0; Font font = getFont(label); FontMetrics fm = label.getFontMetrics(font); int defaultFontSize = font.getSize(); FontMetrics fm2; if (style != null && ((style.getFontStyle() != -1 && font.getStyle() != style.getFontStyle()) || font.getSize() != size)) { font = FontUtils.getCachedDerivedFont(font, style.getFontStyle() == -1 ? font.getStyle() : style.getFontStyle(), size); fm2 = label.getFontMetrics(font); if (label.getInsets() != null) { paintWidth += label.getInsets().left + label.getInsets().right; if (label.getInsets() != null) { x -= label.getInsets().left + label.getInsets().right;
public static StyledLabel createStyledLabel(String text) { StyledLabel label = new StyledLabel(); setStyledText(label, text); return label; }
Font font = getFont(label); int defaultFontSize = font.getSize(); FontMetrics fm = label.getFontMetrics(font); FontMetrics fm2; nextRowStartIndex = 0; fm2 = label.getFontMetrics(font); if (label.getMaxRows() > 0 && _preferredRowCount >= label.getMaxRows()) { needBreak = true;
/** * Sets if the color defined by StyleRange should be ignored. This flag is used when StyledLabel is used as a * selected cell renderer. Since the selection usually has it own unique selection background and foreground, the * color setting set on this StyledLabel could be unreadable on the selection background, it'd better if we don't * use any color settings in this case. * * @param ignoreColorSettings true or false. */ public void setIgnoreColorSettings(boolean ignoreColorSettings) { boolean old = _ignoreColorSettings; if (old != ignoreColorSettings) { _ignoreColorSettings = ignoreColorSettings; firePropertyChange(PROPERTY_IGNORE_COLOR_SETTINGS, old, ignoreColorSettings); } }
private void customizeStyledLabel(StyledLabel label, String text) { label.addStyleRange(new StyleRange(0, 3, Font.BOLD, Color.RED)); label.addStyleRange(new StyleRange(3, length, Font.BOLD, Color.BLACK)); label.addStyleRange(new StyleRange(0, 3, Font.BOLD, Color.BLACK, Color.YELLOW, 0)); label.addStyleRange(new StyleRange(find, -1, Font.PLAIN, Color.BLUE)); label.addStyleRange(new StyleRange(find, -1, Font.PLAIN, Color.GRAY)); label.addStyleRange(new StyleRange(find, 10, Font.PLAIN, Color.BLACK, selectedAddressColor, 0)); } else if (selectedAddress != null && text.contains(selectedAddress) && !text.contains("syscall")) { int find = text.indexOf(selectedAddress); label.addStyleRange(new StyleRange(find, 8, Font.PLAIN, Color.BLACK, selectedAddressColor, 0)); label.addStyleRange(new StyleRange(lastfind, 3, Font.PLAIN, Color.BLACK, selectedRegColors[j], 0));
/** * Gets the font from the label. * * @param label the label. * @return the font. If label's getFont is null, we will use Label.font instead. */ protected Font getFont(StyledLabel label) { Font font = label.getFont(); if (font == null) { font = UIDefaultsLookup.getFont("Label.font"); } return font; }
/** * Clears all the StyleRanges. */ public synchronized void clearStyleRanges() { internalGetStyleRanges().clear(); firePropertyChange(PROPERTY_STYLE_RANGE, null, null); }
public StyledLabel createLabel() { return configure(new StyledLabel()); }
/** * Overridden for performance reasons. See the <a href="#override">Implementation Note</a> for more information. */ @Override protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { // Strings get interned... if (propertyName.equals("text")) super.firePropertyChange(propertyName, oldValue, newValue); }
/** * Gets the font of this component. * * @return this component's font; if a font has not been set for this component, the font of its parent is returned */ @Override public Font getFont() { Font font = super.getFont(); if (font == null && tree != null) { // Strive to return a non-null value, otherwise the html support // will typically pick up the wrong font in certain situations. font = tree.getFont(); } return font; }
/** * Adds a list of StyleRanges into this <code>StyledLabel</code>. * * @param styleRanges an array of StyleRanges. */ public synchronized void addStyleRanges(StyleRange[] styleRanges) { if (styleRanges != null) { for (StyleRange styleRange : styleRanges) { internalGetStyleRanges().add(styleRange); } firePropertyChange(PROPERTY_STYLE_RANGE, null, styleRanges); } else { firePropertyChange(PROPERTY_STYLE_RANGE, null, null); } }