Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-08-03 11:45:54 +02:00
5 changed files with 123 additions and 160 deletions
@@ -19,21 +19,20 @@ import com.intellij.designer.model.ErrorInfo;
import com.intellij.designer.model.PropertiesContainer;
import com.intellij.designer.model.Property;
import com.intellij.designer.model.PropertyContext;
import com.intellij.icons.AllIcons;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
import com.intellij.ui.*;
import com.intellij.ui.ColoredTableCellRenderer;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.TableUtil;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.IndentedIcon;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -79,6 +78,10 @@ public abstract class PropertyTable extends JBTable {
setModel(myModel);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
showColumns(false);
setShowGrid(false);
setRowSelectionAllowed(true);
setColumnSelectionAllowed(false);
addMouseListener(new MouseTableListener());
@@ -874,6 +877,14 @@ public abstract class PropertyTable extends JBTable {
}
}
private static int getDepth(@NotNull Property property) {
int result = 0;
for (Property each = property.getParent(); each != null; each = each.getParent(), result++) {
// empty
}
return result;
}
private class PropertyCellEditorListener implements PropertyEditorListener {
@Override
public void valueCommitted(PropertyEditor source, boolean continueEditing, boolean closeEditorOnError) {
@@ -969,161 +980,89 @@ public abstract class PropertyTable extends JBTable {
protected abstract TextAttributesKey getErrorAttributes(@NotNull HighlightSeverity severity);
private class PropertyCellRenderer implements TableCellRenderer {
private final Map<HighlightSeverity, SimpleTextAttributes> myRegularAttributes = new HashMap<HighlightSeverity, SimpleTextAttributes>();
private final Map<HighlightSeverity, SimpleTextAttributes> myBoldAttributes = new HashMap<HighlightSeverity, SimpleTextAttributes>();
private final Map<HighlightSeverity, SimpleTextAttributes> myItalicAttributes = new HashMap<HighlightSeverity, SimpleTextAttributes>();
private final ColoredTableCellRenderer myPropertyNameRenderer;
private final ColoredTableCellRenderer myErrorRenderer;
private final Icon myExpandIcon;
private final Icon myCollapseIcon;
private final Icon myIndentedExpandIcon;
private final Icon myIndentedCollapseIcon;
private final Icon[] myIndentIcons = new Icon[3];
private final ColoredTableCellRenderer myRenderer;
private PropertyCellRenderer() {
myPropertyNameRenderer = new ColoredTableCellRenderer() {
protected void customizeCellRenderer(
JTable table,
Object value,
boolean selected,
boolean hasFocus,
int row,
int column
) {
myRenderer = new ColoredTableCellRenderer() {
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
setPaintFocusBorder(false);
setFocusBorderAroundIcon(true);
}
};
myErrorRenderer = new ColoredTableCellRenderer() {
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
setPaintFocusBorder(false);
}
};
myExpandIcon = AllIcons.Nodes.ExpandNode;
myCollapseIcon = AllIcons.Nodes.CollapseNode;
for (int i = 0; i < myIndentIcons.length; i++) {
myIndentIcons[i] = new EmptyIcon(9 + 11 * i, 9);
}
myIndentedExpandIcon = new IndentedIcon(myExpandIcon, 11);
myIndentedCollapseIcon = new IndentedIcon(myCollapseIcon, 11);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean selected,
boolean cellHasFocus,
int row,
int column) {
column = table.convertColumnIndexToModel(column);
Property property = (Property)value;
Color background = table.getBackground();
boolean isDefault = true;
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
boolean tableHasFocus = focusOwner != null && SwingUtilities.isDescendingFrom(focusOwner, table);
try {
isDefault = isDefault(property);
}
catch (Throwable e) {
catch (Exception e) {
LOG.debug(e);
}
if (isDefault) {
background = Gray._240;
}
myRenderer.clear();
if (column == 0) {
myPropertyNameRenderer.getTableCellRendererComponent(table, value, selected, hasFocus, row, column);
myRenderer.getTableCellRendererComponent(table, value, selected, cellHasFocus, row, column);
if (!selected) {
myPropertyNameRenderer.setBackground(background);
myRenderer.setBackground(selected ? UIUtil.getTreeSelectionBackground(tableHasFocus) : background);
SimpleTextAttributes attr = SimpleTextAttributes.REGULAR_ATTRIBUTES;
if (!selected && !isDefault) {
attr = attr.derive(-1, FileStatus.MODIFIED.getColor(), null, null);
}
SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
if (property.isImportant()) {
attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
attr = attr.derive(attr.getStyle() | SimpleTextAttributes.STYLE_BOLD, null, null, null);
}
else if (property.isExpert()) {
attributes = SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES;
if (property.isExpert()) {
attr = attr.derive(attr.getStyle() | SimpleTextAttributes.STYLE_ITALIC, null, null, null);
}
if (property.isDeprecated()) {
attr = attr.derive(attr.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT, null, null, null);
}
ErrorInfo errorInfo = getErrorInfoForRow(row);
if (errorInfo != null) {
Map<HighlightSeverity, SimpleTextAttributes> cache = myRegularAttributes;
if (property.isImportant()) {
cache = myBoldAttributes;
}
else if (property.isExpert()) {
cache = myItalicAttributes;
}
SimpleTextAttributes template = SimpleTextAttributes.fromTextAttributes(
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(getErrorAttributes(errorInfo.getLevel().getSeverity())));
HighlightSeverity severity = errorInfo.getLevel().getSeverity();
SimpleTextAttributes errorAttributes = cache.get(severity);
if (errorAttributes == null) {
TextAttributesKey attributesKey = getErrorAttributes(severity);
TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
if (property.isImportant()) {
textAttributes = textAttributes.clone();
textAttributes.setFontType(textAttributes.getFontType() | Font.BOLD);
}
else if (property.isExpert()) {
textAttributes = textAttributes.clone();
textAttributes.setFontType(textAttributes.getFontType() | Font.ITALIC);
}
errorAttributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
cache.put(severity, errorAttributes);
}
attributes = errorAttributes;
int style = ((template.getStyle() & SimpleTextAttributes.STYLE_WAVED) != 0 ? SimpleTextAttributes.STYLE_WAVED : 0)
| ((template.getStyle() & SimpleTextAttributes.STYLE_UNDERLINE) != 0 ? SimpleTextAttributes.STYLE_UNDERLINE : 0);
attr = attr.derive(attr.getStyle() | style, template.getFgColor(), template.getBgColor(), template.getWaveColor());
}
if (property.isDeprecated()) {
attributes = new SimpleTextAttributes(attributes.getBgColor(), attributes.getFgColor(), attributes.getWaveColor(),
attributes.getStyle() | SimpleTextAttributes.STYLE_STRIKEOUT);
}
myRenderer.append(property.getName(), attr);
myPropertyNameRenderer.append(property.getName(), attributes);
Icon icon = UIUtil.getTreeNodeIcon(isExpanded(property), selected, tableHasFocus);
boolean hasChildren = !getChildren(property).isEmpty();
if (!getChildren(property).isEmpty()) {
if (property.getParent() == null) {
if (isExpanded(property)) {
myPropertyNameRenderer.setIcon(myCollapseIcon);
}
else {
myPropertyNameRenderer.setIcon(myExpandIcon);
}
}
else {
if (isExpanded(property)) {
myPropertyNameRenderer.setIcon(myIndentedCollapseIcon);
}
else {
myPropertyNameRenderer.setIcon(myIndentedExpandIcon);
}
}
}
else {
myPropertyNameRenderer.setIcon(myIndentIcons[property.getIndent()]);
}
myRenderer.setIcon(hasChildren ? icon : null);
int indent = (icon.getIconWidth() + myRenderer.getIconTextGap()) * (getDepth(property) + (hasChildren ? 0 : 1));
myRenderer.setIpad(new Insets(0, indent, 0, 0));
if (!selected) {
if (isDefault) {
myPropertyNameRenderer.setForeground(property.isExpert() ? Color.LIGHT_GRAY : table.getForeground());
}
else {
myPropertyNameRenderer.setForeground(FileStatus.MODIFIED.getColor());
}
}
return myPropertyNameRenderer;
return myRenderer;
}
else {
try {
PropertyRenderer renderer = property.getRenderer();
JComponent component = renderer.getComponent(getCurrentComponent(), getPropertyContext(), getValue(property), selected, hasFocus);
if (!selected) {
component.setBackground(background);
}
JComponent component =
renderer.getComponent(getCurrentComponent(), getPropertyContext(), getValue(property), selected, tableHasFocus);
component.setBackground(selected ? UIUtil.getTreeSelectionBackground(tableHasFocus) : background);
component.setFont(table.getFont());
if (component instanceof JCheckBox) {
@@ -1132,11 +1071,11 @@ public abstract class PropertyTable extends JBTable {
return component;
}
catch (Throwable e) {
catch (Exception e) {
LOG.debug(e);
myErrorRenderer.clear();
myErrorRenderer.append(formatErrorGettingValueMesage(e.getMessage()), SimpleTextAttributes.ERROR_ATTRIBUTES);
return myErrorRenderer;
myRenderer.getTableCellRendererComponent(table, value, selected, cellHasFocus, row, column);
myRenderer.append(formatErrorGettingValueMesage(e.getMessage()), SimpleTextAttributes.ERROR_ATTRIBUTES);
return myRenderer;
}
}
}
@@ -154,7 +154,7 @@ public class TreeExpandableItemsHandler extends AbstractExpandableItemsHandler<I
}
if (myComponent.isRowSelected(key)) {
rComponent.setBackground(myComponent.hasFocus() ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground());
rComponent.setBackground(UIUtil.getTreeSelectionBackground(myComponent.hasFocus()));
} else {
Color bg = UIUtil.getTreeTextBackground();
if (myComponent instanceof Tree && ((Tree)myComponent).isFileColorsEnabled()) {
@@ -20,27 +20,42 @@ import javax.swing.*;
import java.awt.*;
public class CenteredIcon implements Icon {
private final Icon myIcon;
private Icon myIcon;
private final int myWidth;
private final int myHight;
private int myWidth;
private int myHight;
private final boolean myCenteredInComponent;
public CenteredIcon(Icon icon) {
this(icon, icon.getIconWidth(), icon.getIconHeight());
this(icon, icon.getIconWidth(), icon.getIconHeight(), true);
}
public CenteredIcon(Icon icon, int width, int hight) {
public CenteredIcon(Icon icon, int width, int height) {
this(icon, width, height, true);
}
public CenteredIcon(Icon icon, int width, int height, boolean centeredInComponent) {
myIcon = icon;
myWidth = width;
myHight = hight;
myHight = height;
myCenteredInComponent = centeredInComponent;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
final Dimension size = c.getSize();
int actualX = size.width / 2 - myIcon.getIconWidth() /2;
int actualY = size.height / 2 - myIcon.getIconHeight() /2;
int actualX;
int actualY;
if (myCenteredInComponent) {
actualX = size.width / 2 - myIcon.getIconWidth() / 2;
actualY = size.height / 2 - myIcon.getIconHeight() / 2;
}
else {
actualX = (myWidth - myIcon.getIconWidth()) / 2;
actualY = (myHight - myIcon.getIconHeight()) / 2;
}
myIcon.paintIcon(c, g, x + actualX, y + actualY);
}
@@ -506,7 +506,7 @@ public class UIUtil {
public static Color getInactiveTextColor() {
return UIManager.getColor("textInactiveText");
}
public static Color getSlightlyDarkerColor(Color c) {
float[] hsl = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), new float[3]);
return new Color(Color.HSBtoRGB(hsl[0], hsl[1], hsl[2] - .08f > 0 ? hsl[2] - .08f : hsl[2]));
@@ -668,6 +668,10 @@ public class UIUtil {
return isUnderDarcula() ? Gray._52 : UNFOCUSED_SELECTION_COLOR;
}
public static Color getTreeSelectionBackground(boolean focused) {
return focused ? getTreeSelectionBackground() : getTreeUnfocusedSelectionBackground();
}
public static Color getTreeUnfocusedSelectionBackground() {
Color background = getTreeTextBackground();
return ColorUtil.isDark(background) ? Gray._30 : UNFOCUSED_SELECTION_COLOR;
@@ -811,6 +815,20 @@ public class UIUtil {
return UIManager.getIcon("RadioButton.icon");
}
public static Icon getTreeNodeIcon(boolean expanded, boolean selected, boolean focused) {
boolean white = (selected && focused) || isUnderDarcula();
Icon selectedIcon = getTreeSelectedExpandedIcon();
Icon notSelectedIcon = getTreeExpandedIcon();
int widht = Math.max(selectedIcon.getIconWidth(), notSelectedIcon.getIconWidth());
int height = Math.max(selectedIcon.getIconWidth(), notSelectedIcon.getIconWidth());
return new CenteredIcon(expanded ? (white ? getTreeSelectedExpandedIcon() : getTreeExpandedIcon())
: (white ? getTreeSelectedCollapsedIcon() : getTreeCollapsedIcon()),
widht, height, false);
}
public static Icon getTreeCollapsedIcon() {
return UIManager.getIcon("Tree.collapsedIcon");
}
@@ -819,6 +837,16 @@ public class UIUtil {
return UIManager.getIcon("Tree.expandedIcon");
}
public static Icon getTreeSelectedCollapsedIcon() {
return isUnderAquaBasedLookAndFeel() || isUnderNimbusLookAndFeel() || isUnderGTKLookAndFeel()
? AllIcons.Mac.Tree_white_right_arrow : getTreeCollapsedIcon();
}
public static Icon getTreeSelectedExpandedIcon() {
return isUnderAquaBasedLookAndFeel() || isUnderNimbusLookAndFeel() || isUnderGTKLookAndFeel()
? AllIcons.Mac.Tree_white_down_arrow : getTreeExpandedIcon();
}
public static Border getTableHeaderCellBorder() {
return UIManager.getBorder("TableHeader.cellBorder");
}
@@ -1362,7 +1390,7 @@ public class UIUtil {
* <p/>
* The whole idea is that <a href="http://en.wikipedia.org/wiki/X_Rendering_Extension">XRender-based</a> pipeline doesn't support
* {@link AlphaComposite#SRC} and we should use {@link AlphaComposite#SRC_OVER} instead.
*
*
* @param g target graphics container
*/
public static void setupComposite(@NotNull Graphics2D g) {
@@ -1671,7 +1699,7 @@ public class UIUtil {
public static Color getBorderColor() {
return BORDER_COLOR;
}
public static Font getTitledBorderFont() {
Font defFont = getLabelFont();
return defFont.deriveFont(Math.max(defFont.getSize() - 2f, 11f));
@@ -2331,7 +2359,7 @@ public class UIUtil {
public static JComponent mergeComponentsWithAnchor(PanelWithAnchor...panels) {
return mergeComponentsWithAnchor(Arrays.asList(panels));
}
@Nullable
public static JComponent mergeComponentsWithAnchor(Collection<? extends PanelWithAnchor> panels) {
JComponent maxWidthAnchor = null;
@@ -2379,7 +2407,7 @@ public class UIUtil {
component.setBorder(new EmptyBorder(insets));
}
}
public static Dimension addInsets(@NotNull Dimension dimension, @NotNull Insets insets) {
Dimension ans = new Dimension(dimension);
@@ -15,7 +15,6 @@
*/
package com.intellij.util.ui.tree;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.containers.ComparatorUtil;
import com.intellij.util.ui.UIUtil;
@@ -40,16 +39,6 @@ public class WideSelectionTreeUI extends BasicTreeUI {
@NonNls public static final String SOURCE_LIST_CLIENT_PROPERTY = "mac.ui.source.list";
@NonNls public static final String STRIPED_CLIENT_PROPERTY = "mac.ui.striped";
private static Icon getTreeSelectedCollapsedIcon() {
return UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() || UIUtil.isUnderGTKLookAndFeel()
? AllIcons.Mac.Tree_white_right_arrow : UIUtil.getTreeCollapsedIcon();
}
private static Icon getTreeSelectedExpandedIcon() {
return UIUtil.isUnderAquaBasedLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() || UIUtil.isUnderGTKLookAndFeel()
? AllIcons.Mac.Tree_white_down_arrow : UIUtil.getTreeExpandedIcon();
}
private static final Border LIST_BACKGROUND_PAINTER = UIManager.getBorder("List.sourceListBackgroundPainter");
private static final Border LIST_SELECTION_BACKGROUND_PAINTER = UIManager.getBorder("List.sourceListSelectionBackgroundPainter");
private static final Border LIST_FOCUSED_SELECTION_BACKGROUND_PAINTER = UIManager.getBorder("List.sourceListFocusedSelectionBackgroundPainter");
@@ -315,7 +304,7 @@ public class WideSelectionTreeUI extends BasicTreeUI {
}
else {
if (UIUtil.isUnderAquaBasedLookAndFeel()) {
Color bg = tree.hasFocus() ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground();
Color bg = UIUtil.getTreeSelectionBackground(tree.hasFocus());
if (!selected) {
bg = background;
}
@@ -370,7 +359,7 @@ public class WideSelectionTreeUI extends BasicTreeUI {
for (int row = firstVisibleRow; row <= lastVisibleRow; row++) {
if (tr.getSelectionModel().isRowSelected(row)) {
final Rectangle bounds = tr.getRowBounds(row);
Color color = tr.hasFocus() ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground();
Color color = UIUtil.getTreeSelectionBackground(tr.hasFocus());
if (color != null) {
g.setColor(color);
g.fillRect(0, bounds.y, tr.getWidth(), bounds.height);
@@ -404,17 +393,9 @@ public class WideSelectionTreeUI extends BasicTreeUI {
boolean hasBeenExpanded,
boolean isLeaf) {
boolean isPathSelected = tree.getSelectionModel().isPathSelected(path);
boolean dark = UIUtil.isUnderDarcula();
Icon expandIcon = (isPathSelected && tree.hasFocus()) || dark ? getTreeSelectedExpandedIcon()
: UIUtil.getTreeExpandedIcon();
Icon collapseIcon = (isPathSelected && tree.hasFocus()) || dark? getTreeSelectedCollapsedIcon()
: UIUtil.getTreeCollapsedIcon();
if (!isLeaf(row)) {
setExpandedIcon(expandIcon);
setCollapsedIcon(collapseIcon);
setExpandedIcon(UIUtil.getTreeNodeIcon(true, isPathSelected, tree.hasFocus()));
setCollapsedIcon(UIUtil.getTreeNodeIcon(false, isPathSelected, tree.hasFocus()));
}
super.paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);