Java com.intellij.uiDesigner.core.GridConstraints 代码实例

・17 分钟阅读

以下是展示如何使用com.intellij.uiDesigner.core.GridConstraints的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


private void layout(JPanel panel, int row, int ident) {
  GridConstraints c = new GridConstraints();
  c.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
  c.setRow(row);
  c.setColumn(0);
  c.setFill(GridConstraints.FILL_NONE);
  c.setAnchor(GridConstraints.ANCHOR_WEST);
  c.setRow(row);
  c.setIndent(ident);
  panel.add(myLabel, c);
  c.setIndent(0);
  c.setColumn(1);
  c.setFill(GridConstraints.FILL_HORIZONTAL);
  panel.add(myMinSdkCombobox, c);
}
 

实例 2


public static JPanel createWizardStepHeader(JBColor headerColor, Icon icon, String title) {
  JPanel panel = new JPanel();
  panel.setBackground(headerColor);
  panel.setBorder(new EmptyBorder(WizardConstants.STUDIO_WIZARD_INSETS));
  panel.setLayout(new GridLayoutManager(2, 2, new Insets(18, 0, 12, 0), 2, 2));
  GridConstraints c = new GridConstraints(0, 0, 2, 1, GridConstraints.ANCHOR_NORTHWEST,
                                          GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED,
                                          GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(60, 60), null);
  ImageComponent image = new ImageComponent(icon);
  panel.add(image, c);
  c = new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_SOUTHWEST, GridConstraints.FILL_HORIZONTAL,
                          GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW,
                          GridConstraints.SIZEPOLICY_FIXED, null, null, null);
  JLabel titleLabel = new JLabel(title);
  titleLabel.setForeground(Color.WHITE);
  titleLabel.setFont(titleLabel.getFont().deriveFont(24f));
  panel.add(titleLabel, c);
  c.setRow(1);
  c.setAnchor(GridConstraints.ANCHOR_NORTHWEST);
  JLabel productLabel = new JLabel("Android Studio");
  productLabel.setForeground(Color.WHITE);
  panel.add(productLabel, c);
  return panel;
}
 

实例 3


private void updateFileChooser() {
  boolean containsHxml = false;
  boolean containsNME = false;
  boolean containsOpenFL = false;
  Component[] components = myBuildFilePanel.getComponents();
  for (Component component : components) {
    if (component == myHxmlFileChooserPanel) {
      containsHxml = true;
    }
    if (component == myNMEFilePanel) {
      containsNME = true;
    }
    if (component == myOpenFLFilePanel) {
      containsOpenFL = true;
    }
  }
  if (!myHxmlFileRadioButton.isSelected() && containsHxml) {
    myBuildFilePanel.remove(myHxmlFileChooserPanel);
  }
  if (!myNmmlFileRadioButton.isSelected() && containsNME) {
    myBuildFilePanel.remove(myNMEFilePanel);
  }
  if (!myOpenFLFileRadioButton.isSelected() && containsOpenFL) {
    myBuildFilePanel.remove(myOpenFLFilePanel);
    myBuildFilePanel.remove(myOpenFLFileChooserTextField);
  }
  final GridConstraints constraints = new GridConstraints();
  constraints.setRow(0);
  constraints.setFill(GridConstraints.FILL_HORIZONTAL);
  if (myHxmlFileRadioButton.isSelected() && !containsHxml) {
    myBuildFilePanel.add(myHxmlFileChooserPanel, constraints);
  }
  if (myNmmlFileRadioButton.isSelected() && !containsNME) {
    myBuildFilePanel.add(myNMEFilePanel, constraints);
  }
  if (myOpenFLFileRadioButton.isSelected() && !containsOpenFL) {
    myBuildFilePanel.add(myOpenFLFilePanel, constraints);
  }
}
 

实例 4


private void updateUserProperties() {
  boolean contains = false;
  Component[] components = myCompilerOptionsWrapper.getComponents();
  for (Component component : components) {
    if (component == myCompilerOptions) {
      contains = true;
      break;
    }
  }
  if (myUserPropertiesRadioButton.isSelected() && !contains) {
    final GridConstraints constraints = new GridConstraints();
    constraints.setRow(0);
    constraints.setFill(GridConstraints.FILL_HORIZONTAL);
    myCompilerOptionsWrapper.add(myCompilerOptions, constraints);
  }
  else if (!myUserPropertiesRadioButton.isSelected() && contains) {
    myCompilerOptionsWrapper.remove(myCompilerOptions);
  }
}
 

实例 5


