use of javax.swing.text.View in project intellij-community by JetBrains.
the class DarculaCheckBoxUI method drawText.
protected void drawText(JComponent c, Graphics2D g, JCheckBox b, FontMetrics fm, Rectangle textRect, String text) {
//text
if (text != null) {
View view = (View) c.getClientProperty(BasicHTML.propertyKey);
if (view != null) {
view.paint(g, textRect);
} else {
g.setColor(b.isEnabled() ? b.getForeground() : getDisabledTextColor());
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, b.getDisplayedMnemonicIndex(), textRect.x, textRect.y + fm.getAscent());
}
}
}
use of javax.swing.text.View in project intellij-community by JetBrains.
the class MacIntelliJButtonUI method paint.
@Override
public void paint(Graphics g, JComponent c) {
if (!(c.getBorder() instanceof MacIntelliJButtonBorder) && !isComboButton(c)) {
super.paint(g, c);
return;
}
int w = c.getWidth();
int h = c.getHeight();
if (isHelpButton(c)) {
Icon icon = MacIntelliJIconCache.getIcon("helpButton", false, c.hasFocus());
int x = (w - icon.getIconWidth()) / 2;
int y = (h - icon.getIconHeight()) / 2;
icon.paintIcon(c, g, x, y);
} else {
AbstractButton b = (AbstractButton) c;
String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());
boolean isFocused = c.hasFocus();
if (isSquare(c)) {
Icon icon = MacIntelliJIconCache.getIcon("browseButton");
int x = (c.getWidth() - icon.getIconWidth()) / 2;
int y = (c.getHeight() - icon.getIconHeight()) / 2;
icon.paintIcon(c, g, x, y);
return;
} else {
int x = isFocused ? 0 : 2;
int y = isFocused ? 0 : (h - viewRect.height) / 2;
Icon icon;
icon = getLeftIcon(b);
icon.paintIcon(b, g, x, y);
x += icon.getIconWidth();
int stop = w - (isFocused ? 0 : 2) - (getRightIcon(b).getIconWidth());
Graphics gg = g.create(0, 0, w, h);
gg.setClip(x, y, stop - x, h);
icon = getMiddleIcon(b);
while (x < stop) {
icon.paintIcon(b, gg, x, y);
x += icon.getIconWidth();
}
gg.dispose();
icon = getRightIcon(b);
icon.paintIcon(b, g, stop, y);
clearTextShiftOffset();
}
// Paint the Icon
if (b.getIcon() != null) {
paintIcon(g, c, iconRect);
}
if (text != null && !text.isEmpty()) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
UISettings.setupAntialiasing(g);
paintText(g, b, textRect, text);
}
}
}
}
use of javax.swing.text.View in project adempiere by adempiere.
the class HTMLRenderer method get.
/**
* Get View from HTML String
* @param html html string
* @return renderer view
*/
public static HTMLRenderer get(String html) {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
try {
doc.remove(0, doc.getLength());
Reader r = new StringReader(html);
kit.read(r, doc, 0);
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
// Create Renderer
Element element = doc.getDefaultRootElement();
ViewFactory factory = kit.getViewFactory();
// Y_AXIS is main
View view = factory.create(element);
HTMLRenderer renderer = new HTMLRenderer(factory, view);
renderer.preferenceChanged(null, true, true);
return renderer;
}
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