1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2025-01-05 19:09:03 +01:00

Make the workspace frame load more responsively.

This commit is contained in:
sk89q 2015-07-26 02:20:27 -07:00
parent a11fed622e
commit c5faed3c40
2 changed files with 18 additions and 8 deletions

View File

@ -6,6 +6,8 @@
package com.skcraft.launcher.creator;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.skcraft.launcher.Launcher;
import com.skcraft.launcher.creator.controller.WelcomeController;
import com.skcraft.launcher.creator.dialog.WelcomeDialog;
@ -21,11 +23,13 @@ import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Executors;
public class Creator {
@Getter private final File dataDir;
@Getter private final CreatorConfig config;
@Getter private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
public Creator() {
this.dataDir = getAppDataDir();

View File

@ -8,6 +8,9 @@ package com.skcraft.launcher.creator.controller;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.skcraft.concurrency.Deferred;
import com.skcraft.concurrency.Deferreds;
import com.skcraft.launcher.creator.Creator;
import com.skcraft.launcher.creator.dialog.AboutDialog;
import com.skcraft.launcher.creator.dialog.PackManagerFrame;
@ -16,10 +19,12 @@ import com.skcraft.launcher.creator.model.creator.RecentEntry;
import com.skcraft.launcher.creator.model.creator.Workspace;
import com.skcraft.launcher.creator.model.swing.RecentListModel;
import com.skcraft.launcher.creator.swing.WorkspaceDirectoryFilter;
import com.skcraft.launcher.dialog.ProgressDialog;
import com.skcraft.launcher.persistence.Persistence;
import com.skcraft.launcher.swing.PopupMouseAdapter;
import com.skcraft.launcher.swing.SwingHelper;
import com.skcraft.launcher.util.MorePaths;
import com.skcraft.launcher.util.SwingExecutor;
import javax.swing.*;
import java.awt.*;
@ -51,16 +56,17 @@ public class WelcomeController {
}
private boolean openWorkspace(File dir) {
try {
PackManagerFrame frame = new PackManagerFrame();
ListeningExecutorService executor = creator.getExecutor();
PackManagerFrame frame = new PackManagerFrame();
Deferred<?> deferred = Deferreds.makeDeferred(executor.submit(() -> {
PackManagerController controller = new PackManagerController(frame, dir, creator);
addRecentEntry(dir);
controller.show();
return true;
} catch (IOException e) {
SwingHelper.showErrorDialog(dialog, "An unexpected error has occurred.", "Error", e);
return false;
}
return controller;
}), executor)
.handleAsync(PackManagerController::show, ex -> {}, SwingExecutor.INSTANCE);
SwingHelper.addErrorDialogCallback(frame, deferred);
return true;
}
private void addRecentEntry(File dir) {