1 11 package org.eclipse.ui.internal.dnd; 12 13 import org.eclipse.jface.util.Geometry; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.PaintEvent; 16 import org.eclipse.swt.events.PaintListener; 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.Point; 19 import org.eclipse.swt.graphics.RGB; 20 import org.eclipse.swt.graphics.Rectangle; 21 import org.eclipse.swt.widgets.Canvas; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.ui.themes.ColorUtil; 25 26 33 public class DragBorder { 34 private Composite clientControl = null; 36 private Control dragControl = null; 37 private Canvas border = null; 38 39 private Color baseColor; 41 private Color hilightColor; 42 private boolean isHighlight; 43 44 50 public DragBorder(Composite client, Control toDrag, boolean provideFrame) { 51 clientControl = client; 52 dragControl = toDrag; 53 Point dragSize = toDrag.getSize(); 54 55 border = new Canvas(dragControl.getParent(), SWT.NONE); 57 border.setSize(dragSize.x+2, dragSize.y+2); 58 59 baseColor = border.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); 62 RGB background = border.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(); 63 RGB blended = ColorUtil.blend(baseColor.getRGB(), background); 64 hilightColor = new Color(border.getDisplay(), blended); 65 66 border.moveAbove(null); 68 dragControl.moveAbove(null); 69 70 if (provideFrame) { 71 border.addPaintListener(new PaintListener() { 72 public void paintControl(PaintEvent e) { 73 if (isHighlight) { 74 e.gc.setForeground(hilightColor); 75 } 76 else { 77 e.gc.setForeground(baseColor); 78 } 79 80 Rectangle bb = border.getBounds(); 82 e.gc.drawRectangle(0,0,bb.width-1, bb.height-1); 83 } 84 }); 85 } 86 } 87 88 89 99 public void setLocation(Point newPos, int alignment) { 100 if (alignment == SWT.CENTER) { 102 Point size = border.getSize(); 103 border.setLocation(newPos.x - (size.x/2), newPos.y - (size.y/2)); 104 } 105 else if (alignment == SWT.TOP) { 106 border.setLocation(newPos.x, newPos.y); 107 } else { 108 border.setLocation(newPos.x, newPos.y - border.getSize().y); 109 } 110 111 Rectangle bb = border.getBounds(); 113 Rectangle cr = clientControl.getClientArea(); 114 Geometry.moveInside(bb,cr); 115 116 border.moveAbove(null); 118 dragControl.moveAbove(null); 119 120 dragControl.setLocation(bb.x+1, bb.y+1); 122 border.setBounds(bb); 123 } 124 125 129 public void setHighlight(boolean highlight) { 130 isHighlight = highlight; 131 border.redraw(); 132 } 133 134 137 public void dispose() { 138 hilightColor.dispose(); 139 border.dispose(); 140 } 141 142 143 146 public Rectangle getBounds() { 147 return border.getBounds(); 148 } 149 } 150 | Popular Tags |