public void generatePushValue(final GeneratorAdapter generator, final Object value) { IconDescriptor descriptor = (IconDescriptor) value; generator.newInstance(ourImageIconType); generator.dup(); generator.loadThis(); generator.invokeVirtual(ourObjectType, ourGetClassMethod); generator.push("/" + descriptor.getIconPath()); generator.invokeVirtual(ourClassType, ourGetResourceMethod); generator.invokeConstructor(ourImageIconType, ourInitMethod); }
@Override protected void setValueImpl(final RadComponent component, final IconDescriptor value) throws Exception { component.getDelegee().putClientProperty(CLIENT_PROPERTY_KEY_PREFIX + getName(), value); if (value != null) { ensureIconLoaded(component.getModule(), value); invokeSetter(component, value.getIcon()); } else { invokeSetter(component, null); } }
public static void ensureIconLoaded(final Module module, final IconDescriptor value) { if (value.getIcon() == null) { VirtualFile iconFile = ResourceFileUtil.findResourceFileInScope(value.getIconPath(), module.getProject(), module.getModuleWithDependenciesAndLibrariesScope(true)); if (iconFile != null) { loadIconFromFile(iconFile, value); } } }
public static void loadIconFromFile(final VirtualFile virtualFile, final IconDescriptor descriptor) { if (virtualFile != null) { try { descriptor.setIcon(new ImageIcon(virtualFile.contentsToByteArray())); } catch (Exception e1) { descriptor.setIcon(null); } } }
@Override public JLabel getComponent(final RadRootContainer rootContainer, final IconDescriptor iconDescriptor, final boolean selected, final boolean hasFocus) { if (iconDescriptor != null) { IntroIconProperty.ensureIconLoaded(rootContainer.getModule(), iconDescriptor); } final JLabel component = super.getComponent(rootContainer, iconDescriptor, selected, hasFocus); if (!selected && iconDescriptor != null && iconDescriptor.getIcon() == null) { setForeground(Color.RED); } return component; }
public IconEditor() { myTextField.getTextField().setBorder(null); myTextField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { final TreeClassChooserFactory factory = TreeClassChooserFactory.getInstance(getModule().getProject()); PsiFile iconFile = null; if (myValue != null) { VirtualFile iconVFile = ResourceFileUtil.findResourceFileInScope(myValue.getIconPath(), getModule().getProject(), getModule() .getModuleWithDependenciesAndLibrariesScope(true)); if (iconVFile != null) { iconFile = PsiManager.getInstance(getModule().getProject()).findFile(iconVFile); } } TreeFileChooser fileChooser = factory.createFileChooser(UIDesignerBundle.message("title.choose.icon.file"), iconFile, null, new ImageFileFilter(getModule()), false, true); fileChooser.showDialog(); PsiFile file = fileChooser.getSelectedFile(); if (file != null) { String resourceName = FormEditingUtil.buildResourceName(file); if (resourceName != null) { IconDescriptor descriptor = new IconDescriptor(resourceName); IntroIconProperty.loadIconFromFile(file.getVirtualFile(), descriptor); myValue = descriptor; myTextField.setText(descriptor.getIconPath()); } } } }); }
public IconDescriptor getValue() throws Exception { if (myTextField.getText().length() == 0) { return null; } final IconDescriptor descriptor = new IconDescriptor(myTextField.getText()); IntroIconProperty.ensureIconLoaded(getModule(), descriptor); return descriptor; }
public JComponent getComponent(RadComponent component, IconDescriptor value, InplaceContext inplaceContext) { myValue = value; myComponent = component; if (myValue != null) { myTextField.setText(myValue.getIconPath()); } else { myTextField.setText(""); } return myTextField; }
public void write(@NotNull IconDescriptor value, XmlWriter writer) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VALUE, value.getIconPath()); }
@NotNull public PropertyRenderer<IconDescriptor> getRenderer() { return myRenderer; }
@Override public IconDescriptor getValue(final RadComponent component) { return (IconDescriptor)component.getDelegee().getClientProperty(CLIENT_PROPERTY_KEY_PREFIX + getName()); }
protected void customize(@NotNull IconDescriptor value) { setIcon(value.getIcon()); setText(value.getIconPath()); }