use of org.pepsoft.worldpainter.App 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);
}
Aggregations