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; }
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"); } }
public void writeFontDescriptor(final FontDescriptor value) { if (value.getSwingFont() != null) { addAttribute(UIFormXmlConstants.ATTRIBUTE_SWING_FONT, value.getSwingFont()); } else { if (value.getFontName() != null) { addAttribute(UIFormXmlConstants.ATTRIBUTE_NAME, value.getFontName()); } if (value.getFontSize() >= 0) { addAttribute(UIFormXmlConstants.ATTRIBUTE_SIZE, value.getFontSize()); } if (value.getFontStyle() >= 0) { addAttribute(UIFormXmlConstants.ATTRIBUTE_STYLE, value.getFontStyle()); } } }
private static FontDescriptor[] collectSwingFontDescriptors() { ArrayList<FontDescriptor> result = new ArrayList<FontDescriptor>(); 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, new Comparator<FontDescriptor>() { public int compare(final FontDescriptor o1, final FontDescriptor o2) { return o1.getSwingFont().compareTo(o2.getSwingFont()); } }); return result.toArray(new FontDescriptor[result.size()]); }
public void setValue(@NotNull final FontDescriptor value) { myValue = value; if (value.getSwingFont() != null) { myTabbedPane.setSelectedIndex(1); mySwingFontList.setSelectedValue(myValue, true); } else { myFontNameCheckbox.setSelected(value.getFontName() != null); myFontSizeCheckbox.setSelected(value.getFontSize() >= 0); myFontStyleCheckbox.setSelected(value.getFontStyle() >= 0); myFontNameList.setSelectedValue(value.getFontName(), true); myFontStyleList.setSelectedIndex(value.getFontStyle()); if (value.getFontSize() >= 0) { myFontSizeList.setSelectedValue(Integer.toString(value.getFontSize()), true); if (myFontSizeList.getSelectedIndex() < 0) { myFontSizeEdit.setValue(new Integer(value.getFontSize())); } } else { myFontSizeList.setSelectedIndex(-1); myFontSizeEdit.setValue(0); } } }
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()) { generator.loadLocal(componentLocal); generatePushFont(generator, componentLocal, lwComponent, descriptor, property.getReadMethodName()); Method setFontMethod = new Method(property.getWriteMethodName(), Type.VOID_TYPE, new Type[] { ourFontType } ); Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); generator.invokeVirtual(componentType, setFontMethod); return true; } return false; }
@Override public FontDescriptor getValue(final RadComponent component) { final FontDescriptor fontDescriptor = (FontDescriptor) component.getDelegee().getClientProperty(CLIENT_PROPERTY_KEY_PREFIX + getName()); if (fontDescriptor == null) { return new FontDescriptor(null, -1, -1); } return fontDescriptor; }
@Override protected void setValueImpl(final RadComponent component, final FontDescriptor value) throws Exception { component.getDelegee().putClientProperty(CLIENT_PROPERTY_KEY_PREFIX + getName(), value); if (value != null) { if (!component.isLoadingProperties()) { invokeSetter(component, getDefaultValue(component.getDelegee())); } Font defaultFont = (Font) invokeGetter(component); final Font resolvedFont = value.getResolvedFont(defaultFont); invokeSetter(component, resolvedFont); } }
public static String descriptorToString(final FontDescriptor value) { if (value == null) { return ""; } if (value.getSwingFont() != null) { return value.getSwingFont(); } StringBuilder builder = new StringBuilder(); if (value.getFontName() != null) { builder.append(value.getFontName()); } if (value.getFontSize() >= 0) { builder.append(' ').append(value.getFontSize()).append(" pt"); } if (value.getFontStyle() >= 0) { if (value.getFontStyle() == 0) { builder.append(' ').append(UIDesignerBundle.message("font.chooser.regular")); } else { if ((value.getFontStyle() & Font.BOLD) != 0) { builder.append(' ').append(UIDesignerBundle.message("font.chooser.bold")); } if ((value.getFontStyle() & Font.ITALIC) != 0) { builder.append(" ").append(UIDesignerBundle.message("font.chooser.italic")); } } } String result = builder.toString().trim(); if (result.length() > 0) { return result; } return UIDesignerBundle.message("font.default"); }
@NotNull public PropertyRenderer<FontDescriptor> getRenderer() { if (myRenderer == null) { myRenderer = new FontRenderer(); } return myRenderer; }
private void updateValue() { final int fontSize = ((Integer)myFontSizeEdit.getValue()).intValue(); myValue = new FontDescriptor(myFontNameCheckbox.isSelected() ? (String) myFontNameList.getSelectedValue() : null, myFontStyleCheckbox.isSelected() ? myFontStyleList.getSelectedIndex() : -1, myFontSizeCheckbox.isSelected() ? fontSize : -1); updatePreview(); }
public static void generatePushFont(final GeneratorAdapter generator, final int componentLocal, final LwComponent lwComponent, final FontDescriptor descriptor, final String readMethodName) { final int fontLocal = generator.newLocal(ourFontType); generator.loadLocal(componentLocal); Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); Method getFontMethod = new Method(readMethodName, ourFontType, new Type[0] ); generator.invokeVirtual(componentType, getFontMethod); generator.storeLocal(fontLocal); generator.newInstance(ourFontType); generator.dup(); if (descriptor.getFontName() != null) { generator.push(descriptor.getFontName()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetNameMethod); } if (descriptor.getFontStyle() >= 0) { generator.push(descriptor.getFontStyle()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetStyleMethod); } if (descriptor.getFontSize() >= 0) { generator.push(descriptor.getFontSize()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetSizeMethod); } generator.invokeConstructor(ourFontType, ourInitMethod); }
public static void generatePushFont(final GeneratorAdapter generator, final int componentLocal, final LwComponent lwComponent, final FontDescriptor descriptor, final String readMethodName, Label fontNullLabel) { final int fontLocal = generator.newLocal(ourFontType); generator.loadLocal(componentLocal); Type componentType = AsmCodeGenerator.typeFromClassName(lwComponent.getComponentClassName()); Method getFontMethod = new Method(readMethodName, ourFontType, new Type[0] ); generator.invokeVirtual(componentType, getFontMethod); generator.storeLocal(fontLocal); if (fontNullLabel != null) { generator.loadLocal(fontLocal); generator.ifNull(fontNullLabel); generator.loadLocal(componentLocal); } generator.newInstance(ourFontType); generator.dup(); if (descriptor.getFontName() != null) { generator.push(descriptor.getFontName()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetNameMethod); } if (descriptor.getFontStyle() >= 0) { generator.push(descriptor.getFontStyle()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetStyleMethod); } if (descriptor.getFontSize() >= 0) { generator.push(descriptor.getFontSize()); } else { generator.loadLocal(fontLocal); generator.invokeVirtual(ourFontType, ourGetSizeMethod); } generator.invokeConstructor(ourFontType, ourInitMethod); }
public void write(@NotNull FontDescriptor value, XmlWriter writer) { writer.writeFontDescriptor(value); }
@NotNull public PropertyRenderer<FontDescriptor> getRenderer() { return myFontRenderer; }
public FontDescriptor getValue(final RadContainer component) { return component.getBorderTitleFont(); }
protected void setValueImpl(final RadContainer component, final FontDescriptor value) throws Exception { component.setBorderTitleFont(value); }
protected void customize(FontDescriptor value) { setText(IntroFontProperty.descriptorToString(value)); }
public FontDescriptor getValue() { return myValue; }
public FontDescriptor getValue() throws Exception { return myValue; }
public JComponent getComponent(RadComponent component, FontDescriptor value, InplaceContext inplaceContext) { myProject = component.getProject(); myValue = value != null ? value : new FontDescriptor(null, -1, -1); myTextField.setText(IntroFontProperty.descriptorToString(myValue)); return myTextField; }