Java Code Examples for com.alee.laf.WebLookAndFeel#checkEventDispatchThread()

The following examples show how to use com.alee.laf.WebLookAndFeel#checkEventDispatchThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsProcessor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs new {@link SettingsProcessor} for the specified {@link JComponent} and {@link Configuration}.
 *
 * @param component     {@link JComponent} which settings are being managed
 * @param configuration {@link Configuration}
 */
public SettingsProcessor ( @NotNull final C component, @NotNull final K configuration )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Component and configuration
    this.component = component;
    this.configuration = configuration;

    // Performing initial settings load
    loadInitialSettings ();

    // Initializing processor settings
    initialize ();
}
 
Example 2
Source File: WebTreeFilterField.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets nodes filter.
 *
 * @param filter new nodes filter
 */
public void setFilter ( @NotNull final StructuredTreeNodesFilter<N> filter )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Saving tree state before applying the filter
    saveState ();

    // Removing old filter
    removeFieldFilter ();

    // Saving reference to new filter
    this.filter = filter;

    // Applying new filter
    applyFieldFilter ();

    // Restoring tree state after applying the filter
    restoreState ();
}
 
Example 3
Source File: SettingsProcessor.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Destroys this SettingsProcessor.
 */
public final void destroy ()
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Unegistering specific processor settings
    try
    {
        unregister ( component () );
    }
    catch ( final Exception e )
    {
        final String msg = "Unable to unregister specific processor settings for component " +
                "with group '%s' and key '%s' due to unexpected exception";
        final String fmsg = String.format ( msg, configuration.group (), configuration.key () );
        LoggerFactory.getLogger ( SettingsProcessor.class ).error ( fmsg, e );
    }
}
 
Example 4
Source File: WebAsyncTree.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets {@link AsyncTreeDataProvider} used by this {@link WebAsyncTree}.
 *
 * @param dataProvider new {@link AsyncTreeDataProvider} for this {@link WebAsyncTree}
 */
public void setDataProvider ( @NotNull final AsyncTreeDataProvider dataProvider )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    /**
     * Initializing new {@link AsyncTreeModel} based on specified {@link AsyncTreeDataProvider}.
     * This is necessary as the model will keep {@link AsyncTreeDataProvider} instead of {@link WebAsyncTree}.
     */
    setModel ( new AsyncTreeModel<N> ( dataProvider ) );
}
 
Example 5
Source File: AsyncTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeNodesFromParent ( @NotNull final N parent )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure model is installed
    checkInstalled ();

    // Ensure parent exists and children are loaded
    if ( parent.isLoaded () )
    {
        // Removing raw children
        final List<N> removed = rawNodeChildrenCache.get ( parent.getId () );

        // Clearing node children caches
        clearNodeChildrenCache ( parent, false );

        // Removing node children
        super.removeNodesFromParent ( parent );

        // Removing image observers
        if ( CollectionUtils.notEmpty ( removed ) )
        {
            for ( final N node : removed )
            {
                node.detachLoadIconObserver ( tree );
            }
        }
    }
}
 
Example 6
Source File: AsyncTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void removeNodeFromParent ( @NotNull final MutableTreeNode node )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure model is installed
    checkInstalled ();

    final N child = ( N ) node;
    final N parent = ( N ) child.getParent ();

    // Ensure parent exists and children are loaded
    if ( parent != null && parent.isLoaded () )
    {
        // Removing raw children
        final List<N> children = rawNodeChildrenCache.get ( parent.getId () );
        if ( children != null )
        {
            children.remove ( child );
        }

        // Clearing node cache
        clearNodeChildrenCache ( child, true );

        // Removing node children so they won't mess up anything when we place node back into tree
        child.removeAllChildren ();

        // Removing node from parent
        super.removeNodeFromParent ( node );

        // Removing image observer
        child.detachLoadIconObserver ( tree );
    }
}
 
Example 7
Source File: ExTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates filtering and sorting for the specified {@link UniqueNode} children.
 *
 * @param parent      {@link UniqueNode} for which children filtering and sorting should be updated
 * @param recursively whether should update filtering and sorting for all {@link UniqueNode} children recursively
 */
public void filterAndSort ( @NotNull final N parent, final boolean recursively )
{
    // Operation might have finished after model was removed from the tree
    if ( isInstalled () )
    {
        // Event Dispatch Thread check
        WebLookAndFeel.checkEventDispatchThread ();

        // Saving tree state to restore it right after children update
        final TreeState treeState = tree.getTreeState ( parent );

        // Updating root node children
        if ( recursively )
        {
            filterAndSortRecursively ( parent );
        }
        else
        {
            filterAndSort ( parent );
        }

        // Informing tree about possible major structure changes
        nodeStructureChanged ( parent );

        // Restoring tree state including all selections and expansions
        tree.setTreeState ( treeState, parent );
    }
}
 
