Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  jDTAUS - DTAUS fileformat.
   *  Copyright (c) 2005 Christian Schulte <cs@schulte.it>
   *
   *  This library is free software; you can redistribute it and/or
   *  modify it under the terms of the GNU Lesser General Public
   *  License as published by the Free Software Foundation; either
   *  version 2.1 of the License, or any later version.
   *
  *  This library is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  *  Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public
  *  License along with this library; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 package org.jdtaus.core.swing.util;
 
 import  org.jdtaus.core.container.Implementation;
 import  org.jdtaus.core.container.ModelFactory;
 import  org.jdtaus.core.container.Properties;
 import  org.jdtaus.core.container.Property;

JComponent for use as a blocking glasspane.

Blocking is controlled by property visible. If true, the current look and feel's provideErrorFeedback method is called whenever a mouse clicked MouseEvent, or a KeyEvent of type KEY_TYPED, whose source is not null and descending from the parent of this component, is received. Also the cursor is set to the cursor to use when blocking is in effect. If false, the cursor is reset to the system's default cursor and no more blocking is performed. Property visible defaults to false.

Author(s):
Christian Schulte
Version:
$Id: BlockingGlassPane.java 4650 2008-03-10 04:25:23Z schulte2005 $
 
 public final class BlockingGlassPane extends JComponent
 {
     //--Implementation----------------------------------------------------------
 
 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausImplementation
     // This section is managed by jdtaus-container-mojo.
 
    
Meta-data describing the implementation.
 
     private static final Implementation META =
         ModelFactory.getModel().getModules().
         getImplementation(BlockingGlassPane.class.getName());
 // </editor-fold>//GEN-END:jdtausImplementation
 
     //----------------------------------------------------------Implementation--
     //--Constructors------------------------------------------------------------
 
 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausConstructors
     // This section is managed by jdtaus-container-mojo.
 
    
Initializes the properties of the instance.

Parameters:
meta the property values to initialize the instance with.
Throws:
NullPointerException if meta is null.
 
     private void initializeProperties(final Properties meta)
     {
         Property p;
 
         if(meta == null)
         {
             throw new NullPointerException("meta");
         }
 
         p = meta.getProperty("cursorType");
         this. = ((java.lang.Integerp.getValue()).intValue();
 
     }
 // </editor-fold>//GEN-END:jdtausConstructors
 
     //------------------------------------------------------------Constructors--
     //--Dependencies------------------------------------------------------------
 
 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausDependencies
    // This section is managed by jdtaus-container-mojo.
// </editor-fold>//GEN-END:jdtausDependencies
    //------------------------------------------------------------Dependencies--
    //--Properties--------------------------------------------------------------
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausProperties
    // This section is managed by jdtaus-container-mojo.

    
Property cursorType.

Serial:
    private int pCursorType;

    
Gets the value of property cursorType.

Returns:
the value of property cursorType.
    private int getCursorType()
    {
        return this.;
    }
// </editor-fold>//GEN-END:jdtausProperties
    //--------------------------------------------------------------Properties--
    //--JComponent--------------------------------------------------------------

    
Enables or disables blocking.

This method registers a KeyEventDispatcher with AWT's current KeyboardFocusManager blocking the keyboard for any user interaction and updates the cursor to the cursor to use when blocking is in effect if visible is true. If visible is false the KeyEventDispatcher is removed and the cursor is reset to the system's default cursor.

Parameters:
visible true to enable blocking; false to disable blocking.
    public void setVisiblefinal boolean visible )
    {
        final Runnable runnable = new Runnable()
        {
            public void run()
            {
                if ( visible )
                {
                    BlockingGlassPane.super.setVisibletrue );
                    setCursor );
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        addKeyEventDispatcher );
                }
                else
                {
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
                        removeKeyEventDispatcher );
                    setCursor( Cursor.getDefaultCursor() );
                    BlockingGlassPane.super.setVisiblefalse );
                    .getContentPane().validate();
                }
            }
        };
        if ( !SwingUtilities.isEventDispatchThread() )
        {
            SwingUtilities.invokeLaterrunnable );
        }
        else
        {
            runnable.run();
        }
    }
    //--------------------------------------------------------------JComponent--
    //--BlockingGlassPane-------------------------------------------------------

    
KeyEventDispatcher used for blocking.
    private class BlockingDispatcher implements Serializable,
                                                 KeyEventDispatcher
    {
        public boolean dispatchKeyEventfinal KeyEvent e )
        {
            final Component source = e.getComponent();
            if ( source != null &&
                SwingUtilities.isDescendingFromsourcegetParent() ) &&
                e.getID() == . )
            {
                UIManager.getLookAndFeel().provideErrorFeedbackgetParent() );
                e.consume();
            }
            return e.isConsumed();
        }
    }

    
Container this component is registered as the glasspane with.

Serial:
    private final RootPaneContainer container;

    
KeyEventDispatcher used for blocking keyboard interaction.

Serial:
    private final KeyEventDispatcher keyDispatcher;

    
Cursor to use when blocking is in effect.

Serial:
    private final Cursor cursor;

    
Creates a new BlockingGlassPane instance taking the container this component is registered with.

Parameters:
container the container this component is registered with.
Throws:
NullPointerException if container is null.
    public BlockingGlassPanefinal RootPaneContainer container )
    {
        super();
        if ( container == null )
        {
            throw new NullPointerException"container" );
        }
        this.initializeProperties.getProperties() );
        this. = container;
        this. = Cursor.getPredefinedCursorthis.getCursorType() );
        this. = new BlockingDispatcher();
        this.initialize();
    }

    
Creates a new BlockingGlassPane instance taking the container this component is registered with and the cursor to use when blocking is in effect.

Parameters:
container the container this component is registered with.
cursor the cursor to use when blocking is in effect.
Throws:
NullPointerException if either container or cursor is null.
    public BlockingGlassPanefinal RootPaneContainer container,
                               final Cursor cursor )
    {
        super();
        if ( container == null )
        {
            throw new NullPointerException"container" );
        }
        if ( cursor == null )
        {
            throw new NullPointerException"cursor" );
        }
        this. = container;
        this. = cursor;
        this. = new BlockingDispatcher();
        this.initializeProperties.getProperties() );
        this.initialize();
    }

    
Initializes the instance.
    private void initialize()
    {
        super.setVisiblefalse );
        this.setOpaquefalse );
        this.addMouseListener(
            new MouseAdapter()
            {
                public void mouseClickedfinal MouseEvent e )
                {
                    UIManager.getLookAndFeel().
                        provideErrorFeedbackgetParent() );
                }
            } );
    }
    //-------------------------------------------------------BlockingGlassPane--
New to GrepCode? Check out our FAQ X