# HG changeset patch # Parent 5c4df3d3ef9cb8d1a9e333d7258a10ef0912b48a RT-38138: -fx-spacing used wrong in .menubar in modena.css diff -r 5c4df3d3ef9c modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java --- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java Mon Aug 04 16:46:27 2014 -0400 +++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java Tue Aug 05 14:47:37 2014 -0400 @@ -25,19 +25,30 @@ package com.sun.javafx.scene.control.skin; +import com.sun.javafx.css.converters.EnumConverter; +import com.sun.javafx.css.converters.SizeConverter; import com.sun.javafx.scene.traversal.ParentTraversalEngine; import javafx.beans.InvalidationListener; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.WeakChangeListener; +import javafx.beans.value.WritableValue; import javafx.collections.ListChangeListener; import javafx.collections.MapChangeListener; import javafx.collections.ObservableList; +import javafx.css.CssMetaData; +import javafx.css.Styleable; +import javafx.css.StyleableDoubleProperty; +import javafx.css.StyleableObjectProperty; +import javafx.css.StyleableProperty; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.event.WeakEventHandler; import javafx.geometry.Bounds; import javafx.geometry.NodeOrientation; +import javafx.geometry.Pos; import javafx.scene.AccessibleAttribute; import javafx.scene.AccessibleRole; import javafx.scene.Node; @@ -48,6 +59,7 @@ import javafx.scene.control.MenuButton; import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; +import javafx.scene.control.SkinBase; import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyEvent; import javafx.scene.input.MouseEvent; @@ -788,6 +800,81 @@ showPrevMenu(); } */ + private DoubleProperty spacing; + public final void setSpacing(double value) { + spacingProperty().set(snapSpace(value)); + } + + public final double getSpacing() { + return spacing == null ? 0.0 : snapSpace(spacing.get()); + } + + public final DoubleProperty spacingProperty() { + if (spacing == null) { + spacing = new StyleableDoubleProperty() { + + @Override + protected void invalidated() { + final double value = get(); + container.setSpacing(value); + } + + @Override + public Object getBean() { + return MenuBarSkin.this; + } + + @Override + public String getName() { + return "spacing"; + } + + @Override + public CssMetaData getCssMetaData() { + return SPACING; + } + }; + } + return spacing; + } + + private ObjectProperty containerAlignment; + public final void setContainerAlignment(Pos value) { + containerAlignmentProperty().set(value); + } + + public final Pos getContainerAlignment() { + return containerAlignment == null ? Pos.TOP_LEFT : containerAlignment.get(); + } + + public final ObjectProperty containerAlignmentProperty() { + if (containerAlignment == null) { + containerAlignment = new StyleableObjectProperty(Pos.TOP_LEFT) { + + @Override + public void invalidated() { + final Pos value = get(); + container.setAlignment(value); + } + + @Override + public Object getBean() { + return MenuBarSkin.this; + } + + @Override + public String getName() { + return "containerAlignment"; + } + + @Override + public CssMetaData getCssMetaData() { + return ALIGNMENT; + } + }; + } + return containerAlignment; + } @Override public void dispose() { @@ -1055,6 +1142,83 @@ } + /*************************************************************************** + * * + * CSS * + * * + **************************************************************************/ + + private static final CssMetaData SPACING = + new CssMetaData("-fx-spacing", + SizeConverter.getInstance(), 0.0) { + + @Override + public boolean isSettable(MenuBar n) { + final MenuBarSkin skin = (MenuBarSkin) n.getSkin(); + return skin.spacing == null || !skin.spacing.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(MenuBar n) { + final MenuBarSkin skin = (MenuBarSkin) n.getSkin(); + return (StyleableProperty)(WritableValue)skin.spacingProperty(); + } + }; + + private static final CssMetaDataALIGNMENT = + new CssMetaData("-fx-alignment", + new EnumConverter(Pos.class), Pos.TOP_LEFT ) { + + @Override + public boolean isSettable(MenuBar n) { + final MenuBarSkin skin = (MenuBarSkin) n.getSkin(); + return skin.containerAlignment == null || !skin.containerAlignment.isBound(); + } + + @Override + public StyleableProperty getStyleableProperty(MenuBar n) { + final MenuBarSkin skin = (MenuBarSkin) n.getSkin(); + return (StyleableProperty)(WritableValue)skin.containerAlignmentProperty(); + } + }; + + + private static final List> STYLEABLES; + static { + + final List> styleables = + new ArrayList>(SkinBase.getClassCssMetaData()); + + // StackPane also has -fx-alignment. Replace it with + // MenuBarSkin's. + // TODO: Really should be able to reference StackPane.StyleableProperties.ALIGNMENT + final String alignmentProperty = ALIGNMENT.getProperty(); + for (int n=0, nMax=styleables.size(); n prop = styleables.get(n); + if (alignmentProperty.equals(prop.getProperty())) styleables.remove(prop); + } + + styleables.add(SPACING); + styleables.add(ALIGNMENT); + STYLEABLES = Collections.unmodifiableList(styleables); + + } + + /** + * @return The CssMetaData associated with this class, which may include the + * CssMetaData of its super classes. + */ + public static List> getClassCssMetaData() { + return STYLEABLES; + } + + /** + * {@inheritDoc} + */ + @Override + public List> getCssMetaData() { + return getClassCssMetaData(); + } /*************************************************************************** * *