diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index b99b0b9d602d..bf59f5284a10 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -209,6 +209,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { myLayeredPane.add(rootPanel, LAYER_COMPONENT); myParseTime = false; + doPaint = true; runnable.run(); } @@ -595,6 +596,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { return false; } finally { + doPaint = true; myPSIChangeListener.start(); } } @@ -615,6 +617,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { showError("Execute command", e); } finally { + doPaint = true; myPSIChangeListener.start(); } } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java index b8b0458c1f23..04d052051e2a 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/componentTree/ComponentTree.java @@ -1,285 +1,285 @@ -/* - * 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.componentTree; - -import com.intellij.codeHighlighting.HighlightDisplayLevel; -import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; -import com.intellij.designer.actions.DesignerActionPanel; -import com.intellij.designer.actions.StartInplaceEditing; -import com.intellij.designer.designSurface.DesignerEditorPanel; -import com.intellij.designer.designSurface.EditableArea; -import com.intellij.designer.designSurface.FeedbackTreeLayer; -import com.intellij.designer.inspection.ErrorInfo; -import com.intellij.designer.model.RadComponent; -import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -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.project.Project; -import com.intellij.ui.ColoredTreeCellRenderer; -import com.intellij.ui.SimpleTextAttributes; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.ui.tree.TreeUtil; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.LineBorder; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.event.MouseEvent; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Alexander Lobas - */ -public final class ComponentTree extends Tree implements DataProvider { - private final Map> myAttributes = - new HashMap>(); - private final StartInplaceEditing myInplaceEditingAction; - private QuickFixManager myQuickFixManager; - private DesignerEditorPanel myDesigner; - private EditableArea myArea; - private RadComponent myMarkComponent; - private int myMarkFeedback; - - public ComponentTree() { - newModel(); - - setScrollsOnExpand(true); - installCellRenderer(); - - setRootVisible(false); - setShowsRootHandles(true); - - // Enable tooltips - ToolTipManager.sharedInstance().registerComponent(this); - - // Install convenient keyboard navigation - TreeUtil.installActions(this); - - myInplaceEditingAction = DesignerActionPanel.createInplaceEditingAction(this); - } - - public void newModel() { - setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); - } - - public void initQuickFixManager(JViewport viewPort) { - myQuickFixManager = new QuickFixManager(this, viewPort); - } - - public void updateInspections() { - myQuickFixManager.update(); - } - - public void setDesignerPanel(@Nullable DesignerEditorPanel designer) { - myDesigner = designer; - myMarkComponent = null; - myArea = null; - myInplaceEditingAction.setDesignerPanel(designer); - myQuickFixManager.setDesigner(designer); - } - - public void setArea(@Nullable EditableArea area) { - myArea = area; - myQuickFixManager.setEditableArea(area); - } - - public void mark(RadComponent component, int feedback) { - myMarkComponent = component; - myMarkFeedback = feedback; - repaint(); - } - - @Override - public Object getData(@NonNls String dataId) { - if (EditableArea.DATA_KEY.is(dataId)) { - return myArea; - } - if (myDesigner != null) { - if (PlatformDataKeys.FILE_EDITOR.is(dataId)) { - return myDesigner.getEditor(); - } - return myDesigner.getActionPanel().getData(dataId); - } - return null; - } - - @Nullable - public RadComponent extractComponent(Object value) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; - Object userObject = node.getUserObject(); - - if (myDesigner != null && userObject instanceof TreeNodeDescriptor) { - TreeNodeDescriptor descriptor = (TreeNodeDescriptor)userObject; - Object element = descriptor.getElement(); - - if (element instanceof RadComponent) { - return (RadComponent)element; - } - } - return null; - } - - public int getEdgeSize() { - return Math.max(5, ((JComponent)getCellRenderer()).getPreferredSize().height / 2 - 3); - } - - @Override - public String getToolTipText(MouseEvent event) { - TreePath path = getPathForLocation(event.getX(), event.getY()); - if (path != null) { - RadComponent component = extractComponent(path.getLastPathComponent()); - if (component != null) { - List errorInfos = ErrorInfo.get(component); - if (!errorInfos.isEmpty()) { - return errorInfos.get(0).getName(); - } - } - } - return super.getToolTipText(event); - } - - @Nullable - private static HighlightDisplayLevel getHighlightDisplayLevel(Project project, RadComponent component) { - HighlightDisplayLevel displayLevel = null; - SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(project); - for (ErrorInfo errorInfo : ErrorInfo.get(component)) { - if (displayLevel == null || severityRegistrar.compare(errorInfo.getLevel().getSeverity(), displayLevel.getSeverity()) > 0) { - displayLevel = errorInfo.getLevel(); - } - } - return displayLevel; - } - - private AttributeWrapper getAttributeWrapper(RadComponent component) { - AttributeWrapper wrapper = AttributeWrapper.DEFAULT; - final HighlightDisplayLevel level = getHighlightDisplayLevel(myDesigner.getProject(), component); - - if (level != null) { - TextAttributesKey attributesKey = - SeverityRegistrar.getInstance(myDesigner.getProject()).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey(); - final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey); - - wrapper = new AttributeWrapper() { - @Override - public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) { - Map attributesMap = myAttributes.get(level.getSeverity()); - if (attributesMap == null) { - attributesMap = new HashMap(); - myAttributes.put(level.getSeverity(), attributesMap); - } - - SimpleTextAttributes result = attributesMap.get(attributes); - if (result == null) { - result = SimpleTextAttributes.fromTextAttributes(TextAttributes.merge(attributes.toTextAttributes(), textAttributes)); - attributesMap.put(attributes, result); - } - - return result; - } - }; - } - - return wrapper; - } - - private void installCellRenderer() { - setCellRenderer(new ColoredTreeCellRenderer() { - @Override - public void customizeCellRenderer(JTree tree, - Object value, - boolean selected, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - try { - RadComponent component = extractComponent(value); - - if (component != null) { - myDesigner.getTreeDecorator().decorate(component, this, getAttributeWrapper(component), true); - - if (myMarkComponent == component) { - if (myMarkFeedback == FeedbackTreeLayer.INSERT_SELECTION) { - setBorder(BorderFactory.createLineBorder(Color.RED, 1)); - } - else { - setBorder(new InsertBorder(myMarkFeedback)); - } - } - else { - setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); - } - } - } - catch (RuntimeException e) { - if (myDesigner == null) { - throw e; - } - myDesigner.showError("Tree paint operation", e); - } - } - }); - } - - private static class InsertBorder extends LineBorder { - private final int myMode; - - public InsertBorder(int mode) { - super(Color.BLACK, 2); - myMode = mode; - } - - @Override - public Insets getBorderInsets(Component component) { - return getBorderInsets(component, new Insets(0, 0, 0, 0)); - } - - @Override - public Insets getBorderInsets(Component component, Insets insets) { - insets.top = myMode == FeedbackTreeLayer.INSERT_BEFORE ? thickness : 0; - insets.left = insets.right = thickness; - insets.bottom = myMode == FeedbackTreeLayer.INSERT_AFTER ? thickness : 0; - return insets; - } - - @Override - public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { - Color oldColor = g.getColor(); - - g.setColor(getLineColor()); - if (myMode == FeedbackTreeLayer.INSERT_BEFORE) { - g.fillRect(x, y, width, thickness); - g.fillRect(x, y, thickness, 2 * thickness); - g.fillRect(x + width - thickness, y, thickness, 2 * thickness); - } - else { - g.fillRect(x, y + height - thickness, width, thickness); - g.fillRect(x, y + height - 2 * thickness, thickness, 2 * thickness); - g.fillRect(x + width - thickness, y + height - 2 * thickness, thickness, 2 * thickness); - } - g.setColor(oldColor); - } - } +/* + * 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.componentTree; + +import com.intellij.codeHighlighting.HighlightDisplayLevel; +import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; +import com.intellij.designer.actions.DesignerActionPanel; +import com.intellij.designer.actions.StartInplaceEditing; +import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.EditableArea; +import com.intellij.designer.designSurface.FeedbackTreeLayer; +import com.intellij.designer.inspection.ErrorInfo; +import com.intellij.designer.model.RadComponent; +import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.PlatformDataKeys; +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.project.Project; +import com.intellij.ui.ColoredTreeCellRenderer; +import com.intellij.ui.SimpleTextAttributes; +import com.intellij.ui.treeStructure.Tree; +import com.intellij.util.ui.tree.TreeUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import javax.swing.border.LineBorder; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Alexander Lobas + */ +public final class ComponentTree extends Tree implements DataProvider { + private final Map> myAttributes = + new HashMap>(); + private final StartInplaceEditing myInplaceEditingAction; + private QuickFixManager myQuickFixManager; + private DesignerEditorPanel myDesigner; + private EditableArea myArea; + private RadComponent myMarkComponent; + private int myMarkFeedback; + + public ComponentTree() { + newModel(); + + setScrollsOnExpand(true); + installCellRenderer(); + + setRootVisible(false); + setShowsRootHandles(true); + + // Enable tooltips + ToolTipManager.sharedInstance().registerComponent(this); + + // Install convenient keyboard navigation + TreeUtil.installActions(this); + + myInplaceEditingAction = DesignerActionPanel.createInplaceEditingAction(this); + } + + public void newModel() { + setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); + } + + public void initQuickFixManager(JViewport viewPort) { + myQuickFixManager = new QuickFixManager(this, viewPort); + } + + public void updateInspections() { + myQuickFixManager.update(); + } + + public void setDesignerPanel(@Nullable DesignerEditorPanel designer) { + myDesigner = designer; + myMarkComponent = null; + myArea = null; + myInplaceEditingAction.setDesignerPanel(designer); + myQuickFixManager.setDesigner(designer); + } + + public void setArea(@Nullable EditableArea area) { + myArea = area; + myQuickFixManager.setEditableArea(area); + } + + public void mark(RadComponent component, int feedback) { + myMarkComponent = component; + myMarkFeedback = feedback; + repaint(); + } + + @Override + public Object getData(@NonNls String dataId) { + if (EditableArea.DATA_KEY.is(dataId)) { + return myArea; + } + if (myDesigner != null) { + if (PlatformDataKeys.FILE_EDITOR.is(dataId)) { + return myDesigner.getEditor(); + } + return myDesigner.getActionPanel().getData(dataId); + } + return null; + } + + @Nullable + public RadComponent extractComponent(Object value) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; + Object userObject = node.getUserObject(); + + if (myDesigner != null && userObject instanceof TreeNodeDescriptor) { + TreeNodeDescriptor descriptor = (TreeNodeDescriptor)userObject; + Object element = descriptor.getElement(); + + if (element instanceof RadComponent) { + return (RadComponent)element; + } + } + return null; + } + + public int getEdgeSize() { + return Math.max(5, ((JComponent)getCellRenderer()).getPreferredSize().height / 2 - 3); + } + + @Override + public String getToolTipText(MouseEvent event) { + TreePath path = getPathForLocation(event.getX(), event.getY()); + if (path != null) { + RadComponent component = extractComponent(path.getLastPathComponent()); + if (component != null) { + List errorInfos = ErrorInfo.get(component); + if (!errorInfos.isEmpty()) { + return errorInfos.get(0).getName(); + } + } + } + return super.getToolTipText(event); + } + + @Nullable + private static HighlightDisplayLevel getHighlightDisplayLevel(Project project, RadComponent component) { + HighlightDisplayLevel displayLevel = null; + SeverityRegistrar severityRegistrar = SeverityRegistrar.getInstance(project); + for (ErrorInfo errorInfo : ErrorInfo.get(component)) { + if (displayLevel == null || severityRegistrar.compare(errorInfo.getLevel().getSeverity(), displayLevel.getSeverity()) > 0) { + displayLevel = errorInfo.getLevel(); + } + } + return displayLevel; + } + + private AttributeWrapper getAttributeWrapper(RadComponent component) { + AttributeWrapper wrapper = AttributeWrapper.DEFAULT; + final HighlightDisplayLevel level = getHighlightDisplayLevel(myDesigner.getProject(), component); + + if (level != null) { + TextAttributesKey attributesKey = + SeverityRegistrar.getInstance(myDesigner.getProject()).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey(); + final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey); + + wrapper = new AttributeWrapper() { + @Override + public SimpleTextAttributes getAttribute(SimpleTextAttributes attributes) { + Map attributesMap = myAttributes.get(level.getSeverity()); + if (attributesMap == null) { + attributesMap = new HashMap(); + myAttributes.put(level.getSeverity(), attributesMap); + } + + SimpleTextAttributes result = attributesMap.get(attributes); + if (result == null) { + result = SimpleTextAttributes.fromTextAttributes(TextAttributes.merge(attributes.toTextAttributes(), textAttributes)); + attributesMap.put(attributes, result); + } + + return result; + } + }; + } + + return wrapper; + } + + private void installCellRenderer() { + setCellRenderer(new ColoredTreeCellRenderer() { + @Override + public void customizeCellRenderer(JTree tree, + Object value, + boolean selected, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + try { + RadComponent component = extractComponent(value); + + if (component != null && myDesigner.doPaint) { + myDesigner.getTreeDecorator().decorate(component, this, getAttributeWrapper(component), true); + + if (myMarkComponent == component) { + if (myMarkFeedback == FeedbackTreeLayer.INSERT_SELECTION) { + setBorder(BorderFactory.createLineBorder(Color.RED, 1)); + } + else { + setBorder(new InsertBorder(myMarkFeedback)); + } + } + else { + setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); + } + } + } + catch (RuntimeException e) { + if (myDesigner == null) { + throw e; + } + myDesigner.showError("Tree paint operation", e); + } + } + }); + } + + private static class InsertBorder extends LineBorder { + private final int myMode; + + public InsertBorder(int mode) { + super(Color.BLACK, 2); + myMode = mode; + } + + @Override + public Insets getBorderInsets(Component component) { + return getBorderInsets(component, new Insets(0, 0, 0, 0)); + } + + @Override + public Insets getBorderInsets(Component component, Insets insets) { + insets.top = myMode == FeedbackTreeLayer.INSERT_BEFORE ? thickness : 0; + insets.left = insets.right = thickness; + insets.bottom = myMode == FeedbackTreeLayer.INSERT_AFTER ? thickness : 0; + return insets; + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + Color oldColor = g.getColor(); + + g.setColor(getLineColor()); + if (myMode == FeedbackTreeLayer.INSERT_BEFORE) { + g.fillRect(x, y, width, thickness); + g.fillRect(x, y, thickness, 2 * thickness); + g.fillRect(x + width - thickness, y, thickness, 2 * thickness); + } + else { + g.fillRect(x, y + height - thickness, width, thickness); + g.fillRect(x, y + height - 2 * thickness, thickness, 2 * thickness); + g.fillRect(x + width - thickness, y + height - 2 * thickness, thickness, 2 * thickness); + } + g.setColor(oldColor); + } + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java index 581dd637329a..9fbaa43b4086 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java @@ -1,116 +1,116 @@ -/* - * 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.designSurface; - -import com.intellij.designer.designSurface.tools.InputTool; -import com.intellij.designer.model.RadComponent; -import com.intellij.designer.model.RadComponentVisitor; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class DecorationLayer extends JComponent { - private final DesignerEditorPanel myDesigner; - private final EditableArea myArea; - private boolean myShowSelection = true; - - public DecorationLayer(DesignerEditorPanel designer, EditableArea area) { - myDesigner = designer; - myArea = area; - } - - public EditableArea getArea() { - return myArea; - } - - public boolean showSelection() { - return myShowSelection; - } - - public void showSelection(boolean value) { - if (myShowSelection != value) { - myShowSelection = value; - repaint(); - } - } - - @Nullable - public InputTool findTargetTool(int x, int y) { - List selection = myArea.getSelection(); - for (RadComponent component : selection) { - ComponentDecorator decorator = getDecorator(component, selection); - InputTool tracker = decorator.findTargetTool(this, component, x, y); - if (tracker != null) { - return tracker; - } - } - return null; - } - - @Override - public void paint(Graphics g) { - try { - if (myArea.getRootComponent() != null) { - Graphics2D g2d = (Graphics2D)g; - paintStaticDecorators(g2d); - if (myShowSelection) { - paintSelection(g2d); - } - } - } - catch (Throwable e) { - myDesigner.showError("Paint operation", e); - } - } - - private void paintStaticDecorators(Graphics2D g) { - final List decorators = new ArrayList(); - final List selection = myArea.getSelection(); - - myArea.getRootComponent().accept(new RadComponentVisitor() { - @Override - public void endVisit(RadComponent component) { - component.addStaticDecorators(decorators, selection); - } - }, true); - - for (StaticDecorator decorator : decorators) { - decorator.decorate(this, g); - } - } - - private void paintSelection(Graphics2D g) { - List selection = myArea.getSelection(); - for (RadComponent component : selection) { - ComponentDecorator decorator = getDecorator(component, selection); - decorator.decorate(this, g, component); - } - } - - private ComponentDecorator getDecorator(RadComponent component, List selection) { - RadComponent parent = component.getParent(); - if (parent == null) { - return myArea.getRootSelectionDecorator(); - } - return parent.getLayout().getChildSelectionDecorator(component, selection); - } +/* + * 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.designSurface; + +import com.intellij.designer.designSurface.tools.InputTool; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.model.RadComponentVisitor; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class DecorationLayer extends JComponent { + private final DesignerEditorPanel myDesigner; + private final EditableArea myArea; + private boolean myShowSelection = true; + + public DecorationLayer(DesignerEditorPanel designer, EditableArea area) { + myDesigner = designer; + myArea = area; + } + + public EditableArea getArea() { + return myArea; + } + + public boolean showSelection() { + return myShowSelection; + } + + public void showSelection(boolean value) { + if (myShowSelection != value) { + myShowSelection = value; + repaint(); + } + } + + @Nullable + public InputTool findTargetTool(int x, int y) { + List selection = myArea.getSelection(); + for (RadComponent component : selection) { + ComponentDecorator decorator = getDecorator(component, selection); + InputTool tracker = decorator.findTargetTool(this, component, x, y); + if (tracker != null) { + return tracker; + } + } + return null; + } + + @Override + public void paint(Graphics g) { + try { + if (myArea.getRootComponent() != null && myDesigner.doPaint) { + Graphics2D g2d = (Graphics2D)g; + paintStaticDecorators(g2d); + if (myShowSelection) { + paintSelection(g2d); + } + } + } + catch (Throwable e) { + myDesigner.showError("Paint operation", e); + } + } + + private void paintStaticDecorators(Graphics2D g) { + final List decorators = new ArrayList(); + final List selection = myArea.getSelection(); + + myArea.getRootComponent().accept(new RadComponentVisitor() { + @Override + public void endVisit(RadComponent component) { + component.addStaticDecorators(decorators, selection); + } + }, true); + + for (StaticDecorator decorator : decorators) { + decorator.decorate(this, g); + } + } + + private void paintSelection(Graphics2D g) { + List selection = myArea.getSelection(); + for (RadComponent component : selection) { + ComponentDecorator decorator = getDecorator(component, selection); + decorator.decorate(this, g, component); + } + } + + private ComponentDecorator getDecorator(RadComponent component, List selection) { + RadComponent parent = component.getParent(); + if (parent == null) { + return myArea.getRootSelectionDecorator(); + } + return parent.getLayout().getChildSelectionDecorator(component, selection); + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java index 2ad949679875..1c1c2ba4f4e7 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DesignerEditorPanel.java @@ -131,6 +131,8 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider private AsyncProcessIcon myProgressIcon; private JLabel myProgressMessage; + public volatile boolean doPaint = true; + public DesignerEditorPanel(@NotNull DesignerEditor editor, @NotNull Project project, @NotNull Module module, @NotNull VirtualFile file) { myEditor = editor; myProject = project; diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ExternalPSIChangeListener.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ExternalPSIChangeListener.java index ff4e54741edd..e7026cce9f8c 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ExternalPSIChangeListener.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/ExternalPSIChangeListener.java @@ -114,8 +114,9 @@ public class ExternalPSIChangeListener extends PsiTreeChangeAdapter { } protected void updatePsi(PsiTreeChangeEvent event) { - if (myRunState) { - if (myFile == event.getFile()) { + if (myFile == event.getFile()) { + myDesigner.doPaint = false; + if (myRunState) { addRequest(); } } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java index d28d3d62c463..f6e6fc5ca22c 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java @@ -1023,6 +1023,7 @@ public final class PropertyTable extends JBTable implements DataProvider, Compon private final Map myItalicAttributes = new HashMap(); private final ColoredTableCellRenderer myPropertyNameRenderer; private final ColoredTableCellRenderer myErrorRenderer; + private final JLabel myNoRenderer = new JLabel(); private final Icon myExpandIcon; private final Icon myCollapseIcon; private final Icon myIndentedExpandIcon; @@ -1061,8 +1062,6 @@ public final class PropertyTable extends JBTable implements DataProvider, Compon @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { - myPropertyNameRenderer.getTableCellRendererComponent(table, value, selected, hasFocus, row, column); - column = table.convertColumnIndexToModel(column); Property property = (Property)value; Color background = table.getBackground(); @@ -1079,11 +1078,13 @@ public final class PropertyTable extends JBTable implements DataProvider, Compon background = Gray._240; } - if (!selected) { - myPropertyNameRenderer.setBackground(background); - } - if (column == 0) { + myPropertyNameRenderer.getTableCellRendererComponent(table, value, selected, hasFocus, row, column); + + if (!selected) { + myPropertyNameRenderer.setBackground(background); + } + SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES; if (property.isImportant()) { attributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES; @@ -1163,8 +1164,13 @@ public final class PropertyTable extends JBTable implements DataProvider, Compon myPropertyNameRenderer.setForeground(FileStatus.MODIFIED.getColor()); } } + return myPropertyNameRenderer; } else { + if (!myDesigner.doPaint) { + return myNoRenderer; + } + try { PropertyRenderer renderer = property.getRenderer(); JComponent component = renderer.getComponent(getCurrentComponent(), getValue(property), selected, hasFocus); @@ -1189,8 +1195,6 @@ public final class PropertyTable extends JBTable implements DataProvider, Compon return myErrorRenderer; } } - - return myPropertyNameRenderer; } } } \ No newline at end of file