001: /*
002: * ConnectionProgressDialog.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.databasemediators;
023:
024: import java.awt.Container;
025: import java.awt.Dimension;
026: import java.awt.GridBagConstraints;
027: import java.awt.GridBagLayout;
028: import java.awt.Insets;
029:
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.BorderFactory;
034: import javax.swing.JButton;
035: import javax.swing.JDialog;
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import org.executequery.Constants;
039:
040: import org.executequery.GUIUtilities;
041: import org.executequery.util.Log;
042: import org.underworldlabs.swing.IndeterminateProgressBar;
043:
044: /* ----------------------------------------------------------
045: * CVS NOTE: Changes to the CVS repository prior to the
046: * release of version 3.0.0beta1 has meant a
047: * resetting of CVS revision numbers.
048: * ----------------------------------------------------------
049: */
050:
051: /**
052: *
053: * @author Takis Diakoumis
054: * @version $Revision: 1.7 $
055: * @date $Date: 2006/07/15 11:48:00 $
056: */
057: public class ConnectionProgressDialog extends JDialog implements
058: Runnable, ActionListener {
059:
060: /** The connection event parent to this object */
061: private ConnectionProcess connectonEvent;
062:
063: /** The progress bar widget */
064: private IndeterminateProgressBar progressBar;
065:
066: public ConnectionProgressDialog(ConnectionProcess _connectonEvent) {
067: super (GUIUtilities.getParentFrame(), "Connecting...", true);
068: connectonEvent = _connectonEvent;
069: try {
070: jbInit();
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074: }
075:
076: public void run() {
077: progressBar.start();
078: setVisible(true);
079: }
080:
081: private void jbInit() throws Exception {
082:
083: progressBar = new IndeterminateProgressBar();
084: progressBar.setPreferredSize(new Dimension(260, 18));
085:
086: JPanel base = new JPanel(new GridBagLayout());
087:
088: JButton cancelButton = new CancelButton();
089: cancelButton.addActionListener(this );
090:
091: GridBagConstraints gbc = new GridBagConstraints();
092: Insets ins = new Insets(10, 20, 10, 20);
093: gbc.insets = ins;
094: base.add(new JLabel("Establishing connection to "
095: + connectonEvent.getConnectionName()), gbc);
096: gbc.gridy = 1;
097: gbc.insets.top = 0;
098: base.add(progressBar, gbc);
099: gbc.gridy = 2;
100: gbc.weighty = 1.0;
101: gbc.insets.left = 10;
102: gbc.insets.right = 10;
103: base.add(cancelButton, gbc);
104:
105: base.setBorder(BorderFactory.createEtchedBorder());
106:
107: Container c = this .getContentPane();
108: c.setLayout(new GridBagLayout());
109: c.add(base, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0,
110: GridBagConstraints.SOUTHEAST, GridBagConstraints.BOTH,
111: new Insets(5, 5, 5, 5), 0, 0));
112: setResizable(false);
113: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
114:
115: pack();
116: setLocation(GUIUtilities.getLocationForDialog(getSize()));
117: }
118:
119: public void actionPerformed(ActionEvent e) {
120: Log.info("Connection cancelled");
121: connectonEvent.setCancelled(true);
122: connectonEvent.interrupt();
123: dispose();
124: }
125:
126: public void dispose() {
127: if (progressBar != null) {
128: progressBar.stop();
129: progressBar.cleanup();
130: }
131: super .dispose();
132: }
133:
134: class CancelButton extends JButton {
135:
136: private int DEFAULT_WIDTH = 75;
137: private int DEFAULT_HEIGHT = 30;
138:
139: public CancelButton() {
140: super ("Cancel");
141: setMargin(Constants.EMPTY_INSETS);
142: }
143:
144: public int getWidth() {
145: int width = super .getWidth();
146: if (width < DEFAULT_WIDTH) {
147: return DEFAULT_WIDTH;
148: }
149: return width;
150: }
151:
152: public int getHeight() {
153: int height = super .getHeight();
154: if (height < DEFAULT_HEIGHT) {
155: return DEFAULT_HEIGHT;
156: }
157: return height;
158: }
159:
160: public Dimension getPreferredSize() {
161: return new Dimension(getWidth(), getHeight());
162: }
163: }
164:
165: }
|