private JComponent buildTopPanel(boolean enablePipette) throws ParseException {
    final JPanel result = new JPanel(new BorderLayout());

    final JPanel previewPanel = new JPanel(new BorderLayout());
    if (enablePipette && myPicker != null) {
      final JButton pipette = new JButton();
      pipette.setUI(new BasicButtonUI());
      pipette.setRolloverEnabled(true);
      pipette.setIcon(AllIcons.Ide.Pipette);
      pipette.setBorder(IdeBorderFactory.createEmptyBorder());
      pipette.setRolloverIcon(AllIcons.Ide.Pipette_rollover);
      pipette.setFocusable(false);
      pipette.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              myPicker.setInitialColor(getColor());
              myPicker.show();
            }
          });
      previewPanel.add(pipette, BorderLayout.WEST);
    }

    myPreviewComponent = new ColorPreviewComponent();
    previewPanel.add(myPreviewComponent, BorderLayout.CENTER);

    result.add(previewPanel, BorderLayout.NORTH);

    final JPanel rgbPanel = new JPanel();
    rgbPanel.setLayout(new BoxLayout(rgbPanel, BoxLayout.X_AXIS));
    if (!UIUtil.isUnderAquaLookAndFeel()) {
      myR_after.setPreferredSize(new Dimension(14, -1));
      myG_after.setPreferredSize(new Dimension(14, -1));
      myB_after.setPreferredSize(new Dimension(14, -1));
    }
    rgbPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
    rgbPanel.add(myR);
    rgbPanel.add(myRed);
    if (!UIUtil.isUnderAquaLookAndFeel()) rgbPanel.add(myR_after);
    rgbPanel.add(Box.createHorizontalStrut(2));
    rgbPanel.add(myG);
    rgbPanel.add(myGreen);
    if (!UIUtil.isUnderAquaLookAndFeel()) rgbPanel.add(myG_after);
    rgbPanel.add(Box.createHorizontalStrut(2));
    rgbPanel.add(myB);
    rgbPanel.add(myBlue);
    if (!UIUtil.isUnderAquaLookAndFeel()) rgbPanel.add(myB_after);
    rgbPanel.add(Box.createHorizontalStrut(2));
    rgbPanel.add(myFormat);

    result.add(rgbPanel, BorderLayout.WEST);

    final JPanel hexPanel = new JPanel();
    hexPanel.setLayout(new BoxLayout(hexPanel, BoxLayout.X_AXIS));
    hexPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
    hexPanel.add(new JLabel("#"));
    hexPanel.add(myHex);

    result.add(hexPanel, BorderLayout.EAST);

    return result;
  }
  @NotNull
  protected List<Pair<String, JPanel>> createAdditionalPanels() {
    // this method is invoked before constructor body
    myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
    myExceptionsModel.setTypeInfos(myMethod.getMethod());

    final JBTable table = new JBTable(myExceptionsModel);
    table.setStriped(true);
    table.setRowHeight(20);
    table
        .getColumnModel()
        .getColumn(0)
        .setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    final JavaCodeFragmentTableCellEditor cellEditor =
        new JavaCodeFragmentTableCellEditor(myProject);
    cellEditor.addDocumentListener(
        new DocumentAdapter() {
          @Override
          public void documentChanged(DocumentEvent e) {
            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();
            myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
            updateSignature();
          }
        });
    table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().setSelectionInterval(0, 0);
    table.setSurrendersFocusOnKeystroke(true);

    myPropExceptionsButton =
        new AnActionButton(
            RefactoringBundle.message("changeSignature.propagate.exceptions.title"),
            null,
            PlatformIcons.NEW_EXCEPTION) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<JavaCallerChooser>();
            Consumer<Set<PsiMethod>> callback =
                new Consumer<Set<PsiMethod>>() {
                  @Override
                  public void consume(Set<PsiMethod> psiMethods) {
                    myMethodsToPropagateExceptions = psiMethods;
                    myExceptionPropagationTree = chooser.get().getTree();
                  }
                };
            chooser.set(
                new JavaCallerChooser(
                    myMethod.getMethod(),
                    myProject,
                    RefactoringBundle.message("changeSignature.exception.caller.chooser"),
                    myExceptionPropagationTree,
                    callback));
            chooser.get().show();
          }
        };
    myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));

    final JPanel panel =
        ToolbarDecorator.createDecorator(table)
            .addExtraAction(myPropExceptionsButton)
            .createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder(0));

    myExceptionsModel.addTableModelListener(mySignatureUpdater);

    final ArrayList<Pair<String, JPanel>> result = new ArrayList<Pair<String, JPanel>>();
    final String message =
        RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
  }
Exemple #3
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);
        }
      }
    }
  }