use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaButtonUI method getMaximumSize.
public Dimension getMaximumSize(final JComponent c) {
final Dimension d = getPreferredSize(c);
final View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
}
return d;
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaButtonUI method getMinimumSize.
// Layout Methods
public Dimension getMinimumSize(final JComponent c) {
final Dimension d = getPreferredSize(c);
final View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
}
return d;
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class MotifGraphicsUtils method paintMenuItem.
/**
* This method is not being used to paint menu item since
* 6.0 This code left for compatibility only. Do not use or
* override it, this will not cause any visible effect.
*/
public static void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) {
JMenuItem b = (JMenuItem) c;
ButtonModel model = b.getModel();
Dimension size = b.getSize();
Insets i = c.getInsets();
Rectangle viewRect = new Rectangle(size);
viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Rectangle acceleratorRect = new Rectangle();
Rectangle checkRect = new Rectangle();
Rectangle arrowRect = new Rectangle();
Font holdf = g.getFont();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
FontMetrics fmAccel = SwingUtilities2.getFontMetrics(c, g, UIManager.getFont("MenuItem.acceleratorFont"));
if (c.isOpaque()) {
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
g.setColor(background);
} else {
g.setColor(c.getBackground());
}
g.fillRect(0, 0, size.width, size.height);
}
// get Accelerator text
KeyStroke accelerator = b.getAccelerator();
String acceleratorText = "";
if (accelerator != null) {
int modifiers = accelerator.getModifiers();
if (modifiers > 0) {
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
acceleratorText += "+";
}
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
}
// layout the text and icon
String text = layoutMenuItem(c, fm, b.getText(), fmAccel, acceleratorText, b.getIcon(), checkIcon, arrowIcon, b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, acceleratorRect, checkRect, arrowRect, b.getText() == null ? 0 : defaultTextIconGap, defaultTextIconGap);
// Paint the Check
Color holdc = g.getColor();
if (checkIcon != null) {
if (model.isArmed() || (c instanceof JMenu && model.isSelected()))
g.setColor(foreground);
checkIcon.paintIcon(c, g, checkRect.x, checkRect.y);
g.setColor(holdc);
}
// Paint the Icon
if (b.getIcon() != null) {
Icon icon;
if (!model.isEnabled()) {
icon = b.getDisabledIcon();
} else if (model.isPressed() && model.isArmed()) {
icon = b.getPressedIcon();
if (icon == null) {
// Use default icon
icon = b.getIcon();
}
} else {
icon = b.getIcon();
}
if (icon != null) {
icon.paintIcon(c, g, iconRect.x, iconRect.y);
}
}
// Draw the Text
if (text != null && !text.equals("")) {
// Once BasicHTML becomes public, use BasicHTML.propertyKey
// instead of the hardcoded string below!
View v = (View) c.getClientProperty("html");
if (v != null) {
v.paint(g, textRect);
} else {
int mnemIndex = b.getDisplayedMnemonicIndex();
if (!model.isEnabled()) {
// *** paint the text disabled
g.setColor(b.getBackground().brighter());
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x, textRect.y + fmAccel.getAscent());
g.setColor(b.getBackground().darker());
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x - 1, textRect.y + fmAccel.getAscent() - 1);
} else {
// *** paint the text normally
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
g.setColor(foreground);
} else {
g.setColor(b.getForeground());
}
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
}
}
// Draw the Accelerator Text
if (acceleratorText != null && !acceleratorText.equals("")) {
//Get the maxAccWidth from the parent to calculate the offset.
int accOffset = 0;
Container parent = b.getParent();
if (parent != null && parent instanceof JComponent) {
JComponent p = (JComponent) parent;
Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH);
int maxValue = maxValueInt != null ? maxValueInt.intValue() : acceleratorRect.width;
//Calculate the offset, with which the accelerator texts will be drawn with.
accOffset = maxValue - acceleratorRect.width;
}
g.setFont(UIManager.getFont("MenuItem.acceleratorFont"));
if (!model.isEnabled()) {
// *** paint the acceleratorText disabled
g.setColor(b.getBackground().brighter());
SwingUtilities2.drawString(c, g, acceleratorText, acceleratorRect.x - accOffset, acceleratorRect.y + fm.getAscent());
g.setColor(b.getBackground().darker());
SwingUtilities2.drawString(c, g, acceleratorText, acceleratorRect.x - accOffset - 1, acceleratorRect.y + fm.getAscent() - 1);
} else {
// *** paint the acceleratorText normally
if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
g.setColor(foreground);
} else {
g.setColor(b.getForeground());
}
SwingUtilities2.drawString(c, g, acceleratorText, acceleratorRect.x - accOffset, acceleratorRect.y + fmAccel.getAscent());
}
}
// Paint the Arrow
if (arrowIcon != null) {
if (model.isArmed() || (c instanceof JMenu && model.isSelected()))
g.setColor(foreground);
if (!(b.getParent() instanceof JMenuBar))
arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y);
}
g.setColor(holdc);
g.setFont(holdf);
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaTabbedPaneContrastUI method paintTitle.
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
v.paint(g2d, textRect);
return;
}
if (title == null)
return;
final Color color = tabPane.getForegroundAt(tabIndex);
if (color instanceof UIResource) {
g2d.setColor(getNonSelectedTabTitleColor());
if (tabPane.getSelectedIndex() == tabIndex) {
boolean pressed = isPressedAt(tabIndex);
boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
Color textColor = getSelectedTabTitleColor(enabled, pressed);
Color shadowColor = getSelectedTabTitleShadowColor(enabled);
AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
return;
}
} else {
g2d.setColor(color);
}
g2d.setFont(font);
SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
use of javax.swing.text.View in project jdk8u_jdk by JetBrains.
the class AquaTabbedPaneCopyFromBasicUI method calculateTabHeight.
protected int calculateTabHeight(final int tabPlacement, final int tabIndex, final int fontHeight) {
int height = 0;
final Component c = tabPane.getTabComponentAt(tabIndex);
if (c != null) {
height = c.getPreferredSize().height;
} else {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
height += (int) v.getPreferredSpan(View.Y_AXIS);
} else {
// plain text
height += fontHeight;
}
final Icon icon = getIconForTab(tabIndex);
if (icon != null) {
height = Math.max(height, icon.getIconHeight());
}
}
final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
height += tabInsets.top + tabInsets.bottom + 2;
return height;
}
Aggregations