void update() {
   for (int i = 0; i < getComponentCount(); ++i) {
     Component component = getComponent(i);
     if (component instanceof JButton) {
       final JButton button = (JButton) component;
       button.setEnabled(!isSearchInProgress());
     }
   }
 }
Exemplo n.º 2
0
 private void moveMousePointerOnButton(final JButton button) {
   Application application = ApplicationManager.getApplication();
   if (application != null && application.hasComponent(UISettings.class)) {
     if (button != null && UISettings.getInstance().MOVE_MOUSE_ON_DEFAULT_BUTTON) {
       Point p = button.getLocationOnScreen();
       Rectangle r = button.getBounds();
       try {
         Robot robot = new Robot();
         robot.mouseMove(p.x + r.width / 2, p.y + r.height / 2);
       } catch (AWTException e) {
         LOG.warn(e);
       }
     }
   }
 }
 @Override
 public void removeNotify() {
   if (myButtonSynchronizer != null) {
     myPresentation.removePropertyChangeListener(myButtonSynchronizer);
     myButtonSynchronizer = null;
   }
   super.removeNotify();
 }
 @Override
 public void addNotify() {
   super.addNotify();
   if (myButtonSynchronizer == null) {
     myButtonSynchronizer = new MyButtonSynchronizer();
     myPresentation.addPropertyChangeListener(myButtonSynchronizer);
   }
   initButton();
 }
  private JComponent createActionsPanel() {
    final JButton include = new JButton(IdeBundle.message("button.include"));
    final JButton includeRec = new JButton(IdeBundle.message("button.include.recursively"));
    final JButton exclude = new JButton(IdeBundle.message("button.exclude"));
    final JButton excludeRec = new JButton(IdeBundle.message("button.exclude.recursively"));
    myPackageTree
        .getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {
              @Override
              public void valueChanged(TreeSelectionEvent e) {
                final boolean recursiveEnabled = isButtonEnabled(true, e.getPaths(), e);
                includeRec.setEnabled(recursiveEnabled);
                excludeRec.setEnabled(recursiveEnabled);

                final boolean nonRecursiveEnabled = isButtonEnabled(false, e.getPaths(), e);
                include.setEnabled(nonRecursiveEnabled);
                exclude.setEnabled(nonRecursiveEnabled);
              }
            });

    JPanel buttonsPanel = new JPanel(new VerticalFlowLayout());
    buttonsPanel.add(include);
    buttonsPanel.add(includeRec);
    buttonsPanel.add(exclude);
    buttonsPanel.add(excludeRec);

    include.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            includeSelected(false);
          }
        });
    includeRec.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            includeSelected(true);
          }
        });
    exclude.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            excludeSelected(false);
          }
        });
    excludeRec.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            excludeSelected(true);
          }
        });

    return buttonsPanel;
  }
  public AvailablePluginsManagerMain(
      PluginManagerMain installed, PluginManagerUISettings uiSettings, String vendorFilter) {
    super(uiSettings);
    this.installed = installed;
    myVendorFilter = vendorFilter;
    init();
    final JButton manageRepositoriesBtn = new JButton(MANAGE_REPOSITORIES);
    if (myVendorFilter == null) {
      manageRepositoriesBtn.setMnemonic('m');
      manageRepositoriesBtn.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (ShowSettingsUtil.getInstance()
                  .editConfigurable(myActionsPanel, new PluginHostsConfigurable())) {
                final ArrayList<String> pluginHosts = UpdateSettings.getInstance().myPluginHosts;
                if (!pluginHosts.contains(
                    ((AvailablePluginsTableModel) pluginsModel).getRepository())) {
                  ((AvailablePluginsTableModel) pluginsModel)
                      .setRepository(
                          AvailablePluginsTableModel.ALL, myFilter.getFilter().toLowerCase());
                }
                loadAvailablePlugins();
              }
            }
          });
      myActionsPanel.add(manageRepositoriesBtn, BorderLayout.EAST);
    }

    final JButton httpProxySettingsButton =
        new JButton(IdeBundle.message("button.http.proxy.settings"));
    httpProxySettingsButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            HTTPProxySettingsDialog settingsDialog = new HTTPProxySettingsDialog();
            settingsDialog.pack();
            settingsDialog.show();
            if (settingsDialog.isOK()) {
              loadAvailablePlugins();
            }
          }
        });
    myActionsPanel.add(httpProxySettingsButton, BorderLayout.WEST);
  }
 @Override
 public void updateUI() {
   super.updateUI();
   // putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);
   if (UIUtil.isMotifLookAndFeel()) {
     setBorder(BorderFactory.createEtchedBorder());
   } else if (!UIUtil.isUnderGTKLookAndFeel()) {
     setBorder(UIUtil.getButtonBorder());
   }
 }
    public void addButtonRunnable(int index, final Runnable runnable, String text) {
      if (getBorder() == null) setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));

      final JButton button = new JButton(UIUtil.replaceMnemonicAmpersand(text));
      DialogUtil.registerMnemonic(button);

      button.setFocusable(false);
      button.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              runnable.run();
            }
          });

      add(button, index);

      invalidate();
      if (getParent() != null) {
        getParent().validate();
      }
    }
    private void doPaint(Graphics g) {
      GraphicsUtil.setupAntialiasing(g);

      final boolean isEmpty = getIcon() == null && StringUtil.isEmpty(getText());
      final Dimension size = getSize();
      if (isSmallVariant()) {
        final Graphics2D g2 = (Graphics2D) g;
        g2.setColor(UIUtil.getControlColor());
        final int w = getWidth();
        final int h = getHeight();
        if (getModel().isArmed() && getModel().isPressed()) {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getControlColor(),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.8)));
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  ColorUtil.shift(UIUtil.getControlColor(), 1.1),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.9)));
        }
        g2.fillRect(2, 0, w - 2, h);
        GraphicsUtil.setupAntialiasing(g2);
        if (!myMouseInside) {
          g2.setPaint(
              new GradientPaint(
                  0, 0, UIUtil.getBorderColor(), 0, h, UIUtil.getBorderColor().darker()));
          // g2.setColor(UIUtil.getBorderColor());
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getBorderColor().darker(),
                  0,
                  h,
                  UIUtil.getBorderColor().darker().darker()));
        }
        g2.drawRect(2, 0, w - 3, h - 1);
        final Icon icon = getIcon();
        int x = 7;
        if (icon != null) {
          icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
          x += icon.getIconWidth() + 3;
        }
        if (!StringUtil.isEmpty(getText())) {
          final Font font = getFont();
          g2.setFont(font);
          g2.setColor(UIManager.getColor("Panel.foreground"));
          g2.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
        }
      } else {
        super.paintComponent(g);
      }
      final Insets insets = super.getInsets();
      final Icon icon = isEnabled() ? ARROW_ICON : DISABLED_ARROW_ICON;
      final int x;
      if (isEmpty) {
        x = (size.width - icon.getIconWidth()) / 2;
      } else {
        if (isSmallVariant()) {
          x = size.width - icon.getIconWidth() - insets.right + 1;
        } else {
          x =
              size.width
                  - icon.getIconWidth()
                  - insets.right
                  + (UIUtil.isUnderNimbusLookAndFeel() ? -3 : 2);
        }
      }
      if (UIUtil.isUnderDarcula()) {
        g.setXORMode(new Color(208, 188, 159));
      }
      icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
      g.setPaintMode();
    }
