Skip to content

Commit 0623378

Browse files
committed
makes addon icons now
1 parent 5dc351f commit 0623378

File tree

8 files changed

+67
-25
lines changed

8 files changed

+67
-25
lines changed
152 Bytes
Binary file not shown.
1.22 KB
Binary file not shown.
-24 Bytes
Binary file not shown.
672 Bytes
Binary file not shown.

app/src/main/java/fn10/bedrockr/addons/source/jsonClasses/WPFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
public class WPFile {
44
public String WorkspaceName;
55
public String MinimumEngineVersion;
6+
public String Description;
7+
public String IconExtension;
68

79

8-
public WPFile(String WPName, String MEV) {
10+
public WPFile(String WPName, String MEV, String DES, String IE) {
911
this.WorkspaceName = WPName;
1012
this.MinimumEngineVersion = MEV;
13+
this.Description = DES;
14+
this.IconExtension = IE;
1115
}
1216
}

app/src/main/java/fn10/bedrockr/windows/RNewAddon.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package fn10.bedrockr.windows;
22

3+
import java.awt.Component;
34
import java.awt.Dimension;
45
import java.awt.event.ActionEvent;
56
import java.awt.event.ActionListener;
7+
import java.io.PrintWriter;
8+
import java.io.StringWriter;
9+
610
import javax.imageio.ImageIO;
711
import javax.swing.BorderFactory;
812
import javax.swing.ImageIcon;
@@ -11,6 +15,7 @@
1115
import javax.swing.JFileChooser;
1216
import javax.swing.JFrame;
1317
import javax.swing.JLabel;
18+
import javax.swing.JOptionPane;
1419
import javax.swing.JTextArea;
1520
import javax.swing.JTextField;
1621
import javax.swing.SpringLayout;
@@ -19,6 +24,7 @@
1924
import javax.swing.filechooser.FileNameExtensionFilter;
2025

2126
import fn10.bedrockr.Launcher;
27+
import fn10.bedrockr.addons.source.jsonClasses.WPFile;
2228
import fn10.bedrockr.windows.base.RDialog;
2329
import fn10.bedrockr.windows.base.RLoadingScreen;
2430
import fn10.bedrockr.windows.utils.ImageUtilites;
@@ -34,9 +40,12 @@ public class RNewAddon extends RDialog implements ActionListener {
3440
"1.21.80",
3541
"1.21.90"
3642
};
37-
protected JLabel AddonIcon;
3843
protected ImageIcon ChosenIcon = ImageUtilites.ResizeImageByURL(getClass().getResource("/addons/DefaultIcon.png"),
3944
250, 250);
45+
protected JFileChooser file = new JFileChooser();
46+
protected String imageExtension = "png";
47+
48+
protected JLabel AddonIcon = new JLabel(ChosenIcon);
4049
protected JTextArea DescInput = new JTextArea("My new addon, made in bedrockR");
4150
protected JTextField NameInput = new JTextField("New AddonR");
4251
protected JComboBox<String> MinimumEngineVersionSelection = new JComboBox<String>(PICKABLE_VERSIONS);
@@ -47,7 +56,6 @@ public RNewAddon(JFrame Parent) {
4756
"New Addon",
4857
new Dimension(459, 350));
4958

50-
AddonIcon = new JLabel(ChosenIcon);
5159
AddonIcon.setSize(new Dimension(300, 300));
5260
AddonIcon.setHorizontalAlignment(SwingConstants.CENTER);
5361
AddonIcon.setVerticalAlignment(SwingConstants.CENTER);
@@ -122,17 +130,27 @@ public RNewAddon(JFrame Parent) {
122130
add(CreateButton);
123131
}
124132

133+
private static void showError(Component parent, String msg, String title, Exception ex) {
134+
StringWriter sw = new StringWriter();
135+
ex.printStackTrace(new PrintWriter(sw));
136+
JOptionPane.showMessageDialog(parent,
137+
msg + "\n" + sw.toString(),
138+
title, JOptionPane.ERROR_MESSAGE);
139+
}
140+
125141
@Override
126142
public void actionPerformed(ActionEvent e) {
127143
if (e.getActionCommand() == "changeIcon") {
128144
try {
129-
var file = new JFileChooser();
130145
file.setDialogTitle("Choose Addon Icon");
131146
file.setFileFilter(
132-
new FileNameExtensionFilter("Image Files (*.png,*.jpg/jpeg)", "png", "jpg", "jpeg", "tga"));
147+
new FileNameExtensionFilter("Image Files (*.png,*.jpg)", "png", "jpg"));
133148
file.showOpenDialog(this);
134149
ChosenIcon = ImageUtilites.ResizeIcon(new ImageIcon(ImageIO.read(file.getSelectedFile())), 250, 250);
135150
AddonIcon.setIcon(ChosenIcon);
151+
Launcher.LOG.info(file.getSelectedFile().getName());
152+
imageExtension = file.getSelectedFile().getName().split(".")[1];
153+
Launcher.LOG.info("Icon extension will be: " + imageExtension);
136154
} catch (Exception ex) {
137155
ex.printStackTrace();
138156
}
@@ -148,9 +166,17 @@ public void actionPerformed(ActionEvent e) {
148166
loading.setVisible(true);
149167
});
150168

151-
RFileOperations.createWorkspace(loading, name, MinimumEngineVersionSelection.getSelectedItem().toString());
169+
RFileOperations.createWorkspace(loading,
170+
171+
new WPFile(NameInput.getText(),
172+
MinimumEngineVersionSelection.getSelectedItem().toString(), DescInput.getText(),
173+
imageExtension),
174+
175+
(ImageIcon) AddonIcon.getIcon());
152176
} catch (Exception ex) {
153177
ex.printStackTrace();
178+
showError(this, "Failed to make new addon.", "Grrrr", ex);
179+
return;
154180
}
155181

