-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicsTextPane.java
More file actions
executable file
·421 lines (398 loc) · 16.4 KB
/
TopicsTextPane.java
File metadata and controls
executable file
·421 lines (398 loc) · 16.4 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
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
/*
* Projet : Trustopics
* Version : 0.2.1
* Fichier : TopicsTextPane.java
*/
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
import javax.swing.JTextPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
public class TopicsTextPane extends JTextPane implements HyperlinkListener {
private Vector glb_vectTopicsList = new Vector();
private Vector glb_vectTopicsHtmlList = new Vector();
private String[][] glb_htmlDatas_0 = new String[2][2];
private String[][] glb_htmlDatas_1 = new String[3][3];
private String[][] glb_htmlDatas_2 = new String[5][3];
private boolean glb_htmlDataAdd = false;
private HTMLEditorKit glb_kit;
private HTMLDocument glb_doc;
/*
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
*/
public TopicsTextPane() {
InitDatas();
glb_kit = new HTMLEditorKit();
glb_doc = (HTMLDocument) (glb_kit.createDefaultDocument());
addHyperlinkListener(this);
addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent evt) {
glb_htmlDataAdd = false;
UpdateList();
}
});
setEditable(false);
setEditorKit(glb_kit);
setDocument(glb_doc);
setContentType("text/html");
setBackground(Defines.UIcolBackGDrawing);
LoadTopics();
setText(CreateHtmlList());
}
public void ExternClear() {
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
int lcl_nbTopic = lcl_ctu.GetTotalTopic();
if (lcl_nbTopic > 0) {
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
for (int i = 0 ; i < lcl_nbTopic ; i++) {
lcl_topicsDatas = lcl_ctu.GetTopicDatas(1);
lcl_ctu.DelTopicDatas(lcl_topicsDatas);
glb_vectTopicsList.removeElementAt(0);
glb_vectTopicsHtmlList.removeElementAt(0);
}
lcl_ctu.SaveTopicsDatas();
UpdateList();
}
}
public void ExternRaz() {
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
int lcl_nbTopic = lcl_ctu.GetTotalTopic();
if (lcl_nbTopic > 0) {
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
for (int i = 0 ; i < lcl_nbTopic ; i++) {
lcl_topicsDatas = lcl_ctu.GetTopicDatas(i + 1);
lcl_ctu.ChangeTopicData(lcl_topicsDatas,0,"1");
lcl_topicsDatas[0] = "1";
glb_vectTopicsList.setElementAt(lcl_topicsDatas,i);
glb_vectTopicsHtmlList.set(i,CreateHtmlLine(i));
}
lcl_ctu.SaveTopicsDatas();
UpdateList();
}
}
public void UpdateList() {
try {
DefaultHtmlList();
setText(CreateHtmlList());
setEditable(false);
setEditorKit(glb_kit);
setDocument(glb_doc);
setContentType("text/html");
}
catch(Exception prm_exc) {/* bug pb maj JTextPane ? à résoudre...*/}
}
public void hyperlinkUpdate(HyperlinkEvent prm_ev) {
Defines.eventMouseIsActivated = true;
String lcl_description = prm_ev.getDescription();
if (prm_ev.getEventType() == HyperlinkEvent.EventType.ENTERED) {
if (ParamatersColAndLigIsOk(lcl_description)==true) {
int[] lcl_param = new int[3];
lcl_param = GetParametersColAndLig(lcl_description);
if (glb_vectTopicsHtmlList.size() > lcl_param[1]) {
glb_vectTopicsHtmlList.set(lcl_param[1],CreateHtmlLine(lcl_param[1],lcl_param[2]));
setText(CreateHtmlList(lcl_param[1],lcl_param[2]));
}
}
if (lcl_description.equals("add")) {
glb_htmlDataAdd = true;
setText(CreateHtmlList());
}
}
if (prm_ev.getEventType() == HyperlinkEvent.EventType.EXITED) {
if (ParamatersColAndLigIsOk(lcl_description)) {
int[] lcl_param = new int[3];
lcl_param = GetParametersColAndLig(lcl_description);
if (glb_vectTopicsHtmlList.size() > lcl_param[1]) {
glb_vectTopicsHtmlList.set(lcl_param[1],CreateHtmlLine(lcl_param[1]));
setText(CreateHtmlList());
}
}
if (lcl_description.equals("add")) {
glb_htmlDataAdd = false;
setText(CreateHtmlList());
}
}
if (prm_ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (lcl_description.equals("add")) {
AddTopic();
DefaultHtmlList();
glb_htmlDataAdd = false;
setText(CreateHtmlList());
}
else {
if (ParamatersColAndLigIsOk(lcl_description)) {
setText("");
int[] lcl_param = new int[3];
lcl_param = GetParametersColAndLig(lcl_description);
HyperlinkEvent(lcl_param[1],lcl_param[2]);
DefaultHtmlList();
setText(CreateHtmlList());
}
}
}
Defines.eventMouseIsActivated = false;
}
public void LoadTopics() {
glb_vectTopicsList.removeAllElements();
glb_vectTopicsHtmlList.removeAllElements();
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
int lcl_cptTopics = lcl_ctu.GetTotalTopic();
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
for (int i = 0 ; i < lcl_cptTopics ; i++) {
lcl_topicsDatas = lcl_ctu.GetTopicDatas(i+1);
glb_vectTopicsList.add(lcl_topicsDatas);
glb_vectTopicsHtmlList.add(CreateHtmlLine(i));
}
}
private void AddTopic() {
Defines.selectTopicIsInProgress = true;
SelectTopicUI lcl_st = new SelectTopicUI();
if (lcl_st.TopicIsSelected()) {
WebMemory lcl_wm = new WebMemory();
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
lcl_topicsDatas[0] = "1";
lcl_topicsDatas[1] = Integer.toString(lcl_st.GetCategorie());
lcl_topicsDatas[2] = lcl_wm.GetTopicValue(lcl_st.GetTopic());
lcl_topicsDatas[3] = lcl_wm.GetTopicMessage(lcl_st.GetTopic());
lcl_topicsDatas[4] = lcl_wm.GetTopicAnswer(lcl_st.GetTopic());
lcl_topicsDatas[5] = lcl_wm.GetTopicView(lcl_st.GetTopic());
lcl_topicsDatas[6] = lcl_wm.GetTopicAuthor(lcl_st.GetTopic());
lcl_topicsDatas[7] = lcl_wm.GetTopicAuthorAnswer(lcl_st.GetTopic());
glb_vectTopicsList.add(lcl_topicsDatas);
int lcl_line = glb_vectTopicsHtmlList.size();
String lcl_topicsHtmlDatas = new String();
lcl_topicsHtmlDatas = glb_htmlDatas_0[0][0]+lcl_line+glb_htmlDatas_0[0][1];
lcl_topicsHtmlDatas += glb_htmlDatas_1[0][0]+glb_htmlDatas_1[0][1]+""+glb_htmlDatas_1[0][2];
lcl_topicsHtmlDatas += glb_htmlDatas_2[0][0]+lcl_line+glb_htmlDatas_2[0][1]+lcl_topicsDatas[3]+glb_htmlDatas_2[0][2];
glb_vectTopicsHtmlList.add(lcl_topicsHtmlDatas);
lcl_ctu.AddTopicDatas(lcl_topicsDatas);
lcl_ctu.SaveTopicsDatas();
}
Defines.selectTopicIsInProgress = false;
}
private void HyperlinkEvent(int prm_lig,int prm_col) {
switch(prm_col) {
case 0: {
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
lcl_topicsDatas = lcl_ctu.GetTopicDatas(prm_lig + 1);
lcl_ctu.DelTopicDatas(lcl_topicsDatas);
lcl_ctu.SaveTopicsDatas();
glb_vectTopicsList.removeElementAt(prm_lig);
glb_vectTopicsHtmlList.removeElementAt(prm_lig);
break;
}
case 1: {
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
lcl_topicsDatas = lcl_ctu.GetTopicDatas(prm_lig + 1);
lcl_ctu.ChangeTopicData(lcl_topicsDatas,0,"1");
lcl_ctu.SaveTopicsDatas();
lcl_topicsDatas[0] = "1";
glb_vectTopicsList.setElementAt(lcl_topicsDatas,prm_lig);
glb_vectTopicsHtmlList.set(prm_lig,CreateHtmlLine(prm_lig));
break;
}
case 2: {
ConfigTopicsUpdates lcl_ctu = new ConfigTopicsUpdates();
lcl_ctu.LoadTopicsDatas();
String[] lcl_topicsDatas = new String[lcl_ctu.GetMaxTopicDatas()];
lcl_topicsDatas = lcl_ctu.GetTopicDatas(prm_lig + 1);
int lcl_categorie = Integer.parseInt(lcl_topicsDatas[1]) + 1;
int lcl_topicValue = Integer.parseInt(lcl_topicsDatas[2]);
String lcl_url;
try {
lcl_url = new WebConnectExtra().GetUrlTopicPage(lcl_categorie,lcl_topicValue);
if (!lcl_url.equals("")) {
lcl_topicsDatas[0] = "1";
new ExecProcess(lcl_url);
}
else {
lcl_topicsDatas[0] = "0";
}
}
catch (TrustException prm_ev) { prm_ev.Action(); }
lcl_ctu.ChangeTopicData(lcl_topicsDatas,0,lcl_topicsDatas[0]);
lcl_ctu.SaveTopicsDatas();
glb_vectTopicsList.setElementAt(lcl_topicsDatas,prm_lig);
glb_vectTopicsHtmlList.set(prm_lig,CreateHtmlLine(prm_lig));
}
}
}
private void DefaultHtmlList() {
for (int i = 0 ; i < glb_vectTopicsHtmlList.size() ; i++) {
glb_vectTopicsHtmlList.set(i,CreateHtmlLine(i));
}
}
private String CreateHtmlLine(int prm_lig) {
return(CreateHtmlLine(prm_lig,-1));
}
private String CreateHtmlList() {
return(CreateHtmlList(-1,-1));
}
private String CreateHtmlLine(int prm_lig,int prm_colSelect) {
String lcl_htmlLine = new String();
int lcl_topicState = Integer.parseInt(GetDataTopicsList(prm_lig,0));
switch(prm_colSelect) {
case -1: {
lcl_htmlLine = glb_htmlDatas_0[0][0] + prm_lig + glb_htmlDatas_0[0][1];
if (lcl_topicState > 1)
lcl_htmlLine += glb_htmlDatas_1[1][0] + prm_lig + glb_htmlDatas_1[1][1] + (lcl_topicState-1) + glb_htmlDatas_1[1][2];
else
lcl_htmlLine += glb_htmlDatas_1[0][0] + glb_htmlDatas_1[0][1] + glb_htmlDatas_1[0][2];
switch(lcl_topicState) {
case 0: { lcl_htmlLine += glb_htmlDatas_2[2][0] + glb_htmlDatas_2[2][1] + GetDataTopicsList(prm_lig,3) + glb_htmlDatas_2[2][2]; break; }
case 1: { lcl_htmlLine += glb_htmlDatas_2[0][0] + prm_lig + glb_htmlDatas_2[0][1] + GetDataTopicsList(prm_lig,3) + glb_htmlDatas_2[0][2]; break; }
default: { lcl_htmlLine += glb_htmlDatas_2[1][0] + prm_lig + glb_htmlDatas_2[1][1] + GetDataTopicsList(prm_lig,3) + glb_htmlDatas_2[1][2]; }
}
break;
}
case 0: {
lcl_htmlLine = glb_htmlDatas_0[1][0]+prm_lig+glb_htmlDatas_0[1][1];
if (lcl_topicState > 1) {
lcl_htmlLine += glb_htmlDatas_1[1][0]+prm_lig+glb_htmlDatas_1[1][1] + (lcl_topicState-1) + glb_htmlDatas_1[1][2];
}
else {
lcl_htmlLine += glb_htmlDatas_1[0][0]+glb_htmlDatas_1[0][1]+glb_htmlDatas_1[0][2];
}
switch(lcl_topicState) {
case 0: { lcl_htmlLine += glb_htmlDatas_2[2][0]+glb_htmlDatas_2[2][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[2][2]; break; }
case 1: { lcl_htmlLine += glb_htmlDatas_2[0][0]+prm_lig+glb_htmlDatas_2[0][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[0][2]; break; }
default: { lcl_htmlLine += glb_htmlDatas_2[1][0]+prm_lig+glb_htmlDatas_2[1][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[1][2]; }
}
break;
}
case 1: {
lcl_htmlLine = glb_htmlDatas_0[0][0]+prm_lig+glb_htmlDatas_0[0][1];
if (lcl_topicState > 1) {
lcl_htmlLine += glb_htmlDatas_1[2][0]+prm_lig+glb_htmlDatas_1[2][1] + (lcl_topicState-1) + glb_htmlDatas_1[2][2];
}
else {
lcl_htmlLine += glb_htmlDatas_1[0][0]+glb_htmlDatas_1[0][1]+glb_htmlDatas_1[0][2];
}
switch(lcl_topicState) {
case 0: { lcl_htmlLine += glb_htmlDatas_2[2][0]+glb_htmlDatas_2[2][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[2][2]; break; }
case 1: { lcl_htmlLine += glb_htmlDatas_2[0][0]+prm_lig+glb_htmlDatas_2[0][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[0][2]; break; }
default: { lcl_htmlLine += glb_htmlDatas_2[1][0]+prm_lig+glb_htmlDatas_2[1][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[1][2]; }
}
break;
}
case 2: {
lcl_htmlLine = glb_htmlDatas_0[0][0]+prm_lig+glb_htmlDatas_0[0][1];
if (lcl_topicState > 1) {
lcl_htmlLine += glb_htmlDatas_1[1][0]+prm_lig+glb_htmlDatas_1[1][1] + (lcl_topicState-1) + glb_htmlDatas_1[1][2];
}
else {
lcl_htmlLine += glb_htmlDatas_1[0][0]+glb_htmlDatas_1[0][1]+glb_htmlDatas_1[0][2];
}
switch(lcl_topicState) {
case 0: { lcl_htmlLine += glb_htmlDatas_2[2][0]+glb_htmlDatas_2[2][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[2][2]; break; }
case 1: { lcl_htmlLine += glb_htmlDatas_2[4][0]+prm_lig+glb_htmlDatas_2[4][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[4][2]; break; }
default: { lcl_htmlLine += glb_htmlDatas_2[3][0]+prm_lig+glb_htmlDatas_2[3][1]+GetDataTopicsList(prm_lig,3)+glb_htmlDatas_2[3][2]; }
}
}
}
return(lcl_htmlLine);
}
private String CreateHtmlList(int prm_lig,int prm_col) {
String lcl_text = new String();
if (Defines.topicsUpdateIsInProgress) {
lcl_text = "<html><body>";
lcl_text += "<font face=\"helvetica\" color=\"green\" size=3><b>Recherche de nouveaux messages ...</b></font>";
lcl_text += "</body></html>";
return(lcl_text);
}
lcl_text = "<html><body>";
if (glb_vectTopicsHtmlList.size() > 0) {
lcl_text = "<table border=\"0\" cellpadding=\"0\">";
for (int i = 0 ; i < glb_vectTopicsHtmlList.size() ; i++) {
lcl_text += "<tr>";
lcl_text += (String)glb_vectTopicsHtmlList.elementAt(i);
lcl_text += "</tr>";
}
lcl_text += "</table>";
}
if (prm_col == 2) {
lcl_text += "<font face=\"helvetica\" color=\"#63619c\" size=2><b>";
lcl_text += new WebMemory().GetCategories(Integer.parseInt(GetDataTopicsList(prm_lig,1)))+" - ";
lcl_text += GetDataTopicsList(prm_lig,4)+"/"+GetDataTopicsList(prm_lig,5)+" - ";
lcl_text += GetDataTopicsList(prm_lig,6)+"/"+GetDataTopicsList(prm_lig,7);
lcl_text += "</b></font>";
}
else {
if (!(glb_vectTopicsList.size() >= Defines.MaxTopic)) {
if (glb_htmlDataAdd == false) {
lcl_text += "<font face=\"helvetica\" color=\"yellow\" size=3><a href=\"add\" style=\"text-decoration:none;\"><b>ADD</b></a></font>";
}
else {
lcl_text += "<font face=\"helvetica\" color=\"black\" bgcolor=\"yellow\" size=3><a href=\"add\" style=\"text-decoration:none;\"><b>ADD</b></a></font>";
}
}
}
lcl_text += "</body></html>";
return(lcl_text);
}
private void InitDatas() {
glb_htmlDatas_0[0][0] = "<td><font face=\"helvetica\" color=\"teal\" size=2><a href=\"col=0&lig=";
glb_htmlDatas_0[0][1] = "\" style=\"text-decoration:none;\"><b>DEL</b></a></font></td>";
glb_htmlDatas_0[1][0] = "<td><font face=\"helvetica\" color=black bgcolor=\"teal\" size=2><a href=\"col=0&lig=";
glb_htmlDatas_0[1][1] = "\" style=\"text-decoration:none;\"><b>DEL</b></a></font></td>";
glb_htmlDatas_1[0][0] = "<td width=\"35\" align=\"center\">";
glb_htmlDatas_1[0][1] = "";
glb_htmlDatas_1[0][2] = "</td>";
glb_htmlDatas_1[1][0] = "<td width=\"40\" align=\"center\"><font face=\"helvetica\" color=\"lime\" size=2><a href=\"col=1&lig=";
glb_htmlDatas_1[1][1] = "\" style=\"text-decoration:none;\"><b>+";
glb_htmlDatas_1[1][2] = "</b></a></font></td>";
glb_htmlDatas_1[2][0] = "<td width=\"40\" align=\"center\"><font face=\"helvetica\" color=\"black\" bgcolor=\"lime\" size=2><a href=\"col=1&lig=";
glb_htmlDatas_1[2][1] = "\" style=\"text-decoration:none;\">+";
glb_htmlDatas_1[2][2] = "</b></a></font></td>";
glb_htmlDatas_2[0][0] = "<td><font face=\"helvetica\" color=\"green\" size=2><a href=\"col=2&lig=";
glb_htmlDatas_2[0][1] = "\" style=\"text-decoration:none;\"><b>";
glb_htmlDatas_2[0][2] = "</b></a></font></td>";
glb_htmlDatas_2[1][0] = "<td><font face=\"helvetica\" color=\"white\" size=2><a href=\"col=2&lig=";
glb_htmlDatas_2[1][1] = "\" style=\"text-decoration:none;\"><b>";
glb_htmlDatas_2[1][2] = "</b></a></font></td>";
glb_htmlDatas_2[2][0] = "<td><font face=\"helvetica\" color=\"olive\" size=2>";
glb_htmlDatas_2[2][1] = "<strike>";
glb_htmlDatas_2[2][2] = "</strike></font></td>";
glb_htmlDatas_2[3][0] = "<td><font face=\"helvetica\" color=black bgcolor=\"white\" size=2><a href=\"col=2&lig=";
glb_htmlDatas_2[3][1] = "\" style=\"text-decoration:none;\"><b>";
glb_htmlDatas_2[3][2] = "</b></a></font></td>";
glb_htmlDatas_2[4][0] = "<td><font face=\"helvetica\" color=black bgcolor=\"green\" size=2><a href=\"col=2&lig=";
glb_htmlDatas_2[4][1] = "\" style=\"text-decoration:none;\"><b>";
glb_htmlDatas_2[4][2] = "</b></a></font></td>";
}
private boolean ParamatersColAndLigIsOk(String prm_description) {
int[] lcl_param = new int[3];
lcl_param = GetParametersColAndLig(prm_description);
if (lcl_param[0] == 0) return(false);
return(true);
}
private int[] GetParametersColAndLig(String prm_description) {
int[] lcl_param = new int[3];
try {
lcl_param[1] = Integer.parseInt(new WebParser().GetParameter(prm_description,"lig="));
lcl_param[2] = Integer.parseInt(new WebParser().GetParameter(prm_description,"col="));
lcl_param[0] = 1;
}
catch (NumberFormatException prm_nfe) {
lcl_param[0] = 0;
}
return(lcl_param);
}
private String GetDataTopicsList(int prm_lig,int prm_ind) {
return(((String[])glb_vectTopicsList.elementAt(prm_lig))[prm_ind]);
}
}