Bonjour,
Je recherche un éditeur de texte java que je puisse introduire dans un de mes pg.... un éditeur style worldpad.java
Merci
Version imprimable
Bonjour,
Je recherche un éditeur de texte java que je puisse introduire dans un de mes pg.... un éditeur style worldpad.java
Merci
N'importe quel éditeur de texte édite du Java puisqu'un code source [u]est|/u] du texte...
Il est existe un éditeur de texte en Swing ou Awt (je ne sais plus trop...),
à toi de trouver ;)
Je sais pas ce que ca vaut :
http://membres.lycos.fr/benymarc/java/wordexpli.html
Mais utilise :google: avec wordpad et pas worldpad tu devrais trouver pas mal de sources...
tu n'as pas compris! je recherhce le code source d'un éditeur de texte style wordpad!!
et si je demande tu penses bien que j'ai cherché
:wink:
A qui parles-tu ?Citation:
Envoyé par doudine
(merci d'utiliser 'Citer')
Il existe tout plein de composants graphiques dans les bibliothèques Swing, AWT et autres...
Il doit y avoir un éditeur texte :?
je veux bien te croire... tout existe! mais je ne pense pas qu'il réunisse toutes les fonctions (enregistrer, copier, taille du texte...) tel que wordpad!Citation:
Envoyé par Kimael
D'ou ma recherche d'un source java style wordpad...
http://membres.lycos.fr/benymarc/java/wordexpli.html
:google2:
Et si t'es pas satisfait par ce que tu trouves, le mieux c'est encore de l'ecrire. On sera la pour te donner des conseils.
bon ok... je vais essayer... merci qd meme..
j'avais trouvé ces liens..; mais le premier est en j++ et le second n'a pas toutes les sources... :-(
dommage pour moi...
Merci!
moi je te conseillerais d'écrire le tien (moi c'est ce que je suis en train de faire)
tu prend un JEditorPane, tu le met dans un JScrollPane, tu mets le tout dans ton getContentPane(), une barre de menu et go! toutes les fonctions propres à un éditeur de texte sont déjà implémentées dans le JEditorPane
du genre pour faire un copier-coller:
Code:
1
2
3 monEdiPane.copy(); monEdiPane.paste();
:wink:
Citation:
Envoyé par ThePills
bon l'ébauche c'est à peu près comme ça
dans un constructeur de JFrame
et ensuite tu ajoutes les fonctionnalités que tu veux (mais il y en a déjà pas mal d'implémentées)Code:
1
2
3
4
5
6 JEditorPane ediPane = new JEditorPane(); JScrollPane scrollPane = new JScrollPane(ediPane); Container content = getContentPane(); content.add(scrollPane, BorderLayout.CENTER);
:wink:
C'est clair, c'est une ebauche :lol:Citation:
Envoyé par ThePills
Mais c'est une bonne base de depart 8)
ok! merci en tout cas!
Mais si vous avez une version beta n'hésitez pas à me la refiler!!
Je me ferais les dents dessus...
Merci encore!
8O :wink:
si vraiment... j'en suis a peu près là du miens
Code:
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738 import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetAdapter; import java.awt.dnd.DropTargetDropEvent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import javax.swing.filechooser.FileFilter; import javax.swing.text.html.HTMLEditorKit; public class JFrameEditeur extends JFrame implements ActionListener { /** DOCUMENT ME! */ private static final String TITRE = "Blo->kenotte"; /** DOCUMENT ME! */ private JPanel jContentPane = null; /** DOCUMENT ME! */ private JScrollPane jScrollPane = null; /** DOCUMENT ME! */ private PrintableJEditorPane ediPane = null; /** DOCUMENT ME! */ private JMenuBar barreMenu = null; /** DOCUMENT ME! */ private JMenu menuFichier = null; /** DOCUMENT ME! */ private JMenu menuEdition = null; /** DOCUMENT ME! */ private JMenu menuFormat = null; /** DOCUMENT ME! */ private JMenuItem itemNouveau = null; /** DOCUMENT ME! */ private JMenuItem itemOuvrir = null; /** DOCUMENT ME! */ private JMenuItem itemEnregistrer = null; /** DOCUMENT ME! */ private JMenuItem itemEnregistrerSous = null; /** DOCUMENT ME! */ private File currentFile = null; /** DOCUMENT ME! */ private boolean fileIsNotSaved = false; /** DOCUMENT ME! */ private JMenuItem itemFermer = null; /** DOCUMENT ME! */ private JMenuItem itemCouper = null; /** DOCUMENT ME! */ private JMenuItem itemCopier = null; /** DOCUMENT ME! */ private JMenuItem itemColler = null; /** DOCUMENT ME! */ private JPopupMenu jPopupMenu = null; /** DOCUMENT ME! */ private JMenuItem popItemCopier = null; /** DOCUMENT ME! */ private JMenuItem popItemCouper = null; /** DOCUMENT ME! */ private JMenuItem popItemColler = null; /** DOCUMENT ME! */ private JMenuItem itemRechercher = null; /** DOCUMENT ME! */ private JMenuItem itemPolice = null; /** DOCUMENT ME! */ private JMenuItem itemImprimer = null; /** * This is the default constructor */ public JFrameEditeur() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); this.setTitle(TITRE); this.setJMenuBar(getBarreMenu()); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.setPreferredSize(new Dimension(screen.width / 2, screen.height / 2)); this.setSize(300, 200); pack(); this.setLocationRelativeTo(getParent()); this.setContentPane(getJContentPane()); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private javax.swing.JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new javax.swing.JPanel(); jContentPane.setLayout(new java.awt.BorderLayout()); jContentPane.add(getJScrollPane(), java.awt.BorderLayout.CENTER); } return jContentPane; } /** * This method initializes jScrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() { if (jScrollPane == null) { jScrollPane = new JScrollPane(); jScrollPane.setPreferredSize(new Dimension(1024, 768)); jScrollPane.setViewportView(getEdiPane()); } return jScrollPane; } /** * This method initializes ediPane * * @return javax.swing.JEditorPane */ private JEditorPane getEdiPane() { if (ediPane == null) { ediPane = new PrintableJEditorPane(); ediPane.setDropTarget(new DropTarget(ediPane, new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { System.out.println("Drop event"); } })); ediPane.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { getJPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); } return ediPane; } /** * This method initializes barreMenu * * @return javax.swing.JMenuBar */ private JMenuBar getBarreMenu() { if (barreMenu == null) { barreMenu = new JMenuBar(); barreMenu.add(getMenuFichier()); barreMenu.add(getMenuEdition()); barreMenu.add(getMenuFormat()); } return barreMenu; } /** * This method initializes menuFichier * * @return javax.swing.JMenu */ private JMenu getMenuFichier() { if (menuFichier == null) { menuFichier = new JMenu(); menuFichier.setText("Fichier"); menuFichier.setMnemonic('f'); menuFichier.add(getItemNouveau()); menuFichier.addSeparator(); menuFichier.add(getItemOuvrir()); menuFichier.addSeparator(); menuFichier.add(getItemEnregistrer()); menuFichier.add(getItemEnregistrerSous()); menuFichier.addSeparator(); menuFichier.add(getItemImprimer()); menuFichier.addSeparator(); menuFichier.add(getItemFermer()); } return menuFichier; } /** * This method initializes menuEdition * * @return javax.swing.JMenu */ private JMenu getMenuEdition() { if (menuEdition == null) { menuEdition = new JMenu("Edition"); menuEdition.setMnemonic('e'); menuEdition.add(getItemCopier()); menuEdition.add(getItemCouper()); menuEdition.add(getItemColler()); menuEdition.addSeparator(); menuEdition.add(getItemRechercher()); } return menuEdition; } /** * This method initializes menuFormat * * @return javax.swing.JMenu */ private JMenu getMenuFormat() { if (menuFormat == null) { menuFormat = new JMenu(); menuFormat.setText("Format"); menuFormat.setMnemonic('o'); menuFormat.add(getItemPolice()); } return menuFormat; } /** * This method initializes itemOuvrir * * @return javax.swing.JMenuItem */ private JMenuItem getItemOuvrir() { if (itemOuvrir == null) { itemOuvrir = new JMenuItem("Ouvrir"); itemOuvrir.setMnemonic('o'); itemOuvrir.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); itemOuvrir.addActionListener(this); } return itemOuvrir; } /** * This method initializes itemNouveau * * @return javax.swing.JMenuItem */ private JMenuItem getItemNouveau() { if (itemNouveau == null) { itemNouveau = new JMenuItem("Nouveau"); itemNouveau.setMnemonic('n'); itemNouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); itemNouveau.addActionListener(this); } return itemNouveau; } /** * This method initializes itemEnregistrer * * @return javax.swing.JMenuItem */ private JMenuItem getItemEnregistrer() { if (itemEnregistrer == null) { itemEnregistrer = new JMenuItem("Enregistrer"); itemEnregistrer.setMnemonic('e'); itemEnregistrer.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); itemEnregistrer.addActionListener(this); } return itemEnregistrer; } /** * This method initializes itemEnregistrerSous * * @return javax.swing.JMenuItem */ private JMenuItem getItemEnregistrerSous() { if (itemEnregistrerSous == null) { itemEnregistrerSous = new JMenuItem("Enregistrer sous..."); itemEnregistrerSous.setMnemonic('s'); itemEnregistrerSous.addActionListener(this); } return itemEnregistrerSous; } /** * This method initializes itemFermer * * @return javax.swing.JMenuItem */ private JMenuItem getItemFermer() { if (itemFermer == null) { itemFermer = new JMenuItem("Fermer"); itemFermer.setMnemonic('f'); itemFermer.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.ALT_MASK)); itemFermer.addActionListener(this); } return itemFermer; } /** * This method initializes itemCouper * * @return javax.swing.JMenuItem */ private JMenuItem getItemCouper() { if (itemCouper == null) { itemCouper = new JMenuItem("Couper"); itemCouper.setMnemonic('o'); itemCouper.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_MASK)); itemCouper.addActionListener(this); } return itemCouper; } /** * DOCUMENT ME! */ private void open() { JFileChooser chooser = new JFileChooser("Choisissez un fichier texte:"); chooser.setFileFilter(new FileFilter() { public boolean accept(File f) { return (f.getPath().endsWith(".utf") || f.getPath().endsWith(".txt") || f.getPath().endsWith(".data") || f.getPath().endsWith(".ini") || f.getPath().endsWith(".nfo") || f.getPath().endsWith(".htm") || f.getPath().endsWith(".html") || f.getPath().endsWith(".php") || f.getPath().endsWith(".css") || f.getPath().endsWith(".js") || f.getPath().endsWith(".bat") || f.isDirectory()); } public String getDescription() { return "Fichiers texte"; } }); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { currentFile = chooser.getSelectedFile(); try { ediPane.read(new FileInputStream(currentFile), null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } /** * DOCUMENT ME! */ private void saveAs() { JFileChooser chooser = new JFileChooser("Choisissez un fichier"); if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { currentFile = chooser.getSelectedFile(); save(); } } /** * DOCUMENT ME! */ private void save() { if (currentFile == null) { saveAs(); } else { try { ediPane.write(new FileWriter(currentFile)); fileIsNotSaved = false; } catch (IOException e) { e.printStackTrace(); } } } /** * DOCUMENT ME! * * @param ae DOCUMENT ME! */ public void actionPerformed(ActionEvent ae) { if (ae.getSource() == itemNouveau) { if (fileIsNotSaved) { askToSave(); } ediPane.setText(""); fileIsNotSaved = false; currentFile = null; } else if (ae.getSource() == itemOuvrir) { if (fileIsNotSaved) { askToSave(); } open(); } else if (ae.getSource() == itemEnregistrer) { save(); } else if (ae.getSource() == itemEnregistrerSous) { saveAs(); } else if (ae.getSource() == itemImprimer) { PrinterJob imprimante = PrinterJob.getPrinterJob(); imprimante.setPrintable(ediPane); try { imprimante.print(); } catch (PrinterException e) { e.printStackTrace(); } } else if (ae.getSource() == itemFermer) { if (fileIsNotSaved) { askToSave(); } dispose(); System.exit(0); } else if ((ae.getSource() == itemCouper) || (ae.getSource() == popItemCouper)) { ediPane.cut(); } else if ((ae.getSource() == itemCopier) || (ae.getSource() == popItemCopier)) { ediPane.copy(); } else if ((ae.getSource() == itemColler) || (ae.getSource() == popItemColler)) { ediPane.paste(); } else if (ae.getSource() == itemRechercher) { //ediPane. } else if (ae.getSource() == itemPolice) { JFontChooser chooser = new JFontChooser(this, ediPane); chooser.setVisible(true); } System.out.println("Action sur " + ae.getActionCommand()); if (currentFile == null) { this.setTitle(TITRE); } else { this.setTitle(TITRE + " << " + currentFile.getName() + " >>"); } } /** * DOCUMENT ME! */ private void askToSave() { int answer = JOptionPane.showConfirmDialog(this, "Voulez-vous enregistrer le fichier courant ?", "Sauvegarder les modifications...", JOptionPane.YES_NO_OPTION); if (answer == JOptionPane.YES_OPTION) { save(); } } /** * DOCUMENT ME! * * @param visible DOCUMENT ME! */ public void setVisible(boolean visible) { if (fileIsNotSaved) { askToSave(); } super.setVisible(visible); } /** * This method initializes itemCopier * * @return javax.swing.JMenuItem */ private JMenuItem getItemCopier() { if (itemCopier == null) { itemCopier = new JMenuItem("Copier"); itemCopier.setMnemonic('c'); itemCopier.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK)); itemCopier.addActionListener(this); } return itemCopier; } /** * This method initializes itemColler * * @return javax.swing.JMenuItem */ private JMenuItem getItemColler() { if (itemColler == null) { itemColler = new JMenuItem("Coller"); itemColler.setMnemonic('l'); itemColler.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK)); itemColler.addActionListener(this); } return itemColler; } /** * This method initializes jPopupMenu * * @return javax.swing.JPopupMenu */ private JPopupMenu getJPopupMenu() { if (jPopupMenu == null) { jPopupMenu = new JPopupMenu(); jPopupMenu.add(getPopItemCopier()); jPopupMenu.add(getPopItemCouper()); jPopupMenu.add(getPopItemColler()); } return jPopupMenu; } /** * This method initializes popItemCopier * * @return javax.swing.JMenuItem */ private JMenuItem getPopItemCopier() { if (popItemCopier == null) { popItemCopier = new JMenuItem("Copier"); popItemCopier.addActionListener(this); } return popItemCopier; } /** * This method initializes popItemCouper * * @return javax.swing.JMenuItem */ private JMenuItem getPopItemCouper() { if (popItemCouper == null) { popItemCouper = new JMenuItem("Couper"); popItemCouper.addActionListener(this); } return popItemCouper; } /** * This method initializes popItemColler * * @return javax.swing.JMenuItem */ private JMenuItem getPopItemColler() { if (popItemColler == null) { popItemColler = new JMenuItem("Coller"); popItemColler.addActionListener(this); } return popItemColler; } /** * This method initializes itemRechercher * * @return javax.swing.JMenuItem */ private JMenuItem getItemRechercher() { if (itemRechercher == null) { itemRechercher = new JMenuItem("Rechercher"); itemRechercher.setMnemonic('r'); itemRechercher.addActionListener(this); } return itemRechercher; } /** * This method initializes itemPolice * * @return javax.swing.JMenuItem */ private JMenuItem getItemPolice() { if (itemPolice == null) { itemPolice = new JMenuItem("Police"); itemPolice.setMnemonic('p'); itemPolice.addActionListener(this); } return itemPolice; } /** * This method initializes itemImprimer * * @return javax.swing.JMenuItem */ private JMenuItem getItemImprimer() { if (itemImprimer == null) { itemImprimer = new JMenuItem("Imprimer"); itemImprimer.setMnemonic('i'); itemImprimer.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK)); itemImprimer.addActionListener(this); } return itemImprimer; } } class PrintableJEditorPane extends JEditorPane implements Printable { /** DOCUMENT_ME */ private boolean fileIsNotSaved = false; /** * Creates a new PrintableJEditorPane object. */ public PrintableJEditorPane() { setSelectionColor(Color.LIGHT_GRAY); setSelectedTextColor(Color.YELLOW); getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent de) { fileIsNotSaved = true; } public void removeUpdate(DocumentEvent de) { fileIsNotSaved = true; } public void changedUpdate(DocumentEvent de) { } }); addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.isShiftDown()) { switch (e.getKeyCode()) { case KeyEvent.VK_INSERT: paste(); break; case KeyEvent.VK_DELETE: cut(); break; } } } }); } /** * DOCUMENT ME! * * @param g DOCUMENT ME! * @param pf DOCUMENT ME! * @param i DOCUMENT ME! * * @return DOCUMENT ME! * * @throws PrinterException DOCUMENT ME! */ public int print(Graphics g, PageFormat pf, int i) throws PrinterException { //int nPages = this.get return NO_SUCH_PAGE; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public boolean fileIsNotSaved() { return fileIsNotSaved; } }
et le JFontChooser...
c'est cadeau :wink:Code:
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 package sebpiller.Editeur; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.GraphicsEnvironment; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.AttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; public class JFontChooser extends JDialog implements ActionListener { /** DOCUMENT_ME */ private JColorChooser colorChooser = null; /** DOCUMENT_ME */ private JComboBox fontName = null; /** DOCUMENT_ME */ private JCheckBox fontBold; /** DOCUMENT_ME */ private JCheckBox fontItalic = null; /** DOCUMENT_ME */ private JSpinner fontSize = null; /** DOCUMENT_ME */ private JLabel previewLabel = null; /** DOCUMENT_ME */ private SimpleAttributeSet attributes = null; /** DOCUMENT_ME */ private Font newFont = null; /** DOCUMENT_ME */ private Color newColor = null; /** DOCUMENT_ME */ private JComponent compo = null; /** * Creates a new JFontChooser object. * * @param parent DOCUMENT ME! * @param compo DOCUMENT ME! */ public JFontChooser(Frame parent, JComponent compo) { super(parent, "Font Chooser", true); this.compo = compo; setSize(450, 450); attributes = new SimpleAttributeSet(); // Make sure that any way the user cancels the window does the right thing addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { closeAndCancel(); } }); // Start the long process of setting up our interface Container c = getContentPane(); JPanel fontPanel = new JPanel(); fontName = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment() .getAvailableFontFamilyNames()); fontName.setSelectedItem(compo.getFont().getName()); fontName.addActionListener(this); fontSize = new JSpinner(new SpinnerNumberModel(compo.getFont().getSize(), 4, 50, 2)); fontSize.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { actionPerformed(null); } }); fontBold = new JCheckBox("Bold"); fontBold.setSelected(compo.getFont().isBold()); fontBold.addActionListener(this); fontItalic = new JCheckBox("Italic"); fontItalic.setSelected(compo.getFont().isItalic()); fontItalic.addActionListener(this); fontPanel.add(fontName); fontPanel.add(new JLabel(" Size: ")); fontPanel.add(fontSize); fontPanel.add(fontBold); fontPanel.add(fontItalic); c.add(fontPanel, BorderLayout.NORTH); // Set up the color chooser panel and attach a change listener so that color // updates get reflected in our preview label. colorChooser = new JColorChooser(compo.getForeground()); colorChooser.getSelectionModel().addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { updatePreviewColor(); } }); c.add(colorChooser, BorderLayout.CENTER); JPanel previewPanel = new JPanel(new BorderLayout()); previewLabel = new JLabel("Le résultat ressemblera un peu à ça"); previewLabel.setBackground(Color.WHITE); previewLabel.setForeground(colorChooser.getColor()); previewPanel.add(previewLabel, BorderLayout.CENTER); // Add in the Ok and Cancel buttons for our dialog box JButton okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndApply(); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { closeAndCancel(); } }); JPanel controlPanel = new JPanel(); controlPanel.add(okButton); controlPanel.add(cancelButton); previewPanel.add(controlPanel, BorderLayout.SOUTH); // Give the preview label room to grow. previewPanel.setMinimumSize(new Dimension(100, 100)); previewPanel.setPreferredSize(new Dimension(100, 100)); c.add(previewPanel, BorderLayout.SOUTH); actionPerformed(null); } // Ok, something in the font changed, so figure that out and make a // new font for the preview label public void actionPerformed(ActionEvent ae) { // Check the name of the font if (!StyleConstants.getFontFamily(attributes).equals(fontName.getSelectedItem())) { StyleConstants.setFontFamily(attributes, (String) fontName.getSelectedItem()); } // Check the font size (no error checking yet) if (StyleConstants.getFontSize(attributes) != ((Integer) fontSize.getValue()).intValue()) { StyleConstants.setFontSize(attributes, ((Integer) fontSize.getValue()).intValue()); } // Check to see if the font should be bold if (StyleConstants.isBold(attributes) != fontBold.isSelected()) { StyleConstants.setBold(attributes, fontBold.isSelected()); } // Check to see if the font should be italic if (StyleConstants.isItalic(attributes) != fontItalic.isSelected()) { StyleConstants.setItalic(attributes, fontItalic.isSelected()); } // and update our preview label updatePreviewFont(); } // Get the appropriate font from our attributes object and update // the preview label protected void updatePreviewFont() { String name = StyleConstants.getFontFamily(attributes); boolean bold = StyleConstants.isBold(attributes); boolean ital = StyleConstants.isItalic(attributes); int size = StyleConstants.getFontSize(attributes); //Bold and italic donât work properly in beta 4. Font f = new Font(name, (bold ? Font.BOLD : 0) + (ital ? Font.ITALIC : 0), size); previewLabel.setFont(f); } // Get the appropriate color from our chooser and update previewLabel protected void updatePreviewColor() { previewLabel.setForeground(colorChooser.getColor()); // Manually force the label to repaint previewLabel.repaint(); } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public Font getNewFont() { return newFont; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public Color getNewColor() { return newColor; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public AttributeSet getAttributes() { return attributes; } /** * DOCUMENT ME! */ public void closeAndApply() { // Save font & color information newFont = previewLabel.getFont(); newColor = previewLabel.getForeground(); // apply the changes to the jcomponent compo.setFont(newFont); compo.setForeground(newColor); // Close the window setVisible(false); } /** * DOCUMENT ME! */ public void closeAndCancel() { // Erase any font information and then close the window newFont = null; newColor = null; setVisible(false); } }
Alors là je sais plus quoi dire ThePills!!!!
C'est vraiment exttrèmenent sympa de ta part!! :oops:
Je te dis pas "si je peux t'aider" mais bon j'aimerais pouvoir te renvoyer l'ascenseur... à dans 10 ans! :wink:
Bon je fais donc un main et je test! merci encore!
Bon boulot...
Un petit [Résolu] :?:
PS: prochaine fois, met un lien sur le net ou envoi-lui le code par MP (ou courriel), parce que si tout le monde colle du code (joli au fait ;) ) dans ses réponse, BOOM la base :twisted:
héhéhé lol... tu verras il te faudra beaucoup moins que 10ans :wink:Citation:
Envoyé par doudine
Kimael: tu as raison, la prochaine fois j'enverrai par pv
Bonjour,
C'est le genre de chose que je recherchais mais la fonction "Rechercher" ne marche pas. Une idee sur ce qu'il faut rajouter ici (et ailleur)?
Merci d'avance.Code:
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 public void actionPerformed(ActionEvent ae) { if (ae.getSource() == itemNouveau) { if (fileIsNotSaved) { askToSave(); } ediPane.setText(""); fileIsNotSaved = false; currentFile = null; } else if (ae.getSource() == itemOuvrir) { if (fileIsNotSaved) { askToSave(); } open(); } else if (ae.getSource() == itemEnregistrer) { save(); } else if (ae.getSource() == itemEnregistrerSous) { saveAs(); } else if (ae.getSource() == itemImprimer) { PrinterJob imprimante = PrinterJob.getPrinterJob(); imprimante.setPrintable(ediPane); try { imprimante.print(); } catch (PrinterException e) { e.printStackTrace(); } } else if (ae.getSource() == itemFermer) { if (fileIsNotSaved) { askToSave(); } dispose(); System.exit(0); } else if ((ae.getSource() == itemCouper) || (ae.getSource() == popItemCouper)) { ediPane.cut(); } else if ((ae.getSource() == itemCopier) || (ae.getSource() == popItemCopier)) { ediPane.copy(); } else if ((ae.getSource() == itemColler) || (ae.getSource() == popItemColler)) { ediPane.paste(); } else if (ae.getSource() == itemRechercher) { // ediPane } else if (ae.getSource() == itemPolice) { JFontChooser chooser = new JFontChooser(this, ediPane); chooser.setVisible(true); }