javafx.scene.control.Control Java Examples

The following examples show how to use javafx.scene.control.Control. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragPopup.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param content
 * 		Popup content.
 * @param handle
 * 		Draggable header control.
 */
public DragPopup(Node content, Control handle) {
	double[] xOffset = {0};
	double[] yOffset = {0};
	handle.getStyleClass().add("drag-popup-header");
	handle.setOnMousePressed(event -> {
		xOffset[0] = event.getSceneX();
		yOffset[0] = event.getSceneY();
	});
	handle.setOnMouseDragged(event -> {
		pop.setX(event.getScreenX() - xOffset[0]);
		pop.setY(event.getScreenY() - yOffset[0]);
	});
	BorderPane wrapper = new BorderPane();
	wrapper.getStyleClass().add("drag-popup-wrapper");
	wrapper.setCenter(content);
	wrapper.setTop(handle);
	wrapper.addEventHandler(MouseEvent.MOUSE_EXITED, e -> pop.hide());
	handle.prefWidthProperty().bind(wrapper.widthProperty());
	pop.getContent().setAll(wrapper);
	pop.setAutoHide(true);
}
 
Example #2
Source File: PropertySheet.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Control getEditorControl(Property pProperty)   
{      
	if( pProperty.get() instanceof String )
	{
		if( extended(pProperty.getName()))
		{
			return createExtendedStringEditor(pProperty);
		}
		else
		{
			return createStringEditor(pProperty);
		}
	}
	else if( pProperty.get() instanceof Enum )
	{
		return createEnumEditor(pProperty);
	}
	else if( pProperty.get() instanceof Boolean)
	{
		return createBooleanEditor(pProperty);
	}
	return null;
}
 
Example #3
Source File: ImageManufactureColorController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }
    if (paletteButton.equals(control)) {
        colorRect.setFill(color);
        FxmlControl.setTooltip(colorRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImageColorSet", color.toString());

    } else if (paletteOriginalButton.equals(control)) {
        originalRect.setFill(color);
        FxmlControl.setTooltip(originalRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImageColorOriginal", color.toString());

    } else if (paletteNewButton.equals(control)) {
        newRect.setFill(color);
        FxmlControl.setTooltip(newRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImageColorNew", color.toString());
    }
    return true;
}
 
Example #4
Source File: ImageManufacturePenController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }

    if (paletteButton.equals(control)) {
        strokeRect.setFill(color);
        FxmlControl.setTooltip(strokeRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImagePenStrokeColor", color.toString());

    } else if (paletteFillButton.equals(control)) {
        fillRect.setFill(color);
        FxmlControl.setTooltip(fillRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImagePenFillColor", color.toString());
    }
    updateMask();
    return true;
}
 
Example #5
Source File: ImageManufactureBatchReplaceColorController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }
    if (paletteOriginalButton.equals(control)) {
        originalRect.setFill(color);
        FxmlControl.setTooltip(originalRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImageColorOriginal", color.toString());

    } else if (paletteNewButton.equals(control)) {
        newRect.setFill(color);
        FxmlControl.setTooltip(newRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImageColorNew", color.toString());
    }
    return true;
}
 
Example #6
Source File: FX.java    From FxDock with Apache License 2.0 6 votes vote down vote up
/** sets a tool tip on the control. */
public static void setTooltip(Control n, Object tooltip)
{
	if(tooltip == null)
	{
		n.setTooltip(null);
	}
	else if(tooltip instanceof Tooltip)
	{
		n.setTooltip((Tooltip)tooltip);
	}
	else
	{
		n.setTooltip(new Tooltip(tooltip.toString()));
	}
}
 
Example #7
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void stateChanged(Control control) {
  TestbedSetting setting = getClientProperty(control, SETTING_TAG);

  switch (setting.constraintType) {
    case BOOLEAN:
      CheckBox box = (CheckBox) control;
      setting.enabled = box.isSelected();
      break;
    case RANGE:
      Slider slider = (Slider) control;
      setting.value = (int) slider.getValue();
      Label label = getClientProperty(slider, LABEL_TAG);
      label.setText(setting.name + ": " + setting.value);
      break;
  }
  model.getPanel().grabFocus();
}
 
Example #8
Source File: PropertySheet.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Control createEnumEditor(Property pProperty)
{
	Enum<?> value = (Enum<?>)pProperty.get();
	try 
	{
		Enum<?>[] enumValues = (Enum<?>[])value.getClass().getMethod("values").invoke(null);
		final ComboBox<Enum<?>> comboBox = new ComboBox<>(FXCollections.observableArrayList(enumValues));
		
		comboBox.getSelectionModel().select(value);
		comboBox.valueProperty().addListener((pObservable, pOldValue, pNewValue) -> 
		{
			pProperty.set(pNewValue.toString());
			aListener.propertyChanged();
		});
	
		return comboBox;
	}
	catch(NoSuchMethodException | InvocationTargetException | IllegalAccessException e) 
	{ 
		return null; 
	}
}
 
Example #9
Source File: SearchBoxSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public SearchBox() {
    setId("SearchBox");
    getStyleClass().add("search-box");
    setMinHeight(24);
    setPrefSize(200, 24);
    setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
    textBox = new TextField();
    textBox.setPromptText("Search");
    clearButton = new Button();
    clearButton.setVisible(false);
    getChildren().addAll(textBox, clearButton);
    clearButton.setOnAction(new EventHandler<ActionEvent>() {                
        @Override public void handle(ActionEvent actionEvent) {
            textBox.setText("");
            textBox.requestFocus();
        }
    });
    textBox.textProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            clearButton.setVisible(textBox.getText().length() != 0);
        }
    });
}
 
