public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   final Color color = UIUtil.getTableFocusCellBackground();
   Component component;
   T t = (T) value;
   try {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, table.getSelectionBackground());
     component =
         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     setText(t != null ? getItemText(t) : "");
     if (component instanceof JLabel) {
       ((JLabel) component).setBorder(noFocusBorder);
     }
   } finally {
     UIManager.put(UIUtil.TABLE_FOCUS_CELL_BACKGROUND_PROPERTY, color);
   }
   final MyTableModel model = (MyTableModel) table.getModel();
   component.setEnabled(
       ElementsChooser.this.isEnabled()
           && (myColorUnmarkedElements ? model.isElementMarked(row) : true));
   final ElementProperties properties = myElementToPropertiesMap.get(t);
   if (component instanceof JLabel) {
     final Icon icon =
         properties != null ? properties.getIcon() : t != null ? getItemIcon(t) : null;
     JLabel label = (JLabel) component;
     label.setIcon(icon);
     label.setDisabledIcon(icon);
   }
   component.setForeground(
       properties != null && properties.getColor() != null
           ? properties.getColor()
           : (isSelected ? table.getSelectionForeground() : table.getForeground()));
   return component;
 }
 private void updateCountLabel() {
   int placesCount = 0;
   int enablePlacesCount = 0;
   final List<InjInfo> items = myInjectionsTable.getListTableModel().getItems();
   if (!items.isEmpty()) {
     for (InjInfo injection : items) {
       for (InjectionPlace place : injection.injection.getInjectionPlaces()) {
         placesCount++;
         if (place.isEnabled()) enablePlacesCount++;
       }
     }
     myCountLabel.setText(
         items.size()
             + " injection"
             + (items.size() > 1 ? "s" : "")
             + " ("
             + enablePlacesCount
             + " of "
             + placesCount
             + " place"
             + (placesCount > 1 ? "s" : "")
             + " enabled) ");
   } else {
     myCountLabel.setText("no injections configured ");
   }
 }
  public InjectionsSettingsUI(final Project project, final Configuration configuration) {
    myProject = project;
    myConfiguration = configuration;

    final CfgInfo currentInfo = new CfgInfo(configuration, "Project");
    myInfos =
        configuration instanceof Configuration.Prj
            ? new CfgInfo[] {
              new CfgInfo(((Configuration.Prj) configuration).getParentConfiguration(), "IDE"),
              currentInfo
            }
            : new CfgInfo[] {currentInfo};

    myRoot = new JPanel(new BorderLayout());

    myInjectionsTable = new InjectionsTable(getInjInfoList(myInfos));
    myInjectionsTable.getEmptyText().setText("No injections configured");

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myInjectionsTable);
    createActions(decorator);

    // myRoot.add(new TitledSeparator("Languages injection places"), BorderLayout.NORTH);
    myRoot.add(decorator.createPanel(), BorderLayout.CENTER);
    myCountLabel = new JLabel();
    myCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    myCountLabel.setForeground(SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES.getFgColor());
    myRoot.add(myCountLabel, BorderLayout.SOUTH);
    updateCountLabel();
  }
 private void updateCaretPositionText() {
   if (myErrorMessage != null) {
     myCaretPositionLabel.setText(
         IdeBundle.message("label.scope.editor.caret.position", myCaretPosition + 1));
   } else {
     myCaretPositionLabel.setText("");
   }
   myPositionPanel.setVisible(myErrorMessage != null);
   myCaretPositionLabel.setVisible(myErrorMessage != null);
   myPanel.revalidate();
 }
