コード例 #1
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (UIUtil.isUnderDarcula() && false) { // todo[kb] fix DarculaTextBorder
     g.setColor(myTextField.getBackground());
     g.fillRect(2, 3, getWidth(), getHeight() - 5);
   }
 }
コード例 #2
0
  public SearchTextField(boolean historyEnabled) {
    super(new BorderLayout());

    myModel = new MyModel();

    myTextField =
        new TextFieldWithProcessing() {
          @Override
          public void processKeyEvent(final KeyEvent e) {
            if (preprocessEventForTextField(e)) return;
            super.processKeyEvent(e);
          }

          @Override
          public void setBackground(final Color bg) {
            super.setBackground(bg);
            if (!hasIconsOutsideOfTextField()) {
              if (myClearFieldLabel != null) {
                myClearFieldLabel.setBackground(bg);
              }
            }
            if (myToggleHistoryLabel != null) {
              myToggleHistoryLabel.setBackground(bg);
            }
          }
        };
    myTextField.setColumns(15);
    myTextField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onFocusLost();
            super.focusLost(e);
          }

          @Override
          public void focusGained(FocusEvent e) {
            onFocusGained();
            super.focusGained(e);
          }
        });
    add(myTextField, BorderLayout.CENTER);
    myTextField.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              if (hasNativeLeopardSearchControl() && myNativeSearchPopup != null) {
                myNativeSearchPopup.show(myTextField, 5, myTextField.getHeight());
              } else if (myPopup == null || !myPopup.isVisible()) {
                showPopup();
              }
            }
          }
        });

    if (hasNativeLeopardSearchControl() || UIUtil.isUnderDarcula()) {
      myTextField.putClientProperty("JTextField.variant", "search");
    }
    if (hasNativeLeopardSearchControl()) {
      if (historyEnabled) {
        myNativeSearchPopup = new JBPopupMenu();
        myNoItems = new JBMenuItem("No recent searches");
        myNoItems.setEnabled(false);

        updateMenu();
        myTextField.putClientProperty("JTextField.Search.FindPopup", myNativeSearchPopup);
      }
    } else {
      myToggleHistoryLabel = new JLabel(AllIcons.Actions.Search);
      myToggleHistoryLabel.setOpaque(true);
      myToggleHistoryLabel.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              togglePopup();
            }
          });
      if (historyEnabled) {
        add(myToggleHistoryLabel, BorderLayout.WEST);
      }

      myClearFieldLabel =
          new JLabel(
              UIUtil.isUnderDarcula() ? AllIcons.Actions.Clean : AllIcons.Actions.CleanLight);
      myClearFieldLabel.setOpaque(true);
      add(myClearFieldLabel, BorderLayout.EAST);
      myClearFieldLabel.addMouseListener(
          new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
              myTextField.setText("");
              onFieldCleared();
            }
          });

      if (!hasIconsOutsideOfTextField()) {
        final Border originalBorder;
        if (SystemInfo.isMac) {
          originalBorder = BorderFactory.createLoweredBevelBorder();
        } else {
          originalBorder = myTextField.getBorder();
        }

        myToggleHistoryLabel.setBackground(myTextField.getBackground());
        myClearFieldLabel.setBackground(myTextField.getBackground());

        setBorder(
            new CompoundBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0), originalBorder));

        myTextField.setOpaque(true);
        myTextField.setBorder(IdeBorderFactory.createEmptyBorder(0, 5, 0, 5));
      } else {
        setBorder(IdeBorderFactory.createEmptyBorder(2, 0, 2, 0));
      }
    }

    if (ApplicationManager.getApplication() != null) { // tests
      final ActionManager actionManager = ActionManager.getInstance();
      if (actionManager != null) {
        final AnAction clearTextAction = actionManager.getAction(IdeActions.ACTION_CLEAR_TEXT);
        if (clearTextAction.getShortcutSet().getShortcuts().length == 0) {
          clearTextAction.registerCustomShortcutSet(CommonShortcuts.ESCAPE, this);
        }
      }
    }
  }
コード例 #3
0
 public final void keyEventToTextField(KeyEvent e) {
   myTextField.processKeyEvent(e);
 }
コード例 #4
0
 public boolean requestFocusInWindow() {
   return myTextField.requestFocusInWindow();
 }