Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: text alignment in Spinner widget #2339

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@
*******************************************************************************/
package org.csstudio.display.builder.model.widgets;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propBackgroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propEnabled;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFont;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propForegroundColor;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propFormat;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propIncrement;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propLimitsFromPV;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMaximum;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMinimum;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propPrecision;
import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propShowUnits;

import java.util.Arrays;
import java.util.List;

Expand All @@ -35,11 +23,11 @@
import org.csstudio.display.builder.model.persist.NamedWidgetFonts;
import org.csstudio.display.builder.model.persist.WidgetColorService;
import org.csstudio.display.builder.model.persist.WidgetFontService;
import org.csstudio.display.builder.model.properties.CommonWidgetProperties;
import org.csstudio.display.builder.model.properties.WidgetColor;
import org.csstudio.display.builder.model.properties.WidgetFont;
import org.csstudio.display.builder.model.properties.*;
import org.phoebus.ui.vtype.FormatOption;

import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.*;

/** Widget that represents a spinner
* @author Amanda Carpenter
*/
Expand Down Expand Up @@ -79,6 +67,8 @@ public Widget createWidget()
private volatile WidgetProperty<Boolean> buttons_on_left;
private volatile WidgetProperty<Boolean> enabled;
private volatile WidgetProperty<WidgetFont> font;
private volatile WidgetProperty<HorizontalAlignment> horizontal_alignment;
private volatile WidgetProperty<VerticalAlignment> vertical_alignment;

/** Constructor */
public SpinnerWidget()
Expand All @@ -102,6 +92,8 @@ protected void defineProperties(final List<WidgetProperty<?>> properties)
properties.add(increment = propIncrement.createProperty(this, 1.0));
properties.add(buttons_on_left = propButtonsOnLeft.createProperty(this, false));
properties.add(enabled = propEnabled.createProperty(this, true));
properties.add(horizontal_alignment = propHorizontalAlignment.createProperty(this, HorizontalAlignment.LEFT));
properties.add(vertical_alignment = propVerticalAlignment.createProperty(this, VerticalAlignment.TOP));
}

@Override
Expand Down Expand Up @@ -181,4 +173,17 @@ public WidgetProperty<WidgetFont> propFont()
{
return font;
}

/** @return 'horizontal_alignment' property */
public WidgetProperty<HorizontalAlignment> propHorizontalAlignment()
{
return horizontal_alignment;
}

/** @return 'vertical_alignment' property */
public WidgetProperty<VerticalAlignment> propVerticalAlignment()
{
return vertical_alignment;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.logging.Level;

import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import org.csstudio.display.builder.model.DirtyFlag;
import org.csstudio.display.builder.model.UntypedWidgetPropertyListener;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class SpinnerRepresentation extends RegionBaseRepresentation<Spinner<Stri
protected volatile VType value = null;
private volatile double value_max = 100.0;
private volatile double value_min = 0.0;
private volatile Pos pos;

private static WidgetColor active_color = WidgetColorService.getColor(NamedWidgetColors.ACTIVE_TEXT);

Expand Down Expand Up @@ -377,13 +379,17 @@ private String computeText(final VType value)
protected void registerListeners()
{
super.registerListeners();
pos = JFXUtil.computePos(model_widget.propHorizontalAlignment().getValue(),
model_widget.propVerticalAlignment().getValue());
model_widget.propWidth().addUntypedPropertyListener(styleListener);
model_widget.propHeight().addUntypedPropertyListener(styleListener);
model_widget.propButtonsOnLeft().addUntypedPropertyListener(styleListener);

model_widget.propForegroundColor().addUntypedPropertyListener(styleListener);
model_widget.propBackgroundColor().addUntypedPropertyListener(styleListener);
model_widget.propFont().addUntypedPropertyListener(styleListener);
model_widget.propHorizontalAlignment().addUntypedPropertyListener(styleListener);
model_widget.propVerticalAlignment().addUntypedPropertyListener(styleListener);
model_widget.propEnabled().addUntypedPropertyListener(styleListener);
model_widget.runtimePropPVWritable().addUntypedPropertyListener(styleListener);

Expand Down Expand Up @@ -434,6 +440,8 @@ protected boolean isFilteringEditModeClicks()

private void styleChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value)
{
pos = JFXUtil.computePos(model_widget.propHorizontalAlignment().getValue(),
model_widget.propVerticalAlignment().getValue());
dirty_style.mark();
toolkit.scheduleUpdate(this);
}
Expand Down Expand Up @@ -491,6 +499,7 @@ public void updateChanges()
JFXUtil.appendWebRGB(style, back_color).append(";");

jfx_node.editorProperty().getValue().setStyle(style.toString());
jfx_node.editorProperty().getValue().setAlignment(pos);
jfx_node.resize(model_widget.propWidth().getValue(), model_widget.propHeight().getValue());

// Enable if enabled by user and there's write access
Expand Down