Search in sources :

Example 1 with LayerGroupProvider

use of blue.score.layers.LayerGroupProvider in project blue by kunstmusik.

the class ScoreManagerDialog method getAddLayerGroupMenu.

private JPopupMenu getAddLayerGroupMenu() {
    if (addLayerGroupMenu == null) {
        addLayerGroupMenu = new JPopupMenu();
        ActionListener listener = (ActionEvent e) -> {
            JMenuItem menuItem = (JMenuItem) e.getSource();
            LayerGroupProvider provider = (LayerGroupProvider) menuItem.getClientProperty("provider");
            LayerGroup layerGroup = provider.createLayerGroup();
            LayerGroupTableModel model = getLayerGroupListModel();
            int index = (layerGroupsTable.getSelectionModel().getMaxSelectionIndex());
            if (index < 0 || index > model.getRowCount()) {
                index = model.getRowCount();
                model.addLayerGroup(index, layerGroup);
            } else {
                model.addLayerGroup(index, layerGroup);
            }
            ListSelectionModel selection = layerGroupsTable.getSelectionModel();
            selection.setSelectionInterval(index, index);
        };
        LayerGroupProviderManager manager = LayerGroupProviderManager.getInstance();
        for (LayerGroupProvider provider : manager) {
            JMenuItem item = new JMenuItem("Add " + provider.getLayerGroupName() + " Layer Group");
            item.putClientProperty("provider", provider);
            item.addActionListener(listener);
            addLayerGroupMenu.add(item);
        }
    }
    return addLayerGroupMenu;
}
Also used : LayerGroupProvider(blue.score.layers.LayerGroupProvider) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) LayerGroup(blue.score.layers.LayerGroup) LayerGroupProviderManager(blue.score.layers.LayerGroupProviderManager)

Aggregations

LayerGroup (blue.score.layers.LayerGroup)1 LayerGroupProvider (blue.score.layers.LayerGroupProvider)1 LayerGroupProviderManager (blue.score.layers.LayerGroupProviderManager)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1