156182
} else {

app/src/main/java/fn10/bedrockr/windows/base/RLoadingScreen.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@
55
import javax.swing.JProgressBar;
66
import javax.swing.SpringLayout;
77
import javax.swing.SwingUtilities;
8-
import javax.swing.border.LineBorder;
9-
108
import fn10.bedrockr.windows.utils.ImageUtilites;
119
import fn10.bedrockr.windows.utils.RFonts;
1210

1311
import java.awt.*;
1412

1513
public class RLoadingScreen extends RDialog {
1614

17-
protected JProgressBar MAINBAR;
18-
protected JLabel MAIN_TEXT;
15+
protected JProgressBar MainBar = new JProgressBar();
16+
protected JLabel MainText = new JLabel("Loading...");;
1917

2018
public Integer Steps = null;
2119

2220
public void changeText(String text) {
2321
SwingUtilities.invokeLater(() -> {
24-
MAIN_TEXT.setText(text);
22+
MainText.setText(text);
2523
});
2624
}
2725

2826
public void increaseProgress(int increase,@Nullable String TextChange) {
2927

3028
changeText(TextChange);
3129
SwingUtilities.invokeLater(() -> {
32-
MAINBAR.setValue(MAINBAR.getValue() + increase);
30+
MainBar.setValue(MainBar.getValue() + increase);
3331
});
3432
}
3533

@@ -45,7 +43,7 @@ public void increaseProgressBySteps(@Nullable String TextChange) throws IllegalA
4543
changeText(TextChange);
4644

4745
SwingUtilities.invokeLater(() -> {
48-
MAINBAR.setValue(MAINBAR.getValue() + 100 / Steps);
46+
MainBar.setValue(MainBar.getValue() + 100 / Steps);
4947
});
5048
}
5149

@@ -63,7 +61,7 @@ public RLoadingScreen(Frame Parent) {
6361
.ResizeImageByURL(getClass().getResource("/branding/BrandingFullWShadow.png"), titleImgW, titleImageH));
6462
Branding.setPreferredSize(new Dimension(titleImgW, titleImageH));
6563

66-
var MainBar = new JProgressBar();
64+
6765
MainBar.setPreferredSize(new Dimension(600, 20));
6866
// MainBar.setBackground(getForeground());
6967
MainBar.setOrientation(JProgressBar.HORIZONTAL);
@@ -75,7 +73,7 @@ public RLoadingScreen(Frame Parent) {
7573
// MainBar.setStringPainted(true);
7674
// MainBar.setString("Loading...");
7775

78-
var MainText = new JLabel("Loading...");
76+
7977
MainText.setFont(RFonts.RegMinecraftFont.deriveFont(2, 18));
8078
MainText.setForeground(Color.WHITE);
8179

@@ -96,6 +94,5 @@ public RLoadingScreen(Frame Parent) {
9694
add(MainBar);
9795

9896
add(BG); // always add last!
99-
MAINBAR = MainBar;
10097
}
10198
}

app/src/main/java/fn10/bedrockr/windows/utils/RFileOperations.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package fn10.bedrockr.windows.utils;
22

33
import java.awt.Component;
4+
import java.awt.Image;
5+
import java.awt.image.BufferedImage;
6+
import java.awt.image.RenderedImage;
47
import java.io.File;
58
import java.io.IOException;
69
import java.io.PrintWriter;
710
import java.io.StringWriter;
811
import java.nio.file.DirectoryNotEmptyException;
912
import java.nio.file.Files;
1013

14+
import javax.imageio.ImageIO;
15+
import javax.swing.ImageIcon;
1116
import javax.swing.JOptionPane;
1217

1318
import fn10.bedrockr.addons.source.SourceWPFile;
@@ -54,10 +59,11 @@ public static File getFileFromWorkspace(Component windowDoingThis, String Worksp
5459
e.printStackTrace();
5560
return null;
5661
}
57-
62+
5863
}
5964

