Skip to content

Commit

Permalink
Application: Improve exception reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Feb 18, 2024
1 parent 350853a commit 3159c21
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.shade.platform.model.runtime.ProgressMonitor;
import com.shade.util.NotNull;

import java.io.IOException;
import java.nio.channels.SeekableByteChannel;

public interface ModelExporter {
Expand All @@ -13,5 +14,5 @@ void export(
@NotNull CoreBinary core,
@NotNull RTTIObject object,
@NotNull SeekableByteChannel channel
) throws Exception;
) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void export(
@NotNull CoreBinary core,
@NotNull RTTIObject object,
@NotNull SeekableByteChannel channel
) throws Exception {
) throws IOException {
final DMFSceneFile scene = export(monitor, core, object, IOUtils.getBasename(output));

try (Writer writer = Channels.newWriter(channel, StandardCharsets.UTF_8)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.shade.util.NotNull;
import org.joml.Matrix4f;

import java.io.IOException;
import java.io.Writer;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void export(
@NotNull CoreBinary core,
@NotNull RTTIObject object,
@NotNull SeekableByteChannel channel
) throws Exception {
) throws IOException {
final Node root = SceneSerializer.serialize(monitor, object, core, project);
root.setMatrix(new Matrix4f().rotateX((float) Math.toRadians(-90.0)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.shade.util.NotNull;
import com.shade.util.Nullable;

import java.io.IOException;

public interface RTTITypeProvider {
void initialize(@NotNull RTTITypeRegistry registry, @NotNull ProjectContainer container);
void initialize(@NotNull RTTITypeRegistry registry, @NotNull ProjectContainer container) throws IOException;

@Nullable
default RTTIType<?> lookup(@NotNull RTTITypeRegistry registry, @NotNull String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.shade.decima.model.rtti.RTTITypeSerialized;
import com.shade.util.NotNull;

import java.io.IOException;
import java.util.*;

public class RTTITypeRegistry implements Iterable<RTTIType<?>> {
Expand All @@ -17,7 +18,7 @@ public class RTTITypeRegistry implements Iterable<RTTIType<?>> {

private final Deque<PendingType> pendingTypes = new ArrayDeque<>();

public RTTITypeRegistry(@NotNull ProjectContainer container) {
public RTTITypeRegistry(@NotNull ProjectContainer container) throws IOException {
for (RTTITypeProvider provider : ServiceLoader.load(RTTITypeProvider.class)) {
provider.initialize(this, container);
providers.add(provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public class ExternalTypeProvider implements RTTITypeProvider {

@SuppressWarnings("unchecked")
@Override
public void initialize(@NotNull RTTITypeRegistry registry, @NotNull ProjectContainer container) {
public void initialize(@NotNull RTTITypeRegistry registry, @NotNull ProjectContainer container) throws IOException {
try (Reader reader = IOUtils.newCompressedReader(container.getTypeMetadataPath())) {
declarations.putAll(new Gson().fromJson(reader, Map.class));
} catch (IOException e) {
throw new RuntimeException("Error loading types definition from " + container.getTypeMetadataPath(), e);
}

if (declarations.containsKey("$spec")) {
Expand Down Expand Up @@ -173,7 +171,8 @@ private void resolveClassType(@NotNull RTTITypeRegistry registry, @NotNull RTTIT
final var memberOffset = getInt(memberInfo, "offset");
final var memberFlags = getInt(memberInfo, "flags");

fields.add(new MyField(type,
fields.add(new MyField(
type,
memberType,
memberName,
memberCategory.isEmpty() ? null : memberCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.shade.decima.model.util.graph.GraphLayoutConfig;
import com.shade.decima.model.util.graph.impl.HorizontalGraphVisualizer;
import com.shade.util.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
Expand All @@ -17,6 +19,7 @@
import java.util.function.BiConsumer;

public class GraphComponent extends JComponent implements Scrollable {
private static final Logger log = LoggerFactory.getLogger(GraphComponent.class);
private static final int GRID_SIZE = 20;

private final Graph<RTTIObject> graph;
Expand Down Expand Up @@ -295,16 +298,16 @@ public Dimension getSpacing() {
}

private class Handler extends MouseAdapter {
private final Robot robot;
private Robot robot;

private Point origin;
private boolean panning;

public Handler() {
try {
this.robot = new Robot();
robot = new Robot();
} catch (AWTException e) {
throw new RuntimeException(e);
log.warn("Can't create robot", e);
}
}

Expand Down Expand Up @@ -362,7 +365,7 @@ public void mouseDragged(MouseEvent e) {
final Point mouse = e.getLocationOnScreen();
final Rectangle bounds = new Rectangle(viewport.getLocationOnScreen(), viewport.getSize());

if (!bounds.contains(mouse)) {
if (robot != null && !bounds.contains(mouse)) {
if (mouse.x >= bounds.x + bounds.width) {
mouse.x = bounds.x + 1;
} else if (mouse.x < bounds.x) {
Expand Down

0 comments on commit 3159c21

Please sign in to comment.