|
|
@ -35,15 +35,22 @@ import javax.swing.*; |
|
|
|
import javax.swing.event.ListDataListener; |
|
|
|
import javax.swing.event.ListDataListener; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.*; |
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URL; |
|
|
|
import java.nio.file.FileSystem; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.nio.file.FileSystems; |
|
|
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
public class AllIcons { |
|
|
|
public class AllIcons { |
|
|
|
|
|
|
|
|
|
|
|
private static String[] FOLDERS = new String[]{ |
|
|
|
private static String[] FOLDERS = new String[]{ |
|
|
|
"control", "dialog", "files", "indicator", "menu", "misc", "navigation", "window", |
|
|
|
"icons/control", "icons/dialog", "icons/files", "icons/indicator", "icons/menu", "icons/misc", |
|
|
|
|
|
|
|
"icons/navigation", "platform/windows/icons/window", "platform/windows/icons" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(final String[] args) { |
|
|
|
public static void main(final String[] args) { |
|
|
@ -79,38 +86,51 @@ public class AllIcons { |
|
|
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
|
|
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
|
|
|
frame.setLocationRelativeTo(null); |
|
|
|
frame.setLocationRelativeTo(null); |
|
|
|
frame.setVisible(true); |
|
|
|
frame.setVisible(true); |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
} catch (URISyntaxException | IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static List<Pair<String, Icon>> loadIcons() throws URISyntaxException { |
|
|
|
private static List<Pair<String, Icon>> loadIcons() throws URISyntaxException, IOException { |
|
|
|
List<Pair<String, Icon>> list = new ArrayList<>(); |
|
|
|
List<Pair<String, Icon>> list = new ArrayList<>(); |
|
|
|
for (String folder : FOLDERS) { |
|
|
|
for (String folder : FOLDERS) { |
|
|
|
File[] files = getResourceFolderFiles("icons/" + folder, DarkLaf.class); |
|
|
|
Pair<Stream<Path>, Optional<FileSystem>> files = walk(folder, DarkLaf.class); |
|
|
|
for (File f : files) { |
|
|
|
try (FileSystem fs = files.getSecond().isPresent() ? files.getSecond().get() : null) { |
|
|
|
if (f.getName().endsWith(".svg")) { |
|
|
|
files.getFirst().forEach(p -> { |
|
|
|
|
|
|
|
if (p.getFileName().toString().endsWith(".svg")) { |
|
|
|
int SIZE = 30; |
|
|
|
int SIZE = 30; |
|
|
|
ThemedSVGIcon icon = (ThemedSVGIcon) IconLoader.get().loadSVGIcon(folder + "/" + f.getName(), |
|
|
|
ThemedSVGIcon icon = (ThemedSVGIcon) IconLoader.get(DarkLaf.class) |
|
|
|
|
|
|
|
.loadSVGIcon(folder + "/" + p.getFileName(), |
|
|
|
SIZE, SIZE, true); |
|
|
|
SIZE, SIZE, true); |
|
|
|
SVGIcon svgIcon = icon.getSVGIcon(); |
|
|
|
SVGIcon svgIcon = icon.getSVGIcon(); |
|
|
|
int autosize = svgIcon.getAutosize(); |
|
|
|
int autosize = svgIcon.getAutosize(); |
|
|
|
svgIcon.setAutosize(SVGIcon.AUTOSIZE_NONE); |
|
|
|
svgIcon.setAutosize(SVGIcon.AUTOSIZE_NONE); |
|
|
|
icon.setDisplaySize(svgIcon.getIconWidth() * 2, svgIcon.getIconHeight() * 2); |
|
|
|
int width = Math.min(svgIcon.getIconWidth() * 2, 100); |
|
|
|
|
|
|
|
int height = (int) (((double) width / svgIcon.getIconWidth()) * svgIcon.getIconHeight()); |
|
|
|
|
|
|
|
icon.setDisplaySize(width, height); |
|
|
|
svgIcon.setAutosize(autosize); |
|
|
|
svgIcon.setAutosize(autosize); |
|
|
|
list.add(new Pair<>(f.getName(), icon)); |
|
|
|
list.add(new Pair<>(p.getFileName().toString(), icon)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static File[] getResourceFolderFiles(final String folder, |
|
|
|
public static Pair<Stream<Path>, Optional<FileSystem>> walk(final String path, final Class<?> clazz) |
|
|
|
final Class<?> clazz) throws URISyntaxException { |
|
|
|
throws URISyntaxException, IOException { |
|
|
|
URL url = clazz.getResource(folder); |
|
|
|
URI uri = clazz.getResource(path).toURI(); |
|
|
|
return new File(url.toURI()).listFiles(); |
|
|
|
if ("jar".equals(uri.getScheme())) { |
|
|
|
|
|
|
|
FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap()); |
|
|
|
|
|
|
|
Path resourcePath = fileSystem.getPath("com/github/weisj/darklaf/" + path); |
|
|
|
|
|
|
|
// Get all contents of a resource (skip resource itself), if entry is a directory remove trailing /
|
|
|
|
|
|
|
|
return new Pair<>(Files.walk(resourcePath, 1), Optional.of(fileSystem)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return new Pair<>(Arrays.stream(Optional.ofNullable(new File(uri).listFiles()) |
|
|
|
|
|
|
|
.orElse(new File[0])).map(File::toPath), Optional.empty()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final class IconListRenderer extends JLabel implements ListCellRenderer<Pair<String, Icon>> { |
|
|
|
private static final class IconListRenderer extends JLabel implements ListCellRenderer<Pair<String, Icon>> { |
|
|
|