mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
sort editor top-bottom components and make breadcrumbs the last
This commit is contained in:
@@ -28,6 +28,7 @@ import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.Weighted;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.components.panels.HorizontalLayout;
|
||||
@@ -50,7 +51,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class EditorNotificationPanel extends JPanel implements IntentionActionProvider {
|
||||
public class EditorNotificationPanel extends JPanel implements IntentionActionProvider, Weighted {
|
||||
protected final JLabel myLabel = new JLabel();
|
||||
protected final JLabel myGearLabel = new JLabel();
|
||||
protected final JPanel myLinksPanel = new NonOpaquePanel(new HorizontalLayout(JBUI.scale(5)));
|
||||
@@ -123,7 +124,12 @@ public class EditorNotificationPanel extends JPanel implements IntentionActionPr
|
||||
MyIntentionAction action = new MyIntentionAction();
|
||||
return action.getOptions().isEmpty() ? null : action;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private class MyIntentionAction extends AbstractEmptyIntentionAction implements IntentionActionWithOptions, Iconable {
|
||||
private final List<IntentionAction> myOptions = new ArrayList<IntentionAction>();
|
||||
|
||||
|
||||
+19
-5
@@ -30,10 +30,7 @@ import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorProviderManager;
|
||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.NullUtils;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.FocusWatcher;
|
||||
import com.intellij.ui.JBColor;
|
||||
@@ -42,6 +39,7 @@ import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.TabbedPaneWrapper;
|
||||
import com.intellij.ui.components.JBPanelWithEmptyText;
|
||||
import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.ui.components.panels.Wrapper;
|
||||
import com.intellij.ui.tabs.UiDecorator;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
@@ -326,11 +324,27 @@ public abstract class EditorComposite implements Disposable {
|
||||
else {
|
||||
NonOpaquePanel wrapper = new NonOpaquePanel(component);
|
||||
wrapper.setBorder(createTopBottomSideBorder(top));
|
||||
container.add(wrapper);
|
||||
container.add(wrapper, calcComponentInsertionIndex(component, container));
|
||||
}
|
||||
container.revalidate();
|
||||
}
|
||||
|
||||
private static int calcComponentInsertionIndex(@NotNull JComponent newComponent, @NotNull JComponent container) {
|
||||
for (int i = 0, max = container.getComponentCount(); i < max; i++) {
|
||||
Component childWrapper = container.getComponent(i);
|
||||
Component childComponent = childWrapper instanceof Wrapper ? ((Wrapper)childWrapper).getTargetComponent() : childWrapper;
|
||||
boolean weighted1 = newComponent instanceof Weighted;
|
||||
boolean weighted2 = childComponent instanceof Weighted;
|
||||
if (!weighted2) continue;
|
||||
if (!weighted1) return i;
|
||||
|
||||
double w1 = ((Weighted)newComponent).getWeight();
|
||||
double w2 = ((Weighted)childComponent).getWeight();
|
||||
if (w1 < w2) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setDisplayName(@NotNull FileEditor editor, @NotNull String name) {
|
||||
int index = ContainerUtil.indexOfIdentity(ContainerUtil.immutableList(myEditors), editor);
|
||||
assert index != -1;
|
||||
|
||||
@@ -51,6 +51,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.ui.Gray;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.JBEmptyBorder;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.UiNotifyConnector;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
@@ -62,7 +64,10 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/**
|
||||
* @author spleaner
|
||||
@@ -76,7 +81,6 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
|
||||
private boolean myUserCaretChange;
|
||||
private final MergingUpdateQueue myQueue;
|
||||
private final BreadcrumbsInfoProvider myInfoProvider;
|
||||
private final JPanel myWrapperPanel;
|
||||
|
||||
public static final Key<BreadcrumbsXmlWrapper> BREADCRUMBS_COMPONENT_KEY = new Key<BreadcrumbsXmlWrapper>("BREADCRUMBS_KEY");
|
||||
|
||||
@@ -198,12 +202,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
|
||||
Disposer.register(this, new UiNotifyConnector(myComponent, myQueue));
|
||||
Disposer.register(this, myQueue);
|
||||
|
||||
myWrapperPanel = new JPanel();
|
||||
myWrapperPanel.setLayout(new BorderLayout());
|
||||
myWrapperPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 1, 2));
|
||||
myWrapperPanel.setOpaque(false);
|
||||
|
||||
myWrapperPanel.add(myComponent, BorderLayout.CENTER);
|
||||
myComponent.setBorder(new JBEmptyBorder(JBUI.insets(2, 0, 1, 2)));
|
||||
queueUpdate(editor);
|
||||
}
|
||||
|
||||
@@ -372,7 +371,7 @@ public class BreadcrumbsXmlWrapper implements BreadcrumbsItemListener<Breadcrumb
|
||||
}
|
||||
|
||||
public JComponent getComponent() {
|
||||
return myWrapperPanel;
|
||||
return myComponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,16 +18,19 @@ package com.intellij.xml.breadcrumbs;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Weighted;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.Gray;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -38,7 +41,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author spleaner
|
||||
*/
|
||||
public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent implements Disposable {
|
||||
public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent implements Disposable, Weighted {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.xml.breadcrumbs.BreadcrumbsComponent");
|
||||
private static final Painter DEFAULT_PAINTER = new DefaultPainter(new ButtonSettings());
|
||||
|
||||
@@ -337,8 +340,12 @@ public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
final Graphics2D g2 = (Graphics2D)getGraphics();
|
||||
return new Dimension(Integer.MAX_VALUE, g2 != null ? DEFAULT_PAINTER.getSize("DUMMY", g2.getFontMetrics(), Integer.MAX_VALUE).height + 1 : 1);
|
||||
Border border = getBorder();
|
||||
Graphics2D g2 = (Graphics2D)getGraphics();
|
||||
Dimension dim = new Dimension(Integer.MAX_VALUE, g2 != null ? DEFAULT_PAINTER.getSize("DUMMY", g2.getFontMetrics(), Integer.MAX_VALUE).height + 1 : 1);
|
||||
Insets insets = border != null ? border.getBorderInsets(this) : JBUI.emptyInsets();
|
||||
dim.height += insets.top + insets.bottom;
|
||||
return dim;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -354,6 +361,11 @@ public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent
|
||||
myListeners = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getWeight() {
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
private static class PagedImage {
|
||||
private final int myPageWidth;
|
||||
private int myPage;
|
||||
@@ -709,13 +721,13 @@ public class BreadcrumbsComponent<T extends BreadcrumbsItem> extends JComponent
|
||||
final int width = c.getWidth();
|
||||
if (bg != null) {
|
||||
g2.setColor(bg);
|
||||
g2.fillRoundRect(offset + 2, 1, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE);
|
||||
g2.fillRoundRect(offset + 2, 2, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE);
|
||||
}
|
||||
|
||||
final Color borderColor = s.getBorderColor(c);
|
||||
if (borderColor != null) {
|
||||
g2.setColor(borderColor);
|
||||
g2.drawRoundRect(offset + 2, 1, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE);
|
||||
g2.drawRoundRect(offset + 2, 2, width - 4, height - 3, ROUND_VALUE, ROUND_VALUE);
|
||||
}
|
||||
|
||||
final Color textColor = s.getForegroundColor(c);
|
||||
|
||||
Reference in New Issue
Block a user