001/* [{ 002Copyright 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.multiAwt; 020 021import java.awt.Component; 022import jpen.event.PenListener; 023import jpen.owner.multiAwt.MultiAwtPenOwner; 024import jpen.PenEvent; 025import jpen.PenManager; 026 027/** 028Contains a {@link PenManager} ready to be used on multiple Java AWT components. 029*/ 030public final class AwtPenToolkit{ 031 private static final MultiAwtPenOwner multiAwtPenOwner=new MultiAwtPenOwner(); 032 private static final PenManager penManager=new PenManager(multiAwtPenOwner); 033 034 private AwtPenToolkit(){} 035 036 public static final PenManager getPenManager(){ 037 return penManager; 038 } 039 040 public static void addPenListener(Component component, PenListener penListener){ 041 multiAwtPenOwner.componentPool.addPenListener(component, penListener); 042 } 043 044 public static void removePenListener(Component component, PenListener penListener){ 045 multiAwtPenOwner.componentPool.removePenListener(component, penListener); 046 } 047 048 public static Component getPenEventComponent(PenEvent ev){ 049 Object penOwnerTag= multiAwtPenOwner.getPenManagerHandle().retrievePenEventTag(ev); 050 if(penOwnerTag instanceof MultiAwtPenOwner.ActiveComponentInfo){ 051 MultiAwtPenOwner.ActiveComponentInfo activeComponentInfo=(MultiAwtPenOwner.ActiveComponentInfo)penOwnerTag; 052 return activeComponentInfo.getComponent(); 053 } 054 throw new IllegalArgumentException("the given PenEvent was not tagged by the MultiAwtPenOwner"); 055 } 056}