Browse Source

Minor changes

Cleanups, refactorings
master
Sogomn 9 years ago
parent
commit
3fea654e5a
  1. 30
      Ratty/src/de/sogomn/rat/Ratty.java
  2. 4
      Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java
  3. 2
      Ratty/src/de/sogomn/rat/server/gui/RattyGui.java
  4. 25
      Ratty/src/de/sogomn/rat/server/gui/RattyGuiController.java
  5. 5
      Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

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

@ -1,11 +1,17 @@
package de.sogomn.rat;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import de.sogomn.engine.util.FileUtils;
import de.sogomn.rat.server.ActiveServer;
@ -38,6 +44,23 @@ public final class Ratty {
//...
}
private static void setLookAndFeel() {
final NimbusLookAndFeel nimbus = new NimbusLookAndFeel();
final UIDefaults defaults = nimbus.getDefaults();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
defaults.put("nimbusBase", Color.LIGHT_GRAY);
defaults.put("cotrol", Color.LIGHT_GRAY);
try {
UIManager.setLookAndFeel(nimbus);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
private static void readConnectionData() throws ArrayIndexOutOfBoundsException, NumberFormatException {
final String[] lines = FileUtils.readInternalLines(CONNECTION_DATA_FILE_NAME);
final String addressString = lines[0].trim();
@ -110,6 +133,7 @@ public final class Ratty {
}
public static void main(final String[] args) {
setLookAndFeel();
readConnectionData();
if (DEBUG) {
@ -131,11 +155,9 @@ public final class Ratty {
} else {
final int port = getPortInput();
if (port == -1) {
return;
if (port != -1) {
startServer(port);
}
startServer(port);
}
}

4
Ratty/src/de/sogomn/rat/server/gui/DisplayPanel.java

@ -34,8 +34,8 @@ public final class DisplayPanel extends AbstractListenerContainer<IGuiController
//...
}
private Screen createScreen(final int width, final int height) {
final Screen screen = new Screen(width, height);
private Screen createScreen(final int screenWidth, final int screenHeight) {
final Screen screen = new Screen(screenWidth, screenHeight);
screen.setResizeBehavior(ResizeBehavior.KEEP_ASPECT_RATIO);
screen.setTitle(title);

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

@ -190,7 +190,7 @@ public final class RattyGui extends AbstractListenerContainer<IGuiController> {
}
public String getInput() {
final String input = JOptionPane.showInputDialog(frame);
final String input = JOptionPane.showInputDialog(frame, null);
return input;
}

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

@ -1,5 +1,6 @@
package de.sogomn.rat.server.gui;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import de.sogomn.rat.ActiveConnection;
@ -35,6 +36,12 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
* ==================================================
*/
private void showScreenshot(final ServerClient client, final ScreenshotPacket packet) {
final BufferedImage image = packet.getImage();
client.displayPanel.showImage(image);
}
private PopupPacket createPopupPacket() {
final String input = gui.getInput();
@ -72,14 +79,26 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
}
private boolean handlePacket(final ServerClient client, final IPacket packet) {
return false;
final Class<? extends IPacket> clazz = packet.getClass();
boolean consumed = true;
if (clazz == ScreenshotPacket.class) {
final ScreenshotPacket screenshot = (ScreenshotPacket)packet;
showScreenshot(client, screenshot);
} else {
consumed = false;
}
return consumed;
}
private void handleCommand(final ServerClient client, final String command) {
//...
}
private IPacket getPacket(final String command, final ServerClient client) {
private IPacket getPacket(final ServerClient client, final String command) {
IPacket packet = null;
if (command == RattyGui.FREE) {
@ -172,7 +191,7 @@ public final class RattyGuiController implements IServerObserver, IConnectionObs
@Override
public void userInput(final String command) {
final ServerClient client = gui.getLastServerClientClicked();
final IPacket packet = getPacket(command, client);
final IPacket packet = getPacket(client, command);
handleCommand(client, command);

5
Ratty/src/de/sogomn/rat/server/gui/ServerClient.java

@ -18,6 +18,11 @@ final class ServerClient {
displayPanel = new DisplayPanel();
fileTree = new FileTree();
final String address = connection.getAddress();
displayPanel.setTitle(address);
fileTree.setTitle(address);
}
public void logIn(final String name, final String os, final String version) {

Loading…
Cancel
Save