-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitre.java
More file actions
63 lines (52 loc) · 1.7 KB
/
Titre.java
File metadata and controls
63 lines (52 loc) · 1.7 KB
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
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
public class Titre extends JDialog implements ActionListener {
private static final long serialVersionUID = 1L;
private JLabel labNomTitre;
private JTextField tfTitre;
private JButton valid;
private JTextPane textPane;
private Onglet onglet;
public Titre(Onglet onglet) {
this.setTitle("Nouveau titre");
this.setLayout(new GridLayout(3,1));
this.setSize(400, 100);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.onglet = onglet;
this.textPane = onglet.getJTextPane();
JPanel pBas = new JPanel(new BorderLayout());
this.labNomTitre = new JLabel("Entrez le nom du titre");
add(this.labNomTitre, BorderLayout.NORTH);
this.tfTitre = new JTextField();
add(this.tfTitre);
this.valid = new JButton("Valider");
this.valid.addActionListener(this);
pBas.add(this.valid, BorderLayout.EAST);
add(pBas, BorderLayout.SOUTH);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.valid) {
try {
onglet.getKit().insertHTML(onglet.getDoc(), this.textPane.getCaretPosition(), "<h1 style=\"text-align:center;\">"+this.tfTitre.getText()+"</h1>\n\n", 0, 0, null);
} catch (BadLocationException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
this.dispose();
}
}
}