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);
}
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);
}
Aggregations