Search in sources :

Example 11 with ProgressReceiver

use of org.pepsoft.util.ProgressReceiver in project WorldPainter by Captain-Chaos.

the class CopySelectionOperation method tick.

@Override
protected void tick(int centreX, int centreY, boolean inverse, boolean first, float dynamicLevel) {
    selectionHelper.setOptions(options);
    Dimension dimension = getDimension();
    dimension.setEventsInhibited(true);
    try {
        // TODO: opening the progress dialog (and presumeably any dialog)
        // causes the JIDE docking framework to malfunction
        // ProgressDialog.executeTask(SwingUtilities.getWindowAncestor(getView()), new ProgressTask<Void>() {
        // @Override
        // public String getName() {
        // return "Copying selection";
        // }
        // 
        // @Override
        // public Void execute(ProgressReceiver progressReceiver) throws ProgressReceiver.OperationCancelled {
        selectionHelper.copySelection(centreX, centreY, null);
    // return null;
    // }
    // }, false);
    } catch (ProgressReceiver.OperationCancelled e) {
        throw new InternalError(e);
    } finally {
        dimension.setEventsInhibited(false);
    }
}
Also used : ProgressReceiver(org.pepsoft.util.ProgressReceiver) Dimension(org.pepsoft.worldpainter.Dimension)

Example 12 with ProgressReceiver

use of org.pepsoft.util.ProgressReceiver in project WorldPainter by Captain-Chaos.

the class ExportProgressDialog method getTask.

@Override
protected ProgressTask<Map<Integer, ChunkFactory.Stats>> getTask() {
    return new ProgressTask<Map<Integer, ChunkFactory.Stats>>() {

        @Override
        public String getName() {
            return "Exporting world " + name;
        }

        @Override
        public Map<Integer, ChunkFactory.Stats> execute(ProgressReceiver progressReceiver) throws OperationCancelled {
            progressReceiver = new TaskbarProgressReceiver(App.getInstance(), progressReceiver);
            progressReceiver.setMessage("Exporting world " + name);
            WorldExporter exporter = PlatformManager.getInstance().getExporter(world);
            try {
                backupDir = exporter.selectBackupDir(new File(baseDir, FileUtils.sanitiseName(name)));
                return exporter.export(baseDir, name, backupDir, progressReceiver);
            } catch (IOException e) {
                throw new RuntimeException("I/O error while exporting world", e);
            }
        }
    };
}
Also used : ProgressTask(org.pepsoft.util.swing.ProgressTask) TaskbarProgressReceiver(org.pepsoft.util.TaskbarProgressReceiver) ProgressReceiver(org.pepsoft.util.ProgressReceiver) WorldExporter(org.pepsoft.worldpainter.exporting.WorldExporter) IOException(java.io.IOException) TaskbarProgressReceiver(org.pepsoft.util.TaskbarProgressReceiver) File(java.io.File)

Example 13 with ProgressReceiver

use of org.pepsoft.util.ProgressReceiver in project WorldPainter by Captain-Chaos.

the class FillDialog method fillWithLayer.

private void fillWithLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxSetLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        int baseLayerValue = Math.round((sliderLayerValue.getValue() + 2) / 6.667f);
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    int layerValue;
                    if (filter == null) {
                        layerValue = baseLayerValue;
                    } else {
                        layerValue = (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * baseLayerValue);
                    }
                    if (tile.getLayerValue(layer, x, y) < layerValue) {
                        tile.setLayerValue(layer, x, y, layerValue);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x += 16) {
                for (int y = 0; y < TILE_SIZE; y += 16) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Example 14 with ProgressReceiver

use of org.pepsoft.util.ProgressReceiver in project WorldPainter by Captain-Chaos.

the class FillDialog method invertLayer.

private void invertLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxInvertLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setLayerValue(layer, x, y, 15 - tile.getLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x += 16) {
                for (int y = 0; y < TILE_SIZE; y += 16) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set) {
                        tile.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, progressReceiver);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Example 15 with ProgressReceiver

use of org.pepsoft.util.ProgressReceiver in project WorldPainter by Captain-Chaos.

the class ImportHeightMapDialog method getImportedWorld.

public World2 getImportedWorld() {
    if (currentDimension != null) {
        throw new IllegalStateException();
    }
    final HeightMapImporter importer = new HeightMapImporter();
    HeightMap heightMap = new BitmapHeightMap(selectedFile.getName(), image, 0, selectedFile, false, false);
    int scale = (Integer) spinnerScale.getValue();
    int offsetX = (Integer) spinnerOffsetX.getValue();
    int offsetY = (Integer) spinnerOffsetY.getValue();
    if ((scale != 100) || (offsetX != 0) || (offsetY != 0)) {
        ((BitmapHeightMap) heightMap).setSmoothScaling(true);
        heightMap = new TransformingHeightMap(heightMap.getName() + " transformed", heightMap, scale, scale, offsetX, offsetY, 0);
    }
    if (checkBoxInvert.isSelected()) {
        if (image.getSampleModel().getSampleSize(0) == 16) {
            heightMap = new DifferenceHeightMap(new ConstantHeightMap(65535f), heightMap);
        } else {
            heightMap = new DifferenceHeightMap(new ConstantHeightMap(255f), heightMap);
        }
    }
    importer.setHeightMap(heightMap);
    importer.setImageFile(selectedFile);
    String name = selectedFile.getName();
    int p = name.lastIndexOf('.');
    if (p != -1) {
        name = name.substring(0, p);
    }
    importer.setName(name);
    importer.setTileFactory(tileFactory);
    importer.setMaxHeight(Integer.parseInt((String) comboBoxHeight.getSelectedItem()));
    importer.setImageLowLevel((Integer) spinnerImageLow.getValue());
    importer.setImageHighLevel((Integer) spinnerImageHigh.getValue());
    importer.setWorldLowLevel((Integer) spinnerWorldLow.getValue());
    importer.setWorldWaterLevel((Integer) spinnerWorldMiddle.getValue());
    importer.setWorldHighLevel((Integer) spinnerWorldHigh.getValue());
    importer.setVoidBelowLevel(checkBoxVoid.isSelected() ? ((Integer) spinnerVoidBelow.getValue()) : 0);
    World2 world = ProgressDialog.executeTask(this, new ProgressTask<World2>() {

        @Override
        public String getName() {
            return "Importing height map";
        }

        @Override
        public World2 execute(ProgressReceiver progressReceiver) throws OperationCancelled {
            return importer.importToNewWorld(progressReceiver);
        }
    }, false);
    Configuration.getInstance().setHeightMapsDirectory(selectedFile.getParentFile());
    return world;
}
Also used : HeightMapImporter(org.pepsoft.worldpainter.importing.HeightMapImporter) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) ProgressReceiver(org.pepsoft.util.ProgressReceiver)

Aggregations

ProgressReceiver (org.pepsoft.util.ProgressReceiver)16 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)9 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)6 ProgressTask (org.pepsoft.util.swing.ProgressTask)6 Layer (org.pepsoft.worldpainter.layers.Layer)6 File (java.io.File)5 List (java.util.List)5 IOException (java.io.IOException)4 java.util (java.util)4 javax.swing (javax.swing)4 ProgressDialog (org.pepsoft.util.swing.ProgressDialog)4 java.awt (java.awt)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Set (java.util.Set)3 ExecutorService (java.util.concurrent.ExecutorService)3 Pattern (java.util.regex.Pattern)3 ParallelProgressManager (org.pepsoft.util.ParallelProgressManager)3 Dimension (org.pepsoft.worldpainter.Dimension)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2