diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsInitializingActivity.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsInitializingActivity.java index 4cf33566d78e..7947105d3f63 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsInitializingActivity.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsInitializingActivity.java @@ -141,7 +141,7 @@ public class BreadcrumbsInitializingActivity implements StartupActivity, DumbAwa @NotNull FileEditor fileEditor, @NotNull BreadcrumbsXmlWrapper wrapper) { //noinspection deprecation - if (wrapper.above) { + if (wrapper.breadcrumbs.above) { fileEditorManager.addTopComponent(fileEditor, wrapper); } else { @@ -154,7 +154,7 @@ public class BreadcrumbsInitializingActivity implements StartupActivity, DumbAwa @NotNull FileEditor fileEditor, @NotNull BreadcrumbsXmlWrapper wrapper) { //noinspection deprecation - if (wrapper.above) { + if (wrapper.breadcrumbs.above) { fileEditorManager.removeTopComponent(fileEditor, wrapper); } else { diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java index 8e5a45b8391c..6bb7a3150664 100644 --- a/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/BreadcrumbsXmlWrapper.java @@ -49,8 +49,6 @@ import com.intellij.openapi.vcs.FileStatusManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.ui.Gray; -import com.intellij.ui.RelativeFont; -import com.intellij.ui.components.breadcrumbs.Breadcrumbs; import com.intellij.ui.components.breadcrumbs.Crumb; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -77,77 +75,7 @@ import static com.intellij.ui.ScrollPaneFactory.createScrollPane; * @author spleaner */ public class BreadcrumbsXmlWrapper extends JComponent implements Disposable { - private static final class PsiCrumb extends Crumb.Impl { - private final PsiElement element; - private CrumbPresentation presentation; - - private PsiCrumb(PsiElement element, BreadcrumbsInfoProvider provider) { - super(null, provider.getElementInfo(element), provider.getElementTooltip(element)); - this.element = element; - } - - private static PsiElement getElement(Crumb crumb) { - return crumb instanceof PsiCrumb ? ((PsiCrumb)crumb).element : null; - } - - private static CrumbPresentation getPresentation(Crumb crumb) { - return crumb instanceof PsiCrumb ? ((PsiCrumb)crumb).presentation : null; - } - } - - final boolean above = Registry.is("editor.breadcrumbs.above"); - - private final Breadcrumbs breadcrumbs = new Breadcrumbs() { - @Override - protected void paint(Graphics2D g, int x, int y, int width, int height, int thickness) { - super.paint(g, x, y, width, above ? height : thickness, thickness); - } - - @Override - public void setFont(Font font) { - super.setFont(RelativeFont.SMALL.derive(font)); - } - - @Override - public Color getForeground() { - if (!isForegroundSet()) { - Color foreground = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.LINE_NUMBERS_COLOR); - if (foreground != null) return foreground; - } - return super.getForeground(); - } - - @Override - public Color getBackground() { - if (!isBackgroundSet()) { - Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.GUTTER_BACKGROUND); - if (background != null) return background; - } - return super.getBackground(); - } - - @Override - protected Color getForeground(Crumb crumb) { - CrumbPresentation presentation = PsiCrumb.getPresentation(crumb); - if (presentation == null) return super.getForeground(crumb); - - Color background = super.getBackground(crumb); - if (background != null) return super.getForeground(crumb); - - return presentation.getBackgroundColor(isSelected(crumb), isHovered(crumb), isAfterSelected(crumb)); - } - - @Override - protected Color getBackground(Crumb crumb) { - CrumbPresentation presentation = PsiCrumb.getPresentation(crumb); - if (presentation == null) return super.getBackground(crumb); - - Color background = super.getBackground(crumb); - if (background == null) return null; - - return presentation.getBackgroundColor(isSelected(crumb), isHovered(crumb), isAfterSelected(crumb)); - } - }; + final PsiBreadcrumbs breadcrumbs = new PsiBreadcrumbs(); private final static Logger LOG = Logger.getInstance(BreadcrumbsXmlWrapper.class); @@ -256,7 +184,7 @@ public class BreadcrumbsXmlWrapper extends JComponent implements Disposable { ComponentAdapter resizeListener = new ComponentAdapter() { @Override public void componentResized(ComponentEvent event) { - updateBorder(gutterComponent.getWhitespaceSeparatorOffset()); + breadcrumbs.updateBorder(gutterComponent.getWhitespaceSeparatorOffset()); } }; @@ -266,10 +194,10 @@ public class BreadcrumbsXmlWrapper extends JComponent implements Disposable { removeComponentListener(resizeListener); gutterComponent.removeComponentListener(resizeListener); }); - updateBorder(gutterComponent.getWhitespaceSeparatorOffset()); + breadcrumbs.updateBorder(gutterComponent.getWhitespaceSeparatorOffset()); } else { - updateBorder(0); + breadcrumbs.updateBorder(0); } Disposer.register(this, new UiNotifyConnector(breadcrumbs, myQueue)); Disposer.register(this, myQueue); @@ -277,10 +205,6 @@ public class BreadcrumbsXmlWrapper extends JComponent implements Disposable { queueUpdate(); } - private void updateBorder(int offset) { - breadcrumbs.setBorder(BorderFactory.createEmptyBorder(above ? 2 : 0, offset, above ? 0 : 2, 0)); - } - private void updateCrumbs() { if (breadcrumbs != null && myEditor != null && !myEditor.isDisposed()) { breadcrumbs.setFont(getEditorFont(myEditor)); diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/PsiBreadcrumbs.java b/xml/impl/src/com/intellij/xml/breadcrumbs/PsiBreadcrumbs.java new file mode 100644 index 000000000000..ce1f7cc82ed1 --- /dev/null +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/PsiBreadcrumbs.java @@ -0,0 +1,90 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.xml.breadcrumbs; + +import com.intellij.openapi.editor.colors.EditorColors; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.util.registry.Registry; +import com.intellij.ui.RelativeFont; +import com.intellij.ui.components.breadcrumbs.Breadcrumbs; +import com.intellij.ui.components.breadcrumbs.Crumb; + +import javax.swing.border.EmptyBorder; +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; + +/** + * @author Sergey.Malenkov + */ +final class PsiBreadcrumbs extends Breadcrumbs { + final boolean above = Registry.is("editor.breadcrumbs.above"); + + void updateBorder(int offset) { + // do not use scaling here because this border is used to align breadcrumbs with a gutter + setBorder(new EmptyBorder(above ? 2 : 0, offset, above ? 0 : 2, 0)); + } + + @Override + protected void paint(Graphics2D g, int x, int y, int width, int height, int thickness) { + super.paint(g, x, y, width, above ? height : thickness, thickness); + } + + @Override + public void setFont(Font font) { + super.setFont(RelativeFont.SMALL.derive(font)); + } + + @Override + public Color getForeground() { + if (!isForegroundSet()) { + Color foreground = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.LINE_NUMBERS_COLOR); + if (foreground != null) return foreground; + } + return super.getForeground(); + } + + @Override + public Color getBackground() { + if (!isBackgroundSet()) { + Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.GUTTER_BACKGROUND); + if (background != null) return background; + } + return super.getBackground(); + } + + @Override + protected Color getForeground(Crumb crumb) { + CrumbPresentation presentation = PsiCrumb.getPresentation(crumb); + if (presentation == null) return super.getForeground(crumb); + + Color background = super.getBackground(crumb); + if (background != null) return super.getForeground(crumb); + + return presentation.getBackgroundColor(isSelected(crumb), isHovered(crumb), isAfterSelected(crumb)); + } + + @Override + protected Color getBackground(Crumb crumb) { + CrumbPresentation presentation = PsiCrumb.getPresentation(crumb); + if (presentation == null) return super.getBackground(crumb); + + Color background = super.getBackground(crumb); + if (background == null) return null; + + return presentation.getBackgroundColor(isSelected(crumb), isHovered(crumb), isAfterSelected(crumb)); + } +} diff --git a/xml/impl/src/com/intellij/xml/breadcrumbs/PsiCrumb.java b/xml/impl/src/com/intellij/xml/breadcrumbs/PsiCrumb.java new file mode 100644 index 000000000000..247f72e001b2 --- /dev/null +++ b/xml/impl/src/com/intellij/xml/breadcrumbs/PsiCrumb.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.xml.breadcrumbs; + +import com.intellij.psi.PsiElement; +import com.intellij.ui.components.breadcrumbs.Crumb; + +/** + * @author Sergey.Malenkov + */ +final class PsiCrumb extends Crumb.Impl { + final PsiElement element; + CrumbPresentation presentation; + + PsiCrumb(PsiElement element, BreadcrumbsInfoProvider provider) { + super(null, provider.getElementInfo(element), provider.getElementTooltip(element)); + this.element = element; + } + + static PsiElement getElement(Crumb crumb) { + return crumb instanceof PsiCrumb ? ((PsiCrumb)crumb).element : null; + } + + static CrumbPresentation getPresentation(Crumb crumb) { + return crumb instanceof PsiCrumb ? ((PsiCrumb)crumb).presentation : null; + } +}