1 11 package org.eclipse.ui.internal.dnd; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.Color; 15 import org.eclipse.swt.graphics.RGB; 16 import org.eclipse.swt.graphics.Rectangle; 17 import org.eclipse.swt.widgets.Canvas; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.ui.themes.ColorUtil; 20 21 27 public class InsertCaret { 28 private static final int width = 6; private static final int pctInset = 10; 32 private Canvas caretControl; 34 private Canvas end1; 35 private Canvas end2; 36 37 private Color baseColor; 39 private Color hilightColor; 40 private boolean isHighlight; 41 42 51 public InsertCaret(Composite parent, Rectangle trimRect, int swtSide, int threshold) { 52 baseColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION); 55 RGB background = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB(); 56 RGB blended = ColorUtil.blend(baseColor.getRGB(), background); 57 hilightColor = new Color(parent.getDisplay(), blended); 58 59 createControl(parent, trimRect, swtSide, threshold); 61 } 62 63 72 private void createControl(Composite parent, Rectangle trimRect, int swtSide, int threshold) { 73 int hDelta = trimRect.width/pctInset; 74 int vDelta = trimRect.height/pctInset; 75 caretControl = new Canvas (parent.getShell(), SWT.BORDER); 76 77 end1 = new Canvas (parent.getShell(), SWT.BORDER); 78 end1.setSize(width, width); 79 end2 = new Canvas (parent.getShell(), SWT.BORDER); 80 end2.setSize(width, width); 81 82 Rectangle bb; 83 switch (swtSide) { 84 case SWT.TOP: 85 caretControl.setSize(trimRect.width-(2*hDelta), width); 86 caretControl.setLocation(trimRect.x + hDelta, trimRect.y + trimRect.height + threshold); 87 bb = caretControl.getBounds(); 88 end1.setLocation(bb.x, bb.y-width); 89 end2.setLocation((bb.x+bb.width)-width, bb.y-width); 90 break; 91 case SWT.BOTTOM: 92 caretControl.setSize(trimRect.width-(2*hDelta), width); 93 caretControl.setLocation(trimRect.x + hDelta, trimRect.y - threshold); 94 bb = caretControl.getBounds(); 95 end1.setLocation(bb.x, bb.y+width); 96 end2.setLocation((bb.x+bb.width)-width, bb.y+width); 97 break; 98 case SWT.LEFT: 99 caretControl.setSize(width, trimRect.height -(2*vDelta)); 100 caretControl.setLocation(trimRect.x + trimRect.width + threshold, 101 trimRect.y + vDelta); 102 bb = caretControl.getBounds(); 103 end1.setLocation(bb.x-bb.width, bb.y); 104 end2.setLocation(bb.x-bb.width, (bb.y+bb.height)-width); 105 break; 106 case SWT.RIGHT: 107 caretControl.setSize(width, trimRect.height -(2*vDelta)); 108 caretControl.setLocation(trimRect.x - threshold, 109 trimRect.y + vDelta); 110 bb = caretControl.getBounds(); 111 end1.setLocation(bb.x+bb.width, bb.y); 112 end2.setLocation(bb.x+bb.width, (bb.y+bb.height)-width); 113 break; 114 } 115 116 setHighlight(false); 118 caretControl.moveAbove(null); 119 end1.moveAbove(null); 120 end2.moveAbove(null); 121 } 122 123 127 public void setHighlight(boolean highlight) { 128 isHighlight = highlight; 129 130 if (isHighlight) { 133 caretControl.setBackground(hilightColor); 134 end1.setBackground(hilightColor); 135 end2.setBackground(hilightColor); 136 } 137 else { 138 caretControl.setBackground(baseColor); 139 end1.setBackground(baseColor); 140 end2.setBackground(baseColor); 141 } 142 } 143 144 public void dispose() { 145 hilightColor.dispose(); 148 149 caretControl.dispose(); 150 end1.dispose(); 151 end2.dispose(); 152 } 153 } 154 | Popular Tags |