From 690012182907a2e14d9b7c3fdca1d1565be3ee2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Sun, 3 Jun 2012 15:45:39 +0200 Subject: [PATCH] some small refactorings. made the hosts configurable --- src/de/ctdo/crashtest/game/TheGame.java | 6 ++--- src/de/ctdo/crashtest/gui/MainGui.java | 6 ++++- src/de/ctdo/crashtest/irc/IrcClient.java | 11 ++++---- src/de/ctdo/crashtest/mpd/MPDController.java | 28 +++++++++----------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/de/ctdo/crashtest/game/TheGame.java b/src/de/ctdo/crashtest/game/TheGame.java index a92f8a0..b5c06d6 100644 --- a/src/de/ctdo/crashtest/game/TheGame.java +++ b/src/de/ctdo/crashtest/game/TheGame.java @@ -23,10 +23,10 @@ public class TheGame implements StateChangeListener, GuiEventListener, IRCEventL public TheGame(IGuiControl guiControl) { this.guiControl = guiControl; - this.ircClient = new IrcClient(); - this.machine = new Statemachine(); + this.ircClient = new IrcClient("crashtest", "#crashtest","irc.ctdo.de"); this.bunti = new BuntiClient("bunti.ctdo.de", 8080); - this.mpdController = new MPDController(); + this.mpdController = new MPDController("dampfradio.raum.ctdo.de"); + this.machine = new Statemachine(); initGame(); } diff --git a/src/de/ctdo/crashtest/gui/MainGui.java b/src/de/ctdo/crashtest/gui/MainGui.java index 871417a..fd69252 100644 --- a/src/de/ctdo/crashtest/gui/MainGui.java +++ b/src/de/ctdo/crashtest/gui/MainGui.java @@ -17,8 +17,10 @@ public class MainGui extends JFrame implements IGuiControl { public MainGui() { initGui(); setDefaultCloseOperation(EXIT_ON_CLOSE); - setVisible(true); + setBounds(0,0, 1280, 1024); + setExtendedState(Frame.MAXIMIZED_BOTH); + setUndecorated(true); addKeyListener(new KeyAdapter() { @Override @@ -39,6 +41,8 @@ public class MainGui extends JFrame implements IGuiControl { } } }); + + setVisible(true); } // diff --git a/src/de/ctdo/crashtest/irc/IrcClient.java b/src/de/ctdo/crashtest/irc/IrcClient.java index cb2b5c3..a399fc6 100644 --- a/src/de/ctdo/crashtest/irc/IrcClient.java +++ b/src/de/ctdo/crashtest/irc/IrcClient.java @@ -22,11 +22,12 @@ public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventL private final List listenerListIRC = new ArrayList(); private final static String CHANNEL = "#crashtest"; private Session ircsession; + private final String channel; - public IrcClient() { - ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl("crashtest", "crashtest", - "crashtest2", "crashtest3")); - ircsession = ircConnection.requestConnection("irc.chaostreff-dortmund.de"); + public IrcClient(String nick, String channel, String server) { + this.channel = channel; + ConnectionManager ircConnection = new ConnectionManager(new ProfileImpl(nick,nick, nick+2, nick+3)); + ircsession = ircConnection.requestConnection(server); ircsession.addIRCEventListener(this); } @@ -34,7 +35,7 @@ public class IrcClient implements IIrcClient, jerklib.events.listeners.IRCEventL public void recieveEvent(IRCEvent ircEvent) { if(ircEvent instanceof ConnectionCompleteEvent) { - ircEvent.getSession().joinChannel(CHANNEL); + ircEvent.getSession().joinChannel(channel); } else if (ircEvent instanceof JoinCompleteEvent) { JoinCompleteEvent jce = (JoinCompleteEvent) ircEvent; diff --git a/src/de/ctdo/crashtest/mpd/MPDController.java b/src/de/ctdo/crashtest/mpd/MPDController.java index 588dad4..100675b 100644 --- a/src/de/ctdo/crashtest/mpd/MPDController.java +++ b/src/de/ctdo/crashtest/mpd/MPDController.java @@ -1,6 +1,5 @@ package de.ctdo.crashtest.mpd; -import de.ctdo.crashtest.game.TheGame; import de.ctdo.crashtest.log.Logger; import org.bff.javampd.MPD; import org.bff.javampd.MPDDatabase; @@ -14,27 +13,17 @@ import org.bff.javampd.objects.MPDSong; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; /** - * @author: lucas - * @date: 01.06.12 10:34 + * A MPD abstraction to the org.bff.javampd library */ public class MPDController implements IMPDController { - private MPD mpd; - public MPDController() { - initMPD(); - - } - - private void initMPD() { + public MPDController(String host) { try { - mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600); - - + mpd = new MPD(host, 6600); } catch (UnknownHostException e) { Logger.sLog("MPD error: " + e.getMessage()); } catch (MPDConnectionException e) { @@ -42,7 +31,12 @@ public class MPDController implements IMPDController { } } - + /** + * Play a song, defined by artist and track title + * Song gets added to current playlist and is played. + * @param artist Artist of the track to play + * @param title Title of the track to play + */ @Override public void playSong(final String artist, final String title) { if(mpd != null) { @@ -109,6 +103,10 @@ public class MPDController implements IMPDController { } } + /** + * Sets the current mpd volume + * @param volume the volume in percent (0-100) + */ @Override public void setVolume(final int volume) { if(mpd != null) {