001: package fr.ign.cogit.geoxygene.util.loader.gui;
002:
003: import java.awt.Color;
004: import java.awt.Container;
005: import java.awt.Dialog;
006: import java.awt.Dimension;
007: import java.awt.FlowLayout;
008: import java.awt.Toolkit;
009: import java.awt.event.ActionEvent;
010: import java.awt.event.ActionListener;
011: import java.awt.event.ItemEvent;
012: import java.awt.event.ItemListener;
013:
014: import javax.swing.BorderFactory;
015: import javax.swing.Box;
016: import javax.swing.BoxLayout;
017: import javax.swing.ButtonGroup;
018: import javax.swing.JButton;
019: import javax.swing.JCheckBox;
020: import javax.swing.JDialog;
021: import javax.swing.JFrame;
022: import javax.swing.JPanel;
023: import javax.swing.JScrollPane;
024:
025: /**
026: * Choix des paramètres géométriques lors de la création de tables postgis
027: * et du fichier de mapping à partir d'une classe java (le problème ne se
028: * pose pas avec Oracle)
029: *
030: * @author Eric Grosso - IGN / Laboratoire COGIT
031: * @version 1.0
032: */
033:
034: public class GUISelectionGeometrie extends JDialog {
035:
036: private static Dialog frame = new JDialog();
037: private final GUISelectionGeometrie selectionGeometrie;
038: private Color bluegray = new Color(197, 197, 232);
039: private JPanel panneauType, panneauDimension, jPanelBoutton;
040: private JScrollPane scrollChargement, scrollStockage;
041: private Box boxType, boxDimension;
042: private int selectionType = 0, selectionDimension = 0;
043: private JButton jButtonOK;
044: private Box boxe = Box.createVerticalBox();
045: private static String[] stringsChoixType = new String[4];
046: private static String[] stringsChoixDimension = new String[2];
047: private String titreType = "";
048: private String titreDimension = "";
049:
050: private int typeGeometrie;
051:
052: public int getTypeGeometrie() {
053: return typeGeometrie;
054: }
055:
056: public void setTypeGeometrie(int typeGeometrie) {
057: this .typeGeometrie = typeGeometrie;
058: }
059:
060: private int dimensionGeometrie;
061:
062: public int getDimensionGeometrie() {
063: return dimensionGeometrie;
064: }
065:
066: public void setDimensionGeometrie(int dimensionGeometrie) {
067: this .dimensionGeometrie = dimensionGeometrie;
068: }
069:
070: /** Constructeur de l'interface **/
071: public GUISelectionGeometrie() {
072: super (frame, "Choix de la géométrie", true);
073: selectionGeometrie = this ;
074: setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
075: setPreferredSize(new Dimension(430, 270));
076: setSize(430, 270);
077: setResizable(false);
078: setBackground(Color.white);
079: setAlwaysOnTop(true);
080:
081: Dimension tailleEcran = Toolkit.getDefaultToolkit()
082: .getScreenSize();
083: this .setLocation((tailleEcran.width - this .getWidth()) / 2,
084: (tailleEcran.height - this .getHeight()) / 2);
085:
086: Container contentPane = this .getContentPane();
087: contentPane.setLayout(new BoxLayout(contentPane,
088: BoxLayout.Y_AXIS));
089:
090: //initialisation des différents composants et variables
091: stringsChoixType[0] = "Point";
092: stringsChoixType[1] = "LineString";
093: stringsChoixType[2] = "Polygon";
094: stringsChoixType[3] = "Geometry collection";
095:
096: stringsChoixDimension[0] = "2D";
097: stringsChoixDimension[1] = "3D";
098:
099: titreType = "Quel est le type de votre géométrie ?";
100: titreDimension = "Quel est la dimension de votre géométrie ?";
101: initBoxTypeGeom();
102: initBoxDimensionGeom();
103: initJPanelType(true);
104: initJPanelDimension(true);
105: initJPanelBoutton();
106:
107: boxe.setBackground(Color.white);
108: boxe.add(panneauType);
109: boxe.add(panneauDimension);
110:
111: boxe.add(jPanelBoutton);
112:
113: //Association des panneaux au conteneur
114: this .setContentPane(boxe);
115:
116: //Visualisation
117: this .pack();
118: this .setVisible(true);
119: }
120:
121: /**initialise le panel principal**/
122: private void initJPanelType(boolean flag) {
123: panneauType = new JPanel(new java.awt.BorderLayout());
124: panneauType.setPreferredSize(new Dimension(820, 300));
125: panneauType.setMaximumSize(new Dimension(820, 300));
126: panneauType.setBackground(Color.white);
127: panneauType.setBorder(BorderFactory.createTitledBorder(
128: BorderFactory.createEtchedBorder(bluegray, bluegray),
129: titreType));
130: panneauType.add(boxType);
131: }
132:
133: /**initialise le panel principal**/
134: private void initJPanelDimension(boolean flag) {
135: panneauDimension = new JPanel(new java.awt.BorderLayout());
136: panneauDimension.setPreferredSize(new Dimension(820, 300));
137: panneauDimension.setMaximumSize(new Dimension(820, 300));
138: panneauDimension.setBackground(Color.white);
139: panneauDimension.setBorder(BorderFactory.createTitledBorder(
140: BorderFactory.createEtchedBorder(bluegray, bluegray),
141: titreDimension));
142: panneauDimension.add(boxDimension);
143: }
144:
145: private void initBoxTypeGeom() {
146: boxType = Box.createVerticalBox();
147: ButtonGroup choix = new ButtonGroup();
148: JCheckBox checkBox;
149: final int t = stringsChoixType.length;
150: for (int i = 0; i < t; i++) {
151: checkBox = new JCheckBox((String) stringsChoixType[i]);
152: checkBox.setBackground(Color.white);
153: if (i == 0) {
154: checkBox.setSelected(true);
155: setTypeGeometrie(0);
156: }
157: checkBox.addItemListener(new ItemListener() {
158: public void itemStateChanged(ItemEvent e) {
159: if (e.getStateChange() == 1) {
160: Object source = e.getItemSelectable();
161: for (int i = 0; i < t; i++) {
162: if (((JCheckBox) source).getText().equals(
163: stringsChoixType[i])) {
164: setTypeGeometrie(i);
165: }
166: }
167: }
168: }
169: });
170: choix.add(checkBox);
171: boxType.add(checkBox);
172: }
173: }
174:
175: private void initBoxDimensionGeom() {
176: boxDimension = Box.createVerticalBox();
177: ButtonGroup choix = new ButtonGroup();
178: JCheckBox checkBox;
179: final int t = stringsChoixDimension.length;
180: for (int i = 0; i < t; i++) {
181: checkBox = new JCheckBox((String) stringsChoixDimension[i]);
182: checkBox.setBackground(Color.white);
183: if (i == 0) {
184: checkBox.setSelected(true);
185: setDimensionGeometrie(2);
186: }
187: checkBox.addItemListener(new ItemListener() {
188: public void itemStateChanged(ItemEvent e) {
189: if (e.getStateChange() == 1) {
190: Object source = e.getItemSelectable();
191: for (int i = 0; i < t; i++) {
192: if (((JCheckBox) source).getText().equals(
193: stringsChoixDimension[i])) {
194: setDimensionGeometrie(i + 2);
195: }
196: }
197: }
198: }
199: });
200: choix.add(checkBox);
201: boxDimension.add(checkBox);
202: }
203: }
204:
205: /** initialisation de jPanelBoutton*/
206: private void initJPanelBoutton() {
207: initJButtonOK();
208:
209: jPanelBoutton = new JPanel();
210: jPanelBoutton.setLayout(new FlowLayout());
211: jPanelBoutton.add(jButtonOK);
212: jPanelBoutton.setBackground(Color.white);
213: }
214:
215: /** This method initializes jButtonChargement */
216: private void initJButtonOK() {
217: jButtonOK = new JButton();
218: jButtonOK.setPreferredSize(new java.awt.Dimension(80, 30));
219: jButtonOK.setSize(new java.awt.Dimension(80, 30));
220: jButtonOK.setText("Ok");
221: jButtonOK.setVisible(true);
222:
223: jButtonOK.addActionListener(new ActionListener() {
224: public void actionPerformed(ActionEvent e) {
225: selectionGeometrie.dispose();
226: }
227: });
228: }
229: }
|