Source code: jaxe/elements/JEString.java
1 /*
2 Jaxe - Editeur XML en Java
3
4 Copyright (C) 2002 Observatoire de Paris-Meudon
5
6 Ce programme est un logiciel libre ; vous pouvez le redistribuer et/ou le modifier conformément aux dispositions de la Licence Publique Générale GNU, telle que publiée par la Free Software Foundation ; version 2 de la licence, ou encore (à votre choix) toute version ultérieure.
7
8 Ce programme est distribué dans l'espoir qu'il sera utile, mais SANS AUCUNE GARANTIE ; sans même la garantie implicite de COMMERCIALISATION ou D'ADAPTATION A UN OBJET PARTICULIER. Pour plus de détail, voir la Licence Publique Générale GNU .
9
10 Vous devez avoir reçu un exemplaire de la Licence Publique Générale GNU en même temps que ce programme ; si ce n'est pas le cas, écrivez à la Free Software Foundation Inc., 675 Mass Ave, Cambridge, MA 02139, Etats-Unis.
11 */
12
13 package jaxe.elements;
14
15 import jaxe.DialogueAttributs;
16 import jaxe.JaxeDocument;
17 import jaxe.JaxeElement;
18 import jaxe.JaxeResourceBundle;
19
20 import java.awt.*;
21 import java.util.ArrayList;
22 import javax.swing.*;
23 import javax.swing.text.Position;
24 import javax.swing.text.BadLocationException;
25 import javax.swing.text.SimpleAttributeSet;
26
27 import org.w3c.dom.*;
28
29 /**
30 * Petite zone de texte.
31 * Type d'élément Jaxe: 'string'
32 * paramètre: style: NORMAL | GRAS | ITALIQUE | EXPOSANT | INDICE | SOULIGNE
33 */
34 public class JEString extends JaxeElement {
35
36 MonBouton lstart = null;
37 MonBouton lend = null;
38 ArrayList attributsTitre = null;
39
40 public JEString(JaxeDocument doc) {
41 this.doc = doc;
42 }
43
44 public void init(Position pos, Node noeud) {
45 Element el = (Element)noeud;
46
47 String titre = el.getTagName();
48 Element defbalise = null;
49 if (doc.cfg != null)
50 defbalise = doc.cfg.getBaliseDef(el.getTagName());
51 String valeurTitre = null;
52 if (defbalise != null) {
53 attributsTitre = doc.cfg.getValeursParam(defbalise, "titreAtt");
54 for (int i=0; i<attributsTitre.size() && valeurTitre == null; i++)
55 if (!"".equals(el.getAttribute((String)attributsTitre.get(i))))
56 valeurTitre = el.getAttribute((String)attributsTitre.get(i));
57 }
58 if (valeurTitre != null)
59 titre += " '" + valeurTitre + "'";
60 titre += " >";
61 lstart = new MonBouton(titre, false);
62 int offsetdebut = pos.getOffset();
63 Position newpos = insertComponent(pos, lstart);
64
65 creerEnfants(newpos);
66
67 lend = new MonBouton("< " + el.getTagName(), false);
68 insertComponent(newpos, lend);
69 if (defbalise != null && newpos.getOffset() - offsetdebut - 1 > 0) {
70 SimpleAttributeSet style = attStyle(null);
71 if (style != null)
72 doc.setCharacterAttributes(offsetdebut, newpos.getOffset() - offsetdebut - 1, style, false);
73 }
74 }
75
76 public Element nouvelElement(Element defbalise) {
77 String nombalise = doc.cfg.nomBalise(defbalise);
78 Element newel = nouvelElementDOM(doc, nombalise);
79 ArrayList latt = doc.cfg.listeAttributs(defbalise);
80 if (latt != null && latt.size() > 0) {
81 DialogueAttributs dlg = new DialogueAttributs(doc.jframe, doc,
82 JaxeResourceBundle.getRB().getString("zone.NouvelleBalise") + " " + nombalise, defbalise, newel);
83 if (!dlg.afficher())
84 return null;
85 try {
86 dlg.enregistrerReponses();
87 } catch (Exception ex) {
88 System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
89 return(null);
90 }
91 }
92
93 return(newel);
94 }
95
96 public Position insPosition() {
97 try {
98 return(doc.createPosition(debut.getOffset() + 1));
99 } catch (BadLocationException ex) {
100 System.err.println("BadLocationException: " + ex.getMessage());
101 return(null);
102 }
103 }
104
105 public void afficherDialogue(JFrame jframe) {
106 Element el = (Element)noeud;
107
108 Element defbalise = doc.cfg.getBaliseDef(el.getTagName());
109 ArrayList latt = doc.cfg.listeAttributs(defbalise);
110 if (latt != null && latt.size() > 0) {
111 DialogueAttributs dlg = new DialogueAttributs(doc.jframe, doc,
112 getString("string.String") + ": " + el.getTagName(), defbalise, el);
113 if (!dlg.afficher())
114 return;
115 dlg.enregistrerReponses();
116 }
117 majAffichage();
118 }
119
120 public void majAffichage() {
121 Element el = (Element)noeud;
122
123 String titreBstart = el.getTagName();
124 String valeurTitre = null;
125 if (attributsTitre != null) {
126 for (int i=0; i<attributsTitre.size() && valeurTitre == null; i++)
127 if (!"".equals(el.getAttribute((String)attributsTitre.get(i))))
128 valeurTitre = el.getAttribute((String)attributsTitre.get(i));
129 }
130 if (valeurTitre != null)
131 titreBstart += " '" + valeurTitre + "'";
132 titreBstart += " >";
133 String titreBend = "< " + el.getTagName();
134 lstart.setText(titreBstart);
135 lend.setText(titreBend);
136 doc.imageChanged(lstart);
137 doc.imageChanged(lend);
138 }
139 }