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: import java.io.File;
036:
037: import javax.swing.JButton;
038: import javax.swing.JDialog;
039: import javax.swing.JFileChooser;
040: import javax.swing.JFrame;
041: import javax.swing.JLabel;
042: import javax.swing.JOptionPane;
043: import javax.swing.JPanel;
044: import javax.swing.JTextField;
045: import javax.swing.filechooser.FileFilter;
046:
047: /**
048: * Choix des parametres pour la generation de tables dans le SGBD et de fichiers de mapping OJB.
049: * Ces parametres sont : repertoires d'accueil (XML), nom du package,nom des fichiers de mapping.
050: *
051: * @author Eric Grosso - IGN / Laboratoire COGIT
052: * @version 1.0
053: *
054: */
055:
056: public class GUIConfigSqlOJBXML extends JFrame {
057:
058: private static final String FRAME_TITLE = "GeOxygene Configuration SQL / mapping OJB";
059:
060: private String javaFilePath;
061: private String tableName;
062: private String mappingDirectory;
063: private String mappingFileName;
064:
065: private static String javaFilePathText = "Classe Java à traduire : ";
066: private static String tableNameText = "Nom de la table : ";
067: private static String mappingDirectoryText = "Repertoire d'accueil du fichier de mapping : ";
068: private static String mappingFileNameText = "Nom du fichier de mapping : ";
069:
070: private String[] selectedValues = new String[4];
071:
072: public GUIConfigSqlOJBXML(String GeoxygeneDirectory,
073: String MappingDirectory, String MappingFileName) {
074: javaFilePath = GeoxygeneDirectory;
075: mappingDirectory = MappingDirectory;
076: mappingFileName = MappingFileName;
077: }
078:
079: public String[] showDialog() {
080: final JDialog dialog = createDialog(this );
081: dialog.setVisible(true);
082: dialog.dispose();
083: return selectedValues;
084: }
085:
086: private void getSelectedValues() {
087: selectedValues[0] = javaFilePath;
088: selectedValues[1] = mappingDirectory;
089: selectedValues[2] = tableName;
090: selectedValues[3] = mappingFileName;
091: }
092:
093: private JDialog createDialog(Frame parent) {
094:
095: String title = FRAME_TITLE;
096: final JDialog dialog = new JDialog(parent, title, true);
097:
098: Container contentPane = dialog.getContentPane();
099: contentPane.setLayout(new GridLayout(5, 2));
100:
101: JLabel javaFilePathLabel = new JLabel(javaFilePathText);
102: JPanel javaFilePathPanel = new JPanel(new FlowLayout());
103: final JTextField javaFilePathTextField = new JTextField(
104: javaFilePath);
105: JButton javaFilePathChoiceButton = new JButton("...");
106: javaFilePathChoiceButton
107: .addActionListener(new ActionListener() {
108: public void actionPerformed(ActionEvent e) {
109: javaFilePathTextField
110: .setText(GUIConfigSqlOJBXML
111: .selectRepertoire(javaFilePath));
112: }
113: });
114: javaFilePathPanel.add(javaFilePathTextField);
115: javaFilePathPanel.add(javaFilePathChoiceButton);
116: contentPane.add(javaFilePathLabel);
117: contentPane.add(javaFilePathPanel);
118:
119: JLabel tableNameLabel = new JLabel(tableNameText);
120: final JTextField tableNameTextField = new JTextField(tableName);
121: contentPane.add(tableNameLabel);
122: contentPane.add(tableNameTextField);
123:
124: JLabel mappingDirectoryLabel = new JLabel(mappingDirectoryText);
125: JPanel mappingDirectoryPanel = new JPanel(new FlowLayout());
126: final JTextField mappingDirectoryTextField = new JTextField(
127: mappingDirectory);
128: JButton mappingDirectoryChoiceButton = new JButton("...");
129: mappingDirectoryChoiceButton
130: .addActionListener(new ActionListener() {
131: public void actionPerformed(ActionEvent e) {
132: mappingDirectoryTextField
133: .setText(GUIConfigSqlOJBXML
134: .selectRepertoire(mappingDirectory));
135: }
136: });
137: mappingDirectoryPanel.add(mappingDirectoryTextField);
138: mappingDirectoryPanel.add(mappingDirectoryChoiceButton);
139: contentPane.add(mappingDirectoryLabel);
140: contentPane.add(mappingDirectoryPanel);
141:
142: JLabel mappingFileNameLabel = new JLabel(mappingFileNameText);
143: final JTextField mappingFileNameTextField = new JTextField(
144: mappingFileName);
145: contentPane.add(mappingFileNameLabel);
146: contentPane.add(mappingFileNameTextField);
147:
148: JPanel controlPanel = new JPanel(new FlowLayout(
149: FlowLayout.CENTER, 20, 10));
150:
151: JButton okButton = new JButton("Ok");
152: okButton.setActionCommand("Ok");
153: okButton.addActionListener(new ActionListener() {
154: public void actionPerformed(ActionEvent e) {
155: tableName = tableNameTextField.getText();
156: javaFilePath = javaFilePathTextField.getText().replace(
157: '/', '.');
158: javaFilePath = javaFilePath.replace('\\', '.');
159: mappingDirectory = mappingDirectoryTextField.getText();
160: mappingFileName = mappingFileNameTextField.getText();
161: getSelectedValues();
162: dialog.dispose();
163: }
164: });
165:
166: JButton cancelButton = new JButton("Annuler");
167: cancelButton.addActionListener(new ActionListener() {
168: public void actionPerformed(ActionEvent e) {
169: selectedValues[0] = null; //file java path
170: dialog.dispose();
171: }
172: });
173:
174: controlPanel.add(okButton);
175: controlPanel.add(cancelButton);
176: contentPane.add(controlPanel);
177:
178: dialog.pack();
179: dialog.setLocationRelativeTo(parent);
180:
181: return dialog;
182: }
183:
184: ///////////////////////////////////////////////////////////////////////////////////////////////////////////
185: ///////////////////////////////////////////////////////////////////////////////////////////////////////////
186: private static String selectRepertoire(String javaFilePath) {
187: JFileChooser fileChooser = new JFileChooser(javaFilePath);
188: fileChooser.setFileFilter(new FileFilter() {
189: public boolean accept(File f) {
190: return f.getName().toLowerCase().endsWith(".java")
191: || f.isDirectory();
192: }
193:
194: public String getDescription() {
195: return "Java Files (*.java)";
196: }
197: });
198:
199: int result = fileChooser.showOpenDialog(null);
200: String pathFileJava = "";
201:
202: if (result == JFileChooser.APPROVE_OPTION) {
203: File f = fileChooser.getSelectedFile();
204: String absolutePathFileJava = f.getPath();
205: pathFileJava = absolutePathFileJava.substring(javaFilePath
206: .toString().length() + 1);
207: System.out.println(pathFileJava);
208:
209: }
210:
211: if (pathFileJava == null || pathFileJava.equals("")
212: || !pathFileJava.endsWith(".java")) {
213: JOptionPane
214: .showMessageDialog(
215: null,
216: "Le type de votre fichier n'est pas valide (.java)",
217: "Fichier de type incorrect",
218: JOptionPane.WARNING_MESSAGE);
219: pathFileJava = "";
220: } else {
221: if (pathFileJava.startsWith("src"))
222: pathFileJava = pathFileJava.substring(4, pathFileJava
223: .length() - 5);
224: else if (pathFileJava.startsWith("data"))
225: pathFileJava = pathFileJava.substring(5, pathFileJava
226: .length() - 5);
227: }
228: return pathFileJava;
229: }
230: }
|