-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanelMain.java
152 lines (113 loc) · 4.56 KB
/
PanelMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import javax.swing.*;
import java.awt.GridLayout;
import java.awt.Font;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.*;
import java.awt.Toolkit;
public class PanelMain extends JPanel implements ActionListener
{
private Controleur ctrl;
private JLabel[] ensJLabels;
private JTextField[] ensTextFields;
private String[] txtLabel = {"Lien:", "Identifiant:", "Mot de passe:", "Informations supp:"};
private JPanel[] panelMdpCopy;
private JButton[] ensBtnCopy;
private JPasswordField lblPassword;
public PanelMain( Controleur ctrl)
{
this.ctrl = ctrl;
this.setLayout ( new GridLayout( 4, 2, 10, 10 ) );
/*----------------------------*/
/* Création des composants */
/*----------------------------*/
this.ensJLabels = new JLabel[4];
this.ensTextFields = new JTextField[4];
this.panelMdpCopy = new JPanel[4];
this.ensBtnCopy = new JButton[4];
this.lblPassword = new JPasswordField();
this.lblPassword.setFont( new Font ("Arial", Font.PLAIN, 20));
this.lblPassword.setEditable( false );
for (int i =0; i < 4; i++)
{
this.ensJLabels[i] = new JLabel( this.txtLabel[i], JLabel.CENTER);
this.ensJLabels[i].setFont( new Font ("Arial", Font.PLAIN, 20));
this.ensTextFields[i] = new JTextField ( 20 );
this.ensTextFields[i].setFont( new Font ("Arial", Font.PLAIN, 20));
this.ensTextFields[i].setText("Aucun compte selectionné");
this.ensTextFields[i].setForeground(Color.BLACK);
this.ensTextFields[i].setEditable( false );
if (i < 3)
{
this.ensBtnCopy[i] = new JButton("Copier");
this.ensBtnCopy[i].setBackground( new Color(158, 158, 158));
this.ensBtnCopy[i].setForeground( Color.DARK_GRAY );
}
else
{
this.ensBtnCopy[i] = new JButton("Supprimer compte");
this.ensBtnCopy[i].setForeground( Color.white );
this.ensBtnCopy[i].setBackground( new Color(186, 30, 30));
}
this.ensBtnCopy[i].setFont( new Font ("Arial", Font.PLAIN, 20));
this.panelMdpCopy[i] = new JPanel( new BorderLayout ());
}
/*--------------------------------*/
/* positionnement des composants */
/*--------------------------------*/
for (int i = 0; i < 4; i++)
{
// Label
this.add( this.ensJLabels[i] );
// mdp + copy
if (i != 2 )
{
this.panelMdpCopy[i].add( this.ensTextFields[i]);
this.ensTextFields[i].setBackground(Color.WHITE);
this.panelMdpCopy[i].add( this.ensBtnCopy[i], BorderLayout.EAST);
}
else
{
this.panelMdpCopy[i].add( this.lblPassword );
this.panelMdpCopy[i].add( this.ensBtnCopy[i], BorderLayout.EAST);
}
this.add (this.panelMdpCopy[i]);
}
/*----------------------------------------*/
/* Activation des composants */
/*----------------------------------------*/
for( int i =0; i < 4; i++)
{
this.ensBtnCopy[i].addActionListener( this );
}
//Colors
this.setBackground( new Color(233, 126, 126) );
}
public void actionPerformed(ActionEvent e)
{
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection testData;
if ( e.getSource() == this.ensBtnCopy[0] )
{
testData = new StringSelection( this.ctrl.getLink() );
c.setContents(testData, testData);
}
if ( e.getSource() == this.ensBtnCopy[1] )
{
testData = new StringSelection( this.ctrl.getId() );
c.setContents(testData, testData);
}
if ( e.getSource() == this.ensBtnCopy[2] )
{
testData = new StringSelection( this.ctrl.getMdp() );
c.setContents(testData, testData);
}
if ( e.getSource() == this.ensBtnCopy[3] ) this.ctrl.removeAccount();
}
public void setLink(String link) { this.ensTextFields[0].setText(link);}
public void setId (String id ) { this.ensTextFields[1].setText(id );}
public void setMdp (String mdp ) { this.lblPassword.setText(mdp ) ;}
public void setNote(String note) { this.ensTextFields[3].setText(note);}
}