use of javax.swing.text.View in project intellij-community by JetBrains.
the class DarculaRadioButtonUI method drawText.
protected void drawText(AbstractButton b, Graphics2D g, String text, Rectangle textRect, FontMetrics fm) {
// Draw the Text
if (text != null) {
View v = (View) b.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
int mnemIndex = b.getDisplayedMnemonicIndex();
if (b.isEnabled()) {
// *** paint the text normally
g.setColor(b.getForeground());
} else {
// *** paint the text disabled
g.setColor(getDisabledTextColor());
}
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
}
if (b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0) {
paintFocus(g, textRect, b.getSize());
}
}
use of javax.swing.text.View in project android by JetBrains.
the class SimpleTabUI method layoutLabel.
@Override
protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
View v = getTextViewForTab(tabIndex);
if (v != null) {
tabPane.putClientProperty("html", v);
}
// CHANGE FROM DEFAULT: take tab insets into account
Insets insets = getTabInsets(tabPlacement, tabIndex);
tabRect = new Rectangle(tabRect);
tabRect.x += insets.left;
tabRect.y += insets.top;
tabRect.width = tabRect.width - insets.left - insets.right;
tabRect.height = tabRect.height - insets.top - insets.bottom;
SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingConstants.CENTER, // CHANGE FROM DEFAULT
SwingConstants.LEADING, SwingConstants.CENTER, SwingConstants.TRAILING, tabRect, iconRect, textRect, textIconGap);
tabPane.putClientProperty("html", null);
int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
iconRect.x += xNudge;
iconRect.y += yNudge;
textRect.x += xNudge;
textRect.y += yNudge;
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaMenuPainter method paintMenuItem.
protected void paintMenuItem(final Client client, final Graphics g, final JComponent c, final Icon checkIcon, final Icon arrowIcon, final Color background, final Color foreground, final Color disabledForeground, final Color selectionForeground, final int defaultTextIconGap, final Font acceleratorFont) {
final JMenuItem b = (JMenuItem) c;
final ButtonModel model = b.getModel();
// Dimension size = b.getSize();
final int menuWidth = b.getWidth();
final int menuHeight = b.getHeight();
final Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(0, 0, menuWidth, menuHeight);
viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
final Font holdf = g.getFont();
final Color holdc = g.getColor();
final Font f = c.getFont();
g.setFont(f);
final FontMetrics fm = g.getFontMetrics(f);
final FontMetrics fmAccel = g.getFontMetrics(acceleratorFont);
// Paint background (doesn't touch the Graphics object's color)
if (c.isOpaque()) {
client.paintBackground(g, c, menuWidth, menuHeight);
}
// get Accelerator text
final KeyStroke accelerator = b.getAccelerator();
String modifiersString = "", keyString = "";
final boolean leftToRight = AquaUtils.isLeftToRight(c);
if (accelerator != null) {
final int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
modifiersString = getKeyModifiersText(modifiers, leftToRight);
}
final int keyCode = accelerator.getKeyCode();
if (keyCode != 0) {
keyString = KeyEvent.getKeyText(keyCode);
} else {
keyString += accelerator.getKeyChar();
}
}
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Rectangle acceleratorRect = new Rectangle();
Rectangle checkIconRect = new Rectangle();
Rectangle arrowIconRect = new Rectangle();
// layout the text and icon
final String text = layoutMenuItem(b, fm, b.getText(), fmAccel, keyString, modifiersString, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkIconRect, arrowIconRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap);
// if this is in a AquaScreenMenuBar that's attached to a DialogPeer
// the native menu will be disabled, though the awt Menu won't know about it
// so the JPopupMenu will not have visibility set and the items should draw disabled
// If it's not on a JPopupMenu then it should just use the model's enable state
final Container parent = b.getParent();
final boolean parentIsMenuBar = parent instanceof JMenuBar;
Container ancestor = parent;
while (ancestor != null && !(ancestor instanceof JPopupMenu)) ancestor = ancestor.getParent();
boolean isEnabled = model.isEnabled() && (ancestor == null || ancestor.isVisible());
// Set the accel/normal text color
boolean isSelected = false;
if (!isEnabled) {
// *** paint the text disabled
g.setColor(disabledForeground);
} else {
// *** paint the text normally
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
g.setColor(selectionForeground);
isSelected = true;
} else {
// Which is either MenuItem.foreground or the user's choice
g.setColor(parentIsMenuBar ? parent.getForeground() : b.getForeground());
}
}
// Paint the Icon
if (b.getIcon() != null) {
paintIcon(g, b, iconRect, isEnabled);
}
// Paint the Check using the current text color
if (checkIcon != null) {
paintCheck(g, b, checkIcon, checkIconRect);
}
// Draw the accelerator first in case the HTML renderer changes the color
if (keyString != null && !keyString.equals("")) {
final int yAccel = acceleratorRect.y + fm.getAscent();
if (modifiersString.equals("")) {
// just draw the keyString
SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x, yAccel);
} else {
final int modifiers = accelerator.getModifiers();
int underlinedChar = 0;
// This is a Java2 thing, we won't be getting kOptionGlyph
if ((modifiers & ALT_GRAPH_MASK) > 0)
underlinedChar = kUOptionGlyph;
// The keyStrings should all line up, so always adjust the width by the same amount
// (if they're multi-char, they won't line up but at least they won't be cut off)
final int emWidth = Math.max(fm.charWidth('M'), SwingUtilities.computeStringWidth(fm, keyString));
if (leftToRight) {
g.setFont(acceleratorFont);
drawString(g, c, modifiersString, underlinedChar, acceleratorRect.x, yAccel, isEnabled, isSelected);
g.setFont(f);
SwingUtilities2.drawString(c, g, keyString, acceleratorRect.x + acceleratorRect.width - emWidth, yAccel);
} else {
final int xAccel = acceleratorRect.x + emWidth;
g.setFont(acceleratorFont);
drawString(g, c, modifiersString, underlinedChar, xAccel, yAccel, isEnabled, isSelected);
g.setFont(f);
SwingUtilities2.drawString(c, g, keyString, xAccel - fm.stringWidth(keyString), yAccel);
}
}
}
// Draw the Text
if (text != null && !text.equals("")) {
final View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
final int mnemonic = (AquaMnemonicHandler.isMnemonicHidden() ? -1 : model.getMnemonic());
drawString(g, c, text, mnemonic, textRect.x, textRect.y + fm.getAscent(), isEnabled, isSelected);
}
}
// Paint the Arrow
if (arrowIcon != null) {
paintArrow(g, b, model, arrowIcon, arrowIconRect);
}
g.setColor(holdc);
g.setFont(holdf);
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaTabbedPaneCopyFromBasicUI method calculateTabWidth.
protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
int width = tabInsets.left + tabInsets.right + 3;
final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
if (tabComponent != null) {
width += tabComponent.getPreferredSize().width;
} else {
final Icon icon = getIconForTab(tabIndex);
if (icon != null) {
width += icon.getIconWidth() + textIconGap;
}
final View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
width += (int) v.getPreferredSpan(View.X_AXIS);
} else {
// plain text
final String title = tabPane.getTitleAt(tabIndex);
width += SwingUtilities2.stringWidth(tabPane, metrics, title);
}
}
return width;
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaTabbedPaneCopyFromBasicUI method paintText.
protected void paintText(final Graphics g, final int tabPlacement, final Font font, final FontMetrics metrics, final int tabIndex, final String title, final Rectangle textRect, final boolean isSelected) {
g.setFont(font);
final View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
v.paint(g, textRect);
} else {
// plain text
final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
Color fg = tabPane.getForegroundAt(tabIndex);
if (isSelected && (fg instanceof UIResource)) {
final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
if (selectedFG != null) {
fg = selectedFG;
}
}
g.setColor(fg);
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
} else {
// tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
}
}
}
Aggregations