use of javafx.scene.Node in project trex-stateless-gui by cisco-system-traffic-generator.
the class StatsTableGenerator method generateXStatPane.
public GridPane generateXStatPane(boolean full, Port port, boolean notempty, String filter, boolean resetCounters) {
if (full) {
statXTable.getChildren().clear();
Util.optimizeMemory();
}
Map<String, Long> xstatsList = port.getXstats();
Map<String, Long> xstatsListPinned = port.getXstatsPinned();
String pinnedChar = "✖";
String notPinnedChar = "✚";
/*String pinnedChar = "☑";
String notPinnedChar = "☐";*/
rowIndex = 0;
addHeaderCell(statXTable, "xstats-header0", "Counter", 0, WIDTH_COL_0 * 1.5);
addHeaderCell(statXTable, "xstats-header1", "Value", 1, WIDTH_COL_1);
addHeaderCell(statXTable, "xstats-header2", "Pin", 2, WIDTH_COL_PIN);
rowIndex = 1;
odd = true;
xstatsListPinned.forEach((k, v) -> {
if (v != null) {
if (resetCounters) {
fixCounter(port.getIndex(), k, v);
}
Node check = new Label(pinnedChar);
GridPane.setHalignment(check, HPos.CENTER);
addXstatRow(statXTable, (event) -> xstatsListPinned.remove(k, v), "xstat-red", "xstat-green", new Tooltip("Click '" + pinnedChar + "' to un-pin the counter."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, pinnedChar, WIDTH_COL_PIN, 2);
}
});
xstatsList.forEach((k, v) -> {
if (v != null && (!notempty || (notempty && (v - getShadowCounter(port.getIndex(), k) != 0))) && xstatsListPinned.get(k) == null) {
if ((filter == null || filter.trim().length() == 0) || k.contains(filter)) {
if (resetCounters) {
fixCounter(port.getIndex(), k, v);
}
Node check = new Label(notPinnedChar);
GridPane.setHalignment(check, HPos.CENTER);
addXstatRow(statXTable, (event) -> xstatsListPinned.put(k, v), "xstat-green", "xstat-red", new Tooltip("Click '" + notPinnedChar + "' to pin the counter.\nPinned counter is always visible."), "xstats-val-0-" + rowIndex, k, WIDTH_COL_0 * 1.5, 0, "xstats-val-1-" + rowIndex, String.valueOf(v - getShadowCounter(port.getIndex(), k)), WIDTH_COL_1, 1, "xstats-val-2-" + rowIndex, notPinnedChar, WIDTH_COL_PIN, 2);
}
}
});
GridPane gp = new GridPane();
gp.setGridLinesVisible(false);
gp.add(statXTable, 1, 1, 1, 2);
return gp;
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class SkinPreviewViewComposite method previewTabInit.
@FxPostInitialize
public void previewTabInit() {
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
Thread.sleep(5000L);
Platform.runLater(() -> {
//메뉴바 배경.
{
Background background = mbSample.getBackground();
Color fill = (Color) background.getFills().get(0).getFill();
colorMbSample.setValue(fill);
//메뉴바 텍스트
{
Label lookup = (Label) mbSample.lookup(".label");
Color textFill = (Color) lookup.getTextFill();
colorMbLabelSample.setValue(textFill);
}
}
//Hbox 배경.
{
Background background = hboxSample.getBackground();
Color fill = (Color) background.getFills().get(0).getFill();
colorHboxSample.setValue(fill);
}
{
//선택디지않는 탭 색상 처리.
Set<Node> lookupAll = tabpaneSample.lookupAll(".tab:top");
lookupAll.forEach(lookup -> {
Optional<PseudoClass> findFirst = lookup.getPseudoClassStates().stream().filter(v -> {
return "selected".equals(v.getPseudoClassName());
}).findFirst();
if (findFirst.isPresent()) {
Label selectedTabLabel = (Label) lookup.lookup(".tab-label");
Color textFill = (Color) selectedTabLabel.getTextFill();
colorSelectedTabText.setValue(textFill);
} else {
Label selectedTabLabel = (Label) lookup.lookup(".tab-label");
Color textFill = (Color) selectedTabLabel.getTextFill();
colorUnSelectedTabText.setValue(textFill);
}
});
{
lookupAll.stream().findFirst().ifPresent(n -> {
Pane p = (Pane) n;
Background background = p.getBackground();
Color fill = (Color) background.getFills().get(0).getFill();
colorTabSample1Selected.setValue(fill);
});
}
}
});
return null;
}
};
Window window = this.getScene().getWindow();
if (window != null) {
FxUtil.showLoading(window, task);
} else
FxUtil.showLoading(task);
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class ButtonStyleViewComposite method initialize.
@FXML
public void initialize() {
loadButtonStyles();
colSkinName.setCellValueFactory(param -> {
return new SimpleStringProperty(param.getValue().getName());
});
tbSkins.getSelectionModel().selectedItemProperty().addListener((oba, o, n) -> {
File selectedItem = n;
if (selectedItem != null && selectedItem.exists()) {
String readFile = FileUtil.readFile(selectedItem, true, null);
txtStyle.setText(readFile);
try {
List<Node> findAllByNodes = FxUtil.findAllByNodes(borPreview, node -> node instanceof Button);
String className = String.format("%s", selectedItem.getName().replaceAll(".css", ""));
LOGGER.debug("{}", className);
findAllByNodes.forEach(btn -> {
btn.getStyleClass().add("button");
btn.getStyleClass().add(className);
});
borPreview.getStylesheets().clear();
borPreview.getStylesheets().add(selectedItem.toURI().toURL().toExternalForm());
borPreview.applyCss();
} catch (Exception e) {
e.printStackTrace();
}
} else {
txtStyle.setText("");
}
});
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class DockTitleBar method handle.
@Override
public void handle(MouseEvent event) {
//이벤트 관련 코드 추가. 마우스 메인키클릭의 경우에만 적용.
if (MouseButton.PRIMARY != event.getButton())
return;
if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) {
dockNode.setMaximized(!dockNode.isMaximized());
} else {
// drag detected is used in place of mouse pressed so there is
// some threshold for the
// dragging which is determined by the default drag detection
// threshold
dragStart = new Point2D(event.getX(), event.getY());
}
} else if (event.getEventType() == MouseEvent.DRAG_DETECTED) {
if (!dockNode.isFloating()) {
// the height of this title bar
if (!dockNode.isCustomTitleBar() && dockNode.isDecorated()) {
dockNode.setFloating(true, new Point2D(0, DockTitleBar.this.getHeight()));
} else {
dockNode.setFloating(true);
}
// TODO: Find a better solution.
// Temporary work around for nodes losing the drag event when
// removed from
// the scene graph.
// A possible alternative is to use "ghost" panes in the
// DockPane layout
// while making DockNode simply an overlay stage that is always
// shown.
// However since flickering when popping out was already
// eliminated that would
// be overkill and is not a suitable solution for native
// decorations.
// Bug report open:
// https://bugs.openjdk.java.net/browse/JDK-8133335
DockPane dockPane = this.getDockNode().getDockPane();
if (dockPane != null) {
dockPane.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
dockPane.addEventFilter(MouseEvent.MOUSE_RELEASED, this);
}
} else if (dockNode.isMaximized()) {
double ratioX = event.getX() / this.getDockNode().getWidth();
double ratioY = event.getY() / this.getDockNode().getHeight();
// Please note that setMaximized is ruined by width and height
// changes occurring on the
// stage and there is currently a bug report filed for this
// though I did not give them an
// accurate test case which I should and wish I would have. This
// was causing issues in the
// original release requiring maximized behavior to be
// implemented manually by saving the
// restored bounds. The problem was that the resize
// functionality in DockNode.java was
// executing at the same time canceling the maximized change.
// https://bugs.openjdk.java.net/browse/JDK-8133334
// restore/minimize the window after we have obtained its
// dimensions
dockNode.setMaximized(false);
// scale the drag start location by our restored dimensions
dragStart = new Point2D(ratioX * dockNode.getWidth(), ratioY * dockNode.getHeight());
}
dragging = true;
event.consume();
} else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
if (dockNode.isFloating() && event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY) {
event.setDragDetect(false);
event.consume();
return;
}
if (!dragging)
return;
Stage stage = dockNode.getStage();
Insets insetsDelta = this.getDockNode().getBorderPane().getInsets();
// dragging this way makes the interface more responsive in the
// event
// the system is lagging as is the case with most current JavaFX
// implementations on Linux
stage.setX(event.getScreenX() - dragStart.getX() - insetsDelta.getLeft());
stage.setY(event.getScreenY() - dragStart.getY() - insetsDelta.getTop());
// TODO: change the pick result by adding a copyForPick()
DockEvent dockEnterEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_ENTER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
DockEvent dockOverEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_OVER, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
DockEvent dockExitEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_EXIT, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
EventTask eventTask = new EventTask() {
@Override
public void run(Node node, Node dragNode) {
executions++;
if (dragNode != node) {
Event.fireEvent(node, dockEnterEvent.copyFor(DockTitleBar.this, node));
if (dragNode != null) {
// fire the dock exit first so listeners
// can actually keep track of the node we
// are currently over and know when we
// aren't over any which DOCK_OVER
// does not provide
Event.fireEvent(dragNode, dockExitEvent.copyFor(DockTitleBar.this, dragNode));
}
dragNodes.put(node.getScene().getWindow(), node);
}
Event.fireEvent(node, dockOverEvent.copyFor(DockTitleBar.this, node));
}
};
this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, dockExitEvent);
} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
dragging = false;
DockEvent dockReleasedEvent = new DockEvent(this, DockEvent.NULL_SOURCE_TARGET, DockEvent.DOCK_RELEASED, event.getX(), event.getY(), event.getScreenX(), event.getScreenY(), null, this.getDockNode());
EventTask eventTask = new EventTask() {
@Override
public void run(Node node, Node dragNode) {
executions++;
// if (dragNode != node) {
// Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
// }
Event.fireEvent(node, dockReleasedEvent.copyFor(DockTitleBar.this, node));
}
};
this.pickEventTarget(new Point2D(event.getScreenX(), event.getScreenY()), eventTask, null);
dragNodes.clear();
// Remove temporary event handler for bug mentioned above.
DockPane dockPane = this.getDockNode().getDockPane();
if (dockPane != null) {
dockPane.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
dockPane.removeEventFilter(MouseEvent.MOUSE_RELEASED, this);
}
}
}
use of javafx.scene.Node in project Gargoyle by callakrsos.
the class FxUtil method newInstance.
private static <T, C> T newInstance(Class<?> controllerClass, Object rootInstance, boolean isSelfController, String _fxml, Consumer<T> option, Consumer<C> controllerAction) throws Exception {
String fxml = _fxml;
if (fxml == null) {
FXMLController controller = getFxmlController(controllerClass);
if (controller == null) {
throw new GargoyleException("this is not FXMLController. check @FXMLController");
}
//controller.value();
fxml = getFxml(controller);
}
URL resource = controllerClass.getResource(fxml);
FXMLLoader loader = createNewFxmlLoader();
loader.setLocation(resource);
if (isSelfController && rootInstance != null) {
try {
loader.setRoot(rootInstance);
loader.setController(rootInstance);
} catch (Exception e) {
throw new GargoyleException(e);
}
}
T load = loader.load();
C instanceController = loader.getController();
// show warning...
if (load == null) {
LOGGER.warn("load result is empty.. controller class : {} ", controllerClass);
}
Method[] declaredMethods = controllerClass.getDeclaredMethods();
// 2017-02-07 findfirst에서 어노테이션으로 선언된 다건의 함수를 호출하게 다시 유도.
// findfirst로 수정. @FxPostInitialize가 여러건있는경우를 잘못된 로직 유도를 방지.
Stream.of(declaredMethods).filter(m -> m.getParameterCount() == 0 && m.getAnnotation(FxPostInitialize.class) != null).forEach(m -> {
if (m.getModifiers() == Modifier.PUBLIC) {
try {
if (instanceController != null) {
Platform.runLater(() -> {
try {
m.setAccessible(true);
m.invoke(instanceController);
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
});
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
}
});
if (option != null) {
option.accept(load);
}
if (controllerAction != null)
controllerAction.accept(instanceController);
Platform.runLater(() -> {
Parent parent = (Parent) load;
List<Node> findAllByNodes = FxUtil.findAllByNodes(parent, v -> v instanceof Button);
findAllByNodes.forEach(v -> {
GargoyleButtonBuilder.applyStyleClass((Button) v, SkinManager.BUTTON_STYLE_CLASS_NAME);
});
});
return load;
}
Aggregations