Best way to update a huge number of buttons / nodes at the same time?
I apologize in advance, this is my first StackOverflow question ...
So, I created an emulator for the specific in the home device that we are creating. This device has a button on it that flashes with an LED at a speed of 100 ms.
So, I basically created a view similar to an embedded device. I installed a button on my view that blinks throughbtn.setStyle("-fx-background-color: #"+rgb";");
This works fine and that’s it, but when I add 100 of these “Devices” on my screen, the unsafe processor rockets and the application become unusable.
Here, I hope, some relevant code snippets:
This code fragment calls the method Updateon Deviceif it is currently displayed:
final Duration oneFrameAmt = Duration.millis(10);
final KeyFrame oneFrame = new KeyFrame(oneFrameAmt, new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
updateDrawnEntities();
}
});
loop = TimelineBuilder.create().cycleCount(Animation.INDEFINITE).keyFrames(oneFrame).build();
}
protected void updateDrawnEntities() {
for (ADeviceView<?> view : DeviceLayoutManager.getDeviceViews()) {
Pane content = view.getMainContentPanel();
if (content.isVisible()) {
view.update();
}
}
}
The Update method itself looks like that (the note m_TaskLEDhas values that are set via jfx ChangeListeners, but it is updated only when the launch function is called.):
@Override
public void update() {
m_TaskLED.run();
}
The runnable method is as follows:
@Override
public void run() {
if (m_Color == null) return;
if (m_LEDState == null) return;
if (!m_IsChanged) return;
if (m_LEDState != ELEDState.Off && m_Color != EColor.Off) {
ColorRegistry.applyColor(m_Control, m_Color);
}
else {
ColorRegistry.applyColor(m_Control, null);
}
m_IsChanged = false;
}
And last but not least, the method is applyColoras follows:
public static void applyColor(Node p_Node, EColor p_Color) {
if (p_Color != null) {
if (p_Node instanceof Shape) {
((Shape) p_Node).setFill(Paint.valueOf(getRGB(p_Color)));
}
else {
p_Node.setStyle(FX_BACKGROUND_COLOR + getRGB(p_Color) + ";");
}
}
else {
if (p_Node instanceof Shape) {
String style = ((Shape) p_Node).getStyle().toLowerCase();
String rgb = style.substring(style.indexOf(FX_BACKGROUND_COLOR) + FX_BACKGROUND_COLOR.length());
((Shape) p_Node).setFill(Paint.valueOf(rgb));
}
p_Node.setStyle("");
}
}
JavaFX 2, JavaFX 8 . JavaFX 2, JavaFX 8 , , JavaFX 8. , , JDK8, / - , 20%.
:

, :

:

