Lines 31-36
Link Here
|
31 |
import org.eclipse.draw2d.IFigure; |
31 |
import org.eclipse.draw2d.IFigure; |
32 |
import org.eclipse.draw2d.MarginBorder; |
32 |
import org.eclipse.draw2d.MarginBorder; |
33 |
import org.eclipse.draw2d.Toggle; |
33 |
import org.eclipse.draw2d.Toggle; |
|
|
34 |
import org.eclipse.draw2d.geometry.Insets; |
34 |
import org.eclipse.draw2d.geometry.Rectangle; |
35 |
import org.eclipse.draw2d.geometry.Rectangle; |
35 |
|
36 |
|
36 |
import org.eclipse.gef.AccessibleEditPart; |
37 |
import org.eclipse.gef.AccessibleEditPart; |
Lines 201-206
Link Here
|
201 |
} |
202 |
} |
202 |
} |
203 |
} |
203 |
|
204 |
|
|
|
205 |
/** |
206 |
* The figure for for a <code>ToolEntryEditPart</code>. |
207 |
*/ |
208 |
class ToolEntryToggle |
209 |
extends Toggle { |
210 |
|
211 |
private boolean showHoverFeedback = false; |
212 |
|
213 |
ToolEntryToggle(IFigure contents) { |
214 |
super(contents); |
215 |
setOpaque(false); |
216 |
setEnabled(true); |
217 |
if (isToolbarItem() |
218 |
&& !PaletteStack.PALETTE_TYPE_STACK.equals(getPaletteEntry() |
219 |
.getParent().getType())) { |
220 |
setStyle(Clickable.STYLE_BUTTON | Clickable.STYLE_TOGGLE); |
221 |
setBorder(TOOLBAR_ITEM_BORDER); |
222 |
} |
223 |
} |
224 |
public boolean containsPoint(int x, int y) { |
225 |
Rectangle rect = getBounds().getCopy(); |
226 |
if (customLabel.getBorder() == ICON_BORDER) { |
227 |
rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; |
228 |
} else if (customLabel.getBorder() == LIST_BORDER) { |
229 |
rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; |
230 |
rect.x += PinnablePaletteStackFigure.ARROW_WIDTH; |
231 |
} |
232 |
return rect.contains(x, y); |
233 |
} |
234 |
|
235 |
public IFigure findMouseEventTargetAt(int x, int y) { |
236 |
return null; |
237 |
} |
238 |
|
239 |
public IFigure getToolTip() { |
240 |
return createToolTip(); |
241 |
} |
242 |
|
243 |
public void setEnabled(boolean value) { |
244 |
super.setEnabled(value); |
245 |
if (isEnabled()) { |
246 |
setRolloverEnabled(true); |
247 |
if (getFlag(STYLE_BUTTON)) { |
248 |
setBorder(TOOLBAR_ITEM_BORDER); |
249 |
} |
250 |
setForegroundColor(null); |
251 |
} else { |
252 |
if (getFlag(STYLE_BUTTON)) { |
253 |
setBorder(null); |
254 |
} |
255 |
setRolloverEnabled(false); |
256 |
setForegroundColor(ColorConstants.gray); |
257 |
} |
258 |
} |
259 |
|
260 |
protected void paintFigure(Graphics graphics) { |
261 |
super.paintFigure(graphics); |
262 |
|
263 |
if (!isToolbarItem() && isEnabled() && isRolloverEnabled()) { |
264 |
ButtonModel model = getModel(); |
265 |
|
266 |
if (model.isSelected()) { |
267 |
graphics.setBackgroundColor(PaletteColorUtil.getSelectedColor()); |
268 |
graphics.fillRoundRectangle(getSelectionRectangle( |
269 |
getLayoutSetting(), customLabel), 3, 3); |
270 |
} else if (model.isMouseOver() || showHoverFeedback) { |
271 |
graphics.setBackgroundColor(PaletteColorUtil.getHoverColor()); |
272 |
graphics.fillRoundRectangle(getSelectionRectangle( |
273 |
getLayoutSetting(), customLabel), 3, 3); |
274 |
} |
275 |
} |
276 |
} |
277 |
|
278 |
protected void paintBorder(Graphics graphics) { |
279 |
if (!isToolbarItem() && isEnabled()) { |
280 |
|
281 |
if (getBorder() != null) |
282 |
getBorder().paint(this, graphics, NO_INSETS); |
283 |
if (hasFocus()) { |
284 |
graphics.setForegroundColor(ColorConstants.black); |
285 |
graphics.setBackgroundColor(ColorConstants.white); |
286 |
|
287 |
Rectangle area = getSelectionRectangle(getLayoutSetting(), |
288 |
customLabel); |
289 |
if (isStyle(STYLE_BUTTON)) |
290 |
graphics.drawFocus(area.x, area.y, area.width, area.height); |
291 |
else |
292 |
graphics.drawFocus(area.x, area.y, area.width - 1, |
293 |
area.height - 1); |
294 |
} |
295 |
} else { |
296 |
super.paintBorder(graphics); |
297 |
} |
298 |
} |
299 |
|
300 |
/** |
301 |
* Should hover feedback be shown? Allows other palette entities to control when |
302 |
* the hover feedback should be shown on this tool entry. |
303 |
* |
304 |
* @param showHoverFeedback |
305 |
* true if the hover feedback is to be shown; false otherwise. |
306 |
*/ |
307 |
public void setShowHoverFeedback(boolean showHoverFeedback) { |
308 |
this.showHoverFeedback = showHoverFeedback; |
309 |
repaint(); |
310 |
} |
311 |
} |
312 |
|
204 |
private static final String ACTIVE_STATE = "active"; //$NON-NLS-1$ |
313 |
private static final String ACTIVE_STATE = "active"; //$NON-NLS-1$ |
205 |
private DetailedLabelFigure customLabel; |
314 |
private DetailedLabelFigure customLabel; |
206 |
|
315 |
|
Lines 245-332
Link Here
|
245 |
|
354 |
|
246 |
static final Border TOOLBAR_ITEM_BORDER = new ButtonBorder( |
355 |
static final Border TOOLBAR_ITEM_BORDER = new ButtonBorder( |
247 |
ButtonBorder.SCHEMES.TOOLBAR); |
356 |
ButtonBorder.SCHEMES.TOOLBAR); |
248 |
static final Border COLUMNS_BORDER = new MarginBorder(2, 0, 1, 0); |
|
|
249 |
static final Border LIST_BORDER = new MarginBorder(3, 16, 2, 0); |
250 |
static final Border ICON_BORDER = new MarginBorder(3, 3, 3, 3); |
251 |
|
357 |
|
252 |
public IFigure createFigure() { |
358 |
// The following are the insets that the bounds of the label figure should be |
253 |
class InactiveToggleButton extends Toggle { |
359 |
// cropped to paint the blue/orange select and hover feedback rectangles. |
254 |
|
360 |
static final Insets LIST_HIGHLIGHT_INSETS = new Insets(1, 5, 2, 0); |
255 |
InactiveToggleButton(IFigure contents) { |
361 |
static final Insets ICON_HIGHLIGHT_INSETS = new Insets(2, 1, 2, 1); |
256 |
super(contents); |
362 |
|
257 |
setOpaque(false); |
363 |
// The following are the borders that go around the entire tool figure to |
258 |
setEnabled(true); |
364 |
// provide room to draw the arrow and outline of the palette stack figure if |
259 |
if (isToolbarItem() |
365 |
// this tool happens to appear as the active tool of a stack. |
260 |
&& !PaletteStack.PALETTE_TYPE_STACK.equals(getPaletteEntry() |
366 |
static final Border LIST_BORDER = new MarginBorder(3, |
261 |
.getParent().getType())) { |
367 |
PinnablePaletteStackFigure.ARROW_WIDTH + 7, 4, 0); |
262 |
setStyle(Clickable.STYLE_BUTTON | Clickable.STYLE_TOGGLE); |
368 |
static final Border ICON_BORDER = new MarginBorder(4, 4, 3, |
263 |
setBorder(TOOLBAR_ITEM_BORDER); |
369 |
PinnablePaletteStackFigure.ARROW_WIDTH + 4); |
264 |
} |
|
|
265 |
} |
266 |
public IFigure findMouseEventTargetAt(int x, int y) { |
267 |
return null; |
268 |
} |
269 |
public IFigure getToolTip() { |
270 |
return createToolTip(); |
271 |
} |
272 |
public void setEnabled(boolean value) { |
273 |
super.setEnabled(value); |
274 |
if (isEnabled()) { |
275 |
setRolloverEnabled(true); |
276 |
if (getFlag(STYLE_BUTTON)) { |
277 |
setBorder(TOOLBAR_ITEM_BORDER); |
278 |
} |
279 |
setForegroundColor(null); |
280 |
} else { |
281 |
if (getFlag(STYLE_BUTTON)) { |
282 |
setBorder(null); |
283 |
} |
284 |
setRolloverEnabled(false); |
285 |
setForegroundColor(ColorConstants.gray); |
286 |
} |
287 |
} |
288 |
protected void paintFigure(Graphics graphics) { |
289 |
super.paintFigure(graphics); |
290 |
|
291 |
if (!isToolbarItem() && isEnabled()) { |
292 |
ButtonModel model = getModel(); |
293 |
if (isRolloverEnabled() && !model.isMouseOver() && !model.isSelected()) |
294 |
return; |
295 |
|
296 |
if (model.isSelected()) { |
297 |
graphics.setBackgroundColor(PaletteColorUtil.getSelectedColor()); |
298 |
} else { |
299 |
graphics.setBackgroundColor(PaletteColorUtil.getHoverColor()); |
300 |
} |
301 |
graphics.fillRoundRectangle(getSelectionRectangle( |
302 |
getLayoutSetting(), customLabel), 3, 3); |
303 |
} |
304 |
} |
305 |
protected void paintBorder(Graphics graphics) { |
306 |
if (!isToolbarItem() && isEnabled()) { |
307 |
|
370 |
|
308 |
if (getBorder() != null) |
371 |
public IFigure createFigure() { |
309 |
getBorder().paint(this, graphics, NO_INSETS); |
|
|
310 |
if (hasFocus()) { |
311 |
graphics.setForegroundColor(ColorConstants.black); |
312 |
graphics.setBackgroundColor(ColorConstants.white); |
313 |
|
314 |
Rectangle area = getSelectionRectangle( |
315 |
getLayoutSetting(), customLabel); |
316 |
if (isStyle(STYLE_BUTTON)) |
317 |
graphics.drawFocus(area.x, area.y, area.width, area.height); |
318 |
else |
319 |
graphics.drawFocus(area.x, area.y, area.width - 1, area.height - 1); |
320 |
} |
321 |
} else { |
322 |
super.paintBorder(graphics); |
323 |
} |
324 |
} |
325 |
|
326 |
} |
327 |
|
372 |
|
328 |
customLabel = new DetailedLabelFigure(); |
373 |
customLabel = new DetailedLabelFigure(); |
329 |
Clickable button = new InactiveToggleButton(customLabel); |
374 |
Clickable button = new ToolEntryToggle(customLabel); |
330 |
button.addActionListener(new ActionListener() { |
375 |
button.addActionListener(new ActionListener() { |
331 |
public void actionPerformed(ActionEvent event) { |
376 |
public void actionPerformed(ActionEvent event) { |
332 |
getPaletteViewer().setActiveTool(getToolEntry()); |
377 |
getPaletteViewer().setActiveTool(getToolEntry()); |
Lines 408-414
Link Here
|
408 |
int layoutMode = getLayoutSetting(); |
453 |
int layoutMode = getLayoutSetting(); |
409 |
customLabel.setLayoutMode(layoutMode); |
454 |
customLabel.setLayoutMode(layoutMode); |
410 |
if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { |
455 |
if (layoutMode == PaletteViewerPreferences.LAYOUT_COLUMNS) { |
411 |
customLabel.setBorder(COLUMNS_BORDER); |
456 |
customLabel.setBorder(ICON_BORDER); |
412 |
} else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST |
457 |
} else if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST |
413 |
|| layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { |
458 |
|| layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { |
414 |
customLabel.setBorder(LIST_BORDER); |
459 |
customLabel.setBorder(LIST_BORDER); |
Lines 478-494
Link Here
|
478 |
|
523 |
|
479 |
static Rectangle getSelectionRectangle(int layoutMode, DetailedLabelFigure labelFigure) { |
524 |
static Rectangle getSelectionRectangle(int layoutMode, DetailedLabelFigure labelFigure) { |
480 |
Rectangle rect = Rectangle.SINGLETON; |
525 |
Rectangle rect = Rectangle.SINGLETON; |
481 |
rect.setBounds(labelFigure.getClientArea()); |
526 |
rect.setBounds(labelFigure.getBounds()); |
482 |
if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST |
527 |
if (layoutMode == PaletteViewerPreferences.LAYOUT_LIST |
483 |
|| layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { |
528 |
|| layoutMode == PaletteViewerPreferences.LAYOUT_DETAILS) { |
484 |
rect.x -= 5; |
529 |
|
485 |
rect.y -= 2; |
530 |
rect.x += PinnablePaletteStackFigure.ARROW_WIDTH; |
486 |
rect.width = labelFigure.getPreferredSize().width + 17; |
531 |
rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; |
487 |
rect.height += 4; |
532 |
int newWidth = labelFigure.getPreferredSize().width + 17; |
|
|
533 |
if (newWidth < rect.width) { |
534 |
rect.width = newWidth; |
535 |
} |
536 |
rect.crop(LIST_HIGHLIGHT_INSETS); |
488 |
} else { |
537 |
} else { |
489 |
rect.expand(2, 2); |
538 |
rect.width -= PinnablePaletteStackFigure.ARROW_WIDTH; |
|
|
539 |
rect.crop(ICON_HIGHLIGHT_INSETS); |
490 |
} |
540 |
} |
491 |
rect.intersect(labelFigure.getBounds().getExpanded(-1, -1)); |
|
|
492 |
return rect; |
541 |
return rect; |
493 |
} |
542 |
} |
|
|
543 |
|
494 |
} |
544 |
} |