Search in sources :

Example 1 with Paint

use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.

the class App method createBiomesPanel.

private JPanel createBiomesPanel() {
    final JPanel biomesPanel = new JPanel();
    biomesPanel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(1, 1, 1, 1);
    Configuration config = Configuration.getInstance();
    constraints.anchor = GridBagConstraints.FIRST_LINE_START;
    constraints.weightx = 0.0;
    biomesCheckBox = new JCheckBox("Show:");
    biomesCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
    biomesCheckBox.setToolTipText("Uncheck to hide biomes from view (it will still be exported)");
    biomesCheckBox.addActionListener(e -> {
        if (biomesCheckBox.isSelected()) {
            hiddenLayers.remove(Biome.INSTANCE);
        } else {
            hiddenLayers.add(Biome.INSTANCE);
        }
        updateLayerVisibility();
    });
    if (!config.isEasyMode()) {
        constraints.gridwidth = 1;
        constraints.weightx = 0.0;
        biomesPanel.add(biomesCheckBox, constraints);
    }
    biomesSoloCheckBox = new JCheckBox("Solo:");
    biomesSoloCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
    biomesSoloCheckBox.setToolTipText("<html>Check to show <em>only</em> the biomes (the other layers are still exported)</html>");
    biomesSoloCheckBox.addActionListener(e -> {
        if (biomesSoloCheckBox.isSelected()) {
            layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != biomesSoloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
            soloLayer = Biome.INSTANCE;
        } else {
            soloLayer = null;
        }
        updateLayerVisibility();
    });
    layerSoloCheckBoxes.put(Biome.INSTANCE, biomesSoloCheckBox);
    if (!config.isEasyMode()) {
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        biomesPanel.add(biomesSoloCheckBox, constraints);
    }
    biomesPanel.add(new BiomesPanel(defaultColourScheme, customBiomeManager, biomeId -> {
        paintUpdater = () -> {
            paint = PaintFactory.createDiscreteLayerPaint(Biome.INSTANCE, biomeId);
            paintChanged();
        };
        paintUpdater.updatePaint();
    }, paintButtonGroup), constraints);
    return biomesPanel;
}
Also used : RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) GZIPInputStream(java.util.zip.GZIPInputStream) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) UI_SCALE(org.pepsoft.util.GUIUtils.UI_SCALE) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) Paint(org.pepsoft.worldpainter.painting.Paint) DockableFrame(com.jidesoft.docking.DockableFrame) org.pepsoft.worldpainter.painting(org.pepsoft.worldpainter.painting) SET_SPAWN_POINT(org.pepsoft.worldpainter.Platform.Capability.SET_SPAWN_POINT) BiomeSchemeManager(org.pepsoft.worldpainter.biomeschemes.BiomeSchemeManager) Timer(javax.swing.Timer) Void(java.lang.Void) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) InfoPanel(org.pepsoft.worldpainter.panels.InfoPanel) KeyEvent(java.awt.event.KeyEvent) AffineTransform(java.awt.geom.AffineTransform) Box(javax.swing.Box) InvocationTargetException(java.lang.reflect.InvocationTargetException) Direction(org.pepsoft.minecraft.Direction) org.pepsoft.worldpainter.operations(org.pepsoft.worldpainter.operations) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) EmptyBorder(javax.swing.border.EmptyBorder) GZIPOutputStream(java.util.zip.GZIPOutputStream) CustomItemsTreeModel(org.pepsoft.worldpainter.importing.CustomItemsTreeModel) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) java.util(java.util) SimpleDateFormat(java.text.SimpleDateFormat) DOCK_SIDE_WEST(com.jidesoft.docking.DockContext.DOCK_SIDE_WEST) BrushOptions(org.pepsoft.worldpainter.panels.BrushOptions) AffineTransformOp(java.awt.image.AffineTransformOp) MapImportDialog(org.pepsoft.worldpainter.importing.MapImportDialog) com.jidesoft.docking(com.jidesoft.docking) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BetterAction(org.pepsoft.worldpainter.util.BetterAction) ScriptRunner(org.pepsoft.worldpainter.tools.scripts.ScriptRunner) BevelBorder(javax.swing.border.BevelBorder) FileFilter(javax.swing.filechooser.FileFilter) CustomLayerProvider(org.pepsoft.worldpainter.plugins.CustomLayerProvider) java.awt(java.awt) RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) LayoutUtils(org.pepsoft.worldpainter.util.LayoutUtils) WPPluginManager(org.pepsoft.worldpainter.plugins.WPPluginManager) RespawnPlayerDialog(org.pepsoft.worldpainter.tools.RespawnPlayerDialog) URL(java.net.URL) EventVO(org.pepsoft.worldpainter.vo.EventVO) PropertyVetoException(java.beans.PropertyVetoException) TiledImageViewerContainer(org.pepsoft.util.swing.TiledImageViewerContainer) FLUIDS_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.FLUIDS_AS_LAYER) CustomBiomeListener(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager.CustomBiomeListener) PlatformManager(org.pepsoft.worldpainter.plugins.PlatformManager) Material(org.pepsoft.minecraft.Material) BackupUtil(org.pepsoft.worldpainter.util.BackupUtil) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) ImageIO(javax.imageio.ImageIO) WorldHistoryDialog(org.pepsoft.worldpainter.history.WorldHistoryDialog) BufferedImage(java.awt.image.BufferedImage) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) Collectors(java.util.stream.Collectors) JideLabel(com.jidesoft.swing.JideLabel) ProgressTask(org.pepsoft.util.swing.ProgressTask) List(java.util.List) Constants(org.pepsoft.minecraft.Constants) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) org.pepsoft.worldpainter.selection(org.pepsoft.worldpainter.selection) java.awt.event(java.awt.event) BIOMES(org.pepsoft.worldpainter.Platform.Capability.BIOMES) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) org.pepsoft.util(org.pepsoft.util) NonNls(org.jetbrains.annotations.NonNls) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) BufferedImageOp(java.awt.image.BufferedImageOp) ThreeDeeFrame(org.pepsoft.worldpainter.threedeeview.ThreeDeeFrame) MessageFormat(java.text.MessageFormat) VoidRenderer(org.pepsoft.worldpainter.layers.renderers.VoidRenderer) UndoManager(org.pepsoft.util.undo.UndoManager) UsageVO(org.pepsoft.worldpainter.vo.UsageVO) PropertyChangeEvent(java.beans.PropertyChangeEvent) Constants(org.pepsoft.worldpainter.Constants) TERRAIN_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.TERRAIN_AS_LAYER) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) AttributeKeyVO(org.pepsoft.worldpainter.vo.AttributeKeyVO) MalformedURLException(java.net.MalformedURLException) BiomesViewerFrame(org.pepsoft.worldpainter.tools.BiomesViewerFrame) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) JOptionPane(javax.swing.JOptionPane) Terrain(org.pepsoft.worldpainter.Terrain) DOCK_SIDE_EAST(com.jidesoft.docking.DockContext.DOCK_SIDE_EAST) URLEncoder(java.net.URLEncoder) java.io(java.io) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) WritableRaster(java.awt.image.WritableRaster) ImportMaskDialog(org.pepsoft.worldpainter.importing.ImportMaskDialog) ImportCustomItemsDialog(org.pepsoft.worldpainter.importing.ImportCustomItemsDialog) javax.swing(javax.swing)

