001: /*
002: * DataTypesDialog.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.executequery.gui.table;
023:
024: import java.awt.BorderLayout;
025: import java.awt.Container;
026: import java.awt.Dialog;
027: import java.awt.Dimension;
028: import java.awt.Frame;
029: import java.awt.event.KeyEvent;
030: import java.awt.event.KeyListener;
031: import java.awt.event.MouseEvent;
032: import java.awt.event.MouseListener;
033: import javax.swing.BorderFactory;
034: import javax.swing.JDialog;
035: import javax.swing.JList;
036: import javax.swing.JPanel;
037: import javax.swing.JScrollPane;
038: import javax.swing.ListSelectionModel;
039: import org.executequery.GUIUtilities;
040:
041: /* ----------------------------------------------------------
042: * CVS NOTE: Changes to the CVS repository prior to the
043: * release of version 3.0.0beta1 has meant a
044: * resetting of CVS revision numbers.
045: * ----------------------------------------------------------
046: */
047:
048: /**
049: * Simple data type selection dialog.
050: *
051: * @author Takis Diakoumis
052: * @version $Revision: 1.4 $
053: * @date $Date: 2006/05/14 06:56:52 $
054: */
055: public class DataTypesDialog extends JDialog implements MouseListener,
056: KeyListener {
057:
058: public static final String TITLE = "Data Type Selection";
059:
060: /** the type values */
061: private String[] values;
062:
063: /** the list object */
064: private JList list;
065:
066: /** the parent listener */
067: private DataTypeSelectionListener parent;
068:
069: /** Creates a new instance of DataTypesPanel */
070: public DataTypesDialog(Frame owner,
071: DataTypeSelectionListener parent, String[] values) {
072: super (owner, TITLE, true);
073: this .parent = parent;
074: this .values = values;
075: init();
076: }
077:
078: /** Creates a new instance of DataTypesPanel */
079: public DataTypesDialog(Dialog owner,
080: DataTypeSelectionListener parent, String[] values) {
081: super (owner, TITLE, true);
082: this .parent = parent;
083: this .values = values;
084: init();
085: }
086:
087: private void init() {
088: list = new JList(values);
089: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
090: list.addMouseListener(this );
091: list.addKeyListener(this );
092:
093: JPanel panel = new JPanel(new BorderLayout());
094: panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
095: panel.add(new JScrollPane(list), BorderLayout.CENTER);
096: panel.setPreferredSize(new Dimension(300, 450));
097:
098: Container c = getContentPane();
099: c.setLayout(new BorderLayout());
100: c.add(panel, BorderLayout.CENTER);
101:
102: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
103: display();
104: }
105:
106: public void dispose() {
107: if (!selected) {
108: parent.dataTypeSelectionCancelled();
109: }
110: super .dispose();
111: }
112:
113: public void keyPressed(KeyEvent e) {
114: if (e.getKeyCode() == KeyEvent.VK_ENTER) {
115: selectionMade();
116: }
117: }
118:
119: public void keyReleased(KeyEvent e) {
120: keyPressed(e);
121: }
122:
123: public void keyTyped(KeyEvent e) {
124: }
125:
126: private void selectionMade() {
127: if (selected) {
128: return;
129: }
130: Object value = list.getSelectedValue();
131: parent.dataTypeSelected(value.toString());
132: selected = true;
133: dispose();
134: }
135:
136: /** Indicates a selection has been made */
137: private boolean selected;
138:
139: public void mouseClicked(MouseEvent e) {
140: if (e.getClickCount() < 2) {
141: return;
142: }
143: selectionMade();
144: }
145:
146: public void mousePressed(MouseEvent e) {
147: mouseClicked(e);
148: }
149:
150: public void mouseReleased(MouseEvent e) {
151: }
152:
153: public void mouseEntered(MouseEvent e) {
154: }
155:
156: public void mouseExited(MouseEvent e) {
157: }
158:
159: private void display() {
160: pack();
161: setLocation(GUIUtilities.getLocationForDialog(getSize()));
162: GUIUtilities.registerDialog(this );
163: setVisible(true);
164: }
165:
166: }
|