Added TTSearchBar functionality for add and remove users
This commit is contained in:
parent
48705f7e76
commit
eb1754e63e
6 changed files with 417 additions and 287 deletions
|
|
@ -2,6 +2,7 @@ package com.texttwist.client.pages;
|
|||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -14,16 +15,15 @@ import java.util.concurrent.Callable;
|
|||
public class MatchSetup extends Page{
|
||||
|
||||
public TTContainer matchSetupContainer;
|
||||
MatchSetup(JFrame window) throws IOException {
|
||||
public MatchSetupController matchSetupController;
|
||||
|
||||
MatchSetup(JFrame window) throws Exception {
|
||||
super(window);
|
||||
matchSetupController = new MatchSetupController();
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
private Callable addUserToInvitationList(){
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO Spostare i metodi di fetches nella classe MatchSetupService per separare MVC
|
||||
private DefaultListModel fetchUsers(){
|
||||
DefaultListModel<String> usersList = new DefaultListModel<String>();
|
||||
|
|
@ -48,7 +48,7 @@ public class MatchSetup extends Page{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() throws IOException {
|
||||
public void createUIComponents() throws Exception {
|
||||
addLogo(root);
|
||||
|
||||
matchSetupContainer = new TTContainer(
|
||||
|
|
@ -66,36 +66,12 @@ public class MatchSetup extends Page{
|
|||
null,
|
||||
matchSetupContainer);
|
||||
|
||||
TTLabel playerFinder_flavourText = new TTLabel(
|
||||
new Point(20,40),
|
||||
new Dimension(350,50),
|
||||
"<html>Search players to invite...</html>",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
matchSetupContainer);
|
||||
|
||||
TTSearchBar searchUserBar = new TTSearchBar(
|
||||
new Point(20, 80),
|
||||
new Dimension(250, 40),
|
||||
"Username",
|
||||
new DefaultListModel(),
|
||||
addUserToInvitationList(),
|
||||
matchSetupContainer);
|
||||
|
||||
TTLabel playerToSendInvite_flavourText = new TTLabel(
|
||||
new Point(305,40),
|
||||
new Dimension(350,50),
|
||||
"Click on user for remove it",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
matchSetupContainer);
|
||||
|
||||
TTScrollList playerToSendInvite = new TTScrollList(
|
||||
new Point(305, 80),
|
||||
new Dimension(232, 135),
|
||||
new DefaultListModel(),
|
||||
matchSetupContainer);
|
||||
|
||||
addFooter(root);
|
||||
addNext(footer,
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 40),
|
||||
|
|
@ -104,7 +80,20 @@ public class MatchSetup extends Page{
|
|||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new Game(Page.window);
|
||||
//If server response ok, start play, else error
|
||||
Response res = matchSetupController.play(searchUserBar.list);
|
||||
if (res.code == 200){
|
||||
//OK, go to next page and show popup
|
||||
return new Game(Page.window);
|
||||
} else {
|
||||
return new TTDialog("alert", res.message,
|
||||
new Callable() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return new MatchSetup(Page.window);
|
||||
}
|
||||
},null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.App;
|
||||
import models.Response;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
/**
|
||||
* Created by loke on 18/06/2017.
|
||||
*/
|
||||
public class MatchSetupController {
|
||||
|
||||
public MatchSetupController(){}
|
||||
public Response play(DefaultListModel<String> userNames) throws RemoteException, NotBoundException, MalformedURLException {
|
||||
|
||||
System.out.print(userNames.toString());
|
||||
/* Response res = App.authService.login(userName,password);
|
||||
if (res.code == 200){
|
||||
App.sessionService.create(userName, res.data.get("token").toString());
|
||||
}*/
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ public class Page {
|
|||
window.add(root);
|
||||
}
|
||||
|
||||
public void createUIComponents() throws IOException {}
|
||||
public void createUIComponents() throws Exception {}
|
||||
|
||||
public void addLogo(TTContainer parent) {
|
||||
TTContainer container = new TTContainer(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.texttwist.client.ui;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.MatchSetup;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
|
|
@ -12,34 +14,103 @@ import java.util.concurrent.Callable;
|
|||
/**
|
||||
* Created by loke on 14/06/2017.
|
||||
*/
|
||||
public class TTSearchBar extends TTInputField{
|
||||
public class TTSearchBar extends TTContainer{
|
||||
|
||||
private DefaultListModel matchedUsers = new DefaultListModel();
|
||||
public DefaultListModel<String> list = new DefaultListModel<String>();
|
||||
|
||||
private Callable<Object> add(TTInputField ctx){
|
||||
return new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
String username = ctx.getText();
|
||||
ctx.setText("");
|
||||
list.addElement(username);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public TTSearchBar(Point position,
|
||||
Dimension dimension,
|
||||
String placeholer,
|
||||
DefaultListModel listModel,
|
||||
Callable<Object> clickHandler,
|
||||
TTContainer parent){
|
||||
TTContainer parent) throws Exception {
|
||||
|
||||
super(position, dimension, placeholer, parent);
|
||||
super(position, dimension, Palette.inputBox_backgroundColor, -1, parent);
|
||||
setBackground(Palette.scrollPanel_backgroundColor);
|
||||
setFont(Palette.inputBox_font);
|
||||
setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
|
||||
TTScrollList userList = new TTScrollList(
|
||||
TTLabel playerFinder_flavourText = new TTLabel(
|
||||
new Point(20,40),
|
||||
new Dimension(350,50),
|
||||
"<html>Player to invite</html>",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 18),
|
||||
null,
|
||||
parent);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(20,80),
|
||||
new Dimension(250,45),
|
||||
"Username",
|
||||
parent);
|
||||
/* TTScrollList userList = new TTScrollList(
|
||||
new Point(20,120),
|
||||
new Dimension(250,95),
|
||||
matchedUsers,
|
||||
parent
|
||||
);
|
||||
);*/
|
||||
|
||||
addKeyListener(new KeyAdapter() {
|
||||
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 user 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);
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
//Every time i press a key, execute a search of users
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue