Example usage for com.jgoodies.forms.layout FormLayout getColumnSpec

List of usage examples for com.jgoodies.forms.layout FormLayout getColumnSpec

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout FormLayout getColumnSpec.

Prototype

public ColumnSpec getColumnSpec(int columnIndex) 

Source Link

Document

Returns the ColumnSpec at the specified column index.

Usage

From source file:com.intellij.uiDesigner.compiler.FormLayoutUtils.java

License:Apache License

public static String getEncodedColumnSpecs(final FormLayout formLayout) {
    StringBuffer result = new StringBuffer();
    for (int i = 1; i <= formLayout.getColumnCount(); i++) {
        if (result.length() > 0) {
            result.append(",");
        }/*from   www .ja va 2  s .  c  o  m*/
        result.append(getEncodedSpec(formLayout.getColumnSpec(i)));
    }
    return result.toString();
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

@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 {//  w ww  . j  a  v  a2  s. c  o  m
            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());
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

@Override
public boolean canCellGrow(RadContainer container, boolean isRow, int index) {
    FormLayout layout = (FormLayout) container.getLayout();
    FormSpec spec = isRow ? layout.getRowSpec(index + 1) : layout.getColumnSpec(index + 1);
    return spec.getResizeWeight() > 0.01d;
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

private static void copyFormSpecs(final FormLayout sourceLayout, final FormLayout destinationLayout,
        final boolean isRow, int cellIndex, int cellCount, int targetIndex) {
    for (int i = 0; i < cellCount; i++) {
        if (isRow) {
            RowSpec rowSpec = sourceLayout.getRowSpec(cellIndex + 1);
            insertOrAppendRow(destinationLayout, targetIndex + 1, rowSpec);
        } else {/*  w w  w .ja  v  a  2s  . c  o m*/
            ColumnSpec colSpec = sourceLayout.getColumnSpec(cellIndex + 1);
            insertOrAppendColumn(destinationLayout, targetIndex + 1, colSpec);
        }
        cellIndex += (targetIndex < cellIndex && sourceLayout == destinationLayout) ? 2 : 1;
        targetIndex++;
    }
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

@Override
public void processCellResized(RadContainer container, final boolean isRow, final int cell, final int newSize) {
    FormLayout formLayout = (FormLayout) container.getLayout();
    final ConstantSize updatedSize = getUpdatedSize(container, isRow, cell, newSize);
    FormSpec newSpec;//from   ww w .  java  2 s.c  o m
    if (isRow) {
        RowSpec rowSpec = formLayout.getRowSpec(cell + 1);
        newSpec = new RowSpec(rowSpec.getDefaultAlignment(), updatedSize, rowSpec.getResizeWeight());
    } else {
        ColumnSpec colSpec = formLayout.getColumnSpec(cell + 1);
        newSpec = new ColumnSpec(colSpec.getDefaultAlignment(), updatedSize, colSpec.getResizeWeight());
    }
    setSpec(formLayout, newSpec, cell + 1, isRow);
    resizeSameGroupCells(cell, formLayout, newSpec, isRow);
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

private static ConstantSize getUpdatedSize(RadContainer container, boolean isRow, int cell, int newPx) {
    FormLayout formLayout = (FormLayout) container.getLayout();
    if (isRow) {/*from  w  w w.  j av a  2 s. c om*/
        return scaleSize(formLayout.getRowSpec(cell + 1), container, newPx);
    } else {
        return scaleSize(formLayout.getColumnSpec(cell + 1), container, newPx);
    }
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

private void moveCells(final RadContainer container, final boolean isRow, final int cell, int targetCell) {
    if (targetCell >= cell && targetCell <= cell + 2) {
        return;/*  www .  j  a  va  2  s .  c  o m*/
    }
    FormLayout layout = (FormLayout) container.getLayout();
    List<RadComponent> componentsToMove = new ArrayList<RadComponent>();
    FormSpec oldSpec = isRow ? layout.getRowSpec(cell + 1) : layout.getColumnSpec(cell + 1);
    for (RadComponent c : container.getComponents()) {
        if (c.getConstraints().getCell(isRow) == cell) {
            componentsToMove.add(c);
            container.removeComponent(c);
        }
    }
    int count = deleteGridCells(container, cell, isRow);
    int insertCell = (targetCell > cell) ? targetCell - count - 1 : targetCell;
    final boolean isBefore = targetCell < cell;
    int newIndex = insertGridCells(container, insertCell, isRow, isBefore, oldSpec);
    for (RadComponent c : componentsToMove) {
        c.getConstraints().setCell(isRow, newIndex);
        container.addComponent(c);
    }
}

From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java

License:Apache License

public int getAlignment(RadComponent component, boolean horizontal) {
    CellConstraints cc = (CellConstraints) component.getCustomLayoutConstraints();
    CellConstraints.Alignment al = horizontal ? cc.hAlign : cc.vAlign;
    if (al == CellConstraints.DEFAULT) {
        FormLayout formLayout = (FormLayout) component.getParent().getLayout();
        FormSpec formSpec = horizontal ? formLayout.getColumnSpec(component.getConstraints().getColumn() + 1)
                : formLayout.getRowSpec(component.getConstraints().getRow() + 1);
        final FormSpec.DefaultAlignment defaultAlignment = formSpec.getDefaultAlignment();
        if (defaultAlignment.equals(RowSpec.FILL)) {
            return GridConstraints.ALIGN_FILL;
        }/*from   w w w . j a  v a  2  s  .com*/
        if (defaultAlignment.equals(RowSpec.TOP) || defaultAlignment.equals(ColumnSpec.LEFT)) {
            return GridConstraints.ALIGN_LEFT;
        }
        if (defaultAlignment.equals(RowSpec.CENTER)) {
            return GridConstraints.ALIGN_CENTER;
        }
        return GridConstraints.ALIGN_RIGHT;
    }
    return Utils.alignFromConstraints(component.getConstraints(), horizontal);
}

From source file:com.jeta.swingbuilder.codegen.builder.PanelWriter.java

License:Open Source License

public MethodWriter createPanel(DeclarationManager decl_mgr, FormMemento fm) {
    decl_mgr.addImport("javax.swing.JPanel");
    decl_mgr.addImport("com.jgoodies.forms.layout.CellConstraints");
    decl_mgr.addImport("com.jgoodies.forms.layout.FormLayout");

    PropertiesMemento pm = fm.getPropertiesMemento();

    MethodWriter method_writer = new MethodWriter(decl_mgr, null,
            getSuggestedMethodName(pm.getComponentName()));
    BeanWriter form_bean_writer = new BeanWriter(method_writer, pm);
    method_writer.setReturnResult(form_bean_writer);

    LocalVariableDeclaration layout = new LocalVariableDeclaration(method_writer,
            com.jgoodies.forms.layout.FormLayout.class);
    layout.addParameter(new StringExpression(fm.getColumnSpecs()));
    layout.addParameter(new StringExpression(fm.getRowSpecs()));

    /** we need this to get the row/column count */
    FormLayout formlayout = new FormLayout(FormSpecAdapter.fixupSpecs(fm.getColumnSpecs()),
            FormSpecAdapter.fixupSpecs(fm.getRowSpecs()));

    method_writer.addStatements(form_bean_writer.getStatements());

    method_writer.addStatement(layout);/* ww  w. j  av a 2s. c  o  m*/

    /** set the column and row groups */
    setGroups(method_writer, layout.getVariable(), fm, true);
    setGroups(method_writer, layout.getVariable(), fm, false);

    LocalVariableDeclaration ccvar = new LocalVariableDeclaration(method_writer,
            com.jgoodies.forms.layout.CellConstraints.class, "cc");
    method_writer.addStatement(ccvar);

    /** add the panel declaration/ctor to the method */
    MethodStatement ss = new MethodStatement(form_bean_writer.getBeanVariable(), "setLayout");
    ss.addParameter(new BasicExpression(layout.getVariable()));
    method_writer.addStatement(ss);

    decl_mgr.addMethod(method_writer);

    /** puts a newline between beans */
    method_writer.addStatement(new BasicStatement(""));

    HashMap row_cache = new HashMap();
    HashMap col_cache = new HashMap();

    Iterator iter = fm.iterator();
    while (iter.hasNext()) {
        ComponentMemento cm = (ComponentMemento) iter.next();
        CellConstraintsMemento ccm = cm.getCellConstraintsMemento();
        CellConstraints cc = ccm.createCellConstraints();

        try {
            if (cm instanceof FormMemento) {
                FormMemento cfm = (FormMemento) cm;
                MethodWriter subpanel = createPanel(method_writer, cfm);
                method_writer.addStatement(createAddComponentStatement(form_bean_writer.getBeanVariable(),
                        subpanel.getMethodName() + "()", ccvar.getVariable(), cc));

            } else if (cm instanceof BeanMemento) {
                BeanMemento bm = (BeanMemento) cm;
                Integer icol = new Integer(cc.gridX);
                Integer irow = new Integer(cc.gridY);

                if (bm.getBeanClass() == null) {
                    /** found an empty component */
                    if (col_cache.get(icol) == null)
                        col_cache.put(icol, new FillMarker(bm, formlayout.getColumnSpec(icol.intValue())));

                    if (row_cache.get(irow) == null)
                        row_cache.put(irow, new FillMarker(bm, formlayout.getRowSpec(irow.intValue())));

                } else if (bm.getProperties() != null) {
                    String beanclass = bm.getBeanClass();
                    if (beanclass.indexOf("GridView") > 0 || beanclass.indexOf("JETALabel") > 0
                            || decl_mgr.isIncludeNonStandard() || beanclass.indexOf("com.jeta") < 0) {

                        BeanWriter bw = new BeanWriter(method_writer, bm.getProperties());
                        method_writer.addStatements(bw.getStatements());

                        method_writer
                                .addStatement(createAddComponentStatement(form_bean_writer.getBeanVariable(),
                                        bw.getResultVariable(), ccvar.getVariable(), cc));
                        /** puts a newline between beans */
                        method_writer.addStatement(new BasicStatement(""));

                        if (icol.intValue() == 1)
                            row_cache.put(irow, new FillMarker(bm, formlayout.getRowSpec(irow.intValue())));

                        if (irow.intValue() == 1)
                            col_cache.put(icol, new FillMarker(bm, formlayout.getColumnSpec(icol.intValue())));
                    }

                }
            } else {
                assert (false);
            }
        } catch (Exception e) {

        }
    }

    MethodStatement addseps = new MethodStatement("addFillComponents");
    addseps.addParameter(form_bean_writer.getBeanVariable());
    addseps.addParameter(createFillArray(col_cache, formlayout.getColumnCount()));
    addseps.addParameter(createFillArray(row_cache, formlayout.getRowCount()));
    method_writer.addStatement(addseps);

    return method_writer;
}