Skip to content

Commit ee1e782

Browse files
committed
Action button: Darker background when pressed
1 parent 5dface5 commit ee1e782

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ActionButtonRepresentation.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015-2020 Oak Ridge National Laboratory.
2+
* Copyright (c) 2015-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -23,6 +23,7 @@
2323
import org.csstudio.display.builder.model.properties.OpenDisplayActionInfo;
2424
import org.csstudio.display.builder.model.properties.RotationStep;
2525
import org.csstudio.display.builder.model.properties.StringWidgetProperty;
26+
import org.csstudio.display.builder.model.properties.WidgetColor;
2627
import org.csstudio.display.builder.model.properties.WritePVActionInfo;
2728
import org.csstudio.display.builder.model.widgets.ActionButtonWidget;
2829
import org.csstudio.display.builder.representation.javafx.Cursors;
@@ -36,6 +37,7 @@
3637
import org.phoebus.ui.vtype.FormatOptionHandler;
3738

3839
import javafx.application.Platform;
40+
import javafx.event.EventHandler;
3941
import javafx.geometry.Dimension2D;
4042
import javafx.scene.Cursor;
4143
import javafx.scene.control.Button;
@@ -76,7 +78,7 @@ public class ActionButtonRepresentation extends RegionBaseRepresentation<Pane, A
7678
private final DirtyFlag dirty_actionls = new DirtyFlag();
7779

7880
private volatile ButtonBase base;
79-
private volatile String background;
81+
private volatile String background, pressed_background;
8082
private volatile Color foreground;
8183
private volatile String button_text;
8284
private volatile boolean enabled = true;
@@ -135,6 +137,9 @@ private void checkModifiers(final MouseEvent event)
135137
return;
136138
}
137139

140+
// Indicate that button is pressed
141+
base.setStyle(pressed_background);
142+
138143
// 'control' ('command' on Mac OS X)
139144
if (event.isShortcutDown())
140145
target_modifier = Optional.of(OpenDisplayActionInfo.Target.TAB);
@@ -211,7 +216,13 @@ private ButtonBase makeBaseButton()
211216
// Monitor keys that modify the OpenDisplayActionInfo.Target.
212217
// Use filter to capture event that's otherwise already handled.
213218
if (! toolkit.isEditMode())
219+
{
220+
// Pressed button will use pressed_background, check modifiers, then invoke actions
214221
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+
}
215226

216227
// Need to attach TT to the specific button, not the common jfx_node Pane
217228
TooltipSupport.attach(result, model_widget.propTooltip());
@@ -323,7 +334,7 @@ private void handleActions(final List<ActionInfo> actions)
323334
/** @param action Action that the user invoked */
324335
private void handleAction(ActionInfo action)
325336
{
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
327338
if (! enabled)
328339
return;
329340

@@ -428,10 +439,22 @@ private void updateColors()
428439
{
429440
foreground = JFXUtil.convert(model_widget.propForegroundColor().getValue());
430441
if (model_widget.propTransparent().getValue())
442+
{
431443
// Set most colors to transparent, including the 'arrow' used by MenuButton
432444
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+
}
433447
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+
}
435458
}
436459

437460
@Override

0 commit comments

Comments
 (0)