コード例 #1
0
  @Override
  protected void init() {
    super.init();

    myPanel.setLayout(new GridBagLayout());
    initTables();

    myTreeTable = createOptionsTree(getSettings());
    myTreeTable.setBackground(UIUtil.getPanelBackground());
    myTreeTable.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    JBScrollPane scrollPane =
        new JBScrollPane(myTreeTable) {
          @Override
          public Dimension getMinimumSize() {
            return super.getPreferredSize();
          }
        };
    myPanel.add(
        scrollPane,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            JBUI.emptyInsets(),
            0,
            0));

    final JPanel previewPanel = createPreviewPanel();
    myPanel.add(
        previewPanel,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            JBUI.emptyInsets(),
            0,
            0));

    installPreviewPanel(previewPanel);
    addPanelToWatch(myPanel);

    isFirstUpdate = false;
    customizeSettings();
  }
コード例 #2
0
  @NotNull
  public final synchronized Dimension computePreferredSize(final boolean mainTextOnly) {
    // Calculate width
    int width = myIpad.left;

    if (myIcon != null) {
      width += myIcon.getIconWidth() + myIconTextGap;
    }

    final Insets borderInsets =
        myBorder != null ? myBorder.getBorderInsets(this) : JBUI.emptyInsets();
    width += borderInsets.left;

    Font font = getBaseFont();
    LOG.assertTrue(font != null);

    width += computeTextWidth(font, mainTextOnly);
    width += myIpad.right + borderInsets.right;

    // Calculate height
    int height = myIpad.top + myIpad.bottom;

    final FontMetrics metrics = getFontMetrics(font);
    int textHeight = Math.max(JBUI.scale(16), metrics.getHeight()); // avoid too narrow rows
    textHeight += borderInsets.top + borderInsets.bottom;

    if (myIcon != null) {
      height += Math.max(myIcon.getIconHeight(), textHeight);
    } else {
      height += textHeight;
    }

    // Take into account that the component itself can have a border
    final Insets insets = getInsets();
    if (insets != null) {
      width += insets.left + insets.right;
      height += insets.top + insets.bottom;
    }

    return new Dimension(width, height);
  }
コード例 #3
0
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.weightx = 1;
    gbConstraints.weighty = 0;
    gbConstraints.gridwidth = 1;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = 0;
    gbConstraints.insets = JBUI.emptyInsets();

    if (myOccurrencesCount > 1) {
      myCbReplaceAll = new NonFocusableCheckBox();
      myCbReplaceAll.setText(
          RefactoringBundle.message("replace.all.occurences", myOccurrencesCount));

      panel.add(myCbReplaceAll, gbConstraints);
      myReplaceAllListener =
          new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
              updateControls();
            }
          };
      myCbReplaceAll.addItemListener(myReplaceAllListener);

      if (myAnyLValueOccurences) {
        myCbReplaceWrite = new StateRestoringCheckBox();
        myCbReplaceWrite.setText(RefactoringBundle.message("replace.write.access.occurrences"));
        gbConstraints.insets = JBUI.insetsLeft(8);
        gbConstraints.gridy++;
        panel.add(myCbReplaceWrite, gbConstraints);
        myCbReplaceWrite.addItemListener(myReplaceAllListener);
      }
    }

    myCbFinal = new NonFocusableCheckBox();
    myCbFinal.setText(RefactoringBundle.message("declare.final"));
    final Boolean createFinals =
        JavaRefactoringSettings.getInstance().INTRODUCE_LOCAL_CREATE_FINALS;
    myCbFinalState =
        createFinals == null
            ? CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_LOCALS
            : createFinals.booleanValue();

    gbConstraints.insets = JBUI.emptyInsets();
    gbConstraints.gridy++;
    panel.add(myCbFinal, gbConstraints);
    myFinalListener =
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (myCbFinal.isEnabled()) {
              myCbFinalState = myCbFinal.isSelected();
            }
          }
        };
    myCbFinal.addItemListener(myFinalListener);

    updateControls();

    return panel;
  }