001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.loader.gui;
028:
029: import java.awt.Container;
030: import java.awt.FlowLayout;
031: import java.awt.Frame;
032: import java.awt.GridLayout;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035:
036: import javax.swing.JButton;
037: import javax.swing.JDialog;
038: import javax.swing.JFileChooser;
039: import javax.swing.JFrame;
040: import javax.swing.JLabel;
041: import javax.swing.JOptionPane;
042: import javax.swing.JPanel;
043: import javax.swing.JTextArea;
044: import javax.swing.JTextField;
045:
046: /**
047: * Choix des parametres pour la generation de fichiers de mapping OJB.
048: * Ces parametres sont : repertoires d'accueil (XML et Java), nom du package,
049: * nom de la classe mere, nom des fichiers de mapping.
050: *
051: * @author Thierry Badard & Arnaud Braun
052: * @version 1.0
053: *
054: */
055:
056: /* Le pasage des parametres se fait par un tableau de String
057: */
058:
059: public class GUIConfigOJBXMLJava extends JFrame {
060:
061: private static final String FRAME_TITLE = "GeOxygene Configuration mapping OJB / Java ";
062:
063: private String dataDirectory;
064: private String mappingDirectory;
065: private String packageName;
066: private String motherClass;
067: private String mappingFileName;
068: private String motherClasseMappingFileName;
069:
070: private static String packageNameText = "Nom du package : ";
071: private static String dataDirectoryText = "Repertoire d'accueil des packages : ";
072: private static String mappingDirectoryText = "Repertoire d'accueil des fichiers de mapping : ";
073: private static String motherClassText = "Nom de la classe mere : ";
074: private static String mappingFileNameText = "Nom du fichier de mapping : ";
075: private static String motherClasseMappingFileNameText = "Nom du fichier de mapping de la classe mere(*) :";
076:
077: private static String explicationText = "(*) : \nNe rien mettre si vous ne souhaitez pas faire apparaitre la classe mere dans le mapping"
078: + "\nOn peut aussi indiquer le meme fichier que le fichier de mapping";
079:
080: private String[] selectedValues = new String[6];
081:
082: public GUIConfigOJBXMLJava(String PackageName,
083: String DataDirectory, String MappingDirectory,
084: String MotherClass, String MappingFileName,
085: String MotherClasseMappingFileName) {
086: packageName = PackageName;
087: dataDirectory = DataDirectory;
088: mappingDirectory = MappingDirectory;
089: motherClass = MotherClass;
090: mappingFileName = MappingFileName;
091: motherClasseMappingFileName = MotherClasseMappingFileName;
092: }
093:
094: public String[] showDialog() {
095: final JDialog dialog = createDialog(this );
096: dialog.show();
097: dialog.dispose();
098: return selectedValues;
099: }
100:
101: private void getSelectedValues() {
102: selectedValues[0] = dataDirectory;
103: selectedValues[1] = mappingDirectory;
104: selectedValues[2] = packageName;
105: selectedValues[3] = motherClass;
106: selectedValues[4] = mappingFileName;
107: selectedValues[5] = motherClasseMappingFileName;
108: if (selectedValues[5].trim().equals(""))
109: selectedValues[5] = null;
110: }
111:
112: private JDialog createDialog(Frame parent) {
113:
114: String title = FRAME_TITLE;
115: final JDialog dialog = new JDialog(parent, title, true);
116:
117: Container contentPane = dialog.getContentPane();
118: contentPane.setLayout(new GridLayout(7, 2));
119:
120: JLabel dataDirectoryLabel = new JLabel(dataDirectoryText);
121: JPanel dataDirectoryPanel = new JPanel(new FlowLayout());
122: final JTextField dataDirectoryTextField = new JTextField(
123: dataDirectory);
124: JButton dataDirectoryChoiceButton = new JButton("...");
125: dataDirectoryChoiceButton
126: .addActionListener(new ActionListener() {
127: public void actionPerformed(ActionEvent e) {
128: dataDirectoryTextField
129: .setText(GUIConfigOJBXMLJava
130: .selectRepertoire());
131: }
132: });
133: dataDirectoryPanel.add(dataDirectoryTextField);
134: dataDirectoryPanel.add(dataDirectoryChoiceButton);
135: contentPane.add(dataDirectoryLabel);
136: contentPane.add(dataDirectoryPanel);
137:
138: JLabel mappingDirectoryLabel = new JLabel(mappingDirectoryText);
139: JPanel mappingDirectoryPanel = new JPanel(new FlowLayout());
140: final JTextField mappingDirectoryTextField = new JTextField(
141: mappingDirectory);
142: JButton mappingDirectoryChoiceButton = new JButton("...");
143: mappingDirectoryChoiceButton
144: .addActionListener(new ActionListener() {
145: public void actionPerformed(ActionEvent e) {
146: mappingDirectoryTextField
147: .setText(GUIConfigOJBXMLJava
148: .selectRepertoire());
149: }
150: });
151: mappingDirectoryPanel.add(mappingDirectoryTextField);
152: mappingDirectoryPanel.add(mappingDirectoryChoiceButton);
153: contentPane.add(mappingDirectoryLabel);
154: contentPane.add(mappingDirectoryPanel);
155:
156: JLabel packageNameLabel = new JLabel(packageNameText);
157: final JTextField packageNameTextField = new JTextField(
158: packageName);
159: contentPane.add(packageNameLabel);
160: contentPane.add(packageNameTextField);
161:
162: JLabel motherClassLabel = new JLabel(motherClassText);
163: final JTextField motherClassTextField = new JTextField(
164: motherClass);
165: contentPane.add(motherClassLabel);
166: contentPane.add(motherClassTextField);
167:
168: JLabel mappingFileNameLabel = new JLabel(mappingFileNameText);
169: final JTextField mappingFileNameTextField = new JTextField(
170: mappingFileName);
171: contentPane.add(mappingFileNameLabel);
172: contentPane.add(mappingFileNameTextField);
173:
174: JLabel motherClasseMappingFileNameLabel = new JLabel(
175: motherClasseMappingFileNameText);
176: final JTextField motherClasseMappingFileNameTextField = new JTextField(
177: motherClasseMappingFileName);
178: contentPane.add(motherClasseMappingFileNameLabel);
179: contentPane.add(motherClasseMappingFileNameTextField);
180:
181: JTextArea expl = new JTextArea(explicationText);
182: contentPane.add(expl);
183:
184: JPanel controlPanel = new JPanel(new FlowLayout(
185: FlowLayout.CENTER, 20, 10));
186:
187: JButton okButton = new JButton("Ok");
188: okButton.setActionCommand("Ok");
189: okButton.addActionListener(new ActionListener() {
190: public void actionPerformed(ActionEvent e) {
191: packageName = packageNameTextField.getText();
192: dataDirectory = dataDirectoryTextField.getText();
193: mappingDirectory = mappingDirectoryTextField.getText();
194: motherClass = motherClassTextField.getText();
195: mappingFileName = mappingFileNameTextField.getText();
196: motherClasseMappingFileName = motherClasseMappingFileNameTextField
197: .getText();
198: getSelectedValues();
199: dialog.dispose();
200: }
201: });
202:
203: JButton cancelButton = new JButton("Cancel");
204: cancelButton.addActionListener(new ActionListener() {
205: public void actionPerformed(ActionEvent e) {
206: selectedValues[2] = null; //package name
207: dialog.dispose();
208: }
209: });
210:
211: controlPanel.add(okButton);
212: controlPanel.add(cancelButton);
213: contentPane.add(controlPanel);
214:
215: dialog.pack();
216: dialog.setLocationRelativeTo(parent);
217:
218: return dialog;
219: }
220:
221: ///////////////////////////////////////////////////////////////////////////////////////////////////////////
222: ///////////////////////////////////////////////////////////////////////////////////////////////////////////
223: private static String selectRepertoire() {
224: JFileChooser choixRep = new JFileChooser();
225: choixRep.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
226:
227: int result = choixRep.showSaveDialog(null);
228:
229: if (result == JFileChooser.CANCEL_OPTION)
230: return "";
231:
232: String rep = choixRep.getSelectedFile().getPath();
233:
234: if (rep == null || rep.equals("")) {
235: JOptionPane.showMessageDialog(null,
236: "nom de fichier incorrect",
237: "nom de fichier incorrect",
238: JOptionPane.ERROR_MESSAGE);
239: return "";
240: } else
241: return rep;
242:
243: }
244:
245: }
|