2012-05-09 23:04:14 +00:00
|
|
|
package de.ctdo.crashtest;
|
|
|
|
|
2012-05-10 13:53:18 +00:00
|
|
|
import org.bff.javampd.MPD;
|
|
|
|
import org.bff.javampd.MPDPlayer;
|
|
|
|
import org.bff.javampd.exception.MPDConnectionException;
|
|
|
|
import org.bff.javampd.exception.MPDResponseException;
|
|
|
|
|
2012-05-09 23:04:14 +00:00
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.*;
|
2012-05-10 13:53:18 +00:00
|
|
|
import java.net.UnknownHostException;
|
2012-05-09 23:04:14 +00:00
|
|
|
|
2012-05-10 13:53:18 +00:00
|
|
|
public class SteuerungFrame extends JFrame implements StateChangeListener {
|
|
|
|
private JPanel pnlRoot;
|
|
|
|
private JLabel lblState;
|
|
|
|
private char lastKey = ' ';
|
|
|
|
private MPD mpd;
|
|
|
|
private MPDPlayer player;
|
2012-05-09 23:04:14 +00:00
|
|
|
|
|
|
|
Statemachine machine = new Statemachine();
|
2012-05-10 13:53:18 +00:00
|
|
|
BuntiClient bunti = new BuntiClient("bunti.ctdo.de", 8080);
|
2012-05-09 23:04:14 +00:00
|
|
|
|
|
|
|
public SteuerungFrame() {
|
2012-05-10 09:06:16 +00:00
|
|
|
//setType(Type.UTILITY);
|
2012-05-09 23:04:14 +00:00
|
|
|
setBackground(Color.black);
|
2012-05-10 13:53:18 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-05-09 23:04:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
addKeyListener(new KeyAdapter() {
|
|
|
|
@Override
|
|
|
|
public void keyTyped(KeyEvent e) {
|
2012-05-10 13:53:18 +00:00
|
|
|
lastKey = e.getKeyChar();
|
2012-05-10 09:06:16 +00:00
|
|
|
//System.out.println(e.getKeyChar());
|
|
|
|
machine.handleInput(e.getKeyChar());
|
2012-05-10 13:53:18 +00:00
|
|
|
//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();
|
|
|
|
}
|
2012-05-09 23:04:14 +00:00
|
|
|
}
|
|
|
|
});
|
2012-05-10 13:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
2012-05-09 23:04:14 +00:00
|
|
|
|
|
|
|
}
|
2012-05-10 13:53:18 +00:00
|
|
|
|
|
|
|
private void initGui() {
|
|
|
|
Container pane = getContentPane();
|
2012-05-09 23:04:14 +00:00
|
|
|
|
2012-05-10 13:53:18 +00:00
|
|
|
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>");
|
|
|
|
|
|
|
|
}
|
2012-05-09 23:04:14 +00:00
|
|
|
}
|