mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support for SimpleTextAttributes.STYLE_SMALLER in SimpleColoredComponent
This commit is contained in:
@@ -317,11 +317,15 @@ public class SimpleColoredComponent extends JComponent implements Accessible {
|
||||
|
||||
LOG.assertTrue(font != null);
|
||||
|
||||
int baseSize = font.getSize();
|
||||
boolean wasSmaller = false;
|
||||
for (int i = 0; i < myAttributes.size(); i++) {
|
||||
SimpleTextAttributes attributes = myAttributes.get(i);
|
||||
if (font.getStyle() != attributes.getFontStyle()) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle());
|
||||
boolean isSmaller = attributes.isSmaller();
|
||||
if (font.getStyle() != attributes.getFontStyle() || isSmaller != wasSmaller) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle(), isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
|
||||
}
|
||||
wasSmaller = isSmaller;
|
||||
final FontMetrics metrics = getFontMetrics(font);
|
||||
width += metrics.stringWidth(myFragments.get(i));
|
||||
|
||||
@@ -365,11 +369,16 @@ public class SimpleColoredComponent extends JComponent implements Accessible {
|
||||
Font font = getFont();
|
||||
LOG.assertTrue(font != null);
|
||||
|
||||
int baseSize = font.getSize();
|
||||
boolean wasSmaller = false;
|
||||
for (int i = 0; i < myAttributes.size(); i++) {
|
||||
SimpleTextAttributes attributes = myAttributes.get(i);
|
||||
if (font.getStyle() != attributes.getFontStyle()) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle());
|
||||
boolean isSmaller = attributes.isSmaller();
|
||||
if (font.getStyle() != attributes.getFontStyle() || isSmaller != wasSmaller) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle(), isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
|
||||
}
|
||||
wasSmaller = isSmaller;
|
||||
|
||||
final FontMetrics metrics = getFontMetrics(font);
|
||||
final int curWidth = metrics.stringWidth(myFragments.get(i));
|
||||
if (x >= curX && x < curX + curWidth) {
|
||||
@@ -455,12 +464,18 @@ public class SimpleColoredComponent extends JComponent implements Accessible {
|
||||
UIUtil.applyRenderingHints(g);
|
||||
applyAdditionalHints(g);
|
||||
|
||||
int baseSize = getFont().getSize();
|
||||
boolean wasSmaller = false;
|
||||
for (int i = 0; i < myFragments.size(); i++) {
|
||||
final SimpleTextAttributes attributes = myAttributes.get(i);
|
||||
|
||||
Font font = g.getFont();
|
||||
if (font.getStyle() != attributes.getFontStyle()) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle());
|
||||
boolean isSmaller = attributes.isSmaller();
|
||||
if (font.getStyle() != attributes.getFontStyle() || isSmaller != wasSmaller) { // derive font only if it is necessary
|
||||
font = font.deriveFont(attributes.getFontStyle(), isSmaller ? UIUtil.getFontSize(UIUtil.FontSize.SMALL) : baseSize);
|
||||
}
|
||||
wasSmaller = isSmaller;
|
||||
|
||||
g.setFont(font);
|
||||
final FontMetrics metrics = g.getFontMetrics(font);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ public final class SimpleTextAttributes {
|
||||
public static final int STYLE_UNDERLINE = STYLE_WAVED << 1;
|
||||
public static final int STYLE_BOLD_DOTTED_LINE = STYLE_UNDERLINE << 1;
|
||||
public static final int STYLE_SEARCH_MATCH = STYLE_BOLD_DOTTED_LINE << 1;
|
||||
public static final int STYLE_SMALLER = STYLE_SEARCH_MATCH << 1;
|
||||
|
||||
public static final SimpleTextAttributes REGULAR_ATTRIBUTES = new SimpleTextAttributes(STYLE_PLAIN, null);
|
||||
public static final SimpleTextAttributes REGULAR_BOLD_ATTRIBUTES = new SimpleTextAttributes(STYLE_BOLD, null);
|
||||
@@ -85,7 +86,8 @@ public final class SimpleTextAttributes {
|
||||
STYLE_WAVED |
|
||||
STYLE_UNDERLINE |
|
||||
STYLE_BOLD_DOTTED_LINE |
|
||||
STYLE_SEARCH_MATCH) & style) != 0) {
|
||||
STYLE_SEARCH_MATCH |
|
||||
STYLE_SMALLER) & style) != 0) {
|
||||
throw new IllegalArgumentException("Wrong style: " + style);
|
||||
}
|
||||
|
||||
@@ -147,6 +149,10 @@ public final class SimpleTextAttributes {
|
||||
public boolean isSearchMatch() {
|
||||
return (myStyle & STYLE_SEARCH_MATCH) != 0;
|
||||
}
|
||||
|
||||
public boolean isSmaller() {
|
||||
return (myStyle & STYLE_SMALLER) != 0;
|
||||
}
|
||||
|
||||
public static SimpleTextAttributes fromTextAttributes(TextAttributes attributes) {
|
||||
if (attributes == null) return REGULAR_ATTRIBUTES;
|
||||
|
||||
Reference in New Issue
Block a user