001: /*
002: ** $Id: SchemaListView.java,v 1.10 2000/10/26 08:34:16 mrw Exp $
003: **
004: ** Dialog to list all available schema names and allow the user to
005: ** make a selection.
006: **
007: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
008: **
009: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
010: **
011: ** This program is free software; you can redistribute it and/or modify
012: ** it under the terms of the GNU General Public License as published by
013: ** the Free Software Foundation; either version 2 of the License, or
014: ** (at your option) any later version.
015: **
016: ** This program is distributed in the hope that it will be useful,
017: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
018: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: ** GNU General Public License for more details.
020: **
021: ** You should have received a copy of the GNU Library General
022: ** Public License along with this library; if not, write to the
023: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
024: ** Boston, MA 02111-1307 USA.
025: */
026:
027: package uk.co.whisperingwind.vienna;
028:
029: import java.awt.Cursor;
030: import java.awt.event.MouseEvent;
031: import java.awt.event.MouseListener;
032: import java.awt.GridBagConstraints;
033: import java.awt.Insets;
034: import javax.swing.JButton;
035: import javax.swing.JFrame;
036: import javax.swing.JList;
037: import javax.swing.JScrollPane;
038: import javax.swing.ListModel;
039: import uk.co.whisperingwind.framework.ActionFactory;
040: import uk.co.whisperingwind.framework.ButtonView;
041: import uk.co.whisperingwind.framework.ModelEvent;
042:
043: class SchemaListView extends ButtonView {
044: private SchemaListModel schemaListModel = null;
045: private JButton okButton = null;
046: private ActionFactory.DefaultAction okAction = null;
047: private ActionFactory.DefaultAction cancelAction = null;
048: private ListModel listModel = null;
049: private JList schemaList = null;
050: private Cursor originalCursor = null;
051:
052: public SchemaListView(JFrame parent, SchemaListModel model,
053: boolean modal) {
054: super (parent, modal);
055:
056: schemaListModel = model;
057: content.setTitle("Select schema");
058: schemaListModel.addObserver(this );
059: listModel = schemaListModel.getListModel();
060: createActions();
061: createComponents();
062: }
063:
064: /*
065: ** When I become visible, make the "Ok" button the default and set
066: ** the focus to the user name entry.
067: */
068:
069: public void setVisible(boolean visible) {
070: content.setVisible(visible);
071: content.getRootPane().setDefaultButton(okButton);
072: }
073:
074: private void createActions() {
075: ConfigActionFactory factory = new ConfigActionFactory(
076: "/uk/co/whisperingwind/images");
077:
078: okAction = factory.createAction("ok");
079: cancelAction = factory.createAction("cancel");
080:
081: okAction.addActionListener(actionListener);
082: cancelAction.addActionListener(actionListener);
083: }
084:
085: private void createComponents() {
086: schemaList = new JList(listModel);
087: schemaList.addMouseListener(new DoubleMouseListener());
088: JScrollPane listScroller = new JScrollPane(schemaList);
089:
090: GridBagConstraints constraints = new GridBagConstraints();
091:
092: constraints.fill = GridBagConstraints.BOTH;
093: constraints.gridx = 0;
094: constraints.gridy = 0;
095: constraints.insets = new Insets(4, 4, 4, 4);
096: constraints.fill = GridBagConstraints.BOTH;
097: constraints.weightx = 1.0;
098: constraints.weighty = 1.0;
099: content.getContentPane().add(listScroller, constraints);
100:
101: okButton = okAction.toolButtonFactory(buttonPanel);
102: cancelAction.toolButtonFactory(buttonPanel);
103:
104: content.pack();
105: }
106:
107: public String getSelection() {
108: String selected = null;
109: int i = schemaList.getSelectedIndex();
110:
111: if (i >= 0) {
112: return (String) listModel.getElementAt(i);
113: }
114:
115: return selected;
116: }
117:
118: public void busyCursor(boolean busy) {
119: if (busy) {
120: originalCursor = content.getCursor();
121: content.setCursor(new Cursor(Cursor.WAIT_CURSOR));
122: } else {
123: content.setCursor(originalCursor);
124: }
125: }
126:
127: protected void modelEvent(ModelEvent event) {
128: if (event.getField().equals("schema")) {
129: if (event.getValue().equals("end")) {
130: schemaList.setSelectedIndex(0);
131: }
132: }
133: }
134:
135: protected void cleanUp() {
136: schemaListModel.deleteObserver(this );
137: }
138:
139: private class DoubleMouseListener implements MouseListener {
140: public void mouseClicked(MouseEvent event) {
141: if (event.getClickCount() == 2) {
142: fireEvent("ok");
143: }
144: }
145:
146: public void mouseEntered(MouseEvent event) {
147: }
148:
149: public void mouseExited(MouseEvent event) {
150: }
151:
152: public void mousePressed(MouseEvent event) {
153: }
154:
155: public void mouseReleased(MouseEvent event) {
156: }
157: }
158: }
|