mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DBE: expanded renderer allows to render sub components
This commit is contained in:
@@ -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<Component, Rectangle> 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))) {
|
||||
|
||||
@@ -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<Integer> myHandler;
|
||||
|
||||
@@ -42,4 +44,18 @@ public class ExpandedItemListCellRendererWrapper implements ListCellRenderer {
|
||||
public ListCellRenderer getWrappee() {
|
||||
return myWrappee;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Pair<Component, Rectangle> getExpandedSubComponent(Component comp) {
|
||||
if (myWrappee instanceof ExpandedSubComponentProvider) {
|
||||
Pair<Component, Rectangle> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Component, Rectangle> getExpandedSubComponent(Component comp);
|
||||
}
|
||||
@@ -55,6 +55,21 @@ public abstract class AbstractExpandableItemsHandler<KeyType, ComponentType exte
|
||||
private Rectangle myKeyItemBounds;
|
||||
private BufferedImage myImage;
|
||||
|
||||
public static Pair<Component, Rectangle> 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<Component, Rectangle> 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<KeyType, ComponentType exte
|
||||
@Nullable
|
||||
private Point createToolTipImage(@NotNull KeyType key) {
|
||||
Pair<Component, Rectangle> 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<Component, Rectangle> 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<KeyType, ComponentType exte
|
||||
return myComponent.getVisibleRect();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ExpandedSubComponentProvider getExpandedSubComponentProvider() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Pair<Component, Rectangle> getCellRendererAndBounds(KeyType key);
|
||||
|
||||
|
||||
@@ -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<I
|
||||
return rowIndex != -1 ? new Integer(rowIndex) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected ExpandedSubComponentProvider getExpandedSubComponentProvider() {
|
||||
return ObjectUtils.tryCast(myComponent.getCellRenderer(), ExpandedSubComponentProvider.class);
|
||||
}
|
||||
|
||||
protected Pair<Component, Rectangle> getCellRendererAndBounds(Integer key) {
|
||||
int rowIndex = key.intValue();
|
||||
|
||||
|
||||
@@ -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<Component, Rectangle> getExpandedSubComponent(Component comp) {
|
||||
return Pair.create(comp, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createItemComponent() {
|
||||
|
||||
Reference in New Issue
Block a user