private void initExtensions() {
  final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(myModule);
  final HaxeModuleConfigurationExtensionPoint[] extensionPoints = HaxeModuleConfigurationExtensionPoint.EP_NAME.getExtensions();
  if (extensionPoints.length > 0) {
    final GridLayoutManager layoutManager = new GridLayoutManager(extensionPoints.length, 1);
    myAdditionalComponentPanel.setLayout(layoutManager);
  }
  for (int i = 0; i < extensionPoints.length; i++) {
    HaxeModuleConfigurationExtensionPoint extensionPoint = extensionPoints[i];
    final GridConstraints gridConstraints = new GridConstraints();
    gridConstraints.setFill(GridConstraints.FILL_HORIZONTAL);
    gridConstraints.setRow(i);
    final UnnamedConfigurable configurable = extensionPoint.createConfigurable(settings);
    configurables.add(configurable);
    myAdditionalComponentPanel.add(configurable.createComponent(), gridConstraints);
  }
}
 

实例 6


private JPanel createItemDataPanel(AbstractDataPanel itemDataPanel, String title) {
    JPanel panel = new JPanel(new GridLayoutManager(1, 1));
    GridConstraints constraints = new GridConstraints();
    constraints.setFill(GridConstraints.FILL_BOTH);
    panel.add(itemDataPanel.getRootComponent(), constraints);
    panel.setBorder(BorderFactory.createTitledBorder(title));
    return panel;
}
 

实例 7


private GridConstraints createGridConstraints(boolean grab, int columnSpan) {
  GridConstraints gridConstraints = new GridConstraints();
  gridConstraints.setRow(componentNumber / COLUMN_COUNT);
  final int column = componentNumber % COLUMN_COUNT;
  gridConstraints.setColumn(column);
  if (grab) {
    gridConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW);
  }
  gridConstraints.setFill(GridConstraints.FILL_HORIZONTAL);
  gridConstraints.setColSpan(columnSpan);
  componentNumber += columnSpan;
  return gridConstraints;
}
 

实例 8


private static int addComponent(JComponent parent, JComponent component, int row, int column, boolean isLast) {
  GridConstraints gridConstraints = new GridConstraints();
  gridConstraints.setRow(row);
  gridConstraints.setColumn(column);
  boolean isGreedyComponent = component instanceof JTextField || component instanceof Spacer ||
                              component instanceof LabelWithEditLink || component instanceof TextAccessor ||
                              component instanceof EditorComboBox;
  int columnSpan = (isLast && isGreedyComponent) ? COLUMN_COUNT - column : 1;
  gridConstraints.setColSpan(columnSpan);
  gridConstraints.setAnchor(GridConstraints.ALIGN_LEFT);
  gridConstraints.setHSizePolicy(isGreedyComponent
                                 ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW
                                 : GridConstraints.SIZEPOLICY_CAN_SHRINK);
  gridConstraints.setVSizePolicy(component instanceof Spacer
                                 ? GridConstraints.SIZEPOLICY_CAN_GROW | GridConstraints.SIZEPOLICY_WANT_GROW
                                 : GridConstraints.SIZEPOLICY_FIXED);
  gridConstraints.setFill(GridConstraints.FILL_HORIZONTAL);
  parent.add(component, gridConstraints);
  if (isLast && !isGreedyComponent && column < COLUMN_COUNT - 1) {
    addComponent(parent, new Spacer(), row, column + 1, true);
  }
  return columnSpan;
}
 

实例 9


