Search in sources :

Example 1 with FontDescriptor

use of com.intellij.uiDesigner.lw.FontDescriptor in project intellij-community by JetBrains.

the class FontEditorDialog method updateValue.

private void updateValue() {
    final int fontSize = ((Integer) myFontSizeEdit.getValue()).intValue();
    myValue = new FontDescriptor(myFontNameCheckbox.isSelected() ? toString(myFontNameList.getSelectedValue()) : null, myFontStyleCheckbox.isSelected() ? myFontStyleList.getSelectedIndex() : -1, myFontSizeCheckbox.isSelected() ? fontSize : -1);
    updatePreview();
}
Also used : FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Example 2 with FontDescriptor

use of com.intellij.uiDesigner.lw.FontDescriptor in project intellij-community by JetBrains.

the class FontPropertyCodeGenerator method generatePushValue.

public void generatePushValue(final GeneratorAdapter generator, final Object value) {
    FontDescriptor descriptor = (FontDescriptor) value;
    if (descriptor.isFixedFont()) {
        if (!descriptor.isFullyDefinedFont())
            throw new IllegalStateException("Unexpected font state");
        generator.newInstance(ourFontType);
        generator.dup();
        generator.push(descriptor.getFontName());
        generator.push(descriptor.getFontStyle());
        generator.push(descriptor.getFontSize());
        generator.invokeConstructor(ourFontType, ourInitMethod);
    } else if (descriptor.getSwingFont() != null) {
        generator.push(descriptor.getSwingFont());
        generator.invokeStatic(ourUIManagerType, ourUIManagerGetFontMethod);
    } else {
        throw new IllegalStateException("Unknown font type");
    }
}
Also used : FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Example 3 with FontDescriptor

use of com.intellij.uiDesigner.lw.FontDescriptor in project intellij-community by JetBrains.

the class FontPropertyCodeGenerator method generateCustomSetValue.

public boolean generateCustomSetValue(final LwComponent lwComponent, final InstrumentationClassFinder.PseudoClass componentClass, final LwIntrospectedProperty property, final GeneratorAdapter generator, final int componentLocal, final String formClassName) {
    FontDescriptor descriptor = (FontDescriptor) property.getPropertyValue(lwComponent);
    if (descriptor.isFixedFont() && !descriptor.isFullyDefinedFont()) {
        Label fontNullLabel = generator.newLabel();
        generatePushFont(generator, componentLocal, lwComponent, descriptor, property.getReadMethodName(), fontNullLabel);
        Method setFontMethod = new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[] { ourFontType });
        Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName());
        generator.invokeVirtual(componentType, setFontMethod);
        generator.mark(fontNullLabel);
        return true;
    }
    return false;
}
Also used : Label(org.jetbrains.org.objectweb.asm.Label) Method(org.jetbrains.org.objectweb.asm.commons.Method) FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Example 4 with FontDescriptor

use of com.intellij.uiDesigner.lw.FontDescriptor in project intellij-community by JetBrains.

the class FontEditorDialog method collectSwingFontDescriptors.

private static FontDescriptor[] collectSwingFontDescriptors() {
    ArrayList<FontDescriptor> result = new ArrayList<>();
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration e = defaults.keys();
    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        Object value = defaults.get(key);
        if (key instanceof String && value instanceof Font) {
            result.add(FontDescriptor.fromSwingFont((String) key));
        }
    }
    Collections.sort(result, (o1, o2) -> o1.getSwingFont().compareTo(o2.getSwingFont()));
    return result.toArray(new FontDescriptor[result.size()]);
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) Font(java.awt.Font) FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Example 5 with FontDescriptor

use of com.intellij.uiDesigner.lw.FontDescriptor in project intellij-community by JetBrains.

the class IntroFontProperty method importSnapshotValue.

@Override
public void importSnapshotValue(final SnapshotContext context, final JComponent component, final RadComponent radComponent) {
    try {
        if (component.getParent() != null) {
            Font componentFont = (Font) myReadMethod.invoke(component, EMPTY_OBJECT_ARRAY);
            if (componentFont instanceof FontUIResource) {
                final Constructor constructor = component.getClass().getConstructor(ArrayUtil.EMPTY_CLASS_ARRAY);
                constructor.setAccessible(true);
                JComponent newComponent = (JComponent) constructor.newInstance(ArrayUtil.EMPTY_OBJECT_ARRAY);
                Font defaultFont = (Font) myReadMethod.invoke(newComponent, EMPTY_OBJECT_ARRAY);
                if (defaultFont == componentFont) {
                    return;
                }
                UIDefaults defaults = UIManager.getDefaults();
                Enumeration e = defaults.keys();
                while (e.hasMoreElements()) {
                    Object key = e.nextElement();
                    Object value = defaults.get(key);
                    if (key instanceof String && value == componentFont) {
                        setValue(radComponent, FontDescriptor.fromSwingFont((String) key));
                        return;
                    }
                }
            }
            Font parentFont = (Font) myReadMethod.invoke(component.getParent(), EMPTY_OBJECT_ARRAY);
            if (!Comparing.equal(componentFont, parentFont)) {
                String fontName = componentFont.getName().equals(parentFont.getName()) ? null : componentFont.getName();
                int fontStyle = componentFont.getStyle() == parentFont.getStyle() ? -1 : componentFont.getStyle();
                int fontSize = componentFont.getSize() == parentFont.getSize() ? -1 : componentFont.getSize();
                setValue(radComponent, new FontDescriptor(fontName, fontStyle, fontSize));
            }
        }
    } catch (Exception e) {
    // ignore
    }
}
Also used : Enumeration(java.util.Enumeration) FontUIResource(javax.swing.plaf.FontUIResource) Constructor(java.lang.reflect.Constructor) FontDescriptor(com.intellij.uiDesigner.lw.FontDescriptor)

Aggregations

FontDescriptor (com.intellij.uiDesigner.lw.FontDescriptor)5 Enumeration (java.util.Enumeration)2 Font (java.awt.Font)1 Constructor (java.lang.reflect.Constructor)1 ArrayList (java.util.ArrayList)1 FontUIResource (javax.swing.plaf.FontUIResource)1 Label (org.jetbrains.org.objectweb.asm.Label)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1