-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOngletPage.java
More file actions
128 lines (103 loc) · 2.76 KB
/
OngletPage.java
File metadata and controls
128 lines (103 loc) · 2.76 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
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
import java.awt.BorderLayout;
import java.awt.Insets;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import javax.swing.undo.UndoManager;
/*
* Dans cette classe, un onglet correspond à un fichier
*/
public class OngletPage extends Onglet implements UndoableEditListener
{
private static final long serialVersionUID = 1L;
private JTextPane textPane;
private HTMLEditorKit m_Kit;
private HTMLDocument m_Document;
private StyleSheet context;
private UndoManager m_Undo;
public OngletPage(Fichier fichier)
{
super(fichier);
setLayout(new BorderLayout());
this.textPane = new JTextPane();
this.m_Kit = new HTMLEditorKit();
this.context = new StyleSheet();
this.m_Document = new HTMLDocument(context);
this.textPane.setEditorKit(m_Kit);
this.textPane.setDocument(m_Document);
try {
context.importStyleSheet(new URL("File:css/test.css"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
m_Undo = new UndoManager();
textPane.getDocument().addUndoableEditListener(this);
this.textPane.setMargin(new Insets(50, 50, 50, 50));
JScrollPane sclScroll = new JScrollPane(textPane);
add(sclScroll);
this.textPane.setText(((PageHTML) this.fichier).getContenu());
//this.textPane.repaint();
}
public void ajouterElement(String texte, HTML.Tag InsertTag) throws BadLocationException, IOException
{
m_Kit.insertHTML(m_Document, this.textPane.getCaretPosition(), texte, 0, 0, InsertTag);
}
public HTMLEditorKit getM_Kit()
{
return m_Kit;
}
public void setM_Kit(HTMLEditorKit m_Kit)
{
this.m_Kit = m_Kit;
}
public StyleSheet getContext()
{
return context;
}
public void setContext(StyleSheet context)
{
this.context = context;
}
public JTextPane getJTextPane()
{
return textPane;
}
public void setJTextPane(JTextPane textPane)
{
this.textPane = textPane;
}
public HTMLDocument getM_Document()
{
return m_Document;
}
public void setM_Document(HTMLDocument m_Document)
{
this.m_Document = m_Document;
}
public UndoManager getM_Undo()
{
return m_Undo;
}
public void setM_Undo(UndoManager m_Undo)
{
this.m_Undo = m_Undo;
}
@Override
public void undoableEditHappened(UndoableEditEvent arg0)
{
m_Undo.addEdit(arg0.getEdit());
}
public void majContenu() {
((PageHTML) this.fichier).setContenu(this.textPane.getText());
}
}