Changeset 8480


Ignore:
Timestamp:
2004-11-08T11:52:49+13:00 (19 years ago)
Author:
mdewsnip
Message:

Fixed the ModalDialog so it works with Java 1.5.0.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r8474 r8480  
    4646import org.greenstone.gatherer.file.FileAssociationManager;
    4747import org.greenstone.gatherer.gui.GUIManager;
    48 import org.greenstone.gatherer.gui.ModalDialog;
    4948import org.greenstone.gatherer.gui.Splash;
    5049import org.greenstone.gatherer.gui.URLField;
  • trunk/gli/src/org/greenstone/gatherer/gui/ModalDialog.java

    r8257 r8480  
    2727
    2828import java.awt.*;
     29import java.awt.event.*;
    2930import javax.swing.*;
    3031import org.greenstone.gatherer.DebugStream;
     32
    3133
    3234/** An extension of the JDialog that overrides the JVM's typical modal behaviour. This typical behaviour is that when a modal dialog is opened, all other windows cease to respond to user events until the modal dialog is disposed. However this prevents us opening the help documents property whenever a modal dialog is open. Thus we override the modal behaviour so that only the owner frame or dialog is blocked.
     
    133135     * @param visible true if this dialog should be painted on-screen, false otherwise.
    134136     */
    135     public void setVisible (boolean visible) {
    136     if(visible) {
     137    public void setVisible(boolean visible)
     138    {
     139    if (visible) {
    137140        current_modal = this;
    138141    }
     
    140143        current_modal = null;
    141144    }
     145
    142146    // If we are in the AWT Dispatch thread then it is all good.
    143     if (SwingUtilities.isEventDispatchThread ()) {
    144         getParent ().setEnabled (!(visible && modal));
    145         super.setVisible (visible);
     147    if (SwingUtilities.isEventDispatchThread()) {
     148        super.setVisible(visible);
    146149        if (modal && visible) {
    147         ///ystem.err.println("is Event Dispatch Thread. Only process certain events.");
    148150        EventQueue theQueue = getToolkit().getSystemEventQueue();
    149         while (isVisible ()) {
     151        while (isVisible()) {
    150152            try {
    151153            AWTEvent event = theQueue.getNextEvent();
    152             Object src = event.getSource ();
     154            Object src = event.getSource();
     155
     156            // Block all keyboard and mouse events to the parent component
     157            if (src.equals(getParent())) {
     158                if (event instanceof KeyEvent || event instanceof MouseEvent) {
     159                // System.err.println("Event to parent component blocked.");
     160                continue;
     161                }
     162            }
     163
     164            // Re-dispatch other events
    153165            if (event instanceof ActiveEvent) {
    154                 ///ystem.err.println("ActiveEvent:");
    155                 ((ActiveEvent) event).dispatch ();
    156             } else if (src instanceof Component) {
    157                 ///ystem.err.println("Source is component");
    158                 ((Component) src).dispatchEvent (event);
    159             }
    160             else {
    161                 ///ystem.err.println("Event blocked");
     166                ((ActiveEvent) event).dispatch();
     167            }               
     168            else if (src instanceof Component) {
     169                ((Component) src).dispatchEvent(event);
    162170            }
    163171            }
    164             catch(Exception exception) {
     172            catch (Exception exception) {
    165173            DebugStream.printStackTrace(exception);
    166174            }
    167175        }
    168176        }
    169     }
    170     else {
    171         try {
    172         SwingUtilities.invokeAndWait(new MakeDialogVisibleTask(this, visible));
    173         }
    174         catch(Exception exception) {
    175         DebugStream.printStackTrace(exception);
    176         }
    177     }
     177    }
     178    else {
     179        try {
     180        SwingUtilities.invokeAndWait(new MakeDialogVisibleTask(this, visible));
     181        }
     182        catch (Exception exception) {
     183        DebugStream.printStackTrace(exception);
     184        }
     185    }
    178186    }
    179187   
Note: See TracChangeset for help on using the changeset viewer.