Example #10
Source File: SearchBoxSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public SearchBox() {
    setId("SearchBox");
    getStyleClass().add("search-box");
    setMinHeight(24);
    setPrefSize(200, 24);
    setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
    textBox = new TextField();
    textBox.setPromptText("Search");
    clearButton = new Button();
    clearButton.setVisible(false);
    getChildren().addAll(textBox, clearButton);
    clearButton.setOnAction(new EventHandler<ActionEvent>() {                
        @Override public void handle(ActionEvent actionEvent) {
            textBox.setText("");
            textBox.requestFocus();
        }
    });
    textBox.textProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            clearButton.setVisible(textBox.getText().length() != 0);
        }
    });
}
 
Example #11
Source File: JFXHelper.java    From Schillsaver with MIT License 6 votes vote down vote up
/**
 * Creates a GridPane with only one column, but where there are as many rows as there are controls passed
 * to the function.
 *
 * Ex:
 *      If you pass in two controls, then there will be one column with two rows where each row uses 50%
 *      of the height.
 *
 * Ex:
 *      If you pass in four controls, then there will be one column with four rows where each row uses 25%
 *      of the height.
 *
 * @param controls
 *          The controls.
 *
 * @return
 *          The pane.
 */
public static GridPane createVerticalGridPane(final Control... controls) {
    if (controls.length == 0) {
        return new GridPane();
    }

    final GridPane pane = new GridPane();
    final double sectionHeight = 100.0 / controls.length;

    for (final Control ignored : controls) {
        final RowConstraints constraints = new RowConstraints();
        constraints.setPercentHeight(sectionHeight);

        pane.getRowConstraints().add(constraints);
    }

    for (int i = 0 ; i < controls.length ; i++) {
        pane.add(controls[i], 0, i);
    }

    return pane;
}
 
Example #12
Source File: BaseController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public void showPalette(Control control, String title, boolean pickColor) {
    if (paletteController == null || !paletteController.getMyStage().isShowing()) {
        paletteController = (ColorPaletteController) openStage(CommonValues.ColorPaletteFxml);
    }
    paletteController.init(this, control, title, pickColor);

}
 
Example #13
Source File: ImageManufactureCropController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }
    if (paletteButton.equals(control)) {
        bgRect.setFill(color);
        FxmlControl.setTooltip(bgRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("CropBackgroundColor", color.toString());
    }
    return true;
}
 
