001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.task;
034:
035: import java.awt.Frame;
036: import java.awt.GridBagConstraints;
037: import java.awt.GridBagLayout;
038: import java.awt.Insets;
039: import java.awt.event.ActionEvent;
040: import java.awt.event.ActionListener;
041: import java.awt.event.ComponentEvent;
042: import java.awt.event.WindowAdapter;
043: import java.awt.event.WindowEvent;
044:
045: import javax.swing.JButton;
046: import javax.swing.JDialog;
047: import javax.swing.JLabel;
048: import javax.swing.JPanel;
049: import javax.swing.Timer;
050:
051: import com.vividsolutions.jump.I18N;
052: import com.vividsolutions.jump.task.TaskMonitor;
053: import com.vividsolutions.jump.workbench.ui.AnimatedClockPanel;
054: import com.vividsolutions.jump.workbench.ui.ErrorHandler;
055:
056: public class TaskMonitorDialog extends JDialog implements TaskMonitor {
057: JPanel mainPanel = new JPanel();
058: private GridBagLayout gridBagLayout1 = new GridBagLayout();
059: private JPanel labelPanel = new JPanel();
060: private JButton cancelButton = new JButton();
061: private GridBagLayout gridBagLayout2 = new GridBagLayout();
062: private ErrorHandler errorHandler;
063: private boolean cancelled;
064: private GridBagLayout gridBagLayout3 = new GridBagLayout();
065: private JLabel taskProgressLabel = new JLabel();
066: private JLabel subtaskProgressLabel = new JLabel();
067: private String taskProgress = "";
068: private String subtaskProgress = "";
069: private Timer timer = new Timer(500, new ActionListener() {
070: public void actionPerformed(ActionEvent e) {
071: updateLabels();
072: }
073: });
074: private AnimatedClockPanel clockPanel = new AnimatedClockPanel();
075:
076: public TaskMonitorDialog(Frame frame, ErrorHandler errorHandler) {
077: this (frame, errorHandler, true);
078: }
079:
080: public TaskMonitorDialog(Frame frame, ErrorHandler errorHandler,
081: boolean modal) {
082: super (frame, I18N.get("ui.task.TaskMonitorDialog.busy"), modal);
083: this .errorHandler = errorHandler;
084:
085: try {
086: jbInit();
087: pack();
088: } catch (Exception ex) {
089: ex.printStackTrace();
090: }
091:
092: setSize(400, 100);
093: addWindowListener(new WindowAdapter() {
094: public void windowOpened(WindowEvent e) {
095: cancelButton.setEnabled(true);
096: }
097: });
098: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
099: }
100:
101: private void jbInit() throws Exception {
102: mainPanel.setLayout(gridBagLayout1);
103: cancelButton.setText(I18N
104: .get("ui.task.TaskMonitorDialog.cancel"));
105: cancelButton
106: .addActionListener(new java.awt.event.ActionListener() {
107: public void actionPerformed(ActionEvent e) {
108: cancelButton_actionPerformed(e);
109: }
110: });
111: this
112: .addComponentListener(new java.awt.event.ComponentAdapter() {
113: public void componentShown(ComponentEvent e) {
114: this _componentShown(e);
115: }
116:
117: public void componentHidden(ComponentEvent e) {
118: this _componentHidden(e);
119: }
120: });
121: this .getContentPane().setLayout(gridBagLayout2);
122: labelPanel.setLayout(gridBagLayout3);
123: subtaskProgressLabel
124: .setText(I18N
125: .get("ui.task.TaskMonitorDialog.subtask-progress-goes-here"));
126: taskProgressLabel
127: .setText(I18N
128: .get("ui.task.TaskMonitorDialog.task-progress-goes-here"));
129: getContentPane().add(
130: mainPanel,
131: new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0,
132: GridBagConstraints.CENTER,
133: GridBagConstraints.BOTH, new Insets(15, 0, 15,
134: 15), 0, 0));
135: mainPanel.add(labelPanel, new GridBagConstraints(0, 0, 1, 1,
136: 1.0, 1.0, GridBagConstraints.WEST,
137: GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
138: labelPanel.add(taskProgressLabel, new GridBagConstraints(0, 0,
139: 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
140: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
141: 0, 0));
142: labelPanel.add(subtaskProgressLabel, new GridBagConstraints(0,
143: 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
144: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
145: 0, 0));
146: mainPanel.add(cancelButton, new GridBagConstraints(1, 0, 1, 1,
147: 0.0, 0.0, GridBagConstraints.CENTER,
148: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
149: this .getContentPane().add(
150: clockPanel,
151: new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
152: GridBagConstraints.CENTER,
153: GridBagConstraints.NONE,
154: new Insets(4, 4, 4, 4), 0, 0));
155: }
156:
157: void cancelButton_actionPerformed(ActionEvent e) {
158: cancelButton.setEnabled(false);
159: cancelled = true;
160: }
161:
162: void this _componentHidden(ComponentEvent e) {
163: clockPanel.stop();
164: timer.stop();
165: }
166:
167: void this _componentShown(ComponentEvent e) {
168: cancelled = false;
169: updateLabels();
170: cancelButton.setVisible(false);
171: timer.start();
172: clockPanel.start();
173: }
174:
175: private void updateLabels() {
176: taskProgressLabel.setText(taskProgress);
177: subtaskProgressLabel.setText(subtaskProgress);
178: }
179:
180: public void setRefreshRate(int millisecondDelay) {
181: //This feature was requested by Georgi Kostadinov. [Jon Aquino]
182: timer.setDelay(millisecondDelay);
183: }
184:
185: public void report(final String description) {
186: this .taskProgress = description;
187: subtaskProgress = "";
188: }
189:
190: public void report(int subtasksDone, int totalSubtasks,
191: String subtaskDescription) {
192: subtaskProgress = "";
193: subtaskProgress += subtasksDone;
194:
195: if (totalSubtasks != -1) {
196: subtaskProgress += (" / " + totalSubtasks);
197: }
198:
199: subtaskProgress += (" " + subtaskDescription);
200: }
201:
202: public void allowCancellationRequests() {
203: cancelButton.setVisible(true);
204: }
205:
206: public void report(Exception exception) {
207: errorHandler.handleThrowable(exception);
208: }
209:
210: public boolean isCancelRequested() {
211: return cancelled;
212: }
213: }
|