Java Code Examples for com.intellij.util.ui.JBInsets#addTo()

The following examples show how to use com.intellij.util.ui.JBInsets#addTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DarculaEditorTextFieldUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(JComponent c) {
  EditorTextField editorTextField = (EditorTextField)c;

  Editor editor = editorTextField.getEditor();

  Dimension size = JBUI.size(1, 10);
  if (editor != null) {
    size.height = editor.getLineHeight();

    size.height = Math.max(size.height, JBUIScale.scale(16));

    JBInsets.addTo(size, editorTextField.getInsets());
    JBInsets.addTo(size, editor.getInsets());
  }

  return size;
}
 
Example 2
Source File: ScreenUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void moveToFit(final Rectangle rectangle, final Rectangle container, @Nullable Insets padding) {
  Rectangle move = new Rectangle(rectangle);
  JBInsets.addTo(move, padding);

  if (move.getMaxX() > container.getMaxX()) {
    move.x = (int)container.getMaxX() - move.width;
  }


  if (move.getMinX() < container.getMinX()) {
    move.x = (int)container.getMinX();
  }

  if (move.getMaxY() > container.getMaxY()) {
    move.y = (int)container.getMaxY() - move.height;
  }

  if (move.getMinY() < container.getMinY()) {
    move.y = (int)container.getMinY();
  }

  JBInsets.removeFrom(move, padding);
  rectangle.setBounds(move);
}
 
Example 3
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void validate() {
  super.validate();
  DialogWrapper wrapper = myDialogWrapper.get();
  if (wrapper != null && wrapper.isAutoAdjustable()) {
    Window window = wrapper.getWindow();
    if (window != null) {
      Dimension size = getMinimumSize();
      if (!(size == null ? myLastMinimumSize == null : size.equals(myLastMinimumSize))) {
        // update window minimum size only if root pane minimum size is changed
        if (size == null) {
          myLastMinimumSize = null;
        }
        else {
          myLastMinimumSize = new Dimension(size);
          JBInsets.addTo(size, window.getInsets());
        }
        window.setMinimumSize(size);
      }
    }
  }
}
 
Example 4
Source File: ColorPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  if (isPreferredSizeSet()) {
    return super.getPreferredSize();
  }
  Dimension size = myTextField.getPreferredSize();
  JBInsets.addTo(size, getInsets());
  return size;
}
 
Example 5
Source File: BasicEditorTextFieldUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getMinimumSize(JComponent c) {
  EditorTextField editorTextField = (EditorTextField)c;
  Editor editor = editorTextField.getEditor();
  Dimension size = new Dimension(1, 20);
  if (editor != null) {
    size.height = editor.getLineHeight();

    JBInsets.addTo(size, editorTextField.getInsets());
    JBInsets.addTo(size, editor.getInsets());
  }

  return size;
}
 
Example 6
Source File: TextFieldWithPopupHandlerUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void updatePreferredSize(JComponent c, Dimension size) {
  if (!isUnderComboBox(c)) {
    JBInsets.addTo(size, ((JTextComponent)c).getMargin());
    size.height = Math.max(size.height, getMinimumHeight(size.height));
    size.width = Math.max(size.width, DarculaUIUtil.MINIMUM_WIDTH.get());
  }
}
 
Example 7
Source File: BreadcrumbsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  Graphics2D g2 = (Graphics2D)GraphicsUtil.safelyGetGraphics(this);
  Dimension dim = new Dimension(Integer.MAX_VALUE, g2 != null ? DEFAULT_PAINTER.getSize("DUMMY", g2.getFontMetrics(), Integer.MAX_VALUE).height + 1 : 1);
  JBInsets.addTo(dim, getInsets());
  return dim;
}
 
Example 8
Source File: EditorComboBox.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  if (UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula()) {
    return super.getPreferredSize();
  }
  if (myEditorField != null) {
    final Dimension preferredSize = new Dimension(myEditorField.getComponent().getPreferredSize());
    JBInsets.addTo(preferredSize, getInsets());
    return preferredSize;
  }

  //final int cbHeight = new JComboBox().getPreferredSize().height; // should be used actually
  return new Dimension(100, UIUtil.fixComboBoxHeight(20));
}
 
Example 9
Source File: EditorTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  if (isPreferredSizeSet()) {
    return super.getPreferredSize();
  }

  boolean toReleaseEditor = false;
  if (myEditor == null && myEnsureWillComputePreferredSize) {
    myEnsureWillComputePreferredSize = false;
    initEditor();
    toReleaseEditor = true;
  }


  Dimension size = new Dimension(100, 20);
  if (myEditor != null) {
    final Dimension preferredSize = new Dimension(myEditor.getComponent().getPreferredSize());

    if (myPreferredWidth != -1) {
      preferredSize.width = myPreferredWidth;
    }

    JBInsets.addTo(preferredSize, getInsets());
    size = preferredSize;
  }
  else if (myPassivePreferredSize != null) {
    size = myPassivePreferredSize;
  }

  if (toReleaseEditor) {
    releaseEditor(myEditor);
    myEditor = null;
    myPassivePreferredSize = size;
  }

  return size;
}
 