Example #5
0
  private void initUI() {
    myLeftPanel = new NonOpaquePanel(new BorderLayout());
    myLeftPanel.add(mySearchFieldWrapper = new Wrapper(), BorderLayout.NORTH);
    myLeftPanel.add(myReplaceFieldWrapper = new Wrapper(), BorderLayout.CENTER);

    updateSearchComponent();
    updateReplaceComponent();
    initSearchToolbars();
    initReplaceToolBars();

    Wrapper searchToolbarWrapper1 = new NonOpaquePanel(new BorderLayout());
    searchToolbarWrapper1.add(mySearchActionsToolbar1, BorderLayout.WEST);
    Wrapper searchToolbarWrapper2 = new Wrapper(mySearchActionsToolbar2);
    JPanel searchPair =
        new NonOpaquePanel(new BorderLayout()).setVerticalSizeReferent(mySearchFieldWrapper);
    searchPair.add(mySearchActionsToolbar1, BorderLayout.WEST);
    searchPair.add(searchToolbarWrapper2, BorderLayout.CENTER);
    JLabel closeLabel = new JLabel(null, AllIcons.Actions.Cross, SwingConstants.RIGHT);
    closeLabel.setBorder(JBUI.Borders.empty(5, 5, 5, 5));
    closeLabel.setVerticalAlignment(SwingConstants.TOP);
    closeLabel.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            close();
          }
        });

    closeLabel.setToolTipText("Close search bar (Escape)");
    searchPair.add(new Wrapper.North(closeLabel), BorderLayout.EAST);

    Wrapper replaceToolbarWrapper1 =
        new Wrapper(myReplaceActionsToolbar1).setVerticalSizeReferent(myReplaceFieldWrapper);
    Wrapper replaceToolbarWrapper2 =
        new Wrapper(myReplaceActionsToolbar2).setVerticalSizeReferent(myReplaceFieldWrapper);
    myReplaceToolbarWrapper = new NonOpaquePanel(new BorderLayout());
    myReplaceToolbarWrapper.add(replaceToolbarWrapper1, BorderLayout.WEST);
    myReplaceToolbarWrapper.add(replaceToolbarWrapper2, BorderLayout.CENTER);

    searchToolbarWrapper1.setHorizontalSizeReferent(replaceToolbarWrapper1);

    myRightPanel = new NonOpaquePanel(new BorderLayout());
    myRightPanel.add(searchPair, BorderLayout.NORTH);
    myRightPanel.add(myReplaceToolbarWrapper, BorderLayout.CENTER);

    OnePixelSplitter splitter = new OnePixelSplitter(false, .25F);
    splitter.setFirstComponent(myLeftPanel);
    splitter.setSecondComponent(myRightPanel);
    splitter.setHonorComponentsMinimumSize(true);
    splitter.setAndLoadSplitterProportionKey("FindSplitterProportion");
    splitter.setOpaque(false);
    splitter.getDivider().setOpaque(false);
    add(splitter, BorderLayout.CENTER);
  }
  @Nullable
  protected final JComponent createTitlePane() {
    final String description = myChooserDescriptor.getDescription();
    if (StringUtil.isEmptyOrSpaces(description)) return null;

    final JLabel label = new JLabel(description);
    label.setBorder(
        BorderFactory.createCompoundBorder(
            new SideBorder(UIUtil.getPanelBackground().darker(), SideBorder.BOTTOM),
            JBUI.Borders.empty(0, 5, 10, 5)));
    return label;
  }
 private static JLabel createArrow(final ActionLink link) {
   JLabel arrow = new JLabel(AllIcons.General.Combo3);
   arrow.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
   arrow.setVerticalAlignment(SwingConstants.BOTTOM);
   new ClickListener() {
     @Override
     public boolean onClick(@NotNull MouseEvent e, int clickCount) {
       final MouseEvent newEvent = MouseEventAdapter.convert(e, link, e.getX(), e.getY());
       link.doClick(newEvent);
       return true;
     }
   }.installOn(arrow);
   return arrow;
 }
