Search in sources :

Example 1 with FileTypeRenderer

use of com.intellij.openapi.fileTypes.impl.FileTypeRenderer in project intellij-community by JetBrains.

the class SearchDialog method buildOptions.

protected void buildOptions(JPanel searchOptions) {
    recursiveMatching = new JCheckBox(SSRBundle.message("recursive.matching.checkbox"), true);
    if (isRecursiveSearchEnabled()) {
        searchOptions.add(UIUtil.createOptionLine(recursiveMatching));
    }
    caseSensitiveMatch = new JCheckBox(FindBundle.message("find.options.case.sensitive"), true);
    searchOptions.add(UIUtil.createOptionLine(caseSensitiveMatch));
    final List<FileType> types = new ArrayList<>();
    for (FileType fileType : StructuralSearchUtil.getSuitableFileTypes()) {
        if (StructuralSearchUtil.getProfileByFileType(fileType) != null) {
            types.add(fileType);
        }
    }
    Collections.sort(types, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    final DefaultComboBoxModel<FileType> comboBoxModel = new DefaultComboBoxModel<>(types.toArray(new FileType[types.size()]));
    fileTypes = new ComboBox<>(comboBoxModel);
    fileTypes.setRenderer(new FileTypeRenderer());
    new ComboboxSpeedSearch(fileTypes) {

        @Override
        protected String getElementText(Object element) {
            return ((FileType) element).getName();
        }
    };
    contexts = new ComboBox<>();
    contexts.setPreferredSize(new Dimension(60, -1));
    dialects = new ComboBox<>();
    dialects.setRenderer(new ListCellRendererWrapper<Language>() {

        @Override
        public void customize(JList list, Language value, int index, boolean selected, boolean hasFocus) {
            if (value == null) {
                setText("None");
            } else {
                setText(value.getDisplayName());
            }
        }
    });
    dialects.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            updateEditor();
        }
    });
    new ComboboxSpeedSearch(dialects);
    dialects.setPreferredSize(new Dimension(120, -1));
    final JLabel jLabel = new JLabel(SSRBundle.message("search.dialog.file.type.label"));
    final JLabel jLabel2 = new JLabel(SSRBundle.message("search.dialog.context.label"));
    final JLabel jLabel3 = new JLabel(SSRBundle.message("search.dialog.file.dialect.label"));
    searchOptions.add(UIUtil.createOptionLine(new JComponent[] { jLabel, fileTypes, (JComponent) Box.createHorizontalStrut(8), jLabel2, contexts, (JComponent) Box.createHorizontalStrut(8), jLabel3, dialects }));
    jLabel.setLabelFor(fileTypes);
    jLabel2.setLabelFor(contexts);
    jLabel3.setLabelFor(dialects);
    detectFileTypeAndDialect();
    fileTypes.setSelectedItem(ourFtSearchVariant);
    fileTypes.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                updateDialectsAndContexts();
                updateEditor();
                initiateValidation();
            }
        }
    });
    dialects.setSelectedItem(ourDialect);
    contexts.setSelectedItem(ourContext);
    updateDialectsAndContexts();
}
Also used : ItemEvent(java.awt.event.ItemEvent) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) FileTypeRenderer(com.intellij.openapi.fileTypes.impl.FileTypeRenderer) ItemListener(java.awt.event.ItemListener) ComboboxSpeedSearch(com.intellij.ui.ComboboxSpeedSearch)

Example 2 with FileTypeRenderer

use of com.intellij.openapi.fileTypes.impl.FileTypeRenderer in project intellij-community by JetBrains.

the class FileTypeChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTitleLabel.setText(FileTypesBundle.message("filetype.chooser.prompt", myFileName));
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(new FileTypeRenderer());
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            doOKAction();
            return true;
        }
    }.installOn(myList);
    myList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateButtonsState();
        }
    });
    ScrollingUtil.selectItem(myList, FileTypes.PLAIN_TEXT);
    return myPanel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) FileTypeRenderer(com.intellij.openapi.fileTypes.impl.FileTypeRenderer) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

FileTypeRenderer (com.intellij.openapi.fileTypes.impl.FileTypeRenderer)2 Language (com.intellij.lang.Language)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 ComboboxSpeedSearch (com.intellij.ui.ComboboxSpeedSearch)1 DoubleClickListener (com.intellij.ui.DoubleClickListener)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 MouseEvent (java.awt.event.MouseEvent)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1