001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Aurore PENAULT
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package salomeTMF_plug.gen_doc_xml;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.Font;
031: import java.awt.GridLayout;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.io.File;
035: import java.net.URL;
036: import java.text.DateFormat;
037: import java.util.Date;
038: import java.util.Locale;
039:
040: import javax.swing.BorderFactory;
041: import javax.swing.Box;
042: import javax.swing.BoxLayout;
043: import javax.swing.JButton;
044: import javax.swing.JDialog;
045: import javax.swing.JFileChooser;
046: import javax.swing.JLabel;
047: import javax.swing.JOptionPane;
048: import javax.swing.JPanel;
049: import javax.swing.JScrollPane;
050: import javax.swing.JTextArea;
051: import javax.swing.JTextField;
052:
053: import org.dom4j.DocumentFactory;
054: import org.dom4j.Element;
055: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
056: import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
057: import org.objectweb.salome_tmf.ihm.tools.Tools;
058:
059: import salomeTMF_plug.gen_doc_xml.languages.Language;
060:
061: import com.toedter.calendar.JDateChooser;
062:
063: /**
064: * Classe créant l'IMM permettant à l'utilisateur de remplir un formulaire
065: * afin de pouvoir générer à partir de ces informations une page de garde
066: * @author vapu8214
067: */
068: public class GardeDialog extends JDialog {
069:
070: JLabel logoLabel;
071: JTextField logoTextField;
072: JButton logoButton;
073: String logoFile = "";
074: URL urlLogo;
075:
076: JLabel entrepriseLabel;
077: JTextArea entrepriseArea;
078:
079: JLabel auteurLabel;
080: JTextField auteurTextField;
081:
082: JLabel emailLabel;
083: JTextField emailTextField;
084:
085: JLabel titreLabel;
086: JTextField titreTextField;
087:
088: JLabel versionLabel;
089: JTextField versionTextField;
090:
091: JDateChooser date;
092:
093: JLabel infosLabel;
094: JTextArea infosArea;
095:
096: JButton annuler;
097: JButton valider;
098:
099: JLabel champ;
100:
101: GraphicDialog g;
102:
103: /** Creates a new instance of GardeDialog */
104: public GardeDialog(GraphicDialog g) {
105: super (g, true);
106: this .g = g;
107: logoLabel = new JLabel(Language.getInstance()
108: .getText("Logo_:_"));
109: logoTextField = new JTextField(30);
110: logoButton = new JButton(Language.getInstance().getText(
111: "Choisir..."));
112: logoButton.addActionListener(new ActionListener() {
113: public void actionPerformed(ActionEvent e) {
114: JFileChooser fileChooser = new JFileChooser();
115: String[] tab = { ".jpeg", ".jpg", ".png", ".gif" };
116: fileChooser
117: .addChoosableFileFilter(new ScriptFileFilter(
118: Language
119: .getInstance()
120: .getText(
121: "Fichiers_[*.jpeg;_*.jpg;_*.png;_*.gif]"),
122: tab));
123: int returnVal = fileChooser.showDialog(
124: GardeDialog.this , Language.getInstance()
125: .getText("Sélectionner"));
126: if (returnVal == JFileChooser.APPROVE_OPTION) {
127: try {
128: logoFile = fileChooser.getSelectedFile()
129: .getAbsolutePath();
130: urlLogo = fileChooser.getSelectedFile().toURL();
131: logoTextField.setText(logoFile);
132: } catch (Exception ex) {
133: Tools.ihmExceptionView(ex);
134: }
135: }
136: }
137: });
138:
139: entrepriseLabel = new JLabel(Language.getInstance().getText(
140: "Entreprise_:_"));
141: entrepriseArea = new JTextArea(3, 30);
142: JScrollPane entreprisePane = new JScrollPane(entrepriseArea);
143:
144: auteurLabel = new JLabel(Language.getInstance().getText(
145: "Auteur_:_"));
146: auteurTextField = new JTextField(30);
147: auteurTextField.setText(DataModel.getCurrentUser()
148: .getFirstNameFromModel()
149: + " "
150: + DataModel.getCurrentUser().getLastNameFromModel());
151:
152: emailLabel = new JLabel(Language.getInstance().getText(
153: "Email_:_"));
154: emailTextField = new JTextField(30);
155: emailTextField.setText(DataModel.getCurrentUser()
156: .getEmailFromModel());
157:
158: titreLabel = new JLabel(Language.getInstance().getText(
159: "Titre_du_document_(*)_:_"));
160: titreTextField = new JTextField(30);
161: titreTextField.setText(DataModel.getCurrentProject()
162: .getNameFromModel());
163:
164: versionLabel = new JLabel(Language.getInstance().getText(
165: "Version_du_document_:_"));
166: versionTextField = new JTextField(30);
167:
168: infosLabel = new JLabel(Language.getInstance().getText(
169: "Informations_complémentaires_:_"));
170: infosArea = new JTextArea(2, 30);
171: JScrollPane infosPane = new JScrollPane(infosArea);
172:
173: annuler = new JButton(Language.getInstance().getText("Annuler"));
174: annuler.addActionListener(new ActionListener() {
175: public void actionPerformed(ActionEvent e) {
176: GardeDialog.this .dispose();
177: }
178: });
179:
180: valider = new JButton(Language.getInstance().getText("Valider"));
181: valider.addActionListener(new ActionListener() {
182: public void actionPerformed(ActionEvent e) {
183: FormSave save = new FormSave(logoTextField.getText(),
184: entrepriseArea.getText(), auteurTextField
185: .getText(), emailTextField.getText(),
186: titreTextField.getText(), versionTextField
187: .getText(), date.getDate(), infosArea
188: .getText());
189: GardeDialog.this .g.setSave(save);
190: if (titreTextField.getText().equals("")) {
191: JOptionPane
192: .showMessageDialog(
193: GardeDialog.this ,
194: Language
195: .getInstance()
196: .getText(
197: "Vous_devez_entrez_un_titre_pour_le_document"),
198: Language.getInstance().getText(
199: "Erreur_!"),
200: JOptionPane.ERROR_MESSAGE);
201: } else {
202: //vérif que le fichier donné pour le logo existe
203: if (!logoTextField.getText().equals("")) {
204: File fic = new File(logoTextField.getText());
205: boolean estFichier = fic.exists();
206: //System.out.println(Language.getInstance().getText("le_fichier_existe")+estFichier);
207: if (!estFichier) {
208: JOptionPane
209: .showMessageDialog(
210: GardeDialog.this ,
211: Language
212: .getInstance()
213: .getText(
214: "Vous_devez_entrez_un_nom_de_fichier_existant"),
215: Language
216: .getInstance()
217: .getText("Erreur_!"),
218: JOptionPane.ERROR_MESSAGE);
219: } else {
220: createPage(GardeDialog.this .g);
221: }
222: } else {
223: createPage(GardeDialog.this .g);
224: }
225: }
226: }
227: });
228:
229: champ = new JLabel(Language.getInstance().getText(
230: "*_:_champ_obligatoire"));
231: champ.setFont(new Font(null, Font.ITALIC, 12));
232:
233: JPanel logoChois = new JPanel(new FlowLayout(FlowLayout.LEFT));
234: logoChois.add(logoButton);
235:
236: JPanel logo1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
237: logo1.add(logoTextField);
238:
239: JPanel logo2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
240: logo2.add(logoLabel);
241:
242: JPanel pan1 = new JPanel(new BorderLayout());
243: pan1.setBorder(BorderFactory.createTitledBorder(""));
244: pan1.add(logo2, BorderLayout.NORTH);
245: pan1.add(logo1, BorderLayout.CENTER);
246: pan1.add(logoChois, BorderLayout.SOUTH);
247:
248: JPanel entreprise = new JPanel(new FlowLayout(FlowLayout.LEFT));
249: entreprise.add(entrepriseLabel);
250:
251: JPanel entreprise1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
252: entreprise1.add(entreprisePane);
253:
254: JPanel ent1 = new JPanel(new BorderLayout());
255: ent1.setBorder(BorderFactory.createTitledBorder(""));
256: ent1.add(entreprise, BorderLayout.NORTH);
257: ent1.add(entreprise1, BorderLayout.CENTER);
258:
259: JPanel infosSte = new JPanel();
260: infosSte.setLayout(new GridLayout(1, 2));
261: infosSte.add(pan1);
262: infosSte.add(ent1);
263:
264: JPanel auteur = new JPanel(new FlowLayout(FlowLayout.LEFT));
265: auteur.add(auteurLabel);
266:
267: JPanel auteur1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
268: auteur1.add(auteurTextField);
269:
270: JPanel email = new JPanel(new FlowLayout(FlowLayout.LEFT));
271: email.add(emailLabel);
272:
273: JPanel email1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
274: email1.add(emailTextField);
275:
276: JPanel aut1 = new JPanel(new BorderLayout());
277: aut1.setBorder(BorderFactory.createTitledBorder(""));
278: aut1.add(auteur, BorderLayout.NORTH);
279: aut1.add(auteur1, BorderLayout.CENTER);
280:
281: JPanel mail1 = new JPanel(new BorderLayout());
282: mail1.setBorder(BorderFactory.createTitledBorder(""));
283: mail1.add(email, BorderLayout.NORTH);
284: mail1.add(email1, BorderLayout.CENTER);
285:
286: JPanel infosAuteur = new JPanel();
287: infosAuteur.setLayout(new GridLayout(1, 2));
288: infosAuteur.add(aut1);
289: infosAuteur.add(mail1);
290:
291: JPanel titre = new JPanel(new FlowLayout(FlowLayout.LEFT));
292: titre.add(titreLabel);
293:
294: JPanel titre1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
295: titre1.add(titreTextField);
296:
297: JPanel tit1 = new JPanel(new BorderLayout());
298: tit1.setBorder(BorderFactory.createTitledBorder(""));
299: tit1.add(titre, BorderLayout.NORTH);
300: tit1.add(titre1, BorderLayout.CENTER);
301:
302: JPanel version = new JPanel(new FlowLayout(FlowLayout.LEFT));
303: version.add(versionLabel);
304:
305: JPanel version1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
306: version1.add(versionTextField);
307:
308: JPanel vers1 = new JPanel(new BorderLayout());
309: vers1.setBorder(BorderFactory.createTitledBorder(""));
310: vers1.add(version, BorderLayout.NORTH);
311: vers1.add(version1, BorderLayout.CENTER);
312:
313: JPanel infosTitre = new JPanel();
314: infosTitre.setLayout(new GridLayout(1, 2));
315: infosTitre.add(tit1);
316: infosTitre.add(vers1);
317:
318: JLabel dateLabel = new JLabel(Language.getInstance().getText(
319: "Date_:"));
320: JPanel dateLabelPanel = new JPanel(new FlowLayout(
321: FlowLayout.LEFT));
322: dateLabelPanel.add(dateLabel);
323: date = new JDateChooser("d MMMMM yyyy", false);
324: JPanel datePanel = new JPanel();
325: datePanel.setLayout(new BoxLayout(datePanel, BoxLayout.Y_AXIS));
326: datePanel.setBorder(BorderFactory.createTitledBorder(""));
327: datePanel.add(dateLabelPanel);
328: datePanel.add(Box.createRigidArea(new Dimension(1, 10)));
329: datePanel.add(date);
330:
331: JPanel infos = new JPanel(new FlowLayout(FlowLayout.LEFT));
332: infos.add(infosLabel);
333:
334: JPanel infos1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
335: infos1.add(infosPane);
336:
337: JPanel inf1 = new JPanel(new BorderLayout());
338: inf1.setBorder(BorderFactory.createTitledBorder(""));
339: inf1.add(infos, BorderLayout.NORTH);
340: inf1.add(infos1, BorderLayout.CENTER);
341:
342: JPanel dateInfos = new JPanel();
343: dateInfos.setLayout(new GridLayout(1, 2));
344: dateInfos.add(datePanel);
345: dateInfos.add(inf1);
346:
347: /* JPanel endPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
348: endPanel.add(valider);
349: endPanel.add(annuler);*/
350: JPanel endPanel = new JPanel();
351: endPanel.setLayout(new BoxLayout(endPanel, BoxLayout.X_AXIS));
352: endPanel.add(Box.createHorizontalStrut(230));
353: endPanel.add(valider);
354: endPanel.add(annuler);
355: endPanel.add(Box.createHorizontalStrut(100));
356: endPanel.add(champ);
357:
358: JPanel page = new JPanel();
359: page.setLayout(new BoxLayout(page, BoxLayout.Y_AXIS));
360: page.add(infosSte);
361: page.add(Box.createRigidArea(new Dimension(1, 10)));
362: page.add(infosAuteur);
363: page.add(Box.createRigidArea(new Dimension(1, 10)));
364: page.add(infosTitre);
365: page.add(Box.createRigidArea(new Dimension(1, 10)));
366: page.add(dateInfos);
367: page.add(Box.createRigidArea(new Dimension(1, 10)));
368: page.add(endPanel);
369:
370: JPanel vide, vide1, vide2, vide3;
371: vide = new JPanel();
372: vide1 = new JPanel();
373: vide2 = new JPanel();
374: vide3 = new JPanel();
375:
376: if (g.getSave() != null) {
377: restore(g.getSave());
378: }
379:
380: Container contentPaneFrame = this .getContentPane();
381: contentPaneFrame.add(page, BorderLayout.CENTER);
382: contentPaneFrame.add(vide, BorderLayout.NORTH);
383: contentPaneFrame.add(vide1, BorderLayout.EAST);
384: contentPaneFrame.add(vide2, BorderLayout.SOUTH);
385: contentPaneFrame.add(vide3, BorderLayout.WEST);
386:
387: this .setLocation(300, 100);
388: this .setTitle(Language.getInstance().getText("Page_de_garde"));
389: this .pack();
390: this .setVisible(true);
391:
392: }
393:
394: /**
395: * Méthode quirestaure les éléments sauvegardés
396: * @param save objet qui sauvegarde les différentes valeurs des champs du formulaire
397: */
398: public void restore(FormSave save) {
399: logoTextField.setText(save.getLogo());
400: entrepriseArea.setText(save.getEntreprise());
401: auteurTextField.setText(save.getAuteur());
402: emailTextField.setText(save.getEmail());
403: titreTextField.setText(save.getTitre());
404: versionTextField.setText(save.getVersion());
405: date.setDate(save.getDate());
406: infosArea.setText(save.getInfos());
407: }
408:
409: /**
410: * Méthode qui créé l'élément à insérer dans lengthdocument Html
411: * afin d'obtenir une page de garde
412: */
413: public void createPage(GraphicDialog g) {
414: DocumentFactory factory = new DocumentFactory();
415: Element aTransmettre = factory.createElement("table");
416: aTransmettre.addAttribute("style", "height:30cm; ");
417: aTransmettre.addAttribute("width", "100%");
418: Element tr1 = aTransmettre.addElement("tr");
419: Element td11 = tr1.addElement("td");
420: if (!logoTextField.getText().equals("")) {
421: Element img1 = td11.addElement("img");
422: //img1.addAttribute("src", logoTextField.getText());
423: img1.addAttribute("src", urlLogo.toString());
424: img1.addAttribute("border", "0");
425: }
426: Element td12 = tr1.addElement("td");
427: td12.addAttribute("colspan", "2");
428: Element div = td12.addElement("div");
429: div.addAttribute("style", "padding-left:2cm; ");
430: if (!entrepriseArea.getText().equals("")) {
431: String[] list = entrepriseArea.getText().split("\n");
432: div.addElement("h3").setText(list[0]);//à voir pour les retours à la ligne
433: for (int i = 1; i < list.length; i++) {
434: div.addText(list[i]);
435: if (i != list.length) {
436: div.addElement("br");
437: }
438: }
439: }
440: Element tr2 = aTransmettre.addElement("tr");
441: Element td21 = tr2.addElement("td");
442: td21.addAttribute("colspan", "3");
443: td21.addAttribute("height", "25%");
444: Element tr3 = aTransmettre.addElement("tr");
445: Element td31 = tr3.addElement("td");
446: td31.addAttribute("colspan", "3");
447: td31.addAttribute("height", "5%");
448: Element table3 = td31.addElement("table");
449: table3.addAttribute("bgcolor", "#ff9933");
450: table3.addAttribute("width", "90%");
451: table3.addAttribute("border", "0");
452: table3.addAttribute("cellpading", "0");
453: table3.addAttribute("cellspacing", "3");
454: table3.addAttribute("align", "center");
455: Element t3tr1 = table3.addElement("tr");
456: Element t3td11 = t3tr1.addElement("td");
457: Element font = t3td11.addElement("font");
458: font.addAttribute("color", "#ffffff");
459: font.addAttribute("size", "8");
460: font.addElement("center").setText(titreTextField.getText());
461: Element t3tr2 = table3.addElement("tr");
462: Element t3td21 = t3tr2.addElement("td");
463: if (!versionTextField.getText().equals("")) {
464: Element font2 = t3td21.addElement("font");
465: font2.addAttribute("color", "#ffffff");
466: font2.addAttribute("size", "4");
467: font2.addElement("center").setText(
468: "Version " + versionTextField.getText());
469: }
470: Element tr4 = aTransmettre.addElement("tr");
471: Element td41 = tr4.addElement("td");
472: td41.addAttribute("height", "45%");
473: Element td42 = tr4.addElement("td");
474: String infos = infosArea.getText();
475: Element table4 = td42.addElement("table");
476: table4.addAttribute("width", "80%");
477: table4.addAttribute("height", "80%");
478: table4.addAttribute("valign", "center");
479: table4.addAttribute("border", "0");
480: table4.addAttribute("align", "center");
481: Element t4tr1 = table4.addElement("tr");
482: Element t4td11 = t4tr1.addElement("td");
483: if (!infos.equals("")) {
484: String[] list2 = infos.split("\n");
485: for (int i = 0; i < list2.length; i++) {
486: t4td11.addText(list2[i]);
487: t4td11.addElement("br");
488: }
489: }
490: Element tr5 = aTransmettre.addElement("tr");
491: Element td51 = tr5.addElement("td");
492: td51.addAttribute("height", "15%");
493: td51.addAttribute("valign", "center");
494: Date d = date.getDate();
495: DateFormat df = DateFormat.getDateInstance(DateFormat.FULL,
496: Locale.FRENCH);
497: td51.setText(df.format(d));
498: Element td52 = tr5.addElement("td");
499: td52.addAttribute("colspan", "2");
500: td52.addAttribute("align", "right");
501: td52.addAttribute("valign", "center");
502: if (!auteurTextField.getText().equals("")) {
503: td52.addText(auteurTextField.getText());
504: td52.addElement("br");
505: if (!emailTextField.getText().equals("")) {
506: Element a = td52.addElement("a");
507: a.addAttribute("title", Language.getInstance().getText(
508: "Contacter_l'auteur"));
509: a.addAttribute("href", "mailto:"
510: + emailTextField.getText());
511: Element img = a.addElement("img");
512: img.addAttribute("alt", Language.getInstance().getText(
513: "Contacter_l'auteur"));
514: img
515: .addAttribute(
516: "src",
517: (getClass()
518: .getResource("/salomeTMF_plug/gen_doc_xml/resources/img/pied_mail.gif"))
519: .toString());
520: img.addAttribute("border", "0");
521: img.addAttribute("width", "25");
522: img.addAttribute("height", "42");
523: }
524: }
525: g.setElement(aTransmettre);
526: GardeDialog.this .dispose();
527: }
528: }//Fin de la classe GardeDialog
|