KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > views > Chevron


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.views;
12
13 import org.eclipse.swt.graphics.GC;
14 import org.eclipse.swt.graphics.Rectangle;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.ui.forms.widgets.ToggleHyperlink;
17
18 public final class Chevron extends ToggleHyperlink {
19     private static final int[][] offLines = { { 0, 0, 2, 2, 0, 4 },
20             { 1, 0, 3, 2, 1, 4 }, { 4, 0, 6, 2, 4, 4 }, { 5, 0, 7, 2, 5, 4 } };
21
22     private static final int[][] onLines = { { 2, 0, 0, 2, 2, 4 },
23             { 3, 0, 1, 2, 3, 4 }, { 6, 0, 4, 2, 6, 4 }, { 7, 0, 5, 2, 7, 4 } };
24
25     /**
26      * Creates a control in a provided composite.
27      *
28      * @param parent
29      * the parent
30      * @param style
31      * the style
32      */

33     public Chevron(Composite parent, int style) {
34         super(parent, style);
35         innerWidth = 8;
36         innerHeight = 5;
37         marginWidth = 3;
38         marginHeight = 4;
39     }
40
41     /*
42      * @see SelectableControl#paint(GC)
43      */

44     protected void paintHyperlink(GC gc) {
45         if (hover && getHoverDecorationColor() != null)
46             gc.setForeground(getHoverDecorationColor());
47         else if (getDecorationColor() != null)
48             gc.setForeground(getDecorationColor());
49         int[][] data;
50         Rectangle carea = getClientArea();
51         int x = (carea.width - innerWidth) /2;
52         int y = (carea.height - innerHeight) / 2;
53         if (isExpanded())
54             data = translate(onLines, x, y);
55         else
56             data = translate(offLines, x, y);
57         for (int i=0; i<data.length; i++) {
58             gc.drawPolyline(data[i]);
59         }
60         gc.setBackground(getBackground());
61     }
62
63     private int[][] translate(int[][] data, int x, int y) {
64         int[][] target = new int[data.length][];
65         for (int i = 0; i<data.length; i++) {
66             int [] line = data[i];
67             target[i] = new int[line.length];
68             for (int j = 0; j < line.length; j += 2) {
69                 target[i][j] = line[j] + x;
70             }
71             for (int j = 1; j < line.length; j += 2) {
72                 target[i][j] = line[j] + y;
73             }
74         }
75         return target;
76     }
77 }
Popular Tags