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