-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3b82b8
commit b6bf65c
Showing
29 changed files
with
346 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
gui-local/src/main/java/place/sita/labelle/gui/local/fx/modulefx/ChildrenFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package place.sita.labelle.gui.local.fx.modulefx; | ||
|
||
import java.util.List; | ||
|
||
public interface ChildrenFactory { | ||
|
||
<T> T create(Class<T> clazz); | ||
|
||
<T> List<Class<?>> getClasses(Class<T> clazz); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...al/src/main/java/place/sita/labelle/gui/local/fx/modulefx/processors/tabs/FxSmartTab.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package place.sita.labelle.gui.local.fx.modulefx.processors.tabs; | ||
|
||
import javafx.scene.control.Tab; | ||
import place.sita.labelle.gui.local.fx.UnstableSceneReporter; | ||
|
||
public interface FxSmartTab { | ||
|
||
Tab tab(); | ||
|
||
void load(UnstableSceneReporter unstableSceneReporter); | ||
|
||
void unload(); | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...main/java/place/sita/labelle/gui/local/fx/modulefx/processors/tabs/FxSmartTabFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package place.sita.labelle.gui.local.fx.modulefx.processors.tabs; | ||
|
||
import javafx.application.Platform; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.ProgressIndicator; | ||
import javafx.scene.control.Tab; | ||
import javafx.scene.layout.AnchorPane; | ||
import javafx.scene.layout.Region; | ||
import place.sita.labelle.gui.local.fx.UnstableSceneReporter; | ||
import place.sita.labelle.gui.local.fx.modulefx.ChildrenFactory; | ||
import place.sita.labelle.gui.local.fx.modulefx.FxSetupContext; | ||
import place.sita.modulefx.annotations.FxTab; | ||
|
||
import java.util.UUID; | ||
|
||
public class FxSmartTabFactory { | ||
|
||
public static FxSmartTab create(FxTab fxTab, Class<?> tabClass, FxSetupContext setupContext, ChildrenFactory factory) { | ||
switch (fxTab.loadMode()) { | ||
case ONLY_WHEN_NEEDED: | ||
return createUnloadingTab(fxTab, tabClass, setupContext, factory); | ||
default: | ||
throw new IllegalArgumentException("Unknown load mode: " + fxTab.loadMode()); | ||
} | ||
} | ||
|
||
private static FxSmartTab createUnloadingTab(FxTab fxTab, Class<?> tabClass, FxSetupContext setupContext, ChildrenFactory factory) { | ||
UUID id = UUID.randomUUID(); | ||
String stringId = id.toString(); | ||
|
||
Tab internalTab = new Tab(fxTab.tabName()); | ||
internalTab.setId(stringId); | ||
internalTab.setClosable(false); | ||
|
||
Platform.runLater(() -> { | ||
internalTab.setContent(new ProgressIndicator(-1)); | ||
}); | ||
|
||
return new FxSmartTab() { | ||
private boolean loaded = false; | ||
@Override | ||
public Tab tab() { | ||
return internalTab; | ||
} | ||
|
||
@Override | ||
public void load(UnstableSceneReporter unstableSceneReporter) { | ||
if (loaded) { | ||
return; | ||
} | ||
|
||
UUID loadId = UUID.randomUUID(); | ||
unstableSceneReporter.markUnstable(loadId, "Loading tab: " + tabClass.getName()); | ||
|
||
Object bean = factory.create(tabClass); | ||
Node component = setupContext.setupForController(bean, fxTab.resourceFile(), setupContext); | ||
|
||
AnchorPane anchorPane = new AnchorPane(); | ||
if (component instanceof Region region) { | ||
region.setMinWidth(100); | ||
region.setMinHeight(100); | ||
} | ||
anchorPane.getChildren().add(component); | ||
AnchorPane.setTopAnchor(component, 0.0); | ||
AnchorPane.setLeftAnchor(component, 0.0); | ||
AnchorPane.setRightAnchor(component, 0.0); | ||
AnchorPane.setBottomAnchor(component, 0.0); | ||
Platform.runLater(() -> { | ||
internalTab.setContent(anchorPane); | ||
unstableSceneReporter.markStable(loadId); | ||
}); | ||
loaded = true; | ||
} | ||
|
||
@Override | ||
public void unload() { | ||
if (!loaded) { | ||
return; | ||
} | ||
|
||
Platform.runLater(() -> { | ||
internalTab.setContent(new ProgressIndicator(-1)); | ||
}); | ||
|
||
loaded = false; | ||
} | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.