117 lines
3.9 KiB
Java
117 lines
3.9 KiB
Java
package de.ctdo.crashtest.cardplayer;
|
|
|
|
import de.ctdo.crashtest.cardplayer.irc.*;
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.io.*;
|
|
import java.util.Vector;
|
|
|
|
public class MainFrame extends JFrame {
|
|
private IrcClient irc;
|
|
private JList<String> jListWall;
|
|
private JList<String> jListStates;
|
|
|
|
public MainFrame() {
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
setTitle("CrastestCardPlayer");
|
|
setPreferredSize(new Dimension(800,500));
|
|
irc = new IrcClient(HostHelper.getHostName().toLowerCase(), "#crashtest", "localhost", 8888);
|
|
|
|
initGui();
|
|
setVisible(true);
|
|
}
|
|
|
|
private void initGui() {
|
|
Container contentPane = this.getContentPane();
|
|
|
|
jListWall = new JList<String>(readData());
|
|
jListWall.setLayoutOrientation(JList.VERTICAL);
|
|
jListWall.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
jListWall.addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
if (e.getClickCount() == 2) {
|
|
int index = jListWall.locationToIndex(e.getPoint());
|
|
ListModel dlm = jListWall.getModel();
|
|
Object item = dlm.getElementAt(index);
|
|
jListWall.ensureIndexIsVisible(index);
|
|
if (irc != null) irc.say(">wall " + item);
|
|
}
|
|
}
|
|
});
|
|
|
|
JScrollPane listScroller = new JScrollPane(jListWall);
|
|
listScroller.setPreferredSize(new Dimension(600, 500));
|
|
|
|
contentPane.setLayout(new BorderLayout());
|
|
contentPane.add(listScroller, BorderLayout.WEST);
|
|
|
|
Vector<String> states = new Vector<String>();
|
|
states.add("IDLE");
|
|
states.add("ENTERED_ROOM");
|
|
states.add("TABLE_GAME_ONE");
|
|
states.add("TABLE_GAME_TWO");
|
|
states.add("TABLE_GAME_THREE");
|
|
states.add("TABLE_GAME_FOUR");
|
|
states.add("TABLE_GAME_FIVE");
|
|
states.add("TABLE_GAME_SIX");
|
|
states.add("TABLE_GAME_DONE");
|
|
states.add("ROKET_STARTED");
|
|
states.add("ROKET_DONE");
|
|
states.add("NEUTRAL");
|
|
|
|
jListStates = new JList<String>(states);
|
|
jListStates.setLayoutOrientation(JList.VERTICAL);
|
|
jListStates.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
jListStates.addMouseListener(new MouseAdapter() {
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
if (e.getClickCount() == 2) {
|
|
int index = jListStates.locationToIndex(e.getPoint());
|
|
ListModel dlm = jListStates.getModel();
|
|
Object item = dlm.getElementAt(index);
|
|
jListStates.ensureIndexIsVisible(index);
|
|
if (irc != null) irc.say(">state " + item);
|
|
}
|
|
}
|
|
});
|
|
|
|
listScroller = new JScrollPane(jListStates);
|
|
contentPane.add(listScroller);
|
|
|
|
pack();
|
|
}
|
|
|
|
|
|
private Vector<String> readData() {
|
|
try {
|
|
File file;
|
|
BufferedReader br;
|
|
|
|
file = new File ("messages.txt");
|
|
if(file.exists()) {
|
|
br = new BufferedReader(new FileReader (file));
|
|
} else {
|
|
InputStream is = Main.class.getResourceAsStream("/messages.txt");
|
|
br = new BufferedReader(new InputStreamReader(is));
|
|
}
|
|
|
|
Vector<String> lines = new Vector<String>();
|
|
String line;
|
|
while((line=br.readLine())!=null) {
|
|
lines.add(line);
|
|
}
|
|
|
|
return lines;
|
|
} catch(Exception e) {
|
|
e.printStackTrace();
|
|
Vector<String> vector = new Vector<String>();
|
|
vector.add("could not read the input file...");
|
|
return vector;
|
|
}
|
|
}
|
|
|
|
}
|