Skip to content

Commit 8b4ae4e

Browse files
committed
Slight UX improvements
- Busy cursor when loading modpack - Reorganized buttons & menu bar slightly - Automatically make packwiz executable if possible (Owner only)
1 parent e3af241 commit 8b4ae4e

12 files changed

Lines changed: 50 additions & 44 deletions

src/main/java/com/lx862/pwgui/gui/action/CloseWindowAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
public class CloseWindowAction extends AbstractAction {
99
private final Window parent;
1010

11-
public CloseWindowAction(Window parent, boolean useCancelText) {
12-
super(useCancelText ? "Cancel" : "Close");
11+
public CloseWindowAction(String title, Window parent) {
12+
super(title);
1313
this.parent = parent;
1414
putValue(MNEMONIC_KEY, KeyEvent.VK_C);
1515
}

src/main/java/com/lx862/pwgui/gui/action/LocatePackwizAction.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99
import javax.swing.*;
1010
import java.awt.*;
1111
import java.awt.event.ActionEvent;
12-
import java.awt.event.KeyEvent;
1312
import java.io.File;
1413
import java.io.IOException;
14+
import java.nio.file.Files;
15+
import java.nio.file.LinkOption;
16+
import java.nio.file.attribute.PosixFilePermission;
17+
import java.util.Set;
1518

1619
public class LocatePackwizAction extends AbstractAction {
1720
private final Window parent;
1821
private final Runnable finishCallback;
1922

20-
public LocatePackwizAction(Window parent, Runnable finishCallback) {
21-
super("Locate packwiz...");
23+
public LocatePackwizAction(String title, Window parent, Runnable finishCallback) {
24+
super(title);
2225
this.parent = parent;
2326
this.finishCallback = finishCallback;
24-
25-
putValue(MNEMONIC_KEY, KeyEvent.VK_L);
2627
}
2728

2829
@Override
@@ -33,14 +34,20 @@ public void actionPerformed(ActionEvent actionEvent) {
3334
if(fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
3435
File selectedFile = fileChooser.getSelectedFile();
3536
if(!selectedFile.canExecute()) {
36-
JOptionPane.showMessageDialog(parent, "The selected file is not executable!\nConsider adding the executable (x) permission to the file.", Util.withTitlePrefix("File Not Executable!"), JOptionPane.ERROR_MESSAGE);
37-
return;
37+
try {
38+
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(selectedFile.toPath(), LinkOption.NOFOLLOW_LINKS);
39+
perms.add(PosixFilePermission.OWNER_EXECUTE);
40+
Files.setPosixFilePermissions(selectedFile.toPath(), perms);
41+
} catch (Exception ignored) {
42+
JOptionPane.showMessageDialog(parent, "The selected file is not executable!\nConsider adding the executable (x) permission to the file.", Util.withTitlePrefix("File Not Executable!"), JOptionPane.ERROR_MESSAGE);
43+
return;
44+
}
3845
}
3946

4047
PWGUI.getConfig().packwizExecutablePath.setValue(selectedFile.toPath());
4148
String newProbedPath = Executables.packwiz.probe(null);
4249
if(newProbedPath == null) {
43-
JOptionPane.showMessageDialog(parent, "The selected executable is not valid!\nAre you sure you can run the executable?", Util.withTitlePrefix("Invalid Executable"), JOptionPane.ERROR_MESSAGE);
50+
JOptionPane.showMessageDialog(parent, "The selected executable is not valid!\nPlease confirm that you can run the executable?", Util.withTitlePrefix("Invalid Executable"), JOptionPane.ERROR_MESSAGE);
4451
return;
4552
}
4653

src/main/java/com/lx862/pwgui/gui/action/ReinstallAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class ReinstallAction extends AbstractAction {
2222
private final Window parent;
2323
private final Modpack modpack;
2424

25-
public ReinstallAction(Window parent, Modpack modpack) {
26-
super("Reinstall...");
25+
public ReinstallAction(String title, Window parent, Modpack modpack) {
26+
super(title);
2727
this.parent = parent;
2828
this.modpack = modpack;
2929
putValue(MNEMONIC_KEY, KeyEvent.VK_R);

src/main/java/com/lx862/pwgui/gui/dialog/ChangeAcceptableGameVersionDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public ChangeAcceptableGameVersionDialog(JFrame parentFrame, String requiredVers
9292
});
9393
});
9494

95-
KButton cancelButton = new KButton(new CloseWindowAction(this, true));
95+
KButton cancelButton = new KButton(new CloseWindowAction("Cancel", this));
9696

9797
KActionPanel actionPanel = new KActionPanel.Builder().setPositiveButton(okButton).setNegativeButton(cancelButton).build();
9898
actionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

src/main/java/com/lx862/pwgui/gui/dialog/ChangeLicenseDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public ChangeLicenseDialog(JFrame parent, File licenseFile) {
122122
contentPanel.add(splitPane);
123123

124124
JButton changeLicenseButton = new KButton(new ChangeLicenseAction(licenseFile));
125-
JButton cancelButton = new KButton(new CloseWindowAction(this, true));
125+
JButton cancelButton = new KButton(new CloseWindowAction("Cancel", this));
126126

127127
KActionPanel actionPanel = new KActionPanel.Builder().setNegativeButton(cancelButton).setPositiveButton(changeLicenseButton).build();
128128
actionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

src/main/java/com/lx862/pwgui/gui/dialog/GenerateModListDialog.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ public GenerateModListDialog(Window frame, PackFile packFile) {
115115

116116
KButton saveAsButton = new KButton(new SaveModlistAction());
117117
KButton copyButton = new KButton(new CopyModListAction());
118-
KButton closeButton = new KButton(new CloseWindowAction(this, false));
119118

120-
KActionPanel actionPanel = new KActionPanel.Builder().add(saveAsButton, copyButton, closeButton).build();
119+
KActionPanel actionPanel = new KActionPanel.Builder().add(saveAsButton, copyButton).build();
121120
contentPanel.add(actionPanel, BorderLayout.PAGE_END);
122121

123122
add(contentPanel);

src/main/java/com/lx862/pwgui/gui/dialog/SettingsDialog.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.lx862.pwgui.core.data.ApplicationTheme;
88
import com.lx862.pwgui.executable.Executables;
99
import com.lx862.pwgui.gui.action.DownloadPackwizAction;
10-
import com.lx862.pwgui.gui.components.filter.PackwizExecutableFileFilter;
10+
import com.lx862.pwgui.gui.action.LocatePackwizAction;
1111
import com.lx862.pwgui.gui.components.kui.*;
1212
import com.lx862.pwgui.util.GUIHelper;
1313
import com.lx862.pwgui.util.Util;
@@ -196,15 +196,11 @@ public PackwizPanel() {
196196
packwizLocationPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
197197
this.packwizLocationLabel = new JLabel("Location: ???");
198198

199-
KButton changePackwizLocationButton = new KButton("Change...");
200-
changePackwizLocationButton.addActionListener(actionEvent -> {
201-
KFileChooser fileChooser = new KFileChooser("locate-pw");
202-
fileChooser.setFileFilter(new PackwizExecutableFileFilter());
203-
204-
if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
205-
updatePackwizPath(fileChooser.getSelectedFile().toPath());
206-
}
207-
});
199+
KButton changePackwizLocationButton = new KButton(new LocatePackwizAction("Change...", SettingsDialog.this, () -> {
200+
Path newPath = PWGUI.getConfig().packwizExecutablePath.getValue();
201+
packwizLocationLabel.setText(String.format("Location: %s", newPath.toString()));
202+
packwizLocationLabel.setToolTipText(newPath.toString());
203+
}));
208204

209205
packwizLocationPanel.addRow(1, 0, packwizLocationLabel, changePackwizLocationButton);
210206

src/main/java/com/lx862/pwgui/gui/dialog/ViewLogDialog.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313
import org.apache.commons.io.FileUtils;
1414

1515
import javax.swing.*;
16-
import javax.swing.text.BadLocationException;
17-
import javax.swing.text.Document;
18-
import javax.swing.text.Style;
19-
import javax.swing.text.StyleConstants;
16+
import javax.swing.text.*;
2017
import java.awt.*;
2118
import java.awt.event.ActionEvent;
2219
import java.awt.event.KeyEvent;
2320
import java.io.File;
24-
import java.io.FileWriter;
2521
import java.io.IOException;
2622
import java.nio.charset.StandardCharsets;
2723

@@ -55,17 +51,17 @@ public ViewLogDialog(JFrame frame) {
5551

5652
Document doc = logTextPane.getDocument();
5753
try {
58-
doc.insertString(doc.getLength(), line + "\n", style);
54+
doc.insertString(doc.getLength(), line + "\n\n", style);
5955
logHistory.append(line).append("\n");
6056
} catch (BadLocationException ignored) {}
6157
logTextAreaScrollPane.getVerticalScrollBar().setValue(logTextAreaScrollPane.getVerticalScrollBar().getMaximum()); // Jump to bottom
58+
SimpleAttributeSet aSet = new SimpleAttributeSet();
6259
};
6360

6461
PWGUI.LOGGER.addListener(appendLogCallback);
6562

6663
KButton saveAsButton = new KButton(new SaveLogAction());
67-
KButton closeButton = new KButton(new CloseWindowAction(this, false));
68-
KActionPanel actionPanel = new KActionPanel.Builder().add(saveAsButton, closeButton).build();
64+
KActionPanel actionPanel = new KActionPanel.Builder().add(saveAsButton).build();
6965

7066
contentPanel.add(actionPanel, BorderLayout.PAGE_END);
7167
add(contentPanel);

src/main/java/com/lx862/pwgui/gui/frame/BaseFrame.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ protected KMenu getToolMenu(Modpack modpack) {
5757
// KMenuItem refreshMenuItem = new KMenuItem(new RefreshPackAction(this));
5858
// toolMenu.add(refreshMenuItem);
5959

60-
KMenuItem reinstallMenuItem = new KMenuItem(new ReinstallAction(this, modpack));
61-
toolMenu.add(reinstallMenuItem);
62-
63-
KMenuItem updateAllMenuItem = new KMenuItem(new UpdateAction(() -> this));
64-
toolMenu.add(updateAllMenuItem);
65-
66-
6760
KMenuItem generateModlistItem = new KMenuItem(new GenerateModlistAction(this, modpack.packFile.get()));
6861
toolMenu.add(generateModlistItem);
6962

@@ -83,6 +76,12 @@ protected KMenu getToolMenu(Modpack modpack) {
8376

8477
protected KMenu getEditMenu(Modpack modpack) {
8578
KMenu editMenu = new KMenu("Edit");
79+
KMenuItem reinstallMenuItem = new KMenuItem(new ReinstallAction("Reinstall Modpack", this, modpack));
80+
editMenu.add(reinstallMenuItem);
81+
82+
KMenuItem updateAllMenuItem = new KMenuItem(new UpdateAction(() -> this));
83+
editMenu.add(updateAllMenuItem);
84+
8685
KMenu addMissingMenu = new KMenu("Add Missing...");
8786

8887
KMenuItem modsDirectoryMenuItem = new KMenuItem(new CreateMissingDirectoryAction(this, modpack.getRootPath(), "mods", "Mods Folder"));

src/main/java/com/lx862/pwgui/gui/frame/SetupFrame.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
import javax.swing.*;
1414
import java.awt.*;
15+
import java.awt.event.KeyEvent;
16+
17+
import static javax.swing.Action.MNEMONIC_KEY;
1518

1619
/** The greeting splash screen if the packwiz executable is not found */
1720
public class SetupFrame extends BaseFrame {
@@ -75,11 +78,15 @@ public MainPanel(JFrame parent) {
7578

7679
add(Box.createRigidArea(new Dimension(0, 8)));
7780

78-
KButton locateButton = new KButton(new LocatePackwizAction(parent, () -> {
81+
LocatePackwizAction action = new LocatePackwizAction("Locate Packwiz...", parent, () -> {
82+
JOptionPane.showMessageDialog(parent, "Packwiz executable has been configured!", Util.withTitlePrefix("Configure Success!"), JOptionPane.INFORMATION_MESSAGE);
7983
WelcomeFrame welcomeFrame = new WelcomeFrame(parent);
8084
welcomeFrame.setVisible(true);
8185
parent.dispose();
82-
}));
86+
});
87+
action.putValue(MNEMONIC_KEY, KeyEvent.VK_L);
88+
89+
KButton locateButton = new KButton(action);
8390
locateButton.setAlignmentX(Component.CENTER_ALIGNMENT);
8491
add(locateButton);
8592

0 commit comments

Comments
 (0)