60-
public static boolean createWorkspace(RLoadingScreen loading, String workspaceName, String minimumVersion)
65+
public static boolean createWorkspace(RLoadingScreen loading, // String workspaceName, String minimumVersion)
66+
WPFile wpf, ImageIcon imgIcon)
6167
throws DirectoryNotEmptyException, IOException {
6268

6369
String[] wsFolders = {
@@ -67,7 +73,7 @@ public static boolean createWorkspace(RLoadingScreen loading, String workspaceNa
6773

6874
File base = getBaseDirectory(loading);
6975

70-
File wsFolder = new File(base.getAbsolutePath() + "/workspace/" + workspaceName + "/");
76+
File wsFolder = new File(base.getAbsolutePath() + "/workspace/" + wpf.WorkspaceName + "/");
7177

7278
if (wsFolder.exists()) { // throw if folder is already here
7379
var e = new IOException("Folder " + wsFolder.getAbsolutePath() + " already exists.");
@@ -91,16 +97,25 @@ public static boolean createWorkspace(RLoadingScreen loading, String workspaceNa
9197

9298
loading.changeText("Creating workspace...");
9399

94-
var srcWPF = new SourceWPFile(new WPFile(workspaceName, minimumVersion));
95-
srcWPF.buildJSONFile(loading, workspaceName);
100+
var srcWPF = new SourceWPFile(wpf);
101+
srcWPF.buildJSONFile(loading, wpf.WorkspaceName);
102+
103+
var srcIcon = new File(wsFolder.getAbsolutePath() + "/icon." + wpf.IconExtension);
104+
trying = srcIcon;
105+
106+
// make buffered image
107+
var image = imgIcon.getImage();
108+
BufferedImage BI = new BufferedImage(image.getWidth(null),
109+
image.getHeight(null),
110+
BufferedImage.TYPE_INT_ARGB);
111+
BI.getGraphics().drawImage(BI, 0, 0, null);
112+
113+
ImageIO.write(BI, wpf.IconExtension, srcIcon);
96114

97115
return true;
98116

99117
} catch (Exception e) { // handle exception
100-
JOptionPane.showMessageDialog(loading,
101-
"Failed to make Directory " + wsFolder.getAbsolutePath() + ". \n"
102-
+ e.getStackTrace().toString(),
103-
"Failed to make workspace.", JOptionPane.ERROR_MESSAGE);
118+
showError(loading, "IO Error, with path " + wsFolder.getAbsolutePath(), "IO Error", e);
104119
throw e;
105120
}
106121
}

0 commit comments

Comments
 (0)