Search in sources :

Example 1 with EffectCategory

use of blue.ui.core.mixer.EffectCategory in project blue by kunstmusik.

the class EffectsPopup method populateMenu.

private void populateMenu(EffectCategory category, JMenu menu) {
    JMenu currentMenu = menu;
    ArrayList categories = category.getSubCategories();
    ArrayList effects = category.getEffects();
    for (int i = 0; i < categories.size(); i++) {
        EffectCategory cat = (EffectCategory) categories.get(i);
        JMenu catMenu = new JMenu(cat.getCategoryName());
        menu.add(catMenu);
        populateMenu(cat, catMenu);
    }
    int counter = 0;
    for (int i = 0; i < effects.size(); i++) {
        Effect effect = (Effect) effects.get(i);
        AddEffectAction action = new AddEffectAction(effect);
        if (counter < 10) {
            currentMenu.add(action);
            counter++;
        } else {
            JMenu tempMenu = new JMenu(BlueSystem.getString("menu.more"));
            currentMenu.add(tempMenu);
            currentMenu = tempMenu;
            currentMenu.add(action);
            counter = 1;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) EffectCategory(blue.ui.core.mixer.EffectCategory) JMenu(javax.swing.JMenu)

Example 2 with EffectCategory

use of blue.ui.core.mixer.EffectCategory in project blue by kunstmusik.

the class EffectTreeDropTarget method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    Object node = parentpath.getLastPathComponent();
    EffectsLibrary eLibrary = EffectsLibrary.getInstance();
    if (dtde.isDataFlavorSupported(TransferableEffect.EFFECT_CAT_FLAVOR)) {
        if (!(node instanceof EffectCategory)) {
            dtde.rejectDrop();
            return;
        }
        if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable tr = dtde.getTransferable();
            try {
                Object transferNode = tr.getTransferData(TransferableEffect.EFFECT_CAT_FLAVOR);
                EffectCategory effectCategory = (EffectCategory) transferNode;
                EffectCategory parentNode = (EffectCategory) node;
                eLibrary.addCategory(parentNode, effectCategory);
                dtde.dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                dtde.dropComplete(false);
            }
        } else {
            dtde.rejectDrop();
        }
    } else if (dtde.isDataFlavorSupported(TransferableEffect.EFFECT_FLAVOR)) {
        dtde.acceptDrop(dtde.getDropAction());
        try {
            Transferable tr = dtde.getTransferable();
            Object transferNode = tr.getTransferData(TransferableEffect.EFFECT_FLAVOR);
            Effect effect = (Effect) transferNode;
            effect.clearParameters();
            // iLibrary.removeInstrument(instrument);
            if (node instanceof EffectCategory) {
                EffectCategory parentNode = (EffectCategory) node;
                eLibrary.addEffect(parentNode, effect);
            } else if (node instanceof Effect) {
                EffectCategory parentNode = (EffectCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
                int index = ListUtil.indexOfByRef(parentNode.getEffects(), node);
                int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
                Rectangle bounds = tree.getRowBounds(closestRow);
                if (pt.y > bounds.y + bounds.height) {
                    eLibrary.addEffect(parentNode, effect);
                } else {
                    eLibrary.addEffect(parentNode, index, effect);
                }
            }
            dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
            dtde.dropComplete(false);
        }
    } else {
        dtde.rejectDrop();
    }
}
Also used : DropTargetContext(java.awt.dnd.DropTargetContext) Transferable(java.awt.datatransfer.Transferable) Rectangle(java.awt.Rectangle) Point(java.awt.Point) EffectCategory(blue.ui.core.mixer.EffectCategory) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) EffectsLibrary(blue.ui.core.mixer.EffectsLibrary)

Example 3 with EffectCategory

use of blue.ui.core.mixer.EffectCategory in project blue by kunstmusik.

the class EffectTreeDropTarget method dragEnter.

@Override
public void dragEnter(DropTargetDragEvent dtde) {
    if (!dtde.isDataFlavorSupported(TransferableEffect.EFFECT_FLAVOR) && !dtde.isDataFlavorSupported(TransferableEffect.EFFECT_CAT_FLAVOR)) {
        dtde.rejectDrag();
        return;
    }
    Point p = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath path = tree.getClosestPathForLocation(p.x, p.y);
    if (path.getLastPathComponent() instanceof EffectCategory) {
        dtde.acceptDrag(dtde.getDropAction());
    } else if (dtde.isDataFlavorSupported(TransferableEffect.EFFECT_FLAVOR)) {
        dtde.acceptDrag(dtde.getDropAction());
    } else {
        dtde.rejectDrag();
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) DropTargetContext(java.awt.dnd.DropTargetContext) Point(java.awt.Point) EffectCategory(blue.ui.core.mixer.EffectCategory)

Aggregations

EffectCategory (blue.ui.core.mixer.EffectCategory)3 Point (java.awt.Point)2 DropTargetContext (java.awt.dnd.DropTargetContext)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 EffectsLibrary (blue.ui.core.mixer.EffectsLibrary)1 Rectangle (java.awt.Rectangle)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 JMenu (javax.swing.JMenu)1