Search in sources :

Example 1 with FormLayoutInfo

use of org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo in project windowbuilder by eclipse.

the class RowSelectionEditPolicy method getTextFeedbackText.

@Override
protected String getTextFeedbackText(ChangeBoundsRequest request, boolean inverse) {
    final FormLayoutInfo layout = getLayout();
    int pixels = getHostFigure().getSize().height;
    int pixelsDelta = request.getSizeDelta().height;
    try {
        FormSizeInfo sizeCopy = getDimension().copy().getSize();
        if (sizeCopy.getComponentSize() == null ^ inverse) {
            // set current size if "null"
            if (sizeCopy.getConstantSize() == null) {
                FormSizeConstantInfo constantSize = new FormSizeConstantInfo(pixels, ConstantSize.PIXEL);
                Unit newUnit = sizeCopy.getLowerSize() != null ? sizeCopy.getLowerSize().getUnit() : ConstantSize.DIALOG_UNITS_Y;
                constantSize.setUnit(newUnit);
                sizeCopy.setConstantSize(constantSize);
            }
            // update size
            final FormSizeConstantInfo constantSize;
            {
                constantSize = sizeCopy.getConstantSize();
                constantSize.setAsPixels(pixels + pixelsDelta);
            }
            // prepare command
            m_resizeCommand = new EditCommand(layout) {

                @Override
                protected void executeEdit() throws Exception {
                    getDimension().getSize().setConstantSize(constantSize);
                    layout.writeDimensions();
                }
            };
            // return text
            return MessageFormat.format(GefMessages.RowSelectionEditPolicy_heightPattern, constantSize.getSource(true, true));
        } else {
            // set current size if "null"
            if (sizeCopy.getLowerSize() == null) {
                FormSizeConstantInfo lowerSize = new FormSizeConstantInfo(pixels, ConstantSize.PIXEL);
                Unit newUnit = sizeCopy.getConstantSize() != null ? sizeCopy.getConstantSize().getUnit() : ConstantSize.DIALOG_UNITS_Y;
                lowerSize.setUnit(newUnit);
                sizeCopy.setLowerSize(lowerSize);
            }
            // update size
            final FormSizeConstantInfo lowerSize;
            {
                lowerSize = sizeCopy.getLowerSize();
                lowerSize.setAsPixels(pixels + pixelsDelta);
            }
            // prepare command
            m_resizeCommand = new EditCommand(layout) {

                @Override
                protected void executeEdit() throws Exception {
                    FormSizeInfo size = getDimension().getSize();
                    // set component size
                    if (size.getComponentSize() == null) {
                        size.setComponentSize(Sizes.DEFAULT);
                    }
                    // set lower size
                    size.setLowerSize(lowerSize);
                    layout.writeDimensions();
                }
            };
            // return text
            return MessageFormat.format(GefMessages.RowSelectionEditPolicy_minimumHeightPattern, lowerSize.getSource(true, true));
        }
    } catch (Throwable e) {
        return GefMessages.RowSelectionEditPolicy_exception;
    }
}
Also used : FormLayoutInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo) FormSizeInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormSizeInfo) FormSizeConstantInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo) Unit(com.jgoodies.forms.layout.ConstantSize.Unit) EditCommand(org.eclipse.wb.core.gef.command.EditCommand) Point(org.eclipse.wb.draw2d.geometry.Point)

Example 2 with FormLayoutInfo

use of org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo in project windowbuilder by eclipse.

the class ColumnSelectionEditPolicy method getTextFeedbackText.

