List of usage examples for com.jgoodies.forms.layout ConstantSize CENTIMETER
Unit CENTIMETER
To view the source code for com.jgoodies.forms.layout ConstantSize CENTIMETER.
Click Source Link
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in <code>newUnit</code> converted from <code>oldUnit</code>. */// ww w .j a v a 2 s . com private static double convertValue(double value, Unit oldUnit, Unit newUnit) throws Exception { // special cases if (oldUnit == ConstantSize.CENTIMETER && newUnit == ConstantSize.MILLIMETER) { return value * 10.0; } if (oldUnit == ConstantSize.MILLIMETER && newUnit == ConstantSize.CENTIMETER) { return value / 10.0; } // generic case if (oldUnit != newUnit) { int pixels = convertToPixels(value, oldUnit); return convertFromPixels(pixels, newUnit); } return value; }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in pixels for value in given {@link Unit}. *///w ww . j av a2 s . c o m public static int convertToPixels(double value, Unit unit) { UnitConverter converter = DefaultUnitConverter.getInstance(); // int pixels = 0; if (unit == ConstantSize.PIXEL) { pixels = (int) value; } else if (unit == ConstantSize.POINT) { pixels = converter.pointAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.DLUX) { pixels = converter.dialogUnitXAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.DLUY) { pixels = converter.dialogUnitYAsPixel((int) value, m_toolkitComponent); } else if (unit == ConstantSize.MILLIMETER) { pixels = converter.millimeterAsPixel(value, m_toolkitComponent); } else if (unit == ConstantSize.CENTIMETER) { pixels = converter.centimeterAsPixel(value, m_toolkitComponent); } else if (unit == ConstantSize.INCH) { pixels = converter.inchAsPixel(value, m_toolkitComponent); } // return pixels; }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormSizeConstantInfo.java
License:Open Source License
/** * @return the value in given {@link Unit} for value in pixels. */// w ww .j a va 2 s. c om public static double convertFromPixels(int pixels, Unit unit) throws Exception { if (unit == ConstantSize.PIXEL) { return pixels; } else if (unit == ConstantSize.POINT) { return convertFromPixelsInt(pixels, "pointAsPixel"); } else if (unit == ConstantSize.DLUX) { return convertFromPixelsInt(pixels, "dialogUnitXAsPixel"); } else if (unit == ConstantSize.DLUY) { return convertFromPixelsInt(pixels, "dialogUnitYAsPixel"); } else if (unit == ConstantSize.MILLIMETER) { return convertFromPixelsDouble(pixels, "millimeterAsPixel"); } else if (unit == ConstantSize.CENTIMETER) { return convertFromPixelsDouble(pixels, "centimeterAsPixel"); } else { Assert.isTrue(unit == ConstantSize.INCH); return convertFromPixelsDouble(pixels, "inchAsPixel"); } }
From source file:org.eclipse.wb.tests.designer.swing.model.layout.FormLayout.FormSizeInfoTest.java
License:Open Source License
/** * Test for {@link FormSizeConstantInfo} conversion special cases. *///from w w w . ja va 2 s . com public void test_FormSizeConstantInfo_convertSpecial() throws Exception { { FormSizeConstantInfo size = new FormSizeConstantInfo(1.0, ConstantSize.CENTIMETER); size.setUnit(ConstantSize.MILLIMETER); assertEquals("10mm", size.getSource(true, true)); } { FormSizeConstantInfo size = new FormSizeConstantInfo(23.0, ConstantSize.MILLIMETER); size.setUnit(ConstantSize.CENTIMETER); assertEquals("2.3cm", size.getSource(true, true)); } }
From source file:org.eclipse.wb.tests.designer.swing.model.layout.FormLayout.FormSizeInfoTest.java
License:Open Source License
/** * Test for {@link FormSizeConstantInfo#convertFromPixels(int, Unit)} *///from w w w . j a v a2s .co m public void test_FormSizeConstantInfo_convertFromPixels() throws Exception { { double expected = 50.0; check_convertFromPixels(50, ConstantSize.PIXEL, expected); } { double expected = Expectations.get(39.0, new DblValue[] { new DblValue("kosta-home", 31.0), new DblValue("scheglov-win", 39.0) }); check_convertFromPixels(50, ConstantSize.POINT, expected); } { double expected = Expectations.get(34.0, new DblValue[] { new DblValue("kosta-home", 26.0), new DblValue("scheglov-win", 34.0) }); check_convertFromPixels(50, ConstantSize.DIALOG_UNITS_X, expected); } { double expected = Expectations.get(34.0, new DblValue[] { new DblValue("kosta-home", 32.0), new DblValue("scheglov-win", 34.0) }); check_convertFromPixels(50, ConstantSize.DIALOG_UNITS_Y, expected); } { double expected = Expectations.get(13.4, new DblValue[] { new DblValue("kosta-home", 10.7), new DblValue("scheglov-win", 13.4) }); check_convertFromPixels(50, ConstantSize.MILLIMETER, expected); } { double expected = Expectations.get(1.3, new DblValue[] { new DblValue("kosta-home", 1.1), new DblValue("scheglov-win", 1.3) }); check_convertFromPixels(50, ConstantSize.CENTIMETER, expected); } { double expected = Expectations.get(0.5, new DblValue[] { new DblValue("kosta-home", 0.4), new DblValue("scheglov-win", 0.5) }); check_convertFromPixels(50, ConstantSize.INCH, expected); } }
From source file:org.eclipse.wb.tests.designer.swing.model.layout.FormLayout.FormSizeInfoTest.java
License:Open Source License
/** * Test for {@link FormSizeConstantInfo#convertToPixels(double, Unit)} *//*from w ww.j a v a 2s.c o m*/ public void test_FormSizeConstantInfo_convertToPixels() throws Exception { { int expected = 10; check_convertToPixels(10.0, ConstantSize.PIXEL, expected); } { int expected = Expectations.get(13, new IntValue[] { new IntValue("kosta-home", 16), new IntValue("scheglov-win", 13) }); check_convertToPixels(10.0, ConstantSize.POINT, expected); } { int expected = Expectations.get(15, new IntValue[] { new IntValue("kosta-home", 20), new IntValue("scheglov-win", 15) }); check_convertToPixels(10.0, ConstantSize.DIALOG_UNITS_X, expected); } { int expected = Expectations.get(15, new IntValue[] { new IntValue("kosta-home", 16), new IntValue("scheglov-win", 15) }); check_convertToPixels(10.0, ConstantSize.DIALOG_UNITS_Y, expected); } { int expected = Expectations.get(38, new IntValue[] { new IntValue("kosta-home", 47), new IntValue("scheglov-win", 38) }); check_convertToPixels(10.0, ConstantSize.MILLIMETER, expected); } { int expected = Expectations.get(378, new IntValue[] { new IntValue("kosta-home", 472), new IntValue("scheglov-win", 378) }); check_convertToPixels(10.0, ConstantSize.CENTIMETER, expected); } { int expected = Expectations.get(960, new IntValue[] { new IntValue("kosta-home", 1200), new IntValue("scheglov-win", 960) }); check_convertToPixels(10.0, ConstantSize.INCH, expected); } }
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 .j a v a2 s . 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());//from w w w . j av a2 s. co 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 w w . ja va 2s . co m 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()); } }