Example usage for com.jgoodies.forms.layout CellConstraints RIGHT

List of usage examples for com.jgoodies.forms.layout CellConstraints RIGHT

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout CellConstraints RIGHT.

Prototype

Alignment RIGHT

To view the source code for com.jgoodies.forms.layout CellConstraints RIGHT.

Click Source Link

Document

Put the component in the right.

Usage

From source file:org.eclipse.wb.internal.swing.FormLayout.model.CellConstraintsAssistantPage.java

License:Open Source License

public CellConstraintsAssistantPage(Composite parent, FormLayoutInfo layout, List<ObjectInfo> objects) {
    super(parent, objects);
    m_layout = layout;//from  ww w  .  j  a v a2  s  . com
    GridLayoutFactory.create(this).columns(3);
    // horizontal alignments
    {
        Group horizontalGroup = addChoiceProperty(this, "h alignment",
                ModelMessages.CellConstraintsAssistantPage_horizontalGroup,
                new Object[][] {
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_haDefault,
                                CellConstraints.DEFAULT },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_haLeft,
                                CellConstraints.LEFT },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_haCenter,
                                CellConstraints.CENTER },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_haRight,
                                CellConstraints.RIGHT },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_haFill,
                                CellConstraints.FILL } });
        GridDataFactory.modify(horizontalGroup).fill();
    }
    // vertical alignments
    {
        Group verticalGroup = addChoiceProperty(this, "v alignment",
                ModelMessages.CellConstraintsAssistantPage_verticalGroup,
                new Object[][] {
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_vaDefault,
                                CellConstraints.DEFAULT },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_vaTop, CellConstraints.TOP },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_vaCenter,
                                CellConstraints.CENTER },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_vaBottom,
                                CellConstraints.BOTTOM },
                        new Object[] { ModelMessages.CellConstraintsAssistantPage_vaFill,
                                CellConstraints.FILL } });
        GridDataFactory.modify(verticalGroup).fill();
    }
    // grid
    {
        Group gridGroup = addIntegerProperties(this, ModelMessages.CellConstraintsAssistantPage_gridGroup,
                new String[][] { { "grid x", ModelMessages.CellConstraintsAssistantPage_gridX },
                        { "grid y", ModelMessages.CellConstraintsAssistantPage_gridY },
                        { "grid width", ModelMessages.CellConstraintsAssistantPage_gridWidth },
                        { "grid height", ModelMessages.CellConstraintsAssistantPage_gridHeight } });
        GridDataFactory.modify(gridGroup).fill();
    }
}

From source file:org.eclipse.wb.internal.swing.FormLayout.model.CellConstraintsSupport.java

License:Open Source License

/**
 * @return the small {@link Image} that represents horizontal/vertical alignment.
 *///  w  w w  . j av  a 2s. co  m
public Image getSmallAlignmentImage(boolean horizontal) {
    if (horizontal) {
        if (alignH == CellConstraints.LEFT) {
            return Activator.getImage("alignment/h/left.gif");
        } else if (alignH == CellConstraints.CENTER) {
            return Activator.getImage("alignment/h/center.gif");
        } else if (alignH == CellConstraints.RIGHT) {
            return Activator.getImage("alignment/h/right.gif");
        } else if (alignH == CellConstraints.FILL) {
            return Activator.getImage("alignment/h/fill.gif");
        } else {
            return null;
        }
    } else {
        if (alignV == CellConstraints.TOP) {
            return Activator.getImage("alignment/v/top.gif");
        } else if (alignV == CellConstraints.CENTER) {
            return Activator.getImage("alignment/v/center.gif");
        } else if (alignV == CellConstraints.BOTTOM) {
            return Activator.getImage("alignment/v/bottom.gif");
        } else if (alignV == CellConstraints.FILL) {
            return Activator.getImage("alignment/v/fill.gif");
        } else {
            return null;
        }
    }
}

From source file:org.eclipse.wb.internal.swing.FormLayout.model.CellConstraintsSupport.java

License:Open Source License

/**
 * Adds the horizontal alignment {@link Action}'s.
 *///from w  ww.ja  va 2  s.c  o m
