001/* [{ 002Copyright 2007-2011 Nicolas Carranza <nicarran at gmail.com> 003 004This file is part of jpen. 005 006jpen is free software: you can redistribute it and/or modify 007it under the terms of the GNU Lesser General Public License as published by 008the Free Software Foundation, either version 3 of the License, 009or (at your option) any later version. 010 011jpen is distributed in the hope that it will be useful, 012but WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014GNU Lesser General Public License for more details. 015 016You should have received a copy of the GNU Lesser General Public License 017along with jpen. If not, see <http://www.gnu.org/licenses/>. 018}] */ 019package jpen.owner.awt; 020 021import java.awt.Component; 022import java.awt.Dialog; 023import java.awt.event.MouseAdapter; 024import java.awt.event.MouseEvent; 025import java.awt.event.MouseListener; 026import java.awt.event.MouseMotionListener; 027import java.awt.KeyboardFocusManager; 028import java.awt.Window; 029import java.beans.PropertyChangeEvent; 030import java.beans.PropertyChangeListener; 031import java.util.Arrays; 032import java.util.Collection; 033import javax.swing.SwingUtilities; 034import jpen.owner.AbstractPenOwner; 035import jpen.owner.PenClip; 036import jpen.PenProvider; 037import jpen.internal.ActiveWindowProperty; 038 039public final class AwtPenOwner 040 extends ComponentPenOwner{ 041 042 public final Component component; 043 private final MouseListener mouseListener=new MouseAdapter(){ 044 @Override 045 public void mouseExited(MouseEvent ev) { 046 synchronized(getPenSchedulerLock(ev.getComponent())){ 047 if(!startDraggingOut()) 048 pause(); 049 } 050 } 051 052 @Override 053 public void mouseEntered(MouseEvent ev) { 054 synchronized(getPenSchedulerLock(ev.getComponent())){ 055 if(!stopDraggingOut()){ 056 unpauser.enable(); // unpauses when mouse motion is detected. 057 } 058 } 059 } 060 }; 061 062 /** 063 <b>Warning:</b> the Mac OS X provider doesn't work when creating multiple {@code AwtPenOwner}s. If you need to use JPen on multiple AWT components use {@link jpen.owner.multiAwt.AwtPenToolkit} instead. 064 */ 065 public AwtPenOwner(Component component){ 066 this.component=component; 067 } 068 069 @Override 070 public Component getActiveComponent(){ 071 return component; 072 } 073 074 @Override 075 protected void init(){ 076 component.addMouseListener(mouseListener); 077 } 078}