1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 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 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 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. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.editors.layout.parts; 18 19 import com.android.ide.eclipse.adt.internal.editors.layout.parts.UiElementsEditPartFactory.IOutlineProvider; 20 21 import org.eclipse.draw2d.ColorConstants; 22 import org.eclipse.draw2d.Figure; 23 import org.eclipse.draw2d.Graphics; 24 import org.eclipse.draw2d.geometry.Rectangle; 25 import org.eclipse.swt.SWT; 26 27 28 /** 29 * The figure used to draw basic elements. 30 * <p/> 31 * The figure is totally empty and transparent except for the selection border. 32 * 33 * @since GLE1 34 */ 35 class ElementFigure extends Figure { 36 37 private boolean mIsSelected; 38 private Rectangle mInnerBounds; 39 private final IOutlineProvider mProvider; 40 41 public ElementFigure(IOutlineProvider provider) { 42 mProvider = provider; 43 setOpaque(false); 44 } 45 46 public void setSelected(boolean isSelected) { 47 if (isSelected != mIsSelected) { 48 mIsSelected = isSelected; 49 repaint(); 50 } 51 } 52 53 @Override 54 public void setBounds(Rectangle rect) { 55 super.setBounds(rect); 56 57 mInnerBounds = getBounds().getCopy(); 58 if (mInnerBounds.width > 0) { 59 mInnerBounds.width--; 60 } 61 if (mInnerBounds.height > 0) { 62 mInnerBounds.height--; 63 } 64 } 65 66 public Rectangle getInnerBounds() { 67 return mInnerBounds; 68 } 69 70 @Override 71 protected void paintBorder(Graphics graphics) { 72 super.paintBorder(graphics); 73 74 if (mIsSelected || (mProvider != null && mProvider.hasOutline())) { 75 graphics.setLineWidth(1); 76 graphics.setLineStyle(SWT.LINE_SOLID); 77 graphics.setForegroundColor(mIsSelected ? ColorConstants.red : ColorConstants.white); 78 graphics.drawRectangle(getInnerBounds()); 79 } 80 } 81 } 82