Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Jan 31, 2024
1 parent 43646ab commit 8111f85
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 38 deletions.
62 changes: 35 additions & 27 deletions src/main/java/viewtify/ui/dock/DockRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,48 @@
*/
package viewtify.ui.dock;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import kiss.Extensible;
import kiss.I;
import kiss.Managed;
import kiss.Singleton;
import kiss.Variable;
import viewtify.ui.UITab;
import viewtify.ui.View;

@Managed(Singleton.class)
public abstract class DockRegister implements Extensible {

/** The managed independent dock items. */
private final List<DockItem> independents = new ArrayList();

/**
* Initialize and analyze
*/
protected DockRegister() {
I.signal(getClass().getDeclaredMethods())
.take(m -> m.getParameterCount() == 0 && Modifier.isPublic(m.getModifiers()) && m.getReturnType() == void.class)
.to(m -> {
DockItem item = new DockItem(m.getName(), Variable.of(m.getName()), () -> {
});

independents.add(item);
});
}

/**
* Register the specified view.
*
* @param view
*/
protected void register(Class<? extends View> view) {
register(I.make(view));
}

/**
* Register the specified view.
*
Expand All @@ -32,32 +62,10 @@ protected UITab register(View view) {
return DockSystem.register(view.id()).text(view.title()).contentsLazy(tab -> view);
}

final DockItem match(String id) {
int index = id.indexOf('@');
if (index == -1) {
try {
// class id
Class<?> clazz = Class.forName(id);
if (View.class.isAssignableFrom(clazz)) {

} else {

}
} catch (ClassNotFoundException e) {
// normal id
}
} else {

}
}

private void matchByType(String name, String param) {
try {
I.signal(getClass().getMethods()).take(m -> m.getName().equals(name)).take(m -> m.getParameterCount() == 1).to(m -> {

});
} catch (ClassNotFoundException e) {
// name id
}
/**
* Query all independent views.
*/
public List<DockItem> queryIndependentDocks() {
return independents;
}
}
12 changes: 1 addition & 11 deletions src/main/java/viewtify/ui/dock/DockSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;

import kiss.I;
import kiss.JSON;
import kiss.Managed;
Expand Down Expand Up @@ -274,17 +275,6 @@ public static UITab register(String id, UnaryOperator<DockRecommendedLocation> o
return tab;
}

/**
* Register a new view within this dock system.
* <p/>
* The Position will give an advice where this view should be placed.
*
* @param id The view to register.
*/
public static void register(String id, WiseConsumer<UITab> tab) {
register(id, o -> o, tab);
}

/**
* Register a new view within this dock system.
* <p/>
Expand Down
54 changes: 54 additions & 0 deletions src/test/java/viewtify/ui/dock/DockRegisterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.List;

import org.junit.jupiter.api.Test;

import kiss.I;
import kiss.Variable;
import viewtify.ui.View;

class DockRegisterTest {

@Test
void register() {
@SuppressWarnings("unused")
class Register extends DockRegister {
public void dock() {
register(ViewA.class);
}
}

Register register = I.make(Register.class);
List<DockItem> items = register.queryIndependentDocks();
assert items.size() == 1;

DockItem item = items.get(0);
assert item.id.equals("dock");
assert item.title.is("Title A");
assert item.registration != null;
}

private static class ViewA extends View {
@Override
protected void initialize() {
}

/**
* {@inheritDoc}
*/
@Override
public Variable<String> title() {
return Variable.of("Title A");
}
}
}

0 comments on commit 8111f85

Please sign in to comment.