Java 类com.intellij.uiDesigner.compiler.GridBagConverter 实例源码

项目:intellij-ce-playground    文件:GridBagLayoutSerializer.java   
void readChildConstraints(final Element constraintsElement, final LwComponent component) {
  super.readChildConstraints(constraintsElement, component);
  GridBagConstraints gbc = new GridBagConstraints();
  GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc);
  final Element gridBagElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_GRIDBAG);
  if (gridBagElement != null) {
    if (gridBagElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) {
      gbc.insets = LwXmlReader.readInsets(gridBagElement);
    }
    gbc.weightx = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTX, 0.0);
    gbc.weighty = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTY, 0.0);
    gbc.ipadx = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADX, 0);
    gbc.ipady = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADY, 0);
  }
  component.setCustomLayoutConstraints(gbc);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testLayout3() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button1 = new JButton();
  button1.setPreferredSize(new Dimension(100,20));
  final JButton button2 = new JButton();
  button2.setPreferredSize(new Dimension(100,100));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(button2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);
  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(120, preferredSize.height);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * textfield1 | textfield2
 *  textfield3 (span 2)
 *
 * important: hspan should be greater than 0
 */
public void testTextAreas2() {
  final JPanel panel = new JPanel(/*new GridLayoutManager(2,2, new Insets(0,0,0,0), 11, 0)*/ new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(15,20));
  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(15,20));
  final JTextField field3 = new JTextField();
  field3.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field3, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  assertEquals(100, panel.getPreferredSize().width);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testGaps1() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(100,20));
  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 10, 0, false, false);
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(210, preferredSize.width);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * btn1
 * -----
 * empty
 * ----
 * btn2
 */
public void testGaps4() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 0, 7, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(2,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(47, preferredSize.height);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testGaps6() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 0, 500, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(540, preferredSize.height);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout(); // should not crash
}
项目:intellij-ce-playground    文件:GridBagLayoutSourceGenerator.java   
@Override
public void generateComponentLayout(final LwComponent component,
                                    final FormSourceCodeGenerator generator,
                                    final String variable,
                                    final String parentVariable) {
  GridBagConstraints gbc;
  if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
    gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
  }
  else {
    gbc = new GridBagConstraints();
  }

  GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc);

  generateGridBagConstraints(generator, gbc, variable, parentVariable);
}
项目:intellij-ce-playground    文件:RadGridBagLayoutManager.java   
@Override
public void changeContainerLayout(RadContainer container) throws IncorrectOperationException {
  if (container.getLayoutManager().isGrid()) {
    // preprocess: store weights in GridBagConstraints
    RadAbstractGridLayoutManager grid = container.getGridLayoutManager();
    for (RadComponent c : container.getComponents()) {
      GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(c);
      if (grid.canCellGrow(container, false, c.getConstraints().getColumn())) {
        gbc.weightx = 1.0;
      }
      if (grid.canCellGrow(container, true, c.getConstraints().getRow())) {
        gbc.weighty = 1.0;
      }
      c.setCustomLayoutConstraints(gbc);
    }
  }
  super.changeContainerLayout(container);
}
项目:tools-idea    文件:GridBagLayoutSerializer.java   
void readChildConstraints(final Element constraintsElement, final LwComponent component) {
  super.readChildConstraints(constraintsElement, component);
  GridBagConstraints gbc = new GridBagConstraints();
  GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc);
  final Element gridBagElement = LwXmlReader.getChild(constraintsElement, UIFormXmlConstants.ELEMENT_GRIDBAG);
  if (gridBagElement != null) {
    if (gridBagElement.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_TOP) != null) {
      gbc.insets = LwXmlReader.readInsets(gridBagElement);
    }
    gbc.weightx = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTX, 0.0);
    gbc.weighty = LwXmlReader.getOptionalDouble(gridBagElement, UIFormXmlConstants.ATTRIBUTE_WEIGHTY, 0.0);
    gbc.ipadx = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADX, 0);
    gbc.ipady = LwXmlReader.getOptionalInt(gridBagElement, UIFormXmlConstants.ATTRIBUTE_IPADY, 0);
  }
  component.setCustomLayoutConstraints(gbc);
}
项目:tools-idea    文件:GridBagConverterTest.java   
public void testLayout3() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button1 = new JButton();
  button1.setPreferredSize(new Dimension(100,20));
  final JButton button2 = new JButton();
  button2.setPreferredSize(new Dimension(100,100));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(button2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);
  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(120, preferredSize.height);
}
项目:tools-idea    文件:GridBagConverterTest.java   
/**
 * textfield1 | textfield2
 *  textfield3 (span 2)
 *
 * important: hspan should be greater than 0
 */
