package bluej.editor.moe;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.IntegerBinding;
import javafx.beans.binding.ObjectExpression;
import javafx.scene.Node;
import javafx.scene.control.Slider;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.util.StringConverter;

import bluej.Config;
import bluej.prefmgr.PrefMgr;
import bluej.utility.javafx.JavaFXUtil;
import threadchecker.OnThread;
import threadchecker.Tag;


| A manager for the components used to manipulate the scope highlighting strength | preference. | | @author Marion Zalk | @OnThread(Tag.FXPlatform) public class ScopeHighlightingPrefDisplay { public static final int MIN=0; public static final int MAX=20; Slider slider; ScopeColorsBorderPane colorPanel;
| Constructor that sets up the look and feel for the scope highlighting color slider | and the panel displaying the affects of changing the value of the slider | public ScopeHighlightingPrefDisplay() { slider=new Slider(MIN, MAX, PrefMgr.getScopeHighlightStrength().get()); slider.setMajorTickUnit(MAX - MIN); slider.setShowTickLabels(true); slider.setShowTickMarks(true); slider.setLabelFormatter(new StringConverter<Double>() { @Override public String toString(Double d) { if (d == MIN) return Config.getString("prefmgr.edit.highlightLighter"); else if (d == MAX) return Config.getString("prefmgr.edit.highlightDarker"); else{ return ""; } } @Override public Double fromString(String string) { return null; } }); } colorPanel = new ScopeColorsBorderPane(); colorPanel.setBackground(new Background(new BackgroundFill(colorPanel.scopeBackgroundColorProperty().get(), null, null))); JavaFXUtil.addChangeListener(colorPanel.scopeBackgroundColorProperty(), bkColor -> { colorPanel.setBackground(new Background(new BackgroundFill(bkColor, null, null))); }); JavaFXUtil.addStyleClass(colorPanel, "prefmgr-scope-colour-container"); VBox inner = JavaFXUtil.withStyleClass(new VBox(), "prefmgr-scope-colour-rectangles"); inner.getChildren().addAll( makeRectangle(colorPanel.scopeClassColorProperty(), colorPanel.scopeClassOuterColorProperty()), makeRectangle(colorPanel.scopeMethodColorProperty(), colorPanel.scopeMethodOuterColorProperty()), makeRectangle(colorPanel.scopeIterationColorProperty(), colorPanel.scopeIterationOuterColorProperty()), makeRectangle(colorPanel.scopeSelectionColorProperty(), colorPanel.scopeSelectionOuterColorProperty()) ); colorPanel.setCenter(inner); } } private Rectangle makeRectangle(ObjectExpression<Color> body, ObjectExpression<Color> border) { Rectangle r = new Rectangle(100, 20); IntegerBinding sliderValue = Bindings.createIntegerBinding(this::getStrengthValue, slider.valueProperty()); r.fillProperty().bind(colorPanel.getReducedColor(body, sliderValue)); r.strokeProperty().bind(colorPanel.getReducedColor(border, sliderValue)); return r; }
| Returns the highlighter slider | protected Node getHighlightStrengthSlider() { return slider; }
| Returns the color palette | protected Node getColourPalette() { return colorPanel; }
| The value of the slider | protected int getStrengthValue() { return (int)Math.round(slider.getValue()); } }
top, use, map, class ScopeHighlightingPrefDisplay

.   ScopeHighlightingPrefDisplay
.   toString
.   fromString
.   makeRectangle
.   getHighlightStrengthSlider
.   getColourPalette
.   getStrengthValue




130 neLoCode + 8 LoComm