First commit
This commit is contained in:
commit
67b9ec0df1
64 changed files with 3257 additions and 0 deletions
25
Client/src/com/texttwist/client/Main.java
Normal file
25
Client/src/com/texttwist/client/Main.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package com.texttwist.client;
|
||||
import com.texttwist.client.pages.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.out.println("Client started");
|
||||
|
||||
//Load fonts
|
||||
try {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(
|
||||
new File("./Client/resources/fonts/DK Trained Monkey.otf").getCanonicalPath())));
|
||||
|
||||
} catch (IOException|FontFormatException e) {
|
||||
System.out.println("Font non caricato correttamente");
|
||||
}
|
||||
|
||||
Entrypoint entrypoint = new Entrypoint();
|
||||
}
|
||||
}
|
||||
25
Client/src/com/texttwist/client/constants/Palette.java
Normal file
25
Client/src/com/texttwist/client/constants/Palette.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package com.texttwist.client.constants;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Palette {
|
||||
public static Color root_backgroundColor = new Color(145,181,88);
|
||||
public static Color inputBox_backgroundColor = new Color(250,250,250); //"#FAFAFA;
|
||||
public static Color button_backgroundColor = new Color(105,130,63); //#69823f
|
||||
public static Font inputBox_font = new Font("DK Trained Monkey", Font.BOLD, 26);
|
||||
public static Font password_font = new Font("Arial Black", Font.BOLD, 26);
|
||||
public static Color fontColor = new Color(95,0,0);
|
||||
public static Color registerLblBtn_color = new Color(95,0,0);
|
||||
public static Color registerLblBtn_onmouseover_color = new Color(95,0,0, 127);
|
||||
public static Color registerLblBtn_onmouseclick_color = new Color(53,66,32);
|
||||
|
||||
|
||||
public static Font button_font = new Font("DK Trained Monkey", Font.BOLD, 30);
|
||||
|
||||
public Palette() {
|
||||
//TODO fetchare dal server questi dati
|
||||
}
|
||||
}
|
||||
29
Client/src/com/texttwist/client/pages/Entrypoint.java
Normal file
29
Client/src/com/texttwist/client/pages/Entrypoint.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.ui.TTContainer;
|
||||
import com.texttwist.client.ui.TTImage;
|
||||
import oracle.jrockit.jfr.JFR;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Entrypoint extends JFrame {
|
||||
|
||||
protected TTContainer root;
|
||||
|
||||
public Entrypoint(){
|
||||
setPreferredSize( new Dimension( 640, 480 ));
|
||||
setSize(new Dimension(640,480));
|
||||
setLocation(100,100);
|
||||
setResizable( false );
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Home home = new Home(this);
|
||||
}
|
||||
}
|
||||
66
Client/src/com/texttwist/client/pages/Home.java
Normal file
66
Client/src/com/texttwist/client/pages/Home.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
package com.texttwist.client.pages;
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.ui.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class Home extends Page {
|
||||
|
||||
private TTContainer loginDataContainer;
|
||||
private TTContainer logoContainer;
|
||||
|
||||
public Home(JFrame window) {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents(){
|
||||
addLogo(root);
|
||||
|
||||
loginDataContainer = new TTContainer(
|
||||
null,
|
||||
new Dimension(1150,250),
|
||||
Palette.root_backgroundColor,
|
||||
-1,
|
||||
root);
|
||||
|
||||
TTInputField usernameField = new TTInputField(
|
||||
new Point(70,60),
|
||||
new Dimension(210,50),
|
||||
"Username",
|
||||
loginDataContainer);
|
||||
TTPasswordField passwordField = new TTPasswordField(
|
||||
new Point(290,60),
|
||||
new Dimension(210,50),
|
||||
loginDataContainer);
|
||||
TTButton loginBtn = new TTButton(
|
||||
new Point(70,120),
|
||||
new Dimension(430,50),
|
||||
"Go!",
|
||||
loginDataContainer);
|
||||
TTLabel registerText = new TTLabel(
|
||||
new Point(70,200),
|
||||
new Dimension(350,50),
|
||||
"Don't have an account?",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.ITALIC, 24),
|
||||
null,
|
||||
loginDataContainer);
|
||||
TTLabelBtn registerField = new TTLabelBtn(
|
||||
new Point(360, 200),
|
||||
new Dimension(210, 50),
|
||||
"Register!",
|
||||
new Font(Palette.inputBox_font.getFontName(), Font.BOLD, 34),
|
||||
null,
|
||||
new Callable<Page>() {
|
||||
@Override
|
||||
public Page call() throws Exception {
|
||||
return new Register(Page.window);
|
||||
}
|
||||
},
|
||||
loginDataContainer);
|
||||
}
|
||||
}
|
||||
57
Client/src/com/texttwist/client/pages/Page.java
Normal file
57
Client/src/com/texttwist/client/pages/Page.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.ui.TTContainer;
|
||||
import com.texttwist.client.ui.TTImage;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Page {
|
||||
|
||||
public TTContainer root;
|
||||
public static JFrame window;
|
||||
|
||||
public Page(JFrame window){
|
||||
this.window = window;
|
||||
|
||||
window.getContentPane().removeAll();
|
||||
window.repaint();
|
||||
window.revalidate();
|
||||
|
||||
root = new TTContainer(
|
||||
new Point(40,20),
|
||||
new Dimension(0,0),
|
||||
Palette.root_backgroundColor,
|
||||
BoxLayout.Y_AXIS,
|
||||
null);
|
||||
window.add(root);
|
||||
|
||||
}
|
||||
|
||||
public void createUIComponents(){}
|
||||
|
||||
public void addLogo(TTContainer parent) {
|
||||
TTContainer container = new TTContainer(
|
||||
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);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Client/src/com/texttwist/client/pages/Register.java
Normal file
21
Client/src/com/texttwist/client/pages/Register.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package com.texttwist.client.pages;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class Register extends Page {
|
||||
|
||||
public Register(JFrame window) {
|
||||
super(window);
|
||||
createUIComponents();
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createUIComponents() {
|
||||
addLogo(root);
|
||||
|
||||
}
|
||||
}
|
||||
28
Client/src/com/texttwist/client/ui/TTButton.java
Normal file
28
Client/src/com/texttwist/client/ui/TTButton.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTButton extends JButton{
|
||||
|
||||
public TTButton(Point position, Dimension dimension, String caption, JPanel parent) {
|
||||
super();
|
||||
|
||||
setBackground(Palette.button_backgroundColor);
|
||||
setFont(Palette.button_font);
|
||||
setForeground(Palette.fontColor);
|
||||
setBounds(position.x,position.y,dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setText(caption);
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
}
|
||||
33
Client/src/com/texttwist/client/ui/TTContainer.java
Normal file
33
Client/src/com/texttwist/client/ui/TTContainer.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTContainer extends JPanel{
|
||||
|
||||
public TTContainer(Point innerPadding, Dimension dimension, Color backgroundColor, int axis, TTContainer parent) {
|
||||
super();
|
||||
if(axis == -1){
|
||||
setLayout(null);
|
||||
} else {
|
||||
setLayout(new BoxLayout(this, axis));
|
||||
}
|
||||
|
||||
setBackground(backgroundColor != null ? backgroundColor : new Color(0,0,0,0));
|
||||
setFont(Palette.inputBox_font);
|
||||
setMaximumSize(dimension);
|
||||
if(innerPadding != null) {
|
||||
setLocation(innerPadding);
|
||||
setBorder(new EmptyBorder(new Insets(innerPadding.y, innerPadding.x, dimension.width, dimension.height)));
|
||||
}
|
||||
if(parent != null) {
|
||||
parent.add(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Client/src/com/texttwist/client/ui/TTImage.java
Normal file
29
Client/src/com/texttwist/client/ui/TTImage.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTImage extends JLabel{
|
||||
|
||||
public TTImage(Point position, Dimension dimension, ImageIcon image , JPanel parent) throws IOException {
|
||||
super();
|
||||
|
||||
//setBackground(Palette.inputBox_backgroundColor);
|
||||
//setFont(Palette.inputBox_font);
|
||||
setBounds(position.x,position.y,dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setIcon(image);
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
}
|
||||
34
Client/src/com/texttwist/client/ui/TTInputBox.java
Normal file
34
Client/src/com/texttwist/client/ui/TTInputBox.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTInputBox extends JTextField {
|
||||
|
||||
public String placeholder;
|
||||
|
||||
public void setPlaceholder(final String s) {
|
||||
placeholder = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(final Graphics pG) {
|
||||
super.paintComponent(pG);
|
||||
|
||||
if (placeholder.length() == 0 || getText().length() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Graphics2D g = (Graphics2D) pG;
|
||||
g.setRenderingHint(
|
||||
RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setColor(getDisabledTextColor());
|
||||
g.drawString(placeholder, getInsets().left, pG.getFontMetrics()
|
||||
.getMaxAscent() + getInsets().top);
|
||||
}
|
||||
|
||||
}
|
||||
29
Client/src/com/texttwist/client/ui/TTInputField.java
Normal file
29
Client/src/com/texttwist/client/ui/TTInputField.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTInputField extends TTInputBox{
|
||||
|
||||
public TTInputField(Point position, Dimension dimension, String placeholder, JPanel parent) {
|
||||
super();
|
||||
|
||||
setBackground(Palette.inputBox_backgroundColor);
|
||||
setFont(Palette.inputBox_font);
|
||||
setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
setPlaceholder(placeholder);
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
39
Client/src/com/texttwist/client/ui/TTLabel.java
Normal file
39
Client/src/com/texttwist/client/ui/TTLabel.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTLabel extends JLabel{
|
||||
|
||||
public TTLabel(Point position, Dimension dimension, String caption, Font font, Color fontColor, JPanel parent) {
|
||||
super();
|
||||
|
||||
setBackground(Palette.inputBox_backgroundColor);
|
||||
|
||||
if(font == null) {
|
||||
setFont(Palette.inputBox_font);
|
||||
} else {
|
||||
setFont(font);
|
||||
}
|
||||
|
||||
setBounds(position.x,position.y,dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setText(caption);
|
||||
|
||||
if(fontColor == null) {
|
||||
setForeground(Palette.fontColor);
|
||||
} else {
|
||||
setForeground(fontColor);
|
||||
}
|
||||
|
||||
parent.add(this);
|
||||
|
||||
}
|
||||
}
|
||||
55
Client/src/com/texttwist/client/ui/TTLabelBtn.java
Normal file
55
Client/src/com/texttwist/client/ui/TTLabelBtn.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
import com.texttwist.client.pages.Entrypoint;
|
||||
import com.texttwist.client.pages.Page;
|
||||
|
||||
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.
|
||||
*/
|
||||
public class TTLabelBtn extends TTLabel{
|
||||
|
||||
public TTLabelBtn(Point position, Dimension dimension, String caption, Font font, Color fontColor, Callable<Page> clickHandler, JPanel parent) {
|
||||
super(position, dimension, caption, font, fontColor, parent);
|
||||
|
||||
setForeground(Palette.registerLblBtn_color);
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_onmouseclick_color);
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_color);
|
||||
try {
|
||||
clickHandler.call();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_onmouseover_color);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
super.mouseClicked(e);
|
||||
setForeground(Palette.registerLblBtn_color);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
47
Client/src/com/texttwist/client/ui/TTPasswordField.java
Normal file
47
Client/src/com/texttwist/client/ui/TTPasswordField.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package com.texttwist.client.ui;
|
||||
|
||||
import com.texttwist.client.constants.Palette;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by loke on 13/06/2017.
|
||||
*/
|
||||
public class TTPasswordField extends TTInputBox{
|
||||
|
||||
private String placeholder = "Password";
|
||||
|
||||
public TTPasswordField(Point position, Dimension dimension, JPanel parent) {
|
||||
super();
|
||||
|
||||
setBackground(Palette.inputBox_backgroundColor);
|
||||
setFont(Palette.inputBox_font);
|
||||
setBounds(position.x, position.y, dimension.width, dimension.height);
|
||||
setPreferredSize(dimension);
|
||||
setForeground(Palette.fontColor);
|
||||
setPlaceholder(placeholder);
|
||||
|
||||
addKeyListener(new KeyAdapter() {
|
||||
//If wish to have multiple inheritance...
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
super.keyPressed(e);
|
||||
String a = getText();
|
||||
String l = new String();
|
||||
for (int i = 0; i < a.length(); ++i) {
|
||||
l+="*";
|
||||
}
|
||||
setText(l);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
parent.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue