Example usage for com.jgoodies.forms.layout Sizes constant

List of usage examples for com.jgoodies.forms.layout Sizes constant

Introduction

In this page you can find the example usage for com.jgoodies.forms.layout Sizes constant.

Prototype

public static ConstantSize constant(String encodedValueAndUnit, boolean horizontal) 

Source Link

Document

Creates and returns an instance of ConstantSize from the given encoded size and unit description.

Usage

From source file:ai.aitia.meme.utils.FormsUtils.java

License:Open Source License

/**
 * Example:<pre>//from  ww  w.  j  a v  a 2s  . co m
 *    buttonStack( jMoveUpButton, jMoveDownButton, FormsUtils.BS_UNRELATED, 
 *                jRemoveButton, jEditButton ).getPanel()
 * </pre>
 */
public static ButtonStackBuilder buttonStack(Object... args) {
    ButtonStackBuilder ans = new ButtonStackBuilder();
    boolean addrel = false;
    for (int i = 0; i < args.length; ++i) {
        if (args[i] instanceof javax.swing.JComponent) {
            if (addrel)
                ans.addRelatedGap();
            ans.addGridded((javax.swing.JComponent) args[i]);
            addrel = true;
        } else if (BS_UNRELATED.equals(args[i])) {
            ans.addUnrelatedGap();
            addrel = false;
        } else if (BS_GLUE.equals(args[i])) {
            ans.addGlue();
            addrel = false;
        } else {
            ans.addStrut(Sizes.constant(args[i].toString(), false));
            addrel = false;
        }
    }
    return ans;
}

From source file:ai.aitia.meme.utils.FormsUtils.java

License:Open Source License

private static int flushGaps(ArrayList<String> gaps, StringBuilder colstmp, boolean horizontal) {
    if (gaps.isEmpty())
        return 0;
    if (gaps.size() == 1) {
        colstmp.append(gaps.get(0));//from   ww w . j a  v a  2s.  co m
        colstmp.append(',');
    } else {
        int pixelSize = 0;
        for (String size : gaps) {
            // Ide a 'null' helyere erdemes lenne bejuttatni egy GUI komponenst, ha lehet
            pixelSize += Sizes.constant(size, horizontal).getPixelSize(null);
        }
        colstmp.append(pixelSize);
        colstmp.append("px,");
    }
    gaps.clear();
    return 1;
}

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

License:Apache License

private ConstantSize getConstantSize(final JComboBox unitsCombo, final JSpinner spinner) {
    return Sizes.constant(spinner.getValue().toString() + unitsCombo.getSelectedItem().toString(), myIsRow);
}

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

License:Open Source License

/**
 * @return the {@link Size} value.
 */
public Size getSize(boolean horizontal) {
    return Sizes.constant(getSource(true, horizontal), horizontal);
}

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

License:Open Source License

public void test_sourceBounded() throws Exception {
    Size size = Sizes.bounded(Sizes.DEFAULT, Sizes.constant("3cm", true), Sizes.constant("40mm", true));
    FormColumnInfo column = new FormColumnInfo(new ColumnSpec(ColumnSpec.LEFT, size, 0.0));
    assertEquals(/* ww w.  j a  va 2  s.  com*/
            "new com.jgoodies.forms.layout.ColumnSpec(com.jgoodies.forms.layout.ColumnSpec.LEFT, com.jgoodies.forms.layout.Sizes.bounded(com.jgoodies.forms.layout.Sizes.DEFAULT, com.jgoodies.forms.layout.Sizes.constant(\"3cm\", true), com.jgoodies.forms.layout.Sizes.constant(\"40mm\", true)), 0)",
            column.getSource());
}

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

License:Open Source License

/**
 * Test for {@link FormSizeConstantInfo}.
 *///from  ww  w.jav a 2s  .  com
public void test_FormSizeConstantInfo() throws Exception {
    FormSizeConstantInfo size = new FormSizeConstantInfo(25, ConstantSize.PIXEL);
    assertEquals(25.0, size.getValue(), 0.001);
    assertEquals(25, size.getAsPixels());
    assertSame(ConstantSize.PIXEL, size.getUnit());
    // source
    {
        assertEquals("25px", size.getSource(true, true));
        assertEquals("com.jgoodies.forms.layout.Sizes.constant(\"25px\", true)", size.getSource(false, true));
        assertEquals("com.jgoodies.forms.layout.Sizes.constant(\"25px\", false)", size.getSource(false, false));
    }
    // value
    {
        Size sizeValue = size.getSize(true);
        assertEquals(Sizes.constant("25px", true), sizeValue);
    }
    // modify value
    {
        // double
        size.setValue(20.0);
        assertEquals("20px", size.getSource(true, true));
        // String
        {
            size.setValueString("bad string - ignored");
            assertEquals("20px", size.getSource(true, true));
            //
            size.setValueString("18");
            assertEquals("18px", size.getSource(true, true));
        }
        // pixels
        size.setAsPixels(40);
        assertEquals("40px", size.getSource(true, true));
    }
    // modify unit - keep in mind, that it can not be absolutely precise
    {
        // no change - pixels
        size.setUnit(ConstantSize.PIXEL);
        assertEquals(40, size.getValue(), 0.001);
        // to millimeters
        size.setUnit(ConstantSize.MILLIMETER);
        assertEquals(
                Expectations.get(10.7,
                        new DblValue[] { new DblValue("kosta-home", 8.5), new DblValue("scheglov-win", 10.7) }),
                size.getValue(), 0.001);
    }
}

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

License:Open Source License

public void test_FormSize_constant() throws Exception {
    FormSizeInfo size = new FormSizeInfo(Sizes.constant("25px", true), true);
    assertTrue(size.isString());//ww  w . ja  v  a  2  s  .c o m
    assertEquals("25px", size.getSource());
    assertEquals(Sizes.constant("25px", true), size.getSize());
    assertNull(size.getComponentSize());
    // display
    assertEquals("25px", size.getDisplayString());
    assertEquals("25px", size.toString());
    // lower/upper
    assertFalse(size.hasLowerSize());
    assertFalse(size.hasUpperSize());
    assertNull(size.getLowerSize());
    assertNull(size.getUpperSize());
    // constant
    FormSizeConstantInfo constantSize = size.getConstantSize();
    assertNotNull(constantSize);
    assertEquals(25.0, constantSize.getValue(), 0.001);
    assertSame(ConstantSize.PIXEL, constantSize.getUnit());
}

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

License:Open Source License

public void test_FormSize_boundedLower() throws Exception {
    FormSizeInfo size = new FormSizeInfo(new ColumnSpec("max(4cm;default)").getSize(), true);
    assertTrue(size.isString());/*from www . ja v a 2s . co m*/
    assertEquals("max(4cm;default)", size.getSource());
    assertSame(Sizes.DEFAULT, size.getComponentSize());
    assertEquals(Sizes.bounded(Sizes.DEFAULT, Sizes.constant("4cm", true), null), size.getSize());
    assertNull(size.getConstantSize());
    assertNull(size.getUpperSize());
    //
    FormSizeConstantInfo lowerSize = size.getLowerSize();
    assertNotNull(lowerSize);
    assertEquals(4.0, lowerSize.getValue(), 0.001);
    assertSame(ConstantSize.CENTIMETER, lowerSize.getUnit());
}

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

License:Open Source License

public void test_FormSize_boundedUpper() throws Exception {
    FormSizeInfo size = new FormSizeInfo(new ColumnSpec("min(3cm;default)").getSize(), true);
    assertTrue(size.isString());/*  www  .  j  av  a2  s  . c  o m*/
    assertEquals("min(3cm;default)", size.getSource());
    assertSame(Sizes.DEFAULT, size.getComponentSize());
    assertEquals(Sizes.bounded(Sizes.DEFAULT, null, Sizes.constant("3cm", true)), size.getSize());
    assertNull(size.getConstantSize());
    // lower
    assertFalse(size.hasLowerSize());
    assertNull(size.getLowerSize());
    // upper
    assertTrue(size.hasUpperSize());
    FormSizeConstantInfo upperSize = size.getUpperSize();
    assertNotNull(upperSize);
    assertEquals(3.0, upperSize.getValue(), 0.001);
    assertSame(ConstantSize.CENTIMETER, upperSize.getUnit());
}

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

License:Open Source License

public void test_FormSize_boundedLowerUpper() throws Exception {
    Size expectedSize = Sizes.bounded(Sizes.DEFAULT, Sizes.constant("3cm", true), Sizes.constant("40mm", true));
    FormSizeInfo size = new FormSizeInfo(expectedSize, true);
    assertFalse(size.isString());//from  w ww.  j  a  v  a 2  s  .  com
    assertEquals(
            "com.jgoodies.forms.layout.Sizes.bounded(com.jgoodies.forms.layout.Sizes.DEFAULT, com.jgoodies.forms.layout.Sizes.constant(\"3cm\", true), com.jgoodies.forms.layout.Sizes.constant(\"40mm\", true))",
            size.getSource());
    assertEquals(expectedSize, size.getSize());
    assertNull(size.getConstantSize());
    // lower
    {
        FormSizeConstantInfo lowerSize = size.getLowerSize();
        assertNotNull(lowerSize);
        assertEquals(3.0, lowerSize.getValue(), 0.001);
        assertSame(ConstantSize.CENTIMETER, lowerSize.getUnit());
    }
    // upper
    {
        FormSizeConstantInfo upperSize = size.getUpperSize();
        assertNotNull(upperSize);
        assertEquals(40.0, upperSize.getValue(), 0.001);
        assertSame(ConstantSize.MILLIMETER, upperSize.getUnit());
    }
}