mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
Color property
This commit is contained in:
+5
-51
@@ -20,14 +20,11 @@ import com.intellij.designer.ModuleProvider;
|
||||
import com.intellij.designer.model.PropertiesContainer;
|
||||
import com.intellij.designer.model.PropertyContext;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.propertyTable.PropertyRenderer;
|
||||
import com.intellij.designer.propertyTable.PropertyTable;
|
||||
import com.intellij.designer.propertyTable.renderers.AbstractResourceRenderer;
|
||||
import com.intellij.designer.propertyTable.renderers.BooleanRenderer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.jetbrains.android.dom.attrs.AttributeFormat;
|
||||
import org.jetbrains.android.dom.resources.ResourceElement;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
@@ -44,22 +41,17 @@ import java.util.Set;
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class ResourceRenderer implements PropertyRenderer {
|
||||
public class ResourceRenderer extends AbstractResourceRenderer {
|
||||
public static final String[] DIMENSIONS = {"dp", "sp", "pt", "px", "mm", "in"};
|
||||
private static final String ANDROID_PREFIX = "@android:";
|
||||
|
||||
private final ColorIcon myColorIcon = new ColorIcon(10, 9);
|
||||
private BooleanRenderer myBooleanRenderer;
|
||||
protected final SimpleColoredComponent myColoredComponent;
|
||||
private final Set<AttributeFormat> myFormats;
|
||||
|
||||
public ResourceRenderer(Set<AttributeFormat> formats) {
|
||||
if (formats.contains(AttributeFormat.Boolean)) {
|
||||
myBooleanRenderer = new BooleanRenderer();
|
||||
}
|
||||
|
||||
myColoredComponent = new SimpleColoredComponent();
|
||||
|
||||
myFormats = formats;
|
||||
}
|
||||
|
||||
@@ -71,18 +63,14 @@ public class ResourceRenderer implements PropertyRenderer {
|
||||
boolean selected,
|
||||
boolean hasFocus) {
|
||||
String value = (String)object;
|
||||
|
||||
if (myBooleanRenderer != null && (StringUtil.isEmpty(value) || "false".equals(value) || "true".equals(value))) {
|
||||
return myBooleanRenderer.getComponent(container, context, "true".equals(value), selected, hasFocus);
|
||||
}
|
||||
|
||||
myColoredComponent.clear();
|
||||
PropertyTable.updateRenderer(myColoredComponent, selected);
|
||||
if (container instanceof RadComponent) formatValue((RadComponent)container, value);
|
||||
|
||||
return myColoredComponent;
|
||||
return super.getComponent(container, context, object, selected, hasFocus);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void formatValue(RadComponent component, String value) {
|
||||
if (!StringUtil.isEmpty(value)) {
|
||||
StringBuilder colorValue = new StringBuilder();
|
||||
@@ -212,40 +200,6 @@ public class ResourceRenderer implements PropertyRenderer {
|
||||
if (myBooleanRenderer != null) {
|
||||
SwingUtilities.updateComponentTreeUI(myBooleanRenderer);
|
||||
}
|
||||
SwingUtilities.updateComponentTreeUI(myColoredComponent);
|
||||
}
|
||||
|
||||
private static class ColorIcon extends EmptyIcon {
|
||||
private final int myColorSize;
|
||||
private Color myColor;
|
||||
|
||||
public ColorIcon(int size, int colorSize) {
|
||||
super(size, size);
|
||||
myColorSize = colorSize;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component component, Graphics g, final int left, final int top) {
|
||||
int iconWidth = getIconWidth();
|
||||
int iconHeight = getIconHeight();
|
||||
|
||||
SimpleColoredComponent coloredComponent = (SimpleColoredComponent)component;
|
||||
g.setColor(component.getBackground());
|
||||
g.fillRect(left - coloredComponent.getIpad().left, 0,
|
||||
iconWidth + coloredComponent.getIpad().left + coloredComponent.getIconTextGap(), component.getHeight());
|
||||
|
||||
int x = left + (iconWidth - myColorSize) / 2;
|
||||
int y = top + (iconHeight - myColorSize) / 2;
|
||||
|
||||
g.setColor(myColor);
|
||||
g.fillRect(x, y, myColorSize, myColorSize);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(x, y, myColorSize, myColorSize);
|
||||
}
|
||||
super.updateUI();
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.designer.propertyTable.renderers;
|
||||
|
||||
import com.intellij.designer.model.PropertiesContainer;
|
||||
import com.intellij.designer.model.PropertyContext;
|
||||
import com.intellij.designer.model.RadComponent;
|
||||
import com.intellij.designer.propertyTable.PropertyRenderer;
|
||||
import com.intellij.designer.propertyTable.PropertyTable;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public abstract class AbstractResourceRenderer implements PropertyRenderer {
|
||||
protected final ColorIcon myColorIcon = new ColorIcon(10, 9);
|
||||
protected final SimpleColoredComponent myColoredComponent = new SimpleColoredComponent();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getComponent(@Nullable PropertiesContainer container,
|
||||
PropertyContext context,
|
||||
@Nullable Object value,
|
||||
boolean selected,
|
||||
boolean hasFocus) {
|
||||
myColoredComponent.clear();
|
||||
PropertyTable.updateRenderer(myColoredComponent, selected);
|
||||
formatValue((RadComponent)container, (String)value);
|
||||
|
||||
return myColoredComponent;
|
||||
}
|
||||
|
||||
protected abstract void formatValue(RadComponent container, String value);
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
SwingUtilities.updateComponentTreeUI(myColoredComponent);
|
||||
}
|
||||
|
||||
protected final static class ColorIcon extends EmptyIcon {
|
||||
private final int myColorSize;
|
||||
private Color myColor;
|
||||
|
||||
private ColorIcon(int size, int colorSize) {
|
||||
super(size, size);
|
||||
myColorSize = colorSize;
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component component, Graphics g, final int left, final int top) {
|
||||
int iconWidth = getIconWidth();
|
||||
int iconHeight = getIconHeight();
|
||||
|
||||
SimpleColoredComponent coloredComponent = (SimpleColoredComponent)component;
|
||||
g.setColor(component.getBackground());
|
||||
g.fillRect(left - coloredComponent.getIpad().left, 0,
|
||||
iconWidth + coloredComponent.getIpad().left + coloredComponent.getIconTextGap(), component.getHeight());
|
||||
|
||||
int x = left + (iconWidth - myColorSize) / 2;
|
||||
int y = top + (iconHeight - myColorSize) / 2;
|
||||
|
||||
g.setColor(myColor);
|
||||
g.fillRect(x, y, myColorSize, myColorSize);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(x, y, myColorSize, myColorSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user