Example 2 with Paint

use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.

the class App method createLayerButton.

private List<Component> createLayerButton(final Layer layer, char mnemonic, boolean createSoloCheckbox, boolean createButton) {
    boolean readOnlyOperation = layer.equals(ReadOnly.INSTANCE);
    List<Component> components = new ArrayList<>(3);
    final JCheckBox checkBox = new JCheckBox();
    if (readOnlyOperation) {
        readOnlyCheckBox = checkBox;
    }
    checkBox.setToolTipText(strings.getString("whether.or.not.to.display.this.layer"));
    checkBox.setSelected(true);
    checkBox.addChangeListener(e -> {
        if (checkBox.isSelected()) {
            hiddenLayers.remove(layer);
        } else {
            hiddenLayers.add(layer);
        }
        updateLayerVisibility();
    });
    components.add(checkBox);
    if (createSoloCheckbox) {
        final JCheckBox soloCheckBox = new JCheckBox();
        if (readOnlyOperation) {
            readOnlySoloCheckBox = soloCheckBox;
        }
        layerSoloCheckBoxes.put(layer, soloCheckBox);
        soloCheckBox.setToolTipText("<html>Check to show <em>only</em> this layer (the other layers are still exported)</html>");
        soloCheckBox.addChangeListener(e -> {
            if (soloCheckBox.isSelected()) {
                layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != soloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
                soloLayer = layer;
            } else {
                soloLayer = null;
            }
            updateLayerVisibility();
        });
        components.add(soloCheckBox);
    } else {
        components.add(Box.createGlue());
    }
    if (createButton) {
        final JToggleButton button = new JToggleButton();
        if (readOnlyOperation) {
            readOnlyToggleButton = button;
        }
        button.setMargin(new Insets(2, 2, 2, 2));
        if (layer.getIcon() != null) {
            button.setIcon(new ImageIcon(layer.getIcon()));
        }
        button.setToolTipText(layer.getName() + ": " + layer.getDescription());
        // TODO: make this work again, but with Ctrl + Alt or something
        // if (mnemonic != 0) {
        // button.setMnemonic(mnemonic);
        // }
        button.addItemListener(event -> {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                paintUpdater = () -> {
                    paint = PaintFactory.createLayerPaint(layer);
                    paintChanged();
                };
                paintUpdater.updatePaint();
            }
        });
        paintButtonGroup.add(button);
        button.setText(layer.getName());
        button.putClientProperty(HELP_KEY_KEY, "Layer/" + layer.getId());
        components.add(button);
    } else {
        JLabel label = new JLabel(layer.getName(), new ImageIcon(layer.getIcon()), JLabel.LEADING);
        label.putClientProperty(HELP_KEY_KEY, "Layer/" + layer.getId());
        components.add(label);
    }
    return components;
}
Also used : RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) GZIPInputStream(java.util.zip.GZIPInputStream) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) UI_SCALE(org.pepsoft.util.GUIUtils.UI_SCALE) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) Paint(org.pepsoft.worldpainter.painting.Paint) DockableFrame(com.jidesoft.docking.DockableFrame) org.pepsoft.worldpainter.painting(org.pepsoft.worldpainter.painting) SET_SPAWN_POINT(org.pepsoft.worldpainter.Platform.Capability.SET_SPAWN_POINT) BiomeSchemeManager(org.pepsoft.worldpainter.biomeschemes.BiomeSchemeManager) Timer(javax.swing.Timer) Void(java.lang.Void) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) InfoPanel(org.pepsoft.worldpainter.panels.InfoPanel) KeyEvent(java.awt.event.KeyEvent) AffineTransform(java.awt.geom.AffineTransform) Box(javax.swing.Box) InvocationTargetException(java.lang.reflect.InvocationTargetException) Direction(org.pepsoft.minecraft.Direction) org.pepsoft.worldpainter.operations(org.pepsoft.worldpainter.operations) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) EmptyBorder(javax.swing.border.EmptyBorder) GZIPOutputStream(java.util.zip.GZIPOutputStream) CustomItemsTreeModel(org.pepsoft.worldpainter.importing.CustomItemsTreeModel) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) java.util(java.util) SimpleDateFormat(java.text.SimpleDateFormat) DOCK_SIDE_WEST(com.jidesoft.docking.DockContext.DOCK_SIDE_WEST) BrushOptions(org.pepsoft.worldpainter.panels.BrushOptions) AffineTransformOp(java.awt.image.AffineTransformOp) MapImportDialog(org.pepsoft.worldpainter.importing.MapImportDialog) com.jidesoft.docking(com.jidesoft.docking) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BetterAction(org.pepsoft.worldpainter.util.BetterAction) ScriptRunner(org.pepsoft.worldpainter.tools.scripts.ScriptRunner) BevelBorder(javax.swing.border.BevelBorder) FileFilter(javax.swing.filechooser.FileFilter) CustomLayerProvider(org.pepsoft.worldpainter.plugins.CustomLayerProvider) java.awt(java.awt) RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) LayoutUtils(org.pepsoft.worldpainter.util.LayoutUtils) WPPluginManager(org.pepsoft.worldpainter.plugins.WPPluginManager) RespawnPlayerDialog(org.pepsoft.worldpainter.tools.RespawnPlayerDialog) URL(java.net.URL) EventVO(org.pepsoft.worldpainter.vo.EventVO) PropertyVetoException(java.beans.PropertyVetoException) TiledImageViewerContainer(org.pepsoft.util.swing.TiledImageViewerContainer) FLUIDS_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.FLUIDS_AS_LAYER) CustomBiomeListener(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager.CustomBiomeListener) PlatformManager(org.pepsoft.worldpainter.plugins.PlatformManager) Material(org.pepsoft.minecraft.Material) BackupUtil(org.pepsoft.worldpainter.util.BackupUtil) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) ImageIO(javax.imageio.ImageIO) WorldHistoryDialog(org.pepsoft.worldpainter.history.WorldHistoryDialog) BufferedImage(java.awt.image.BufferedImage) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) Collectors(java.util.stream.Collectors) JideLabel(com.jidesoft.swing.JideLabel) ProgressTask(org.pepsoft.util.swing.ProgressTask) List(java.util.List) Constants(org.pepsoft.minecraft.Constants) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) org.pepsoft.worldpainter.selection(org.pepsoft.worldpainter.selection) java.awt.event(java.awt.event) BIOMES(org.pepsoft.worldpainter.Platform.Capability.BIOMES) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) org.pepsoft.util(org.pepsoft.util) NonNls(org.jetbrains.annotations.NonNls) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) BufferedImageOp(java.awt.image.BufferedImageOp) ThreeDeeFrame(org.pepsoft.worldpainter.threedeeview.ThreeDeeFrame) MessageFormat(java.text.MessageFormat) VoidRenderer(org.pepsoft.worldpainter.layers.renderers.VoidRenderer) UndoManager(org.pepsoft.util.undo.UndoManager) UsageVO(org.pepsoft.worldpainter.vo.UsageVO) PropertyChangeEvent(java.beans.PropertyChangeEvent) Constants(org.pepsoft.worldpainter.Constants) TERRAIN_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.TERRAIN_AS_LAYER) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) AttributeKeyVO(org.pepsoft.worldpainter.vo.AttributeKeyVO) MalformedURLException(java.net.MalformedURLException) BiomesViewerFrame(org.pepsoft.worldpainter.tools.BiomesViewerFrame) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) JOptionPane(javax.swing.JOptionPane) Terrain(org.pepsoft.worldpainter.Terrain) DOCK_SIDE_EAST(com.jidesoft.docking.DockContext.DOCK_SIDE_EAST) URLEncoder(java.net.URLEncoder) java.io(java.io) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) WritableRaster(java.awt.image.WritableRaster) ImportMaskDialog(org.pepsoft.worldpainter.importing.ImportMaskDialog) ImportCustomItemsDialog(org.pepsoft.worldpainter.importing.ImportCustomItemsDialog) javax.swing(javax.swing)