public void fillHorizontalAlignmentMenu(IMenuManager manager) {
    manager.add(new SetAlignmentAction(ModelMessages.CellConstraintsSupport_haDefault, "default.gif", true,
            CellConstraints.DEFAULT));
    manager.add(new SetAlignmentAction(ModelMessages.CellConstraintsSupport_haLeft, "left.gif", true,
            CellConstraints.LEFT));
    manager.add(new SetAlignmentAction(ModelMessages.CellConstraintsSupport_haCenter, "center.gif", true,
            CellConstraints.CENTER));
    manager.add(new SetAlignmentAction(ModelMessages.CellConstraintsSupport_haRight, "right.gif", true,
            CellConstraints.RIGHT));
    manager.add(new SetAlignmentAction(ModelMessages.CellConstraintsSupport_haFill, "fill.gif", true,
            CellConstraints.FILL));
}

From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutConverter.java

License:Open Source License

/**
 * Calculate horizontal alignment.//from   w  ww  . j a  v a2s  .  c o m
 */
private static CellConstraints.Alignment getHorizontalAlignment(List<ComponentGroup> columns,
        ComponentInGroup componentInGroup, GeneralLayoutData generalLayoutData) {
    if (generalLayoutData.horizontalAlignment != null) {
        // from general layout data
        CellConstraints.Alignment alignment = GeneralLayoutData
                .getRealValue(FormLayoutInfo.m_horizontalAlignmentMap, generalLayoutData.horizontalAlignment);
        if (alignment != null && alignment != CellConstraints.DEFAULT) {
            return alignment;
        }
    }
    // calculate
    IAbstractComponentInfo component = componentInGroup.getComponent();
    // prepare begin/end column
    ComponentGroup beginColumn = GridConvertionHelper.getBeginForComponent(columns, componentInGroup);
    ComponentGroup endColumn = GridConvertionHelper.getEndForComponent(columns, componentInGroup);
    int columnLeft = beginColumn.getMin();
    int columnRight = endColumn.getMax();
    int columnCenter = columnLeft + (columnRight - columnLeft) / 2;
    Rectangle bounds = component.getBounds();
    Dimension prefSize = component.getPreferredSize();
    int bl = bounds.x;
    int br = bounds.right();
    //
    int leftOffset = Math.abs(bl - columnLeft);
    int rightOffset = Math.abs(columnRight - br);
    // prepare how much location of two sides will be changed for each alignment
    int leftDelta = leftOffset + Math.abs(columnLeft + prefSize.width - br);
    int rightDelta = rightOffset + Math.abs(columnRight - prefSize.width - bl);
    int fillDelta = leftOffset + rightOffset;
    int centerDelta = Math.abs(bl - (columnCenter - prefSize.width / 2))
            + Math.abs(br - (columnCenter + prefSize.width / 2));
    // set alignment
    return getAlignment(new int[] { leftDelta, centerDelta, rightDelta, fillDelta }, new Alignment[] {
            CellConstraints.LEFT, CellConstraints.CENTER, CellConstraints.RIGHT, CellConstraints.FILL });
}

From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo.java

License:Open Source License

/**
 * Performs automatic alignment, such as grab/fill for {@link JTextField} or {@link JTable}, right
 * alignment for {@link JLabel}./*ww  w .ja va2s .  co  m*/
 */