@Override
protected String getTextFeedbackText(ChangeBoundsRequest request, boolean inverse) {
    final FormLayoutInfo layout = getLayout();
    int pixels = getHostFigure().getSize().width;
    int pixelsDelta = request.getSizeDelta().width;
    try {
        FormSizeInfo sizeCopy = getDimension().copy().getSize();
        if (sizeCopy.getComponentSize() == null ^ inverse) {
            // set current size if "null"
            if (sizeCopy.getConstantSize() == null) {
                FormSizeConstantInfo constantSize = new FormSizeConstantInfo(pixels, ConstantSize.PIXEL);
                Unit newUnit = sizeCopy.getLowerSize() != null ? sizeCopy.getLowerSize().getUnit() : ConstantSize.DIALOG_UNITS_X;
                constantSize.setUnit(newUnit);
                sizeCopy.setConstantSize(constantSize);
            }
            // update size
            final FormSizeConstantInfo constantSize;
            {
                constantSize = sizeCopy.getConstantSize();
                constantSize.setAsPixels(pixels + pixelsDelta);
            }
            // prepare command
            m_resizeCommand = new EditCommand(layout) {

                @Override
                protected void executeEdit() throws Exception {
                    getDimension().getSize().setConstantSize(constantSize);
                    layout.writeDimensions();
                }
            };
            // return text
            return MessageFormat.format(GefMessages.ColumnSelectionEditPolicy_widthPattern, constantSize.getSource(true, true));
        } else {
            // set current size if "null"
            if (sizeCopy.getLowerSize() == null) {
                FormSizeConstantInfo lowerSize = new FormSizeConstantInfo(pixels, ConstantSize.PIXEL);
                Unit newUnit = sizeCopy.getConstantSize() != null ? sizeCopy.getConstantSize().getUnit() : ConstantSize.DIALOG_UNITS_X;
                lowerSize.setUnit(newUnit);
                sizeCopy.setLowerSize(lowerSize);
            }
            // update size
            final FormSizeConstantInfo lowerSize;
            {
                lowerSize = sizeCopy.getLowerSize();
                lowerSize.setAsPixels(pixels + pixelsDelta);
            }
            // prepare command
            m_resizeCommand = new EditCommand(layout) {

                @Override
                protected void executeEdit() throws Exception {
                    FormSizeInfo size = getDimension().getSize();
                    // set component size
                    if (size.getComponentSize() == null) {
                        size.setComponentSize(Sizes.DEFAULT);
                    }
                    // set lower size
                    size.setLowerSize(lowerSize);
                    layout.writeDimensions();
                }
            };
            // return text
            return MessageFormat.format(GefMessages.ColumnSelectionEditPolicy_minimumWidthPattern, lowerSize.getSource(true, true));
        }
    } catch (Throwable e) {
        return GefMessages.ColumnSelectionEditPolicy_exception;
    }
}
Also used : FormLayoutInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo) FormSizeInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormSizeInfo) FormSizeConstantInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo) Unit(com.jgoodies.forms.layout.ConstantSize.Unit) EditCommand(org.eclipse.wb.core.gef.command.EditCommand) Point(org.eclipse.wb.draw2d.geometry.Point)

Example 3 with FormLayoutInfo

use of org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo in project windowbuilder by eclipse.

the class FormLayoutParametersTest method test_CREATE_LabelBeforeText_gap.

/**
 * {@link JLabel} is marked as "right" aligned and next widget is {@link JTextField}, so when add
 * {@link JLabel} before {@link JTextField}, use "right" alignment.<br>
 * Variant with gap between {@link JLabel} and {@link JTextField}.
 */
public void test_CREATE_LabelBeforeText_gap() throws Exception {
    final ContainerInfo panel = parseContainer("public class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        FormSpecs.RELATED_GAP_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JTextField textField = new JTextField();", "      add(textField, '3, 1, fill, default');", "    }", "  }", "}");
    // create
    ExecutionUtils.run(panel, new RunnableEx() {

        @Override
        public void run() throws Exception {
            FormLayoutInfo layout = (FormLayoutInfo) panel.getLayout();
            ComponentInfo newComponent = createComponent(JLabel.class);
            layout.command_CREATE(newComponent, 1, false, 1, false);
        }
    });
    // check source
    assertEditor("public class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        FormSpecs.RELATED_GAP_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JLabel label = new JLabel('New label');", "      add(label, '1, 1, right, default');", "    }", "    {", "      JTextField textField = new JTextField();", "      add(textField, '3, 1, fill, default');", "    }", "  }", "}");
}
Also used : FormLayoutInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) JLabel(javax.swing.JLabel) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 4 with FormLayoutInfo

use of org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo in project windowbuilder by eclipse.

the class FormLayoutParametersTest method test_CREATE_LabelBeforeText_disabled.

/**
 * Check that automatic "right alignment" feature for {@link JLabel} can be disabled.
 */