Example 3 with Paint

use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.

the class App method updateStatusBar.

public void updateStatusBar(int x, int y) {
    setTextIfDifferent(locationLabel, MessageFormat.format(strings.getString("location.0.1"), x, y));
    if (dimension == null) {
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        setTextIfDifferent(materialLabel, " ");
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    Tile tile = dimension.getTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS);
    if (tile == null) {
        // Not on a tile
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(slopeLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        if (dimension.isBorderTile(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS)) {
            setTextIfDifferent(materialLabel, "Border");
        } else {
            setTextIfDifferent(materialLabel, "Minecraft Generated");
        }
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    final int xInTile = x & TILE_SIZE_MASK, yInTile = y & TILE_SIZE_MASK;
    if (tile.getBitLayerValue(NotPresent.INSTANCE, xInTile, yInTile)) {
        // Marked as not present
        setTextIfDifferent(heightLabel, " ");
        setTextIfDifferent(slopeLabel, " ");
        setTextIfDifferent(waterLabel, " ");
        setTextIfDifferent(materialLabel, "Minecraft Generated");
        setTextIfDifferent(biomeLabel, " ");
        return;
    }
    int height = tile.getIntHeight(xInTile, yInTile);
    setTextIfDifferent(heightLabel, MessageFormat.format(strings.getString("height.0.of.1"), height, dimension.getMaxHeight() - 1));
    setTextIfDifferent(slopeLabel, MessageFormat.format("Slope: {0}°", (int) (Math.atan(dimension.getSlope(x, y)) * 180 / Math.PI + 0.5)));
    if ((activeOperation instanceof PaintOperation) && (paint instanceof LayerPaint)) {
        Layer layer = ((LayerPaint) paint).getLayer();
        switch(layer.getDataSize()) {
            case BIT:
            case BIT_PER_CHUNK:
                setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.on.off"), layer.getName(), (tile.getBitLayerValue(layer, xInTile, yInTile) ? 1 : 0)));
                break;
            case NIBBLE:
                int value, strength;
                if (!layer.equals(Annotations.INSTANCE)) {
                    value = tile.getLayerValue(layer, xInTile, yInTile);
                    strength = (value > 0) ? ((value - 1) * 100 / 14 + 1) : 0;
                    if ((strength == 51) || (strength == 101)) {
                        strength--;
                    }
                    setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
                } else {
                    setTextIfDifferent(waterLabel, " ");
                }
                break;
            case BYTE:
                if (!layer.equals(Biome.INSTANCE)) {
                    value = tile.getLayerValue(layer, xInTile, yInTile);
                    strength = (value > 0) ? ((value - 1) * 100 / 254 + 1) : 0;
                    setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("layer.0.level.1"), layer.getName(), strength));
                } else {
                    setTextIfDifferent(waterLabel, " ");
                }
                break;
            default:
                // Do nothing
                break;
        }
    } else if (activeOperation instanceof GardenOfEdenOperation) {
        setTextIfDifferent(waterLabel, strings.getString("structure") + ": " + GardenCategory.getLabel(strings, tile.getLayerValue(GardenCategory.INSTANCE, xInTile, yInTile)));
    } else {
        int waterLevel = tile.getWaterLevel(xInTile, yInTile);
        if (waterLevel > height) {
            setTextIfDifferent(waterLabel, MessageFormat.format(strings.getString("fluid.level.1.depth.2"), tile.getBitLayerValue(FloodWithLava.INSTANCE, xInTile, yInTile) ? 1 : 0, waterLevel, waterLevel - height));
        } else {
            setTextIfDifferent(waterLabel, " ");
        }
    }
    Terrain terrain = tile.getTerrain(xInTile, yInTile);
    if (terrain.isCustom()) {
        int index = terrain.getCustomTerrainIndex();
        setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.custom.1.0"), getCustomMaterial(index), index + 1));
    } else {
        setTextIfDifferent(materialLabel, MessageFormat.format(strings.getString("material.0"), terrain.getName()));
    }
    // with biomeNames being null, causing a NPE. How is this possible?
    if (dimension.getDim() == 0) {
        int biome = tile.getLayerValue(Biome.INSTANCE, xInTile, yInTile);
        // TODO: is this too slow?
        if (biome == 255) {
            biome = dimension.getAutoBiome(x, y);
            if (biome != -1) {
                if (biomeNames[biome] == null) {
                    setTextIfDifferent(biomeLabel, "Auto biome: biome " + biome);
                } else {
                    setTextIfDifferent(biomeLabel, "Auto biome: " + biomeNames[biome]);
                }
            }
        } else if (biome != -1) {
            if (biomeNames[biome] == null) {
                setTextIfDifferent(biomeLabel, MessageFormat.format(strings.getString("biome.0"), biome));
            } else {
                setTextIfDifferent(biomeLabel, MessageFormat.format(strings.getString("biome.0"), biomeNames[biome]));
            }
        }
    } else {
        setTextIfDifferent(biomeLabel, strings.getString("biome-"));
    }
}
Also used : Terrain(org.pepsoft.worldpainter.Terrain) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 4 with Paint

