Skip to content

Commit f888337

Browse files
committed
Simpler button coloring which does give 'armed' and 'pressed' feedback
.. because it only updates the -fx-base and keeps the other -fx-..-border settings
1 parent ee1e782 commit f888337

File tree

2 files changed

+20
-52
lines changed

2 files changed

+20
-52
lines changed

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,41 +94,32 @@ public static StringBuilder appendWebRGB(final StringBuilder buf, final WidgetCo
9494

9595
/** Convert model color into CSS style string for shading tabs, buttons, etc
9696
* @param color {@link WidgetColor}
97-
* @return style string of the form "-fx-color: ... -fx-outer-border: ... -fx-inner-border: ... -fx-background: ..."
97+
* @return style string of the form "-fx-base: ..;"
9898
*/
9999
public static String shadedStyle(final WidgetColor color)
100100
{
101101
return shadedStyleCache.computeIfAbsent(color, col ->
102102
{
103103
// How to best set colors?
104-
// Content Pane can be set in API, but Tab has no usable 'set color' API.
104+
// Content Pane can be set in API, but Button and Tab have no usable 'set color' API.
105105
// TabPane has setBackground(), but in "floating" style that would be
106106
// the background behind the tabs, which is usually transparent.
107-
// modena.css of JDK8 reveals a structure of sub-items which are shaded with gradients based
108-
// on -fx-color for the inactive tabs,
109-
// -fx-outer-border and -fx-inner-border for the, well, border,
110-
// and -fx-background for the selected tab,
111-
// so re-define those.
107+
//
108+
// Adjusting the style can break when the underlying style sheet changes,
109+
// but since at least JDK8 that has been modena.css with little changes until JFX 18,
110+
// which can be found in javafx-controls-18-linux.jar as
111+
// com/sun/javafx/scene/control/skin/modena/modena.css
112+
//
113+
// Buttons use nested -fx-background-color entries
114+
// -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color
115+
// with associated ..-insets and ..-radius which are all based on -fx-base,
116+
// so redefine that to adjust the overall color.
117+
// The .button.armed state uses
118+
// -fx-pressed-base: derive(-fx-base,-6%);
119+
// which we change into a more obvious variant.
112120
final String bg = webRGB(col);
113-
return "-fx-color: derive(" + bg + ", 50%);" +
114-
"-fx-outer-border: derive(" + bg + ", -23%);" +
115-
"-fx-inner-border: linear-gradient(to bottom," +
116-
"ladder(" + bg + "," +
117-
" derive(" + bg + ",30%) 0%," +
118-
" derive(" + bg + ",20%) 40%," +
119-
" derive(" + bg + ",25%) 60%," +
120-
" derive(" + bg + ",55%) 80%," +
121-
" derive(" + bg + ",55%) 90%," +
122-
" derive(" + bg + ",75%) 100%" +
123-
")," +
124-
"ladder(" + bg + "," +
125-
" derive(" + bg + ",20%) 0%," +
126-
" derive(" + bg + ",10%) 20%," +
127-
" derive(" + bg + ",5%) 40%," +
128-
" derive(" + bg + ",-2%) 60%," +
129-
" derive(" + bg + ",-5%) 100%" +
130-
"));" +
131-
"-fx-background: " + bg + ";";
121+
return "-fx-base: " + bg + "; " +
122+
"-fx-pressed-base: derive(-fx-base,-25%);";
132123
});
133124
}
134125

@@ -217,7 +208,7 @@ public static Pos computePos(final HorizontalAlignment horiz, final VerticalAlig
217208
}
218209

219210
/**returns double[] array for given line style scaled by line_width
220-
*
211+
*
221212
* @param style - actual line style
222213
* @param line_width - actual line width
223214
* @return double[] with segment lengths

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

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
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;
2726
import org.csstudio.display.builder.model.properties.WritePVActionInfo;
2827
import org.csstudio.display.builder.model.widgets.ActionButtonWidget;
2928
import org.csstudio.display.builder.representation.javafx.Cursors;
@@ -37,7 +36,6 @@
3736
import org.phoebus.ui.vtype.FormatOptionHandler;
3837

3938
import javafx.application.Platform;
40-
import javafx.event.EventHandler;
4139
import javafx.geometry.Dimension2D;
4240
import javafx.scene.Cursor;
4341
import javafx.scene.control.Button;
@@ -78,7 +76,7 @@ public class ActionButtonRepresentation extends RegionBaseRepresentation<Pane, A
7876
private final DirtyFlag dirty_actionls = new DirtyFlag();
7977

8078
private volatile ButtonBase base;
81-
private volatile String background, pressed_background;
79+
private volatile String background;
8280
private volatile Color foreground;
8381
private volatile String button_text;
8482
private volatile boolean enabled = true;
@@ -137,9 +135,6 @@ private void checkModifiers(final MouseEvent event)
137135
return;
138136
}
139137

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

227216
// Need to attach TT to the specific button, not the common jfx_node Pane
228217
TooltipSupport.attach(result, model_widget.propTooltip());
@@ -439,22 +428,10 @@ private void updateColors()
439428
{
440429
foreground = JFXUtil.convert(model_widget.propForegroundColor().getValue());
441430
if (model_widget.propTransparent().getValue())
442-
{
443431
// Set most colors to transparent, including the 'arrow' used by MenuButton
444432
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-
}
447433
else
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-
}
434+
background = JFXUtil.shadedStyle(model_widget.propBackgroundColor().getValue());
458435
}
459436

460437
@Override

0 commit comments

Comments
 (0)