Example #8
0
  private void updateResults(final boolean allowedToChangedEditorSelection) {
    final String text = myFindModel.getStringToFind();
    if (text.length() == 0) {
      nothingToSearchFor();
    } else {

      if (myFindModel.isRegularExpressions()) {
        try {
          Pattern.compile(text);
        } catch (Exception e) {
          setNotFoundBackground();
          myClickToHighlightLabel.setVisible(false);
          mySearchResults.clear();
          myMatchInfoLabel.setText("Incorrect regular expression");
          return;
        }
      }

      final FindManager findManager = FindManager.getInstance(myProject);
      if (allowedToChangedEditorSelection) {
        findManager.setFindWasPerformed();
        FindModel copy = new FindModel();
        copy.copyFrom(myFindModel);
        copy.setReplaceState(false);
        findManager.setFindNextModel(copy);
      }
      if (myLivePreviewController != null) {
        myLivePreviewController.updateInBackground(myFindModel, allowedToChangedEditorSelection);
      }
    }
  }
Example #9
0
 @Override
 public void searchResultsUpdated(SearchResults sr) {
   if (mySearchTextComponent.getText().isEmpty()) {
     updateUIWithEmptyResults();
   } else {
     int count = sr.getMatchesCount();
     boolean notTooMuch = count <= mySearchResults.getMatchesLimit();
     myMatchInfoLabel.setText(
         notTooMuch
             ? ApplicationBundle.message("editorsearch.matches", count)
             : ApplicationBundle.message(
                 "editorsearch.toomuch", mySearchResults.getMatchesLimit()));
     myClickToHighlightLabel.setVisible(!notTooMuch);
     if (notTooMuch) {
       if (count > 0) {
         setRegularBackground();
       } else {
         setNotFoundBackground();
       }
     } else {
       setRegularBackground();
     }
   }
   myReplaceActionsToolbar1.updateActionsImmediately();
 }
 protected JComponent createCenterPanel() {
   final VirtualFile[] sourceRoots = getSourceRoots();
   boolean isDestinationVisible = sourceRoots.length > 1;
   myDestinationFolderCB.setVisible(isDestinationVisible);
   myTargetDestinationLabel.setVisible(isDestinationVisible);
   return null;
 }
  private void updateEnabledState() {
    myLabelEditor.setEnabled(myRbExpressionLabel.isSelected());

    final boolean isChildrenExpression = myRbExpressionChildrenRenderer.isSelected();
    myChildrenExpandedEditor.setEnabled(isChildrenExpression);
    myExpandedLabel.setEnabled(isChildrenExpression);
    myChildrenEditor.setEnabled(isChildrenExpression);
    myTable.setEnabled(myRbListChildrenRenderer.isSelected());
  }
 public void setAdText(@NotNull final String s, int alignment) {
   if (myAdComponent == null) {
     myAdComponent =
         HintUtil.createAdComponent(s, BorderFactory.createEmptyBorder(1, 5, 1, 5), alignment);
     JPanel wrapper =
         new JPanel(new BorderLayout()) {
           @Override
           protected void paintComponent(Graphics g) {
             g.setColor(Gray._135);
             g.drawLine(0, 0, getWidth(), 0);
             super.paintComponent(g);
           }
         };
     wrapper.setOpaque(false);
     wrapper.setBorder(new EmptyBorder(1, 0, 0, 0));
     wrapper.add(myAdComponent, BorderLayout.CENTER);
     myContent.add(wrapper, BorderLayout.SOUTH);
     pack(false, true);
   } else {
     myAdComponent.setText(s);
     myAdComponent.setHorizontalAlignment(alignment);
   }
 }
  protected JComponent createHistoryButton() {
    JLabel label = new JLabel(AllIcons.Actions.Get);
    label.setToolTipText("Recent files");
    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent event, int clickCount) {
        showRecentFilesPopup();
        return true;
      }
    }.installOn(label);

    new AnAction() {
      @Override
      public void actionPerformed(AnActionEvent e) {
        showRecentFilesPopup();
      }

      @Override
      public void update(AnActionEvent e) {
        e.getPresentation().setEnabled(!IdeEventQueue.getInstance().isPopupActive());
      }
    }.registerCustomShortcutSet(KeyEvent.VK_DOWN, 0, myPathTextField.getField());
    return label;
  }
  public static Pair<JPanel, JBList> createActionGroupPanel(
      ActionGroup action, final JComponent parent, final Runnable backAction) {
    JPanel actionsListPanel = new JPanel(new BorderLayout());
    actionsListPanel.setBackground(getProjectsBackground());
    final JBList list = new JBList(action.getChildren(null));
    list.setBackground(getProjectsBackground());
    list.installCellRenderer(
        new NotNullFunction<AnAction, JComponent>() {
          final JLabel label = new JLabel();

          {
            label.setBorder(JBUI.Borders.empty(3, 7));
          }

          @NotNull
          @Override
          public JComponent fun(AnAction action) {
            label.setText(action.getTemplatePresentation().getText());
            Icon icon = action.getTemplatePresentation().getIcon();
            label.setIcon(icon);
            return label;
          }
        });
    JScrollPane pane = ScrollPaneFactory.createScrollPane(list, true);
    pane.setBackground(getProjectsBackground());
    actionsListPanel.add(pane, BorderLayout.CENTER);
    if (backAction != null) {
      final JLabel back = new JLabel(AllIcons.Actions.Back);
      back.setBorder(JBUI.Borders.empty(3, 7, 10, 7));
      back.setHorizontalAlignment(SwingConstants.LEFT);
      new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
          backAction.run();
          return true;
        }
      }.installOn(back);
      actionsListPanel.add(back, BorderLayout.SOUTH);
    }
    final Ref<Component> selected = Ref.create();
    final JPanel main = new JPanel(new BorderLayout());
    main.add(actionsListPanel, BorderLayout.WEST);

    ListSelectionListener selectionListener =
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
              // Update when a change has been finalized.
              // For instance, selecting an element with mouse fires two consecutive
              // ListSelectionEvent events.
              return;
            }
            if (!selected.isNull()) {
              main.remove(selected.get());
            }
            Object value = list.getSelectedValue();
            if (value instanceof AbstractActionWithPanel) {
              JPanel panel = ((AbstractActionWithPanel) value).createPanel();
              panel.setBorder(JBUI.Borders.empty(7, 10));
              selected.set(panel);
              main.add(selected.get());

              for (JButton button : UIUtil.findComponentsOfType(main, JButton.class)) {
                if (button.getClientProperty(DialogWrapper.DEFAULT_ACTION) == Boolean.TRUE) {
                  parent.getRootPane().setDefaultButton(button);
                  break;
                }
              }

              main.revalidate();
              main.repaint();
            }
          }
        };
    list.addListSelectionListener(selectionListener);
    if (backAction != null) {
      new AnAction() {
        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
          backAction.run();
        }
      }.registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, main);
    }
    return Pair.create(main, list);
  }
 private Dimension computeWindowSize(Dimension size) {
   if (myAdComponent != null && myAdComponent.isShowing()) {
     size.height += myAdComponent.getPreferredSize().height + 1;
   }
   return size;
 }
    private JComponent createLogo() {
      NonOpaquePanel panel = new NonOpaquePanel(new BorderLayout());
      ApplicationInfoEx app = ApplicationInfoEx.getInstanceEx();
      JLabel logo = new JLabel(IconLoader.getIcon(app.getWelcomeScreenLogoUrl()));
      logo.setBorder(JBUI.Borders.empty(30, 0, 10, 0));
      logo.setHorizontalAlignment(SwingConstants.CENTER);
      panel.add(logo, BorderLayout.NORTH);
      JLabel appName = new JLabel(ApplicationNamesInfo.getInstance().getFullProductName());
      Font font = getProductFont();
      appName.setForeground(JBColor.foreground());
      appName.setFont(font.deriveFont(JBUI.scale(36f)).deriveFont(Font.PLAIN));
      appName.setHorizontalAlignment(SwingConstants.CENTER);
      String appVersion = "Version " + app.getFullVersion();

      if (app.isEAP() && app.getBuild().getBuildNumber() < Integer.MAX_VALUE) {
        appVersion += " (" + app.getBuild().asString() + ")";
      }

      JLabel version = new JLabel(appVersion);
      version.setFont(getProductFont().deriveFont(JBUI.scale(16f)));
      version.setHorizontalAlignment(SwingConstants.CENTER);
      version.setForeground(Gray._128);

      panel.add(appName);
      panel.add(version, BorderLayout.SOUTH);
      panel.setBorder(JBUI.Borders.emptyBottom(20));
      return panel;
    }
  public void setData(
      PsiElement[] psiElements,
      String targetPackageName,
      final PsiDirectory initialTargetDirectory,
      boolean isTargetDirectoryFixed,
      boolean searchInComments,
      boolean searchForTextOccurences,
      String helpID) {
    myInitialTargetDirectory = initialTargetDirectory;
    myTargetDirectoryFixed = isTargetDirectoryFixed;
    if (targetPackageName.length() != 0) {
      myWithBrowseButtonReference.prependItem(targetPackageName);
      myClassPackageChooser.prependItem(targetPackageName);
    }

    String nameFromCallback =
        myMoveCallback instanceof MoveClassesOrPackagesCallback
            ? ((MoveClassesOrPackagesCallback) myMoveCallback).getElementsToMoveName()
            : null;
    if (nameFromCallback != null) {
      myNameLabel.setText(nameFromCallback);
    } else if (psiElements.length == 1) {
      PsiElement firstElement = psiElements[0];
      if (firstElement instanceof PsiClass) {
        LOG.assertTrue(!MoveClassesOrPackagesImpl.isClassInnerOrLocal((PsiClass) firstElement));
      } else {
        PsiElement parent = firstElement.getParent();
        LOG.assertTrue(parent != null);
      }
      myNameLabel.setText(
          RefactoringBundle.message(
              "move.single.class.or.package.name.label",
              UsageViewUtil.getType(firstElement),
              UsageViewUtil.getLongName(firstElement)));
    } else if (psiElements.length > 1) {
      myNameLabel.setText(
          psiElements[0] instanceof PsiClass
              ? RefactoringBundle.message("move.specified.classes")
              : RefactoringBundle.message("move.specified.packages"));
    }
    selectInitialCard();

    myCbSearchInComments.setSelected(searchInComments);
    myCbSearchTextOccurences.setSelected(searchForTextOccurences);

    ((DestinationFolderComboBox) myDestinationFolderCB)
        .setData(
            myProject,
            myInitialTargetDirectory,
            new Pass<String>() {
              @Override
              public void pass(String s) {
                setErrorText(s);
              }
            },
            myClassPackageChooser.getChildComponent());
    UIUtil.setEnabled(
        myTargetPanel,
        getSourceRoots().length > 0 && isMoveToPackage() && !isTargetDirectoryFixed,
        true);
    validateButtons();
    myHelpID = helpID;
  }
  public ScopeEditorPanel(Project project, final NamedScopesHolder holder) {
    myProject = project;
    myHolder = holder;

    myPackageTree = new Tree(new RootNode(project));

    myButtonsPanel.add(createActionsPanel());

    myTreePanel.setLayout(new BorderLayout());
    myTreePanel.add(ScrollPaneFactory.createScrollPane(myPackageTree), BorderLayout.CENTER);

    myTreeToolbar.setLayout(new BorderLayout());
    myTreeToolbar.add(createTreeToolbar(), BorderLayout.WEST);

    myTreeExpansionMonitor = PackageTreeExpansionMonitor.install(myPackageTree, myProject);

    myTreeMarker =
        new Marker() {
          public boolean isMarked(VirtualFile file) {
            return myCurrentScope != null
                && (myCurrentScope instanceof PackageSetBase
                    ? ((PackageSetBase) myCurrentScope).contains(file, myHolder)
                    : myCurrentScope.contains(PackageSetBase.getPsiFile(file, myHolder), myHolder));
          }
        };

    myPatternField.setDialogCaption("Pattern");
    myPatternField
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              public void textChanged(DocumentEvent event) {
                onTextChange();
              }
            });

    myPatternField
        .getTextField()
        .addCaretListener(
            new CaretListener() {
              public void caretUpdate(CaretEvent e) {
                myCaretPosition = e.getDot();
                updateCaretPositionText();
              }
            });

    myPatternField
        .getTextField()
        .addFocusListener(
            new FocusListener() {
              public void focusGained(FocusEvent e) {
                if (myErrorMessage != null) {
                  myPositionPanel.setVisible(true);
                  myPanel.revalidate();
                }
              }

              public void focusLost(FocusEvent e) {
                myPositionPanel.setVisible(false);
                myPanel.revalidate();
              }
            });

    initTree(myPackageTree);
    new UiNotifyConnector(
        myPanel,
        new Activatable() {
          @Override
          public void showNotify() {}

          @Override
          public void hideNotify() {
            cancelCurrentProgress();
          }
        });
    myPartiallyIncluded.setBackground(MyTreeCellRenderer.PARTIAL_INCLUDED);
    myRecursivelyIncluded.setBackground(MyTreeCellRenderer.WHOLE_INCLUDED);
  }
 private void showErrorMessage() {
   myMatchingCountLabel.setText(StringUtil.capitalize(myErrorMessage));
   myMatchingCountLabel.setForeground(JBColor.red);
   myMatchingCountLabel.setToolTipText(myErrorMessage);
 }