Example #14
Source File: ImagesCombineController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }
    if (paletteButton.equals(control)) {
        bgRect.setFill(color);
        FxmlControl.setTooltip(bgRect, FxmlColor.colorNameDisplay(color));
        AppVariables.setUserConfigValue("ImagesCombineBackgroundColor", color.toString());

        imageCombine.setBgColor(color);
        combineImages();
    }
    return true;
}
 
Example #15
Source File: ControlUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Make a list cell never overflow the width of its container, to
 * avoid having a horizontal scroll bar showing up. This defers
 * resizing constraints to the contents of the cell.
 *
 * @return The given cell
 */
public static <T> ListCell<T> makeListCellFitListViewWidth(ListCell<T> cell) {
    if (cell != null) {
        cell.prefWidthProperty().bind(
            Val.wrap(cell.listViewProperty())
               .flatMap(Region::widthProperty).map(it -> it.doubleValue() - 5)
               .orElseConst(0.)
        );
        cell.setMaxWidth(Control.USE_PREF_SIZE);
    }
    return cell;
}
 
Example #16
Source File: Story.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/** @return content wrapped in a vertical, pannable scroll pane. */
private ScrollPane makeScrollable(final Control content) {
  final ScrollPane scroll = new ScrollPane();
  scroll.setContent(content);
  scroll.setPannable(true);
  scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
  scroll.viewportBoundsProperty().addListener(new ChangeListener<Bounds>() {
    @Override public void changed(ObservableValue<? extends Bounds> observableValue, Bounds oldBounds, Bounds newBounds) {
      content.setPrefWidth(newBounds.getWidth() - 10);
    }
  });

  return scroll;
}
 
Example #17
Source File: ProgressIndicatorTest2.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    StackPane root = new StackPane();
    ProgressIndicator pi = new ProgressIndicator();
    Task<Void> counter = new Task<Void>() {
        @Override
        public Void call() throws Exception {
            for (int i = 1; i <= 100; i++) {
                Thread.sleep(50);
                updateProgress(i, 100);
            }
            return null;
        }
    };
    pi.progressProperty().bind(counter.progressProperty());
    pi.progressProperty().addListener((obs, oldProgress, newProgress) -> {
        PseudoClass warning = PseudoClass.getPseudoClass("warning");
        PseudoClass critical = PseudoClass.getPseudoClass("critical");
        if (newProgress.doubleValue() < 0.3) {
            pi.pseudoClassStateChanged(warning, false);
            pi.pseudoClassStateChanged(critical, true);
        } else if (newProgress.doubleValue() < 0.65) {
            pi.pseudoClassStateChanged(warning, true);
            pi.pseudoClassStateChanged(critical, false);
        } else {
            pi.pseudoClassStateChanged(warning, false);
            pi.pseudoClassStateChanged(critical, false);
        }
    });
    pi.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
    root.setStyle("-fx-background-color: antiqueWhite;");
    root.getChildren().add(pi);
    Scene scene = new Scene(root, 400, 400);
    scene.getStylesheets().add("/css/progress.css");
    primaryStage.setScene(scene);
    primaryStage.show();
    new Thread(counter).start();
}
 
Example #18
Source File: SimpleControl.java    From PreferencesFX with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the error message as tooltip for the matching control and shows
 * them below the same control.
 *
 * @param reference The control which gets the tooltip.
 */
@Override
protected void toggleTooltip(Node reference) {
  if (reference instanceof Control) {
    this.toggleTooltip(reference, (Control) reference);
  }
}
 
Example #19
Source File: PropertySheet.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private Control createBooleanEditor(Property pProperty)
{
	CheckBox checkBox = new CheckBox();
	checkBox.setSelected((boolean)pProperty.get());
	checkBox.selectedProperty().addListener((pObservable, pOldValue, pNewValue) -> 
	{
		pProperty.set(pNewValue);
		aListener.propertyChanged();
	});

	return checkBox;
}
 
