Java Code Examples for com.intellij.util.ui.UIUtil#putClientProperty()

The following examples show how to use com.intellij.util.ui.UIUtil#putClientProperty() . 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: ExpandedItemListCellRendererWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean cellHasFocus) {
  GraphicsUtil.setAntialiasingType(list, AntialiasingTypeUtil.getAntialiasingTypeForSwingComponent());
  Component result = myWrappee.getListCellRendererComponent(list, UIUtil.htmlInjectionGuard(value), index, isSelected, cellHasFocus);
  if (!myHandler.getExpandedItems().contains(index)) return result;
  Rectangle bounds = result.getBounds();
  ExpandedItemRendererComponentWrapper wrapper = ExpandedItemRendererComponentWrapper.wrap(result);
  if (UIUtil.isClientPropertyTrue(list, ExpandableItemsHandler.EXPANDED_RENDERER)) {
    if (UIUtil.isClientPropertyTrue(result, ExpandableItemsHandler.USE_RENDERER_BOUNDS)) {
      wrapper.setBounds(bounds);
      UIUtil.putClientProperty(wrapper, ExpandableItemsHandler.USE_RENDERER_BOUNDS, true);
    }
  }
  wrapper.owner = list;
  return wrapper;
}
 
Example 2
Source File: Updater.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected Updater(@Nonnull Painter painter, JScrollBar bar) {
  myPainter = painter;
  myScrollBar = bar;
  myScrollBar.addMouseListener(myMouseAdapter);
  myScrollBar.addMouseMotionListener(myMouseAdapter);
  myQueue = new MergingUpdateQueue("ErrorStripeUpdater", 100, true, myScrollBar, this);
  UIUtil.putClientProperty(myScrollBar, ScrollBarUIConstants.TRACK, (g, x, y, width, height, object) -> {
    DaemonCodeAnalyzerSettings settings = DaemonCodeAnalyzerSettings.getInstance();
    myPainter.setMinimalThickness(settings == null ? 2 : Math.min(settings.ERROR_STRIPE_MARK_MIN_HEIGHT, JBUI.scale(4)));
    myPainter.setErrorStripeGap(1);
    if (myPainter instanceof ExtraErrorStripePainter) {
      ExtraErrorStripePainter extra = (ExtraErrorStripePainter)myPainter;
      extra.setGroupSwap(!myScrollBar.getComponentOrientation().isLeftToRight());
    }
    myPainter.paint(g, x, y, width, height, object);
  });
}
 
Example 3
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void restoreState() {
  TreeState state = myFileEditor == null ? null : myFileEditor.getUserData(STRUCTURE_VIEW_STATE_KEY);
  if (state == null) {
    if (!Boolean.TRUE.equals(UIUtil.getClientProperty(myTree, STRUCTURE_VIEW_STATE_RESTORED_KEY))) {
      TreeUtil.expand(getTree(), getMinimumExpandDepth(myTreeModel));
    }
  }
  else {
    UIUtil.putClientProperty(myTree, STRUCTURE_VIEW_STATE_RESTORED_KEY, true);
    state.applyTo(myTree);
    if (myFileEditor != null) {
      myFileEditor.putUserData(STRUCTURE_VIEW_STATE_KEY, null);
    }
  }
}
 
Example 4
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(@Nonnull Presentation presentation, @Nonnull String place) {
  JComponent component = new ActionButtonWithText(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE);
  UIUtil.putClientProperty(component, MnemonicHelper.MNEMONIC_CHECKER, keyCode -> KeyEvent.getExtendedKeyCodeForChar(TOGGLE) == keyCode || KeyEvent.getExtendedKeyCodeForChar(CHOOSE) == keyCode);

  MnemonicHelper.registerMnemonicAction(component, CHOOSE);
  InputMap map = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
  int mask = MnemonicHelper.getFocusAcceleratorKeyMask();
  map.put(KeyStroke.getKeyStroke(TOGGLE, mask, false), TOGGLE_ACTION_NAME);
  component.getActionMap().put(TOGGLE_ACTION_NAME, new AbstractAction() {
    @Override
    public void actionPerformed(ActionEvent e) {
      // mimic AnAction event invocation to trigger myEverywhereAutoSet=false logic
      DataContext dataContext = DataManager.getInstance().getDataContext(component);
      KeyEvent inputEvent = new KeyEvent(component, KeyEvent.KEY_PRESSED, e.getWhen(), MnemonicHelper.getFocusAcceleratorKeyMask(), KeyEvent.getExtendedKeyCodeForChar(TOGGLE), TOGGLE);
      AnActionEvent event = AnActionEvent.createFromAnAction(ScopeChooserAction.this, inputEvent, ActionPlaces.TOOLBAR, dataContext);
      ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
      actionManager.fireBeforeActionPerformed(ScopeChooserAction.this, dataContext, event);
      onProjectScopeToggled();
      actionManager.fireAfterActionPerformed(ScopeChooserAction.this, dataContext, event);
    }
  });
  return component;
}
 