Example #20
0
  private void initSearchToolbars() {
    DefaultActionGroup actionGroup1 = new DefaultActionGroup("search bar 1", false);
    mySearchActionsToolbar1 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup1, true);
    mySearchActionsToolbar1.setForceMinimumSize(true);
    mySearchActionsToolbar1.setReservePlaceAutoPopupIcon(false);
    mySearchActionsToolbar1.setSecondaryButtonPopupStateModifier(
        new ActionToolbarImpl.PopupStateModifier() {
          @Override
          public int getModifiedPopupState() {
            return ActionButtonComponent.PUSHED;
          }

          @Override
          public boolean willModify() {
            return myFindModel.getSearchContext() != FindModel.SearchContext.ANY;
          }
        });
    mySearchActionsToolbar1.setSecondaryActionsTooltip(
        "More Options(" + ShowMoreOptions.SHORT_CUT + ")");

    actionGroup1.add(new PrevOccurrenceAction(this, mySearchFieldWrapper));
    actionGroup1.add(new NextOccurrenceAction(this, mySearchFieldWrapper));
    actionGroup1.add(new FindAllAction(this));
    actionGroup1.addSeparator();
    actionGroup1.add(new AddOccurrenceAction(this));
    actionGroup1.add(new RemoveOccurrenceAction(this));
    actionGroup1.add(new SelectAllAction(this));
    // actionGroup1.addSeparator();
    // actionGroup1.add(new ToggleMultiline(this));//todo get rid of it!
    actionGroup1.addSeparator();

    actionGroup1.addAction(new ToggleInCommentsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleInLiteralsOnlyAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptCommentsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptLiteralsAction(this)).setAsSecondary(true);
    actionGroup1.addAction(new ToggleExceptCommentsAndLiteralsAction(this)).setAsSecondary(true);

    DefaultActionGroup actionGroup2 = new DefaultActionGroup("search bar 2", false);
    mySearchActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.add(new ToggleMatchCase(this));
    actionGroup2.add(new ToggleRegex(this));
    actionGroup2.add(new ToggleWholeWordsOnlyAction(this));

    myMatchInfoLabel =
        new JLabel() {
          @Override
          public Font getFont() {
            Font font = super.getFont();
            return font != null ? font.deriveFont(Font.BOLD) : null;
          }
        };
    myMatchInfoLabel.setBorder(JBUI.Borders.empty(2, 20, 0, 20));

    myClickToHighlightLabel =
        new LinkLabel<Object>(
            "Click to highlight",
            null,
            new LinkListener<Object>() {
              @Override
              public void linkSelected(LinkLabel aSource, Object aLinkData) {
                setMatchesLimit(Integer.MAX_VALUE);
                updateResults(true);
              }
            });
    myClickToHighlightLabel.setVisible(false);

    mySearchActionsToolbar2 =
        (ActionToolbarImpl)
            ActionManager.getInstance()
                .createActionToolbar(ActionPlaces.EDITOR_TOOLBAR, actionGroup2, true);
    actionGroup2.add(new DefaultCustomComponentAction(myMatchInfoLabel));
    actionGroup2.add(new DefaultCustomComponentAction(myClickToHighlightLabel));

    mySearchActionsToolbar1.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    mySearchActionsToolbar2.setLayoutPolicy(ActionToolbar.AUTO_LAYOUT_POLICY);
    mySearchActionsToolbar1.setBorder(null);
    mySearchActionsToolbar2.setBorder(null);
    mySearchActionsToolbar1.setOpaque(false);
    mySearchActionsToolbar2.setOpaque(false);

    new ShowMoreOptions(mySearchActionsToolbar1, mySearchFieldWrapper);
    Utils.setSmallerFontForChildren(mySearchActionsToolbar1);
    Utils.setSmallerFontForChildren(mySearchActionsToolbar2);
  }