Example #20
Source File: SearchBoxSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public SearchBoxSample() {
    String searchBoxCss = SearchBoxSample.class.getResource("SearchBox.css").toExternalForm();
    VBox vbox = VBoxBuilder.create().build();
    vbox.getStylesheets().add(searchBoxCss);
    vbox.setPrefWidth(200);
    vbox.setMaxWidth(Control.USE_PREF_SIZE);
    vbox.getChildren().add(new SearchBox());
    getChildren().add(vbox);
}
 
Example #21
Source File: SVRealNodeAdapter.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public SVRealNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls) {
    super(ConnectorUtils.nodeClass(node), node.getClass().getName());
    this.node = node;
    this.collapseControls = collapseControls;
    this.collapseContentControls = collapseContentControls;
    boolean mustBeExpanded = !(node instanceof Control) || !collapseControls;
    if (!mustBeExpanded && !collapseContentControls) {
        mustBeExpanded = node instanceof TabPane || node instanceof SplitPane || node instanceof ScrollPane || node instanceof Accordion || node instanceof TitledPane;
    }
    setExpanded(mustBeExpanded);
}
 
Example #22
Source File: BigDecimalFieldSkin.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) {
    super.layoutChildren(contentX, contentY, contentWidth, contentHeight); //To change body of generated methods, choose Tools | Templates.
    Insets insets = getSkinnable().getInsets();
    double x = insets.getLeft();
    double y = insets.getTop();
    double textfieldHeight = contentHeight;
    double buttonWidth = textField.prefHeight(-1);
    Insets buttonInsets = btnDown.getInsets();
    double textfieldWidth = this.getSkinnable().getWidth()-insets.getLeft()-insets.getRight() - buttonWidth - buttonInsets.getLeft() - buttonInsets.getRight();
    layoutInArea(textField, x, y, textfieldWidth, textfieldHeight, Control.USE_PREF_SIZE, HPos.LEFT, VPos.TOP);
    layoutInArea(btnUp, x+textfieldWidth+buttonInsets.getLeft(), y, buttonWidth, textfieldHeight/2, Control.USE_PREF_SIZE, HPos.LEFT, VPos.TOP);
    layoutInArea(btnDown, x+textfieldWidth+buttonInsets.getLeft(), y+textfieldHeight/2, buttonWidth, textfieldHeight/2, Control.USE_PREF_SIZE, HPos.LEFT, VPos.TOP);
}
 
Example #23
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void putClientProperty(Control control, String tag, Object o) {
  Map<String, Object> map = (Map<String, Object>) control.getUserData();
  if (map == null) {
    map = new HashMap<>();
    control.setUserData(map);
  }
  map.put(tag, o);
}
 
Example #24
Source File: TextUpdateRepresentation.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Control createJFXNode() throws Exception
{   // Start out 'disconnected' until first value arrives
    value_text = computeText(null);

    if (model_widget.propInteractive().getValue()  &&  !toolkit.isEditMode())
    {
        final TextArea area = new TextArea();
        area.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
        area.setEditable(false);
        area.getStyleClass().add("text_entry");
        area.setWrapText(true);
        // 'Interactive' widget needs to react to selection,
        // and as remarked in TextEntry this works best 'managed'
        area.setManaged(true);
        return area;
    }
    else
    {
        final Label label = new Label();
        label.getStyleClass().add("text_update");

        // This code manages layout,
        // because otherwise for example border changes would trigger
        // expensive Node.notifyParentOfBoundsChange() recursing up the scene graph
        label.setManaged(false);

        return label;
    }
}
 
Example #25
Source File: FilterFocusManager.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private static Control findNextFilter() {
    // if we know about a filter control that was focused last but does not currently
    // have focus then return to it. The filter must be visible and attached to the scene.
    if(lastFocusedIndex != -1) {
        Control lastFocused = FILTERS.get(lastFocusedIndex);
        if(!lastFocused.isFocused() && lastFocused.isVisible() && lastFocused.getScene() != null) {
            return lastFocused;
        }
    }

    int focused = findCurrentFilter();

    if(focused == -1) {
        focused = 0;
    }
    // iterate the filters until we find one that is part of the scene or we run out of filters
    int iterations = 0;
    while(iterations < FILTERS.size()) {
        iterations++;
        focused++;
        if(focused >= FILTERS.size()) {
            focused = 0;
        }
        boolean isFocusable = FILTERS.get(focused).getScene() != null;
        if(isFocusable)
            break;
    }
    return FILTERS.get(focused);
}
 