use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.

the class App method createAnnotationsPanel.

private JPanel createAnnotationsPanel() {
    final JPanel layerPanel = new JPanel();
    layerPanel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(1, 1, 1, 1);
    Configuration config = Configuration.getInstance();
    constraints.anchor = GridBagConstraints.FIRST_LINE_START;
    constraints.weightx = 0.0;
    annotationsCheckBox = new JCheckBox("Show:");
    annotationsCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
    annotationsCheckBox.setSelected(true);
    annotationsCheckBox.setToolTipText("Uncheck to hide annotations from view");
    annotationsCheckBox.addActionListener(e -> {
        if (annotationsCheckBox.isSelected()) {
            hiddenLayers.remove(Annotations.INSTANCE);
        } else {
            hiddenLayers.add(Annotations.INSTANCE);
        }
        updateLayerVisibility();
    });
    if (!config.isEasyMode()) {
        constraints.gridwidth = 1;
        constraints.weightx = 0.0;
        layerPanel.add(annotationsCheckBox, constraints);
    }
    annotationsSoloCheckBox = new JCheckBox("Solo:");
    annotationsSoloCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
    annotationsSoloCheckBox.setToolTipText("<html>Check to show <em>only</em> the annotations (the other layers are still exported)</html>");
    annotationsSoloCheckBox.addActionListener(e -> {
        if (annotationsSoloCheckBox.isSelected()) {
            layerSoloCheckBoxes.values().stream().filter(otherSoloCheckBox -> otherSoloCheckBox != annotationsSoloCheckBox).forEach(otherSoloCheckBox -> otherSoloCheckBox.setSelected(false));
            soloLayer = Annotations.INSTANCE;
        } else {
            soloLayer = null;
        }
        updateLayerVisibility();
    });
    layerSoloCheckBoxes.put(Annotations.INSTANCE, annotationsSoloCheckBox);
    if (!config.isEasyMode()) {
        constraints.gridwidth = GridBagConstraints.REMAINDER;
        layerPanel.add(annotationsSoloCheckBox, constraints);
    }
    JPanel colourGrid = new JPanel(new GridLayout(0, 4));
    for (int i = 1; i < 16; i++) {
        final int selectedColour = i, dataValue = i - ((i < 8) ? 1 : 0);
        JToggleButton button = new JToggleButton(IconUtils.createScaledColourIcon(defaultColourScheme.getColour(BLK_WOOL, dataValue)));
        button.setToolTipText(COLOUR_NAMES[dataValue]);
        button.setMargin(App.BUTTON_INSETS);
        if (i == 1) {
            button.setSelected(true);
        }
        paintButtonGroup.add(button);
        button.addActionListener(e -> {
            paintUpdater = () -> {
                paint = PaintFactory.createDiscreteLayerPaint(Annotations.INSTANCE, selectedColour);
                paintChanged();
            };
            paintUpdater.updatePaint();
        });
        colourGrid.add(button);
    }
    layerPanel.add(colourGrid, constraints);
    return layerPanel;
}
Also used : RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) GZIPInputStream(java.util.zip.GZIPInputStream) CustomBiome(org.pepsoft.worldpainter.biomeschemes.CustomBiome) UI_SCALE(org.pepsoft.util.GUIUtils.UI_SCALE) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) TunnelLayerDialog(org.pepsoft.worldpainter.layers.tunnel.TunnelLayerDialog) TunnelLayer(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer) Paint(org.pepsoft.worldpainter.painting.Paint) DockableFrame(com.jidesoft.docking.DockableFrame) org.pepsoft.worldpainter.painting(org.pepsoft.worldpainter.painting) SET_SPAWN_POINT(org.pepsoft.worldpainter.Platform.Capability.SET_SPAWN_POINT) BiomeSchemeManager(org.pepsoft.worldpainter.biomeschemes.BiomeSchemeManager) Timer(javax.swing.Timer) Void(java.lang.Void) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) InfoPanel(org.pepsoft.worldpainter.panels.InfoPanel) KeyEvent(java.awt.event.KeyEvent) AffineTransform(java.awt.geom.AffineTransform) Box(javax.swing.Box) InvocationTargetException(java.lang.reflect.InvocationTargetException) Direction(org.pepsoft.minecraft.Direction) org.pepsoft.worldpainter.operations(org.pepsoft.worldpainter.operations) Brush(org.pepsoft.worldpainter.brushes.Brush) PropertyChangeListener(java.beans.PropertyChangeListener) SymmetricBrush(org.pepsoft.worldpainter.brushes.SymmetricBrush) EmptyBorder(javax.swing.border.EmptyBorder) GZIPOutputStream(java.util.zip.GZIPOutputStream) CustomItemsTreeModel(org.pepsoft.worldpainter.importing.CustomItemsTreeModel) GardenOfEdenOperation(org.pepsoft.worldpainter.gardenofeden.GardenOfEdenOperation) java.util(java.util) SimpleDateFormat(java.text.SimpleDateFormat) DOCK_SIDE_WEST(com.jidesoft.docking.DockContext.DOCK_SIDE_WEST) BrushOptions(org.pepsoft.worldpainter.panels.BrushOptions) AffineTransformOp(java.awt.image.AffineTransformOp) MapImportDialog(org.pepsoft.worldpainter.importing.MapImportDialog) com.jidesoft.docking(com.jidesoft.docking) RotatedBrush(org.pepsoft.worldpainter.brushes.RotatedBrush) BetterAction(org.pepsoft.worldpainter.util.BetterAction) ScriptRunner(org.pepsoft.worldpainter.tools.scripts.ScriptRunner) BevelBorder(javax.swing.border.BevelBorder) FileFilter(javax.swing.filechooser.FileFilter) CustomLayerProvider(org.pepsoft.worldpainter.plugins.CustomLayerProvider) java.awt(java.awt) RemoteJCheckBox(org.pepsoft.util.swing.RemoteJCheckBox) LayoutUtils(org.pepsoft.worldpainter.util.LayoutUtils) WPPluginManager(org.pepsoft.worldpainter.plugins.WPPluginManager) RespawnPlayerDialog(org.pepsoft.worldpainter.tools.RespawnPlayerDialog) URL(java.net.URL) EventVO(org.pepsoft.worldpainter.vo.EventVO) PropertyVetoException(java.beans.PropertyVetoException) TiledImageViewerContainer(org.pepsoft.util.swing.TiledImageViewerContainer) FLUIDS_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.FLUIDS_AS_LAYER) CustomBiomeListener(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager.CustomBiomeListener) PlatformManager(org.pepsoft.worldpainter.plugins.PlatformManager) Material(org.pepsoft.minecraft.Material) BackupUtil(org.pepsoft.worldpainter.util.BackupUtil) BitmapBrush(org.pepsoft.worldpainter.brushes.BitmapBrush) UndergroundPocketsDialog(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsDialog) ImageIO(javax.imageio.ImageIO) WorldHistoryDialog(org.pepsoft.worldpainter.history.WorldHistoryDialog) BufferedImage(java.awt.image.BufferedImage) DynMapColourScheme(org.pepsoft.worldpainter.colourschemes.DynMapColourScheme) Collectors(java.util.stream.Collectors) JideLabel(com.jidesoft.swing.JideLabel) ProgressTask(org.pepsoft.util.swing.ProgressTask) List(java.util.List) Constants(org.pepsoft.minecraft.Constants) UndergroundPocketsLayer(org.pepsoft.worldpainter.layers.pockets.UndergroundPocketsLayer) org.pepsoft.worldpainter.selection(org.pepsoft.worldpainter.selection) java.awt.event(java.awt.event) BIOMES(org.pepsoft.worldpainter.Platform.Capability.BIOMES) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) org.pepsoft.util(org.pepsoft.util) NonNls(org.jetbrains.annotations.NonNls) org.pepsoft.worldpainter.layers(org.pepsoft.worldpainter.layers) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) BufferedImageOp(java.awt.image.BufferedImageOp) ThreeDeeFrame(org.pepsoft.worldpainter.threedeeview.ThreeDeeFrame) MessageFormat(java.text.MessageFormat) VoidRenderer(org.pepsoft.worldpainter.layers.renderers.VoidRenderer) UndoManager(org.pepsoft.util.undo.UndoManager) UsageVO(org.pepsoft.worldpainter.vo.UsageVO) PropertyChangeEvent(java.beans.PropertyChangeEvent) Constants(org.pepsoft.worldpainter.Constants) TERRAIN_AS_LAYER(org.pepsoft.worldpainter.TileRenderer.TERRAIN_AS_LAYER) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) AttributeKeyVO(org.pepsoft.worldpainter.vo.AttributeKeyVO) MalformedURLException(java.net.MalformedURLException) BiomesViewerFrame(org.pepsoft.worldpainter.tools.BiomesViewerFrame) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) HistoryEntry(org.pepsoft.worldpainter.history.HistoryEntry) JOptionPane(javax.swing.JOptionPane) Terrain(org.pepsoft.worldpainter.Terrain) DOCK_SIDE_EAST(com.jidesoft.docking.DockContext.DOCK_SIDE_EAST) URLEncoder(java.net.URLEncoder) java.io(java.io) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) WritableRaster(java.awt.image.WritableRaster) ImportMaskDialog(org.pepsoft.worldpainter.importing.ImportMaskDialog) ImportCustomItemsDialog(org.pepsoft.worldpainter.importing.ImportCustomItemsDialog) javax.swing(javax.swing) Paint(org.pepsoft.worldpainter.painting.Paint)

