show fonts which cannot display latin characters in font selection combobox (following IDEA-154927)

This commit is contained in:
Dmitry Batrak
2016-04-25 17:59:09 +03:00
parent 073bc15085
commit d7e1437058
2 changed files with 10 additions and 8 deletions
@@ -21,8 +21,8 @@ import com.intellij.util.ui.FontInfo;
import com.intellij.util.ui.UIUtil;
import sun.swing.SwingUtilities2;
import java.awt.Font;
import javax.swing.JList;
import javax.swing.*;
import java.awt.*;
/**
* @author Sergey.Malenkov
@@ -31,15 +31,17 @@ public class FontInfoRenderer extends ListCellRendererWrapper {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean focused) {
Font font = list.getFont();
String text = value == null ? "" : value.toString();
setText(text);
if (value instanceof FontInfo) {
FontInfo info = (FontInfo)value;
Integer size = getFontSize();
setFont(info.getFont(size != null ? size : font.getSize()));
Font f = info.getFont(size != null ? size : font.getSize());
if (f.canDisplayUpTo(text) == -1) {
font = f;
}
}
else {
setFont(list.getFont());
}
setText(value == null ? "" : value.toString());
setFont(font);
setForeground(list.isEnabled()
? UIUtil.getListForeground(selected)
: UIUtil.getLabelDisabledForeground());
@@ -215,7 +215,7 @@ public final class FontInfo {
Rectangle bounds = font.getStringBounds(new char[]{ch}, 0, 1, DEFAULT_CONTEXT).getBounds();
if (!bounds.isEmpty()) return bounds.width;
}
throw new IllegalArgumentException(Integer.toHexString(ch) + " cannot be rendered by " + font);
return 0;
}
private static final class LazyListByName {