1 11 package org.eclipse.ui.forms.widgets; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.graphics.Color; 15 import org.eclipse.swt.graphics.GC; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.widgets.Composite; 18 19 31 public class Twistie extends ToggleHyperlink { 32 private static final int[] onPoints = { 0, 2, 8, 2, 4, 6 }; 33 34 private static final int[] offPoints = { 2, -1, 2, 8, 6, 4 }; 35 36 44 public Twistie(Composite parent, int style) { 45 super(parent, style); 46 innerWidth = 9; 47 innerHeight = 9; 48 } 49 50 53 protected void paintHyperlink(GC gc) { 54 Color bg; 55 if (!isEnabled()) 56 bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); 57 else if (hover && getHoverDecorationColor() != null) 58 bg = getHoverDecorationColor(); 59 else if (getDecorationColor() != null) 60 bg = getDecorationColor(); 61 else 62 bg = getForeground(); 63 gc.setBackground(bg); 64 int[] data; 65 Point size = getSize(); 66 int x = (size.x - 9) / 2; 67 int y = (size.y - 9) / 2; 68 if (isExpanded()) 69 data = translate(onPoints, x, y); 70 else 71 data = translate(offPoints, x, y); 72 gc.fillPolygon(data); 73 gc.setBackground(getBackground()); 74 } 75 76 private int[] translate(int[] data, int x, int y) { 77 int[] target = new int[data.length]; 78 for (int i = 0; i < data.length; i += 2) { 79 target[i] = data[i] + x; 80 } 81 for (int i = 1; i < data.length; i += 2) { 82 target[i] = data[i] + y; 83 } 84 return target; 85 } 86 87 92 public void setEnabled(boolean enabled) { 93 super.setEnabled(enabled); 94 redraw(); 95 } 96 } 97 | Popular Tags |