use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.
the class RadComponent method initDefaultProperties.
public void initDefaultProperties(@NotNull final ComponentItem item) {
final IntrospectedProperty[] properties = getPalette().getIntrospectedProperties(this);
for (final IntrospectedProperty property : properties) {
final Object initialValue = item.getInitialValue(property);
if (initialValue != null) {
try {
//noinspection unchecked
property.setValue(this, initialValue);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
myConstraints.restore(item.getDefaultConstraints());
}
use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.
the class RadComponent method getModifiedProperties.
public IProperty[] getModifiedProperties() {
IntrospectedProperty[] props = getPalette().getIntrospectedProperties(this);
ArrayList<IProperty> result = new ArrayList<>();
for (IntrospectedProperty prop : props) {
if (isMarkedAsModified(prop)) {
result.add(prop);
}
}
return result.toArray(new IProperty[result.size()]);
}
use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.
the class RadComponent method createSnapshotComponent.
@Nullable
public static RadComponent createSnapshotComponent(final SnapshotContext context, final JComponent component) {
String id = context.newId();
RadComponent result;
Class componentClass = component.getClass();
if (componentClass.isAnonymousClass()) {
componentClass = componentClass.getSuperclass();
}
if (component instanceof JPanel && !isCompositeComponent(component)) {
RadContainer container = new RadContainer(componentClass, id, context.getPalette());
final RadLayoutManager manager = LayoutManagerRegistry.createFromLayout(component.getLayout());
if (manager == null) {
return null;
}
container.setLayoutManager(manager);
result = container;
} else if (component instanceof Box.Filler) {
Box.Filler filler = (Box.Filler) component;
if (filler.getMaximumSize().height == Short.MAX_VALUE) {
result = new RadVSpacer(null, id);
result.getConstraints().setVSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
} else {
result = new RadHSpacer(null, id);
result.getConstraints().setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
}
} else {
final RadComponentFactory factory = InsertComponentProcessor.getRadComponentFactory(componentClass);
if (factory == null) {
result = new RadAtomicComponent(componentClass, id, context.getPalette());
} else {
result = factory.newInstance(componentClass, id, context.getPalette());
}
}
context.registerComponent(component, result);
result.importSnapshotComponent(context, component);
final IntrospectedProperty[] properties = context.getPalette().getIntrospectedProperties(component.getClass(), result.getDelegee().getClass());
for (IntrospectedProperty prop : properties) {
if (component instanceof AbstractButton) {
AbstractButton btn = (AbstractButton) component;
if (prop.getName().equals(SwingProperties.LABEL) && btn.getLabel().equals(btn.getText())) {
continue;
}
if (prop.getName().equals(SwingProperties.ACTION_COMMAND) && btn.getActionCommand().equals(btn.getText())) {
continue;
}
}
prop.importSnapshotValue(context, component, result);
}
if (component instanceof AbstractButton) {
AbstractButton btn = (AbstractButton) component;
if (btn.getModel() instanceof DefaultButtonModel) {
DefaultButtonModel model = (DefaultButtonModel) btn.getModel();
if (model.getGroup() != null) {
context.registerButtonGroup(model.getGroup());
}
}
}
return result;
}
use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.
the class RadComponent method writeProperties.
protected final void writeProperties(final XmlWriter writer) {
writer.startElement(UIFormXmlConstants.ELEMENT_PROPERTIES);
try {
final IntrospectedProperty[] introspectedProperties = getPalette().getIntrospectedProperties(this);
for (final IntrospectedProperty property : introspectedProperties) {
if (isMarkedAsModified(property)) {
final Object value = property.getValue(this);
if (value != null) {
writer.startElement(property.getName());
try {
//noinspection unchecked
property.write(value, writer);
} finally {
writer.endElement();
}
}
}
}
} finally {
// properties
writer.endElement();
}
writeClientProperties(writer);
}
use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.
the class XmlReader method createComponent.
@NotNull
public static RadComponent createComponent(@NotNull final ModuleProvider module, @NotNull final LwComponent lwComponent, @NotNull final ClassLoader loader, final Locale stringDescriptorLocale) throws Exception {
// Id
final String id = lwComponent.getId();
final RadComponent component;
Class componentClass = null;
if (lwComponent instanceof LwNestedForm) {
LwNestedForm nestedForm = (LwNestedForm) lwComponent;
boolean recursiveNesting = false;
try {
Utils.validateNestedFormLoop(nestedForm.getFormFileName(), new PsiNestedFormLoader(module.getModule()));
} catch (RecursiveFormNestingException ex) {
recursiveNesting = true;
}
if (recursiveNesting) {
component = RadErrorComponent.create(module, id, lwComponent.getComponentClassName(), lwComponent.getErrorComponentProperties(), UIDesignerBundle.message("error.recursive.form.nesting"));
} else {
component = new RadNestedForm(module, nestedForm.getFormFileName(), id);
}
} else {
if (lwComponent.getErrorComponentProperties() == null) {
componentClass = Class.forName(lwComponent.getComponentClassName(), true, loader);
}
if (lwComponent instanceof LwHSpacer) {
component = new RadHSpacer(module, id);
} else if (lwComponent instanceof LwVSpacer) {
component = new RadVSpacer(module, id);
} else if (lwComponent instanceof LwAtomicComponent) {
if (componentClass == null) {
component = createErrorComponent(module, id, lwComponent, loader);
} else {
RadComponent component1;
try {
if (JTable.class.isAssignableFrom(componentClass)) {
component1 = new RadTable(module, componentClass, id);
} else {
component1 = new RadAtomicComponent(module, componentClass, id);
}
} catch (final Exception exc) {
String errorDescription = MessageFormat.format(UIDesignerBundle.message("error.class.cannot.be.instantiated"), lwComponent.getComponentClassName());
final String message = FormEditingUtil.getExceptionMessage(exc);
if (message != null) {
errorDescription += ": " + message;
}
component1 = RadErrorComponent.create(module, id, lwComponent.getComponentClassName(), lwComponent.getErrorComponentProperties(), errorDescription);
}
component = component1;
}
} else if (lwComponent instanceof LwScrollPane) {
component = new RadScrollPane(module, componentClass, id);
} else if (lwComponent instanceof LwTabbedPane) {
component = new RadTabbedPane(module, componentClass, id);
} else if (lwComponent instanceof LwSplitPane) {
component = new RadSplitPane(module, componentClass, id);
} else if (lwComponent instanceof LwToolBar) {
component = new RadToolBar(module, componentClass, id);
} else if (lwComponent instanceof LwContainer) {
final LwContainer lwContainer = (LwContainer) lwComponent;
LayoutManager layout = lwContainer.getLayout();
if (layout instanceof XYLayoutManager) {
// replace stub layout with the real one
final XYLayoutManagerImpl xyLayoutManager = new XYLayoutManagerImpl();
layout = xyLayoutManager;
xyLayoutManager.setPreferredSize(lwComponent.getBounds().getSize());
}
if (componentClass == null) {
component = createErrorComponent(module, id, lwComponent, loader);
} else {
if (lwContainer instanceof LwRootContainer) {
component = new RadRootContainer(module, id);
if (stringDescriptorLocale != null) {
((RadRootContainer) component).setStringDescriptorLocale(stringDescriptorLocale);
}
} else {
component = new RadContainer(module, componentClass, id);
String layoutManagerName = lwContainer.getLayoutManager();
if (layoutManagerName == null || layoutManagerName.length() == 0) {
if (layout instanceof XYLayoutManager) {
layoutManagerName = UIFormXmlConstants.LAYOUT_XY;
} else {
layoutManagerName = UIFormXmlConstants.LAYOUT_INTELLIJ;
}
}
RadLayoutManager layoutManager = LayoutManagerRegistry.createLayoutManager(layoutManagerName);
RadContainer container = (RadContainer) component;
layoutManager.readLayout(lwContainer, container);
container.setLayoutManager(layoutManager);
}
((RadContainer) component).setLayout(layout);
}
} else {
throw new IllegalArgumentException("unexpected component: " + lwComponent);
}
}
// binding
component.setBinding(lwComponent.getBinding());
component.setCustomCreate(lwComponent.isCustomCreate());
component.setDefaultBinding(lwComponent.isDefaultBinding());
// bounds
component.setBounds(lwComponent.getBounds());
// properties
if (stringDescriptorLocale != null) {
component.putClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE, stringDescriptorLocale);
}
final LwIntrospectedProperty[] properties = lwComponent.getAssignedIntrospectedProperties();
if (componentClass != null) {
final Palette palette = Palette.getInstance(module.getProject());
for (final LwIntrospectedProperty lwProperty : properties) {
final IntrospectedProperty property = palette.getIntrospectedProperty(component, lwProperty.getName());
if (property == null) {
continue;
}
component.loadLwProperty(lwComponent, lwProperty, property);
}
}
// GridConstraints
component.getConstraints().restore(lwComponent.getConstraints());
component.setCustomLayoutConstraints(lwComponent.getCustomLayoutConstraints());
HashMap clientProps = lwComponent.getDelegeeClientProperties();
for (Object o : clientProps.entrySet()) {
Map.Entry entry = (Map.Entry) o;
Object value = entry.getValue();
if (value instanceof StringDescriptor) {
value = ((StringDescriptor) value).getValue();
}
component.getDelegee().putClientProperty(entry.getKey(), value);
}
if (component instanceof RadContainer) {
final RadContainer container = (RadContainer) component;
//noinspection ConstantConditions
final LwContainer lwContainer = (LwContainer) lwComponent;
copyBorder(container, lwContainer);
// add children
for (int i = 0; i < lwContainer.getComponentCount(); i++) {
container.addComponent(createComponent(module, (LwComponent) lwContainer.getComponent(i), loader, stringDescriptorLocale));
}
}
if (component instanceof RadRootContainer) {
final RadRootContainer radRootContainer = (RadRootContainer) component;
//noinspection ConstantConditions
final LwRootContainer lwRootContainer = (LwRootContainer) lwComponent;
radRootContainer.setClassToBind(lwRootContainer.getClassToBind());
radRootContainer.setMainComponentBinding(lwRootContainer.getMainComponentBinding());
radRootContainer.setButtonGroups(lwRootContainer.getButtonGroups());
radRootContainer.setInspectionSuppressions(lwRootContainer.getInspectionSuppressions());
radRootContainer.getDelegee().setBackground(new JBColor(Color.WHITE, UIUtil.getListBackground()));
}
component.doneLoadingFromLw();
component.putClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE, null);
return component;
}
Aggregations