|
Lines 1-5
Link Here
|
| 1 |
/****************************************************************************** |
1 |
/****************************************************************************** |
| 2 |
* Copyright (c) 2002, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2002, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 11-57
Link Here
|
| 11 |
|
11 |
|
| 12 |
package org.eclipse.gmf.runtime.draw2d.ui.figures; |
12 |
package org.eclipse.gmf.runtime.draw2d.ui.figures; |
| 13 |
|
13 |
|
| 14 |
import java.beans.PropertyChangeEvent; |
|
|
| 15 |
import java.beans.PropertyChangeListener; |
| 16 |
|
| 17 |
import org.eclipse.draw2d.Border; |
14 |
import org.eclipse.draw2d.Border; |
| 18 |
import org.eclipse.draw2d.ChangeEvent; |
15 |
import org.eclipse.draw2d.ChangeEvent; |
| 19 |
import org.eclipse.draw2d.ChangeListener; |
16 |
import org.eclipse.draw2d.ChangeListener; |
| 20 |
import org.eclipse.draw2d.Clickable; |
17 |
import org.eclipse.draw2d.Clickable; |
| 21 |
import org.eclipse.draw2d.ColorConstants; |
18 |
import org.eclipse.draw2d.ColorConstants; |
|
|
19 |
import org.eclipse.draw2d.Figure; |
| 22 |
import org.eclipse.draw2d.Graphics; |
20 |
import org.eclipse.draw2d.Graphics; |
| 23 |
import org.eclipse.draw2d.IFigure; |
21 |
import org.eclipse.draw2d.IFigure; |
| 24 |
import org.eclipse.draw2d.MarginBorder; |
22 |
import org.eclipse.draw2d.MarginBorder; |
|
|
23 |
import org.eclipse.draw2d.MouseEvent; |
| 25 |
import org.eclipse.draw2d.Panel; |
24 |
import org.eclipse.draw2d.Panel; |
| 26 |
import org.eclipse.draw2d.SchemeBorder; |
|
|
| 27 |
import org.eclipse.draw2d.ScrollBar; |
25 |
import org.eclipse.draw2d.ScrollBar; |
| 28 |
import org.eclipse.draw2d.geometry.Dimension; |
26 |
import org.eclipse.draw2d.geometry.Dimension; |
| 29 |
import org.eclipse.draw2d.geometry.Insets; |
27 |
import org.eclipse.draw2d.geometry.Insets; |
| 30 |
import org.eclipse.gmf.runtime.draw2d.ui.graphics.GCUtilities; |
28 |
import org.eclipse.draw2d.geometry.Point; |
| 31 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.DropShadowButtonBorder; |
29 |
import org.eclipse.draw2d.geometry.PointList; |
| 32 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.figures.ImageFigureEx; |
30 |
import org.eclipse.draw2d.geometry.Rectangle; |
| 33 |
import org.eclipse.gmf.runtime.draw2d.ui.internal.l10n.Draw2dUIPluginImages; |
31 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; |
| 34 |
import org.eclipse.swt.SWT; |
32 |
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; |
| 35 |
import org.eclipse.swt.graphics.Image; |
33 |
import org.eclipse.swt.graphics.Color; |
| 36 |
import org.eclipse.swt.graphics.ImageData; |
|
|
| 37 |
import org.eclipse.swt.graphics.RGB; |
34 |
import org.eclipse.swt.graphics.RGB; |
| 38 |
import org.eclipse.swt.widgets.Display; |
|
|
| 39 |
|
35 |
|
| 40 |
|
36 |
|
| 41 |
/** |
37 |
/** |
|
|
38 |
* Customizes the look of GEF's ScrollBar |
| 42 |
* |
39 |
* |
| 43 |
* @author sshaw |
40 |
* @author sshaw |
|
|
41 |
* @author lgrahek |
| 44 |
* |
42 |
* |
| 45 |
*/ |
43 |
*/ |
| 46 |
public class ListScrollBar extends ScrollBar { |
44 |
public class ListScrollBar extends ScrollBar { |
| 47 |
|
45 |
|
| 48 |
static private ImageConstants icons = new ImageConstants(); |
46 |
protected ArrowButton downButtonFigure; |
| 49 |
private Image upIcon, upPressedIcon, upGrayedIcon, downIcon, downPressedIcon, downGrayedIcon; |
47 |
protected ArrowButton upButtonFigure; |
| 50 |
|
48 |
ThumbFigure thumb; |
| 51 |
private ImageFigureEx upLabel; |
49 |
|
| 52 |
private ImageFigureEx downLabel; |
50 |
protected static Color fillLightGrey = new Color(null, new RGB(240, 240, 240)); |
| 53 |
|
51 |
protected static Color outlineLightGrey = new Color(null, new RGB(185, 185, 185)); |
| 54 |
private static Border dropshadow = new DropShadowButtonBorder(); |
52 |
protected static Color fillDarkGrey = new Color(null, new RGB(84, 84, 84)); |
|
|
53 |
protected static Color outlineDarkGrey = new Color(null, new RGB(109, 109, 109)); |
| 54 |
protected static Color arrowFill = new Color(null, new RGB(187, 187, 187)); |
| 55 |
|
| 56 |
protected int mm_1; |
| 57 |
protected int mm_2; |
| 55 |
|
58 |
|
| 56 |
/** |
59 |
/** |
| 57 |
* Constructor |
60 |
* Constructor |
|
Lines 69-87
Link Here
|
| 69 |
public ListScrollBar(int orientation, Insets insets, Dimension size, int stepInc, int pageInc) { |
72 |
public ListScrollBar(int orientation, Insets insets, Dimension size, int stepInc, int pageInc) { |
| 70 |
setOrientation(orientation); |
73 |
setOrientation(orientation); |
| 71 |
|
74 |
|
| 72 |
Border margin = new MarginBorder(insets.top, insets.left, insets.bottom, insets.right); |
75 |
Border margin = new MarginBorder(insets.top, insets.left, insets.bottom, insets.right); |
| 73 |
|
|
|
| 74 |
setBorder(margin); |
76 |
setBorder(margin); |
| 75 |
setPreferredSize(size.width, size.height); |
77 |
setPreferredSize(size.width, size.height); |
| 76 |
setStepIncrement(stepInc); |
78 |
setStepIncrement(stepInc); |
| 77 |
setPageIncrement(pageInc); |
79 |
setPageIncrement(pageInc); |
| 78 |
|
80 |
if (isHorizontal()) { |
| 79 |
upIcon = isHorizontal()? icons.left : icons.up; |
81 |
downButtonFigure.setDirection(EAST); |
| 80 |
upPressedIcon = isHorizontal()? icons.leftPressed : icons.upPressed; |
82 |
upButtonFigure.setDirection(WEST); |
| 81 |
upGrayedIcon = isHorizontal()? icons.leftGrayed : icons.upGrayed; |
83 |
} else { |
| 82 |
downIcon = isHorizontal()? icons.right : icons.down; |
84 |
downButtonFigure.setDirection(SOUTH); |
| 83 |
downPressedIcon = isHorizontal()? icons.rightPressed : icons.downPressed; |
85 |
upButtonFigure.setDirection(NORTH); |
| 84 |
downGrayedIcon = isHorizontal()? icons.rightGrayed : icons.downGrayed; |
86 |
} |
|
|
87 |
|
| 88 |
IMapMode mm= MapModeUtil.getMapMode(this); |
| 89 |
mm_1 = mm.DPtoLP(1); |
| 90 |
mm_2 = mm.DPtoLP(2); |
| 85 |
} |
91 |
} |
| 86 |
|
92 |
|
| 87 |
|
93 |
|
|
Lines 89-112
Link Here
|
| 89 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultDownButton() |
95 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultDownButton() |
| 90 |
*/ |
96 |
*/ |
| 91 |
protected Clickable createDefaultDownButton() { |
97 |
protected Clickable createDefaultDownButton() { |
| 92 |
downLabel = new ImageFigureEx(downIcon); |
98 |
downButtonFigure = new ArrowButton(); |
| 93 |
downLabel.setOpaque(true); |
99 |
downButtonFigure.setBorder(new MarginBorder(new Insets(mm_1))); |
| 94 |
addPropertyChangeListener(new PropertyChangeListener() { |
100 |
Clickable button = new Clickable(downButtonFigure) { |
| 95 |
public void propertyChange(PropertyChangeEvent event) { |
101 |
@Override |
| 96 |
updateDownLabel(); |
102 |
public boolean hasFocus() { |
| 97 |
} |
103 |
return false; |
| 98 |
}); |
104 |
} |
| 99 |
Clickable button = new Clickable(downLabel); |
105 |
}; |
| 100 |
button.getModel().addChangeListener(new ChangeListener() { |
106 |
button.getModel().addChangeListener(new ChangeListener() { |
| 101 |
public void handleStateChanged(ChangeEvent event) { |
107 |
public void handleStateChanged(ChangeEvent event) { |
| 102 |
updateDownLabel(); |
108 |
updateDownColors(); |
| 103 |
} |
109 |
} |
| 104 |
}); |
110 |
}); |
| 105 |
|
111 |
|
| 106 |
button.setFiringMethod(Clickable.REPEAT_FIRING); |
112 |
button.setFiringMethod(Clickable.REPEAT_FIRING); |
| 107 |
button.setRolloverEnabled(true); |
113 |
button.setRolloverEnabled(true); |
| 108 |
button.setBorder(dropshadow); |
|
|
| 109 |
button.setOpaque(false); |
| 110 |
return button; |
114 |
return button; |
| 111 |
} |
115 |
} |
| 112 |
|
116 |
|
|
Lines 114-138
Link Here
|
| 114 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultUpButton() |
118 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultUpButton() |
| 115 |
*/ |
119 |
*/ |
| 116 |
protected Clickable createDefaultUpButton() { |
120 |
protected Clickable createDefaultUpButton() { |
| 117 |
upLabel = new ImageFigureEx(upIcon); |
121 |
upButtonFigure = new ArrowButton(); |
| 118 |
upLabel.setOpaque(true); |
122 |
upButtonFigure.setBorder(new MarginBorder(new Insets(mm_1))); |
| 119 |
addPropertyChangeListener(new PropertyChangeListener() { |
123 |
Clickable button = new Clickable(upButtonFigure) { |
| 120 |
public void propertyChange(PropertyChangeEvent event) { |
124 |
@Override |
| 121 |
updateUpLabel(); |
125 |
public boolean hasFocus() { |
| 122 |
} |
126 |
return false; |
| 123 |
}); |
127 |
} |
| 124 |
Clickable button = new Clickable(upLabel); |
128 |
}; |
| 125 |
button.getModel().addChangeListener(new ChangeListener() { |
129 |
button.getModel().addChangeListener(new ChangeListener() { |
| 126 |
public void handleStateChanged(ChangeEvent event) { |
130 |
public void handleStateChanged(ChangeEvent event) { |
| 127 |
updateUpLabel(); |
131 |
updateUpColors(); |
| 128 |
} |
132 |
} |
| 129 |
}); |
133 |
}); |
| 130 |
|
134 |
|
| 131 |
button.setFiringMethod(Clickable.REPEAT_FIRING); |
135 |
button.setFiringMethod(Clickable.REPEAT_FIRING); |
| 132 |
button.setRolloverEnabled(true); |
136 |
button.setRolloverEnabled(true); |
| 133 |
button.setBorder(dropshadow); |
137 |
return button; |
| 134 |
button.setOpaque(false); |
|
|
| 135 |
return button; |
| 136 |
} |
138 |
} |
| 137 |
|
139 |
|
| 138 |
/* (non-Javadoc) |
140 |
/* (non-Javadoc) |
|
Lines 142-277
Link Here
|
| 142 |
super.initialize(); |
144 |
super.initialize(); |
| 143 |
setPageUp(null); |
145 |
setPageUp(null); |
| 144 |
setPageDown(null); |
146 |
setPageDown(null); |
| 145 |
setOpaque(false); |
147 |
setOpaque(true); |
| 146 |
} |
148 |
} |
| 147 |
|
149 |
|
| 148 |
/* (non-Javadoc) |
150 |
/* (non-Javadoc) |
| 149 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultThumb() |
151 |
* @see org.eclipse.draw2d.ScrollBar#createDefaultThumb() |
| 150 |
*/ |
152 |
*/ |
| 151 |
protected IFigure createDefaultThumb() { |
153 |
protected IFigure createDefaultThumb() { |
| 152 |
Panel thumb = new Panel() { |
154 |
thumbDragger = new ThumbDraggerColors(); |
| 153 |
|
155 |
|
| 154 |
public void paint(Graphics graphics) { |
156 |
thumb = new ThumbFigure(); |
| 155 |
if (GCUtilities.supportsAdvancedGraphics()){ |
|
|
| 156 |
graphics.setAlpha(128); |
| 157 |
} |
| 158 |
super.paint(graphics); |
| 159 |
} |
| 160 |
|
| 161 |
}; |
| 162 |
thumb.setMinimumSize(new Dimension(6, 6)); |
157 |
thumb.setMinimumSize(new Dimension(6, 6)); |
| 163 |
thumb.setBackgroundColor(ColorConstants.button); |
|
|
| 164 |
|
| 165 |
thumb.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.RIDGED)); |
| 166 |
return thumb; |
158 |
return thumb; |
| 167 |
} |
159 |
} |
| 168 |
|
160 |
|
| 169 |
|
161 |
/** |
| 170 |
private void updateDownLabel() { |
162 |
* Updates colors of down button depending on its state (highlighted, |
| 171 |
Image icon = null; |
163 |
* pressed, or neither) |
| 172 |
if (((Clickable) getButtonDown()).getModel().isPressed() |
164 |
*/ |
| 173 |
|| !((Clickable) getButtonDown()).getModel().isMouseOver()) |
165 |
protected void updateDownColors() { |
| 174 |
icon = downPressedIcon; |
166 |
boolean pressed = false; |
| 175 |
if (getValue() >= (getMaximum() - getExtent())) { |
167 |
boolean highlighted = false; |
| 176 |
icon = downGrayedIcon; |
168 |
if (getValue() < (getMaximum() - getExtent())) { |
| 177 |
getButtonDown().setEnabled(false); |
169 |
// Arrow is scrollable |
| 178 |
} else { |
170 |
if (((Clickable) getButtonDown()).getModel().isPressed()) { |
| 179 |
getButtonDown().setEnabled(true); |
171 |
pressed = true; |
| 180 |
if (icon == null) |
172 |
} else if (((Clickable) getButtonDown()).getModel().isMouseOver()) { |
| 181 |
icon = downIcon; |
173 |
highlighted = true; |
|
|
174 |
} |
| 175 |
} |
| 176 |
boolean doRepaint = false; |
| 177 |
if (downButtonFigure.isHighlighted() != highlighted) { |
| 178 |
downButtonFigure.setHighlighted(highlighted); |
| 179 |
doRepaint = true; |
| 180 |
} |
| 181 |
if (downButtonFigure.isPressed() != pressed) { |
| 182 |
doRepaint = true; |
| 183 |
downButtonFigure.setPressed(pressed); |
| 184 |
} |
| 185 |
if (doRepaint) { |
| 186 |
// Just changing color, no recalculation of arrow position needed |
| 187 |
downButtonFigure.setRecalculate(false); |
| 188 |
downButtonFigure.repaint(); |
| 182 |
} |
189 |
} |
| 183 |
downLabel.setImage(icon); |
|
|
| 184 |
} |
190 |
} |
| 185 |
|
191 |
|
| 186 |
private void updateUpLabel() { |
192 |
/** |
| 187 |
Image icon = null; |
193 |
* Updates colors of up button depending on its state (highlighted, |
| 188 |
if (((Clickable) getButtonUp()).getModel().isPressed() |
194 |
* pressed, or neither) |
| 189 |
|| !((Clickable) getButtonUp()).getModel().isMouseOver()) |
195 |
*/ |
| 190 |
icon = upPressedIcon; |
196 |
protected void updateUpColors() { |
| 191 |
if (getValue() <= getMinimum()) { |
197 |
boolean pressed = false; |
| 192 |
icon = upGrayedIcon; |
198 |
boolean highlighted = false; |
| 193 |
getButtonUp().setEnabled(false); |
199 |
if (getValue() > getMinimum()) { |
| 194 |
} else { |
200 |
// Arrow is scrollable |
| 195 |
getButtonUp().setEnabled(true); |
201 |
if (((Clickable) getButtonUp()).getModel().isPressed()) { |
| 196 |
if (icon == null) |
202 |
pressed = true; |
| 197 |
icon = upIcon; |
203 |
} else if (((Clickable) getButtonUp()).getModel().isMouseOver()) { |
|
|
204 |
highlighted = true; |
| 205 |
} |
| 206 |
} |
| 207 |
boolean doRepaint = false; |
| 208 |
if (upButtonFigure.isHighlighted() != highlighted) { |
| 209 |
upButtonFigure.setHighlighted(highlighted); |
| 210 |
doRepaint = true; |
| 211 |
} |
| 212 |
if (upButtonFigure.isPressed() != pressed) { |
| 213 |
doRepaint = true; |
| 214 |
upButtonFigure.setPressed(pressed); |
| 215 |
} |
| 216 |
if (doRepaint) { |
| 217 |
// Just changing color, no recalculation of arrow position needed |
| 218 |
upButtonFigure.setRecalculate(false); |
| 219 |
upButtonFigure.repaint(); |
| 198 |
} |
220 |
} |
| 199 |
upLabel.setImage(icon); |
|
|
| 200 |
} |
221 |
} |
| 201 |
|
222 |
|
| 202 |
/** |
223 |
/** |
| 203 |
* @author sshaw |
224 |
* Figure that defines the content for up and down buttons |
|
|
225 |
* |
| 226 |
* @author lgrahek |
| 227 |
* |
| 228 |
* @since 1.2 |
| 204 |
* |
229 |
* |
| 205 |
*/ |
230 |
*/ |
| 206 |
static private class ImageConstants { |
231 |
protected class ArrowButton extends Figure |
|
|
232 |
{ |
| 233 |
private PointList arrow = new PointList(); |
| 234 |
private boolean recalculate; |
| 235 |
private int direction; |
| 236 |
private boolean highlighted; |
| 237 |
private boolean pressed; |
| 238 |
|
| 239 |
@Override |
| 240 |
protected void paintFigure(Graphics g) { |
| 241 |
Rectangle r = getBounds(); |
| 242 |
// If not pressed, fill with white, so later there will be 1px of |
| 243 |
// white left around outline. |
| 244 |
g.setAlpha(130); |
| 245 |
if (!pressed) { |
| 246 |
g.setBackgroundColor(ColorConstants.white); |
| 247 |
g.fillRectangle(r); |
| 248 |
} |
| 249 |
// Draw the outline (none when button is pressed) |
| 250 |
if (!pressed) { |
| 251 |
g.setLineWidth(mm_1); |
| 252 |
if (highlighted) { |
| 253 |
g.setForegroundColor(outlineDarkGrey); |
| 254 |
} else { |
| 255 |
g.setForegroundColor(outlineLightGrey); |
| 256 |
} |
| 257 |
g.drawRectangle(r); |
| 258 |
} |
| 259 |
|
| 260 |
// Fill the interior. If not pressed, leave 1px white between outline and filled area. |
| 261 |
if (pressed) { |
| 262 |
g.setBackgroundColor(fillDarkGrey); |
| 263 |
} else { |
| 264 |
g.setBackgroundColor(fillLightGrey); |
| 265 |
r = r.getCopy().shrink(mm_2, mm_2); |
| 266 |
} |
| 267 |
g.fillRectangle(r); |
| 268 |
|
| 269 |
// Draw the arrow |
| 270 |
if (pressed) { |
| 271 |
r = r.getCopy().shrink(mm_2, mm_2); |
| 272 |
} |
| 273 |
if (recalculate || arrow.size() == 0) { |
| 274 |
int size; |
| 275 |
switch (direction) { |
| 276 |
case EAST: |
| 277 |
case WEST: |
| 278 |
size = Math.min(r.height / 2, r.width); |
| 279 |
r.x += (r.width - size) / 2; |
| 280 |
break; |
| 281 |
default: //North or south |
| 282 |
size = Math.min(r.height, r.width / 2); |
| 283 |
r.y += (r.height - size) / 2; |
| 284 |
break; |
| 285 |
} |
| 286 |
size = Math.max(size, 1); //Size cannot be negative |
| 287 |
Point head, p2, p3; |
| 288 |
switch (direction) { |
| 289 |
case NORTH: |
| 290 |
head = new Point(r.x + r.width / 2, r.y); |
| 291 |
p2 = new Point (head.x - size, head.y + size); |
| 292 |
p3 = new Point (head.x + size, head.y + size); |
| 293 |
break; |
| 294 |
case SOUTH: |
| 295 |
head = new Point (r.x + r.width / 2, r.y + size); |
| 296 |
p2 = new Point (head.x - size, head.y - size); |
| 297 |
p3 = new Point (head.x + size, head.y - size); |
| 298 |
break; |
| 299 |
case WEST: |
| 300 |
head = new Point (r.x, r.y + r.height / 2); |
| 301 |
p2 = new Point (head.x + size, head.y - size); |
| 302 |
p3 = new Point (head.x + size, head.y + size); |
| 303 |
break; |
| 304 |
default: |
| 305 |
head = new Point(r.x + size, r.y + r.height / 2); |
| 306 |
p2 = new Point(head.x - size, head.y - size); |
| 307 |
p3 = new Point(head.x - size, head.y + size); |
| 308 |
|
| 309 |
} |
| 310 |
arrow.removeAllPoints(); |
| 311 |
arrow.addPoint(p2); |
| 312 |
arrow.addPoint(head); |
| 313 |
arrow.addPoint(p3); |
| 314 |
} else { |
| 315 |
// Recalculating with every paint unless explicitly told not too |
| 316 |
recalculate = true; |
| 317 |
} |
| 318 |
if (highlighted) { |
| 319 |
g.setForegroundColor(fillDarkGrey); |
| 320 |
} else if (pressed) { |
| 321 |
g.setAlpha(255); |
| 322 |
g.setForegroundColor(ColorConstants.white); |
| 323 |
} else { |
| 324 |
g.setForegroundColor(arrowFill); |
| 325 |
} |
| 326 |
g.setLineWidth(mm_2); |
| 327 |
g.drawPolyline(arrow); |
| 328 |
} |
| 207 |
|
329 |
|
| 208 |
private final Image up, upPressed, upGrayed, |
|
|
| 209 |
down, downPressed, downGrayed, |
| 210 |
left, leftPressed, leftGrayed, |
| 211 |
right, rightPressed, rightGrayed; |
| 212 |
/** |
330 |
/** |
| 213 |
* |
331 |
* @param value |
|
|
332 |
* one of PositionConstants: EAST, WEST, NORTH, SOUTH that |
| 333 |
* determine the arrow direction |
| 214 |
*/ |
334 |
*/ |
| 215 |
public ImageConstants() { |
335 |
public void setDirection(int value) { |
| 216 |
RGB[] palette2 = new RGB[] { FigureUtilities.integerToColor(new Integer(SWT.COLOR_LIST_BACKGROUND)).getRGB(), new RGB(0, 0, 0), new RGB(0, 0, 0), new RGB(0, 0, 0) }; |
336 |
direction = value; |
| 217 |
RGB[] palette1 = new RGB[] { FigureUtilities.integerToColor(new Integer(SWT.COLOR_LIST_FOREGROUND)).getRGB(), new RGB(0, 0, 0)}; |
337 |
} |
| 218 |
|
|
|
| 219 |
ImageData image; |
| 220 |
|
| 221 |
// normal images |
| 222 |
image = |
| 223 |
Draw2dUIPluginImages.DESC_DOWN_ARROW.getImageData(); |
| 224 |
down = convert(image, palette2); |
| 225 |
|
| 226 |
image = |
| 227 |
Draw2dUIPluginImages.DESC_UP_ARROW.getImageData(); |
| 228 |
up = convert(image, palette2); |
| 229 |
|
| 230 |
image = |
| 231 |
Draw2dUIPluginImages.DESC_LEFT_ARROW.getImageData(); |
| 232 |
left = convert(image, palette2); |
| 233 |
|
| 234 |
image = |
| 235 |
Draw2dUIPluginImages.DESC_RIGHT_ARROW.getImageData(); |
| 236 |
right = convert(image, palette2); |
| 237 |
|
| 238 |
// pressed images |
| 239 |
upPressed = Draw2dUIPluginImages |
| 240 |
.get(Draw2dUIPluginImages.IMG_UP_PRESSED_ARROW); |
| 241 |
|
| 242 |
downPressed = Draw2dUIPluginImages |
| 243 |
.get(Draw2dUIPluginImages.IMG_DOWN_PRESSED_ARROW); |
| 244 |
|
| 245 |
leftPressed = Draw2dUIPluginImages |
| 246 |
.get(Draw2dUIPluginImages.IMG_LEFT_PRESSED_ARROW); |
| 247 |
|
| 248 |
rightPressed = Draw2dUIPluginImages |
| 249 |
.get(Draw2dUIPluginImages.IMG_RIGHT_PRESSED_ARROW); |
| 250 |
|
338 |
|
| 251 |
// grayed images |
339 |
/** |
| 252 |
image = |
340 |
* @param value |
| 253 |
Draw2dUIPluginImages.DESC_UP_GRAY_ARROW.getImageData(); |
341 |
* false if arrow points do no have to be recalculated (e.g. |
| 254 |
upGrayed = convert(image, palette1); |
342 |
* when just changing color) |
|
|
343 |
*/ |
| 344 |
public void setRecalculate(boolean value) { |
| 345 |
recalculate = value; |
| 346 |
} |
| 347 |
|
| 348 |
/** |
| 349 |
* @param value true if highlighted, false if not |
| 350 |
*/ |
| 351 |
public void setHighlighted(boolean value) { |
| 352 |
highlighted = value; |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* @return true if highlighted, false if not |
| 357 |
*/ |
| 358 |
public boolean isHighlighted() { |
| 359 |
return highlighted; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* @param value true if pressed, false if not |
| 364 |
*/ |
| 365 |
public void setPressed(boolean value) { |
| 366 |
pressed = value; |
| 367 |
} |
| 255 |
|
368 |
|
| 256 |
image = |
369 |
/** |
| 257 |
Draw2dUIPluginImages.DESC_DOWN_GRAY_ARROW.getImageData(); |
370 |
* @return true if pressed |
| 258 |
downGrayed = convert(image, palette1); |
371 |
*/ |
|
|
372 |
public boolean isPressed() { |
| 373 |
return pressed; |
| 374 |
} |
| 375 |
} |
| 376 |
|
| 377 |
/** |
| 378 |
* Figure that defines scroll bar thumb. |
| 379 |
* |
| 380 |
* @author lgrahek |
| 381 |
* |
| 382 |
* @since 1.2 |
| 383 |
* |
| 384 |
*/ |
| 385 |
protected class ThumbFigure extends Panel { |
| 386 |
boolean highlighted; |
| 387 |
boolean pressed; |
| 388 |
|
| 389 |
@Override |
| 390 |
protected void paintFigure(Graphics g) { |
| 391 |
g.setAlpha(130); |
| 392 |
|
| 393 |
Rectangle r = getBounds().getCopy(); |
| 394 |
// Fill with white, so later there will be 1px of |
| 395 |
// white left around outline. |
| 396 |
g.setBackgroundColor(ColorConstants.white); |
| 397 |
g.fillRectangle(getBounds()); |
| 398 |
// Draw the outline (none when button is pressed) |
| 399 |
g.setLineWidth(mm_1); |
| 400 |
if (highlighted || pressed) { |
| 401 |
g.setForegroundColor(outlineDarkGrey); |
| 402 |
} else { |
| 403 |
g.setForegroundColor(outlineLightGrey); |
| 404 |
} |
| 405 |
g.drawRectangle(r); |
| 406 |
|
| 407 |
// Fill the interior, while leaving 1px white between outline and filled area. |
| 408 |
r = r.getCopy().shrink(mm_2, mm_2); |
| 409 |
if (pressed) { |
| 410 |
g.setBackgroundColor(fillDarkGrey); |
| 411 |
} else { |
| 412 |
g.setBackgroundColor(fillLightGrey); |
| 413 |
} |
| 414 |
g.fillRectangle(r); |
| 415 |
} |
| 259 |
|
416 |
|
| 260 |
image = |
417 |
/** |
| 261 |
Draw2dUIPluginImages.DESC_LEFT_GRAY_ARROW.getImageData(); |
418 |
* @param value true if highlighted, false if not |
| 262 |
leftGrayed = convert(image, palette1); |
419 |
*/ |
|
|
420 |
public void setHighlighted(boolean value) { |
| 421 |
highlighted = value; |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* @return true if highlighted, false if not |
| 426 |
*/ |
| 427 |
public boolean isHighlighted() { |
| 428 |
return highlighted; |
| 429 |
} |
| 430 |
|
| 431 |
/** |
| 432 |
* @param value true if pressed, false if not |
| 433 |
*/ |
| 434 |
public void setPressed(boolean value) { |
| 435 |
pressed = value; |
| 436 |
} |
| 263 |
|
437 |
|
| 264 |
image = |
438 |
/** |
| 265 |
Draw2dUIPluginImages.DESC_RIGHT_GRAY_ARROW.getImageData(); |
439 |
* @return true if pressed |
| 266 |
rightGrayed = convert(image, palette1); |
440 |
*/ |
| 267 |
|
441 |
public boolean isPressed() { |
| 268 |
palette1 = null; |
442 |
return pressed; |
| 269 |
palette2 = null; |
443 |
} |
|
|
444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* Customizes ThumbDragger to set different colors to thumb depending on its |
| 448 |
* state. |
| 449 |
* |
| 450 |
* @author lgrahek |
| 451 |
* |
| 452 |
* @since 1.2 |
| 453 |
* |
| 454 |
*/ |
| 455 |
protected class ThumbDraggerColors extends ThumbDragger { |
| 456 |
|
| 457 |
/* (non-Javadoc) |
| 458 |
* @see org.eclipse.draw2d.MouseMotionListener.Stub#mouseEntered(org.eclipse.draw2d.MouseEvent) |
| 459 |
*/ |
| 460 |
@Override |
| 461 |
public void mouseEntered(MouseEvent me) { |
| 462 |
// Set up highlight colors |
| 463 |
thumb.setHighlighted(true); |
| 464 |
thumb.setPressed(false); |
| 465 |
thumb.repaint(); |
| 466 |
super.mouseEntered(me); |
| 467 |
} |
| 468 |
|
| 469 |
/* (non-Javadoc) |
| 470 |
* @see org.eclipse.draw2d.MouseMotionListener.Stub#mouseExited(org.eclipse.draw2d.MouseEvent) |
| 471 |
*/ |
| 472 |
@Override |
| 473 |
public void mouseExited(MouseEvent me) { |
| 474 |
// Set up colors: back to no-hover, no-drag colors |
| 475 |
thumb.setHighlighted(false); |
| 476 |
thumb.setPressed(false); |
| 477 |
thumb.repaint(); |
| 478 |
super.mouseExited(me); |
| 270 |
} |
479 |
} |
| 271 |
|
480 |
|
| 272 |
private Image convert(ImageData theData, RGB[] colors) { |
481 |
/* (non-Javadoc) |
| 273 |
//theData.palette = new PaletteData(colors); |
482 |
* @see org.eclipse.draw2d.ScrollBar.ThumbDragger#mousePressed(org.eclipse.draw2d.MouseEvent) |
| 274 |
return new Image(Display.getCurrent(), theData); |
483 |
*/ |
|
|
484 |
@Override |
| 485 |
public void mousePressed(MouseEvent me) { |
| 486 |
// Set up pressed colors |
| 487 |
thumb.setHighlighted(false); |
| 488 |
thumb.setPressed(true); |
| 489 |
thumb.repaint(); |
| 490 |
super.mousePressed(me); |
| 275 |
} |
491 |
} |
| 276 |
} |
492 |
|
|
|
493 |
/* (non-Javadoc) |
| 494 |
* @see org.eclipse.draw2d.ScrollBar.ThumbDragger#mouseReleased(org.eclipse.draw2d.MouseEvent) |
| 495 |
*/ |
| 496 |
@Override |
| 497 |
public void mouseReleased(MouseEvent me) { |
| 498 |
// Set up colors: back to hover |
| 499 |
thumb.setHighlighted(true); |
| 500 |
thumb.setPressed(false); |
| 501 |
thumb.repaint(); |
| 502 |
super.mouseReleased(me); |
| 503 |
} |
| 504 |
} |
| 277 |
} |
505 |
} |