From ee1e7825e514c8dcdc9d605b6e6042f3fd79483f Mon Sep 17 00:00:00 2001 From: Kay Kasemir Date: Fri, 24 Jun 2022 16:10:01 -0400 Subject: [PATCH] Action button: Darker background when pressed --- .../widgets/ActionButtonRepresentation.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java index edf9c0fbee..3b494be631 100644 --- a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java +++ b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015-2020 Oak Ridge National Laboratory. + * Copyright (c) 2015-2022 Oak Ridge National Laboratory. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -23,6 +23,7 @@ import org.csstudio.display.builder.model.properties.OpenDisplayActionInfo; import org.csstudio.display.builder.model.properties.RotationStep; import org.csstudio.display.builder.model.properties.StringWidgetProperty; +import org.csstudio.display.builder.model.properties.WidgetColor; import org.csstudio.display.builder.model.properties.WritePVActionInfo; import org.csstudio.display.builder.model.widgets.ActionButtonWidget; import org.csstudio.display.builder.representation.javafx.Cursors; @@ -36,6 +37,7 @@ import org.phoebus.ui.vtype.FormatOptionHandler; import javafx.application.Platform; +import javafx.event.EventHandler; import javafx.geometry.Dimension2D; import javafx.scene.Cursor; import javafx.scene.control.Button; @@ -76,7 +78,7 @@ public class ActionButtonRepresentation extends RegionBaseRepresentation restore = event -> result.setStyle(background); + result.addEventFilter(MouseEvent.MOUSE_RELEASED, restore); + } // Need to attach TT to the specific button, not the common jfx_node Pane TooltipSupport.attach(result, model_widget.propTooltip()); @@ -323,7 +334,7 @@ private void handleActions(final List actions) /** @param action Action that the user invoked */ private void handleAction(ActionInfo action) { - // Keyboard presses are not supressed so check if the widget is enabled + // Keyboard presses are not suppressed so check if the widget is enabled if (! enabled) return; @@ -428,10 +439,22 @@ private void updateColors() { foreground = JFXUtil.convert(model_widget.propForegroundColor().getValue()); if (model_widget.propTransparent().getValue()) + { // Set most colors to transparent, including the 'arrow' used by MenuButton background = "-fx-background: transparent; -fx-color: transparent; -fx-focus-color: rgba(3,158,211,0.1); -fx-mark-color: transparent; -fx-background-color: transparent;"; + pressed_background = background; + } else - background = JFXUtil.shadedStyle(model_widget.propBackgroundColor().getValue()); + { + final WidgetColor norm = model_widget.propBackgroundColor().getValue(); + // Darker color when pressed + final WidgetColor press = new WidgetColor(norm.getRed()/2, + norm.getGreen()/2, + norm.getBlue()/2, + norm.getAlpha()); + background = JFXUtil.shadedStyle(norm); + pressed_background = JFXUtil.shadedStyle(press); + } } @Override