Example 8
Source File: WebExCheckBoxTree.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setComparator ( @Nullable final Comparator<N> comparator )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure parameter changed
    if ( comparator != getComparator () )
    {
        final Comparator<N> old = getComparator ();
        this.comparator = comparator;
        sort ();
        firePropertyChange ( COMPARATOR_PROPERTY, old, comparator );
    }
}
 
Example 9
Source File: LazyContent.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Removes currently added content {@link JComponent}.
 */
protected void removeCurrentContent ()
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure old content exists
    if ( content != null && content.getParent () == container )
    {
        contentIndex = container.getComponentZOrder ( content );
        container.remove ( content );
    }
}
 
Example 10
Source File: AsyncTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Inserts new child node into parent node at the specified index.
 *
 * @param child  new child node
 * @param parent parent node
 * @param index  insert index
 */
@Override
public void insertNodeInto ( @NotNull final MutableTreeNode child, @NotNull final MutableTreeNode parent, final int index )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure model is installed
    checkInstalled ();

    final N parentNode = ( N ) parent;
    final N childNode = ( N ) child;

    // Ensure node children are loaded
    if ( parentNode.isLoaded () )
    {
        // Inserting new raw children
        List<N> cachedChildren = rawNodeChildrenCache.get ( parentNode.getId () );
        if ( cachedChildren == null )
        {
            cachedChildren = new ArrayList<N> ( 1 );
            rawNodeChildrenCache.put ( parentNode.getId (), cachedChildren );
        }
        cachedChildren.add ( index, childNode );
        cacheNodeById ( childNode );

        // Clearing node cache
        // That might be required in case nodes were moved inside of the tree
        clearNodeChildrenCache ( childNode, false );

        // Inserting node
        insertNodeIntoImpl ( childNode, parentNode, index );

        // Updating parent node sorting and filtering
        filterAndSort ( parentNode, false );
    }
}
 
Example 11
Source File: ExTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public N getChild ( @NotNull final Object parent, final int index )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure model is installed
    checkInstalled ();

    // Looking for child node
    return ( N ) super.getChild ( parent, index );
}
 
Example 12
Source File: StyleData.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies specified custom skin to the skinnable component and all of its children linked via {@link StyleId}.
 * Actual linked children information is stored within {@link StyleData} data objects.
 * Custom skin provided using this method will not be replaced if application skin changes.
 *
 * @param skin        skin to be applied
 * @param recursively whether or not should apply skin to child components
 * @return previously applied skin
 */
@Nullable
protected Skin applyCustomSkin ( @NotNull final Skin skin, final boolean recursively )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Replacing component skin
    // Style children are also updated through this call
    // Even though we might encounter style children again in components tree later it will not cause extensive updates
    final Skin previousSkin = applySkin ( skin, true );

    // Pinning applied skin
    // This will keep this skin even if global skin is changed
    setPinnedSkin ( true );

    // Applying new skin to all existing skinnable components
    // This approach is quite different from style children but works better for large UI updates
    if ( recursively )
    {
        final JComponent component = getComponent ();
        for ( int i = 0; i < component.getComponentCount (); i++ )
        {
            final Component child = component.getComponent ( i );
            if ( child instanceof JComponent )
            {
                StyleManager.setSkin ( ( JComponent ) child, skin, true );
            }
        }
    }

    return previousSkin;
}
 
Example 13
Source File: StyleManager.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Registers new {@link ComponentDescriptor}.
 * It will replace any other {@link ComponentDescriptor} registered for the same {@link JComponent} type.
 * Manager initialization is not required to register {@link ComponentDescriptor}.
 *
 * @param descriptor {@link ComponentDescriptor} to register
 */
public static void registerComponentDescriptor ( @NotNull final ComponentDescriptor descriptor )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Synchronized by descriptors
    synchronized ( descriptors )
    {
        final Class componentClass = descriptor.getComponentClass ();

        // Removing existing descriptor with same class
        final ComponentDescriptor toRemove = descriptorsByClass.get ( componentClass );
        if ( toRemove != null )
        {
            unregisterComponentDescriptor ( toRemove );
        }

        // Saving new descriptor
        descriptors.add ( descriptor );

        // Caching descriptor
        descriptorsByIdentifier.put ( descriptor.getId (), descriptor );
        descriptorsByClass.put ( componentClass, descriptor );

        // Updating UIDefaults
        if ( WebLookAndFeel.isInstalled () )
        {
            descriptor.updateDefaults ( UIManager.getLookAndFeelDefaults () );
        }

        // todo Listeners for these changes?
    }
}
 
Example 14
Source File: StyleData.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Uninstalls style listeners and currently applied {@link Skin}.
 */