public void test_CREATE_LabelBeforeText_disabled() throws Exception {
    final ContainerInfo panel = parseContainer("public class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JTextField textField = new JTextField();", "      add(textField, '2, 1, fill, default');", "    }", "  }", "}");
    // create
    Activator.getDefault().getPreferenceStore().setValue(IPreferenceConstants.P_ENABLE_RIGHT_ALIGNMENT, false);
    ExecutionUtils.run(panel, new RunnableEx() {

        @Override
        public void run() throws Exception {
            FormLayoutInfo layout = (FormLayoutInfo) panel.getLayout();
            ComponentInfo newComponent = createComponent(JLabel.class);
            layout.command_CREATE(newComponent, 1, false, 1, false);
        }
    });
    // check source
    assertEditor("public class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JLabel label = new JLabel('New label');", "      add(label, '1, 1');", "    }", "    {", "      JTextField textField = new JTextField();", "      add(textField, '2, 1, fill, default');", "    }", "  }", "}");
}
Also used : FormLayoutInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) JLabel(javax.swing.JLabel) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo)

Example 5 with FormLayoutInfo

use of org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo in project windowbuilder by eclipse.

the class FormLayoutParametersTest method test_CREATE_TextAfterLabel_gap.

/**
 * {@link JLabel} is marked as "right" aligned and next widget is {@link JTextField}, so when add
 * {@link JTextField} after {@link JLabel} , use "right" alignment for {@link JLabel}.<br>
 * Variant with gap between {@link JLabel} and {@link JTextField}.
 */
public void test_CREATE_TextAfterLabel_gap() throws Exception {
    final ContainerInfo panel = parseContainer("class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        FormSpecs.RELATED_GAP_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JLabel label = new JLabel('New label');", "      add(label, '1, 1, right, default');", "    }", "  }", "}");
    panel.refresh();
    // add new component
    ExecutionUtils.run(panel, new RunnableEx() {

        @Override
        public void run() throws Exception {
            FormLayoutInfo layout = (FormLayoutInfo) panel.getLayout();
            ComponentInfo newComponent = createComponent(JTextField.class);
            layout.command_CREATE(newComponent, 3, false, 1, false);
        }
    });
    // check result
    assertEditor("class Test extends JPanel {", "  public Test() {", "    setLayout(new FormLayout(new ColumnSpec[] {", "        FormSpecs.DEFAULT_COLSPEC,", "        FormSpecs.RELATED_GAP_COLSPEC,", "        ColumnSpec.decode('default:grow'),},", "      new RowSpec[] {", "        FormSpecs.DEFAULT_ROWSPEC,", "        RowSpec.decode('default:grow'),}));", "    {", "      JLabel label = new JLabel('New label');", "      add(label, '1, 1, right, default');", "    }", "    {", "      JTextField textField = new JTextField();", "      add(textField, '3, 1, fill, default');", "      textField.setColumns(10);", "    }", "  }", "}");
}
Also used : FormLayoutInfo(org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) ComponentInfo(org.eclipse.wb.internal.swing.model.component.ComponentInfo) JTextField(javax.swing.JTextField)

Aggregations

FormLayoutInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo)90 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)87 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)17 RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)10 List (java.util.List)9 FormColumnInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormColumnInfo)7 JTextField (javax.swing.JTextField)4 IGridInfo (org.eclipse.wb.core.gef.policy.layout.grid.IGridInfo)4 JLabel (javax.swing.JLabel)3 Unit (com.jgoodies.forms.layout.ConstantSize.Unit)2 JTable (javax.swing.JTable)2 EditCommand (org.eclipse.wb.core.gef.command.EditCommand)2 Insets (org.eclipse.wb.draw2d.geometry.Insets)2 Point (org.eclipse.wb.draw2d.geometry.Point)2 CellConstraintsSupport (org.eclipse.wb.internal.swing.FormLayout.model.CellConstraintsSupport)2 FormRowInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormRowInfo)2 FormSizeConstantInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo)2 FormSizeInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormSizeInfo)2 ImmutableList (com.google.common.collect.ImmutableList)1 Dimension (org.eclipse.wb.draw2d.geometry.Dimension)1