Skip to content

Commit

Permalink
- WebLookAndFeel.java - Fixed L&F initialization through UIManager [
Browse files Browse the repository at this point in the history
…#621 ]

- LookAndFeelInitializationTest.java - New test for basic and custom L&F initialization
  • Loading branch information
mgarin committed May 15, 2020
1 parent bce8c15 commit ef303ee
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/ui/src/com/alee/laf/WebLookAndFeel.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public class WebLookAndFeel extends BasicLookAndFeel
public static final String LEADING_COMPONENT_PROPERTY = "leadingComponent";
public static final String TRAILING_COMPONENT_PROPERTY = "trailingComponent";

/**
* Whether or not {@link WebLookAndFeel} is currently installed as application's Look and Feel.
* Separate field is used to store the state instead of checking current Look and Feel to avoid initalization time issues.
*/
protected static boolean installed = false;

/**
* Whether or not library should force Event Dispatch Thread usage for all UI-related operations.
* Enabling this might allow you to find out places where you try to interact with UI elements outside of the EDT.
Expand Down Expand Up @@ -395,6 +401,9 @@ public void initialize ()

// Listening to ALT key for menubar quick focusing
KeyboardFocusManager.getCurrentKeyboardFocusManager ().addKeyEventPostProcessor ( altProcessor );

// Updating state
installed = true;
}

/**
Expand All @@ -408,6 +417,9 @@ public void uninitialize ()

// Removing alt processor
KeyboardFocusManager.getCurrentKeyboardFocusManager ().removeKeyEventPostProcessor ( altProcessor );

// Updating state
installed = false;
}

/**
Expand Down Expand Up @@ -1115,7 +1127,7 @@ public static void install ( @NotNull final LazyInstance<? extends Skin> skin )
*/
public static boolean isInstalled ()
{
return WebLookAndFeel.class.isInstance ( UIManager.getLookAndFeel () );
return installed;
}

/**
Expand Down
89 changes: 89 additions & 0 deletions modules/ui/test/com/alee/laf/LookAndFeelInitializationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of WebLookAndFeel library.
*
* WebLookAndFeel library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WebLookAndFeel 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WebLookAndFeel library. If not, see <http://www.gnu.org/licenses/>.
*/

package com.alee.laf;

import com.alee.utils.CoreSwingUtils;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import javax.swing.*;
import javax.swing.plaf.metal.MetalLookAndFeel;

/**
* Set of JUnit tests for {@link WebLookAndFeel}.
*
* @author Mikle Garin
*/
@FixMethodOrder ( MethodSorters.JVM )
public class LookAndFeelInitializationTest
{
/**
* {@link WebLookAndFeel} installation and uninstallation test through {@link UIManager}.
*/
@Test
public void installUninstallBasic ()
{
CoreSwingUtils.invokeAndWait ( new Runnable ()
{
@Override
public void run ()
{
try
{
// Installing WebLookAndFeel
UIManager.setLookAndFeel ( new WebLookAndFeel () );

// Uninstalling WebLookAndFeel
UIManager.setLookAndFeel ( MetalLookAndFeel.class.getCanonicalName () );
}
catch ( final Exception e )
{
throw new RuntimeException ( e );
}
}
} );
}

/**
* {@link WebLookAndFeel} installation and uninstallation test through custom L&F class methods.
*/
@Test
public void installUninstallCustom ()
{
CoreSwingUtils.invokeAndWait ( new Runnable ()
{
@Override
public void run ()
{
try
{
// Installing WebLookAndFeel
WebLookAndFeel.install ();

// Uninstalling WebLookAndFeel
WebLookAndFeel.uninstall ();
}
catch ( final Exception e )
{
throw new RuntimeException ( e );
}
}
} );
}
}

0 comments on commit ef303ee

Please sign in to comment.