Refactoring frontend
This commit is contained in:
parent
97c88c46bb
commit
10595f5bab
43 changed files with 1348 additions and 1120 deletions
|
|
@ -3,6 +3,10 @@ package com.texttwist.client;
|
|||
import com.texttwist.client.services.GameService;
|
||||
import com.texttwist.client.services.AuthService;
|
||||
import com.texttwist.client.pages.HomePage;
|
||||
import com.texttwist.client.services.NotificationClientService;
|
||||
import constants.Config;
|
||||
import interfaces.INotificationClient;
|
||||
import interfaces.INotificationServer;
|
||||
import models.Session;
|
||||
import utilities.Logger;
|
||||
import javax.swing.*;
|
||||
|
|
@ -10,6 +14,16 @@ import java.awt.*;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
|
|
@ -17,12 +31,22 @@ import java.lang.management.ManagementFactory;
|
|||
* Here is possible to declare services globally accessible.
|
||||
*/
|
||||
public class App extends JFrame {
|
||||
|
||||
private static InetSocketAddress clientTCPSocketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort);
|
||||
public static InetSocketAddress clientUDPSocketAddress = new InetSocketAddress(Config.WordsReceiverServerURI, Config.WordsReceiverServerPort);
|
||||
private static InetAddress clientMulticastSocketAddress;
|
||||
|
||||
public static AuthService authService;
|
||||
public static GameService gameService;
|
||||
public static Logger logger;
|
||||
public static Session session;
|
||||
public static JFrame app;
|
||||
|
||||
public static INotificationClient notificationStub;
|
||||
public static MulticastSocket clientMulticast;
|
||||
public static SocketChannel clientTCP;
|
||||
public static DatagramChannel clientUDP;
|
||||
|
||||
public App() throws IOException {
|
||||
setPreferredSize( new Dimension( 640, 480 ));
|
||||
setSize(new Dimension(640,480));
|
||||
|
|
@ -53,6 +77,54 @@ public class App extends JFrame {
|
|||
new HomePage(this);
|
||||
}
|
||||
|
||||
public static void registerForNotifications() throws RemoteException, NotBoundException {
|
||||
|
||||
Registry registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
|
||||
INotificationClient callbackObj = new NotificationClientService();
|
||||
notificationStub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0);
|
||||
INotificationServer notificationServer = (INotificationServer) registry.lookup(Config.NotificationServerName);
|
||||
notificationServer.registerForCallback(notificationStub);
|
||||
}
|
||||
|
||||
public static void openClientTCPSocket(){
|
||||
try {
|
||||
clientTCP = SocketChannel.open(clientTCPSocketAddress);
|
||||
clientTCP.configureBlocking(false);
|
||||
} catch (IOException e) {
|
||||
logger.write("APP: Can't open client TCP socket!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void openClientMulticastSocket(Integer multicastId){
|
||||
try {
|
||||
App.gameService.setMulticastId(multicastId);
|
||||
clientMulticastSocketAddress = InetAddress.getByName(Config.ScoreMulticastServerURI);
|
||||
clientMulticast = new MulticastSocket(gameService.multicastId);
|
||||
clientMulticast.joinGroup(clientMulticastSocketAddress);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeClientMulticastSocket(){
|
||||
//Leave group and close multicast socket
|
||||
try {
|
||||
App.clientMulticast.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI));
|
||||
App.clientMulticast.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void openClientUDPSocket(){
|
||||
try {
|
||||
clientUDP = DatagramChannel.open();
|
||||
clientUDP.bind(null);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Point getWindowsPosition(){
|
||||
return new Point(app.getX(), app.getY());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ package com.texttwist.client.controllers;
|
|||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.tasks.SendWords;
|
||||
import com.texttwist.client.tasks.StartGame;
|
||||
import com.texttwist.client.tasks.WaitForPlayers;
|
||||
import com.texttwist.client.tasks.WaitForScore;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.texttwist.client.App.gameService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
|
|
@ -14,26 +17,42 @@ import javax.swing.*;
|
|||
*/
|
||||
public class GameController {
|
||||
|
||||
private GamePage game;
|
||||
|
||||
public GameController(GamePage game){
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public SwingWorker waitForPlayers(SwingWorker callback) {
|
||||
return new WaitForPlayers(callback);
|
||||
}
|
||||
private GamePage gamePage;
|
||||
|
||||
private SwingWorker waitForScore(SwingWorker callback){
|
||||
return new WaitForScore(callback);
|
||||
}
|
||||
|
||||
public SwingWorker sendWords(SwingWorker callback){
|
||||
return new SendWords(App.gameService.words, waitForScore(callback));
|
||||
private SwingWorker sendWords(SwingWorker callback){
|
||||
return new SendWords(gameService.words, waitForScore(callback));
|
||||
}
|
||||
|
||||
public SwingWorker startGame() {
|
||||
return new StartGame(App.gameService.letters, game);
|
||||
public GameController(GamePage gamePage){
|
||||
this.gamePage = gamePage;
|
||||
}
|
||||
|
||||
public SwingWorker waitForPlayers(Callable<Void> callback) {
|
||||
return new WaitForPlayers(callback);
|
||||
}
|
||||
|
||||
public Callable<Void> startGame = new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
App.gameService.start();
|
||||
gamePage.showGameIsReadyAlert();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
public DefaultListModel<String> getLetters() {
|
||||
return gameService.getLetters();
|
||||
}
|
||||
|
||||
public SwingWorker timeIsOver(SwingWorker callback) {
|
||||
return sendWords(callback);
|
||||
}
|
||||
|
||||
public DefaultListModel<String> getWords(){
|
||||
return gameService.getWords();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.HighscoresPage;
|
||||
import com.texttwist.client.tasks.FetchHighscore;
|
||||
import javafx.util.Pair;
|
||||
import javax.swing.*;
|
||||
import java.io.ObjectOutput;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.texttwist.client.App.gameService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
|
|
@ -12,18 +15,12 @@ import javax.swing.*;
|
|||
*/
|
||||
public class HighscoresController {
|
||||
|
||||
private HighscoresPage highscoresPage;
|
||||
|
||||
public HighscoresController(HighscoresPage highscoresPage){
|
||||
this.highscoresPage = highscoresPage;
|
||||
}
|
||||
|
||||
public SwingWorker fetchHighscores () {
|
||||
return new FetchHighscore(highscoresPage);
|
||||
public SwingWorker fetchHighscores(Callable<Void> callback) {
|
||||
return new FetchHighscore(callback);
|
||||
}
|
||||
|
||||
public DefaultListModel<Pair<String,Integer>> getRanks(Boolean isPartialRank) {
|
||||
return isPartialRank ? App.gameService.ranks : App.gameService.globalRanks;
|
||||
return isPartialRank ? gameService.ranks : gameService.globalRanks;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import models.User;
|
|||
import java.net.MalformedURLException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import static com.texttwist.client.App.authService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 20/06/2017.
|
||||
|
|
@ -15,7 +16,7 @@ import java.rmi.RemoteException;
|
|||
public class HomeController {
|
||||
|
||||
public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
Response res = App.authService.login(userName,password);
|
||||
Response res = authService.login(userName,password);
|
||||
if (res.code == 200){
|
||||
App.session = (new Session(new User(userName,password,0), res.data.get("token").toString()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 13/072017.
|
||||
* Description: Controller of the Match Request Page
|
||||
*/
|
||||
public class MatchRequestController {
|
||||
|
||||
public DefaultListModel<String> getPendingList(){
|
||||
return App.gameService.pendingList;
|
||||
}
|
||||
|
||||
public void joinMatch(String matchName){
|
||||
App.gameService.joinMatch(matchName);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import static com.texttwist.client.App.gameService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 18/06/2017.
|
||||
|
|
@ -10,12 +9,7 @@ import java.io.IOException;
|
|||
*/
|
||||
public class MatchSetupController {
|
||||
|
||||
public Object play(DefaultListModel<String> userNames) {
|
||||
try {
|
||||
return App.gameService.play(userNames);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
public void play(DefaultListModel<String> userNames) {
|
||||
gameService.beginMatch(userNames);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import interfaces.INotificationClient;
|
||||
import models.Response;
|
||||
import models.Session;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import static com.texttwist.client.App.authService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 17/06/2017.
|
||||
|
|
@ -13,10 +15,14 @@ import java.rmi.RemoteException;
|
|||
*/
|
||||
public class MenuController {
|
||||
|
||||
public void logout(String userName, INotificationClient stub) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
Response res = App.authService.logout(userName, stub);
|
||||
public void logout() throws RemoteException, NotBoundException, MalformedURLException {
|
||||
Response res = authService.logout(App.session.account.userName, App.notificationStub);
|
||||
if (res.code == 200){
|
||||
App.session = null;
|
||||
}
|
||||
}
|
||||
|
||||
public Session getSession(){
|
||||
return App.session;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.texttwist.client.controllers;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import models.Response;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import static com.texttwist.client.App.authService;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 17/06/2017.
|
||||
|
|
@ -13,6 +13,6 @@ import java.rmi.RemoteException;
|
|||
public class RegisterController {
|
||||
|
||||
public Response register(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
return App.authService.register(userName,password);
|
||||
return authService.register(userName,password);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.GameController;
|
||||
import constants.Config;
|
||||
import constants.Palette;
|
||||
|
|
@ -8,10 +9,9 @@ import java.awt.*;
|
|||
import java.io.IOException;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.texttwist.client.App.gameService;
|
||||
|
||||
/**
|
||||
* GamePage Page
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
* Description: Game Page
|
||||
*/
|
||||
public class GamePage extends Page {
|
||||
|
||||
|
|
@ -19,24 +19,28 @@ public class GamePage extends Page {
|
|||
private GameController gameController;
|
||||
public Timer timer;
|
||||
|
||||
/*Spawning points fixed and not modifiable*/
|
||||
//All the spawning points
|
||||
private final DefaultListModel<Point> letterSpawningPoints = setLetterSpawningPoint();
|
||||
|
||||
/*Available spawning points*/
|
||||
//Available spawning points
|
||||
private DefaultListModel<Point> availableLetterSpawningPoint = new DefaultListModel<>();
|
||||
|
||||
public GamePage(JFrame window) throws IOException {
|
||||
super(window);
|
||||
gameController = new GameController(this);
|
||||
|
||||
//Reset and set spawning point for letters
|
||||
availableLetterSpawningPoint.clear();
|
||||
availableLetterSpawningPoint = letterSpawningPoints;
|
||||
gameController.waitForPlayers(gameController.startGame()).execute();
|
||||
|
||||
//Wait for players, then when all players joined start the game
|
||||
gameController.waitForPlayers(gameController.startGame).execute();
|
||||
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
/*Occupy a random position of the available spawning points, if positions ends (can't happen) use position (0,0)*/
|
||||
private Point occupyRandomPosition(){
|
||||
|
||||
if(availableLetterSpawningPoint.size() > 1) {
|
||||
int index = ThreadLocalRandom.current().nextInt(0, letterSpawningPoints.size() - 1);
|
||||
Point placeholder = letterSpawningPoints.get(index);
|
||||
|
|
@ -47,18 +51,6 @@ public class GamePage extends Page {
|
|||
return new Point(0,0);
|
||||
}
|
||||
|
||||
|
||||
private SwingWorker timeIsOver() {
|
||||
return gameController.sendWords(new SwingWorker() {
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
new HighscoresPage(window,true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private DefaultListModel<Point> setLetterSpawningPoint(){
|
||||
|
||||
DefaultListModel<Point> l = new DefaultListModel<>();
|
||||
|
|
@ -90,7 +82,7 @@ public class GamePage extends Page {
|
|||
public void showLetters(){
|
||||
|
||||
/* Place letters in an available random spawning point */
|
||||
DefaultListModel<String> letters = gameService.getLetters();
|
||||
DefaultListModel<String> letters = gameController.getLetters();
|
||||
for(int i = 0; i < letters.size()-1; i++){
|
||||
new TTLetter(
|
||||
occupyRandomPosition(),
|
||||
|
|
@ -103,6 +95,19 @@ public class GamePage extends Page {
|
|||
window.revalidate();
|
||||
}
|
||||
|
||||
public void showGameIsReadyAlert(){
|
||||
//Mostra pannello di conferma che le lettere sono tutte arrivate
|
||||
new TTDialog("success", "GameService is ready. Press OK to start!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
showLetters();
|
||||
timer.start();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
|
||||
|
|
@ -120,7 +125,7 @@ public class GamePage extends Page {
|
|||
new Point(150, 90),
|
||||
new Dimension(250, 40),
|
||||
"Insert word and Press ENTER!",
|
||||
gameService.getWords(),
|
||||
gameController.getWords(),
|
||||
gameContainer
|
||||
);
|
||||
|
||||
|
|
@ -129,7 +134,13 @@ public class GamePage extends Page {
|
|||
timer = addTimer(
|
||||
footer,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
|
||||
timeIsOver(),
|
||||
gameController.timeIsOver(new SwingWorker() {
|
||||
@Override
|
||||
protected Object doInBackground() throws Exception {
|
||||
new HighscoresPage(window,true);
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
Config.timeoutGame
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import java.io.IOException;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Highscores Page
|
||||
* Author: Lorenzo Iovino on 22/06/2017.
|
||||
* Description: Highscores Page
|
||||
*/
|
||||
public class HighscoresPage extends Page{
|
||||
|
||||
|
|
@ -18,26 +19,31 @@ public class HighscoresPage extends Page{
|
|||
public JFrame window;
|
||||
private HighscoresController highscoreController;
|
||||
|
||||
public HighscoresPage(JFrame window, Boolean isPartialScore) throws IOException {
|
||||
HighscoresPage(JFrame window, Boolean isPartialScore) throws IOException {
|
||||
super(window);
|
||||
this.window = window;
|
||||
this.isPartialScore = isPartialScore;
|
||||
highscoreController = new HighscoresController(this);
|
||||
highscoreController.fetchHighscores().execute();
|
||||
|
||||
highscoreController = new HighscoresController();
|
||||
highscoreController.fetchHighscores(showHighscoreList).execute();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
public void showHighscoreList(){
|
||||
new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(515, 142),
|
||||
highscoreController.getRanks(isPartialScore),
|
||||
highscoreContainer
|
||||
);
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
}
|
||||
public Callable<Void> showHighscoreList = new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(515, 142),
|
||||
highscoreController.getRanks(isPartialScore),
|
||||
highscoreContainer
|
||||
);
|
||||
window.revalidate();
|
||||
window.repaint();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
|
|
@ -51,7 +57,7 @@ public class HighscoresPage extends Page{
|
|||
root
|
||||
);
|
||||
|
||||
TTLabel title = new TTLabel(
|
||||
new TTLabel(
|
||||
this.isPartialScore ? new Point(150,0) : new Point(200,0),
|
||||
new Dimension(350,50),
|
||||
this.isPartialScore ? "Scores of the match" : "Highscores",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.controllers.HomeController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
|
@ -8,6 +9,10 @@ import javax.swing.*;
|
|||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 23/06/2017.
|
||||
* Description: Home Page
|
||||
*/
|
||||
public class HomePage extends Page {
|
||||
|
||||
private HomeController homeController;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.controllers.MatchRequestController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
|
|
@ -11,13 +11,16 @@ import java.io.IOException;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* MatchRequest Page
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
* Description: MatchRequest Page
|
||||
*/
|
||||
public class MatchRequestsPage extends Page{
|
||||
|
||||
public TTContainer matchsContainer;
|
||||
private MatchRequestController matchRequestController;
|
||||
|
||||
MatchRequestsPage(JFrame window) throws IOException {
|
||||
super(window);
|
||||
matchRequestController = new MatchRequestController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
|
@ -25,9 +28,9 @@ public class MatchRequestsPage extends Page{
|
|||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
matchsContainer = new TTContainer(
|
||||
TTContainer matchsContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
new Dimension(1150, 220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
|
|
@ -45,7 +48,7 @@ public class MatchRequestsPage extends Page{
|
|||
TTScrollList pendingMatches = new TTScrollList(
|
||||
new Point(20, 60),
|
||||
new Dimension(520, 142),
|
||||
App.gameService.pendingList,
|
||||
matchRequestController.getPendingList(),
|
||||
matchsContainer
|
||||
);
|
||||
|
||||
|
|
@ -56,7 +59,7 @@ public class MatchRequestsPage extends Page{
|
|||
JList thisList = (JList)evt.getSource();
|
||||
if (evt.getClickCount() == 2) {
|
||||
int index = thisList.locationToIndex(evt.getPoint());
|
||||
App.gameService.joinMatch(App.gameService.pendingList.get(index));
|
||||
matchRequestController.joinMatch(matchRequestController.getPendingList().get(index));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import java.awt.*;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* MatchSetup Page
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
* Description: MatchSetup Page
|
||||
*/
|
||||
public class MatchSetupPage extends Page{
|
||||
|
||||
|
|
@ -56,9 +57,10 @@ public class MatchSetupPage extends Page{
|
|||
"Play!",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//If notificationServer response ok, start play, else error
|
||||
return matchSetupController.play(searchUserBar.list);
|
||||
public Void call() throws Exception {
|
||||
//If notificationServer response ok, start beginMatch, else error
|
||||
matchSetupController.play(searchUserBar.list);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,26 +1,25 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.App;
|
||||
|
||||
import com.texttwist.client.controllers.MenuController;
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 17/06/2017.
|
||||
* Description: Menu Page
|
||||
*/
|
||||
public class MenuPage extends Page{
|
||||
|
||||
private TTContainer menuBar;
|
||||
private MenuController menuController;
|
||||
|
||||
public MenuPage(JFrame window) throws IOException {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
menuController = new MenuController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
|
|
@ -28,24 +27,24 @@ public class MenuPage extends Page{
|
|||
public void createUIComponents() throws IOException {
|
||||
addLogo(root);
|
||||
|
||||
menuBar = new TTContainer(
|
||||
TTContainer menuBar = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,280),
|
||||
new Dimension(1150, 280),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
|
||||
TTLabel playerToSendInvite_flavourText = new TTLabel(
|
||||
new TTLabel(
|
||||
new Point(25,15),
|
||||
new Dimension(350,20),
|
||||
"Welcome back, " + App.session.account.userName + "!",
|
||||
"Welcome back, " + menuController.getSession().account.userName + "!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton newMatch = new TTButton(
|
||||
new TTButton(
|
||||
new Point(25,70),
|
||||
new Dimension(250,75),
|
||||
"New GameService!",
|
||||
|
|
@ -59,7 +58,7 @@ public class MenuPage extends Page{
|
|||
menuBar
|
||||
);
|
||||
|
||||
TTButton matchRequests = new TTButton(
|
||||
new TTButton(
|
||||
new Point(290,70),
|
||||
new Dimension(250,75),
|
||||
"In pending",
|
||||
|
|
@ -73,14 +72,7 @@ public class MenuPage extends Page{
|
|||
menuBar
|
||||
);
|
||||
|
||||
TTCircleCounter circleCounter = new TTCircleCounter(
|
||||
new Point(290,70),
|
||||
new Dimension(25,25),
|
||||
menuBar.getGraphics(),
|
||||
menuBar
|
||||
);
|
||||
|
||||
TTButton highscores = new TTButton(
|
||||
new TTButton(
|
||||
new Point(25, 155),
|
||||
new Dimension(250, 75),
|
||||
"Highscores",
|
||||
|
|
@ -93,14 +85,14 @@ public class MenuPage extends Page{
|
|||
menuBar
|
||||
);
|
||||
|
||||
TTButton logout = new TTButton(
|
||||
new TTButton(
|
||||
new Point(290, 155),
|
||||
new Dimension(250, 75),
|
||||
"Logout",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
menuController.logout(App.session.account.userName, App.gameService.notificationStub);
|
||||
menuController.logout();
|
||||
return new HomePage(Page.window);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
|
|
@ -10,7 +11,8 @@ import java.io.IOException;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Base Page
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: Controller of the Home Page
|
||||
*/
|
||||
public class Page {
|
||||
|
||||
|
|
@ -38,18 +40,18 @@ public class Page {
|
|||
|
||||
public void addLogo(TTContainer parent) {
|
||||
TTContainer container = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150, 150),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
parent);
|
||||
null,
|
||||
new Dimension(1150, 150),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
parent);
|
||||
|
||||
try {
|
||||
TTImage logoImg = new TTImage(
|
||||
new Point(0, 10),
|
||||
new Dimension(1150, 150),
|
||||
new ImageIcon(new File("./Client/resources/images/logo.png").getCanonicalPath()),
|
||||
container);
|
||||
new TTImage(
|
||||
new Point(0, 10),
|
||||
new Dimension(1150, 150),
|
||||
new ImageIcon(new File("./Client/resources/images/logo.png").getCanonicalPath()),
|
||||
container);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -78,14 +80,14 @@ public class Page {
|
|||
}
|
||||
|
||||
public void addNext(TTContainer parent, String caption, Callable<Object> clickHandler) {
|
||||
TTLabelBtn next = new TTLabelBtn(
|
||||
new Point(500, 0),
|
||||
new Dimension(150, 50),
|
||||
caption,
|
||||
null,
|
||||
null,
|
||||
clickHandler,
|
||||
parent);
|
||||
new TTLabelBtn(
|
||||
new Point(500, 0),
|
||||
new Dimension(150, 50),
|
||||
caption,
|
||||
null,
|
||||
null,
|
||||
clickHandler,
|
||||
parent);
|
||||
}
|
||||
|
||||
public Timer addTimer(TTContainer parent, Font font, SwingWorker timerEndHandler, Integer value) {
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ import com.texttwist.client.controllers.RegisterController;
|
|||
import constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 16/06/2017.
|
||||
* Description: Register Page
|
||||
*/
|
||||
public class RegisterPage extends Page {
|
||||
|
||||
private TTContainer registerDataContainer;
|
||||
private RegisterController registerController;
|
||||
public RegisterPage(JFrame window) {
|
||||
|
||||
RegisterPage(JFrame window) {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
registerController = new RegisterController();
|
||||
|
|
@ -26,14 +26,14 @@ public class RegisterPage extends Page {
|
|||
@Override
|
||||
public void createUIComponents() {
|
||||
addLogo(root);
|
||||
registerDataContainer = new TTContainer(
|
||||
TTContainer registerDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,220),
|
||||
new Dimension(1150, 220),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root
|
||||
);
|
||||
TTLabel registerText = new TTLabel(
|
||||
new TTLabel(
|
||||
new Point(70,35),
|
||||
new Dimension(400,40),
|
||||
"Insert your datas and press Register!",
|
||||
|
|
@ -55,7 +55,7 @@ public class RegisterPage extends Page {
|
|||
registerDataContainer
|
||||
);
|
||||
|
||||
TTButton register = new TTButton(
|
||||
new TTButton(
|
||||
new Point(70,150),
|
||||
new Dimension(430,50),
|
||||
"Register!",
|
||||
|
|
@ -95,6 +95,5 @@ public class RegisterPage extends Page {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package com.texttwist.client.services;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Config;
|
||||
import interfaces.IAuth;
|
||||
|
|
@ -8,10 +9,11 @@ import java.net.MalformedURLException;
|
|||
import java.rmi.Naming;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
/**
|
||||
* Authentication Service
|
||||
* Author: Lorenzo Iovino on 17/06/2017.
|
||||
* Description: Auth Service.
|
||||
* Provide the interface for authentication
|
||||
*/
|
||||
public class AuthService {
|
||||
|
||||
|
|
@ -19,11 +21,9 @@ public class AuthService {
|
|||
|
||||
public Response login(String userName, String password) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
try {
|
||||
INotificationClient callbackObj = new NotificationClient();
|
||||
App.gameService.notificationStub = (INotificationClient) UnicastRemoteObject.exportObject(callbackObj, 0);
|
||||
App.gameService.notificationServer.registerForCallback(App.gameService.notificationStub);
|
||||
App.registerForNotifications();
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("AUTH SERVICE: Can't register for notification");
|
||||
}
|
||||
IAuth auth = (IAuth) Naming.lookup(baseUrl);
|
||||
return auth.login(userName, password);
|
||||
|
|
|
|||
|
|
@ -6,68 +6,38 @@ import com.texttwist.client.pages.MenuPage;
|
|||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.tasks.InvitePlayers;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import constants.Config;
|
||||
import interfaces.INotificationClient;
|
||||
import interfaces.INotificationServer;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 18/06/2017.
|
||||
* Author: Lorenzo Iovino on 18/06/2017.
|
||||
* Description: GameService.
|
||||
* Provide the interface for the game.
|
||||
*/
|
||||
public class GameService {
|
||||
|
||||
public Integer multicastId = 0 ;
|
||||
public DefaultListModel<String> pendingList = new DefaultListModel<String>();
|
||||
public DefaultListModel<String> words = new DefaultListModel<String>();
|
||||
public DefaultListModel<String> letters = new DefaultListModel<String>();
|
||||
public DefaultListModel<String> pendingList = new DefaultListModel<>();
|
||||
public DefaultListModel<String> words = new DefaultListModel<>();
|
||||
public DefaultListModel<String> letters = new DefaultListModel<>();
|
||||
public DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
public DefaultListModel<Pair<String,Integer>> ranks = new DefaultListModel<>();
|
||||
public INotificationClient notificationStub;
|
||||
public MulticastSocket multicastSocket;
|
||||
public SocketChannel clientSocket;
|
||||
public INotificationServer notificationServer;
|
||||
public Boolean gameIsStarted = false;
|
||||
private Boolean gameIsStarted = false;
|
||||
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
|
||||
public GameService(){
|
||||
|
||||
Registry registry = null;
|
||||
try {
|
||||
registry = LocateRegistry.getRegistry(Config.NotificationServerStubPort);
|
||||
notificationServer = (INotificationServer) registry.lookup(Config.NotificationServerName);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NotBoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
InetSocketAddress socketAddress = new InetSocketAddress(Config.GameServerURI, Config.GameServerPort);
|
||||
try {
|
||||
clientSocket = SocketChannel.open(socketAddress);
|
||||
clientSocket.configureBlocking(false);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
private void addToPendingList(String username) throws IOException {
|
||||
pendingList.addElement(username);
|
||||
}
|
||||
|
||||
public GameService(){
|
||||
App.openClientTCPSocket();
|
||||
}
|
||||
|
||||
public void newMatch(String userName) {
|
||||
//Add to pending invitation list
|
||||
//Add to pending invites list
|
||||
try {
|
||||
this.addToPendingList(userName);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -75,8 +45,8 @@ public class GameService {
|
|||
}
|
||||
|
||||
if(!App.gameService.gameIsStarted) {
|
||||
//Show invitation popup
|
||||
new TTDialog("success", "New invitation from: " + userName + "!",
|
||||
//Show invite popup
|
||||
new TTDialog("success", "New invite from: " + userName + "!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
|
|
@ -93,7 +63,6 @@ public class GameService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public DefaultListModel<String> getLetters(){
|
||||
return App.gameService.letters;
|
||||
}
|
||||
|
|
@ -107,6 +76,7 @@ public class GameService {
|
|||
}
|
||||
|
||||
public void joinMatch(String matchName) {
|
||||
|
||||
//Clear pending invitation list and join selected match
|
||||
if(!gameIsStarted) {
|
||||
this.pendingList.clear();
|
||||
|
|
@ -116,8 +86,8 @@ public class GameService {
|
|||
Message message = new Message("JOIN_GAME", App.session.account.userName, App.session.token, matchNames);
|
||||
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
clientSocket.write(buffer);
|
||||
ByteBuffer buffer = ByteBuffer.wrap(byteMessage);
|
||||
App.clientTCP.write(buffer);
|
||||
new GamePage(Page.window);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
|
@ -126,27 +96,20 @@ public class GameService {
|
|||
}
|
||||
}
|
||||
|
||||
public Object play(DefaultListModel<String> userNames) throws IOException {
|
||||
SwingWorker worker = new InvitePlayers(userNames,clientSocket);
|
||||
worker.execute();
|
||||
return null;
|
||||
//Start game and wait for other players
|
||||
public void beginMatch(DefaultListModel<String> userNames) {
|
||||
new InvitePlayers(userNames).execute();
|
||||
}
|
||||
|
||||
public Void start(){
|
||||
App.gameService.gameIsStarted = true;
|
||||
return null;
|
||||
public void start(){
|
||||
gameIsStarted = true;
|
||||
}
|
||||
|
||||
public Void stop(){
|
||||
App.gameService.gameIsStarted = false;
|
||||
return null;
|
||||
public void stop(){
|
||||
gameIsStarted = false;
|
||||
}
|
||||
|
||||
public void setMulticastId(Integer multicastId){
|
||||
this.multicastId = multicastId;
|
||||
}
|
||||
|
||||
private void addToPendingList(String username) throws IOException {
|
||||
pendingList.addElement(username);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,18 @@
|
|||
package com.texttwist.client.services;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import interfaces.INotificationClient;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
/**
|
||||
* Created by loke on 15/06/2017.
|
||||
* Author: Lorenzo Iovino on 15/06/2017.
|
||||
* Description: Provide the interface for the notifications.
|
||||
*/
|
||||
public class NotificationClient implements INotificationClient {
|
||||
|
||||
|
||||
public NotificationClient() throws RemoteException {
|
||||
}
|
||||
public class NotificationClientService implements INotificationClient {
|
||||
|
||||
@Override
|
||||
public Response sendInvite(String userName, DefaultListModel<String> users) throws RemoteException {
|
||||
public void sendInvite(String userName, DefaultListModel<String> users) throws RemoteException {
|
||||
App.logger.write("Invoked invitation with username =" + userName + "|" + users.toString() );
|
||||
|
||||
if(App.session != null) {
|
||||
|
|
@ -27,6 +23,5 @@ public class NotificationClient implements INotificationClient {
|
|||
App.logger.write("User " + userName + " is slogged");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,24 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.HighscoresPage;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Job: FetchHighscore
|
||||
* Author: Lorenzo Iovino on 20/06/2017.
|
||||
* Description: Task: FetchHighscore.
|
||||
* Ask for highscores to server. When received it shows in highscores list
|
||||
*/
|
||||
public class FetchHighscore extends SwingWorker<Void,Void> {
|
||||
|
||||
private DefaultListModel<Pair<String,Integer>> globalRanks = new DefaultListModel<>();
|
||||
private SocketChannel socketChannel;
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
HighscoresPage highscoresPage;
|
||||
private Callable<Void> callback;
|
||||
|
||||
public FetchHighscore(HighscoresPage highscoresPage){
|
||||
this.socketChannel = App.gameService.clientSocket;
|
||||
this.highscoresPage = highscoresPage;
|
||||
public FetchHighscore(Callable<Void> callback){
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -31,43 +27,38 @@ public class FetchHighscore extends SwingWorker<Void,Void> {
|
|||
buffer = ByteBuffer.allocate(1024);
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
|
||||
try {
|
||||
socketChannel.write(buffer);
|
||||
App.clientTCP.write(buffer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("FETCH HIGHSCORES: Can't write on socket");
|
||||
}
|
||||
|
||||
try {
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
|
||||
while (socketChannel.read(buffer) != -1) {
|
||||
|
||||
while (App.clientTCP.read(buffer) != -1) {
|
||||
String line = new String(buffer.array(), buffer.position(), buffer.remaining());
|
||||
|
||||
if (line.startsWith("MESSAGE")) {
|
||||
Message msg = Message.toMessage(line);
|
||||
if (msg.message.equals("HIGHSCORES") && msg.data != null) {
|
||||
for(int i = 0; i< msg.data.size()-1; i++){
|
||||
String[] splitted = msg.data.get(i).split(":");
|
||||
globalRanks.addElement(new Pair<>(splitted[0],new Integer(splitted[1])));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
App.gameService.globalRanks = utilities.Parse.score(msg.data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
buffer.clear();
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("FETCH HIGHSCORES: Can't read from socket");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void done(){
|
||||
App.gameService.globalRanks = globalRanks;
|
||||
this.highscoresPage.showHighscoreList();
|
||||
try {
|
||||
callback.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,88 +5,78 @@ import com.texttwist.client.pages.GamePage;
|
|||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 25/06/2017.
|
||||
* Author: Lorenzo Iovino on 25/06/2017.
|
||||
* Description: Task: InvitePlayers
|
||||
* Sends invite to all players of the match
|
||||
*/
|
||||
public class InvitePlayers extends SwingWorker<Boolean,Void> {
|
||||
public class InvitePlayers extends SwingWorker<Void,Void> {
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
private DefaultListModel<String> userNames;
|
||||
|
||||
public DefaultListModel<String> userNames;
|
||||
public SocketChannel socketChannel;
|
||||
|
||||
public InvitePlayers(DefaultListModel<String> userNames, SocketChannel socketChannel) {
|
||||
this.socketChannel = socketChannel;
|
||||
public InvitePlayers(DefaultListModel<String> userNames) {
|
||||
this.userNames = userNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean doInBackground() {
|
||||
public Void doInBackground() {
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
Message message = new Message("START_GAME", App.session.account.userName, App.session.token, userNames);
|
||||
|
||||
byte[] byteMessage = new String(message.toString()).getBytes();
|
||||
byte[] byteMessage = message.toString().getBytes();
|
||||
buffer = ByteBuffer.wrap(byteMessage);
|
||||
try {
|
||||
socketChannel.write(buffer);
|
||||
App.clientTCP.write(buffer);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
while (socketChannel.read(buffer) != -1) {
|
||||
while (App.clientTCP.read(buffer) != -1) {
|
||||
|
||||
String line = new String(buffer.array(), buffer.position(), buffer.remaining());
|
||||
|
||||
if (line.startsWith("MESSAGE")) {
|
||||
Message msg = Message.toMessage(line);
|
||||
|
||||
if (msg.message.equals("USER_NOT_ONLINE")) {
|
||||
new TTDialog("alert", "Users not online!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
buffer.clear();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
new Callable() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
buffer.clear();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
buffer.clear();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
if (msg.message.equals("INVITES_ALL_SENDED")) {
|
||||
// clientSocket.close();
|
||||
new TTDialog("success", "Invite all sended!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//In attesa dei giocatori
|
||||
new GamePage(Page.window);
|
||||
buffer.clear();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
new Callable() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
//In attesa dei giocatori
|
||||
new GamePage(Page.window);
|
||||
buffer.clear();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
buffer.clear();
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
buffer.clear();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("INVITE PLAYERS: Can't read from socket");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,21 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Config;
|
||||
import javafx.util.Pair;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.DatagramChannel;
|
||||
|
||||
/**
|
||||
* Created by loke on 29/06/2017.
|
||||
* Author: Lorenzo Iovino on 29/06/2017.
|
||||
* Description: Task: SendWords.
|
||||
* Send words to server and when done it wait for score.
|
||||
*/
|
||||
public class SendWords extends SwingWorker<Void,Void> {
|
||||
|
||||
DefaultListModel<Pair<String,Integer>> ranks = new DefaultListModel<Pair<String,Integer>>();
|
||||
|
||||
SwingWorker callback;
|
||||
DefaultListModel<String> words = new DefaultListModel<>();
|
||||
private SwingWorker callback;
|
||||
private DefaultListModel<String> words = new DefaultListModel<>();
|
||||
|
||||
public SendWords(DefaultListModel<String> words, SwingWorker callback){
|
||||
this.callback = callback;
|
||||
|
|
@ -29,28 +25,23 @@ public class SendWords extends SwingWorker<Void,Void> {
|
|||
@Override
|
||||
public Void doInBackground() {
|
||||
try {
|
||||
System.out.println(words);
|
||||
InetSocketAddress myAddress = new InetSocketAddress(Config.WordsReceiverServerURI, Config.WordsReceiverServerPort);
|
||||
DatagramChannel datagramChannel = DatagramChannel.open();
|
||||
datagramChannel.bind(null);
|
||||
App.openClientUDPSocket();
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
buffer.clear();
|
||||
System.out.println("SENDER=" + App.session.account.userName);
|
||||
|
||||
Message msg = new Message("WORDS", App.session.account.userName, App.session.token, words);
|
||||
String sentence = msg.toString();
|
||||
buffer.put(sentence.getBytes());
|
||||
buffer.flip();
|
||||
datagramChannel.send(buffer, myAddress);
|
||||
System.out.println("WORDS INVIATE");
|
||||
System.out.println(sentence);
|
||||
|
||||
App.clientUDP.send(buffer, App.clientUDPSocketAddress);
|
||||
|
||||
return null;
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("SEND WORDS: Host address not correct");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
App.logger.write("SEND WORDS: Can't write on socket");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -63,5 +54,4 @@ public class SendWords extends SwingWorker<Void,Void> {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import com.texttwist.client.pages.GamePage;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 25/06/2017.
|
||||
*/
|
||||
public class StartGame extends SwingWorker<Void,Void> {
|
||||
|
||||
/*Words inserted from user*/
|
||||
private DefaultListModel<String> letters = new DefaultListModel<>();
|
||||
private GamePage gamePage;
|
||||
|
||||
public StartGame(DefaultListModel<String> letters, GamePage game){
|
||||
this.letters = letters;
|
||||
this.gamePage = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void doInBackground(){
|
||||
App.gameService.start();
|
||||
//Mostra pannello di conferma che le lettere sono tutte arrivate
|
||||
new TTDialog("success", "GameService is ready. Press OK to start!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
gamePage.showLetters();
|
||||
gamePage.timer.start();
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done(){
|
||||
}
|
||||
}
|
||||
|
|
@ -4,136 +4,99 @@ import com.texttwist.client.App;
|
|||
import com.texttwist.client.pages.MenuPage;
|
||||
import com.texttwist.client.pages.Page;
|
||||
import com.texttwist.client.ui.TTDialog;
|
||||
import constants.Config;
|
||||
import models.Message;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MulticastSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 25/06/2017.
|
||||
* Author: Lorenzo Iovino on 25/06/2017.
|
||||
* Description: Task: WaitForPlayers.
|
||||
* Wait for players joins, when all joined then sends a message of game started to all
|
||||
*
|
||||
*/
|
||||
public class WaitForPlayers extends SwingWorker<DefaultListModel<String>,DefaultListModel<String>> {
|
||||
public class WaitForPlayers extends SwingWorker<Void,Void> {
|
||||
|
||||
public SocketChannel socketChannel;
|
||||
public DefaultListModel<String> words;
|
||||
public DefaultListModel<String> letters;
|
||||
boolean joinTimeout = false;
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
SwingWorker callback;
|
||||
private boolean joinTimeout = false;
|
||||
private Callable<Void> callback;
|
||||
|
||||
public WaitForPlayers(SwingWorker callback) {
|
||||
public WaitForPlayers(Callable<Void> callback) {
|
||||
this.callback = callback;
|
||||
this.words = words;
|
||||
this.socketChannel = App.gameService.clientSocket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultListModel<String> doInBackground() {
|
||||
public Void doInBackground() {
|
||||
try {
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
String line1 = new String(buffer.array(), buffer.position(), buffer.remaining());
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024);
|
||||
TTDialog loading = new TTDialog("alert", "Waiting for users joins",null,null);
|
||||
buffer.flip();
|
||||
|
||||
while (this.socketChannel.read(buffer) != -1) {
|
||||
|
||||
while (App.clientTCP.read(buffer) != -1) {
|
||||
String line = new String(buffer.array(), buffer.position(), buffer.remaining());
|
||||
// String line = new String()
|
||||
buffer.clear();
|
||||
|
||||
if (line.startsWith("MESSAGE")) {
|
||||
buffer.clear();
|
||||
System.out.println("Mi arriva questo dal notificationServer " + line);
|
||||
|
||||
Message msg = Message.toMessage(line);
|
||||
System.out.println(msg.message);
|
||||
if (msg.message.equals("JOIN_TIMEOUT")) {
|
||||
loading.dispose();
|
||||
joinTimeout = true;
|
||||
System.out.println("JOIN TIMEOUT ENTERED");
|
||||
|
||||
new TTDialog("alert", "TIMEOUT!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//socketChannel.close();
|
||||
return new MenuPage(Page.window);
|
||||
|
||||
public Void call() throws Exception {
|
||||
new MenuPage(Page.window);
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
return new DefaultListModel<String>();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (msg.message.equals("MATCH_NOT_AVAILABLE")) {
|
||||
loading.dispose();
|
||||
System.out.println("MATCH NOT AVAILABLE ENTERED");
|
||||
|
||||
joinTimeout = true;
|
||||
new TTDialog("alert", "THE GAME IS NOT MORE AVAILABLE!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
//socketChannel.close();
|
||||
return new MenuPage(Page.window);
|
||||
|
||||
}
|
||||
}, null);
|
||||
return new DefaultListModel<String>();
|
||||
new TTDialog("alert", "THE GAME IS NOT MORE AVAILABLE!",
|
||||
new Callable() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
new MenuPage(Page.window);
|
||||
return null;
|
||||
}
|
||||
}, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (msg.message.equals("GAME_STARTED")) {
|
||||
loading.dispose();
|
||||
System.out.println("GAME STARTED ENTERED");
|
||||
|
||||
DefaultListModel<String> data;
|
||||
if(msg.data !=null ) {
|
||||
data= msg.data;
|
||||
|
||||
Integer multicastId = Integer.valueOf(data.remove(data.size()-2));
|
||||
App.gameService.setMulticastId(multicastId);
|
||||
|
||||
App.gameService.multicastSocket = new MulticastSocket(App.gameService.multicastId);
|
||||
InetAddress ia = InetAddress.getByName(Config.ScoreMulticastServerURI);
|
||||
App.gameService.multicastSocket.joinGroup(ia);
|
||||
letters = msg.data;
|
||||
|
||||
|
||||
//socketChannel.close();
|
||||
return words;
|
||||
} else {
|
||||
System.out.println("USCITO CON");
|
||||
System.out.println(line);
|
||||
return new DefaultListModel<>();
|
||||
DefaultListModel<String> data = msg.data;
|
||||
App.openClientMulticastSocket(Integer.valueOf(data.remove(data.size()-2)));
|
||||
App.gameService.setLetters(msg.data);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
buffer = ByteBuffer.allocate(1024);
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
App.logger.write("WAIT FOR SCORE: Can't receive from socket");
|
||||
}
|
||||
return new DefaultListModel<String>();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done(){
|
||||
if(!joinTimeout) {
|
||||
try {
|
||||
App.gameService.setLetters(letters);
|
||||
this.callback.execute();
|
||||
this.callback.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
package com.texttwist.client.tasks;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Config;
|
||||
import models.Message;
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* Author: Lorenzo Iovino on 27/06/2017.
|
||||
* Description: This job will waits for the score of the match sent by server, at end it will execute a callback
|
||||
* Description: Task: WaitForScore.
|
||||
* This task will waits for the score of the match sent by server, at end it will execute a callback
|
||||
* function that show the highscore pages.
|
||||
*/
|
||||
public class WaitForScore extends SwingWorker<Void,Void> {
|
||||
|
|
@ -29,15 +28,14 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
while(true) {
|
||||
byte[] buf = new byte[1024];
|
||||
DatagramPacket receivedDatagram = new DatagramPacket(buf, buf.length);
|
||||
App.gameService.multicastSocket.receive(receivedDatagram);
|
||||
App.clientMulticast.receive(receivedDatagram);
|
||||
|
||||
String s = new String(receivedDatagram.getData());
|
||||
Message msg = Message.toMessage(s);
|
||||
|
||||
//When arrive a message with message=FINALSCORE popolate ranks
|
||||
//When arrive a message with message=FINALSCORE => popolate ranks
|
||||
if(msg.message.equals("FINALSCORE")){
|
||||
if(msg.data != null) {
|
||||
App.gameService.ranks.clear();
|
||||
App.gameService.ranks = utilities.Parse.score(msg.data);
|
||||
}
|
||||
break;
|
||||
|
|
@ -53,18 +51,12 @@ public class WaitForScore extends SwingWorker<Void,Void> {
|
|||
|
||||
@Override
|
||||
public void done(){
|
||||
try {
|
||||
//Leave group and close multicast socket
|
||||
App.gameService.multicastSocket.leaveGroup(InetAddress.getByName(Config.ScoreMulticastServerURI));
|
||||
App.gameService.multicastSocket.close();
|
||||
App.closeClientMulticastSocket();
|
||||
|
||||
//Stop gameService
|
||||
App.gameService.stop();
|
||||
//Stop gameService
|
||||
App.gameService.stop();
|
||||
|
||||
//Call callback
|
||||
this.callback.execute();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Call callback
|
||||
this.callback.execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTContainer component
|
||||
*/
|
||||
public class TTButton extends JButton{
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class TTCircleCounter extends JComponent{
|
||||
|
||||
private Point position;
|
||||
private Dimension dimension;
|
||||
|
||||
public TTCircleCounter(Point position, Dimension dimension, Graphics g, TTContainer parent){
|
||||
this.position=position;
|
||||
this.dimension=dimension;
|
||||
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
Ellipse2D.Double circle = new Ellipse2D.Double(position.x, position.y, dimension.width, dimension.height);
|
||||
g2d.fill(circle);
|
||||
g2d.setColor(Color.RED);
|
||||
|
||||
parent.add(this);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
Ellipse2D.Double circle = new Ellipse2D.Double(position.x, position.y, dimension.width, dimension.height);
|
||||
g2d.setColor(Color.RED);
|
||||
g2d.fill(circle);
|
||||
}
|
||||
}
|
||||
|
|
@ -6,8 +6,10 @@ import javax.swing.*;
|
|||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTButton component
|
||||
*/
|
||||
public class TTContainer extends JPanel{
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ package com.texttwist.client.ui;
|
|||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 17/06/2017.
|
||||
* Author: Lorenzo Iovino on 17/06/2017.
|
||||
* Description: TTDialog component
|
||||
*/
|
||||
public class TTDialog extends JFrame {
|
||||
|
||||
|
|
@ -41,17 +42,60 @@ public class TTDialog extends JFrame {
|
|||
}
|
||||
add(root);
|
||||
|
||||
TTLabel msg = new TTLabel(
|
||||
new Point(60,20),
|
||||
new Dimension(350,50),
|
||||
message,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
root);
|
||||
new TTLabel(
|
||||
new Point(60,20),
|
||||
new Dimension(350,50),
|
||||
message,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 38),
|
||||
null,
|
||||
root);
|
||||
|
||||
if(okHandler != null && cancelHandler != null){
|
||||
TTButton okBtn = new TTButton(
|
||||
new Point(60,100),
|
||||
if(okHandler != null && cancelHandler != null){
|
||||
new TTButton(
|
||||
new Point(60,100),
|
||||
new Dimension(150,50),
|
||||
"Ok",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
okHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
new TTButton(
|
||||
new Point(250,100),
|
||||
new Dimension(150,50),
|
||||
"Cancel",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
cancelHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
} else {
|
||||
if(cancelHandler != null) {
|
||||
new TTButton(
|
||||
new Point(150, 100),
|
||||
new Dimension(150, 50),
|
||||
"Cancel",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
cancelHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
}
|
||||
if(okHandler != null) {
|
||||
new TTButton(
|
||||
new Point(150,100),
|
||||
new Dimension(150,50),
|
||||
"Ok",
|
||||
new Callable<Object>() {
|
||||
|
|
@ -63,51 +107,8 @@ public class TTDialog extends JFrame {
|
|||
}
|
||||
},
|
||||
root);
|
||||
TTButton cancelBtn = new TTButton(
|
||||
new Point(250,100),
|
||||
new Dimension(150,50),
|
||||
"Cancel",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
cancelHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
} else {
|
||||
if(cancelHandler != null) {
|
||||
TTButton cancelBtn = new TTButton(
|
||||
new Point(150, 100),
|
||||
new Dimension(150, 50),
|
||||
"Cancel",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
cancelHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
}
|
||||
if(okHandler != null) {
|
||||
TTButton okBtn = new TTButton(
|
||||
new Point(150,100),
|
||||
new Dimension(150,50),
|
||||
"Ok",
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
okHandler.call();
|
||||
dispose();
|
||||
return null;
|
||||
}
|
||||
},
|
||||
root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
|
@ -135,5 +136,4 @@ public class TTDialog extends JFrame {
|
|||
g2d.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,25 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTGameBox component
|
||||
*/
|
||||
public class TTGameBox extends TTInputField{
|
||||
|
||||
public TTGameBox(Point position,
|
||||
Dimension dimension,
|
||||
String placeholer,
|
||||
String placeholder,
|
||||
DefaultListModel<String> list,
|
||||
TTContainer parent){
|
||||
|
||||
super(position, dimension, placeholer, parent);
|
||||
super(position, dimension, placeholder, parent);
|
||||
setBackground(Palette.scrollPanel_backgroundColor);
|
||||
setFont(Palette.inputBox_font);
|
||||
setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
|
|
@ -29,16 +30,16 @@ public class TTGameBox extends TTInputField{
|
|||
addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
super.keyPressed(e);
|
||||
if(e.getKeyCode() == 10){
|
||||
try {
|
||||
list.addElement(getText());
|
||||
setText("");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
super.keyPressed(e);
|
||||
if(e.getKeyCode() == 10){
|
||||
try {
|
||||
list.addElement(getText());
|
||||
setText("");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
//Every time i press a key, execute a search of users
|
||||
}
|
||||
//Every time i press a key, execute a search of users
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@ import javax.swing.*;
|
|||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTImage component
|
||||
*/
|
||||
public class TTImage extends JLabel{
|
||||
|
||||
|
|
@ -16,6 +18,5 @@ public class TTImage extends JLabel{
|
|||
setIcon(image);
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
|
@ -10,7 +9,8 @@ import java.io.IOException;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTImageBtn component
|
||||
*/
|
||||
public class TTImageBtn extends TTImage {
|
||||
public TTImageBtn(Point position, Dimension dimension, ImageIcon image, Callable<Object> clickHandler, JPanel parent) throws IOException {
|
||||
|
|
@ -19,13 +19,13 @@ public class TTImageBtn extends TTImage {
|
|||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_color);
|
||||
try {
|
||||
clickHandler.call();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_color);
|
||||
try {
|
||||
clickHandler.call();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ package com.texttwist.client.ui;
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTInputBox component
|
||||
*/
|
||||
public class TTInputBox extends JTextField {
|
||||
|
||||
public String placeholder;
|
||||
|
||||
public void setPlaceholder(final String s) {
|
||||
placeholder = s;
|
||||
}
|
||||
|
|
@ -29,6 +30,5 @@ public class TTInputBox extends JTextField {
|
|||
g.setColor(getDisabledTextColor());
|
||||
g.drawString(placeholder, getInsets().left, pG.getFontMetrics()
|
||||
.getMaxAscent() + getInsets().top);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTInputField component
|
||||
*/
|
||||
public class TTInputField extends TTInputBox{
|
||||
|
||||
|
|
@ -19,10 +19,6 @@ public class TTInputField extends TTInputBox{
|
|||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
setPlaceholder(placeholder);
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTLabel component
|
||||
*/
|
||||
public class TTLabel extends JLabel{
|
||||
|
||||
|
|
@ -30,8 +30,6 @@ public class TTLabel extends JLabel{
|
|||
} else {
|
||||
setForeground(fontColor);
|
||||
}
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
|
@ -9,7 +8,8 @@ import java.awt.event.MouseEvent;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTLabelBtn component
|
||||
*/
|
||||
public class TTLabelBtn extends TTLabel{
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ public class TTLabelBtn extends TTLabel{
|
|||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_onmouseclick_color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
|
|
@ -38,7 +39,6 @@ public class TTLabelBtn extends TTLabel{
|
|||
public void mouseEntered(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_onmouseover_color);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,6 +48,5 @@ public class TTLabelBtn extends TTLabel{
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTLetter component
|
||||
*/
|
||||
public class TTLetter extends TTLabel{
|
||||
public TTLetter(Point position, String caption, JPanel parent) {
|
||||
super(position,
|
||||
new Dimension(50,50),
|
||||
caption,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 20),
|
||||
Palette.fontColor,
|
||||
parent);
|
||||
new Dimension(50,50),
|
||||
caption,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 20),
|
||||
Palette.fontColor,
|
||||
parent);
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
* Author: Lorenzo Iovino on 13/06/2017.
|
||||
* Description: TTPasswordField component
|
||||
*/
|
||||
public class TTPasswordField extends JPasswordField{
|
||||
|
||||
|
|
@ -21,8 +22,6 @@ public class TTPasswordField extends JPasswordField{
|
|||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
setText(placeholder);
|
||||
|
||||
parent.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTScrollList component
|
||||
*/
|
||||
public class TTScrollList extends JList {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
|
|
@ -12,11 +12,11 @@ import java.util.concurrent.Callable;
|
|||
|
||||
|
||||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
* Author: Lorenzo Iovino on 14/06/2017.
|
||||
* Description: TTSearchBar component
|
||||
*/
|
||||
public class TTSearchBar extends TTContainer{
|
||||
|
||||
private DefaultListModel matchedUsers = new DefaultListModel();
|
||||
public DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
|
||||
private Callable<Object> add(TTInputField ctx){
|
||||
|
|
@ -33,7 +33,6 @@ public class TTSearchBar extends TTContainer{
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
public TTSearchBar(Point position,
|
||||
Dimension dimension,
|
||||
String placeholder,
|
||||
|
|
@ -46,76 +45,65 @@ public class TTSearchBar extends TTContainer{
|
|||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
|
||||
TTLabel playerFinder_flavourText = new TTLabel(
|
||||
new Point(20,40),
|
||||
new Dimension(350,50),
|
||||
"<html>Add player</html>",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
parent);
|
||||
new TTLabel(
|
||||
new Point(20,40),
|
||||
new Dimension(350,50),
|
||||
"Add player",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
parent);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(20,80),
|
||||
new Dimension(250,45),
|
||||
placeholder,
|
||||
parent);
|
||||
new Point(20,80),
|
||||
new Dimension(250,45),
|
||||
placeholder,
|
||||
parent);
|
||||
|
||||
/*TTScrollList userList = new TTScrollList(
|
||||
new Point(20,120),
|
||||
new Dimension(250,95),
|
||||
matchedUsers,
|
||||
parent
|
||||
);*/
|
||||
new TTButton(
|
||||
new Point(70,140),
|
||||
new Dimension(150,50),
|
||||
"Add!",
|
||||
add(usernameField),
|
||||
parent);
|
||||
|
||||
TTButton addUser = new TTButton(
|
||||
new Point(70,140),
|
||||
new Dimension(150,50),
|
||||
"Add!",
|
||||
add(usernameField),
|
||||
parent);
|
||||
|
||||
|
||||
TTLabel playerToSendInvite_flavourText = new TTLabel(
|
||||
new Point(305,40),
|
||||
new Dimension(350,50),
|
||||
"Double-Click on item for remove",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
parent);
|
||||
new TTLabel(
|
||||
new Point(305,40),
|
||||
new Dimension(350,50),
|
||||
"Double-Click on item for remove",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
parent);
|
||||
|
||||
TTScrollList playerToSendInvite = new TTScrollList(
|
||||
new Point(305, 80),
|
||||
new Dimension(232, 135),
|
||||
list,
|
||||
parent);
|
||||
|
||||
new Point(305, 80),
|
||||
new Dimension(232, 135),
|
||||
list,
|
||||
parent);
|
||||
|
||||
playerToSendInvite.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
super.mouseClicked(evt);
|
||||
JList thisList = (JList)evt.getSource();
|
||||
if (evt.getClickCount() == 2) {
|
||||
|
||||
// Double-click detected
|
||||
int index = thisList.locationToIndex(evt.getPoint());
|
||||
list.remove(index);
|
||||
}
|
||||
super.mouseClicked(evt);
|
||||
JList thisList = (JList)evt.getSource();
|
||||
if (evt.getClickCount() == 2) {
|
||||
int index = thisList.locationToIndex(evt.getPoint());
|
||||
list.remove(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
usernameField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
super.keyPressed(e);
|
||||
if(e.getKeyCode() == 10){
|
||||
try {
|
||||
add(usernameField).call();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
super.keyPressed(e);
|
||||
if(e.getKeyCode() == 10){
|
||||
try {
|
||||
add(usernameField).call();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
parent.add(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue