Search in sources :

Example 1 with IncidentalLayerExporter

use of org.pepsoft.worldpainter.exporting.IncidentalLayerExporter 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

java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)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 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 App (org.pepsoft.worldpainter.App)1 ColourScheme (org.pepsoft.worldpainter.ColourScheme)1 MixedMaterial (org.pepsoft.worldpainter.MixedMaterial)1 MixedMaterialManager (org.pepsoft.worldpainter.MixedMaterialManager)1 NoiseSettings (org.pepsoft.worldpainter.NoiseSettings)1 IncidentalLayerExporter (org.pepsoft.worldpainter.exporting.IncidentalLayerExporter)1 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)1 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)1 CustomLayerDialog (org.pepsoft.worldpainter.layers.CustomLayerDialog)1 EditLayerDialog (org.pepsoft.worldpainter.layers.EditLayerDialog)1