|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2015-2020 Oak Ridge National Laboratory. |
| 2 | + * Copyright (c) 2015-2022 Oak Ridge National Laboratory. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution, and is available at |
|
23 | 23 | import org.csstudio.display.builder.model.properties.OpenDisplayActionInfo; |
24 | 24 | import org.csstudio.display.builder.model.properties.RotationStep; |
25 | 25 | import org.csstudio.display.builder.model.properties.StringWidgetProperty; |
| 26 | +import org.csstudio.display.builder.model.properties.WidgetColor; |
26 | 27 | import org.csstudio.display.builder.model.properties.WritePVActionInfo; |
27 | 28 | import org.csstudio.display.builder.model.widgets.ActionButtonWidget; |
28 | 29 | import org.csstudio.display.builder.representation.javafx.Cursors; |
|
36 | 37 | import org.phoebus.ui.vtype.FormatOptionHandler; |
37 | 38 |
|
38 | 39 | import javafx.application.Platform; |
| 40 | +import javafx.event.EventHandler; |
39 | 41 | import javafx.geometry.Dimension2D; |
40 | 42 | import javafx.scene.Cursor; |
41 | 43 | import javafx.scene.control.Button; |
@@ -76,7 +78,7 @@ public class ActionButtonRepresentation extends RegionBaseRepresentation<Pane, A |
76 | 78 | private final DirtyFlag dirty_actionls = new DirtyFlag(); |
77 | 79 |
|
78 | 80 | private volatile ButtonBase base; |
79 | | - private volatile String background; |
| 81 | + private volatile String background, pressed_background; |
80 | 82 | private volatile Color foreground; |
81 | 83 | private volatile String button_text; |
82 | 84 | private volatile boolean enabled = true; |
@@ -135,6 +137,9 @@ private void checkModifiers(final MouseEvent event) |
135 | 137 | return; |
136 | 138 | } |
137 | 139 |
|
| 140 | + // Indicate that button is pressed |
| 141 | + base.setStyle(pressed_background); |
| 142 | + |
138 | 143 | // 'control' ('command' on Mac OS X) |
139 | 144 | if (event.isShortcutDown()) |
140 | 145 | target_modifier = Optional.of(OpenDisplayActionInfo.Target.TAB); |
@@ -211,7 +216,13 @@ private ButtonBase makeBaseButton() |
211 | 216 | // Monitor keys that modify the OpenDisplayActionInfo.Target. |
212 | 217 | // Use filter to capture event that's otherwise already handled. |
213 | 218 | if (! toolkit.isEditMode()) |
| 219 | + { |
| 220 | + // Pressed button will use pressed_background, check modifiers, then invoke actions |
214 | 221 | result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers); |
| 222 | + // Restore normal background when released |
| 223 | + final EventHandler<MouseEvent> restore = event -> result.setStyle(background); |
| 224 | + result.addEventFilter(MouseEvent.MOUSE_RELEASED, restore); |
| 225 | + } |
215 | 226 |
|
216 | 227 | // Need to attach TT to the specific button, not the common jfx_node Pane |
217 | 228 | TooltipSupport.attach(result, model_widget.propTooltip()); |
@@ -323,7 +334,7 @@ private void handleActions(final List<ActionInfo> actions) |
323 | 334 | /** @param action Action that the user invoked */ |
324 | 335 | private void handleAction(ActionInfo action) |
325 | 336 | { |
326 | | - // Keyboard presses are not supressed so check if the widget is enabled |
| 337 | + // Keyboard presses are not suppressed so check if the widget is enabled |
327 | 338 | if (! enabled) |
328 | 339 | return; |
329 | 340 |
|
@@ -428,10 +439,22 @@ private void updateColors() |
428 | 439 | { |
429 | 440 | foreground = JFXUtil.convert(model_widget.propForegroundColor().getValue()); |
430 | 441 | if (model_widget.propTransparent().getValue()) |
| 442 | + { |
431 | 443 | // Set most colors to transparent, including the 'arrow' used by MenuButton |
432 | 444 | background = "-fx-background: transparent; -fx-color: transparent; -fx-focus-color: rgba(3,158,211,0.1); -fx-mark-color: transparent; -fx-background-color: transparent;"; |
| 445 | + pressed_background = background; |
| 446 | + } |
433 | 447 | else |
434 | | - background = JFXUtil.shadedStyle(model_widget.propBackgroundColor().getValue()); |
| 448 | + { |
| 449 | + final WidgetColor norm = model_widget.propBackgroundColor().getValue(); |
| 450 | + // Darker color when pressed |
| 451 | + final WidgetColor press = new WidgetColor(norm.getRed()/2, |
| 452 | + norm.getGreen()/2, |
| 453 | + norm.getBlue()/2, |
| 454 | + norm.getAlpha()); |
| 455 | + background = JFXUtil.shadedStyle(norm); |
| 456 | + pressed_background = JFXUtil.shadedStyle(press); |
| 457 | + } |
435 | 458 | } |
436 | 459 |
|
437 | 460 | @Override |
|
0 commit comments