Example #21
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      final RegistryValue v = ((MyTableModel) table.getModel()).getRegistryValue(row);
      myLabel.setIcon(null);
      myLabel.setText(null);
      myLabel.setHorizontalAlignment(JLabel.LEFT);

      if (v != null) {
        switch (column) {
          case 0:
            myLabel.setIcon(v.isRestartRequired() ? RESTART_ICON : null);
            myLabel.setHorizontalAlignment(JLabel.CENTER);
            break;
          case 1:
            myLabel.setText(v.getKey());
            break;
          case 2:
            if (v.asColor(null) != null) {
              myLabel.setIcon(createColoredIcon(v.asColor(null)));
            } else if (v.isBoolean()) {
              final JCheckBox box = new JCheckBox();
              box.setSelected(v.asBoolean());
              box.setBackground(table.getBackground());
              return box;
            } else {
              myLabel.setText(v.asString());
            }
        }

        myLabel.setOpaque(true);

        myLabel.setFont(
            myLabel.getFont().deriveFont(v.isChangedFromDefault() ? Font.BOLD : Font.PLAIN));
        myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
        myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
      }

      return myLabel;
    }
Example #22
0
 private void updateUIWithEmptyResults() {
   setRegularBackground();
   myMatchInfoLabel.setText("");
   myClickToHighlightLabel.setVisible(false);
 }
  @Override
  protected JComponent createCenterPanel() {
    final FileChooserDescriptor descriptor =
        FileChooserDescriptorFactory.createAllButJarContentsDescriptor();
    calculateRoots();
    final ArrayList<VirtualFile> list = new ArrayList<VirtualFile>(myRoots);
    final Comparator<VirtualFile> comparator =
        new Comparator<VirtualFile>() {
          @Override
          public int compare(VirtualFile o1, VirtualFile o2) {
            final boolean isDir1 = o1.isDirectory();
            final boolean isDir2 = o2.isDirectory();
            if (isDir1 != isDir2) return isDir1 ? -1 : 1;

            final String module1 = myModulesSet.get(o1);
            final String path1 = module1 != null ? module1 : o1.getPath();
            final String module2 = myModulesSet.get(o2);
            final String path2 = module2 != null ? module2 : o2.getPath();
            return path1.compareToIgnoreCase(path2);
          }
        };
    descriptor.setRoots(list);
    myTree = new Tree();
    myTree.setMinimumSize(new Dimension(200, 200));
    myTree.setBorder(BORDER);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(true);
    myTree.getExpandableItemsHandler().setEnabled(false);
    final MyCheckboxTreeCellRenderer cellRenderer =
        new MyCheckboxTreeCellRenderer(
            mySelectionManager, myModulesSet, myProject, myTree, myRoots);
    final FileSystemTreeImpl fileSystemTree =
        new FileSystemTreeImpl(
            myProject,
            descriptor,
            myTree,
            cellRenderer,
            null,
            new Convertor<TreePath, String>() {
              @Override
              public String convert(TreePath o) {
                final DefaultMutableTreeNode lastPathComponent =
                    ((DefaultMutableTreeNode) o.getLastPathComponent());
                final Object uo = lastPathComponent.getUserObject();
                if (uo instanceof FileNodeDescriptor) {
                  final VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile();
                  final String module = myModulesSet.get(file);
                  if (module != null) return module;
                  return file == null ? "" : file.getName();
                }
                return o.toString();
              }
            });
    final AbstractTreeUi ui = fileSystemTree.getTreeBuilder().getUi();
    ui.setNodeDescriptorComparator(
        new Comparator<NodeDescriptor>() {
          @Override
          public int compare(NodeDescriptor o1, NodeDescriptor o2) {
            if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) {
              final VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile();
              final VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile();
              return comparator.compare(f1, f2);
            }
            return o1.getIndex() - o2.getIndex();
          }
        });
    myRoot = (DefaultMutableTreeNode) myTree.getModel().getRoot();

    new ClickListener() {
      @Override
      public boolean onClick(@NotNull MouseEvent e, int clickCount) {
        int row = myTree.getRowForLocation(e.getX(), e.getY());
        if (row < 0) return false;
        final Object o = myTree.getPathForRow(row).getLastPathComponent();
        if (myRoot == o || getFile(o) == null) return false;

        Rectangle rowBounds = myTree.getRowBounds(row);
        cellRenderer.setBounds(rowBounds);
        Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
        checkBounds.setLocation(rowBounds.getLocation());

        if (checkBounds.height == 0) checkBounds.height = rowBounds.height;

        if (checkBounds.contains(e.getPoint())) {
          mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
          myTree.revalidate();
          myTree.repaint();
        }
        return true;
      }
    }.installOn(myTree);

    myTree.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
              TreePath[] paths = myTree.getSelectionPaths();
              if (paths == null) return;
              for (TreePath path : paths) {
                if (path == null) continue;
                final Object o = path.getLastPathComponent();
                if (myRoot == o || getFile(o) == null) return;
                mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
              }

              myTree.revalidate();
              myTree.repaint();
              e.consume();
            }
          }
        });

    JBPanel panel = new JBPanel(new BorderLayout());
    panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
    mySelectedLabel = new JLabel("");
    mySelectedLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
    panel.add(mySelectedLabel, BorderLayout.SOUTH);

    mySelectionManager.setSelectionChangeListener(
        new PlusMinus<VirtualFile>() {
          @Override
          public void plus(VirtualFile virtualFile) {
            mySelectedFiles.add(virtualFile);
            recalculateErrorText();
          }

          private void recalculateErrorText() {
            checkEmpty();
            if (mySelectionManager.canAddSelection()) {
              mySelectedLabel.setText("");
            } else {
              mySelectedLabel.setText(CAN_NOT_ADD_TEXT);
            }
            mySelectedLabel.revalidate();
          }

          @Override
          public void minus(VirtualFile virtualFile) {
            mySelectedFiles.remove(virtualFile);
            recalculateErrorText();
          }
        });
    return panel;
  }