Search in sources :

Example 1 with CircuitState

use of com.cas.sim.tis.app.state.CircuitState in project TeachingInSimulation by ScOrPiOzzy.

the class TypicalCase3D method showPopupMenu.

/**
 * 显示元器件弹出菜单
 * @param def
 */
public void showPopupMenu(ElecCompDef def) {
    ContextMenu menu = null;
    String key = def.getProxy().getUuid();
    if (menus.containsKey(key)) {
        menu = menus.get(key);
    } else {
        MenuItem tag = new MenuItem(MsgUtil.getMessage("button.tag"));
        tag.setOnAction(e -> {
            TextInputDialog steamIdDialog = new TextInputDialog(def.getProxy().getTagName());
            steamIdDialog.setTitle(MsgUtil.getMessage("button.tag"));
            steamIdDialog.setHeaderText(null);
            steamIdDialog.getEditor().textProperty().addListener((b, o, n) -> {
                Pattern pat = Pattern.compile(REGEX_CHINESE);
                Matcher mat = pat.matcher(n);
                if (mat.find()) {
                    steamIdDialog.getEditor().setText(o);
                }
            });
            steamIdDialog.setContentText(MsgUtil.getMessage("typical.case.prompt.input.comp.tag"));
            steamIdDialog.showAndWait().ifPresent(tagName -> {
                def.getProxy().setTagName(tagName);
                CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
                if (state == null) {
                    return;
                }
                state.setTagNameChanged(true);
            });
        });
        MenuItem del = new MenuItem(MsgUtil.getMessage("button.delete"));
        del.setOnAction(e -> {
            CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
            if (state == null) {
                return;
            }
            boolean enable = state.detachFromCircuit(def);
            if (enable) {
                menus.remove(key);
            } else {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.wiring"));
            }
        });
        menu = new ContextMenu(tag, del);
    }
    Point anchor = MouseInfo.getPointerInfo().getLocation();
    menu.show(GUIState.getStage(), anchor.x, anchor.y);
}
Also used : CircuitState(com.cas.sim.tis.app.state.CircuitState) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Point(java.awt.Point) TextInputDialog(javafx.scene.control.TextInputDialog)

Example 2 with CircuitState

use of com.cas.sim.tis.app.state.CircuitState in project TeachingInSimulation by ScOrPiOzzy.

the class TypicalCase3D method showPopupMenu.

public void showPopupMenu(Wire wire) {
    ContextMenu menu = null;
    WireProxy proxy = wire.getProxy();
    String key = String.format("%s%s-%s%s", proxy.getComp1Uuid(), proxy.getTernimal1Id(), proxy.getComp2Uuid(), proxy.getTernimal2Id());
    if (menus.containsKey(key)) {
        menu = menus.get(key);
    } else {
        MenuItem tag = new MenuItem(MsgUtil.getMessage("typical.case.wire.num"));
        tag.setOnAction(e -> {
            TextInputDialog steamIdDialog = new TextInputDialog(proxy.getNumber());
            steamIdDialog.setTitle(MsgUtil.getMessage("typical.case.wire.num"));
            steamIdDialog.setHeaderText(null);
            steamIdDialog.getEditor().textProperty().addListener((b, o, n) -> {
                Pattern pat = Pattern.compile(REGEX_CHINESE);
                Matcher mat = pat.matcher(n);
                if (mat.find()) {
                    steamIdDialog.getEditor().setText(o);
                }
            });
            steamIdDialog.setContentText(MsgUtil.getMessage("typical.case.prompt.input.wire.num"));
            steamIdDialog.showAndWait().ifPresent(number -> {
                wire.getProxy().setNumber(number);
                CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
                if (state == null) {
                    return;
                }
                state.setTagNameChanged(true);
            });
        });
        MenuItem del = new MenuItem(MsgUtil.getMessage("button.delete"));
        del.setOnAction(e -> {
            CircuitState state = jmeApp.getStateManager().getState(CircuitState.class);
            if (state == null) {
                return;
            }
            boolean enable = state.detachFromCircuit(wire);
            if (enable) {
                menus.remove(key);
            } else {
                AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("alert.warning.wiring"));
            }
        });
        menu = new ContextMenu(tag, del);
    }
    Point anchor = MouseInfo.getPointerInfo().getLocation();
    menu.show(GUIState.getStage(), anchor.x, anchor.y);
}
Also used : WireProxy(com.cas.circuit.vo.archive.WireProxy) CircuitState(com.cas.sim.tis.app.state.CircuitState) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Point(java.awt.Point) TextInputDialog(javafx.scene.control.TextInputDialog)

Aggregations

CircuitState (com.cas.sim.tis.app.state.CircuitState)2 Point (java.awt.Point)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ContextMenu (javafx.scene.control.ContextMenu)2 MenuItem (javafx.scene.control.MenuItem)2 TextInputDialog (javafx.scene.control.TextInputDialog)2 WireProxy (com.cas.circuit.vo.archive.WireProxy)1