Example 10
Source File: Breadcrumbs.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension preferredLayoutSize(Container container) {
  Dimension size = new Dimension();
  if (container instanceof Breadcrumbs) {
    Breadcrumbs breadcrumbs = (Breadcrumbs)container;
    breadcrumbs.updatePreferredSize(size, breadcrumbs.getScale());
  }
  JBInsets.addTo(size, container.getInsets());
  return size;
}
 
Example 11
Source File: SeparatorWithText.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Dimension getPreferredFontSize() {
  Dimension size = new Dimension(myPrefWidth < 0 ? 0 : myPrefWidth, 1);
  String caption = getCaption();
  if (caption != null) {
    FontMetrics fm = getFontMetrics(getFont());
    size.height = fm.getHeight();
    if (myPrefWidth < 0) {
      size.width = 2 * getHgap() + fm.stringWidth(caption);
    }
  }
  JBInsets.addTo(size, getInsets());
  return size;
}
 
Example 12
Source File: SearchTextField.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  Dimension size = super.getPreferredSize();
  Border border = super.getBorder();
  if (border != null && UIUtil.isUnderAquaLookAndFeel()) {
    JBInsets.addTo(size, border.getBorderInsets(this));
  }
  return size;
}
 
Example 13
Source File: Advertiser.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Dimension minimumLayoutSize(Container parent) {
  Dimension minSize = myNextLabel.getPreferredSize();
  JBInsets.addTo(minSize, parent.getInsets());
  return minSize;
}
 
Example 14
Source File: SearchEverywhereManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void show(@Nonnull String contributorID, @Nullable String searchText, @Nonnull AnActionEvent initEvent) {
  if (isShown()) {
    throw new IllegalStateException("Method should cannot be called whe popup is shown");
  }

  Project project = initEvent.getProject();
  Component contextComponent = initEvent.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  List<SearchEverywhereContributor<?>> serviceContributors = Collections.EMPTY_LIST;
  Arrays.asList(//new TopHitSEContributor(project, contextComponent, s -> mySearchEverywhereUI.getSearchField().setValue(s)),
                new RecentFilesSEContributor(project, GotoActionBase.getPsiContext(initEvent)),
                new RunConfigurationsSEContributor(project, contextComponent, () -> mySearchEverywhereUI.getSearchField().getValue()));
  List<SearchEverywhereContributor<?>> contributors = new ArrayList<>(serviceContributors);
  for (SearchEverywhereContributorFactory<?> factory : SearchEverywhereContributor.EP_NAME.getExtensionList()) {
    contributors.add(factory.createContributor(initEvent));
  }
  Collections.sort(contributors, Comparator.comparingInt(SearchEverywhereContributor::getSortWeight));

  mySearchEverywhereUI = createView(myProject, contributors);
  mySearchEverywhereUI.switchToContributor(contributorID);

  myHistoryIterator = myHistoryList.getIterator(contributorID);
  //history could be suppressed by user for some reasons (creating promo video, conference demo etc.)
  boolean suppressHistory = "true".equals(System.getProperty("idea.searchEverywhere.noHistory", "false"));
  //or could be suppressed just for All tab in registry
  suppressHistory = suppressHistory || (ALL_CONTRIBUTORS_GROUP_ID.equals(contributorID) && Registry.is("search.everywhere.disable.history.for.all"));

  if (searchText == null && !suppressHistory) {
    searchText = myHistoryIterator.prev();
  }

  if (searchText != null && !searchText.isEmpty()) {
    mySearchEverywhereUI.getSearchField().setValue(searchText);
    mySearchEverywhereUI.getSearchField().selectAll();
  }

  myBalloon =
          JBPopupFactory.getInstance().createComponentPopupBuilder(mySearchEverywhereUI, (JComponent)TargetAWT.to(mySearchEverywhereUI.getSearchField())).setProject(myProject).setModalContext(false)
                  .setCancelOnClickOutside(true).setRequestFocus(true).setCancelKeyEnabled(false).setCancelCallback(() -> {
            saveSearchText();
            return true;
          }).addUserData("SIMPLE_WINDOW").setResizable(true).setMovable(true).setDimensionServiceKey(project, LOCATION_SETTINGS_KEY, true).setLocateWithinScreenBounds(false).createPopup();
  Disposer.register(myBalloon, mySearchEverywhereUI);
  if (project != null) {
    Disposer.register(project, myBalloon);
  }

  Dimension size = mySearchEverywhereUI.getMinimumSize();
  JBInsets.addTo(size, myBalloon.getContent().getInsets());
  myBalloon.setMinimumSize(size);

  myProject.putUserData(SEARCH_EVERYWHERE_POPUP, myBalloon);
  Disposer.register(myBalloon, () -> {
    saveSize();
    myProject.putUserData(SEARCH_EVERYWHERE_POPUP, null);
    mySearchEverywhereUI = null;
    myBalloon = null;
    myBalloonFullSize = null;
  });

  if (mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) {
    myBalloonFullSize = WindowStateService.getInstance(myProject).getSize(LOCATION_SETTINGS_KEY);
    Dimension prefSize = mySearchEverywhereUI.getPreferredSize();
    myBalloon.setSize(prefSize);
  }
  calcPositionAndShow(project, myBalloon);
}
 
