Search in sources :

Example 11 with Toggle

use of javafx.scene.control.Toggle in project financial by greatkendy123.

the class MyController method initAutoTestMode.

/**
 * 启动测试模式
 *
 * @time 2017年11月11日
 */
private void initAutoTestMode() {
    hbox_autoTestMode.setVisible(false);
    ToggleGroup group = new ToggleGroup();
    radio_autoTest_yes.setToggleGroup(group);
    radio_autoTest_no.setToggleGroup(group);
    radio_autoTest_yes.setUserData("是");
    radio_autoTest_no.setUserData("否");
    radio_autoTest_no.setSelected(true);
    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {

        public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
            String autoTestMode = (String) group.getSelectedToggle().getUserData();
            if ("是".equals(autoTestMode)) {
                hbox_autoTestMode.setVisible(true);
            } else {
                hbox_autoTestMode.setVisible(false);
            }
        }
    });
}
Also used : ToggleGroup(javafx.scene.control.ToggleGroup) Toggle(javafx.scene.control.Toggle)

Example 12 with Toggle

use of javafx.scene.control.Toggle in project POL-POM-5 by PhoenicisOrg.

the class SidebarToggleGroupBehavior method selectFirstToggleButton.

/**
 * Ensures, that always a button is selected:
 * - if because of an invalidation of the input list the selection is lost, the selection is reapplied
 * - if no button is selected, select the first button
 */
private void selectFirstToggleButton() {
    final ToggleGroup toggleGroup = getSkin().getToggleGroup();
    if (toggleGroup.getSelectedToggle() == null && !toggleGroup.getToggles().isEmpty()) {
        final E selectedElement = getControl().selectedElementProperty().getValue();
        if (selectedElement != null && getControl().getElements().contains(selectedElement)) {
            // 1 if an "all" button exists, 0 otherwise
            final int offset = toggleGroup.getToggles().size() - getControl().getElements().size();
            final int index = getControl().getElements().indexOf(getControl().selectedElementProperty().getValue());
            // reselect the previously selected item
            toggleGroup.selectToggle(toggleGroup.getToggles().get(offset + index));
        } else {
            final Toggle firstToggle = toggleGroup.getToggles().get(0);
            // trigger the first item in the toggle group
            if (firstToggle instanceof ToggleButton) {
                ((ToggleButton) firstToggle).fire();
            }
        }
    }
}
Also used : ToggleButton(javafx.scene.control.ToggleButton) ToggleGroup(javafx.scene.control.ToggleGroup) Toggle(javafx.scene.control.Toggle)

Aggregations

Toggle (javafx.scene.control.Toggle)12 ToggleGroup (javafx.scene.control.ToggleGroup)5 ToggleButton (javafx.scene.control.ToggleButton)3 File (java.io.File)2 IOException (java.io.IOException)2 QuestionAction (com.cas.sim.tis.action.QuestionAction)1 Question (com.cas.sim.tis.entity.Question)1 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)1 FxPostInitialize (com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize)1 ResourceLoader (com.kyj.fx.voeditor.visual.momory.ResourceLoader)1 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)1 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)1 RuntimeException (com.sun.star.uno.RuntimeException)1 Closeable (java.io.Closeable)1 FileInputStream (java.io.FileInputStream)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 Charset (java.nio.charset.Charset)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 ArrayList (java.util.ArrayList)1