Search in sources :

Example 66 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class ContentChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final int selectionMode = myAllowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION;
    myList.setSelectionMode(selectionMode);
    if (myUseIdeaEditor) {
        EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
        myList.setFont(scheme.getFont(EditorFontType.PLAIN));
        Color fg = ObjectUtils.chooseNotNull(scheme.getDefaultForeground(), new JBColor(UIUtil::getListForeground));
        Color bg = ObjectUtils.chooseNotNull(scheme.getDefaultBackground(), new JBColor(UIUtil::getListBackground));
        myList.setForeground(fg);
        myList.setBackground(bg);
    }
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            close(OK_EXIT_CODE);
            return true;
        }
    }.installOn(myList);
    MyListCellRenderer renderer = new MyListCellRenderer();
    myList.setCellRenderer(renderer);
    myList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                int newSelectionIndex = -1;
                for (Object o : myList.getSelectedValuesList()) {
                    int i = ((Item) o).index;
                    removeContentAt(myAllContents.get(i));
                    if (newSelectionIndex < 0) {
                        newSelectionIndex = i;
                    }
                }
                rebuildListContent();
                if (myAllContents.isEmpty()) {
                    close(CANCEL_EXIT_CODE);
                    return;
                }
                newSelectionIndex = Math.min(newSelectionIndex, myAllContents.size() - 1);
                myList.setSelectedIndex(newSelectionIndex);
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                doOKAction();
            } else {
                SpeedSearchSupply supply = SpeedSearchSupply.getSupply(myList);
                if (supply != null && supply.isPopupActive())
                    return;
                char aChar = e.getKeyChar();
                if (aChar >= '0' && aChar <= '9') {
                    int idx = aChar == '0' ? 9 : aChar - '1';
                    if (idx < myAllContents.size()) {
                        myList.setSelectedIndex(idx);
                        e.consume();
                        doOKAction();
                    }
                }
            }
        }
    });
    mySplitter.setFirstComponent(ListWithFilter.wrap(myList, ScrollPaneFactory.createScrollPane(myList), o -> o.getShortText(renderer.previewChars)));
    mySplitter.setSecondComponent(new JPanel());
    mySplitter.getFirstComponent().addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            FontMetrics metrics = myList.getFontMetrics(myList.getFont());
            int charWidth = metrics.charWidth('m');
            renderer.previewChars = myList.getParent().getParent().getWidth() / charWidth + 10;
        }
    });
    rebuildListContent();
    ScrollingUtil.installActions(myList);
    ScrollingUtil.ensureSelectionExists(myList);
    updateViewerForSelection();
    myList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (myUpdateAlarm.isDisposed())
                return;
            myUpdateAlarm.cancelAllRequests();
            myUpdateAlarm.addRequest(() -> updateViewerForSelection(), 100);
        }
    });
    mySplitter.setPreferredSize(JBUI.size(500, 500));
    SplitterProportionsData d = new SplitterProportionsDataImpl();
    d.externalizeToDimensionService(getClass().getName());
    d.restoreSplitterProportions(mySplitter);
    return mySplitter;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) JBIterable(com.intellij.util.containers.JBIterable) Document(com.intellij.openapi.editor.Document) EditorFontType(com.intellij.openapi.editor.colors.EditorFontType) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) ListWithFilter(com.intellij.ui.speedSearch.ListWithFilter) ArrayList(java.util.ArrayList) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) JBUI(com.intellij.util.ui.JBUI) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) FilteringListModel(com.intellij.ui.speedSearch.FilteringListModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JBList(com.intellij.ui.components.JBList) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) java.awt.event(java.awt.event) EditorFactory(com.intellij.openapi.editor.EditorFactory) ObjectUtils(com.intellij.util.ObjectUtils) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 67 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class EditorColorSchemesUsagesCollector method getUsages.

