Skip to content

Commit 7fbbdf7

Browse files
committed
Add changing LICENSE feature
Would be good to add a settings later for the default author name, so it can be used together when authoring a new pack/license name
1 parent 17d8591 commit 7fbbdf7

27 files changed

+2942
-22
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Roadmap.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
## Roadmap
22
PW-GUI is considered finish for the most part (Albeit with some slight UX inconvenience). However, the following thing is also nice to have:
33

4-
- Change LICENSE button
5-
- Add new contents from GitHub
6-
- Content browser for Modrinth/CurseForge
7-
- Replace "Run Development Server" dialog with a more thorough tutorial on packwiz-installer
4+
- ~~Add new contents from GitHub~~ (Upstream implementation is not mature enough to be considered useful)
85
- Git Integration
6+
- More detailed/non-technical descriptions of different features for newcomers.
7+
- Content browser for Modrinth/CurseForge
98
- A better file picker (???) (The one swing uses is mildly annoying to use)
109

1110
These will be done in no particular order nor deadline (and might not even be done if it isn't a highly requested feature).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.lx862.pwgui.gui.action;
2+
3+
import com.lx862.pwgui.gui.popup.ChangeLicenseDialog;
4+
5+
import javax.swing.*;
6+
import java.awt.*;
7+
import java.awt.event.ActionEvent;
8+
import java.awt.event.KeyEvent;
9+
import java.io.File;
10+
import java.util.function.Supplier;
11+
12+
public class EditLicenseAction extends AbstractAction {
13+
private final Supplier<JFrame> getParent;
14+
private final File licenseFile;
15+
16+
public EditLicenseAction(Supplier<JFrame> getParent, File licenseFile) {
17+
super("Change license...");
18+
this.getParent = getParent;
19+
this.licenseFile = licenseFile;
20+
putValue(MNEMONIC_KEY, KeyEvent.VK_C);
21+
}
22+
23+
@Override
24+
public void actionPerformed(ActionEvent actionEvent) {
25+
new ChangeLicenseDialog(getParent.get(), licenseFile).setVisible(true);
26+
}
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lx862.pwgui.gui.action;
2+
3+
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.KeyEvent;
6+
7+
public class OKAction extends AbstractAction {
8+
private final Runnable callback;
9+
public OKAction(Runnable callback) {
10+
super("OK");
11+
this.callback = callback;
12+
putValue(MNEMONIC_KEY, KeyEvent.VK_O);
13+
}
14+
15+
@Override
16+
public void actionPerformed(ActionEvent actionEvent) {
17+
callback.run();
18+
}
19+
}

src/main/java/com/lx862/pwgui/gui/components/kui/KListEntryPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public KListEntryPanel() {
1212
}
1313

1414
public KListEntryPanel(String title) {
15-
setBorder(GUIHelper.borderWithPadding(4, GUIHelper.getSeparatorBorder()));
15+
setBorder(GUIHelper.borderWithPadding(4, GUIHelper.getSeparatorBorder(false, true)));
1616
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
1717
setBackground(new JTextField().getBackground());
1818

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.formdev.flatlaf.ui.FlatUIUtils;
44
import com.lx862.pwgui.PWGUI;
55
import com.lx862.pwgui.core.data.model.ManualModInfo;
6+
import com.lx862.pwgui.gui.action.OKAction;
67
import com.lx862.pwgui.gui.components.fstree.FileSystemWatcher;
78
import com.lx862.pwgui.gui.components.kui.*;
89
import com.lx862.pwgui.util.Util;
@@ -81,12 +82,10 @@ public ManualDownloadDialog(JDialog parentDialog, List<ManualModInfo> modList, C
8182

8283
JPanel actionRowPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
8384
actionRowPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
84-
this.okButton = new KButton("OK");
85-
this.okButton.setMnemonic(KeyEvent.VK_O);
86-
this.okButton.addActionListener(actionEvent -> {
85+
this.okButton = new KButton(new OKAction(() -> {
8786
dispose();
8887
finishCallback.accept(watchingPath);
89-
});
88+
}));
9089
actionRowPanel.add(this.okButton);
9190

9291
KButton cancelButton = new KButton("Cancel");

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lx862.pwgui.gui.dialog;
22

33
import com.formdev.flatlaf.ui.FlatUIUtils;
4+
import com.lx862.pwgui.gui.action.OKAction;
45
import com.lx862.pwgui.gui.components.kui.KButton;
56
import com.lx862.pwgui.gui.components.kui.KGridBagLayoutPanel;
67
import com.lx862.pwgui.gui.components.kui.KListCellRenderer;
@@ -42,12 +43,10 @@ private <T> void init(Component component, String title, List<T> list, Consumer<
4243
jList.setAlignmentX(Component.LEFT_ALIGNMENT);
4344
panel.addRow(1, jList);
4445

45-
KButton okButton = new KButton("OK");
46-
okButton.setMnemonic(KeyEvent.VK_O);
47-
okButton.addActionListener(actionEvent -> {
46+
KButton okButton = new KButton(new OKAction(() -> {
4847
callback.accept(jList.getSelectedIndex());
4948
dispose();
50-
});
49+
}));
5150

5251
KButton cancelButton = new KButton("Cancel");
5352
cancelButton.setMnemonic(KeyEvent.VK_C);

src/main/java/com/lx862/pwgui/gui/panel/editing/filetype/LicenseFilePanel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.lx862.pwgui.gui.panel.editing.filetype;
22

33
import com.lx862.pwgui.PWGUI;
4+
import com.lx862.pwgui.gui.action.EditLicenseAction;
5+
import com.lx862.pwgui.gui.components.kui.KButton;
46
import com.lx862.pwgui.util.Util;
57
import com.lx862.pwgui.core.data.model.file.PlainTextFileModel;
68

79
import javax.swing.*;
10+
import java.awt.*;
811

912
public class LicenseFilePanel extends FileTypePanel {
1013
public LicenseFilePanel(FileEntryPaneContext context, PlainTextFileModel fileEntry) {
1114
super(context);
1215
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1316

17+
KButton changeLicenseButton = new KButton(new EditLicenseAction(() -> (JFrame)getTopLevelAncestor(), fileEntry.path.toFile()));
18+
changeLicenseButton.setAlignmentX(LEFT_ALIGNMENT);
19+
add(changeLicenseButton);
20+
1421
JTextArea textArea = new JTextArea();
1522
textArea.setEditable(false);
1623
textArea.setLineWrap(true);
@@ -27,6 +34,7 @@ public LicenseFilePanel(FileEntryPaneContext context, PlainTextFileModel fileEnt
2734
textArea.select(0, 0);
2835

2936
JScrollPane jScrollPane = new JScrollPane(textArea);
37+
jScrollPane.setAlignmentX(LEFT_ALIGNMENT);
3038
add(jScrollPane);
3139
}
3240
}

0 commit comments

Comments
 (0)