Example 5
Source File: BigPopupUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
private JPanel createSuggestionsPanel() {
  JPanel pnl = new JPanel(new BorderLayout());
  pnl.setOpaque(false);
  pnl.setBorder(JBUI.Borders.customLine(JBUI.CurrentTheme.BigPopup.searchFieldBorderColor(), 1, 0, 0, 0));

  JScrollPane resultsScroll = new JBScrollPane(myResultsList);
  resultsScroll.setBorder(null);
  resultsScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  UIUtil.putClientProperty(resultsScroll.getVerticalScrollBar(), JBScrollPane.IGNORE_SCROLLBAR_IN_INSETS, true);

  resultsScroll.setPreferredSize(JBUI.size(670, JBUI.CurrentTheme.BigPopup.maxListHeight()));
  pnl.add(resultsScroll, BorderLayout.CENTER);

  myHintLabel = createHint();
  pnl.add(myHintLabel, BorderLayout.SOUTH);

  return pnl;
}
 
Example 6
Source File: TouchbarDataKeys.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static DlgButtonDesc putDialogButtonDescriptor(@Nonnull JButton button, int orderIndex, boolean isMainGroup) {
  DlgButtonDesc result = UIUtil.getClientProperty(button, DIALOG_BUTTON_DESCRIPTOR_KEY);
  if (result == null) UIUtil.putClientProperty(button, DIALOG_BUTTON_DESCRIPTOR_KEY, result = new DlgButtonDesc(orderIndex));
  result.setMainGroup(isMainGroup);
  return result;
}
 
Example 7
Source File: AnAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public final void registerCustomShortcutSet(@Nullable JComponent component, @Nullable consulo.disposer.Disposable parentDisposable) {
  if (component == null) return;
  List<AnAction> actionList = UIUtil.getClientProperty(component, ACTIONS_KEY);
  if (actionList == null) {
    UIUtil.putClientProperty(component, ACTIONS_KEY, actionList = new SmartList<>());
  }
  if (!actionList.contains(this)) {
    actionList.add(this);
  }

  if (parentDisposable != null) {
    Disposer.register(parentDisposable, () -> unregisterCustomShortcutSet(component));
  }
}
 
Example 8
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void storeState() {
  if (isDisposed() || !myProject.isOpen()) return;
  Object root = myTree.getModel().getRoot();
  if (root == null) return;
  TreeState state = TreeState.createOn(myTree, new TreePath(root));
  if (myFileEditor != null) {
    myFileEditor.putUserData(STRUCTURE_VIEW_STATE_KEY, state);
  }
  UIUtil.putClientProperty(myTree, STRUCTURE_VIEW_STATE_RESTORED_KEY, null);
}
 
Example 9
Source File: ActionUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void clearActions(@Nonnull JComponent component) {
  UIUtil.putClientProperty(component, AnAction.ACTIONS_KEY, null);
}
 
Example 10
Source File: JBLabel.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 *
 * In 'copyable' mode JBLabel has the same appearance but user can select text with mouse and copy it to clipboard with standard shortcut.
 * @return 'this' (the same instance)
 */
