-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fenetre.java
445 lines (388 loc) · 10.3 KB
/
Fenetre.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.JTabbedPane;
public class Fenetre extends JFrame
{
private JPanel general;
private Dessin dessin;
private String forme;
private int x;
private int y;
private boolean first_clic=false;
private boolean second_clic=false;
private int old_x;
private int old_y;
private int old_x_2;
private int old_y_2;
private int rayon;
private int rayon2;
private Vue zone;
private JPanel jp; //panel nord
private JPanel pannel_sud;
private JButton b_select;
BoutonListener blis=new BoutonListener();
private JTabbedPane onglets;
private JButton remplis;
private boolean remplissage=false;
private Color couleur;
private JColorChooser tcc;
private Crayon cray=new Crayon(0,0,0,couleur);
private Gomme gomme=new Gomme();
private int taille_gomme=50;
private JPanel panel_text;
private JTextArea texte;
private String text2;
public Fenetre(Dessin dessin)
{
super("test");
//KeyListener klis=new ClavierListener();
//this.addKeyListener(klis);
//this.setFocusable(true);
//this.requestFocus();
this.dessin=dessin;
this.setSize(800,600);
this.initialise();
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(true);
}
public void initialise()
{
onglets=new JTabbedPane();
general=new JPanel();
general.setLayout(new BorderLayout());
initPanelNord();
general.add(jp,BorderLayout.NORTH);
initPanelSud();
general.add(pannel_sud,BorderLayout.SOUTH);
zone=new Vue(dessin);
CurseurListener mlis=new CurseurListener();
zone.addMouseListener(mlis);
MouveMouseListener mml=new MouveMouseListener();
zone.addMouseMotionListener(mml);
general.add(zone,BorderLayout.CENTER);
initPanelText();
onglets.add("General",general);
onglets.add("Texte",panel_text);
onglets.add("Couleurs",initPanelDroite());
this.add(onglets);
dessin.add(gomme);
}
public void actualiser()
{
zone=new Vue(dessin);
b_select.setBackground(null);
repaint();
}
public void initPanelText()
{
panel_text=new JPanel();
panel_text.setLayout(new BorderLayout());
JButton text=new JButton("Valider");
text.addActionListener(blis);
texte=new JTextArea();
panel_text.add(texte,BorderLayout.CENTER);
panel_text.add(text,BorderLayout.SOUTH);
}
public JPanel initPanelDroite()
{
JPanel couleurs=new JPanel();
tcc= new JColorChooser();
CouleurListener cl=new CouleurListener();
tcc.getSelectionModel().addChangeListener(cl);
tcc.setBorder(BorderFactory.createTitledBorder("Choisissez votre couleur"));
couleurs.add(tcc);
return couleurs;
}
public void initPanelNord()
{
jp=new JPanel();;
JButton s=new JButton("Segment");
s.addActionListener(blis);
jp.add(s);
JButton r=new JButton("Rectangle");
r.addActionListener(blis);
jp.add(r);
JButton t=new JButton("Triangle");
t.addActionListener(blis);
jp.add(t);
JButton c=new JButton("Cercle");
c.addActionListener(blis);
jp.add(c);
JButton e=new JButton("Ellipse");
e.addActionListener(blis);
jp.add(e);
}
public void initPanelSud()
{
pannel_sud=new JPanel();
JButton crayon=new JButton("Crayon");
crayon.addActionListener(blis);
pannel_sud.add(crayon);
remplis=new JButton("Remplissage");
remplis.addActionListener(blis);
pannel_sud.add(remplis);
JButton del=new JButton("Supprimer");
del.addActionListener(blis);
pannel_sud.add(del);
JButton gomme=new JButton("Gomme");
gomme.addActionListener(blis);
pannel_sud.add(gomme);
}
class CurseurListener extends MouseAdapter
{
int pos_x;
int pos_y;
int rayon;
public void mouseClicked(MouseEvent e)
{
if(forme!=null)
{
x=e.getX();
y=e.getY();
switch(forme)
{
case "Cercle":
if(!first_clic)
{
old_x=x;
old_y=y;
first_clic=true;
}else
{
pos_x=old_x;
pos_y=old_y;
rayon=Math.abs(x-old_x);
if(old_x>x)
{
pos_x=x;
}
if(old_y>y)
{
pos_y=y;
}
dessin.add(new Cercle(pos_x,pos_y,0,rayon,remplissage,couleur));
forme=null;
first_clic=false;
actualiser();
}
break;
case "Rectangle":
if(!first_clic)
{
old_x=x;
old_y=y;
first_clic=true;
}else
{
dessin.add(new Rectangle_mine(old_x,old_y,0,x,y,remplissage,couleur));
first_clic=false;
forme=null;
actualiser();
}
break;
case "Triangle":
if(!first_clic)
{
old_x=x;
old_y=y;
first_clic=true;
}else if(!second_clic)
{
old_x_2=x;
old_y_2=y;
second_clic=true;
}else
{
dessin.add(new Triangle(old_x,old_y,0,old_x_2,old_y_2,x,y,remplissage,couleur));
first_clic=false;
second_clic=false;
forme=null;
actualiser();
}
break;
case "Ellipse":
if(!first_clic)
{
old_x=x;
old_y=y;
first_clic=true;
}else
{
rayon=Math.abs(x-old_x);
rayon2=Math.abs(y-old_y);
if(old_x>x)
{
old_x=x;
}
if(old_y>y)
{
old_y=y;
}
dessin.add(new Ellipse(old_x,old_y,0,rayon,rayon2,remplissage,couleur));
first_clic=false;
forme=null;
actualiser();
}
break;
case "Segment":
if(!first_clic)
{
old_x=x;
old_y=y;
first_clic=true;
}else
{
dessin.add(new Segment(old_x,old_y,0,x,y,couleur));
first_clic=false;
forme=null;
actualiser();
}
break;
case "Crayon":
forme=null;
cray.Crayon_add(null);
break;
case "Texte":
forme=null;
dessin.add(new Texte(x,y,couleur,text2));
actualiser();
break;
}
}
}
}
class MouveMouseListener implements MouseMotionListener
{
java.awt.Point mp;
boolean ajouter=false;
public void mouseDragged(MouseEvent med)
{
if(forme=="Crayon")
{
if(!ajouter)
{
cray.set_color(couleur);
dessin.add(cray);
ajouter=true;
}
mp=med.getPoint();
cray.Crayon_add(new Point((int)mp.getX(),(int)mp.getY()));
dessin.add(cray);
actualiser();
}else if(forme=="Gomme")
{
mp=med.getPoint();
ArrayList<Cercle> gommes=new ArrayList<Cercle>();
gommes.add(new Cercle((int)mp.getX(),(int)mp.getY(),0,taille_gomme,true,null));
//gomme.Gomme_add((int)mp.getX(),(int)mp.getY(),taille_gomme);
dessin.add(new Gomme(gommes));
actualiser();
}
}
public void mouseMoved(MouseEvent med2){}
public void mouseExited(MouseEvent e){}
}
/*class ClavierListener implements KeyListener
{
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public void keyPressed(KeyEvent e)
{
System.out.println("press");
int touche=e.getKeyCode();
System.out.println(touche);
boolean ok=false;
switch(touche)
{
case KeyEvent.VK_C:
forme="Cercle";
System.out.println("Cercle press");
ok=true;
case 'r':
forme="Rectangle";
ok=true;
case 'e':
forme="Ellipse";
ok=true;
case 't':
forme="Triangle";
ok=true;
case 's':
forme="Segment";
ok=true;
}
if(ok)
{
if(b_select!=null)
{
//b_select.setBackground(null);
}
}
}
}*/
class BoutonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String commande=e.getActionCommand();
if(commande=="Remplissage")
{
if(remplissage)
{
remplissage=false;
remplis.setBackground(null);
}else
{
remplissage=true;
remplis.setBackground(couleur);
}
}else
{
if(b_select!=null)
{
b_select.setBackground(null);
}
b_select=(JButton)e.getSource();
b_select.setBackground(Color.RED);
forme=commande;
}
if(commande=="Supprimer")
{
while (!dessin.isEmpty())
{
dessin.remove(dessin.size()-1);
}
actualiser();
}
if(commande=="Valider")
{
text2=texte.getText();
forme="Texte";
}
}
}
class CouleurListener implements ChangeListener
{
public void stateChanged(ChangeEvent cou)
{
couleur=tcc.getColor();
if(remplissage==true)
{
remplis.setBackground(couleur);
}
}
}
}