Search in sources :

Example 1 with CardTransfertHandler

use of org.magic.game.transfert.CardTransfertHandler in project MtgDesktopCompanion by nicho92.

the class DisplayableCard method construct.

public void construct(MagicCard mc, Dimension d, boolean activateCards, boolean rightClick) {
    rightActions = rightClick;
    menu = new JPopupMenu();
    sep = new JSeparator();
    attachedCards = new ArrayList<>();
    obs = new Observable();
    counters = new ArrayList<>();
    setSize(d);
    setPreferredSize(d);
    setHorizontalAlignment(JLabel.CENTER);
    setVerticalAlignment(JLabel.CENTER);
    try {
        setMagicCard((MagicCard) BeanUtils.cloneBean(mc));
    } catch (Exception e1) {
        MTGLogger.printStackTrace(e1);
    }
    if (activateCards) {
        addMouseListener(new MouseAdapter() {

            @Override
            public void mouseEntered(MouseEvent e) {
                describe();
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e)) {
                    if (e.getClickCount() == 1 && e.isControlDown()) {
                        setSelected(!isSelected());
                        repaint();
                    }
                    if (e.getClickCount() == 2) {
                        if (isTappable())
                            tap(!isTapped());
                        return;
                    }
                }
            }
        });
        addMouseMotionListener(new MouseAdapter() {

            @Override
            public void mouseDragged(MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e) && isDraggable())
                    enableDrag(e);
            }
        });
    }
    initActions();
    setTransferHandler(new CardTransfertHandler());
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator) Observable(org.utils.patterns.observer.Observable) InvocationTargetException(java.lang.reflect.InvocationTargetException) CardTransfertHandler(org.magic.game.transfert.CardTransfertHandler)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JPopupMenu (javax.swing.JPopupMenu)1 JSeparator (javax.swing.JSeparator)1 CardTransfertHandler (org.magic.game.transfert.CardTransfertHandler)1 Observable (org.utils.patterns.observer.Observable)1