void readChildConstraints(final Element constraintsElement, final LwComponent component) { super.readChildConstraints(constraintsElement, component); GridBagConstraints gbc = new GridBagConstraints(); GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc); final Element gridBagElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_GRIDBAG); if (gridBagElement != null) { if (gridBagElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) { gbc.insets = LwXmlReader.readInsets(gridBagElement); } gbc.weightx = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTX, 0.0); gbc.weighty = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTY, 0.0); gbc.ipadx = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADX, 0); gbc.ipady = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADY, 0); } component.setCustomLayoutConstraints(gbc); }
private void createLayoutSerializer() { if (UIFormXmlConstants.LAYOUT_BORDER.equals(myLayoutManager)) { myLayoutSerializer = BorderLayoutSerializer.INSTANCE; } else if (UIFormXmlConstants.LAYOUT_FLOW.equals(myLayoutManager)) { myLayoutSerializer = FlowLayoutSerializer.INSTANCE; } else if (UIFormXmlConstants.LAYOUT_CARD.equals(myLayoutManager)) { myLayoutSerializer = CardLayoutSerializer.INSTANCE; } else if (UIFormXmlConstants.LAYOUT_XY.equals(myLayoutManager)) { myLayoutSerializer = XYLayoutSerializer.INSTANCE; } else if (UIFormXmlConstants.LAYOUT_FORM.equals(myLayoutManager)) { myLayoutSerializer = FormLayoutSerializer.INSTANCE; } else if (UIFormXmlConstants.LAYOUT_GRIDBAG.equals(myLayoutManager)) { myLayoutSerializer = GridBagLayoutSerializer.INSTANCE; } else { myLayoutSerializer = GridLayoutSerializer.INSTANCE; } }
void readChildConstraints(final Element constraintsElement, final LwComponent component) { super.readChildConstraints(constraintsElement, component); CellConstraints cc = new CellConstraints(); final Element formsElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_FORMS); if (formsElement != null) { if (formsElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) { cc.insets = LwXmlReader.readInsets(formsElement); } if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_HORZ, true)) { cc.hAlign = ourHorizontalAlignments [Utils.alignFromConstraints(component.getConstraints(), true)]; } if (!LwXmlReader.getOptionalBoolean(formsElement, UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_VERT, true)) { cc.vAlign = ourVerticalAlignments [Utils.alignFromConstraints(component.getConstraints(), false)]; } } component.setCustomLayoutConstraints(cc); }
void readLayout(Element element, LwContainer container) { final int rowCount = LwXmlReader.getRequiredInt(element, UIFormXmlConstants.ATTRIBUTE_ROW_COUNT); final int columnCount = LwXmlReader.getRequiredInt(element, UIFormXmlConstants.ATTRIBUTE_COLUMN_COUNT); final int hGap = LwXmlReader.getOptionalInt(element, UIFormXmlConstants.ATTRIBUTE_HGAP, -1); final int vGap = LwXmlReader.getOptionalInt(element, UIFormXmlConstants.ATTRIBUTE_VGAP, -1); // attribute is optional for compatibility with IDEA 4.0 forms final boolean sameSizeHorizontally = LwXmlReader.getOptionalBoolean(element, UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_HORIZONTALLY, false); final boolean sameSizeVertically = LwXmlReader.getOptionalBoolean(element, UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_VERTICALLY, false); final Element marginElement = LwXmlReader.getRequiredChild(element, "margin"); final Insets margin = new Insets( LwXmlReader.getRequiredInt(marginElement,"top"), LwXmlReader.getRequiredInt(marginElement,"left"), LwXmlReader.getRequiredInt(marginElement,"bottom"), LwXmlReader.getRequiredInt(marginElement,"right") ); final GridLayoutManager layout = new GridLayoutManager(rowCount, columnCount); layout.setMargin(margin); layout.setVGap(vGap); layout.setHGap(hGap); layout.setSameSizeHorizontally(sameSizeHorizontally); layout.setSameSizeVertically(sameSizeVertically); container.setLayout(layout); }
public static StringDescriptor getStringDescriptor(final Element element, final String valueAttr, final String bundleAttr, final String keyAttr) { final String title = element.getAttributeValue(valueAttr); if (title != null) { StringDescriptor descriptor = StringDescriptor.create(title); descriptor.setNoI18n(getOptionalBoolean(element, UIFormXmlConstants.ATTRIBUTE_NOI18N, false)); return descriptor; } else { final String bundle = element.getAttributeValue(bundleAttr); if (bundle != null) { final String key = getRequiredString(element, keyAttr); return new StringDescriptor(bundle, key); } } return null; }
public static ColorDescriptor getColorDescriptor(final Element element) throws Exception { Attribute attr = element.getAttribute(UIFormXmlConstants.ATTRIBUTE_COLOR); if (attr != null) { return new ColorDescriptor(new Color(attr.getIntValue())); } String swingColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_SWING_COLOR); if (swingColor != null) { return ColorDescriptor.fromSwingColor(swingColor); } String systemColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_SYSTEM_COLOR); if (systemColor != null) { return ColorDescriptor.fromSystemColor(systemColor); } String awtColor = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_AWT_COLOR); if (awtColor != null) { return ColorDescriptor.fromAWTColor(awtColor); } return new ColorDescriptor(null); }
private LayoutCodeGenerator getComponentCodeGenerator(final LwContainer container) { LayoutCodeGenerator generator = (LayoutCodeGenerator) myComponentLayoutCodeGenerators.get(container.getClass()); if (generator != null) { return generator; } LwContainer parent = container; while(parent != null) { final String layoutManager = parent.getLayoutManager(); if (layoutManager != null && layoutManager.length() > 0) { if (layoutManager.equals(UIFormXmlConstants.LAYOUT_FORM) && !myContainerLayoutCodeGenerators.containsKey(UIFormXmlConstants.LAYOUT_FORM)) { myContainerLayoutCodeGenerators.put(UIFormXmlConstants.LAYOUT_FORM, new FormLayoutCodeGenerator()); } generator = (LayoutCodeGenerator) myContainerLayoutCodeGenerators.get(layoutManager); if (generator != null) { return generator; } } parent = parent.getParent(); } return GridLayoutCodeGenerator.INSTANCE; }
public void generateComponentLayout(LwComponent lwComponent, GeneratorAdapter generator, int componentLocal, int parentLocal) { super.generateComponentLayout(lwComponent, generator, componentLocal, parentLocal); String defaultCard = (String)lwComponent.getParent().getClientProperty(UIFormXmlConstants.LAYOUT_CARD); if (lwComponent.getId().equals(defaultCard)) { generator.loadLocal(parentLocal); generator.invokeVirtual(ourContainerType, ourGetLayoutMethod); generator.checkCast(myLayoutType); generator.loadLocal(parentLocal); generator.push((String) lwComponent.getCustomLayoutConstraints()); generator.invokeVirtual(myLayoutType, ourShowMethod); } }
@Override public void writeLayout(final XmlWriter writer, final RadContainer radContainer) { FormLayout layout = (FormLayout) radContainer.getLayout(); for(int i=1; i<=layout.getRowCount(); i++) { RowSpec rowSpec = layout.getRowSpec(i); writer.startElement(UIFormXmlConstants.ELEMENT_ROWSPEC); try { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VALUE, FormLayoutUtils.getEncodedSpec(rowSpec)); } finally { writer.endElement(); } } for(int i=1; i<=layout.getColumnCount(); i++) { ColumnSpec columnSpec = layout.getColumnSpec(i); writer.startElement(UIFormXmlConstants.ELEMENT_COLSPEC); try { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VALUE, FormLayoutUtils.getEncodedSpec(columnSpec)); } finally { writer.endElement(); } } writeGroups(writer, UIFormXmlConstants.ELEMENT_ROWGROUP, layout.getRowGroups()); writeGroups(writer, UIFormXmlConstants.ELEMENT_COLGROUP, layout.getColumnGroups()); }
@Override public void writeChildConstraints(final XmlWriter writer, final RadComponent child) { writeGridConstraints(writer, child); if (child.getCustomLayoutConstraints() instanceof CellConstraints) { CellConstraints cc = (CellConstraints) child.getCustomLayoutConstraints(); writer.startElement(UIFormXmlConstants.ELEMENT_FORMS); try { if (!cc.insets.equals(new Insets(0, 0, 0, 0))) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_TOP, cc.insets.top); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_LEFT, cc.insets.left); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_BOTTOM, cc.insets.bottom); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_RIGHT, cc.insets.right); } if (cc.hAlign != CellConstraints.DEFAULT) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_HORZ, false); } if (cc.vAlign != CellConstraints.DEFAULT) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_DEFAULTALIGN_VERT, false); } } finally { writer.endElement(); } } }
public void writeChildConstraints(final XmlWriter writer, final RadComponent child) { writeGridConstraints(writer, child); if (child.getCustomLayoutConstraints() instanceof GridBagConstraints) { GridBagConstraints gbc = (GridBagConstraints)child.getCustomLayoutConstraints(); writer.startElement(UIFormXmlConstants.ELEMENT_GRIDBAG); try { if (!gbc.insets.equals(new Insets(0, 0, 0, 0))) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_TOP, gbc.insets.top); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_LEFT, gbc.insets.left); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_BOTTOM, gbc.insets.bottom); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_RIGHT, gbc.insets.right); } writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_WEIGHTX, gbc.weightx); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_WEIGHTY, gbc.weighty); if (gbc.ipadx != 0) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_IPADX, gbc.ipadx); } if (gbc.ipady != 0) { writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_IPADY, gbc.ipady); } } finally { writer.endElement(); } } }
public void write(final XmlWriter writer) { writer.startElement(UIFormXmlConstants.ELEMENT_SPLITPANE); try { writeId(writer); writeClassIfDifferent(writer, JSplitPane.class.getName()); writeBinding(writer); // Constraints and properties writeConstraints(writer); writeProperties(writer); // Margin and border writeBorder(writer); writeChildren(writer); } finally { writer.endElement(); // scrollpane } }
public void write(final XmlWriter writer) { writer.startElement("form", Utils.FORM_NAMESPACE); try{ writer.addAttribute("version", 1); final String classToBind = getClassToBind(); if (classToBind != null){ writer.addAttribute("bind-to-class", classToBind); } final String mainComponentBinding = getMainComponentBinding(); if (mainComponentBinding != null) { writer.addAttribute("stored-main-component-binding", mainComponentBinding); } writeChildrenImpl(writer); if (myButtonGroups.size() > 0) { writer.startElement(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS); for(RadButtonGroup group: myButtonGroups) { group.write(writer); } writer.endElement(); } writeInspectionSuppressions(writer); } finally{ writer.endElement(); // form } }
public void writeLayout(final XmlWriter writer, final RadContainer radContainer) { final AbstractLayout layout = (AbstractLayout)radContainer.getLayout(); // It has sense to save hpap and vgap even for XY layout. The reason is // that XY was previously GRID with non default gaps, so when the user // compose XY into the grid again then he will get the same non default gaps. writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_HGAP, layout.getHGap()); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_VGAP, layout.getVGap()); // Margins final Insets margin = layout.getMargin(); writer.startElement("margin"); try { writer.writeInsets(margin); } finally { writer.endElement(); // margin } }
protected static void writeGridConstraints(final XmlWriter writer, final RadComponent child) { // Constraints in Grid layout writer.startElement("grid"); try { final GridConstraints constraints = child.getConstraints(); writer.addAttribute("row",constraints.getRow()); writer.addAttribute("column",constraints.getColumn()); writer.addAttribute("row-span",constraints.getRowSpan()); writer.addAttribute("col-span",constraints.getColSpan()); writer.addAttribute("vsize-policy",constraints.getVSizePolicy()); writer.addAttribute("hsize-policy",constraints.getHSizePolicy()); writer.addAttribute("anchor",constraints.getAnchor()); writer.addAttribute("fill",constraints.getFill()); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_INDENT, constraints.getIndent()); writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_USE_PARENT_LAYOUT, constraints.isUseParentLayout()); // preferred size writer.writeDimension(constraints.myMinimumSize,"minimum-size"); writer.writeDimension(constraints.myPreferredSize,"preferred-size"); writer.writeDimension(constraints.myMaximumSize,"maximum-size"); } finally { writer.endElement(); // grid } }
protected void readConstraintsForChild(final Element element, final LwComponent component) { final Element constraintsElement = LwXmlReader.getRequiredChild(element, UIFormXmlConstants.ELEMENT_CONSTRAINTS); final Element tabbedPaneChild = LwXmlReader.getRequiredChild(constraintsElement, UIFormXmlConstants.ELEMENT_TABBEDPANE); final StringDescriptor descriptor = LwXmlReader.getStringDescriptor(tabbedPaneChild, UIFormXmlConstants.ATTRIBUTE_TITLE, UIFormXmlConstants.ATTRIBUTE_TITLE_RESOURCE_BUNDLE, UIFormXmlConstants.ATTRIBUTE_TITLE_KEY); if (descriptor == null) { throw new IllegalArgumentException("String descriptor value required"); } final Constraints constraints = new Constraints(descriptor); final Element tooltipElement = LwXmlReader.getChild(tabbedPaneChild, UIFormXmlConstants.ELEMENT_TOOLTIP); if (tooltipElement != null) { constraints.myToolTip = LwXmlReader.getStringDescriptor(tooltipElement, UIFormXmlConstants.ATTRIBUTE_VALUE, UIFormXmlConstants.ATTRIBUTE_RESOURCE_BUNDLE, UIFormXmlConstants.ATTRIBUTE_KEY); } String icon = tabbedPaneChild.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_ICON); if (icon != null) { constraints.myIcon = new IconDescriptor(icon); } icon = tabbedPaneChild.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_DISABLED_ICON); if (icon != null) { constraints.myDisabledIcon = new IconDescriptor(icon); } constraints.myEnabled = LwXmlReader.getOptionalBoolean(tabbedPaneChild, UIFormXmlConstants.ATTRIBUTE_ENABLED, true); component.setCustomLayoutConstraints(constraints); }
/** * 'id' is required attribute * 'binding' is optional attribute */ protected final void readBase(final Element element) { setId(LwXmlReader.getRequiredString(element, UIFormXmlConstants.ATTRIBUTE_ID)); setBinding(element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_BINDING)); myCustomCreate = LwXmlReader.getOptionalBoolean(element, UIFormXmlConstants.ATTRIBUTE_CUSTOM_CREATE, false); myDefaultBinding = LwXmlReader.getOptionalBoolean(element, UIFormXmlConstants.ATTRIBUTE_DEFAULT_BINDING, false); }
/** * 'properties' is not required subtag * @param provider can be null if no properties should be read */ protected final void readProperties(final Element element, final PropertiesProvider provider) { if (provider == null) { // do not read properties return; } Element propertiesElement = LwXmlReader.getChild(element, UIFormXmlConstants.ELEMENT_PROPERTIES); if(propertiesElement == null){ propertiesElement = new Element(UIFormXmlConstants.ELEMENT_PROPERTIES, element.getNamespace()); } final HashMap name2property = provider.getLwProperties(getComponentClassName()); if (name2property == null) { myErrorComponentProperties = (Element)propertiesElement.clone(); return; } final List propertyElements = propertiesElement.getChildren(); for (int i = 0; i < propertyElements.size(); i++) { final Element t = (Element)propertyElements.get(i); final String name = t.getName(); final LwIntrospectedProperty property = (LwIntrospectedProperty)name2property.get(name); if (property == null){ continue; } try { final Object value = property.read(t); setPropertyValue(property, value); } catch (final Exception exc) { // Skip non readable properties } } readClientProperties(element); }
public void read(final Element element, final PropertiesProvider provider) throws Exception { if (element == null) { throw new IllegalArgumentException("element cannot be null"); } if (!Utils.FORM_NAMESPACE.equals(element.getNamespace().getURI())) { throw new AlienFormFileException(); } if(!"form".equals(element.getName())){ throw new UnexpectedFormElementException("unexpected element: "+element); } setId("root"); myClassToBind = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS); // Constraints and properties for(Iterator i=element.getChildren().iterator(); i.hasNext();){ final Element child = (Element)i.next(); if (child.getName().equals(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS)) { readButtonGroups(child); } else if (child.getName().equals(UIFormXmlConstants.ELEMENT_INSPECTION_SUPPRESSIONS)) { readInspectionSuppressions(child); } else { final LwComponent component = createComponentFromTag(child); addComponent(component); component.read(child, provider); } } myMainComponentBinding = element.getAttributeValue("stored-main-component-binding"); }