From ee45ccb1c31967839c27b466447f072cce79daa3 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Mon, 6 May 2013 14:30:18 +0400 Subject: [PATCH] Make ui designer card and tool providers extendable [fix-34266] --- .../designSurface/DesignerEditorPanel.java | 324 ++++++++++-------- 1 file changed, 176 insertions(+), 148 deletions(-) diff --git a/plugins/ui-designer-core/src/com/intellij/designer/designSurface/DesignerEditorPanel.java b/plugins/ui-designer-core/src/com/intellij/designer/designSurface/DesignerEditorPanel.java index cc5fa084a550..96411c342b2d 100644 --- a/plugins/ui-designer-core/src/com/intellij/designer/designSurface/DesignerEditorPanel.java +++ b/plugins/ui-designer-core/src/com/intellij/designer/designSurface/DesignerEditorPanel.java @@ -155,163 +155,20 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider private void createDesignerCard() { myLayeredPane = new MyLayeredPane(); - mySurfaceArea = new ComponentEditableArea(myLayeredPane) { - @Override - protected void fireSelectionChanged() { - super.fireSelectionChanged(); - myLayeredPane.revalidate(); - myLayeredPane.repaint(); - } + mySurfaceArea = createEditableArea(); - @Override - public void scrollToSelection() { - List selection = getSelection(); - if (selection.size() == 1) { - Rectangle bounds = selection.get(0).getBounds(myLayeredPane); - if (bounds != null) { - myLayeredPane.scrollRectToVisible(bounds); - } - } - } - - @Override - public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) { - return DesignerEditorPanel.this.findTarget(x, y, filter); - } - - @Override - public InputTool findTargetTool(int x, int y) { - return myDecorationLayer.findTargetTool(x, y); - } - - @Override - public void showSelection(boolean value) { - myDecorationLayer.showSelection(value); - } - - @Override - public ComponentDecorator getRootSelectionDecorator() { - return DesignerEditorPanel.this.getRootSelectionDecorator(); - } - - @Nullable - public EditOperation processRootOperation(OperationContext context) { - return DesignerEditorPanel.this.processRootOperation(context); - } - - @Override - public FeedbackLayer getFeedbackLayer() { - return myFeedbackLayer; - } - - @Override - public RadComponent getRootComponent() { - return myRootComponent; - } - - @Override - public ActionGroup getPopupActions() { - return myActionPanel.getPopupActions(this); - } - - @Override - public String getPopupPlace() { - return ActionPlaces.GUI_DESIGNER_EDITOR_POPUP; - } - }; - - myToolProvider = new ToolProvider() { - @Override - public void loadDefaultTool() { - setActiveTool(createDefaultTool()); - } - - @Override - public void setActiveTool(InputTool tool) { - if (getActiveTool() instanceof CreationTool && !(tool instanceof CreationTool)) { - PaletteToolWindowManager.getInstance(getProject()).clearActiveItem(); - } - if (!(tool instanceof SelectionTool)) { - hideInspections(); - } - super.setActiveTool(tool); - } - - @Override - public boolean execute(final ThrowableRunnable operation, String command, final boolean updateProperties) { - final boolean[] is = {true}; - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - public void run() { - is[0] = DesignerEditorPanel.this.execute(operation, updateProperties); - } - }, command, null); - return is[0]; - } - - @Override - public void executeWithReparse(final ThrowableRunnable operation, String command) { - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - public void run() { - DesignerEditorPanel.this.executeWithReparse(operation); - } - }, command, null); - } - - @Override - public void execute(final List operations, String command) { - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - public void run() { - DesignerEditorPanel.this.execute(operations); - } - }, command, null); - } - - @Override - public void startInplaceEditing(@Nullable InplaceContext inplaceContext) { - myInplaceEditingLayer.startEditing(inplaceContext); - } - - @Override - public void hideInspections() { - myQuickFixManager.hideHint(); - } - - @Override - public void showError(@NonNls String message, Throwable e) { - DesignerEditorPanel.this.showError(message, e); - } - - @Override - public boolean isZoomSupported() { - return DesignerEditorPanel.this.isZoomSupported(); - } - - @Override - public void zoom(@NotNull ZoomType type) { - DesignerEditorPanel.this.zoom(type); - } - - @Override - public void setZoom(double zoom) { - DesignerEditorPanel.this.setZoom(zoom); - } - - @Override - public double getZoom() { - return DesignerEditorPanel.this.getZoom(); - } - }; + myToolProvider = createToolProvider(); myGlassLayer = new GlassLayer(myToolProvider, mySurfaceArea); myLayeredPane.add(myGlassLayer, LAYER_GLASS); - myDecorationLayer = new DecorationLayer(this, mySurfaceArea); + myDecorationLayer = createDecorationLayer(); myLayeredPane.add(myDecorationLayer, LAYER_DECORATION); - myFeedbackLayer = new FeedbackLayer(); + myFeedbackLayer = createFeedbackLayer(); myLayeredPane.add(myFeedbackLayer, LAYER_FEEDBACK); - myInplaceEditingLayer = new InplaceEditingLayer(this); + myInplaceEditingLayer = createInplaceEditingLayer(); myLayeredPane.add(myInplaceEditingLayer, LAYER_INPLACE_EDITING); JPanel content = new JPanel(new GridBagLayout()); @@ -363,6 +220,26 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider }); } + protected EditableArea createEditableArea() { + return new DesignerEditableArea(); + } + + protected ToolProvider createToolProvider() { + return new DesignerToolProvider(); + } + + protected DecorationLayer createDecorationLayer() { + return new DecorationLayer(this, mySurfaceArea); + } + + protected FeedbackLayer createFeedbackLayer() { + return new FeedbackLayer(); + } + + protected InplaceEditingLayer createInplaceEditingLayer() { + return new InplaceEditingLayer(this); + } + protected CaptionPanel createCaptionPanel(boolean horizontal) { return new CaptionPanel(this, horizontal, true); } @@ -988,6 +865,157 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider return new Dimension(width, height); } + protected class DesignerEditableArea extends ComponentEditableArea { + public DesignerEditableArea() { + super(myLayeredPane); + } + + @Override + protected void fireSelectionChanged() { + super.fireSelectionChanged(); + myLayeredPane.revalidate(); + myLayeredPane.repaint(); + } + + @Override + public void scrollToSelection() { + List selection = getSelection(); + if (selection.size() == 1) { + Rectangle bounds = selection.get(0).getBounds(myLayeredPane); + if (bounds != null) { + myLayeredPane.scrollRectToVisible(bounds); + } + } + } + + @Override + public RadComponent findTarget(int x, int y, @Nullable ComponentTargetFilter filter) { + return DesignerEditorPanel.this.findTarget(x, y, filter); + } + + @Override + public InputTool findTargetTool(int x, int y) { + return myDecorationLayer.findTargetTool(x, y); + } + + @Override + public void showSelection(boolean value) { + myDecorationLayer.showSelection(value); + } + + @Override + public ComponentDecorator getRootSelectionDecorator() { + return DesignerEditorPanel.this.getRootSelectionDecorator(); + } + + @Nullable + public EditOperation processRootOperation(OperationContext context) { + return DesignerEditorPanel.this.processRootOperation(context); + } + + @Override + public FeedbackLayer getFeedbackLayer() { + return myFeedbackLayer; + } + + @Override + public RadComponent getRootComponent() { + return myRootComponent; + } + + @Override + public ActionGroup getPopupActions() { + return myActionPanel.getPopupActions(this); + } + + @Override + public String getPopupPlace() { + return ActionPlaces.GUI_DESIGNER_EDITOR_POPUP; + } + } + + protected class DesignerToolProvider extends ToolProvider { + @Override + public void loadDefaultTool() { + setActiveTool(createDefaultTool()); + } + + @Override + public void setActiveTool(InputTool tool) { + if (getActiveTool() instanceof CreationTool && !(tool instanceof CreationTool)) { + PaletteToolWindowManager.getInstance(getProject()).clearActiveItem(); + } + if (!(tool instanceof SelectionTool)) { + hideInspections(); + } + super.setActiveTool(tool); + } + + @Override + public boolean execute(final ThrowableRunnable operation, String command, final boolean updateProperties) { + final boolean[] is = {true}; + CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + public void run() { + is[0] = DesignerEditorPanel.this.execute(operation, updateProperties); + } + }, command, null); + return is[0]; + } + + @Override + public void executeWithReparse(final ThrowableRunnable operation, String command) { + CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + public void run() { + DesignerEditorPanel.this.executeWithReparse(operation); + } + }, command, null); + } + + @Override + public void execute(final List operations, String command) { + CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + public void run() { + DesignerEditorPanel.this.execute(operations); + } + }, command, null); + } + + @Override + public void startInplaceEditing(@Nullable InplaceContext inplaceContext) { + myInplaceEditingLayer.startEditing(inplaceContext); + } + + @Override + public void hideInspections() { + myQuickFixManager.hideHint(); + } + + @Override + public void showError(@NonNls String message, Throwable e) { + DesignerEditorPanel.this.showError(message, e); + } + + @Override + public boolean isZoomSupported() { + return DesignerEditorPanel.this.isZoomSupported(); + } + + @Override + public void zoom(@NotNull ZoomType type) { + DesignerEditorPanel.this.zoom(type); + } + + @Override + public void setZoom(double zoom) { + DesignerEditorPanel.this.setZoom(zoom); + } + + @Override + public double getZoom() { + return DesignerEditorPanel.this.getZoom(); + } + } + private final class MyLayeredPane extends JBLayeredPane implements Scrollable { public void doLayout() { for (int i = getComponentCount() - 1; i >= 0; i--) {