2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.internal.editors.layout.parts;
19 import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider;
20 import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiLayoutEditPart.HighlightInfo;
22 import org.eclipse.draw2d.ColorConstants;
23 import org.eclipse.draw2d.Figure;
24 import org.eclipse.draw2d.Graphics;
25 import org.eclipse.draw2d.geometry.Rectangle;
26 import org.eclipse.swt.SWT;
29 * The figure used to draw the feedback on a layout.
31 * By default the figure is transparent and empty.
32 * The base {@link ElementFigure} knows how to draw the selection border.
33 * This figure knows how to draw the drop feedback.
37 class LayoutFigure extends ElementFigure {
39 private HighlightInfo mHighlightInfo;
41 public LayoutFigure(IOutlineProvider provider) {
45 public void setHighlighInfo(HighlightInfo highlightInfo) {
46 mHighlightInfo = highlightInfo;
51 * Paints the "border" for this figure.
53 * The parent {@link Figure#paint(Graphics)} calls {@link #paintFigure(Graphics)} then
54 * {@link #paintClientArea(Graphics)} then {@link #paintBorder(Graphics)}. Here we thus
55 * draw the actual highlight border but also the highlight anchor lines and points so that
56 * we can make sure they are all drawn on top of the border.
58 * Note: This method doesn't really need to restore its graphic state. The parent
59 * Figure will do it for us.
62 * @param graphics The Graphics object used for painting
65 protected void paintBorder(Graphics graphics) {
66 super.paintBorder(graphics);
68 if (mHighlightInfo == null) {
72 // Draw the border. We want other highlighting to be drawn on top of the border.
73 if (mHighlightInfo.drawDropBorder) {
74 graphics.setLineWidth(3);
75 graphics.setLineStyle(SWT.LINE_SOLID);
76 graphics.setForegroundColor(ColorConstants.green);
77 graphics.drawRectangle(getInnerBounds().getCopy().shrink(1, 1));
80 Rectangle bounds = getBounds();
84 int h = bounds.height;
86 // Draw frames of target child parts, if any
87 if (mHighlightInfo.childParts != null) {
88 graphics.setLineWidth(2);
89 graphics.setLineStyle(SWT.LINE_DOT);
90 graphics.setForegroundColor(ColorConstants.lightBlue);
91 for (UiElementEditPart part : mHighlightInfo.childParts) {
93 graphics.drawRectangle(part.getBounds().getCopy().translate(bx, by));
98 // Draw the target line, if any
99 if (mHighlightInfo.linePoints != null) {
100 int x1 = mHighlightInfo.linePoints[0].x;
101 int y1 = mHighlightInfo.linePoints[0].y;
102 int x2 = mHighlightInfo.linePoints[1].x;
103 int y2 = mHighlightInfo.linePoints[1].y;
105 // if the line is right to the edge, draw it one pixel more inside so that the
106 // full 2-pixel width be visible.
112 if (x1 >= w - 1) x1--;
113 if (x2 >= w - 1) x2--;
114 if (y1 >= h - 1) y1--;
115 if (y2 >= h - 1) y2--;
122 graphics.setLineWidth(2);
123 graphics.setLineStyle(SWT.LINE_DASH);
124 graphics.setLineCap(SWT.CAP_ROUND);
125 graphics.setForegroundColor(ColorConstants.orange);
126 graphics.drawLine(x1, y1, x2, y2);
129 // Draw the anchor point, if any
130 if (mHighlightInfo.anchorPoint != null) {
131 int x = mHighlightInfo.anchorPoint.x;
132 int y = mHighlightInfo.anchorPoint.y;
134 // If the point is right on the edge, draw it one pixel inside so that it
135 // matches the highlight line. It makes it slightly more visible that way.
143 graphics.setLineWidth(2);
144 graphics.setLineStyle(SWT.LINE_SOLID);
145 graphics.setLineCap(SWT.CAP_ROUND);
146 graphics.setForegroundColor(ColorConstants.orange);
147 graphics.drawLine(x-5, y-5, x+5, y+5);
148 graphics.drawLine(x-5, y+5, x+5, y-5);
149 // 7 * cos(45) == 5 so we use 8 for the circle radius (it looks slightly better than 7)
150 graphics.setLineWidth(1);
151 graphics.drawOval(x-8, y-8, 16, 16);