List of usage examples for com.jgoodies.forms.layout ConstantSize PIXEL
Unit PIXEL
To view the source code for com.jgoodies.forms.layout ConstantSize PIXEL.
Click Source Link
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
private static ConstantSize scaleSize(final FormSpec rowSpec, final RadContainer container, final int newPx) { if (rowSpec.getSize() instanceof ConstantSize) { ConstantSize oldSize = (ConstantSize) rowSpec.getSize(); int oldPx = oldSize.getPixelSize(container.getDelegee()); double newValue = Math.round(oldSize.getValue() * newPx / oldPx * 10) / 10; return new ConstantSize(newValue, oldSize.getUnit()); }/*from ww w.jav a2 s . c om*/ return new ConstantSize(newPx, ConstantSize.PIXEL); }
From source file:org.eclipse.wb.internal.swing.FormLayout.gef.header.selection.ColumnSelectionEditPolicy.java
License:Open Source License
@Override protected String getTextFeedbackText(ChangeBoundsRequest request, boolean inverse) { final FormLayoutInfo layout = getLayout(); int pixels = getHostFigure().getSize().width; int pixelsDelta = request.getSizeDelta().width; try {// www. j a v a 2s.com 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; } }
From source file:org.eclipse.wb.internal.swing.FormLayout.gef.header.selection.RowSelectionEditPolicy.java
License:Open Source License
@Override protected String getTextFeedbackText(ChangeBoundsRequest request, boolean inverse) { final FormLayoutInfo layout = getLayout(); int pixels = getHostFigure().getSize().height; int pixelsDelta = request.getSizeDelta().height; try {/*from w w w.ja v a 2 s. c om*/ 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; } }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormDimensionInfo.java
License:Open Source License
/** * Converts this {@link FormDimensionInfo} (with constant size in pixels) into nearest gap * template with size difference not more than given delta. *//*from w ww. j a v a 2s. c o m*/ public void convertToNearestGap(int maxDelta) throws Exception { // prepare size of this dimension in pixels int thisPixels; { Assert.isNotNull(m_size.getConstantSize()); Assert.isTrue(m_size.getConstantSize().getUnit() == ConstantSize.PIXEL); thisPixels = (int) m_size.getConstantSize().getValue(); } // int minDelta = Integer.MAX_VALUE; Field minField = null; // Field[] fields = FormDimensionUtils.getTemplateFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; // check for type if (m_horizontal && !ColumnSpec.class.isAssignableFrom(field.getType())) { continue; } if (!m_horizontal && !RowSpec.class.isAssignableFrom(field.getType())) { continue; } // check for constant size int sizeInPixels; { FormSpec formSpec = (FormSpec) field.get(null); if (!(formSpec.getSize() instanceof ConstantSize)) { continue; } if (formSpec.getResizeWeight() != FormSpec.NO_GROW) { continue; } ConstantSize constantSize = (ConstantSize) formSpec.getSize(); sizeInPixels = constantSize.getPixelSize(FormSizeConstantInfo.m_toolkitComponent); } // check that size in range int delta = Math.abs(sizeInPixels - thisPixels); if (delta <= maxDelta && delta < minDelta) { minDelta = delta; minField = field; } } // set found gap if (minField != null) { setFormSpec((FormSpec) minField.get(null)); } }
From source file:org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutConverter.java
License:Open Source License
/** * Creates {@link FormColumnInfo} or {@link FormRowInfo} for given {@link ComponentGroup}'s. *//* w w w . j av a 2s . co m*/ private static void createDimensions(FormLayoutInfo layout, List<ComponentGroup> groups, boolean horizontal) throws Exception { for (ComponentGroup group : groups) { // create new "default" dimension FormDimensionInfo dimension; if (horizontal) { FormColumnInfo column = new FormColumnInfo(FormFactory.DEFAULT_COLSPEC); layout.getColumns().add(column); dimension = column; } else { FormRowInfo row = new FormRowInfo(FormFactory.DEFAULT_ROWSPEC); layout.getRows().add(row); dimension = row; } // set constant size { FormSizeInfo size = dimension.getSize(); size.setConstantSize(new FormSizeConstantInfo(group.getSize(), ConstantSize.PIXEL)); } } }
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 w w . j a va2s .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. *//*from w ww .j a v 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.internal.swing.FormLayout.model.ui.ConstantSizeComposite.java
License:Open Source License
/** * Configures value {@link Spinner} according current {@link Unit}. *///from w w w .j a v a 2 s . c om private void configureSpinnerForUnit() { Unit unit = m_currentSize.getUnit(); if (unit == ConstantSize.PIXEL || unit == ConstantSize.POINT || unit == ConstantSize.DIALOG_UNITS_X || unit == ConstantSize.DIALOG_UNITS_Y) { m_valueSpinner.setDigits(0); m_divider = 1.0; } else { m_valueSpinner.setDigits(1); m_divider = 10.0; } }
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 a 2 s . c o 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#convertFromPixels(int, Unit)} *//*from w w w . j a v a 2s . c o 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); } }