List of usage examples for com.jgoodies.forms.layout ConstantSize MILLIMETER
Unit MILLIMETER
To view the source code for com.jgoodies.forms.layout ConstantSize MILLIMETER.
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>. *///from w ww. java 2 s.c om 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}. *//*from w w w . j av a2s . co 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. *//*from w w w . jav a2 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}. *///from w w w. j a v a2 s.co m 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
/** * Test for {@link FormSizeConstantInfo} conversion special cases. *//*w ww. ja v a 2 s.co m*/ 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 a 2 s.c om*/ 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 w w .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_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());/*w ww . j av a2 s. c om*/ 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()); } }