private void doAutomaticAlignment(ComponentInfo component) throws Exception {
    final IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
    GridAlignmentHelper.doAutomaticAlignment(component, new IAlignmentProcessor<ComponentInfo>() {
        public boolean grabEnabled() {
            return preferences.getBoolean(P_ENABLE_GRAB);
        }

        public boolean rightEnabled() {
            return preferences.getBoolean(P_ENABLE_RIGHT_ALIGNMENT);
        }

        public ComponentInfo getComponentAtLeft(ComponentInfo component) {
            CellConstraintsSupport constraints = getConstraints(component);
            int x = constraints.x - 1;
            if (x > 0 && m_columns.get(x - 1).isGap()) {
                x--;
            }
            return getComponentAt(x, constraints.y);
        }

        public ComponentInfo getComponentAtRight(ComponentInfo component) {
            CellConstraintsSupport constraints = getConstraints(component);
            int x = constraints.x + 1;
            if (x < m_columns.size() && m_columns.get(x - 1).isGap()) {
                x++;
            }
            return getComponentAt(x, constraints.y);
        }

        public void setGrabFill(ComponentInfo component, boolean horizontal) throws Exception {
            boolean canChangeDimensions = canChangeDimensions();
            CellConstraintsSupport constraints = getConstraints(component);
            if (horizontal) {
                if (canChangeDimensions) {
                    getColumns().get(constraints.x - 1).setWeight(FormSpec.DEFAULT_GROW);
                }
                constraints.setAlignH(CellConstraints.FILL);
            } else {
                if (canChangeDimensions) {
                    getRows().get(constraints.y - 1).setWeight(FormSpec.DEFAULT_GROW);
                }
                constraints.setAlignV(CellConstraints.FILL);
            }
            if (canChangeDimensions) {
                writeDimensions();
            }
            constraints.write();
        }

        public void setRightAlignment(ComponentInfo component) throws Exception {
            CellConstraintsSupport constraints = getConstraints(component);
            constraints.setAlignH(CellConstraints.RIGHT);
            constraints.write();
        }
    });
}

From source file:org.eclipse.wb.internal.swing.FormLayout.model.SelectionActionsSupport.java

License:Open Source License

@Override
public void addSelectionActions(List<ObjectInfo> objects, List<Object> actions) throws Exception {
    if (objects.isEmpty()) {
        return;/*from   w  w  w  . j  ava2s.  c om*/
    }
    // prepare constraints
    List<CellConstraintsSupport> constraints = Lists.newArrayList();
    for (ObjectInfo object : objects) {
        // check object
        if (!(object instanceof ComponentInfo) || object.getParent() != m_layout.getContainer()) {
            return;
        }
        // add data info
        ComponentInfo component = (ComponentInfo) object;
        constraints.add(FormLayoutInfo.getConstraints(component));
    }
    // create horizontal actions
    actions.add(new Separator());
    addAlignmentAction(actions, constraints, true, "default.gif",
            ModelMessages.SelectionActionsSupport_haDefault, CellConstraints.DEFAULT);
    addAlignmentAction(actions, constraints, true, "left.gif", ModelMessages.SelectionActionsSupport_haLeft,
            CellConstraints.LEFT);
    addAlignmentAction(actions, constraints, true, "center.gif", ModelMessages.SelectionActionsSupport_haCenter,
            CellConstraints.CENTER);
    addAlignmentAction(actions, constraints, true, "right.gif", ModelMessages.SelectionActionsSupport_haRight,
            CellConstraints.RIGHT);
    addAlignmentAction(actions, constraints, true, "fill.gif", ModelMessages.SelectionActionsSupport_haFill,
            CellConstraints.FILL);
    // create vertical actions
    actions.add(new Separator());
    addAlignmentAction(actions, constraints, false, "default.gif",
            ModelMessages.SelectionActionsSupport_vaDefault, CellConstraints.DEFAULT);
    addAlignmentAction(actions, constraints, false, "top.gif", ModelMessages.SelectionActionsSupport_haTop,
            CellConstraints.TOP);
    addAlignmentAction(actions, constraints, false, "center.gif",
            ModelMessages.SelectionActionsSupport_vaCenter, CellConstraints.CENTER);
    addAlignmentAction(actions, constraints, false, "bottom.gif",
            ModelMessages.SelectionActionsSupport_vaBottom, CellConstraints.BOTTOM);
    addAlignmentAction(actions, constraints, false, "fill.gif", ModelMessages.SelectionActionsSupport_vaFill,
            CellConstraints.FILL);
}

From source file:org.eclipse.wb.tests.designer.swing.model.layout.FormLayout.CellConstraintsSupportTest.java

License:Open Source License

