replace icon image instances with a static main class

This commit is contained in:
Wirlaburla 2024-07-19 14:45:39 -05:00
parent 16f729e4c2
commit 079697fb89
10 changed files with 96 additions and 60 deletions

View File

@ -23,12 +23,10 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
public class Bert implements ActionListener { public class Bert implements ActionListener {
BufferedImage windowIcon;
public JFrame frame = new JFrame(); public JFrame frame = new JFrame();
private JPanel frameContainer; private JPanel frameContainer;
private JButton cancelbtn; private JButton cancelbtn;
@ -60,12 +58,7 @@ public class Bert implements ActionListener {
cancelbtn.addActionListener(this); cancelbtn.addActionListener(this);
downloadbtn.addActionListener(this); downloadbtn.addActionListener(this);
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
frame.setVisible(true); frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {

View File

@ -84,12 +84,7 @@ public class Clifford implements ActionListener {
creating = false; creating = false;
frame.add(frameContainer); frame.add(frameContainer);
try { frame.setIconImage(Main.windowIcon);
BufferedImage windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find resource titleIcon.png. Window will not have an icon.");
}
frame.setSize(600, 300); // 1280 800 frame.setSize(600, 300); // 1280 800
frame.setMinimumSize(new Dimension(200,100)); frame.setMinimumSize(new Dimension(200,100));
frame.setTitle("Options"); frame.setTitle("Options");

View File

@ -61,18 +61,12 @@ public class Ernie implements ActionListener {
private JButton surebtn; private JButton surebtn;
public boolean backgroundDone = false; public boolean backgroundDone = false;
private BufferedImage windowIcon;
private JFrame parent; private JFrame parent;
public Ernie(JFrame parent) { public Ernie(JFrame parent) {
this.parent = parent; this.parent = parent;
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
byte[] urlraw = getFile(gitapi+"/releases?draft=false&pre-release=false"); byte[] urlraw = getFile(gitapi+"/releases?draft=false&pre-release=false");
if (urlraw.length <= 0) { if (urlraw.length <= 0) {
JOptionPane.showMessageDialog(frame, "Internal Error: Couldn't check for updates.", "Fatal Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(frame, "Internal Error: Couldn't check for updates.", "Fatal Error", JOptionPane.ERROR_MESSAGE);

View File

@ -55,12 +55,7 @@ public class Fozzie {
frame.setLayout(new GridLayout()); frame.setLayout(new GridLayout());
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
frame.setAlwaysOnTop(true); frame.setAlwaysOnTop(true);
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
frame.setVisible(true); frame.setVisible(true);
label.setText("Downloading \"" + dname + "\""); label.setText("Downloading \"" + dname + "\"");

View File

@ -60,12 +60,7 @@ public class Gonzo {
frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA
try { frame.setIconImage(Main.windowIcon);
BufferedImage windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
frame.setSize(800, 400); frame.setSize(800, 400);
frame.setMinimumSize(new Dimension(600,400)); frame.setMinimumSize(new Dimension(600,400));
frame.setTitle("Mod Installation"); frame.setTitle("Mod Installation");

View File

@ -49,7 +49,6 @@ import static java.nio.file.StandardCopyOption.*;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE; import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class MissPiggy implements ActionListener { public class MissPiggy implements ActionListener {
BufferedImage windowIcon;
JFrame frame = new JFrame(); JFrame frame = new JFrame();
JPanel frameContainer; JPanel frameContainer;
JPanel actionsContainer; JPanel actionsContainer;
@ -154,12 +153,7 @@ public class MissPiggy implements ActionListener {
descriptionField.getDocument().putProperty("filterNewlines", Boolean.FALSE); descriptionField.getDocument().putProperty("filterNewlines", Boolean.FALSE);
// display window // display window
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
menuBar.setBackground(new Color(25, 41, 93)); menuBar.setBackground(new Color(25, 41, 93));
fileMenu.setForeground(new Color(255, 255, 255)); fileMenu.setForeground(new Color(255, 255, 255));

View File

@ -0,0 +1,87 @@
/*
* Firestar Mod Manager
* Copyright (C) 2024 bonkmaykr
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Rizzo {
public void Rizzo(File infile) {
}
public static String[] translateCommandline(String toProcess) {
if (toProcess == null || toProcess.length() == 0) {
return new String[0];
}
final int normal = 0;
final int inQuote = 1;
final int inDoubleQuote = 2;
int state = normal;
final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
final ArrayList<String> result = new ArrayList<String>();
final StringBuilder current = new StringBuilder();
boolean lastTokenHasBeenQuoted = false;
while (tok.hasMoreTokens()) {
String nextTok = tok.nextToken();
switch (state) {
case inQuote:
if ("\'".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
case inDoubleQuote:
if ("\"".equals(nextTok)) {
lastTokenHasBeenQuoted = true;
state = normal;
} else {
current.append(nextTok);
}
break;
default:
if ("\'".equals(nextTok)) {
state = inQuote;
} else if ("\"".equals(nextTok)) {
state = inDoubleQuote;
} else if (" ".equals(nextTok)) {
if (lastTokenHasBeenQuoted || current.length() != 0) {
result.add(current.toString());
current.setLength(0);
}
} else {
current.append(nextTok);
}
lastTokenHasBeenQuoted = false;
break;
}
}
if (lastTokenHasBeenQuoted || current.length() != 0) {
result.add(current.toString());
}
if (state == inQuote || state == inDoubleQuote) {
throw new RuntimeException("unbalanced quotes in " + toProcess);
}
return result.toArray(new String[result.size()]);
}
}

View File

@ -26,7 +26,6 @@ import java.io.IOException;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
public class Rowlf { public class Rowlf {
private BufferedImage windowIcon;
JFrame frame = new JFrame(); JFrame frame = new JFrame();
JPanel frameContainer; JPanel frameContainer;
Image logo; Image logo;
@ -42,12 +41,7 @@ public class Rowlf {
System.out.println("ERROR: Failed to open About screen because we couldn't find an image needed to display the page."); System.out.println("ERROR: Failed to open About screen because we couldn't find an image needed to display the page.");
throw new RuntimeException(e); throw new RuntimeException(e);
} }
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
//frame.add(picLabel); //frame.add(picLabel);
frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA frame.add(frameContainer); // initialize window contents -- will be handled by IntelliJ IDEA

View File

@ -50,12 +50,7 @@ public class Waldorf implements ActionListener {
invoker = inv; invoker = inv;
frame.add(frameContainer); frame.add(frameContainer);
try { frame.setIconImage(Main.windowIcon);
BufferedImage windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
frame.setSize(600, 300); // 1280 800 frame.setSize(600, 300); // 1280 800
frame.setMinimumSize(new Dimension(200,100)); frame.setMinimumSize(new Dimension(200,100));
frame.setTitle("Options"); frame.setTitle("Options");

View File

@ -32,7 +32,6 @@ import java.nio.file.Files;
import static javax.swing.WindowConstants.EXIT_ON_CLOSE; import static javax.swing.WindowConstants.EXIT_ON_CLOSE;
public class WilkinsCoffee implements ActionListener { public class WilkinsCoffee implements ActionListener {
BufferedImage windowIcon;
Image logo; Image logo;
public Pages page; public Pages page;
public JFrame frame = new JFrame(); public JFrame frame = new JFrame();
@ -82,12 +81,7 @@ public class WilkinsCoffee implements ActionListener {
// reformat path slightly for windows // reformat path slightly for windows
if (Main.windows) {outPathTemp.replace("/", "\\");} if (Main.windows) {outPathTemp.replace("/", "\\");}
try { frame.setIconImage(Main.windowIcon);
windowIcon = ImageIO.read(Main.class.getResourceAsStream("/titleIcon.png"));
frame.setIconImage(windowIcon);
} catch (IOException e) {
System.out.println("ERROR: Failed to find /resources/titleIcon.png. Window will not have an icon.");
}
try { try {
logo = ImageIO.read(Main.class.getResourceAsStream("/programIcon.png")).getScaledInstance(96, 96, Image.SCALE_SMOOTH); logo = ImageIO.read(Main.class.getResourceAsStream("/programIcon.png")).getScaledInstance(96, 96, Image.SCALE_SMOOTH);
picLabel.setIcon(new ImageIcon(logo));picLabel.setText(""); picLabel.setIcon(new ImageIcon(logo));picLabel.setText("");