Example 15
Source File: RunAnythingManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void show(@Nullable String searchText, boolean selectSearchText, @Nonnull AnActionEvent initEvent) {
  IdeEventQueue.getInstance().getPopupManager().closeAllPopups(false);

  Project project = initEvent.getProject();

  myRunAnythingUI = createView(initEvent);

  if (searchText != null && !searchText.isEmpty()) {
    myRunAnythingUI.getSearchField().setValue(searchText);
  }
  if (selectSearchText) {
    myRunAnythingUI.getSearchField().selectAll();
  }

  predefineSelectedText(searchText);

  myBalloon = JBPopupFactory.getInstance().createComponentPopupBuilder(myRunAnythingUI, (JComponent)TargetAWT.to(myRunAnythingUI.getSearchField())).setProject(myProject).setModalContext(false)
          .setCancelOnClickOutside(true).setRequestFocus(true).setCancelKeyEnabled(false).setCancelCallback(() -> {
            saveSearchText();
            return true;
          }).addUserData("SIMPLE_WINDOW").setResizable(true).setMovable(true).setDimensionServiceKey(myProject, LOCATION_SETTINGS_KEY, true).setLocateWithinScreenBounds(false).createPopup();
  Disposer.register(myBalloon, myRunAnythingUI);
  if (project != null) {
    Disposer.register(project, myBalloon);
  }

  Dimension size = myRunAnythingUI.getMinimumSize();
  JBInsets.addTo(size, myBalloon.getContent().getInsets());
  myBalloon.setMinimumSize(size);

  Disposer.register(myBalloon, () -> {
    saveSize();
    myRunAnythingUI = null;
    myBalloon = null;
    myBalloonFullSize = null;
  });

  if (myRunAnythingUI.getViewType() == RunAnythingPopupUI.ViewType.SHORT) {
    myBalloonFullSize = WindowStateService.getInstance(myProject).getSize(LOCATION_SETTINGS_KEY);
    Dimension prefSize = myRunAnythingUI.getPreferredSize();
    myBalloon.setSize(prefSize);
  }
  calcPositionAndShow(project, myBalloon);
}
 
Example 16
Source File: DiffUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
private Dimension addInsets(Dimension dimension) {
  JBInsets.addTo(dimension, getInsets());
  return dimension;
}
 
Example 17
Source File: IntelliJExpandableSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected Content prepare(@Nonnull Source field, @Nonnull Function<? super String, String> onShow) {
  Font font = field.getFont();
  FontMetrics metrics = font == null ? null : field.getFontMetrics(font);
  int height = metrics == null ? 16 : metrics.getHeight();
  Dimension size = new Dimension(height * 32, height * 16);

  JTextArea area = new JTextArea(onShow.fun(field.getText()));
  area.putClientProperty(Expandable.class, this);
  area.setEditable(field.isEditable());
  area.setBackground(field.getBackground());
  area.setForeground(field.getForeground());
  area.setFont(font);
  area.setWrapStyleWord(true);
  area.setLineWrap(true);
  copyCaretPosition(field, area);
  UIUtil.addUndoRedoActions(area);

  JLabel label = ExpandableSupport.createLabel(createCollapseExtension());
  label.setBorder(JBUI.Borders.empty(5, 0, 5, 5));

  JBScrollPane pane = new JBScrollPane(area);
  pane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
  pane.getVerticalScrollBar().add(JBScrollBar.LEADING, label);
  pane.getVerticalScrollBar().setBackground(area.getBackground());

  Insets insets = field.getInsets();
  Insets margin = field.getMargin();
  if (margin != null) {
    insets.top += margin.top;
    insets.left += margin.left;
    insets.right += margin.right;
    insets.bottom += margin.bottom;
  }

  JBInsets.addTo(size, insets);
  JBInsets.addTo(size, pane.getInsets());
  pane.setPreferredSize(size);
  pane.setViewportBorder(insets != null ? createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right) : createEmptyBorder());
  return new Content() {
    @Nonnull
    @Override
    public JComponent getContentComponent() {
      return pane;
    }

    @Override
    public JComponent getFocusableComponent() {
      return area;
    }

    @Override
    public void cancel(@Nonnull Function<? super String, String> onHide) {
      if (field.isEditable()) {
        field.setText(onHide.fun(area.getText()));
        copyCaretPosition(area, field);
      }
    }
  };
}