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;
}
}
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;
}
}
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');", " }", " }", "}");
}
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');", " }", " }", "}");
}
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);", " }", " }", "}");
}
Aggregations