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 Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.main;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Color;
028: import java.awt.Component;
029: import java.awt.Container;
030: import java.awt.Dimension;
031: import java.awt.Rectangle;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034:
035: import javax.swing.BorderFactory;
036: import javax.swing.Box;
037: import javax.swing.BoxLayout;
038: import javax.swing.JButton;
039: import javax.swing.JComboBox;
040: import javax.swing.JDialog;
041: import javax.swing.JLabel;
042: import javax.swing.JOptionPane;
043: import javax.swing.JPanel;
044: import javax.swing.JScrollPane;
045: import javax.swing.JTextArea;
046: import javax.swing.JTextField;
047:
048: import org.objectweb.salome_tmf.data.Campaign;
049: import org.objectweb.salome_tmf.ihm.languages.Language;
050: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
051:
052: /**
053: * Classe qui définit la fenêtre permettant de créer une nouvelle campagne
054: * @author teaml039
055: * @version 0.1
056: */
057: public class AskNewCampagne extends JDialog {
058:
059: /**
060: * Le champ du nom de campagne
061: */
062: JTextField campagneNameField;
063:
064: /**
065: * Le champ du concepteur
066: */
067: JComboBox conceptorNameField;
068:
069: /**
070: * La description
071: */
072: JTextArea descriptionArea;
073:
074: /**
075: * La campagne créée
076: */
077: Campaign campagne;
078:
079: /******************************************************************************/
080: /** CONSTRUCTEUR ***/
081: /******************************************************************************/
082:
083: /**
084: * Constructeur de la fenêtre.
085: * @param textToBePrompt chaîne correspondant à la demande.
086: */
087: public AskNewCampagne(Component parent, String textToBePrompt) {
088:
089: //Pour bloquer le focus sur la boite de dialogue
090: super (SalomeTMFContext.getInstance().ptrFrame, true);
091: campagneNameField = new JTextField(10);
092: conceptorNameField = new JComboBox();
093: descriptionArea = new JTextArea(10, 20);
094: JPanel page = new JPanel();
095:
096: JLabel testNameLabel = new JLabel(Language.getInstance()
097: .getText("Nom_de_la_campagne_:_"));
098: JLabel conceptorNameLabel = new JLabel(Language.getInstance()
099: .getText("Nom_du_concepteur_:"));
100:
101: JPanel giveName = new JPanel();
102: giveName.setLayout(new BoxLayout(giveName, BoxLayout.X_AXIS));
103: giveName.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
104: 10));
105: giveName.add(Box.createHorizontalGlue());
106: giveName.add(testNameLabel);
107: giveName.add(Box.createRigidArea(new Dimension(10, 0)));
108: giveName.add(campagneNameField);
109:
110: JPanel giveConceptorName = new JPanel();
111: giveConceptorName.setLayout(new BoxLayout(giveConceptorName,
112: BoxLayout.X_AXIS));
113: giveConceptorName.setBorder(BorderFactory.createEmptyBorder(0,
114: 10, 10, 10));
115: giveConceptorName.add(Box.createHorizontalGlue());
116: giveConceptorName.add(conceptorNameLabel);
117: giveConceptorName
118: .add(Box.createRigidArea(new Dimension(10, 0)));
119: giveConceptorName.add(conceptorNameField);
120:
121: //descriptionArea.setPreferredSize(new Dimension(100,150));
122: JScrollPane descriptionScrollPane = new JScrollPane(
123: descriptionArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
124: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
125: descriptionScrollPane.setBorder(BorderFactory
126: .createTitledBorder(BorderFactory
127: .createLineBorder(Color.BLACK), Language
128: .getInstance().getText("Description")));
129:
130: JPanel textPanel = new JPanel();
131: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
132: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
133: textPanel.add(giveName);
134:
135: textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
136: textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
137: textPanel.add(descriptionScrollPane);
138:
139: JButton okButton = new JButton(Language.getInstance().getText(
140: "Valider"));
141: okButton.setToolTipText(Language.getInstance().getText(
142: "Valider"));
143: okButton.addActionListener(new ActionListener() {
144: public void actionPerformed(ActionEvent e) {
145:
146: if (campagneNameField.getText() != null
147: && !campagneNameField.getText().trim().equals(
148: "")) {
149: campagne = new Campaign(campagneNameField.getText()
150: .trim(), descriptionArea.getText());
151: campagne.setConceptorInModel(DataModel
152: .getCurrentUser().getLoginFromModel());
153: AskNewCampagne.this .dispose();
154: } else {
155: JOptionPane
156: .showMessageDialog(
157: AskNewCampagne.this ,
158: Language
159: .getInstance()
160: .getText(
161: "Il_faut_obligatoirement_donner_un_nom_à_la_campagne_!"),
162: Language.getInstance().getText(
163: "Attention_!"),
164: JOptionPane.WARNING_MESSAGE);
165: }
166: }
167: });
168:
169: campagneNameField.addActionListener(new ActionListener() {
170: public void actionPerformed(ActionEvent e) {
171: }
172: });
173:
174: JButton cancelButton = new JButton(Language.getInstance()
175: .getText("Annuler"));
176: cancelButton.setToolTipText(Language.getInstance().getText(
177: "Annuler"));
178: cancelButton.addActionListener(new ActionListener() {
179: public void actionPerformed(ActionEvent e) {
180: AskNewCampagne.this .dispose();
181: }
182: });
183:
184: JPanel buttonPanel = new JPanel();
185: buttonPanel.setLayout(new BorderLayout());
186: buttonPanel.add(okButton, BorderLayout.NORTH);
187: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
188:
189: page.add(textPanel, BorderLayout.WEST);
190: page.add(Box.createRigidArea(new Dimension(40, 10)),
191: BorderLayout.CENTER);
192: page.add(buttonPanel, BorderLayout.EAST);
193:
194: Container contentPaneFrame = this .getContentPane();
195: contentPaneFrame.add(page, BorderLayout.CENTER);
196: this .setTitle(textToBePrompt);
197: /*this.pack();
198: this.setLocationRelativeTo(this.getParent());
199: this.setVisible(true);*/
200: centerScreen();
201: } // Fin du constructeur AskNewCampagne/2
202:
203: void centerScreen() {
204: Dimension dim = getToolkit().getScreenSize();
205: this .pack();
206: Rectangle abounds = getBounds();
207: setLocation((dim.width - abounds.width) / 2,
208: (dim.height - abounds.height) / 2);
209: this .setVisible(true);
210: requestFocus();
211: }
212:
213: /******************************************************************************/
214: /** METHODES PUBLIQUES ***/
215: /******************************************************************************/
216:
217: /**
218: * Retourne la campagne
219: * @return la campagne
220: */
221: public Campaign getCampagne() {
222: return campagne;
223: } // Fin de la méthode getCampagne/0
224:
225: } // Fin de la classe AskNewCampagne
|