//
// By default JBLabel is NOT copyable
// This method re
public JBLabel setCopyable(boolean copyable) {
  if (copyable ^ myEditorPane != null) {
    if (myEditorPane == null) {
      final JLabel ellipsisLabel = new JBLabel("...");
      myIconLabel = new JLabel(getIcon());
      myEditorPane = new JEditorPane() {
        @Override
        public void paint(Graphics g) {
          Dimension size = getSize();
          boolean paintEllipsis = getPreferredSize().width > size.width && !myMultiline && !myAllowAutoWrapping;

          if (!paintEllipsis) {
            super.paint(g);
          }
          else {
            Dimension ellipsisSize = ellipsisLabel.getPreferredSize();
            int endOffset = size.width - ellipsisSize.width;
            try {
              // do not paint half of the letter
              endOffset = modelToView(viewToModel(new Point(endOffset, 0)) - 1).x;
            }
            catch (BadLocationException ignore) {
            }
            Shape oldClip = g.getClip();
            g.clipRect(0, 0, endOffset, size.height);

            super.paint(g);
            g.setClip(oldClip);

            g.translate(endOffset, 0);
            ellipsisLabel.setSize(ellipsisSize);
            ellipsisLabel.paint(g);
            g.translate(-endOffset, 0);
          }
        }
      };
      myEditorPane.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
          if (myEditorPane == null) return;
          int caretPosition = myEditorPane.getCaretPosition();
          myEditorPane.setSelectionStart(caretPosition);
          myEditorPane.setSelectionEnd(caretPosition);
        }
      });
      myEditorPane.setContentType("text/html");
      myEditorPane.setEditable(false);
      myEditorPane.setBackground(UIUtil.TRANSPARENT_COLOR);
      myEditorPane.setOpaque(false);
      myEditorPane.setBorder(null);
      UIUtil.putClientProperty(myEditorPane, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ellipsisLabel));

      myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
      updateStyle(myEditorPane);

      myEditorPane.setText(getText());
      checkMultiline();
      myEditorPane.setCaretPosition(0);
      updateLayout();
    } else {
      removeAll();
      myEditorPane = null;
      myIconLabel = null;
    }
  }
  return this;
}
 
Example 11
Source File: Updater.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void dispose() {
  myScrollBar.removeMouseListener(myMouseAdapter);
  myScrollBar.removeMouseMotionListener(myMouseAdapter);
  UIUtil.putClientProperty(myScrollBar, ScrollBarUIConstants.TRACK, null);
}
 
Example 12
Source File: LookupUi.java    From consulo with Apache License 2.0 4 votes vote down vote up
LookupUi(@Nonnull LookupImpl lookup, Advertiser advertiser, JBList list) {
  myLookup = lookup;
  myAdvertiser = advertiser;
  myList = list;

  myProcessIcon.setVisible(false);
  myLookup.resort(false);

  MenuAction menuAction = new MenuAction();
  menuAction.add(new ChangeSortingAction());
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) {
    @Override
    public void update(@Nonnull AnActionEvent e) {
      e.getPresentation().setVisible(!CodeInsightSettings.getInstance().AUTO_POPUP_JAVADOC_INFO);
    }
  });
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_IMPLEMENTATIONS)));

  Presentation presentation = new Presentation();
  presentation.setIcon(AllIcons.Actions.More);
  presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);

  myMenuButton = new ActionButton(menuAction, presentation, ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);

  AnAction hintAction = new HintAction();
  myHintButton = new ActionButton(hintAction, hintAction.getTemplatePresentation(), ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);
  myHintButton.setVisible(false);

  myBottomPanel = new NonOpaquePanel(new LookupBottomLayout());
  myBottomPanel.add(myAdvertiser.getAdComponent());
  myBottomPanel.add(myProcessIcon);
  myBottomPanel.add(myHintButton);
  myBottomPanel.add(myMenuButton);

  LookupLayeredPane layeredPane = new LookupLayeredPane();
  layeredPane.mainPanel.add(myBottomPanel, BorderLayout.SOUTH);

  myScrollPane = ScrollPaneFactory.createScrollPane(lookup.getList(), true);
  myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  UIUtil.putClientProperty(myScrollPane.getVerticalScrollBar(), JBScrollPane.IGNORE_SCROLLBAR_IN_INSETS, true);

  lookup.getComponent().add(layeredPane, BorderLayout.CENTER);

  layeredPane.mainPanel.add(myScrollPane, BorderLayout.CENTER);

  myModalityState = ModalityState.stateForComponent(lookup.getTopLevelEditor().getComponent());

  addListeners();

  Disposer.register(lookup, myProcessIcon);
  Disposer.register(lookup, myHintAlarm);
}