Package org.bitbucket.woolmark.impl.swing

Source Code of org.bitbucket.woolmark.impl.swing.SheepJWindow$DragWindowListener

package org.bitbucket.woolmark.impl.swing;

import java.awt.Point;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

import org.bitbucket.woolmark.impl.awt.SheepCanvas;

public class SheepJWindow extends JWindow {

    private static final long serialVersionUID = -1218019336886248653L;

    private SheepCanvas canvas;

    public SheepJWindow(JFrame frame) {

        super(frame);

        canvas = new SheepCanvas();

        DragWindowListener dwl = new DragWindowListener();
        canvas.addMouseListener(dwl);
        canvas.addMouseMotionListener(dwl);

        add(canvas);
        pack();

    }

    private class DragWindowListener extends MouseAdapter {
        private MouseEvent start;
        private Window window;

        @Override
        public void mousePressed(MouseEvent me) {
            start = me;
        }

        @Override
        public void mouseDragged(MouseEvent me) {
            if (window == null) {
                window = SwingUtilities.windowForComponent(me.getComponent());
            }
            Point eventLocationOnScreen = me.getLocationOnScreen();
            window.setLocation(eventLocationOnScreen.x - start.getX(),
                    eventLocationOnScreen.y - start.getY());
        }
    }

}
TOP

Related Classes of org.bitbucket.woolmark.impl.swing.SheepJWindow$DragWindowListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.