@NotNull
@Override
public Set<UsageDescriptor> getUsages() throws CollectUsagesException {
    EditorColorsScheme currentScheme = EditorColorsManager.getInstance().getGlobalScheme();
    Set<UsageDescriptor> usages = ContainerUtil.newHashSet();
    String schemeName = SCHEME_NAME_OTHER;
    if (currentScheme instanceof AbstractColorsScheme) {
        String name = currentScheme.getName();
        if (name.startsWith(SchemeManager.EDITABLE_COPY_PREFIX)) {
            EditorColorsScheme original = ((AbstractColorsScheme) currentScheme).getOriginal();
            if (original != null) {
                schemeName = original.getName();
            }
        }
        usages.add(new UsageDescriptor(schemeName, 1));
    }
    return usages;
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class EditorColorsManagerImpl method getDefaultScheme.

@NotNull
private EditorColorsScheme getDefaultScheme() {
    DefaultColorsScheme defaultScheme = myDefaultColorSchemeManager.getFirstScheme();
    String editableCopyName = defaultScheme.getEditableCopyName();
    EditorColorsScheme editableCopy = getScheme(editableCopyName);
    assert editableCopy != null : "An editable copy of " + defaultScheme.getName() + " has not been initialized.";
    return editableCopy;
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) NotNull(org.jetbrains.annotations.NotNull)

Example 69 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class DiffStatusBar method setColorScheme.

public void setColorScheme(EditorColorsScheme colorScheme) {
    EditorColorsScheme oldScheme = myColorScheme;
    myColorScheme = colorScheme;
    if (oldScheme != colorScheme)
        repaint();
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme)

Example 70 with EditorColorsScheme

use of com.intellij.openapi.editor.colors.EditorColorsScheme in project intellij-community by JetBrains.

the class ChangeType method addBlock.

@Nullable
private RangeHighlighter addBlock(CharSequence text, ChangeSide changeSide, final ChangeHighlighterHolder markup, TextDiffType diffType) {
    EditorColorsScheme colorScheme = markup.getEditor().getColorsScheme();
    Color separatorColor = getSeparatorColor(diffType.getLegendColor(colorScheme));
    int length = text.length();
    int start = changeSide.getStart();
    int end = start + length;
    RangeHighlighter highlighter = markup.addRangeHighlighter(start, end, LAYER, diffType, HighlighterTargetArea.EXACT_RANGE, myApplied);
    LineSeparatorRenderer lineSeparatorRenderer = new LineSeparatorRenderer() {

        @Override
        public void drawLine(Graphics g, int x1, int x2, int y) {
            Graphics2D g2 = (Graphics2D) g;
            Color color = myDiffType.getPolygonColor(markup.getEditor());
            if (color != null) {
                if (myApplied) {
                    Rectangle bounds = g.getClipBounds();
                    // do not paint line behind clip bounds - it's very slow for dotted line
                    x1 = Math.max(x1, bounds.x);
                    if (x1 >= x2)
                        return;
                    UIUtil.drawBoldDottedLine(g2, x1, x2, y, null, color, false);
                } else {
                    UIUtil.drawLine(g2, x1, y, x2, y, null, DiffUtil.getFramingColor(color));
                }
            }
        }
    };
    if (highlighter != null) {
        highlighter.setLineSeparatorPlacement(SeparatorPlacement.TOP);
        highlighter.setLineSeparatorColor(separatorColor);
        highlighter.setLineSeparatorRenderer(lineSeparatorRenderer);
    }
    if (text.charAt(length - 1) == '\n') {
        end--;
    }
    highlighter = markup.addRangeHighlighter(start, end, LAYER, TextDiffType.NONE, HighlighterTargetArea.EXACT_RANGE, myApplied);
    if (highlighter != null) {
        highlighter.setLineSeparatorPlacement(SeparatorPlacement.BOTTOM);
        highlighter.setLineSeparatorColor(separatorColor);
        highlighter.setLineSeparatorRenderer(lineSeparatorRenderer);
    }
    return highlighter;
}
Also used : EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)105 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)31 NotNull (org.jetbrains.annotations.NotNull)28 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)17 Nullable (org.jetbrains.annotations.Nullable)15 Document (com.intellij.openapi.editor.Document)14 Project (com.intellij.openapi.project.Project)14 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)12 Editor (com.intellij.openapi.editor.Editor)11 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)8 TextRange (com.intellij.openapi.util.TextRange)8 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 List (java.util.List)7 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 java.awt (java.awt)6 java.util (java.util)6