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.BorderLayout;
030: import java.awt.Container;
031: import java.awt.Dimension;
032: import java.awt.FlowLayout;
033: import java.awt.Frame;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.JButton;
038: import javax.swing.JDialog;
039: import javax.swing.JFrame;
040: import javax.swing.JList;
041: import javax.swing.JPanel;
042: import javax.swing.JScrollPane;
043:
044: /**
045: * Visualisation et selection des tables geographiques.
046: *
047: * @author Thierry Badard & Arnaud Braun
048: * @version 1.0
049: *
050: */
051:
052: public class GUITableChoice extends JFrame {
053:
054: private static final String FRAME_TITLE = "GeOxygene Geographic Tables in DBMS - ";
055: private String[] selectedData = new String[0];
056: private String[] data;
057: private JList dataList;
058: private String userName;
059:
060: public GUITableChoice(Object[] classesNames, String user) {
061: userName = user;
062: data = new String[classesNames.length];
063: for (int i = 0; i < data.length; i++)
064: data[i] = (String) classesNames[i];
065: sortData();
066: dataList = new JList(data);
067: }
068:
069: public String[] showDialog() {
070: final JDialog dialog = createDialog(this );
071: dialog.show();
072: dialog.dispose();
073: return selectedData;
074: }
075:
076: private void getSelectedValues() {
077: Object[] selectedObjects = dataList.getSelectedValues();
078: selectedData = new String[selectedObjects.length];
079: for (int i = 0; i < selectedObjects.length; i++)
080: selectedData[i] = (String) selectedObjects[i];
081: }
082:
083: private JDialog createDialog(Frame parent) {
084:
085: String title = FRAME_TITLE + userName;
086: final JDialog dialog = new JDialog(parent, title, true);
087:
088: JScrollPane scrollPane = new JScrollPane(dataList);
089: scrollPane.setPreferredSize(new Dimension(500, 600));
090:
091: JPanel controlPanel = new JPanel(new FlowLayout(
092: FlowLayout.CENTER, 20, 10));
093:
094: JButton okButton = new JButton("Ok");
095: okButton.setActionCommand("Ok");
096: okButton.addActionListener(new ActionListener() {
097: public void actionPerformed(ActionEvent e) {
098: getSelectedValues();
099: dialog.dispose();
100: }
101: });
102:
103: JButton cancelButton = new JButton("Cancel");
104: cancelButton.addActionListener(new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: dialog.dispose();
107: }
108: });
109:
110: controlPanel.add(okButton);
111: controlPanel.add(cancelButton);
112:
113: Container contentPane = dialog.getContentPane();
114: contentPane.add(scrollPane, BorderLayout.CENTER);
115: contentPane.add(controlPanel, BorderLayout.SOUTH);
116:
117: dialog.pack();
118: dialog.setLocationRelativeTo(parent);
119:
120: return dialog;
121: }
122:
123: private void sortData() {
124: if (data.length > 1) {
125: for (int i = 0; i < data.length - 1; i++) {
126: for (int j = i + 1; j < data.length; j++) {
127: String A = new String(data[i]);
128: String B = new String(data[j]);
129: if (B.compareTo(A) < 0) {
130: data[i] = B;
131: data[j] = A;
132: }
133: }
134: }
135: }
136: }
137:
138: }
|