@Override
public void _init() {
  myParamContainer.removeAll();
  myPreferredFocusComponent = null;
  int row = 0;
  Collection<Parameter> parameters = myTemplateState.getTemplateMetadata().getParameters();
  myParamContainer.setLayout(new GridLayoutManager(parameters.size() + 1, 3));
  String packageName = null;
  if (myTemplateState.hasAttr(TemplateMetadata.ATTR_PACKAGE_NAME)) {
    packageName = myTemplateState.getString(TemplateMetadata.ATTR_PACKAGE_NAME);
  }
  GridConstraints c = new GridConstraints();
  c.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
  c.setAnchor(GridConstraints.ANCHOR_WEST);
  c.setFill(GridConstraints.FILL_HORIZONTAL);
  for (Parameter parameter : parameters) {
    if (myTemplateState.myHidden.contains(parameter.id)) {
      continue;
    }
    JLabel label = new JLabel(parameter.name);
    registerLabel(parameter.id, label);
    c.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW);
    c.setColumn(0);
    c.setColSpan(1);
    c.setRow(row++);
    Object value = myTemplateState.get(parameter.id) != null ? myTemplateState.get(parameter.id) : parameter.initial;
    myTemplateState.put(parameter.id, value);
    switch(parameter.type) {
      case SEPARATOR:
        c.setColSpan(3);
        JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
        myParamContainer.add(separator, c);
        break;
      case BOOLEAN:
        c.setColumn(1);
        JCheckBox checkBox = new JCheckBox(parameter.name);
        register(parameter.id, checkBox);
        myParamContainer.add(checkBox, c);
        if (myPreferredFocusComponent == null) {
          myPreferredFocusComponent = checkBox;
        }
        break;
      case ENUM:
        myParamContainer.add(label, c);
        JComboBox comboBox = new JComboBox();
        c.setColumn(1);
        populateComboBox(comboBox, parameter);
        register(parameter.id, comboBox);
        myParamContainer.add(comboBox, c);
        if (myPreferredFocusComponent == null) {
          myPreferredFocusComponent = comboBox;
        }
        break;
      case CUSTOM:
      case STRING:
        myParamContainer.add(label, c);
        c.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
        JTextField textField = new JTextField();
        c.setColumn(1);
        c.setColSpan(2);
        register(parameter.id, textField);
        myParamContainer.add(textField, c);
        if (myPreferredFocusComponent == null) {
          myPreferredFocusComponent = textField;
          textField.selectAll();
        }
        break;
      case EXTERNAL:
        final String url = parameter.sourceUrl;
        if (url == null) {
          break;
        }
        myParamContainer.add(label, c);
        c.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
        TextFieldWithLaunchBrowserButton externalField = new TextFieldWithLaunchBrowserButton(url);
        c.setColumn(1);
        c.setColSpan(2);
        register(parameter.id, externalField);
        myParamContainer.add(externalField, c);
        if (myPreferredFocusComponent == null) {
          myPreferredFocusComponent = externalField;
          externalField.getTextField().selectAll();
        }
        break;
    }
    updateVisibility(parameter);
  }
  update();
  deduplicateSuggestions(packageName);
  c.setFill(GridConstraints.FILL_HORIZONTAL);
  c.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
  c.setVSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
  c.setRow(row);
  c.setRowSpan(1);
  c.setColSpan(1);
  c.setColumn(2);
  Spacer spacer = new Spacer();
  myParamContainer.add(spacer, c);
  setDescriptionHtml(myTemplateState.getTemplateMetadata().getDescription());
}
 

实例 10


private void populateAdditionalFormFactors() {
  TemplateManager manager = TemplateManager.getInstance();
  List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
  GridLayoutManager gridLayoutManager = new GridLayoutManager(applicationTemplates.size() * 2 + 1, 2);
  gridLayoutManager.setVGap(5);
  gridLayoutManager.setHGap(10);
  myFormFactorPanel.setLayout(gridLayoutManager);
  GridConstraints c = new GridConstraints();
  c.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
  int row = 0;
  for (File templateFile : applicationTemplates) {
    TemplateMetadata metadata = manager.getTemplate(templateFile);
    if (metadata == null || metadata.getFormFactor() == null) {
      continue;
    }
    FormFactor formFactor = FormFactor.get(metadata.getFormFactor());
    if (formFactor == null) {
      continue;
    }
    myFormFactors.add(formFactor);
    c.setRow(row);
    c.setColumn(0);
    c.setFill(GridConstraints.FILL_NONE);
    c.setAnchor(GridConstraints.ANCHOR_WEST);
    JCheckBox inclusionCheckBox = new JCheckBox(formFactor.toString());
    myFormFactorPanel.add(inclusionCheckBox, c);
    register(FormFactorUtils.getInclusionKey(formFactor), inclusionCheckBox);
    FormFactorSdkControls controls = new FormFactorSdkControls(formFactor, metadata.getMinSdk());
    FormFactorApiComboBox minSdkComboBox = controls.getMinSdkCombo();
    minSdkComboBox.setName(formFactor.id + ".minSdk");
    controls.layout(myFormFactorPanel, ++row, inclusionCheckBox.getIconTextGap());
    minSdkComboBox.register(this);
    myFormFactorApiSelectors.put(formFactor, controls);
    // If we don't have any valid targets for the given form factor, disable that form factor
    if (minSdkComboBox.getItemCount() == 0) {
      inclusionCheckBox.setSelected(false);
      inclusionCheckBox.setEnabled(false);
      inclusionCheckBox.setText(inclusionCheckBox.getText() + " (Not Installed)");
    } else if (row == 1) {
      myState.put(FormFactorUtils.getInclusionKey(formFactor), true);
    }
    if (formFactor.equals(MOBILE)) {
      c.setRow(++row);
      c.setColumn(1);
      c.setAnchor(GridConstraints.ANCHOR_NORTHWEST);
      c.setFill(GridConstraints.FILL_NONE);
      myFormFactorPanel.add(myHelpMeChooseLabel, c);
    }
    row++;
  }
}
 
讨论
淘淘あ西西 profile image