mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
12 changed files with 328 additions and 217 deletions
@ -1,51 +0,0 @@ |
|||||||
# |
|
||||||
# MIT License |
|
||||||
# |
|
||||||
# Copyright (c) 2020 Jannis Weis |
|
||||||
# |
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||||
# of this software and associated documentation files (the "Software"), to deal |
|
||||||
# in the Software without restriction, including without limitation the rights |
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||||
# copies of the Software, and to permit persons to whom the Software is |
|
||||||
# furnished to do so, subject to the following conditions: |
|
||||||
# |
|
||||||
# The above copyright notice and this permission notice shall be included in all |
|
||||||
# copies or substantial portions of the Software. |
|
||||||
# |
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
||||||
# SOFTWARE. |
|
||||||
# |
|
||||||
# |
|
||||||
name: Fonts |
|
||||||
|
|
||||||
on: |
|
||||||
push: |
|
||||||
branches: |
|
||||||
- 'master' |
|
||||||
jobs: |
|
||||||
gradle: |
|
||||||
strategy: |
|
||||||
matrix: |
|
||||||
os: [windows-latest, macos-latest, ubuntu-latest] |
|
||||||
runs-on: ${{ matrix.os }} |
|
||||||
steps: |
|
||||||
- uses: actions/checkout@v2 |
|
||||||
with: |
|
||||||
fetch-depth: 10 |
|
||||||
- name: Set up JDK 11 |
|
||||||
uses: actions/setup-java@v1 |
|
||||||
with: |
|
||||||
java-version: 11 |
|
||||||
- name: Build |
|
||||||
run: ./gradlew :darklaf-core:fontTest -PskipAutostyle |
|
||||||
- name: Upload Results |
|
||||||
uses: actions/upload-artifact@v1 |
|
||||||
with: |
|
||||||
name: ${{ matrix.os }}-font_test |
|
||||||
path: build/font_test |
|
@ -0,0 +1,127 @@ |
|||||||
|
/* |
||||||
|
* MIT License |
||||||
|
* |
||||||
|
* Copyright (c) 2020 Jannis Weis |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
* of this software and associated documentation files (the "Software"), to deal |
||||||
|
* in the Software without restriction, including without limitation the rights |
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
* copies of the Software, and to permit persons to whom the Software is |
||||||
|
* furnished to do so, subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
* SOFTWARE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.lang.reflect.Modifier; |
||||||
|
import java.net.URISyntaxException; |
||||||
|
import java.net.URL; |
||||||
|
import java.util.*; |
||||||
|
import java.util.function.Function; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
import java.util.stream.Stream; |
||||||
|
import java.util.stream.StreamSupport; |
||||||
|
|
||||||
|
public class ClassFinder { |
||||||
|
|
||||||
|
public static <T> List<T> getInstancesOfType(final Class<T> type, final String... packages) { |
||||||
|
return getClasses(packages).filter(type::isAssignableFrom) |
||||||
|
.filter(cls -> !cls.isInterface()) |
||||||
|
.filter(cls -> !Modifier.isAbstract(cls.getModifiers())) |
||||||
|
.map(ClassFinder::getInstance) |
||||||
|
.filter(Objects::nonNull) |
||||||
|
.map(type::cast) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
} |
||||||
|
|
||||||
|
private static <T> T getInstance(final Class<T> type) { |
||||||
|
try { |
||||||
|
return type.getDeclaredConstructor().newInstance(); |
||||||
|
} catch (InstantiationException |
||||||
|
| IllegalAccessException |
||||||
|
| InvocationTargetException |
||||||
|
| NoSuchMethodException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static Stream<Class<?>> getClasses(final String... packageNames) { |
||||||
|
return Stream.of(packageNames).flatMap(wrap(ClassFinder::getClasses)); |
||||||
|
} |
||||||
|
|
||||||
|
private static Stream<Class<?>> getClasses(final String packageName) throws IOException { |
||||||
|
ClassLoader classLoader = ClassFinder.class.getClassLoader(); |
||||||
|
String pack = packageName.replace(".", "/"); |
||||||
|
Enumeration<URL> resources = classLoader.getResources(pack); |
||||||
|
return enumerationAsStream(resources).map(ClassFinder::URLtoFile) |
||||||
|
.filter(Objects::nonNull) |
||||||
|
.map(dir -> findClasses(dir, packageName)) |
||||||
|
.flatMap(List::stream); |
||||||
|
} |
||||||
|
|
||||||
|
private static File URLtoFile(final URL url) { |
||||||
|
try { |
||||||
|
return new File(url.toURI()); |
||||||
|
} catch (URISyntaxException e) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private static List<Class<?>> findClasses(final File dir, final String packageName) { |
||||||
|
File directory = dir.getAbsoluteFile(); |
||||||
|
List<Class<?>> classes = new ArrayList<>(); |
||||||
|
File[] files = directory.listFiles(); |
||||||
|
if (files == null) return classes; |
||||||
|
for (File file : files) { |
||||||
|
if (file.isDirectory()) { |
||||||
|
assert !file.getName().contains("."); |
||||||
|
classes.addAll(findClasses(file, packageName + "." + file.getName())); |
||||||
|
} else if (file.getName().endsWith(".class")) { |
||||||
|
try { |
||||||
|
classes.add(Class.forName(packageName + '.' |
||||||
|
+ file.getName().substring(0, file.getName().length() - 6))); |
||||||
|
} catch (ClassNotFoundException ignored) {} |
||||||
|
} |
||||||
|
} |
||||||
|
return classes; |
||||||
|
} |
||||||
|
|
||||||
|
public static <T> Stream<T> enumerationAsStream(final Enumeration<T> e) { |
||||||
|
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<T>() { |
||||||
|
public T next() { |
||||||
|
return e.nextElement(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasNext() { |
||||||
|
return e.hasMoreElements(); |
||||||
|
} |
||||||
|
}, Spliterator.ORDERED), false); |
||||||
|
} |
||||||
|
|
||||||
|
public static <T, K, E extends Throwable> Function<T, K> wrap(final CheckedFunction<T, K, E> wrappee) { |
||||||
|
return t -> { |
||||||
|
try { |
||||||
|
return wrappee.apply(t); |
||||||
|
} catch (final Throwable e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
public interface CheckedFunction<T, K, E extends Throwable> { |
||||||
|
|
||||||
|
K apply(final T value) throws E; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
/* |
||||||
|
* MIT License |
||||||
|
* |
||||||
|
* Copyright (c) 2020 Jannis Weis |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
* of this software and associated documentation files (the "Software"), to deal |
||||||
|
* in the Software without restriction, including without limitation the rights |
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
* copies of the Software, and to permit persons to whom the Software is |
||||||
|
* furnished to do so, subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
* SOFTWARE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
package test; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.nio.file.Files; |
||||||
|
|
||||||
|
import javax.imageio.ImageIO; |
||||||
|
import javax.swing.*; |
||||||
|
|
||||||
|
import com.github.weisj.darklaf.graphics.ImageUtil; |
||||||
|
|
||||||
|
public abstract class AbstractImageTest { |
||||||
|
private static final int SCALING_FACTOR = 3; |
||||||
|
protected final static String WORKING_DIR = "image_test"; |
||||||
|
private final String workingDir; |
||||||
|
|
||||||
|
public AbstractImageTest(final String dir) { |
||||||
|
this.workingDir = dir != null ? WORKING_DIR + "/" + dir : WORKING_DIR; |
||||||
|
} |
||||||
|
|
||||||
|
protected String getWorkingDirectory() { |
||||||
|
return workingDir; |
||||||
|
} |
||||||
|
|
||||||
|
protected void createFolder(final String folder) throws IOException { |
||||||
|
Files.createDirectories(new File(getWorkingDirectory() + "/" + folder).toPath()); |
||||||
|
} |
||||||
|
|
||||||
|
protected BufferedImage saveScreenShot(final String name, final JComponent c) { |
||||||
|
return saveScreenShot(name, c, SCALING_FACTOR); |
||||||
|
} |
||||||
|
|
||||||
|
protected String getPath(final String name) { |
||||||
|
return getWorkingDirectory() + "/" + name; |
||||||
|
} |
||||||
|
|
||||||
|
protected BufferedImage saveScreenShot(final String name, final JComponent c, final double scalingFactor) { |
||||||
|
try { |
||||||
|
Rectangle rect = new Rectangle(0, 0, c.getWidth(), c.getHeight()); |
||||||
|
BufferedImage image = ImageUtil.scaledImageFromComponent(c, rect, scalingFactor, scalingFactor, false); |
||||||
|
ImageIO.write(image, "png", new File(name + ".png")); |
||||||
|
return image; |
||||||
|
} catch (IOException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
/* |
||||||
|
* MIT License |
||||||
|
* |
||||||
|
* Copyright (c) 2020 Jannis Weis |
||||||
|
* |
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
* of this software and associated documentation files (the "Software"), to deal |
||||||
|
* in the Software without restriction, including without limitation the rights |
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
* copies of the Software, and to permit persons to whom the Software is |
||||||
|
* furnished to do so, subject to the following conditions: |
||||||
|
* |
||||||
|
* The above copyright notice and this permission notice shall be included in all |
||||||
|
* copies or substantial portions of the Software. |
||||||
|
* |
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
* SOFTWARE. |
||||||
|
* |
||||||
|
*/ |
||||||
|
package test; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.condition.EnabledOnOs; |
||||||
|
import org.junit.jupiter.api.condition.OS; |
||||||
|
|
||||||
|
import com.github.weisj.darklaf.LafManager; |
||||||
|
import com.github.weisj.darklaf.ui.tooltip.ToolTipConstants; |
||||||
|
|
||||||
|
public class TooltipTest extends AbstractImageTest { |
||||||
|
|
||||||
|
public TooltipTest() { |
||||||
|
super("tooltip"); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
@EnabledOnOs({OS.MAC, OS.WINDOWS}) |
||||||
|
public void testTooltipTransparency() { |
||||||
|
LafManager.install(); |
||||||
|
JToolTip toolTip = new JToolTip(); |
||||||
|
toolTip.setTipText("Test ToolTip"); |
||||||
|
toolTip.putClientProperty(ToolTipConstants.KEY_STYLE, ToolTipConstants.VARIANT_BALLOON); |
||||||
|
toolTip.setSize(toolTip.getPreferredSize()); |
||||||
|
toolTip.doLayout(); |
||||||
|
BufferedImage img = saveScreenShot(getPath("tooltip_mac"), toolTip); |
||||||
|
Assertions.assertNotNull(img); |
||||||
|
int alpha = new Color(img.getRGB(img.getMinX(), img.getMinY() + img.getHeight() - 1), true).getAlpha(); |
||||||
|
Assertions.assertEquals(0, alpha); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue