root / tmp / org.txm.analec.rcp / src matt / visuAnalec / PanneauEditeur.java @ 3225
Historique | Voir | Annoter | Télécharger (12,76 ko)
1 |
/*
|
---|---|
2 |
* To change this template, choose Tools | Templates
|
3 |
* and open the template in the editor.
|
4 |
*/
|
5 |
package visuAnalec; |
6 |
|
7 |
import java.awt.*; |
8 |
import java.util.*; |
9 |
import javax.swing.*; |
10 |
import javax.swing.border.*; |
11 |
import javax.swing.text.Document; |
12 |
import javax.swing.text.SimpleAttributeSet; |
13 |
import javax.swing.text.StyleConstants; |
14 |
import visuAnalec.Message.*; |
15 |
import visuAnalec.elements.*; |
16 |
import visuAnalec.texte.*; |
17 |
import visuAnalec.texte.PanneauTexte.*; |
18 |
import visuAnalec.util.GMessages.*; |
19 |
import visuAnalec.vue.*; |
20 |
import visuAnalec.vue.Vue.*; |
21 |
|
22 |
/**
|
23 |
*
|
24 |
* @author Bernard Victorri
|
25 |
*/
|
26 |
public class PanneauEditeur extends JPanel implements VueListener { |
27 |
private enum Commandes { |
28 |
GESTION_UNITES, |
29 |
GESTION_RELATIONS, |
30 |
GESTION_SCHEMAS, |
31 |
MODIF_TEXTE; |
32 |
private static Commandes getCommande(Class<? extends Element> classe) { |
33 |
if (classe==Unite.class) return GESTION_UNITES; |
34 |
if (classe==Relation.class) return GESTION_RELATIONS; |
35 |
if (classe==Schema.class) return GESTION_SCHEMAS; |
36 |
throw new UnsupportedOperationException("sous-classe non traitée"); |
37 |
} |
38 |
} |
39 |
private Vue vue;
|
40 |
private PanneauAffTexte panneauTexte;
|
41 |
private JPanel panneauOccurrences; |
42 |
private PanneauChamps panneauChamps;
|
43 |
private Commandes commandes = null; |
44 |
private HashMap<Commandes, PanneauCommandes> panneauxCommandes = |
45 |
new HashMap<Commandes, PanneauCommandes>(); |
46 |
private HashMap<Commandes, String> titresPanneauxCommandes = |
47 |
new HashMap<Commandes, String>(); |
48 |
private JDialog fenetreModifTexte; |
49 |
private PanneauModifTexte panneauModifTexte;
|
50 |
private PanneauCommandesModifTexte panneauCommandesModifTexte;
|
51 |
private String recherche = ""; |
52 |
private Element elementCourant; |
53 |
|
54 |
public static class ElementMarque { |
55 |
public Element elt; |
56 |
public String id; |
57 |
public TypeMarquage marque;
|
58 |
public ElementMarque(Element elt, TypeMarquage marque, String id) { |
59 |
this.elt = elt;
|
60 |
this.id = id;
|
61 |
this.marque = marque;
|
62 |
} |
63 |
} |
64 |
|
65 |
public static abstract class PanneauCommandes extends Box { |
66 |
protected Vue vue;
|
67 |
protected PanneauAffTexte panneauTexte;
|
68 |
PanneauCommandes(Vue vue, PanneauAffTexte panneauTexte) { |
69 |
super(BoxLayout.Y_AXIS); |
70 |
this.vue = vue;
|
71 |
this.panneauTexte = panneauTexte;
|
72 |
} |
73 |
public Vue getVue() {
|
74 |
return vue;
|
75 |
} |
76 |
abstract public void reafficher(); // quand la vue n'a pas changé |
77 |
abstract public void reinitialiser(); // quand la vue a changé |
78 |
abstract public void elementSuivant(int sens); |
79 |
abstract public Element elementSelectionne(); |
80 |
abstract public void editerElement(Element elt); |
81 |
abstract public void traiterElementEvent(ElementEvent evt); |
82 |
abstract public void traiterSourisEvent(PanneauAffTexte.SourisEvent evt); // appelée par le panneau AffTexte |
83 |
abstract public ArrayList<ElementMarque> trouverElementsVises(Unite uniteVisee, |
84 |
TypeMarquage marqueUniteVisee, boolean avecId); // appelée par le panneau AffTexte |
85 |
} |
86 |
public PanneauEditeur(Vue vue) {
|
87 |
super(new BorderLayout()); |
88 |
this.vue = vue;
|
89 |
vue.addEventListener(this);
|
90 |
setBorder(new TitledBorder("")); |
91 |
panneauOccurrences = new JPanel(new BorderLayout()); |
92 |
panneauTexte = new PanneauAffTexte(vue.getCorpus());
|
93 |
panneauOccurrences.add(new JScrollPane(panneauTexte), BorderLayout.CENTER); |
94 |
panneauChamps = new PanneauChamps(this, vue); |
95 |
add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, panneauOccurrences, panneauChamps), BorderLayout.CENTER); |
96 |
// Les différents panneaux de commandes
|
97 |
panneauxCommandes.put(Commandes.GESTION_UNITES, |
98 |
new PanneauCommandesUnites(vue, panneauTexte, panneauChamps));
|
99 |
titresPanneauxCommandes.put(Commandes.GESTION_UNITES, "Gestion des unités");
|
100 |
panneauxCommandes.put(Commandes.GESTION_RELATIONS, |
101 |
new PanneauCommandesRelations(vue, panneauTexte, panneauChamps));
|
102 |
titresPanneauxCommandes.put(Commandes.GESTION_RELATIONS, "Gestion des relations");
|
103 |
panneauxCommandes.put(Commandes.GESTION_SCHEMAS, |
104 |
new PanneauCommandesSchemas(vue, panneauTexte, panneauChamps));
|
105 |
titresPanneauxCommandes.put(Commandes.GESTION_SCHEMAS, "Gestion des schémas");
|
106 |
new GActionClavier(this, "suivant", "F1", "control DOWN") { |
107 |
public void executer() { |
108 |
elementSuivant(1);
|
109 |
} |
110 |
}; |
111 |
new GActionClavier(this, "précédent", "F2", "control UP") { |
112 |
public void executer() { |
113 |
elementSuivant(-1);
|
114 |
} |
115 |
}; |
116 |
new GActionClavier(this, "copier", "F3", "control M") { |
117 |
public void executer() { |
118 |
copierElement(); |
119 |
} |
120 |
}; |
121 |
new GActionClavier(this, "coller", "F4", "control R") { |
122 |
public void executer() { |
123 |
collerElement(); |
124 |
} |
125 |
}; |
126 |
// La fenêtre modale pour éditer le texte
|
127 |
fenetreModifTexte = new JDialog((VisuMain) getTopLevelAncestor(), true); |
128 |
fenetreModifTexte.setUndecorated(true);
|
129 |
fenetreModifTexte.getContentPane().setLayout(new BorderLayout()); |
130 |
panneauModifTexte = new PanneauModifTexte(vue.getCorpus());
|
131 |
fenetreModifTexte.getContentPane().add(new JScrollPane(panneauModifTexte), BorderLayout.CENTER); |
132 |
panneauCommandesModifTexte = new visuAnalec.texte.PanneauCommandesModifTexte(this, vue, panneauModifTexte); |
133 |
panneauModifTexte.setCommandesModifTexte(panneauCommandesModifTexte); |
134 |
fenetreModifTexte.getContentPane().add(panneauCommandesModifTexte, BorderLayout.SOUTH);
|
135 |
fenetreModifTexte.setVisible(false);
|
136 |
// Panneau initial : gestion des unités
|
137 |
changerPanneauCommandes(Commandes.GESTION_UNITES); |
138 |
reinitCommandes(); |
139 |
|
140 |
} |
141 |
void agencerPanneaux() {
|
142 |
JSplitPane split = (JSplitPane) panneauOccurrences.getParent(); |
143 |
split.setDividerLocation(2./3); |
144 |
revalidate(); |
145 |
repaint(); |
146 |
} |
147 |
private void changerPanneauCommandes(Commandes newCommandes) { |
148 |
if (commandes!=null) |
149 |
panneauOccurrences.remove(panneauxCommandes.get(commandes)); |
150 |
commandes = newCommandes; |
151 |
panneauOccurrences.add(panneauxCommandes.get(commandes), BorderLayout.NORTH);
|
152 |
((TitledBorder) getBorder()).setTitle(titresPanneauxCommandes.get(commandes));
|
153 |
panneauTexte.setCommandes(panneauxCommandes.get(commandes)); |
154 |
revalidate(); |
155 |
repaint(); |
156 |
} |
157 |
private void reinitCommandes() { |
158 |
panneauxCommandes.get(commandes).reinitialiser(); |
159 |
} |
160 |
private void elementSuivant(int sens) { |
161 |
panneauxCommandes.get(commandes).elementSuivant(sens); |
162 |
} |
163 |
private void copierElement() { |
164 |
Element elt = panneauxCommandes.get(commandes).elementSelectionne();
|
165 |
if (elt!=null) elementCourant = elt; |
166 |
} |
167 |
private void collerElement() { |
168 |
if (elementCourant==null) return; |
169 |
Element elt = panneauxCommandes.get(commandes).elementSelectionne();
|
170 |
if (elt==null) return; |
171 |
vue.copierValeurs(elementCourant, elt); |
172 |
} |
173 |
private void reinitCommandes(Element elt) { |
174 |
panneauxCommandes.get(commandes).reinitialiser(); |
175 |
panneauxCommandes.get(commandes).editerElement(elt); |
176 |
} |
177 |
private void reaffCommandes() { |
178 |
panneauxCommandes.get(commandes).reafficher(); |
179 |
} |
180 |
private void initNewCorpus() { |
181 |
panneauTexte.setTexteVisu(); |
182 |
panneauTexte.initAscenseur(); |
183 |
colorierTexte(); |
184 |
changerPanneauCommandes(Commandes.GESTION_UNITES); |
185 |
reinitCommandes(); |
186 |
} |
187 |
private void colorierTexte() { |
188 |
panneauTexte.setAttributsStandard(vue.getStyleTexte()); |
189 |
panneauTexte.colorierUnites(vue.getUnitesAColorier()); |
190 |
} |
191 |
void initRechercherTexte() {
|
192 |
recherche = (String) JOptionPane.showInputDialog(this, "Recherche dans le texte", |
193 |
"Rechercher", JOptionPane.PLAIN_MESSAGE, null, null, recherche); |
194 |
if (recherche==null) recherche = ""; |
195 |
if (recherche.isEmpty()) return; |
196 |
panneauTexte.rechercherTexte(recherche); |
197 |
} |
198 |
void rechercherSuivantTexte() {
|
199 |
if (recherche.isEmpty()) return; |
200 |
panneauTexte.rechercherTexte(recherche); |
201 |
|
202 |
} |
203 |
void initModifierTexte() {
|
204 |
((TitledBorder) getBorder()).setTitle("Modification du texte"); |
205 |
repaint(); |
206 |
fenetreModifTexte.setSize(panneauOccurrences.getSize()); |
207 |
fenetreModifTexte.setLocationRelativeTo(panneauOccurrences); |
208 |
panneauChamps.effacer(); |
209 |
panneauModifTexte.init(); |
210 |
fenetreModifTexte.setModal(false);
|
211 |
fenetreModifTexte.setVisible(true);
|
212 |
panneauModifTexte.ajusterAscenseur(panneauTexte); |
213 |
fenetreModifTexte.setVisible(false);
|
214 |
fenetreModifTexte.setModal(true);
|
215 |
fenetreModifTexte.setVisible(true);
|
216 |
} |
217 |
public void finModifTexte() { |
218 |
fenetreModifTexte.setVisible(false);
|
219 |
panneauTexte.ajusterAscenseur(panneauModifTexte); |
220 |
if (commandes==null) { |
221 |
changerPanneauCommandes(Commandes.GESTION_UNITES); |
222 |
reinitCommandes(); |
223 |
} else {
|
224 |
((TitledBorder) getBorder()).setTitle(titresPanneauxCommandes.get(commandes));
|
225 |
reaffCommandes(); |
226 |
} |
227 |
repaint(); |
228 |
} |
229 |
public void saisirStyleTexte(Vue vue) { |
230 |
VisuStyleTexte.newVisuStyleTexte(this, vue.getStyleTexte());
|
231 |
} |
232 |
public void changerStyleTexte(SimpleAttributeSet att) { |
233 |
vue.setStyleTexte(att); |
234 |
panneauTexte.setAttributsStandard(att); |
235 |
panneauModifTexte.setAttributsStandard(att); |
236 |
reaffCommandes(); |
237 |
} |
238 |
public Document getTexteFormate() { |
239 |
return panneauTexte.getDocument();
|
240 |
} |
241 |
public void editerElement(Element elt) { |
242 |
// typiquement, appelée de l'extérieur par d'autres fenêtres
|
243 |
changerPanneauCommandes(Commandes.getCommande(elt.getClass())); |
244 |
reinitCommandes(elt); |
245 |
((VisuMain) getTopLevelAncestor()).premierPlan(); |
246 |
} |
247 |
public void editerUniteChaine(Unite unit, Schema chaine) { |
248 |
// appelée de l'extérieur notamment par visuChaines)
|
249 |
changerPanneauCommandes(Commandes.GESTION_SCHEMAS); |
250 |
reinitCommandes(); |
251 |
((PanneauCommandesSchemas) panneauxCommandes.get(commandes)).editerSchemaElement(chaine, unit); |
252 |
((VisuMain) getTopLevelAncestor()).premierPlan(); |
253 |
} |
254 |
public void editerUniteTypeChaine(Unite unit, String typechaine) { |
255 |
// appelée de l'extérieur notamment par visuChaines)
|
256 |
changerPanneauCommandes(Commandes.GESTION_SCHEMAS); |
257 |
reinitCommandes(); |
258 |
((PanneauCommandesSchemas) panneauxCommandes.get(commandes)).editerElementTypeSchema(unit, typechaine); |
259 |
((VisuMain) getTopLevelAncestor()).premierPlan(); |
260 |
} |
261 |
void initGestionUnites() {
|
262 |
if (vue.getTypesUnitesAVoir().length==0) { |
263 |
JOptionPane.showMessageDialog(getTopLevelAncestor(), "Aucun type d'unités n'est défini dans la vue actuelle", |
264 |
"Saisie d'unités impossible", JOptionPane.ERROR_MESSAGE); |
265 |
return;
|
266 |
} |
267 |
changerPanneauCommandes(Commandes.GESTION_UNITES); |
268 |
reinitCommandes(); |
269 |
} |
270 |
void initGestionRelations() {
|
271 |
if (vue.getTypesRelationsAVoir().length==0) { |
272 |
JOptionPane.showMessageDialog(getTopLevelAncestor(), "Aucun type de relation n'est défini dans la vue actuelle", |
273 |
"Saisie de relations impossible", JOptionPane.ERROR_MESSAGE); |
274 |
return;
|
275 |
} |
276 |
changerPanneauCommandes(Commandes.GESTION_RELATIONS); |
277 |
reinitCommandes(); |
278 |
} |
279 |
void initGestionSchemas() {
|
280 |
if (vue.getTypesSchemasAVoir().length==0) { |
281 |
JOptionPane.showMessageDialog(getTopLevelAncestor(), "Aucun type de schéma n'est défini dans la vue actuelle", |
282 |
"Saisie de schéma impossible", JOptionPane.ERROR_MESSAGE); |
283 |
return;
|
284 |
} |
285 |
changerPanneauCommandes(Commandes.GESTION_SCHEMAS); |
286 |
reinitCommandes(); |
287 |
} |
288 |
public void traiterVueEvent(VueEvent evt) { |
289 |
switch (evt.getModif()) {
|
290 |
case EXTRACTION:
|
291 |
case NEW_VUE:
|
292 |
case VUE_DEFAUT:
|
293 |
colorierTexte(); |
294 |
reinitCommandes(); |
295 |
return;
|
296 |
default:
|
297 |
throw new UnsupportedOperationException("Cas "+evt.getModif()+" oublié dans un switch"); |
298 |
} |
299 |
} |
300 |
public void traiterStructureEvent(StructureEvent evt) { |
301 |
switch (evt.getModif()) {
|
302 |
case SUPPR_TYPE:
|
303 |
case FUSION_TYPE:
|
304 |
case RENOM_TYPE:
|
305 |
case AJOUT_TYPE:
|
306 |
case AJOUT_TYPE_ET_ELEMENTS:
|
307 |
colorierTexte(); |
308 |
reinitCommandes(); |
309 |
return;
|
310 |
case VALEUR_PAR_DEFAUT:
|
311 |
case AJOUT_FORME_UNITE:
|
312 |
case FUSION_PROP:
|
313 |
case RENOM_PROP:
|
314 |
case SUPPR_PROP:
|
315 |
case AJOUT_PROP:
|
316 |
case FUSION_VALEUR:
|
317 |
case RENOM_VALEUR:
|
318 |
case SUPPR_VALEUR:
|
319 |
case AJOUT_VALEUR:
|
320 |
colorierTexte(); |
321 |
panneauChamps.reafficher(); |
322 |
return;
|
323 |
default:
|
324 |
throw new UnsupportedOperationException("Cas "+evt.getModif()+" oublié dans un switch"); |
325 |
} |
326 |
} |
327 |
public void traiterEvent(Message evt) { |
328 |
switch (evt.getType()) {
|
329 |
case CLEAR_CORPUS:
|
330 |
initNewCorpus(); |
331 |
return;
|
332 |
case NEW_CORPUS:
|
333 |
initNewCorpus(); |
334 |
return;
|
335 |
case MODIF_TEXTE:
|
336 |
panneauTexte.setTexteVisu(); |
337 |
return;
|
338 |
case MODIF_VUE:
|
339 |
traiterVueEvent((VueEvent) evt); |
340 |
return;
|
341 |
case MODIF_STRUCTURE:
|
342 |
traiterStructureEvent((StructureEvent) evt); |
343 |
return;
|
344 |
case MODIF_ELEMENT:
|
345 |
colorierTexte(); |
346 |
panneauxCommandes.get(commandes).traiterElementEvent((ElementEvent) evt); |
347 |
return;
|
348 |
default:
|
349 |
throw new UnsupportedOperationException("Cas "+evt.getType()+" oublié dans un switch"); |
350 |
} |
351 |
|
352 |
} |
353 |
} |