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;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Component;
028: import java.awt.Container;
029: import java.awt.Dimension;
030: import java.awt.Frame;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033:
034: import javax.swing.BorderFactory;
035: import javax.swing.Box;
036: import javax.swing.BoxLayout;
037: import javax.swing.JButton;
038: import javax.swing.JDialog;
039: import javax.swing.JLabel;
040: import javax.swing.JOptionPane;
041: import javax.swing.JPanel;
042: import javax.swing.JTextField;
043:
044: /**
045: * Classe qui créer une fenêtre permettant de récupérer une chaîne de
046: * caractère.
047: */
048: public class AskName extends JDialog {
049:
050: /**
051: * La chaîne récupérée
052: */
053: private String result;
054:
055: /**
056: * Le Field permettant de récupérer la chaîne
057: */
058: private JTextField nomProjet;
059:
060: private String message;
061:
062: /******************************************************************************/
063: /** CONSTRUCTEUR ***/
064: /******************************************************************************/
065:
066: /**
067: * Constructeur de la fenêtre.
068: * @param textToBePrompt chaîne correspondant à la demande.
069: * @param title le titre de la fenêtre
070: */
071: public AskName(String textToBePrompt, String title, String type,
072: String oldValue, Frame owner) {
073:
074: super (owner, true);
075:
076: nomProjet = new JTextField(10);
077: JPanel page = new JPanel();
078:
079: JLabel text = new JLabel("");
080:
081: JLabel prompt = new JLabel(textToBePrompt);
082:
083: JPanel giveName = new JPanel();
084:
085: initData(type, oldValue);
086:
087: giveName.setLayout(new BoxLayout(giveName, BoxLayout.X_AXIS));
088: giveName.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
089: 10));
090: giveName.add(Box.createHorizontalGlue());
091: giveName.add(prompt);
092: giveName.add(Box.createRigidArea(new Dimension(10, 0)));
093: giveName.add(nomProjet);
094:
095: JPanel textPanel = new JPanel();
096: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
097: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
098: textPanel.add(giveName);
099: text.setAlignmentX(Component.LEFT_ALIGNMENT);
100:
101: JButton okButton = new JButton("Valider");
102: okButton.setToolTipText("Valider");
103: okButton.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent e) {
105: if (nomProjet.getText() != null) {
106: result = nomProjet.getText().trim();
107: } else {
108: result = "";
109: }
110: AskName.this .dispose();
111: }
112: });
113:
114: nomProjet.addActionListener(new ActionListener() {
115: public void actionPerformed(ActionEvent e) {
116: if ((nomProjet.getText() != null)
117: && (!nomProjet.getText().trim().equals(""))) {
118: result = nomProjet.getText().trim();
119: AskName.this .dispose();
120: } else if ((nomProjet.getText() != null)
121: && (nomProjet.getText().trim().equals(""))
122: && message.equals("valeur")) {
123: result = nomProjet.getText().trim();
124: AskName.this .dispose();
125: } else {
126: nomProjet.selectAll();
127: JOptionPane.showMessageDialog(AskName.this ,
128: "Vous devez entrez " + message + ".",
129: "Erreur !", JOptionPane.ERROR_MESSAGE);
130: result = null;
131: nomProjet.requestFocusInWindow();
132:
133: }
134:
135: }
136: });
137: JButton cancelButton = new JButton("Annuler");
138: cancelButton.setToolTipText("Annuler");
139: cancelButton.addActionListener(new ActionListener() {
140: public void actionPerformed(ActionEvent e) {
141: result = null;
142: AskName.this .dispose();
143: }
144: });
145:
146: JPanel buttonPanel = new JPanel();
147: buttonPanel.setLayout(new BorderLayout());
148: buttonPanel.add(okButton, BorderLayout.NORTH);
149: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
150:
151: page.add(textPanel, BorderLayout.WEST);
152: page.add(Box.createRigidArea(new Dimension(40, 10)),
153: BorderLayout.CENTER);
154: page.add(buttonPanel, BorderLayout.EAST);
155:
156: Container contentPaneFrame = this .getContentPane();
157: contentPaneFrame.add(page, BorderLayout.CENTER);
158:
159: this .setLocation(400, 300);
160: this .setTitle(title);
161: this .pack();
162: this .setVisible(true);
163: } // Fin du constructeur AskName/1
164:
165: /******************************************************************************/
166: /** METHODES PUBLIQUES ***/
167: /******************************************************************************/
168:
169: /**
170: * Récupère le nom entré
171: * @return le nom entré par l'utilisateur
172: */
173: public String getResult() {
174: return result;
175: } // Fin de la méthode getResult/0
176:
177: private void initData(String type, String oldValue) {
178: if (oldValue != null) {
179: nomProjet.setText(oldValue);
180: }
181: if (type.equals("valeur")) {
182: message = "une valeur";
183: } else if (type.equals("passe")) {
184: message = "un mot de passe";
185: } else if (type.equals("url")) {
186: message = "une url";
187: } else if (type.equals("classpath")) {
188: message = " un classPath";
189: } else if (type.equals("class")) {
190: message = "une classe";
191: } else {
192: message = "un nom";
193: }
194: }
195: } // Fin de la classe AskName
|