001: /*
002: * <copyright>
003: *
004: * Copyright 2000-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.csmart.ui.viewer;
028:
029: import org.cougaar.tools.csmart.core.db.DBConflictHandler;
030:
031: import javax.swing.*;
032: import javax.swing.event.MouseInputAdapter;
033: import java.awt.*;
034: import java.awt.event.MouseEvent;
035: import java.awt.event.MouseListener;
036:
037: /**
038: * Methods to put up a wait cursor and consume mouse events while
039: * a time consuming task is being done in the background.
040: * Also a method to create a UI based <code>DBConflictHandler</code>
041: */
042: public class GUIUtils {
043:
044: static final Cursor waitCursor = Cursor
045: .getPredefinedCursor(Cursor.WAIT_CURSOR);
046: static final Cursor defaultCursor = Cursor
047: .getPredefinedCursor(Cursor.DEFAULT_CURSOR);
048:
049: public static void timeConsumingTaskStart(Component c) {
050: JFrame frame = null;
051: if (c != null)
052: frame = (JFrame) SwingUtilities.getRoot(c);
053: if (frame == null)
054: return;
055: Component glass = frame.getGlassPane();
056: glass.setCursor(waitCursor);
057: glass.addMouseListener(new MyMouseListener());
058: glass.setVisible(true);
059: }
060:
061: public static void timeConsumingTaskEnd(Component c) {
062: JFrame frame = null;
063: if (c != null)
064: frame = (JFrame) SwingUtilities.getRoot(c);
065: if (frame == null)
066: return;
067: Component glass = frame.getGlassPane();
068: MouseListener[] mls = (MouseListener[]) glass
069: .getListeners(MouseListener.class);
070: for (int i = 0; i < mls.length; i++)
071: if (mls[i] instanceof MyMouseListener)
072: glass.removeMouseListener(mls[i]);
073: glass.setCursor(defaultCursor);
074: glass.setVisible(false);
075: }
076:
077: static class MyMouseListener extends MouseInputAdapter {
078: public void mouseClicked(MouseEvent e) {
079: e.consume();
080: }
081:
082: public void mouseDragged(MouseEvent e) {
083: e.consume();
084: }
085:
086: public void mouseEntered(MouseEvent e) {
087: e.consume();
088: }
089:
090: public void mouseExited(MouseEvent e) {
091: e.consume();
092: }
093:
094: public void mouseMoved(MouseEvent e) {
095: e.consume();
096: }
097:
098: public void mousePressed(MouseEvent e) {
099: e.consume();
100: }
101:
102: public void mouseReleased(MouseEvent e) {
103: e.consume();
104: }
105: }
106:
107: /**
108: * Create a new window to prompt the user to handle conflicts in
109: * saving to the database.
110: *
111: * @param parent a <code>Component</code> frame to base this one on, may be null
112: * @return a <code>DBConflictHandler</code> to show
113: */
114: public static DBConflictHandler createSaveToDbConflictHandler(
115: final Component parent) {
116: return new GUIDBConflictHandler(parent);
117: }
118:
119: }
|