diff --git a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewer.java b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewer.java index b1543fb0e..9f1520cb6 100644 --- a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewer.java +++ b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewer.java @@ -7,7 +7,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -42,8 +41,8 @@ public JComponent createComponent() { @SuppressWarnings("unchecked") @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final ModelViewerPanel panel = (ModelViewerPanel) component; - panel.refresh(monitor, (ValueController) controller); + panel.setController((ValueController) controller); } } diff --git a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewerPanel.java b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewerPanel.java index af206cc3b..253d55fd0 100644 --- a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewerPanel.java +++ b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/ModelViewerPanel.java @@ -12,10 +12,9 @@ import com.shade.decima.ui.menu.MenuConstants; import com.shade.platform.model.Disposable; import com.shade.platform.model.data.DataKey; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.platform.ui.UIColor; +import com.shade.platform.ui.dialogs.ProgressDialog; import com.shade.platform.ui.menus.MenuManager; -import com.shade.util.NotNull; import com.shade.util.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -126,16 +125,19 @@ public void dispose() { controller = null; } - public void refresh(@NotNull ProgressMonitor monitor, @Nullable ValueController controller) { + public void setController(@Nullable ValueController controller) { if (this.controller != controller) { final ValueController oldController = this.controller; + this.controller = controller; - SwingUtilities.invokeLater(() -> firePropertyChange("controller", oldController, controller)); - updatePreview(monitor); + + firePropertyChange("controller", oldController, controller); + + updatePreview(); } } - private void updatePreview(@NotNull ProgressMonitor monitor) { + private void updatePreview() { if (viewport == null) { return; } @@ -144,20 +146,16 @@ private void updatePreview(@NotNull ProgressMonitor monitor) { if (controller != null) { try { - node = SceneSerializer.serialize(monitor, controller); + node = ProgressDialog + .showProgressDialog(null, "Loading model", monitor -> SceneSerializer.serialize(monitor, controller)) + .orElse(null); } catch (Exception e) { log.debug("Can't load preview for model of type {}", controller.getValueType(), e); } } if (node != null) { - final Node finalNode = node; - SwingUtilities.invokeLater(() -> { - final ModelViewport viewport = this.viewport; - if (viewport != null) { - viewport.setModel(new NodeModel(finalNode, viewport)); - } - }); + viewport.setModel(new NodeModel(node, viewport)); } } diff --git a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/isr/SceneSerializer.java b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/isr/SceneSerializer.java index 89f6492ca..5f054804b 100644 --- a/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/isr/SceneSerializer.java +++ b/modules/decima-ext-model-exporter/src/main/java/com/shade/decima/ui/data/viewer/model/isr/SceneSerializer.java @@ -505,7 +505,7 @@ private static void serializeRegularSkinnedMeshResource( final String uuid = RTTIUtils.uuidToString(object.get("ObjectUUID")); if (context.meshes.containsKey(uuid)) { - log.trace("Reusing existing mesh for {}", uuid); + log.debug("Reusing existing mesh for {}", uuid); node.setMesh(context.meshes.get(uuid)); return; } diff --git a/modules/decima-ext-model-viewer/src/main/java/com/shade/decima/model/viewer/ModelViewport.java b/modules/decima-ext-model-viewer/src/main/java/com/shade/decima/model/viewer/ModelViewport.java index 6ea96250e..5ed3cb319 100644 --- a/modules/decima-ext-model-viewer/src/main/java/com/shade/decima/model/viewer/ModelViewport.java +++ b/modules/decima-ext-model-viewer/src/main/java/com/shade/decima/model/viewer/ModelViewport.java @@ -109,10 +109,6 @@ public void paintGL() { final int width = (int) (getWidth() * scaleFactor); final int height = (int) (getHeight() * scaleFactor); - if (width <= 0 || height <= 0) { - return; - } - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); diff --git a/modules/decima-ext-shader-viewer/src/main/java/com/shade/decima/ui/data/viewer/shader/ShaderViewer.java b/modules/decima-ext-shader-viewer/src/main/java/com/shade/decima/ui/data/viewer/shader/ShaderViewer.java index 0aaba4c28..ea8c99f8c 100644 --- a/modules/decima-ext-shader-viewer/src/main/java/com/shade/decima/ui/data/viewer/shader/ShaderViewer.java +++ b/modules/decima-ext-shader-viewer/src/main/java/com/shade/decima/ui/data/viewer/shader/ShaderViewer.java @@ -6,7 +6,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -23,7 +22,7 @@ public JComponent createComponent() { @SuppressWarnings("unchecked") @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { ((ShaderViewerPanel) component).setInput((ValueController) controller); } } diff --git a/modules/decima-ext-texture-viewer/src/main/java/com/shade/decima/ui/data/viewer/texture/TextureViewer.java b/modules/decima-ext-texture-viewer/src/main/java/com/shade/decima/ui/data/viewer/texture/TextureViewer.java index 33962e0b8..08150b7e2 100644 --- a/modules/decima-ext-texture-viewer/src/main/java/com/shade/decima/ui/data/viewer/texture/TextureViewer.java +++ b/modules/decima-ext-texture-viewer/src/main/java/com/shade/decima/ui/data/viewer/texture/TextureViewer.java @@ -19,7 +19,6 @@ import com.shade.decima.ui.data.viewer.texture.reader.ImageReaderProvider; import com.shade.decima.ui.data.viewer.texture.util.Channel; import com.shade.decima.ui.editor.core.CoreEditor; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.platform.model.util.IOUtils; import com.shade.util.NotNull; import com.shade.util.Nullable; @@ -60,18 +59,18 @@ public JComponent createComponent() { } @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final TextureInfo info = Objects.requireNonNull(getTextureInfo(controller)); final HwTextureHeader header = info.texture.obj("Header").cast(); final TextureViewerPanel panel = (TextureViewerPanel) component; - final ImageProvider provider = getImageProvider(info.texture, controller.getProject().getPackfileManager()); - SwingUtilities.invokeLater(() -> { - panel.setStatusText("%sx%s (%s, %s)".formatted( - header.getWidth(), header.getHeight(), - header.getType(), header.getPixelFormat() - )); + panel.setStatusText("%sx%s (%s, %s)".formatted( + header.getWidth(), header.getHeight(), + header.getType(), header.getPixelFormat() + )); + SwingUtilities.invokeLater(() -> { + final ImageProvider provider = getImageProvider(info.texture, controller.getProject().getPackfileManager()); panel.getImagePanel().setProvider(provider, info.channels); panel.getImagePanel().fit(); }); diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewer.java index 07f34fcc0..1443d2d51 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewer.java @@ -1,6 +1,5 @@ package com.shade.decima.ui.data; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -9,20 +8,7 @@ public interface ValueViewer { @NotNull JComponent createComponent(); - /** - * Updates the viewer with the given {@code controller}. - *

- * Viewers should respect the following rules: - *

    - *
  • If the viewer needs to update the UI, it should do so on the EDT thread.
  • - *
  • If the monitor is canceled, the viewer should not attempt to update the UI as it might be disposed.
  • - *
- * - * @param monitor the progress monitor to report progress - * @param component the component to update - * @param controller the value controller to use - */ - void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller); + void refresh(@NotNull JComponent component, @NotNull ValueController controller); default boolean canView(@NotNull ValueController controller) { return true; diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewerPanel.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewerPanel.java deleted file mode 100644 index 39ae7d2df..000000000 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/ValueViewerPanel.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.shade.decima.ui.data; - -import com.shade.platform.model.Disposable; -import com.shade.platform.model.runtime.ProgressMonitor; -import com.shade.platform.ui.icons.LoadingIcon; -import com.shade.util.NotNull; -import net.miginfocom.swing.MigLayout; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.HierarchyEvent; -import java.util.concurrent.Future; - -/** - * Represents a panel that displays a value viewer with a support for asynchronous reload. - */ -public class ValueViewerPanel extends JComponent implements Disposable { - private static final int DELAY_BEFORE_SHOWING_LOADER_MS = 100; - private static final String PAGE_LOADING = "loading"; - private static final String PAGE_VIEWER = "viewer"; - - public interface Callback { - void viewerChanged(@NotNull ValueViewerPanel panel); - - void viewerClosed(@NotNull ValueViewerPanel panel); - } - - private ValueViewer currentViewer; - private JComponent currentComponent; - private SwingWorker currentWorker; - - public ValueViewerPanel() { - setLayout(new CardLayout()); - setPreferredSize(new Dimension(400, 400)); - } - - /** - * Updates the current viewer, optionally swapping it with a supplied {@code viewer}, with the given {@code controller}. - * - * @param viewer the viewer to use - * @param controller the value controller to supply to the viewer - * @param callback the callback to notify about the viewer changes - */ - public void update(@NotNull ValueViewer viewer, @NotNull ValueController controller, @NotNull Callback callback) { - final boolean viewerChanged = currentViewer != viewer; - - if (viewerChanged) { - if (currentComponent instanceof Disposable d) { - d.dispose(); - } - - currentViewer = viewer; - currentComponent = viewer.createComponent(); - - add(currentComponent, PAGE_VIEWER); - callback.viewerChanged(this); - } - - final CardLayout layout = (CardLayout) getLayout(); - layout.show(this, PAGE_VIEWER); - - final SwingWorker worker = currentWorker; - if (worker != null) { - worker.cancel(false); - } - - currentWorker = new SwingWorker<>() { - @Override - protected Object doInBackground() { - currentViewer.refresh(new MyProgressMonitor(this), currentComponent, controller); - return null; - } - - @Override - protected void done() { - if (isCancelled()) { - callback.viewerClosed(ValueViewerPanel.this); - } else { - layout.show(ValueViewerPanel.this, PAGE_VIEWER); - } - - currentWorker = null; - } - }; - currentWorker.execute(); - - final long start = System.currentTimeMillis(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (currentWorker == null || currentWorker.isDone() || currentWorker.isCancelled()) { - return; - } - if (System.currentTimeMillis() - start > DELAY_BEFORE_SHOWING_LOADER_MS) { - final JPanel inner = new JPanel(); - inner.setLayout(new GridBagLayout()); - inner.add(new LoadingPane(currentWorker)); - - add(inner, PAGE_LOADING); - layout.show(ValueViewerPanel.this, PAGE_LOADING); - } else { - SwingUtilities.invokeLater(this); - } - } - }); - } - - @Override - public void dispose() { - if (currentComponent instanceof Disposable d) { - d.dispose(); - } - - final SwingWorker worker = currentWorker; - if (worker != null) { - worker.cancel(false); - } - - currentViewer = null; - currentComponent = null; - currentWorker = null; - - removeAll(); - } - - private static class LoadingPane extends JComponent { - public LoadingPane(@NotNull Future future) { - final LoadingIcon icon = new LoadingIcon(); - final JLabel label = new JLabel("Loading\u2026", icon, SwingConstants.LEADING); - - final Timer timer = new Timer(1000 / LoadingIcon.SEGMENTS, e -> { - label.repaint(); - icon.advance(); - }); - - label.addHierarchyListener(e -> { - if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { - if (label.isShowing()) { - timer.start(); - } else { - timer.stop(); - } - } - }); - - final JButton button = new JButton("Cancel"); - button.addActionListener(e -> { - button.setEnabled(false); - future.cancel(false); - }); - - setLayout(new MigLayout("ins panel,wrap", "[center]")); - add(label); - add(button); - } - } - - private static class MyProgressMonitor implements ProgressMonitor { - private final Future future; - - public MyProgressMonitor(@NotNull Future future) { - this.future = future; - } - - @NotNull - @Override - public IndeterminateTask begin(@NotNull String title) { - return new MyTask(this); - } - - @NotNull - @Override - public Task begin(@NotNull String title, int total) { - return new MyTask(this); - } - - private static class MyTask implements Task { - private final MyProgressMonitor monitor; - - public MyTask(@NotNull MyProgressMonitor monitor) { - this.monitor = monitor; - } - - @NotNull - @Override - public ProgressMonitor split(int ticks) { - return new MyProgressMonitor(monitor.future); - } - - @Override - public void worked(int ticks) { - // do nothing - } - - @Override - public void close() { - // do nothing - } - - @Override - public boolean isCanceled() { - return monitor.future.isCancelled(); - } - - @NotNull - @Override - public String title() { - return ""; - } - } - } -} diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/LocalizedTextResourceViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/LocalizedTextResourceViewer.java index 1530e3fee..3116ce62d 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/LocalizedTextResourceViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/LocalizedTextResourceViewer.java @@ -7,7 +7,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.platform.ui.util.UIUtils; import com.shade.util.NotNull; @@ -29,7 +28,7 @@ public JComponent createComponent() { } @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final RTTIObject object = (RTTIObject) controller.getValue(); final JTable table = (JTable) ((JScrollPane) component).getViewport().getView(); final LanguageTableModel model = (LanguageTableModel) table.getModel(); diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/ReferenceValueViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/ReferenceValueViewer.java index 7b19e31c7..de4f47f2c 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/ReferenceValueViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/ReferenceValueViewer.java @@ -9,8 +9,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueRegistry; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; -import com.shade.platform.ui.util.UIUtils; import com.shade.util.NotNull; import com.shade.util.Nullable; @@ -26,26 +24,18 @@ public class ReferenceValueViewer implements ValueViewer { @NotNull @Override public JComponent createComponent() { - return new WrapperPanel(); + return new JPanel(new BorderLayout()); } @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final Result data = Objects.requireNonNull(getObjectWithViewer(controller)); - final WrapperPanel panel = (WrapperPanel) component; + final JComponent delegate = data.viewer.createComponent(); - if (panel.viewer != data.viewer) { - panel.viewer = data.viewer; - panel.removeAll(); - panel.add(UIUtils.invokeAndWait(() -> { - final JComponent comp = data.viewer.createComponent(); - component.removeAll(); - component.add(comp, BorderLayout.CENTER); - return comp; - })); - } + component.removeAll(); + component.add(delegate, BorderLayout.CENTER); - data.viewer.refresh(monitor, (JComponent) panel.getComponent(0), data.controller); + SwingUtilities.invokeLater(() -> data.viewer.refresh(delegate, data.controller)); } @Override @@ -78,13 +68,5 @@ private static Result getObjectWithViewer(@NotNull ValueController controller return new Result(result.object(), newController, newViewer); } - private record Result(@NotNull RTTIObject object, @NotNull ValueController controller, @NotNull ValueViewer viewer) {} - - private static class WrapperPanel extends JComponent { - private ValueViewer viewer; - - public WrapperPanel() { - setLayout(new BorderLayout()); - } - } + private record Result(@NotNull RTTIObject object, @NotNull ValueController controller, @NotNull ValueViewer viewer) { } } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/audio/AudioPlayer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/audio/AudioPlayer.java index 73cbc96e7..471163eaa 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/audio/AudioPlayer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/audio/AudioPlayer.java @@ -7,7 +7,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -26,7 +25,7 @@ public JComponent createComponent() { } @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final var panel = (AudioPlayerPanel) component; final var value = (RTTIObject) controller.getValue(); panel.setInput(controller.getProject(), value); diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewer.java index 5ba13f1b2..0aacc8587 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/BinaryViewer.java @@ -5,7 +5,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -22,7 +21,7 @@ public JComponent createComponent() { @SuppressWarnings("unchecked") @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final var panel = (BinaryViewerPanel) component; panel.setController((ValueController) controller); } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/DataSourceViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/DataSourceViewer.java index 9f6f0932d..7461534fa 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/DataSourceViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/binary/DataSourceViewer.java @@ -11,7 +11,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.platform.ui.editors.Editor; import com.shade.util.NotNull; import com.shade.util.Nullable; @@ -32,7 +31,7 @@ public JComponent createComponent() { @SuppressWarnings("unchecked") @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final var panel = (BinaryViewerPanel) component; panel.setController(new ProxyValueController((ValueController) controller)); } diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/font/FontViewer.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/font/FontViewer.java index 5561a5386..42d10d7bc 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/font/FontViewer.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/data/viewer/font/FontViewer.java @@ -6,7 +6,6 @@ import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Selector; import com.shade.decima.ui.data.registry.ValueHandlerRegistration.Type; import com.shade.decima.ui.data.registry.ValueViewerRegistration; -import com.shade.platform.model.runtime.ProgressMonitor; import com.shade.util.NotNull; import javax.swing.*; @@ -22,7 +21,7 @@ public JComponent createComponent() { } @Override - public void refresh(@NotNull ProgressMonitor monitor, @NotNull JComponent component, @NotNull ValueController controller) { + public void refresh(@NotNull JComponent component, @NotNull ValueController controller) { final RTTIObject value = (RTTIObject) controller.getValue(); final FontViewerPanel panel = (FontViewerPanel) component; diff --git a/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/CoreEditor.java b/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/CoreEditor.java index 78cd42f78..4a7ab5e87 100644 --- a/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/CoreEditor.java +++ b/modules/decima-ui/src/main/java/com/shade/decima/ui/editor/core/CoreEditor.java @@ -11,7 +11,6 @@ import com.shade.decima.ui.data.MutableValueController.EditType; import com.shade.decima.ui.data.ValueController; import com.shade.decima.ui.data.ValueViewer; -import com.shade.decima.ui.data.ValueViewerPanel; import com.shade.decima.ui.data.registry.ValueRegistry; import com.shade.decima.ui.editor.FileEditorInput; import com.shade.decima.ui.editor.NodeEditorInput; @@ -362,43 +361,52 @@ private void fireDirtyStateChange() { } private void updateCurrentViewer() { - ValueViewerPanel panel = (ValueViewerPanel) getRightComponent(); + final JComponent currentComponent = (JComponent) getRightComponent(); + final ValueViewer currentViewer = currentComponent != null ? VALUE_VIEWER_KEY.get(currentComponent) : null; if (tree.getLastSelectedPathComponent() instanceof CoreNodeObject node) { final CoreValueController controller = new CoreValueController<>(this, node, EditType.INLINE); final ValueViewer viewer = ValueRegistry.getInstance().findViewer(controller); if (viewer != null && viewer.canView(controller)) { - if (panel == null) { - panel = new ValueViewerPanel(); - setRightComponent(panel); - } + final boolean viewerChanged = currentViewer != viewer; + final JComponent component; - panel.update(viewer, controller, new ValueViewerPanel.Callback() { - @Override - public void viewerChanged(@NotNull ValueViewerPanel panel) { - fitValueViewer(panel); + if (viewerChanged) { + if (currentComponent instanceof Disposable d) { + d.dispose(); } - @Override - public void viewerClosed(@NotNull ValueViewerPanel panel) { - panel.dispose(); - setRightComponent(null); + component = viewer.createComponent(); + component.putClientProperty(VALUE_VIEWER_KEY, viewer); + setRightComponent(component); + } else { + component = currentComponent; + } + + viewer.refresh(component, controller); + validate(); + + if (viewerChanged) { + fitValueViewer(component); + + if (!CoreEditorSettings.getInstance().showValuePanel) { + UIUtils.minimizePanel(this, false); } - }); + } return; } } - if (panel != null) { - panel.dispose(); + if (currentComponent instanceof Disposable d) { + d.dispose(); } setRightComponent(null); } - private void fitValueViewer(@NotNull Component component) { + private void fitValueViewer(@NotNull JComponent component) { final Dimension size = component.getPreferredSize(); if (component instanceof JScrollPane pane) { diff --git a/modules/platform-model/src/main/java/com/shade/platform/model/util/IOUtils.java b/modules/platform-model/src/main/java/com/shade/platform/model/util/IOUtils.java index ae30dc2e0..b32173d67 100644 --- a/modules/platform-model/src/main/java/com/shade/platform/model/util/IOUtils.java +++ b/modules/platform-model/src/main/java/com/shade/platform/model/util/IOUtils.java @@ -13,6 +13,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.concurrent.Callable; import java.util.function.Function; import java.util.prefs.Preferences; import java.util.stream.Collectors; @@ -302,9 +303,9 @@ public static String getTrimmedOrNullIfEmpty(@NotNull String value) { } } - public static T unchecked(@NotNull ThrowableSupplier supplier) { + public static T unchecked(@NotNull Callable supplier) { try { - return supplier.get(); + return supplier.call(); } catch (Throwable e) { return sneakyThrow(e); } diff --git a/modules/platform-model/src/main/java/com/shade/platform/model/util/ThrowableSupplier.java b/modules/platform-model/src/main/java/com/shade/platform/model/util/ThrowableSupplier.java deleted file mode 100644 index 221765f19..000000000 --- a/modules/platform-model/src/main/java/com/shade/platform/model/util/ThrowableSupplier.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.shade.platform.model.util; - -@FunctionalInterface -public interface ThrowableSupplier { - T get() throws X; -} diff --git a/modules/platform-ui/src/main/java/com/shade/platform/ui/util/UIUtils.java b/modules/platform-ui/src/main/java/com/shade/platform/ui/util/UIUtils.java index 89eed6334..c716736d9 100644 --- a/modules/platform-ui/src/main/java/com/shade/platform/ui/util/UIUtils.java +++ b/modules/platform-ui/src/main/java/com/shade/platform/ui/util/UIUtils.java @@ -1,8 +1,6 @@ package com.shade.platform.ui.util; import com.formdev.flatlaf.FlatClientProperties; -import com.shade.platform.model.util.IOUtils; -import com.shade.platform.model.util.ThrowableSupplier; import com.shade.platform.ui.UIColor; import com.shade.platform.ui.controls.validation.InputValidator; import com.shade.platform.ui.controls.validation.Validation; @@ -21,7 +19,6 @@ import java.awt.event.*; import java.beans.PropertyChangeListener; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.time.Duration; import java.util.Objects; @@ -175,6 +172,10 @@ public static void addOpenDirectoryAction(@NotNull JTextField component, @NotNul }); } + public static void delegateKey(@NotNull JComponent source, int sourceKeyCode, @NotNull JComponent target, @NotNull String targetActionKey) { + delegateAction(source, KeyStroke.getKeyStroke(sourceKeyCode, 0), target, targetActionKey); + } + public static void delegateAction(@NotNull JComponent source, @NotNull JComponent target, @NotNull String targetActionKey, int targetCondition) { final InputMap inputMap = target.getInputMap(targetCondition); @@ -480,29 +481,6 @@ public static void setCursor(@NotNull Component component, @Nullable Cursor curs } } - @SuppressWarnings("unchecked") - public static T invokeAndWait(@NotNull ThrowableSupplier supplier) throws X { - if (SwingUtilities.isEventDispatchThread()) { - return supplier.get(); - } - - try { - final Object[] result = new Object[1]; - SwingUtilities.invokeAndWait(() -> { - try { - result[0] = supplier.get(); - } catch (Throwable e) { - IOUtils.sneakyThrow(e); - } - }); - return (T) result[0]; - } catch (InterruptedException e) { - return IOUtils.sneakyThrow(e); - } catch (InvocationTargetException e) { - throw (X) e.getCause(); - } - } - public interface SelectionProvider { @Nullable U getSelection(@NotNull T component, @Nullable MouseEvent event);