-
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
Showing
8 changed files
with
162 additions
and
214 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (C) 2023 Nameless Production Committee | ||
* | ||
* Licensed under the MIT License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/mit-license.php | ||
*/ | ||
package viewtify.ui.dock; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import kiss.Extensible; | ||
import kiss.I; | ||
import kiss.Managed; | ||
import kiss.Model; | ||
import kiss.Singleton; | ||
import kiss.Ⅱ; | ||
|
||
@Managed(Singleton.class) | ||
public abstract class DockProvider implements Extensible { | ||
|
||
/** The managed independent dock items. */ | ||
private List<Dock> independents; | ||
|
||
private List<Ⅱ<TypedDock, Class>> typed; | ||
|
||
/** | ||
* Initialize and analyze | ||
*/ | ||
protected DockProvider() { | ||
} | ||
|
||
private List<Dock> docks() { | ||
if (independents == null) { | ||
independents = I.signal(getClass().getFields()) | ||
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == Dock.class) | ||
.map(field -> (Dock) field.get(this)) | ||
.sort(Comparator.comparing(Dock::id)) | ||
.toList(); | ||
} | ||
return independents; | ||
} | ||
|
||
private List<Ⅱ<TypedDock, Class>> typed() { | ||
if (typed == null) { | ||
typed = I.signal(getClass().getFields()) | ||
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == TypedDock.class) | ||
.map(field -> I | ||
.pair((TypedDock) field.get(this), (Class) Model.collectParameters(field.getGenericType(), TypedDock.class)[0])) | ||
.toList(); | ||
} | ||
return typed; | ||
} | ||
|
||
/** | ||
* Query all independent views. | ||
*/ | ||
public List<Dock> queryIndependentDocks() { | ||
return docks(); | ||
} | ||
|
||
/** | ||
* Request registering dock by id. | ||
* | ||
* @param id | ||
* @return | ||
*/ | ||
protected boolean register(String id) { | ||
for (Dock dock : docks()) { | ||
if (dock.id().equals(id)) { | ||
dock.registration.accept(dock); | ||
return true; | ||
} | ||
} | ||
|
||
int index = id.indexOf(' '); | ||
if (index != -1) { | ||
String prefix = id.substring(0, index); | ||
String param = id.substring(index + 1); | ||
|
||
for (Ⅱ<TypedDock, Class> dock : typed()) { | ||
if (dock.ⅰ.id.equalsIgnoreCase(prefix)) { | ||
dock.ⅰ.register(I.transform(param, dock.ⅱ)); | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
/* | ||
* Copyright (C) 2023 Nameless Production Committee | ||
* | ||
* Licensed under the MIT License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/mit-license.php | ||
*/ | ||
package viewtify.ui.dock; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
import icy.manipulator.Icy; | ||
import icy.manipulator.Icy.Property; | ||
import kiss.I; | ||
import kiss.WiseBiConsumer; | ||
import viewtify.ui.UITab; | ||
|
||
@Icy | ||
public abstract class TypedDockModel<T> { | ||
|
||
@Property | ||
public abstract String id(); | ||
|
||
@Property | ||
public abstract WiseBiConsumer<UITab, T> registration(); | ||
|
||
@Property | ||
public UnaryOperator<DockRecommendedLocation> location() { | ||
return UnaryOperator.identity(); | ||
} | ||
|
||
public void register(T param) { | ||
UITab tab = DockSystem.register(id() + " " + I.transform(param, String.class)); | ||
registration().accept(tab, param); | ||
} | ||
} |
Oops, something went wrong.