Example #26
Source File: ValidatorBase.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private void install(Node node, Tooltip oldVal, Tooltip newVal) {
    // stash old tooltip if it's not error tooltip
    if (oldVal != null && !oldVal.getStyleClass().contains(ERROR_TOOLTIP_STYLE_CLASS)) {
        node.getProperties().put(TEMP_TOOLTIP_KEY, oldVal);
    }
    if (node instanceof Control) {
        // uninstall
        if (oldVal != null) {
            if (oldVal instanceof JFXTooltip) {
                JFXTooltip.uninstall(node);
            }
            if (newVal == null || !(newVal instanceof JFXTooltip)) {
                ((Control) node).setTooltip(newVal);
                return;
            }
            if (newVal instanceof JFXTooltip) {
                ((Control) node).setTooltip(null);
            }
        }
        // install
        if (newVal instanceof JFXTooltip) {
            install(node, newVal);
        } else {
            ((Control) node).setTooltip(newVal);
        }
    } else {
        uninstall(node, oldVal);
        install(node, newVal);
    }
}
 
Example #27
Source File: SplitDock.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Create a split section
 *  @param dock_parent {@link BorderPane} of {@link SplitDock}
 *  @param horizontally Horizontal?
 *  @param first Top or left item
 *  @param second Bottom or right item
 */
public SplitDock(final Parent dock_parent, final boolean horizontally, final Control first, final Control second)
{
    this.dock_parent = dock_parent;
    if (! horizontally)
        setOrientation(Orientation.VERTICAL);

    if (! ((first instanceof SplitDock) || (first instanceof DockPane)))
        throw new IllegalArgumentException("Expect DockPane or another nested SplitDock, got " + first.getClass().getName());
    if (! ((second instanceof SplitDock) || (second instanceof DockPane)))
        throw new IllegalArgumentException("Expect DockPane or another nested SplitDock, got " + first.getClass().getName());

    getItems().setAll(first, second);
}
 
Example #28
Source File: ParameterEditorFactory.java    From old-mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
private void addValidator(ValidationSupport validationSupport, Parameter<?> p,
    ParameterEditor<?> pe) {

  ParameterValidator pv = p.getValidator();
  if (pv == null)
    return;

  Control mainControl = pe.getMainControl();
  if (mainControl == null)
    return;

  if (mainControl != null && pv != null) {

    // Create the official validator
    Validator<?> validator = (control, value) -> {
      ValidationResult result = new ValidationResult();
      Object currentVal = pe.getValue();
      List<String> errors = new ArrayList<>();
      if (pv.checkValue(currentVal, errors))
        return result;
      // IF no message was produced, add our own message
      if (errors.isEmpty())
        errors.add(p.getName() + " is not set properly");
      // Copy the messages to the result
      for (String er : errors) {
        String m = p.getName() + ": " + er;
        ValidationMessage msg = ValidationMessage.error(control, m);
        result.add(msg);
      }
      return result;
    };

    // Register the validator
    validationSupport.registerValidator(mainControl, false, validator);

  }
}
 
Example #29
Source File: ControlUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Add a hook on the owner window. It's not possible to do this statically,
 * since at construction time the window might not be set.
 */
public static void subscribeOnSkin(Control node,
                                   Function<Skin<?>, Subscription> hook) {
    ReactfxExtensions.dynamic(
        LiveList.wrapVal(node.skinProperty()),
        (w, i) -> hook.apply(w)
    );
}
 
Example #30
Source File: TextValidatorSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ValidatorPane() {
    content.addListener(new ChangeListener<Control>() {
        public void changed(ObservableValue<? extends Control> ov, Control oldValue, Control newValue) {
            if (oldValue != null) getChildren().remove(oldValue);
            if (newValue != null) getChildren().add(0, newValue);
        }
    });
}