mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[ui] un-deprecates ListCellRendererWrapper and makes it usable as a generic renderer
This commit is contained in:
@@ -1,45 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.containers.FList;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicComboBoxRenderer;
|
||||
import java.awt.*;
|
||||
|
||||
import static com.intellij.openapi.util.Pair.pair;
|
||||
|
||||
/**
|
||||
* Please use this wrapper in case you need simple cell renderer with text and icon.
|
||||
* This avoids ugly UI under GTK+ look&feel, because in this case SynthComboBoxUI#SynthComboBoxRenderer
|
||||
* is used instead of DefaultComboBoxRenderer.
|
||||
* Use this class when you need a customizable text-and-icon cell renderer.
|
||||
*
|
||||
* @author oleg
|
||||
* @deprecated GTK+ LaF is obsolete
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class ListCellRendererWrapper<T> implements ListCellRenderer<T> {
|
||||
private final ListCellRenderer myDefaultRenderer;
|
||||
|
||||
private final ListCellRenderer<? super T> myRenderer;
|
||||
private boolean mySeparator;
|
||||
private Icon myIcon;
|
||||
private String myText;
|
||||
@@ -51,16 +32,11 @@ public abstract class ListCellRendererWrapper<T> implements ListCellRenderer<T>
|
||||
|
||||
@SuppressWarnings("UndesirableClassUsage")
|
||||
public ListCellRendererWrapper() {
|
||||
ListCellRenderer renderer = new JComboBox().getRenderer();
|
||||
if (renderer == null) {
|
||||
renderer = new BasicComboBoxRenderer();
|
||||
Logger.getInstance(this.getClass()).error("LaF: " + UIManager.getLookAndFeel());
|
||||
}
|
||||
myDefaultRenderer = renderer;
|
||||
myRenderer = new JComboBox<T>().getRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
public final Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
|
||||
mySeparator = false;
|
||||
myIcon = null;
|
||||
myText = null;
|
||||
@@ -70,20 +46,19 @@ public abstract class ListCellRendererWrapper<T> implements ListCellRenderer<T>
|
||||
myToolTipText = null;
|
||||
myProperties = FList.emptyList();
|
||||
|
||||
@SuppressWarnings("unchecked") final T t = (T)value;
|
||||
customize(list, t, index, isSelected, cellHasFocus);
|
||||
customize(list, value, index, selected, hasFocus);
|
||||
|
||||
if (mySeparator) {
|
||||
return createSeparator(myText);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") final Component component = myDefaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
Component component = myRenderer != null ? myRenderer.getListCellRendererComponent(list, value, index, selected, hasFocus) : new JBLabel();
|
||||
if (component instanceof JLabel) {
|
||||
final JLabel label = (JLabel)component;
|
||||
JLabel label = (JLabel)component;
|
||||
label.setIcon(myIcon);
|
||||
if (myText != null) label.setText(myText);
|
||||
if (myForeground != null) label.setForeground(myForeground);
|
||||
if (myBackground != null && !isSelected) label.setBackground(myBackground);
|
||||
if (myBackground != null && !selected) label.setBackground(myBackground);
|
||||
if (myFont != null) label.setFont(myFont);
|
||||
label.setToolTipText(myToolTipText);
|
||||
for (Pair<Object, Object> pair : myProperties) {
|
||||
@@ -95,8 +70,8 @@ public abstract class ListCellRendererWrapper<T> implements ListCellRenderer<T>
|
||||
|
||||
@NotNull
|
||||
public static Component createSeparator(@Nullable String text) {
|
||||
final TitledSeparator separator = new TitledSeparator(text);
|
||||
separator.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
|
||||
TitledSeparator separator = new TitledSeparator(text);
|
||||
separator.setBorder(JBUI.Borders.emptyLeft(2));
|
||||
separator.setOpaque(false);
|
||||
separator.setBackground(UIUtil.TRANSPARENT_COLOR);
|
||||
separator.getLabel().setOpaque(false);
|
||||
|
||||
Reference in New Issue
Block a user