From abb8bee8aea01c8e6e2bd56088af117304ecbc18 Mon Sep 17 00:00:00 2001 From: Alexander Kass Date: Wed, 13 May 2015 18:44:48 +0300 Subject: [PATCH] DBE: expanded renderer allows to render sub components --- .../roots/ui/configuration/SidePanel.java | 16 +++++-- .../ExpandedItemListCellRendererWrapper.java | 18 +++++++- .../ui/ExpandedSubComponentProvider.java | 27 ++++++++++++ .../ui/AbstractExpandableItemsHandler.java | 44 +++++++++++++++++++ .../ui/ListExpandableItemsHandler.java | 8 ++++ .../popup/list/GroupedItemsListRenderer.java | 10 ++++- 6 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/ui/ExpandedSubComponentProvider.java diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java index 0183dc77d818..6ae66af56072 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java @@ -17,11 +17,10 @@ package com.intellij.openapi.roots.ui.configuration; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.ui.popup.ListItemDescriptor; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.registry.Registry; -import com.intellij.ui.Gray; -import com.intellij.ui.JBColor; -import com.intellij.ui.ScrollPaneFactory; -import com.intellij.ui.SeparatorWithText; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.*; import com.intellij.ui.components.JBList; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.navigation.History; @@ -100,6 +99,14 @@ public class SidePanel extends JPanel { mySeparatorComponent.setCaptionCentered(false); } + @Nullable + @Override + public Pair getExpandedSubComponent(Component comp) { + if (myCountLabel.isVisible() && !StringUtil.isEmpty(myCountLabel.getText())) + return AbstractExpandableItemsHandler.getExpandedSubComponent(comp, myExtraPanel); + return AbstractExpandableItemsHandler.getExpandedSubComponentPreferred(comp, myComponent); + } + @Override protected Color getForeground() { return Registry.is("ide.new.project.settings") ? new JBColor(Gray._60, Gray._140) : super.getForeground(); @@ -124,6 +131,7 @@ public class SidePanel extends JPanel { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + layout(); myCountLabel.setText(""); final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if ("Problems".equals(descriptor.getTextFor(value))) { diff --git a/platform/platform-api/src/com/intellij/ui/ExpandedItemListCellRendererWrapper.java b/platform/platform-api/src/com/intellij/ui/ExpandedItemListCellRendererWrapper.java index 7de2d9ed786a..431024562137 100644 --- a/platform/platform-api/src/com/intellij/ui/ExpandedItemListCellRendererWrapper.java +++ b/platform/platform-api/src/com/intellij/ui/ExpandedItemListCellRendererWrapper.java @@ -15,12 +15,14 @@ */ package com.intellij.ui; +import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -public class ExpandedItemListCellRendererWrapper implements ListCellRenderer { +public class ExpandedItemListCellRendererWrapper implements ListCellRenderer, ExpandedSubComponentProvider { @NotNull private final ListCellRenderer myWrappee; @NotNull private final ExpandableItemsHandler myHandler; @@ -42,4 +44,18 @@ public class ExpandedItemListCellRendererWrapper implements ListCellRenderer { public ListCellRenderer getWrappee() { return myWrappee; } + + @Nullable + @Override + public Pair getExpandedSubComponent(Component comp) { + if (myWrappee instanceof ExpandedSubComponentProvider) { + Pair res = ((ExpandedSubComponentProvider)myWrappee).getExpandedSubComponent(comp); + if (res != null && res.getFirst() != comp) { + Component wrapped = new ExpandedItemRendererComponentWrapper(res.getFirst()); + return Pair.create(wrapped, res.getSecond()); + } + return res; + } + return Pair.create(comp, null); + } } diff --git a/platform/platform-api/src/com/intellij/ui/ExpandedSubComponentProvider.java b/platform/platform-api/src/com/intellij/ui/ExpandedSubComponentProvider.java new file mode 100644 index 000000000000..e7be4ea9fefb --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/ExpandedSubComponentProvider.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2015 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.ui; + +import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +public interface ExpandedSubComponentProvider { + //note: returned component will be removed from parent container + @Nullable + Pair getExpandedSubComponent(Component comp); +} diff --git a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java index 4ea30d0a2a4b..e8b8f2573829 100644 --- a/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/AbstractExpandableItemsHandler.java @@ -55,6 +55,21 @@ public abstract class AbstractExpandableItemsHandler getExpandedSubComponent(Component comp, @NotNull Component child) { + if (UIUtil.isAncestor(comp, child)) { + return Pair.create(child, SwingUtilities.convertRectangle(child, new Rectangle(child.getSize()), comp)); + } + return Pair.create(comp, null); + } + + public static Pair getExpandedSubComponentPreferred(Component comp, @NotNull Component child) { + if (UIUtil.isAncestor(comp, child)) { + return Pair.create(child, SwingUtilities.convertRectangle(child, new Rectangle(child.getPreferredSize()), comp)); + } + return Pair.create(comp, null); + } + + protected AbstractExpandableItemsHandler(@NotNull final ComponentType component) { myComponent = component; myComponent.add(myRendererPane); @@ -366,6 +381,30 @@ public abstract class AbstractExpandableItemsHandler rendererAndBounds = getCellRendererAndBounds(key); + ExpandedSubComponentProvider subComponentProvider = getExpandedSubComponentProvider(); + if (subComponentProvider != null && rendererAndBounds != null) { + Component comp = rendererAndBounds.getFirst(); + myRendererPane.add(comp); + try { + comp.setBounds(rendererAndBounds.getSecond()); + comp.validate(); + Pair subComponent = subComponentProvider.getExpandedSubComponent(comp); + if (subComponent == null) { + rendererAndBounds = null; + } + else if(subComponent.getSecond() == null) { + rendererAndBounds = Pair.create(subComponent.getFirst(), rendererAndBounds.getSecond()); + } + else { + Point offset = rendererAndBounds.getSecond().getLocation(); + subComponent.getSecond().translate((int)offset.getX(), (int)offset.getY()); + rendererAndBounds = subComponent; + } + } + finally { + myRendererPane.remove(comp); + } + } if (rendererAndBounds == null) return null; Component renderer = rendererAndBounds.first; @@ -450,6 +489,11 @@ public abstract class AbstractExpandableItemsHandler getCellRendererAndBounds(KeyType key); diff --git a/platform/platform-impl/src/com/intellij/ui/ListExpandableItemsHandler.java b/platform/platform-impl/src/com/intellij/ui/ListExpandableItemsHandler.java index 86e85f86636f..ea8a9639e095 100644 --- a/platform/platform-impl/src/com/intellij/ui/ListExpandableItemsHandler.java +++ b/platform/platform-impl/src/com/intellij/ui/ListExpandableItemsHandler.java @@ -16,6 +16,8 @@ package com.intellij.ui; import com.intellij.openapi.util.Pair; +import com.intellij.util.ObjectUtils; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.event.ListDataEvent; @@ -94,6 +96,12 @@ public class ListExpandableItemsHandler extends AbstractExpandableItemsHandler getCellRendererAndBounds(Integer key) { int rowIndex = key.intValue(); diff --git a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java index 9383f5c3f08e..936d57712659 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/list/GroupedItemsListRenderer.java @@ -16,16 +16,19 @@ package com.intellij.ui.popup.list; import com.intellij.openapi.ui.popup.ListItemDescriptor; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.ErrorLabel; +import com.intellij.ui.ExpandedSubComponentProvider; import com.intellij.ui.GroupedElementsRenderer; import com.intellij.ui.components.panels.OpaquePanel; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -public class GroupedItemsListRenderer extends GroupedElementsRenderer.List implements ListCellRenderer { +public class GroupedItemsListRenderer extends GroupedElementsRenderer.List implements ListCellRenderer, ExpandedSubComponentProvider { protected ListItemDescriptor myDescriptor; protected JLabel myNextStepLabel; @@ -53,6 +56,11 @@ public class GroupedItemsListRenderer extends GroupedElementsRenderer.List imple return result; } + @Nullable + @Override + public Pair getExpandedSubComponent(Component comp) { + return Pair.create(comp, null); + } @Override protected JComponent createItemComponent() {