Skip to content

Commit

Permalink
Revert "Core File: Lazy load contents of the value panel"
Browse files Browse the repository at this point in the history
This reverts commit e5c0547.
  • Loading branch information
ShadelessFox committed May 14, 2024
1 parent e5c0547 commit f3975ba
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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<RTTIObject>) controller);
panel.setController((ValueController<RTTIObject>) controller);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -126,16 +125,19 @@ public void dispose() {
controller = null;
}

public void refresh(@NotNull ProgressMonitor monitor, @Nullable ValueController<RTTIObject> controller) {
public void setController(@Nullable ValueController<RTTIObject> controller) {
if (this.controller != controller) {
final ValueController<RTTIObject> 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;
}
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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<RTTIObject>) controller);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -9,20 +8,7 @@ public interface ValueViewer {
@NotNull
JComponent createComponent();

/**
* Updates the viewer with the given {@code controller}.
* <p>
* Viewers should respect the following rules:
* <ul>
* <li>If the viewer needs to update the UI, it should do so on the EDT thread.</li>
* <li>If the monitor is canceled, the viewer should <b>not</b> attempt to update the UI as it might be disposed.</li>
* </ul>
*
* @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;
Expand Down

This file was deleted.

Loading

0 comments on commit f3975ba

Please sign in to comment.