public void testTextAreas2() {
  final JPanel panel = new JPanel(/*new GridLayoutManager(2,2, new Insets(0,0,0,0), 11, 0)*/ new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(15,20));
  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(15,20));
  final JTextField field3 = new JTextField();
  field3.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field3, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  assertEquals(100, panel.getPreferredSize().width);
}
项目:tools-idea    文件:GridBagConverterTest.java   
public void testGaps1() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(100,20));
  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 10, 0, false, false);
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(210, preferredSize.width);
}
项目:tools-idea    文件:GridBagConverterTest.java   
/**
 * btn1
 * -----
 * empty
 * ----
 * btn2
 */
public void testGaps4() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 0, 7, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(2,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(47, preferredSize.height);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
}
项目:tools-idea    文件:GridBagConverterTest.java   
public void testGaps6() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 0, 500, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(540, preferredSize.height);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout(); // should not crash
}
项目:tools-idea    文件:GridBagLayoutSourceGenerator.java   
@Override
public void generateComponentLayout(final LwComponent component,
                                    final FormSourceCodeGenerator generator,
                                    final String variable,
                                    final String parentVariable) {
  GridBagConstraints gbc;
  if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
    gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
  }
  else {
    gbc = new GridBagConstraints();
  }

  GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc);

  generateGridBagConstraints(generator, gbc, variable, parentVariable);
}
项目:tools-idea    文件:RadGridBagLayoutManager.java   
@Override
public void changeContainerLayout(RadContainer container) throws IncorrectOperationException {
  if (container.getLayoutManager().isGrid()) {
    // preprocess: store weights in GridBagConstraints
    RadAbstractGridLayoutManager grid = container.getGridLayoutManager();
    for (RadComponent c : container.getComponents()) {
      GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(c);
      if (grid.canCellGrow(container, false, c.getConstraints().getColumn())) {
        gbc.weightx = 1.0;
      }
      if (grid.canCellGrow(container, true, c.getConstraints().getRow())) {
        gbc.weighty = 1.0;
      }
      c.setCustomLayoutConstraints(gbc);
    }
  }
  super.changeContainerLayout(container);
}
项目:consulo-ui-designer    文件:GridBagLayoutSourceGenerator.java   
@Override
public void generateComponentLayout(final LwComponent component,
                                    final FormSourceCodeGenerator generator,
                                    final String variable,
                                    final String parentVariable) {
  GridBagConstraints gbc;
  if (component.getCustomLayoutConstraints() instanceof GridBagConstraints) {
    gbc = (GridBagConstraints) component.getCustomLayoutConstraints();
  }
  else {
    gbc = new GridBagConstraints();
  }

  GridBagConverter.constraintsToGridBag(component.getConstraints(), gbc);

  generateGridBagConstraints(generator, gbc, variable, parentVariable);
}
项目:consulo-ui-designer    文件:RadGridBagLayoutManager.java   
@Override
public void changeContainerLayout(RadContainer container) throws IncorrectOperationException {
  if (container.getLayoutManager().isGrid()) {
    // preprocess: store weights in GridBagConstraints
    RadAbstractGridLayoutManager grid = container.getGridLayoutManager();
    for (RadComponent c : container.getComponents()) {
      GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(c);
      if (grid.canCellGrow(container, false, c.getConstraints().getColumn())) {
        gbc.weightx = 1.0;
      }
      if (grid.canCellGrow(container, true, c.getConstraints().getRow())) {
        gbc.weighty = 1.0;
      }
      c.setCustomLayoutConstraints(gbc);
    }
  }
  super.changeContainerLayout(container);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * button 1
 * <empty>
 * button 2
 */
public void testLayout2() {
  final GridBagLayout layoutManager = new GridBagLayout();
  final JPanel panel = new JPanel(layoutManager);

  final JButton button1 = new JButton();
  button1.setMinimumSize(new Dimension(9, 7));
  button1.setPreferredSize(new Dimension(50, 10));

  final JButton button2 = new JButton();
  button2.setMinimumSize(new Dimension(15, 6));
  button2.setPreferredSize(new Dimension(50, 10));

  GridBagConverter converter = new GridBagConverter();
  final GridConstraints button1Constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 null, null, null, 0);
  converter.addComponent(button1, button1Constraints);

  final GridConstraints button2Constraints = new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0);

  converter.addComponent(button2, button2Constraints);

  applyConversionResults(panel, converter);

  assertEquals(20, panel.getPreferredSize().height);
  assertEquals(50, panel.getPreferredSize().width);

  assertEquals(17, panel.getMinimumSize().height);
  assertEquals(50, panel.getMinimumSize().width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(50, button1.getHeight());
  assertEquals(50, button2.getHeight());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testLayout2ByConstraints() {
  final GridBagLayout layoutManager = new GridBagLayout();
  final JPanel panel = new JPanel(layoutManager);
  final JButton button1 = new JButton();
  final JButton button2 = new JButton();

  GridBagConverter converter = new GridBagConverter();
  final GridConstraints button1Constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW,
                                                                 GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 new Dimension(9, 7), new Dimension(50, 10), null, 0);
  converter.addComponent(button1, button1Constraints);

  final GridConstraints button2Constraints = new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 GridConstraints.SIZEPOLICY_FIXED,
                                                                 new Dimension(15, 6), new Dimension(50, 10), null, 0);

  converter.addComponent(button2, button2Constraints);

  applyConversionResults(panel, converter);

  assertEquals(20, panel.getPreferredSize().height);
  assertEquals(50, panel.getPreferredSize().width);

  assertEquals(17, panel.getMinimumSize().height);
  assertEquals(50, panel.getMinimumSize().width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(50, button1.getHeight());
  assertEquals(50, button2.getHeight());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testLayout4() {
  final JPanel panel = new JPanel(new GridBagLayout());

  // button 1  button 3
  // button 2  button 3

  final JButton button1 = new JButton();
  button1.setPreferredSize(new Dimension(100,10));
  final JButton button2 = new JButton();
  button2.setPreferredSize(new Dimension(100,10));
  final JButton button3 = new JButton();
  button3.setPreferredSize(new Dimension(100,200));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  converter.addComponent(button2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  converter.addComponent(button3, new GridConstraints(0,1,2,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  applyConversionResults(panel, converter);
  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(200, preferredSize.height);
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testLayout7() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JLabel label = new JLabel();
  label.setPreferredSize(new Dimension(50,10));

  final JTextField field = new JTextField();
  field.setPreferredSize(new Dimension(100,10));

  final JTextField scroll = new JTextField();
  scroll.setPreferredSize(new Dimension(503, 10));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(label, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(0,0), null, null, 0));

  converter.addComponent(field, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(0,0), null, null, 0));

  converter.addComponent(scroll, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(0,0), null, null, 0));

  applyConversionResults(panel, converter);

  assertEquals(503, panel.getMinimumSize().width);
  assertEquals(503, panel.getPreferredSize().width);

  panel.setSize(503, 100);
  panel.doLayout();

  assertEquals(50, label.getWidth());
  assertEquals(453, field.getWidth());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testPrefSize1() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setMinimumSize(new Dimension(110,10));
  field1.setPreferredSize(new Dimension(120,10));

  final JTextField field2 = new JTextField();
  field2.setMinimumSize(new Dimension(215,10));
  field2.setPreferredSize(new Dimension(225,10));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(345, preferredSize.width);

  final Dimension minSize = panel.getMinimumSize();
  assertEquals(325, minSize.width);

  panel.setSize(preferredSize.width, preferredSize.height);
  panel.doLayout();

  assertEquals(120, field1.getWidth());
  assertEquals(225, field2.getWidth());

  panel.setSize(400, panel.getWidth());
  panel.invalidate(); // to invalidate layout
  panel.doLayout();
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * button(can grow) | text field (want grow)
 *   text field (want grow, span 2)
 */
public void testSpans1() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button = new JButton();
  button.setPreferredSize(new Dimension(50, 10));

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(50, 10));

  final JTextField field2 = new JTextField();

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field1, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(100, preferredSize.width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(500, field2.getWidth());
  assertEquals(50, button.getWidth());
  assertEquals(450, field1.getWidth());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * button(can grow) | text field (can grow)
 *   text field (want grow, span 2)
 */
public void testSpans2() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button = new JButton();
  button.setPreferredSize(new Dimension(50, 10));

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(50, 10));

  final JTextField field2 = new JTextField();

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field1, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
                                        GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(100, preferredSize.width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(500, field2.getWidth());
  assertEquals(250, button.getWidth());
  assertEquals(250, field1.getWidth());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * button(can grow) | text field (want grow, span 2)
 */
public void testSpans3() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button = new JButton();
  button.setPreferredSize(new Dimension(50, 10));

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(110, 10));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field1, new GridConstraints(0,1,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(160, preferredSize.width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(50, button.getWidth());
  assertEquals(450, field1.getWidth());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * button (can grow, span 2 )       | text field 1 (span 1)
 * text field 2 (want grow, span 2) | empty
 */
public void testSpans4() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton button = new JButton();
  button.setPreferredSize(new Dimension(50, 10));

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(110, 10));

  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(110, 10));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button, new GridConstraints(0,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field1, new GridConstraints(0,2,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(220, preferredSize.width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(250, button.getWidth());
  assertEquals(250, field1.getWidth());
  assertEquals(250, field2.getWidth());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * label   |    label
 * text area (span 2)
 */
public void testTextAreas1() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JLabel label1 = new JLabel();
  label1.setPreferredSize(new Dimension(15,20));
  final JLabel label2 = new JLabel();
  label2.setPreferredSize(new Dimension(15,20));
  final JTextArea textArea = new JTextArea();
  textArea.setLineWrap(true);

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(label1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(label2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(textArea, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0));

  applyConversionResults(panel, converter);

  assertEquals(100, textArea.getPreferredSize().width);

  final Dimension initialPreferredSize = panel.getPreferredSize();
  assertEquals(new Dimension(100,20 + textArea.getPreferredSize().height), initialPreferredSize);

  panel.setSize(initialPreferredSize);
  panel.invalidate();
  panel.doLayout();

  assertEquals(initialPreferredSize, panel.getPreferredSize());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 * field (span 2) | field (span 1)
 */
public void testGaps2() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setPreferredSize(new Dimension(100,20));
  final JTextField field2 = new JTextField();
  field2.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 7, 0, false, false);
  converter.addComponent(field1, new GridConstraints(0,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(0,2,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(207, preferredSize.width);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();

  assertEquals(new Rectangle(0,0,100,20), field1.getBounds());
  assertEquals(new Rectangle(107,0,100,20), field2.getBounds());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 *
 * btn1   |    btn2  | btn4
 *  btn3 (span 2)    |
 */
public void testGaps3() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));
  final JButton btn3 = new JButton();
  btn3.setPreferredSize(new Dimension(100,20));
  final JButton btn4 = new JButton();
  btn4.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 7, 0, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn3, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn4, new GridConstraints(0,2,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(314, preferredSize.width);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 *
 * btn1   |    btn2  | btn4
 *  btn3 (span 2)    |
 */
public void testGaps3a() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));
  final JButton btn3 = new JButton();
  btn3.setPreferredSize(new Dimension(100,20));
  final JButton btn4 = new JButton();
  btn4.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 1000, 0, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn3, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn4, new GridConstraints(0,2,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(2300, preferredSize.width);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
/**
 *
 * btn1   |    btn2
 *  btn3 (span 2)
 */
public void testGaps3b() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JButton btn1 = new JButton();
  btn1.setPreferredSize(new Dimension(100,20));
  final JButton btn2 = new JButton();
  btn2.setPreferredSize(new Dimension(100,20));
  final JButton btn3 = new JButton();
  btn3.setPreferredSize(new Dimension(100,20));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 1000, 0, false, false);
  converter.addComponent(btn1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  converter.addComponent(btn3, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL,
    GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(1200, preferredSize.width);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
public void testEqualSizeCells2() {
  final JPanel panel = new JPanel(new GridBagLayout());

  final JTextField field1 = new JTextField();
  field1.setMinimumSize(new Dimension(20, 5));
  field1.setPreferredSize(new Dimension(20, 10));

  final JTextField field2 = new JTextField();
  field2.setMinimumSize(new Dimension(20, 25));
  field2.setPreferredSize(new Dimension(20, 50));

  final JTextField field3 = new JTextField();
  field3.setMinimumSize(new Dimension(20, 70));
  field3.setPreferredSize(new Dimension(20, 100));

  GridBagConverter converter = new GridBagConverter(new Insets(0, 0, 0, 0), 0, 7, false, true);
  converter.addComponent(field1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null, 0));

  converter.addComponent(field2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null, 0));

  converter.addComponent(field3, new GridConstraints(2,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null, 0));

  applyConversionResults(panel, converter);

  final Dimension minimumSize = panel.getMinimumSize();
  assertEquals(70 + 7 + 70 + 7 + 70, minimumSize.height);

  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(100 + 7 + 100 + 7 + 100, preferredSize.height);

  panel.setSize(panel.getPreferredSize());
  panel.doLayout();

  assertEquals(100, field1.getHeight());
  assertEquals(100, field2.getHeight());
  assertEquals(100, field3.getHeight());
}
项目:intellij-ce-playground    文件:GridBagConverterTest.java   
private static void applyConversionResults(final JPanel panel, final GridBagConverter converter) {
  GridBagConverter.Result[] results = converter.convert();
  for(int i=0; i<results.length; i++)  {
    GridBagConverter.Result result = results [i];
    JComponent component = result.isFillerPanel ? new JPanel() : result.component;
    if (result.minimumSize != null) {
      component.setMinimumSize(result.minimumSize);
    }
    if (result.preferredSize != null) {
      component.setPreferredSize(result.preferredSize);
    }
    panel.add(component, result.constraints);
  }
}
项目:intellij-ce-playground    文件:GridBagLayoutSourceGenerator.java   
private void generateConversionResult(final FormSourceCodeGenerator generator,
                                      final GridBagConverter.Result result,
                                      final String variable, final String parentVariable) {
  checkSetSize(generator, variable, "setMinimumSize", result.minimumSize);
  checkSetSize(generator, variable, "setPreferredSize", result.preferredSize);
  checkSetSize(generator, variable, "setMaximumSize", result.maximumSize);

  generateGridBagConstraints(generator, result.constraints, variable, parentVariable);
}
项目:intellij-ce-playground    文件:RadGridBagLayoutManager.java   
@Override
public void addComponentToContainer(final RadContainer container, final RadComponent component, final int index) {
  super.addComponentToContainer(container, component, index);
  GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(component);
  component.setCustomLayoutConstraints(gbc);
  container.getDelegee().add(component.getDelegee(), gbc, index);
}
项目:intellij-ce-playground    文件:RadGridBagLayoutManager.java   
@Override
protected void updateConstraints(final RadComponent component) {
  GridBagLayout layout = (GridBagLayout)component.getParent().getLayout();
  GridBagConstraints gbc = GridBagConverter.getGridBagConstraints(component);
  layout.setConstraints(component.getDelegee(), gbc);
  super.updateConstraints(component);
}
项目:tools-idea    文件:GridBagConverterTest.java   
/**
 * button 1
 * <empty>
 * button 2
 */
public void testLayout2() {
  final GridBagLayout layoutManager = new GridBagLayout();
  final JPanel panel = new JPanel(layoutManager);

  final JButton button1 = new JButton();
  button1.setMinimumSize(new Dimension(9, 7));
  button1.setPreferredSize(new Dimension(50, 10));

  final JButton button2 = new JButton();
  button2.setMinimumSize(new Dimension(15, 6));
  button2.setPreferredSize(new Dimension(50, 10));

  GridBagConverter converter = new GridBagConverter();
  final GridConstraints button1Constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 null, null, null, 0);
  converter.addComponent(button1, button1Constraints);

  final GridConstraints button2Constraints = new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0);

  converter.addComponent(button2, button2Constraints);

  applyConversionResults(panel, converter);

  assertEquals(20, panel.getPreferredSize().height);
  assertEquals(50, panel.getPreferredSize().width);

  assertEquals(17, panel.getMinimumSize().height);
  assertEquals(50, panel.getMinimumSize().width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(50, button1.getHeight());
  assertEquals(50, button2.getHeight());
}
项目:tools-idea    文件:GridBagConverterTest.java   
public void testLayout2ByConstraints() {
  final GridBagLayout layoutManager = new GridBagLayout();
  final JPanel panel = new JPanel(layoutManager);
  final JButton button1 = new JButton();
  final JButton button2 = new JButton();

  GridBagConverter converter = new GridBagConverter();
  final GridConstraints button1Constraints = new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW,
                                                                 GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 new Dimension(9, 7), new Dimension(50, 10), null, 0);
  converter.addComponent(button1, button1Constraints);

  final GridConstraints button2Constraints = new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                                                                 GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_CAN_SHRINK,
                                                                 GridConstraints.SIZEPOLICY_FIXED,
                                                                 new Dimension(15, 6), new Dimension(50, 10), null, 0);

  converter.addComponent(button2, button2Constraints);

  applyConversionResults(panel, converter);

  assertEquals(20, panel.getPreferredSize().height);
  assertEquals(50, panel.getPreferredSize().width);

  assertEquals(17, panel.getMinimumSize().height);
  assertEquals(50, panel.getMinimumSize().width);

  panel.setSize(new Dimension(500, 100));
  panel.doLayout();

  assertEquals(50, button1.getHeight());
  assertEquals(50, button2.getHeight());
}
项目:tools-idea    文件:GridBagConverterTest.java   
public void testLayout4() {
  final JPanel panel = new JPanel(new GridBagLayout());

  // button 1  button 3
  // button 2  button 3

  final JButton button1 = new JButton();
  button1.setPreferredSize(new Dimension(100,10));
  final JButton button2 = new JButton();
  button2.setPreferredSize(new Dimension(100,10));
  final JButton button3 = new JButton();
  button3.setPreferredSize(new Dimension(100,200));

  GridBagConverter converter = new GridBagConverter();
  converter.addComponent(button1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  converter.addComponent(button2, new GridConstraints(1,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  converter.addComponent(button3, new GridConstraints(0,1,2,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH,
    GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_WANT_GROW + GridConstraints.SIZEPOLICY_CAN_SHRINK, null, null, null,
    0));

  applyConversionResults(panel, converter);
  final Dimension preferredSize = panel.getPreferredSize();
  assertEquals(200, preferredSize.height);
}