mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Support font rendering in UI Designer
This commit is contained in:
@@ -18,6 +18,7 @@ package com.intellij.ui;
|
||||
import com.intellij.ide.ui.AntialiasingType;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.util.ui.FontInfo;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import java.awt.Font;
|
||||
@@ -39,6 +40,9 @@ public class FontInfoRenderer extends ListCellRendererWrapper {
|
||||
setFont(list.getFont());
|
||||
}
|
||||
setText(value == null ? "" : value.toString());
|
||||
setForeground(list.isEnabled()
|
||||
? UIUtil.getListForeground(selected)
|
||||
: UIUtil.getLabelDisabledForeground());
|
||||
|
||||
AntialiasingType type = getAntialiasingType();
|
||||
if (type == null) type = AntialiasingType.GREYSCALE;
|
||||
|
||||
+35
-3
@@ -18,10 +18,12 @@ package com.intellij.uiDesigner.propertyInspector.editors;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.ui.ColoredListCellRenderer;
|
||||
import com.intellij.ui.FontInfoRenderer;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.uiDesigner.UIDesignerBundle;
|
||||
import com.intellij.uiDesigner.lw.FontDescriptor;
|
||||
import com.intellij.uiDesigner.propertyInspector.properties.IntroFontProperty;
|
||||
import com.intellij.util.ui.FontInfo;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -37,11 +39,13 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class FontEditorDialog extends DialogWrapper {
|
||||
private final Model myModel = new Model();
|
||||
private JList myFontNameList;
|
||||
private JList myFontStyleList;
|
||||
private JList myFontSizeList;
|
||||
@@ -61,7 +65,8 @@ public class FontEditorDialog extends DialogWrapper {
|
||||
super(project, false);
|
||||
init();
|
||||
setTitle(UIDesignerBundle.message("font.chooser.title", propertyName));
|
||||
myFontNameList.setListData(UIUtil.getValidFontNames(true));
|
||||
myFontNameList.setModel(myModel);
|
||||
myFontNameList.setCellRenderer(new FontInfoRenderer());
|
||||
myFontNameList.addListSelectionListener(new MyListSelectionListener(myFontNameEdit));
|
||||
myFontStyleList.setListData(new String[] {
|
||||
UIDesignerBundle.message("font.chooser.regular"),
|
||||
@@ -170,7 +175,7 @@ public class FontEditorDialog extends DialogWrapper {
|
||||
myFontNameCheckbox.setSelected(value.getFontName() != null);
|
||||
myFontSizeCheckbox.setSelected(value.getFontSize() >= 0);
|
||||
myFontStyleCheckbox.setSelected(value.getFontStyle() >= 0);
|
||||
myFontNameList.setSelectedValue(value.getFontName(), true);
|
||||
myFontNameList.setSelectedValue(myModel.findElement(value.getFontName()), true);
|
||||
myFontStyleList.setSelectedIndex(value.getFontStyle());
|
||||
if (value.getFontSize() >= 0) {
|
||||
myFontSizeList.setSelectedValue(Integer.toString(value.getFontSize()), true);
|
||||
@@ -187,7 +192,7 @@ public class FontEditorDialog extends DialogWrapper {
|
||||
|
||||
private void updateValue() {
|
||||
final int fontSize = ((Integer)myFontSizeEdit.getValue()).intValue();
|
||||
myValue = new FontDescriptor(myFontNameCheckbox.isSelected() ? (String) myFontNameList.getSelectedValue() : null,
|
||||
myValue = new FontDescriptor(myFontNameCheckbox.isSelected() ? toString(myFontNameList.getSelectedValue()) : null,
|
||||
myFontStyleCheckbox.isSelected() ? myFontStyleList.getSelectedIndex() : -1,
|
||||
myFontSizeCheckbox.isSelected() ? fontSize : -1);
|
||||
updatePreview();
|
||||
@@ -221,4 +226,31 @@ public class FontEditorDialog extends DialogWrapper {
|
||||
updateValue();
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(Object object) {
|
||||
return object == null ? null : object.toString();
|
||||
}
|
||||
|
||||
private static final class Model extends AbstractListModel {
|
||||
private final List<FontInfo> myList = FontInfo.getAll(false);
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return myList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontInfo getElementAt(int index) {
|
||||
return myList.get(index);
|
||||
}
|
||||
|
||||
public FontInfo findElement(String name) {
|
||||
for (FontInfo info : myList) {
|
||||
if (info.toString().equals(name)) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user