Search in sources :

Example 6 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class CustomLayersTableModel method swap.

/**
 * Swap two layers.
 *
 * @param rowIndex1 The index of the first layer.
 * @param rowIndex2 The index of the second layer.
 */
public void swap(int rowIndex1, int rowIndex2) {
    if (isHeaderRow(rowIndex1) || isHeaderRow(rowIndex2)) {
        throw new IllegalStateException("Cannot swap with header rows");
    }
    CustomLayer layer = customLayers.get(rowIndex1);
    customLayers.set(rowIndex1, customLayers.get(rowIndex2));
    customLayers.set(rowIndex2, layer);
    orderPristine = false;
    TableModelEvent event = new TableModelEvent(this, Math.min(rowIndex1, rowIndex2), Math.max(rowIndex1, rowIndex2));
    for (TableModelListener listener : listeners) {
        listener.tableChanged(event);
    }
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener)

Example 7 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class TunnelLayerDialog method setControlStates.

private void setControlStates() {
    spinnerFloorMin.setEnabled(!radioButtonFloorFixedLevel.isSelected());
    spinnerFloorMax.setEnabled(!radioButtonFloorFixedLevel.isSelected());
    spinnerRoofMin.setEnabled(!radioButtonRoofFixedLevel.isSelected());
    spinnerRoofMax.setEnabled(!radioButtonRoofFixedLevel.isSelected());
    spinnerFloodLevel.setEnabled(checkBoxFlood.isSelected());
    checkBoxFloodWithLava.setEnabled(checkBoxFlood.isSelected());
    int selectedFloorRow = tableFloorLayers.getSelectedRow();
    if (selectedFloorRow != -1) {
        buttonRemoveFloorLayer.setEnabled(tableFloorLayers.getSelectedRowCount() > 0);
        Layer selectedLayer = floorLayersTableModel.getLayer(selectedFloorRow);
        buttonEditFloorLayer.setEnabled(selectedLayer instanceof CustomLayer);
    } else {
        buttonRemoveFloorLayer.setEnabled(false);
        buttonEditFloorLayer.setEnabled(false);
    }
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Layer(org.pepsoft.worldpainter.layers.Layer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)

Example 8 with CustomLayer

use of org.pepsoft.worldpainter.layers.CustomLayer in project WorldPainter by Captain-Chaos.

the class TunnelLayerDialog method addFloorLayer.

private void addFloorLayer() {
    JPopupMenu popupMenu = new JPopupMenu();
    LayerManager.getInstance().getLayers().stream().filter(l -> l.getExporter() instanceof IncidentalLayerExporter).forEach(l -> {
        JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
        menuItem.addActionListener(e -> floorLayersTableModel.addLayer(l));
        popupMenu.add(menuItem);
    });
    App app = App.getInstance();
    Set<CustomLayer> customLayers = app.getCustomLayers().stream().filter(l -> l.getExporter() instanceof IncidentalLayerExporter).collect(Collectors.toSet());
    if (customLayers.size() > 15) {
        // If there are fifteen or more custom layers, split them by palette
        // and move them to separate submenus to try and conserve screen
        // space
        app.getCustomLayersByPalette().entrySet().stream().map((entry) -> {
            String palette = entry.getKey();
            JMenu paletteMenu = new JMenu(palette != null ? palette : "Hidden Layers");
            entry.getValue().stream().filter(l -> l.getExporter() instanceof IncidentalLayerExporter).forEach(l -> {
                JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
                menuItem.addActionListener(e -> floorLayersTableModel.addLayer(l));
                paletteMenu.add(menuItem);
            });
            return paletteMenu;
        }).filter((paletteMenu) -> (paletteMenu.getItemCount() > 0)).forEach((paletteMenu) -> {
            popupMenu.add(paletteMenu);
        });
    } else {
        customLayers.forEach(l -> {
            JMenuItem menuItem = new JMenuItem(l.getName(), new ImageIcon(l.getIcon()));
            menuItem.addActionListener(e -> floorLayersTableModel.addLayer(l));
            popupMenu.add(menuItem);
        });
    }
    popupMenu.show(buttonAddFloorLayer, buttonAddFloorLayer.getWidth(), 0);
}
Also used : App(org.pepsoft.worldpainter.App) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) LayerTableCellRenderer(org.pepsoft.worldpainter.layers.LayerTableCellRenderer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Map(java.util.Map) ChangeListener(javax.swing.event.ChangeListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) CustomLayerDialog(org.pepsoft.worldpainter.layers.CustomLayerDialog) ChangeEvent(javax.swing.event.ChangeEvent) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) MixedMaterialManager(org.pepsoft.worldpainter.MixedMaterialManager) BufferedImage(java.awt.image.BufferedImage) Set(java.util.Set) LayerManager(org.pepsoft.worldpainter.layers.LayerManager) IncidentalLayerExporter(org.pepsoft.worldpainter.exporting.IncidentalLayerExporter) Collectors(java.util.stream.Collectors) MixedMaterial(org.pepsoft.worldpainter.MixedMaterial) Layer(org.pepsoft.worldpainter.layers.Layer) java.awt(java.awt) NoiseSettings(org.pepsoft.worldpainter.NoiseSettings) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer) ColourScheme(org.pepsoft.worldpainter.ColourScheme) ListSelectionListener(javax.swing.event.ListSelectionListener) EditLayerDialog(org.pepsoft.worldpainter.layers.EditLayerDialog) Mode(org.pepsoft.worldpainter.layers.tunnel.TunnelLayer.Mode) javax.swing(javax.swing) App(org.pepsoft.worldpainter.App) IncidentalLayerExporter(org.pepsoft.worldpainter.exporting.IncidentalLayerExporter) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer)

Aggregations

CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)8 Layer (org.pepsoft.worldpainter.layers.Layer)5 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)3 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)3 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)3 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)2 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)2 EditLayerDialog (org.pepsoft.worldpainter.layers.EditLayerDialog)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 javax.swing (javax.swing)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1