Skip to content

Commit

Permalink
added settings to hide/show client and server consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaSteward committed Dec 7, 2014
1 parent 601a74e commit 9a755c3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/xmage/launcher/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.slf4j.LoggerFactory;

/**
Expand All @@ -30,6 +32,8 @@ public class Config {
private static int torrentDownRate = 0;
private static String clientJavaOpts = "";
private static String serverJavaOpts = "";
private static boolean showClientConsole = true;
private static boolean showServerConsole = true;

static {
try {
Expand All @@ -51,6 +55,8 @@ public class Config {
useTorrent = Boolean.parseBoolean(props.getProperty("xmage.torrent.use", "False"));
torrentUpRate = Integer.parseInt(props.getProperty("xmage.torrent.uprate", "50"));
torrentDownRate = Integer.parseInt(props.getProperty("xmage.torrent.downrate", "0"));
showClientConsole = Boolean.parseBoolean(props.getProperty("xmage.client.console", "True"));
showServerConsole = Boolean.parseBoolean(props.getProperty("xmage.server.console", "True"));

} catch (IOException ex) {
logger.error("Error: ", ex);
Expand Down Expand Up @@ -93,6 +99,14 @@ public static int getTorrentDownRate() {
return torrentDownRate;
}

public static boolean isShowClientConsole() {
return showClientConsole;
}

public static boolean isShowServerConsole() {
return showServerConsole;
}

public static void setInstalledJavaVersion(String version) {
installedJavaVersion = version;
}
Expand Down Expand Up @@ -124,6 +138,14 @@ public static void setTorrentUpRate(int rate) {
public static void setTorrentDownRate(int rate) {
torrentDownRate = rate;
}

public static void setShowClientConsole(boolean show) {
showClientConsole = show;
}

public static void setShowServerConsole(boolean show) {
showServerConsole = show;
}

public static void saveProperties() {
try {
Expand All @@ -134,6 +156,8 @@ public static void saveProperties() {
props.setProperty("xmage.client.javaopts", clientJavaOpts);
props.setProperty("xmage.server.javaopts", serverJavaOpts);
props.setProperty("xmage.home", homeURL);
props.setProperty("xmage.client.console", Boolean.toString(showClientConsole));
props.setProperty("xmage.server.console", Boolean.toString(showServerConsole));
props.setProperty("xmage.torrent.use", Boolean.toString(useTorrent));
props.setProperty("xmage.torrent.uprate", Integer.toString(torrentUpRate));
props.setProperty("xmage.torrent.downrate", Integer.toString(torrentDownRate));
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/xmage/launcher/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class SettingsDialog extends JDialog {
private JTextField txtServerJavaOpt;
private JCheckBox chkUseTorrent;
private JTextField txtXMageHome;
private JCheckBox chkShowClientConsole;
private JCheckBox chkShowServerConsole;
private JSpinner spnUpRate;
private JSpinner spnDownRate;

Expand Down Expand Up @@ -83,6 +85,30 @@ public void windowClosing(WindowEvent e) {
constraints.fill = GridBagConstraints.BOTH;
panel1.add(txtXMageHome, constraints);

label = new JLabel("Show Client Console:");
constraints.anchor = GridBagConstraints.EAST;
constraints.gridwidth = 1;
constraints.fill = GridBagConstraints.NONE;
panel1.add(label, constraints);

chkShowClientConsole = new JCheckBox();
chkShowClientConsole.setSelected(Config.isShowClientConsole());
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
panel1.add(chkShowClientConsole, constraints);

label = new JLabel("Show Server Console:");
constraints.anchor = GridBagConstraints.EAST;
constraints.gridwidth = 1;
constraints.fill = GridBagConstraints.NONE;
panel1.add(label, constraints);

chkShowServerConsole = new JCheckBox();
chkShowServerConsole.setSelected(Config.isShowServerConsole());
constraints.gridwidth = GridBagConstraints.REMAINDER;
constraints.fill = GridBagConstraints.BOTH;
panel1.add(chkShowServerConsole, constraints);

// Java settings panel
panel2 = new JPanel();
layout = new GridBagLayout();
Expand Down Expand Up @@ -196,6 +222,8 @@ private void handleDone() {
Config.setClientJavaOpts(this.txtClientJavaOpt.getText());
Config.setServerJavaOpts(this.txtServerJavaOpt.getText());
Config.setXMageHome(this.txtXMageHome.getText());
Config.setShowClientConsole(this.chkShowClientConsole.isSelected());
Config.setShowServerConsole(this.chkShowServerConsole.isSelected());
Config.setUseTorrent(this.chkUseTorrent.isSelected());
Config.setTorrentUpRate((Integer)spnUpRate.getValue());
Config.setTorrentDownRate((Integer)spnDownRate.getValue());
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/xmage/launcher/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JTextArea;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -97,23 +96,23 @@ private static String readAll(Reader rd) throws IOException {
return sb.toString();
}

public static Process launchClientProcess(JTextArea out) {
public static Process launchClientProcess() {

return launchProcess("mage.client.MageFrame", Config.getClientJavaOpts(), "mage-client", out);
return launchProcess("mage.client.MageFrame", Config.getClientJavaOpts(), "mage-client");

}

public static Process launchServerProcess(JTextArea out) {
public static Process launchServerProcess() {

return launchProcess("mage.server.Main", Config.getServerJavaOpts(), "mage-server", out);
return launchProcess("mage.server.Main", Config.getServerJavaOpts(), "mage-server");

}

public static void stopProcess(Process p) {
p.destroy();
}

private static Process launchProcess(String main, String args, String path, JTextArea out) {
private static Process launchProcess(String main, String args, String path) {

File installPath = Utilities.getInstallPath();
File javaHome;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/xmage/launcher/XMageLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private XMageLauncher() {

Random r = new Random();
int imageNum = 1 + r.nextInt(17);
ImageIcon background = new ImageIcon(new ImageIcon(XMageLauncher.class.getResource("/backgrounds/" + Integer.toString(imageNum) + ".jpg")).getImage().getScaledInstance(800, 500, Image.SCALE_SMOOTH));
ImageIcon background = new ImageIcon(new ImageIcon(XMageLauncher.class.getResource("/backgrounds/" + Integer.toString(imageNum) + ".jpg")).getImage().getScaledInstance(800, 480, Image.SCALE_SMOOTH));
mainPanel = new JLabel(background) {
@Override
public Dimension getPreferredSize() {
Expand Down Expand Up @@ -377,15 +377,15 @@ private static void openWebpage(String uri) {
}

private void handleClient() {
Process p = Utilities.launchClientProcess(textArea);
clientConsole.setVisible(true);
Process p = Utilities.launchClientProcess();
clientConsole.setVisible(Config.isShowClientConsole());
clientConsole.start(p);
}

private void handleServer() {
if (serverProcess == null) {
serverProcess = Utilities.launchServerProcess(textArea);
serverConsole.setVisible(true);
serverProcess = Utilities.launchServerProcess();
serverConsole.setVisible(Config.isShowServerConsole());
serverConsole.start(serverProcess);
btnLaunchServer.setText(messages.getString("stopServer"));
btnLaunchClientServer.setEnabled(false);
Expand Down

0 comments on commit 9a755c3

Please sign in to comment.