public void uninstall ()
{
    // Removing skin
    removeSkin ();

    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Adding style identifier listener
    final JComponent component = getComponent ();
    component.removePropertyChangeListener ( StyleId.PARENT_STYLE_PROPERTY, this );
    component.removePropertyChangeListener ( StyleId.STYLE_PROPERTY, this );
}
 
Example 15
Source File: AsyncTreeModel.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fires children load start event.
 *
 * @param parent node which children are being loaded
 */
protected void fireChildrenLoadStarted ( @NotNull final N parent )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Firing listeners
    for ( final AsyncTreeModelListener listener : listeners.getListeners ( AsyncTreeModelListener.class ) )
    {
        listener.loadStarted ( parent );
    }
}
 
Example 16
Source File: WebTreeFilterField.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets node text provider.
 *
 * @param textProvider new node text provider
 */
public void setTextProvider ( @NotNull final Function<N, String> textProvider )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Updating filter's text provider
    filter.setTextProvider ( textProvider );

    // Updating filtering
    updateFiltering ();
}
 
Example 17
Source File: WebAsyncTree.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setModel ( @Nullable final TreeModel newModel )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    /**
     * Simply ignoring any models that are not {@link AsyncTreeModel}-based.
     * This is a workaround to avoid default model being set in {@link javax.swing.JTree}.
     * This way we can prevent any models from being forced on us and avoid unnecessary events and UI updates.
     */
    if ( newModel instanceof AsyncTreeModel )
    {
        final AsyncTreeModel<N> old = getModel ();
        final AsyncTreeDataProvider<N> oldDataProvider;
        if ( old != null )
        {
            oldDataProvider = old.getDataProvider ();
            old.uninstall ( this );
        }
        else
        {
            oldDataProvider = null;
        }

        final AsyncTreeModel model = ( AsyncTreeModel ) newModel;
        model.install ( this );

        super.setModel ( model );

        firePropertyChange ( DATA_PROVIDER_PROPERTY, oldDataProvider, model.getDataProvider () );
    }
    else if ( newModel != null )
    {
        throw new NullPointerException ( "Only AsyncTreeModel implementations can be used for WebAsyncTree" );
    }
}
 
Example 18
Source File: WebExTree.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setModel ( @Nullable final TreeModel newModel )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    /**
     * Simply ignoring any models that are not {@link ExTreeModel}-based.
     * This is a workaround to avoid default model being set in {@link javax.swing.JTree}.
     * This way we can prevent any models from being forced on us and avoid unnecessary events and UI updates.
     */
    if ( newModel instanceof ExTreeModel )
    {
        final ExTreeModel<N> old = getModel ();
        final ExTreeDataProvider<N> oldDataProvider;
        if ( old != null )
        {
            oldDataProvider = old.getDataProvider ();
            old.uninstall ( this );
        }
        else
        {
            oldDataProvider = null;
        }

        final ExTreeModel model = ( ExTreeModel ) newModel;
        model.install ( this );

        super.setModel ( model );

        firePropertyChange ( DATA_PROVIDER_PROPERTY, oldDataProvider, model.getDataProvider () );
    }
    else if ( newModel != null )
    {
        throw new NullPointerException ( "Only ExTreeModel implementations can be used for WebExTree" );
    }
}
 
Example 19
Source File: StyleManager.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Changes default {@link Skin} used upon {@link StyleManager} initialization.
 * Manager initialization is not required to change default {@link Skin}.
 *
 * @param skin default skin class
 */
public static void setDefaultSkin ( @NotNull final LazyInstance<? extends Skin> skin )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Updating default skin class
    StyleManager.defaultSkin = skin;
}
 
Example 20
Source File: AsyncTreeModel.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeNodesFromParent ( @NotNull final List<N> nodes )
{
    // Event Dispatch Thread check
    WebLookAndFeel.checkEventDispatchThread ();

    // Ensure model is installed
    checkInstalled ();

    // Removing raw children
    final List<N> removed = new ArrayList<N> ( nodes.size () );
    for ( final N child : nodes )
    {
        // Ensure parent exists and children are loaded
        final N parent = ( N ) child.getParent ();
        if ( parent != null && parent.isLoaded () )
        {
            // Updating children caches
            final List<N> children = rawNodeChildrenCache.get ( parent.getId () );
            if ( children != null )
            {
                children.remove ( child );
            }

            // Clearing nodes children caches
            clearNodeChildrenCache ( child, true );

            // Removing node children so they won't mess up anything when we place node back into tree
            child.removeAllChildren ();

            // Saving removed node
            removed.add ( child );
        }
    }

    // Removing nodes from parent
    super.removeNodesFromParent ( nodes );

    // Removing image observers
    if ( CollectionUtils.notEmpty ( removed ) )
    {
        for ( final N node : removed )
        {
            node.detachLoadIconObserver ( tree );
        }
    }
}