crashtest/src/de/ctdo/crashtest/SteuerungFrame.java

134 lines
3.8 KiB
Java

package de.ctdo.crashtest;
import org.bff.javampd.MPD;
import org.bff.javampd.MPDPlayer;
import org.bff.javampd.exception.MPDConnectionException;
import org.bff.javampd.exception.MPDResponseException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.UnknownHostException;
public class SteuerungFrame extends JFrame implements StateChangeListener {
private JPanel pnlRoot;
private JLabel lblState;
private char lastKey = ' ';
private MPD mpd;
private MPDPlayer player;
Statemachine machine = new Statemachine();
BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
public SteuerungFrame() {
//setType(Type.UTILITY);
setBackground(Color.black);
setBounds(200,200, 400, 200);
machine.addStateChangedListener(this);
initGui();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
try {
mpd = new MPD("dampfradio.raum.chaostreff-dortmund.de", 6600);
player = mpd.getMPDPlayer();
} catch (UnknownHostException e) {
e.printStackTrace();
return;
} catch (MPDConnectionException e) {
e.printStackTrace();
return;
}
addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
lastKey = e.getKeyChar();
//System.out.println(e.getKeyChar());
machine.handleInput(e.getKeyChar());
//bunti.setPar56(1, 0xff, 0xff, 0xff);
updateGui();
}
});
addWindowStateListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
if(mpd != null) mpd.close();
} catch (MPDConnectionException e1) {
e1.printStackTrace();
} catch (MPDResponseException e1) {
e1.printStackTrace();
}
}
});
}
@Override
public void stateChanged(Statemachine.state newState) {
updateGui();
switch (newState) {
case IDLE:
bunti.setPar56(0,0,0,0);
bunti.setPar56(1,0,0,0);
bunti.setPar56(2,0,0,0);
bunti.setPar56(3,0,0,0);
bunti.setLampel(false,false,false);
break;
case ENTERED_ROOM:
bunti.setLampel(true,false,false);
break;
case TABLE_GAME_ONE:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_TWO:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_THREE:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_FOUR:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_FIVE:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_SIX:
bunti.setLampel(false,true,false);
break;
case TABLE_GAME_SEVEN:
bunti.setLampel(false,false,true);
break;
}
}
private void initGui() {
Container pane = getContentPane();
pnlRoot = new JPanel(new FlowLayout());
lblState = new JLabel("", JLabel.LEFT);
pnlRoot.add(lblState);
pane.add(pnlRoot);
updateGui();
}
private void updateGui() {
lblState.setText("<html>LastKey: " + lastKey + "<br>CurrentState: " +
machine.getCurrentState() + "<br>ChangeCounter: " +
machine.getStateChangeCounter() + "</html>");
}
}