Adds various fixes to make the two java versions work as expected
Makes it possible to load a controller without generating a GUI, for better testing Makes sure not to try and parse empty profile lines Saves controller settings in a more readable and appendable format Adds code for using the correct java version for the occasion Adds a new function for writing to files
This commit is contained in:
@ -5,7 +5,11 @@ import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static javax.swing.text.DefaultCaret.ALWAYS_UPDATE;
|
||||
@ -31,7 +35,7 @@ public class Console extends KeyAdapter implements ActionListener, KeyListener {
|
||||
/**
|
||||
* Instantiates a new console
|
||||
*
|
||||
* @param tab <p>The tabbed pane used for displaying the console</p>
|
||||
* @param tab <p>The tabbed pane used for displaying the console</p>
|
||||
* @param name <p>The name of the console tab</p>
|
||||
*/
|
||||
Console(JTabbedPane tab, String name) {
|
||||
@ -77,6 +81,7 @@ public class Console extends KeyAdapter implements ActionListener, KeyListener {
|
||||
|
||||
/**
|
||||
* Truncates the first 50 lines if the console output has reached the max limit
|
||||
*
|
||||
* @param outputLines <p>The currently readable lines in the console output field</p>
|
||||
*/
|
||||
private void truncateConsole(int outputLines) {
|
||||
|
@ -17,15 +17,21 @@ public class ServerConsoles {
|
||||
private static JFrame frame;
|
||||
private static JTabbedPane consolesTabbedPane;
|
||||
|
||||
private ServerConsoles() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the server consoles frame
|
||||
*/
|
||||
public ServerConsoles() {
|
||||
frame = new JFrame();
|
||||
frame.setBounds(100, 100, 450, 300);
|
||||
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
consolesTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(consolesTabbedPane, BorderLayout.CENTER);
|
||||
public static void instantiate() {
|
||||
if (frame == null || consolesTabbedPane == null) {
|
||||
frame = new JFrame();
|
||||
frame.setBounds(100, 100, 450, 300);
|
||||
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
consolesTabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(consolesTabbedPane, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Controller;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
@ -25,13 +25,13 @@ public class ServerControlTab implements ActionListener {
|
||||
private JButton showConsolesButton;
|
||||
private JTextField customCommandTextField;
|
||||
|
||||
private Controller controller = Controller.getInstance();
|
||||
private final ServerLauncherController controller = ServerLauncherController.getInstance();
|
||||
private final ArrayList<String> globalPlayers;
|
||||
|
||||
/**
|
||||
* Instantiates a new server control tab
|
||||
*
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param controlServers <p>The JPanel to attach the server controls to</p>
|
||||
*/
|
||||
public ServerControlTab(JFrame mainFrame, JPanel controlServers) {
|
||||
@ -42,7 +42,7 @@ public class ServerControlTab implements ActionListener {
|
||||
/**
|
||||
* Initializes GUI elements for the server control tab
|
||||
*
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param controlServers <p>The JPanel to attach the server controls to</p>
|
||||
*/
|
||||
private void initialize(JFrame mainFrame, JPanel controlServers) {
|
||||
@ -149,7 +149,7 @@ public class ServerControlTab implements ActionListener {
|
||||
public void update() {
|
||||
this.targetServerCombo.removeAllItems();
|
||||
this.targetServerCombo.addItem("All");
|
||||
for (Collection collection : Controller.getInstance().getCurrentProfile().getCollections()) {
|
||||
for (Collection collection : ServerLauncherController.getInstance().getCurrentProfile().getCollections()) {
|
||||
this.targetServerCombo.addItem(collection.getName());
|
||||
}
|
||||
}
|
||||
@ -232,7 +232,7 @@ public class ServerControlTab implements ActionListener {
|
||||
/**
|
||||
* Handles command buttons acting on a specific server
|
||||
*
|
||||
* @param actionSource <p>The object being interacted with</p>
|
||||
* @param actionSource <p>The object being interacted with</p>
|
||||
* @param selectedServerValue <p>The server currently selected</p>
|
||||
*/
|
||||
private void handleServerCommands(Object actionSource, String selectedServerValue) {
|
||||
@ -252,7 +252,7 @@ public class ServerControlTab implements ActionListener {
|
||||
/**
|
||||
* Handles command buttons which act on a player
|
||||
*
|
||||
* @param actionSource <p>The clicked object</p>
|
||||
* @param actionSource <p>The clicked object</p>
|
||||
* @param selectedServerValue <p>The server currently selected</p>
|
||||
* @param selectedPlayerValue <p>The player currently selected</p>
|
||||
*/
|
||||
|
@ -2,7 +2,7 @@ package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Collection;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Controller;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||
import net.knarcraft.minecraftserverlauncher.server.Server;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
@ -12,15 +12,16 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static java.awt.Frame.NORMAL;
|
||||
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
||||
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getResourceAsScanner;
|
||||
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getResourceAsStream;
|
||||
@ -35,7 +36,7 @@ import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.getR
|
||||
public class ServerLauncherGUI extends MessageHandler implements ActionListener, GUI {
|
||||
|
||||
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
||||
private Controller controller;
|
||||
private final ServerLauncherController controller;
|
||||
private Map<String, String> textStrings;
|
||||
private Tray applicationTray;
|
||||
|
||||
@ -64,6 +65,20 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
this.controller = Main.getController();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the application window
|
||||
*
|
||||
* @param silent <p>Whether to make the GUI silent (hidden, for testing)</p>
|
||||
*/
|
||||
public ServerLauncherGUI(boolean silent) throws IOException {
|
||||
super(silent);
|
||||
if (!silent) {
|
||||
initialize(440, 170);
|
||||
}
|
||||
loadMessages();
|
||||
this.controller = Main.getController();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the application window with a preferred width and height
|
||||
*
|
||||
@ -146,7 +161,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
* Updates ServerLauncherGUI according to current profile settings
|
||||
*/
|
||||
public void updateWithSavedProfileData() {
|
||||
Controller controller = Main.getController();
|
||||
ServerLauncherController controller = Main.getController();
|
||||
serversPane.removeAll();
|
||||
serverLauncherMenu.update();
|
||||
serverControlTab.update();
|
||||
@ -158,7 +173,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
/**
|
||||
* Initializes the server launcher GUI
|
||||
*
|
||||
* @param width <p>The width of the GUI</p>
|
||||
* @param width <p>The width of the GUI</p>
|
||||
* @param height <p>The height of the GUI</p>
|
||||
* @throws IOException <p>If unable to load the GUI icon</p>
|
||||
*/
|
||||
@ -169,7 +184,7 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
UnsupportedLookAndFeelException |
|
||||
InstantiationException |
|
||||
IllegalAccessException e
|
||||
) {
|
||||
) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -311,7 +326,6 @@ public class ServerLauncherGUI extends MessageHandler implements ActionListener,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles buttons and the combo on the main tab
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Controller;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Profile;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -14,7 +14,7 @@ import java.util.Objects;
|
||||
*/
|
||||
public class ServerLauncherMenu implements ActionListener {
|
||||
|
||||
private JMenuBar menuBar;
|
||||
private final JMenuBar menuBar;
|
||||
//Options
|
||||
private JCheckBoxMenuItem runInBackgroundCheckBoxMenuItem;
|
||||
private JCheckBoxMenuItem delayStartupCheckBoxMenuItem;
|
||||
@ -31,17 +31,17 @@ public class ServerLauncherMenu implements ActionListener {
|
||||
private JMenuItem aboutMenuItem;
|
||||
private JMenuItem storyMenuItem;
|
||||
|
||||
private Controller controller;
|
||||
private ServerLauncherGUI serverLauncherGUI;
|
||||
private final ServerLauncherController controller;
|
||||
private final ServerLauncherGUI serverLauncherGUI;
|
||||
|
||||
/**
|
||||
* Initializes a new server launcher menu
|
||||
*
|
||||
* @param menuBar <p>The menu bar to attach items to</p>
|
||||
* @param menuBar <p>The menu bar to attach items to</p>
|
||||
* @param serverLauncherGUI <p>The server launcher GUI to use</p>
|
||||
*/
|
||||
public ServerLauncherMenu(JMenuBar menuBar, ServerLauncherGUI serverLauncherGUI) {
|
||||
this.controller = Controller.getInstance();
|
||||
this.controller = ServerLauncherController.getInstance();
|
||||
this.menuBar = menuBar;
|
||||
this.serverLauncherGUI = serverLauncherGUI;
|
||||
initialize();
|
||||
|
@ -1,13 +1,17 @@
|
||||
package net.knarcraft.minecraftserverlauncher.userinterface;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.Controller;
|
||||
import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController;
|
||||
import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -20,14 +24,14 @@ public class Tray {
|
||||
|
||||
private SystemTray tray;
|
||||
private TrayIcon trayIcon;
|
||||
private Controller controller;
|
||||
private ServerLauncherGUI serverLauncherGUI;
|
||||
private JFrame mainFrame;
|
||||
private final ServerLauncherController controller;
|
||||
private final ServerLauncherGUI serverLauncherGUI;
|
||||
private final JFrame mainFrame;
|
||||
|
||||
/**
|
||||
* Instantiates a new tray
|
||||
*
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param mainFrame <p>The main frame of the GUI</p>
|
||||
* @param serverLauncherGUI <p>The server launcher GUI to use</p>
|
||||
*/
|
||||
public Tray(JFrame mainFrame, ServerLauncherGUI serverLauncherGUI) {
|
||||
|
@ -12,7 +12,8 @@ public class WebBrowser {
|
||||
private static JFrame browserFrame;
|
||||
private static JTextPane editorPane;
|
||||
|
||||
private WebBrowser() {}
|
||||
private WebBrowser() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new web browser
|
||||
@ -44,7 +45,8 @@ public class WebBrowser {
|
||||
editorPane.setContentType("text/html");
|
||||
editorPane.addHyperlinkListener(hyperlinkEvent -> {
|
||||
if (hyperlinkEvent.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
|
||||
displayPage(hyperlinkEvent.getURL().toString()); }
|
||||
displayPage(hyperlinkEvent.getURL().toString());
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
editorPane.setContentType("text/html");
|
||||
|
Reference in New Issue
Block a user