Search in sources :

Example 1 with BitmapBrush

use of org.pepsoft.worldpainter.brushes.BitmapBrush in project WorldPainter by Captain-Chaos.

the class App method loadCustomBrushes.

private void loadCustomBrushes(String category, File brushesDir) {
    File[] files = brushesDir.listFiles(new java.io.FileFilter() {

        @Override
        public boolean accept(File pathname) {
            if (pathname.isDirectory()) {
                return true;
            }
            String name = pathname.getName();
            for (String extension : extensions) {
                if (name.toLowerCase().endsWith(extension)) {
                    return true;
                }
            }
            return false;
        }

        private final String[] extensions = ImageIO.getReaderFileSuffixes();
    });
    List<Brush> brushes = new ArrayList<>();
    for (File file : files) {
        if (file.isDirectory()) {
            loadCustomBrushes(file.getName(), file);
        } else {
            try {
                brushes.add(new BitmapBrush(file));
            } catch (RuntimeException e) {
                logger.error("There was an error loading custom brush image file " + file.getName() + "; skipping file", e);
            }
        }
    }
    if (!brushes.isEmpty()) {
        customBrushes.put(category, brushes);
    }
}
Also used : BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) java.io(java.io) Brush(org.pepsoft.worldpainter.brushes.Brush) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush)

Aggregations

java.io (java.io)1 BitmapBrush (org.pepsoft.worldpainter.brushes.BitmapBrush)1 Brush (org.pepsoft.worldpainter.brushes.Brush)1 RotatedBrush (org.pepsoft.worldpainter.brushes.RotatedBrush)1 SymmetricBrush (org.pepsoft.worldpainter.brushes.SymmetricBrush)1