Exemplo n.º 10
0
  private void initReplaceToolBars() {
    DefaultActionGroup actionGroup1 = new DefaultActionGroup("replace bar 1", false);
    myReplaceActionsToolbar1 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
    myReplaceActionsToolbar1.setForceMinimumSize(true);
    final JButton myReplaceButton = new JButton("Replace");
    myReplaceButton.setFocusable(false);
    myReplaceButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            replaceCurrent();
          }
        });

    final JButton myReplaceAllButton = new JButton("Replace all");
    myReplaceAllButton.setFocusable(false);
    myReplaceAllButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.performReplaceAll();
          }
        });

    final JButton myExcludeButton = new JButton("");
    myExcludeButton.setFocusable(false);
    myExcludeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            myLivePreviewController.exclude();
            moveCursor(SearchResults.Direction.DOWN);
          }
        });

    if (!UISettings.getInstance().DISABLE_MNEMONICS_IN_CONTROLS) {
      myReplaceButton.setMnemonic('p');
      myReplaceAllButton.setMnemonic('a');
      myExcludeButton.setMnemonic('l');
    }

    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceButton.setEnabled(canReplaceCurrent());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myReplaceAllButton) {
          @Override
          public void update(AnActionEvent e) {
            myReplaceAllButton.setEnabled(mySearchResults != null && mySearchResults.hasMatches());
          }
        });
    actionGroup1.addAction(
        new DefaultCustomComponentAction(myExcludeButton) {
          @Override
          public void update(AnActionEvent e) {
            FindResult cursor = mySearchResults != null ? mySearchResults.getCursor() : null;
            myExcludeButton.setEnabled(cursor != null);
            myExcludeButton.setText(
                cursor != null && mySearchResults.isExcluded(cursor) ? "Include" : "Exclude");
          }
        });

    myReplaceActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar1.setBorder(null);
    myReplaceActionsToolbar1.setOpaque(false);
    DefaultActionGroup actionGroup2 = new DefaultActionGroup("replace bar 2", false);
    myReplaceActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.addAction(new TogglePreserveCaseAction(this));
    actionGroup2.addAction(new ToggleSelectionOnlyAction(this));
    myReplaceActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    myReplaceActionsToolbar2.setBorder(null);
    myReplaceActionsToolbar2.setOpaque(false);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar1);
    Utils.setSmallerFontForChildren(myReplaceActionsToolbar2);
  }