public void test_property_align_h() throws Exception {
    Property property = m_subProperties[4];
    assertEquals("h alignment", property.getTitle());
    assertFalse(property.isModified());/*from   w w w. ja  v a2  s.co  m*/
    assertEquals(CellConstraints.DEFAULT, property.getValue());
    // set value
    {
        String expectedSource = StringUtils.replace(m_lastEditor.getSource(), "1, 2", "1, 2, right, default");
        property.setValue(CellConstraints.RIGHT);
        assertEditor(expectedSource, m_lastEditor);
    }
    // reset value
    {
        String expectedSource = StringUtils.replace(m_lastEditor.getSource(), "1, 2, right, default", "1, 2");
        property.setValue(Property.UNKNOWN_VALUE);
        assertEditor(expectedSource, m_lastEditor);
    }
}

From source file:org.eclipse.wb.tests.designer.swing.model.layout.FormLayout.CellConstraintsSupportTest.java

License:Open Source License

public void test_getSmallAlignmentImage() throws Exception {
    check_getSmallAlignmentImage(CellConstraints.DEFAULT, true, false);
    check_getSmallAlignmentImage(CellConstraints.LEFT, true, true);
    check_getSmallAlignmentImage(CellConstraints.CENTER, true, true);
    check_getSmallAlignmentImage(CellConstraints.RIGHT, true, true);
    check_getSmallAlignmentImage(CellConstraints.FILL, true, true);
    ////from ww  w  .  j  a  v a2 s.  c o m
    check_getSmallAlignmentImage(CellConstraints.DEFAULT, false, false);
    check_getSmallAlignmentImage(CellConstraints.TOP, false, true);
    check_getSmallAlignmentImage(CellConstraints.CENTER, false, true);
    check_getSmallAlignmentImage(CellConstraints.BOTTOM, false, true);
    check_getSmallAlignmentImage(CellConstraints.FILL, false, true);
}

From source file:org.openconcerto.ui.FormLayouter.java

License:Open Source License

/**
 * Ajout un composant sur une ligne Si comp est null, un titre est cr.
 * //w  w w.j a  va  2s .c om
 * @param desc le label du champ.
 * @param comp le composant graphique d'edition.
 * @param w la largeur, entre 1 et la largeur de ce layout, ou 0 pour toute la largeur.
 * @return the created label.
 * @throws NullPointerException if comp is <code>null</code>.
 * @throws IllegalArgumentException if w is less than 1.
 */
public JLabel add(String desc, Component comp, int w) {
    w = this.checkArgs(comp, w);

    final int realWidth = this.getRealFieldWidth(w);
    // Guillaume : right alignment like the Mac
    final JLabel lab = new JLabel(desc);
    this.co.add(lab,
            this.constraints.xy(this.getLabelX(), this.getY(), CellConstraints.RIGHT, this.getRowAlign()));
    this.co.add(comp, this.constraints.xyw(this.getFieldX(), this.getY(), realWidth, CellConstraints.DEFAULT,
            this.getRowAlign()));
    this.x += w;
    return lab;
}

From source file:org.pmedv.blackboard.panels.ResistorPanel.java

License:Open Source License

private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    label1 = new JLabel();
    nameField = new JTextField();
    label3 = new JLabel();
    toleranceCombo = new JComboBox();
    label2 = new JLabel();
    valueSpinner = new JSpinner();
    multiplierCombo = new JComboBox();
    CellConstraints cc = new CellConstraints();

    //======== this ========
    setLayout(new FormLayout("2*($lcgap), default, 3*($lcgap, default:grow), $lcgap, default, 2*($lcgap)",
            "2*($lgap), 2*(default, $lgap), $lgap"));

    //---- label1 ----
    label1.setText(resources.getResourceByKey("ResistorPanel.name"));
    add(label1, cc.xy(3, 3));/*ww  w . ja  v a 2  s . c  om*/
    add(nameField, cc.xywh(5, 3, 3, 1));

    //---- label3 ----
    label3.setText(resources.getResourceByKey("ResistorPanel.tolerance"));
    add(label3, cc.xy(9, 3, CellConstraints.RIGHT, CellConstraints.DEFAULT));
    add(toleranceCombo, cc.xy(11, 3));

    //---- label2 ----
    label2.setText(resources.getResourceByKey("ResistorPanel.value"));
    add(label2, cc.xy(3, 5));
    add(valueSpinner, cc.xywh(5, 5, 5, 1));
    add(multiplierCombo, cc.xy(11, 5));
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
}