KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > wizard > objects > ConnectionParameterDialog


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.wizard.objects;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.GridBagConstraints JavaDoc;
29 import java.awt.GridBagLayout JavaDoc;
30 import java.awt.HeadlessException JavaDoc;
31 import java.awt.event.ActionEvent JavaDoc;
32 import java.awt.event.ActionListener JavaDoc;
33 import java.util.ArrayList JavaDoc;
34
35 import javax.swing.BorderFactory JavaDoc;
36 import javax.swing.JButton JavaDoc;
37 import javax.swing.JDialog JavaDoc;
38 import javax.swing.JLabel JavaDoc;
39 import javax.swing.JPanel JavaDoc;
40 import javax.swing.JSlider JavaDoc;
41
42 import org.objectweb.cjdbc.common.i18n.WizardTranslate;
43 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
44 import org.objectweb.cjdbc.console.wizard.WizardConstants;
45
46 /**
47  * This class defines a ConnectionParameterDialog, all the forms and fields
48  * needed to define a connection manager on a backend
49  *
50  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
51  * @version 1.0
52  */

53 public class ConnectionParameterDialog extends JDialog JavaDoc
54     implements
55       ActionListener JavaDoc
56 {
57
58   private ArrayList JavaDoc values;
59
60   /**
61    * Creates a new <code>ConnectionParameterDialog</code> object
62    *
63    * @param type connection type information
64    * @throws java.awt.HeadlessException if an error occurs
65    */

66   public ConnectionParameterDialog(ConnectionTypeInfo type)
67       throws HeadlessException JavaDoc
68   {
69     super();
70     this.setModal(true);
71     this.setTitle(type.getType());
72     this.setResizable(false);
73     this.setBackground(Color.white);
74
75     values = new ArrayList JavaDoc();
76
77     this.setSize(WizardConstants.CONNECTION_FRAME_WIDTH,
78         WizardConstants.CONNECTION_FRAME_HEIGHT);
79     GuiConstants.centerComponent(this, WizardConstants.CONNECTION_FRAME_WIDTH,
80         WizardConstants.CONNECTION_FRAME_HEIGHT);
81
82     JPanel JavaDoc pane = new JPanel JavaDoc();
83     pane.setBorder(BorderFactory.createTitledBorder(type.getType()));
84     this.add(pane);
85
86     pane.setLayout(new GridBagLayout JavaDoc());
87     GridBagConstraints JavaDoc constraints = new GridBagConstraints JavaDoc();
88     constraints.fill = GridBagConstraints.HORIZONTAL;
89     constraints.anchor = GridBagConstraints.CENTER;
90
91     constraints.weightx = 1.0;
92
93     String JavaDoc[] atts = type.getAttributes();
94     for (int i = 0; i < atts.length; i++)
95     {
96       constraints.gridy = ++constraints.gridy;
97       constraints.gridx = 0;
98       pane.add(new JLabel JavaDoc(atts[i]), constraints);
99       constraints.gridx = 1;
100       JSlider JavaDoc slider = new JSlider JavaDoc(0, 600, type.getValue(i));
101       slider.setPaintLabels(true);
102       slider.setPaintTicks(true);
103       slider.setPaintTrack(true);
104       slider.setMajorTickSpacing(100);
105       pane.add(slider, constraints);
106       values.add(slider);
107     }
108
109     constraints.gridy = ++constraints.gridy;
110     constraints.gridx = 0;
111     JButton JavaDoc button = new JButton JavaDoc(WizardTranslate.get("label.finish.edit"));
112     button.addActionListener(this);
113     pane.add(button, constraints);
114
115     this.validate();
116     this.setVisible(true);
117
118   }
119
120   /**
121    * Returns the values value.
122    *
123    * @return Returns the values.
124    */

125   public ArrayList JavaDoc getValues()
126   {
127     int size = values.size();
128     ArrayList JavaDoc results = new ArrayList JavaDoc(size);
129     for (int i = 0; i < size; i++)
130       results.add(new Integer JavaDoc((((JSlider JavaDoc) values.get(i)).getValue())));
131     return results;
132   }
133
134   /**
135    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
136    */

137   public void actionPerformed(ActionEvent JavaDoc e)
138   {
139     this.setVisible(false);
140   }
141 }
Popular Tags