Example 5 with Paint

use of org.pepsoft.worldpainter.painting.Paint in project WorldPainter by Captain-Chaos.

the class App method showCustomTerrainButtonPopup.

public void showCustomTerrainButtonPopup(final AWTEvent event, final int customMaterialIndex) {
    final JToggleButton button = (customMaterialIndex >= 0) ? customMaterialButtons[customMaterialIndex] : null;
    JPopupMenu popupMenu = new JPopupMenu();
    final MixedMaterial material = (customMaterialIndex >= 0) ? getCustomMaterial(customMaterialIndex) : null;
    // JLabel label = new JLabel(MessageFormat.format(strings.getString("current.material.0"), (material != null) ? material : "none"));
    // popupMenu.add(label);
    JMenuItem menuItem;
    if (button == null) {
        menuItem = new JMenuItem(strings.getString("select.custom.material") + "...");
        menuItem.addActionListener(e -> {
            MixedMaterial newMaterial = MixedMaterial.create(BLK_DIRT);
            CustomMaterialDialog dialog = new CustomMaterialDialog(App.this, newMaterial, world.isExtendedBlockIds(), selectedColourScheme);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
                newMaterial = MixedMaterialManager.getInstance().register(newMaterial);
                int index = findNextCustomTerrainIndex();
                addButtonForNewCustomTerrain(index, newMaterial, true);
            }
        });
        popupMenu.add(menuItem);
    }
    MixedMaterial[] customMaterials = MixedMaterialManager.getInstance().getMaterials();
    if (customMaterials.length > 0) {
        JMenu existingMaterialsMenu = new JMenu("Select existing material");
        Set<MixedMaterial> customTerrainMaterials = new HashSet<>();
        for (int i = 0; i < CUSTOM_TERRAIN_COUNT; i++) {
            if (getCustomTerrain(i).isConfigured()) {
                customTerrainMaterials.add(getCustomMaterial(i));
            }
        }
        for (final MixedMaterial customMaterial : customMaterials) {
            if (customTerrainMaterials.contains(customMaterial)) {
                continue;
            }
            menuItem = new JMenuItem(customMaterial.getName());
            menuItem.setIcon(new ImageIcon(customMaterial.getIcon(selectedColourScheme)));
            menuItem.addActionListener(e -> {
                if (button != null) {
                    setCustomMaterial(customMaterialIndex, customMaterial);
                    button.setIcon(new ImageIcon(customMaterial.getIcon(selectedColourScheme)));
                    button.setToolTipText(MessageFormat.format(strings.getString("customMaterial.0.right.click.to.change"), customMaterial));
                    view.refreshTiles();
                } else {
                    addButtonForNewCustomTerrain(findNextCustomTerrainIndex(), customMaterial, true);
                }
            });
            existingMaterialsMenu.add(menuItem);
        }
        if (existingMaterialsMenu.getMenuComponentCount() > 0) {
            popupMenu.add(existingMaterialsMenu);
        }
    }
    if (button != null) {
        menuItem = new JMenuItem(((material != null) ? "Edit custom material" : strings.getString("select.custom.material")) + "...");
        menuItem.addActionListener(e -> {
            if (editCustomMaterial(customMaterialIndex)) {
                button.setSelected(true);
                paintUpdater = () -> {
                    paint = PaintFactory.createTerrainPaint(getCustomTerrain(customMaterialIndex));
                    paintChanged();
                };
                paintUpdater.updatePaint();
            }
        });
        popupMenu.add(menuItem);
    }
    menuItem = new JMenuItem("Import from file...");
    menuItem.addActionListener(e -> {
        if (button != null) {
            if (importCustomMaterial(customMaterialIndex)) {
                button.setSelected(true);
                paintUpdater = () -> {
                    paint = PaintFactory.createTerrainPaint(getCustomTerrain(customMaterialIndex));
                    paintChanged();
                };
                paintUpdater.updatePaint();
            }
        } else {
            MixedMaterial customMaterial = MixedMaterialHelper.load(this);
            if (customMaterial != null) {
                addButtonForNewCustomTerrain(findNextCustomTerrainIndex(), customMaterial, true);
            }
        }
    });
    popupMenu.add(menuItem);
    menuItem = new JMenuItem("Import from another world...");
    menuItem.addActionListener(e -> importCustomItemsFromWorld(CustomItemsTreeModel.ItemType.TERRAIN));
    popupMenu.add(menuItem);
    if (button != null) {
        if (material != null) {
            menuItem = new JMenuItem("Export to file...");
            menuItem.addActionListener(e -> exportCustomMaterial(customMaterialIndex));
            popupMenu.add(menuItem);
        }
        popupMenu.show(button, button.getWidth(), 0);
    } else {
        Component invoker = (Component) event.getSource();
        popupMenu.show(invoker, invoker.getWidth(), 0);
    }
}
Also used : Paint(org.pepsoft.worldpainter.painting.Paint)

Aggregations

Paint (org.pepsoft.worldpainter.painting.Paint)4 com.jidesoft.docking (com.jidesoft.docking)3 DOCK_SIDE_EAST (com.jidesoft.docking.DockContext.DOCK_SIDE_EAST)3 DOCK_SIDE_WEST (com.jidesoft.docking.DockContext.DOCK_SIDE_WEST)3 DockableFrame (com.jidesoft.docking.DockableFrame)3 JideLabel (com.jidesoft.swing.JideLabel)3 java.awt (java.awt)3 java.awt.event (java.awt.event)3 KeyEvent (java.awt.event.KeyEvent)3 AffineTransform (java.awt.geom.AffineTransform)3 AffineTransformOp (java.awt.image.AffineTransformOp)3 BufferedImage (java.awt.image.BufferedImage)3 BufferedImageOp (java.awt.image.BufferedImageOp)3 WritableRaster (java.awt.image.WritableRaster)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3 PropertyVetoException (java.beans.PropertyVetoException)3 java.io (java.io)3 Void (java.lang.Void)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3