下面列出了怎么用java.util.TooManyListenersException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
*
*/
protected void installDropTargetHandler()
{
DropTarget dropTarget = graphComponent.getDropTarget();
try
{
if (dropTarget != null)
{
dropTarget.addDropTargetListener(this);
currentDropTarget = dropTarget;
}
}
catch (TooManyListenersException e)
{
// should not happen... swing drop target is multicast
log.log(Level.SEVERE, "Failed to install drop target handler", e);
}
}
public TraceTabbedPane(TracerViewerSetting tracerViewerSetting, RecentFileContainer recentFileContainer) {
super();
this.tracerViewerSetting = tracerViewerSetting;
this.recentFileContainer = recentFileContainer;
fileTabIndexMap = new LinkedHashMap<String, Integer>();
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
normalBorder = getBorder();
try {
DropTarget dt = new DropTarget();
dt.addDropTargetListener(this);
setDropTarget(dt);
} catch (TooManyListenersException e) {
LOG.error("Error adding drag drop listener", e);
}
}
public void openSerial(String serialPortName, int speed) throws PortInUseException, IOException, UnsupportedCommOperationException, TooManyListenersException {
CommPortIdentifier commPortIdentifier = findPort(serialPortName);
// initalize serial port
serialPort = (SerialPort) commPortIdentifier.open("Arduino", 2000);
inputStream = serialPort.getInputStream();
serialPort.addEventListener(this);
// activate the DATA_AVAILABLE notifier
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
}
/** Activates or deactivates Drag support on asociated JTree
* component
* @param active true if the support should be active, false
* otherwise
*/
public void activate(boolean active) {
if (this.active == active) {
return;
}
this.active = active;
DragGestureRecognizer dgr = getDefaultGestureRecognizer();
if (dgr == null) {
return;
}
if (active) {
dgr.setSourceActions(getAllowedDragActions());
try {
dgr.removeDragGestureListener(this);
dgr.addDragGestureListener(this);
} catch (TooManyListenersException exc) {
throw new IllegalStateException("Too many listeners for drag gesture."); // NOI18N
}
} else {
dgr.removeDragGestureListener(this);
}
}
protected void installDnD() {
tabFrame.setTransferHandler(TRANSFER_HANDLER);
try {
DropTarget dropTarget = tabFrame.getDropTarget();
if (dropTarget != null) {
dropTarget.addDropTargetListener(TRANSFER_HANDLER);
dropTarget.setActive(tabFrame.isDndEnabled());
}
} catch (TooManyListenersException e) {
e.printStackTrace();
}
}
/**
* Constructs a new ruler for the specified graph and orientation.
*
* @param graph
* The graph to create the ruler for.
* @param orientation
* The orientation to use for the ruler.
*/
public EditorRuler(mxGraphComponent graphComponent, int orientation)
{
this.orientation = orientation;
this.graphComponent = graphComponent;
updateIncrementAndUnits();
graphComponent.getGraph().getView().addListener(
mxEvent.SCALE, repaintHandler);
graphComponent.getGraph().getView().addListener(
mxEvent.TRANSLATE, repaintHandler);
graphComponent.getGraph().getView().addListener(
mxEvent.SCALE_AND_TRANSLATE, repaintHandler);
graphComponent.getGraphControl().addMouseMotionListener(this);
DropTarget dropTarget = graphComponent.getDropTarget();
try
{
if (dropTarget != null)
{
dropTarget.addDropTargetListener(this);
}
}
catch (TooManyListenersException tmle)
{
// should not happen... swing drop target is multicast
}
setBorder(BorderFactory.createLineBorder(Color.black));
}
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
/**
* Adds a new <code>DropTargetListener</code> (UNICAST SOURCE).
* <P>
* @param dtl The new <code>DropTargetListener</code>
* <P>
* @throws TooManyListenersException if a
* <code>DropTargetListener</code> is already added to this
* <code>DropTarget</code>.
*/
public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
if (dtl == null) return;
if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener");
if (dtListener == null)
dtListener = dtl;
else
throw new TooManyListenersException();
}
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
if (cbcsrl != null && !cbcsrl.equals(bcsrl))
throw new TooManyListenersException();
requestors.put(requestor, bcsrl);
}
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
public void addTestListener(TestListener listener) throws TooManyListenersException {
if (listener != null) {
if (this.listener != null) {
throw new TooManyListenersException();
}
this.listener = listener;
}
}
public void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
// Since the super class only supports one DropTargetListener,
// and we add one from the constructor, we always add to the
// extended list.
if (listenerList == null) {
listenerList = new EventListenerList();
}
listenerList.add(DropTargetListener.class, dtl);
}
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
if (cbcsrl != null && !cbcsrl.equals(bcsrl))
throw new TooManyListenersException();
requestors.put(requestor, bcsrl);
}
public void register(final String key, final TimerListener listener) throws TooManyListenersException {
if(!listeners.containsKey(key)) {
listeners.put(key, listener);
} else {
final StringBuilder buffer = new StringBuilder();
buffer.append("There is already a listener registered for a key with the name ").append(key);
throw new TooManyListenersException(buffer.toString());
}
}
public void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
// Since the super class only supports one DropTargetListener,
// and we add one from the constructor, we always add to the
// extended list.
if (listenerList == null) {
listenerList = new EventListenerList();
}
listenerList.add(DropTargetListener.class, dtl);
}
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
private void makeDropTarget(final Component c)
{
final DropTarget dt = new DropTarget();
try
{
dt.addDropTargetListener( dropListener );
}
catch(TooManyListenersException e )
{
logger.error("Do you have another listener attached ?",e);
}
c.addHierarchyListener( ( HierarchyEvent evt )->{
Component parent = c.getParent();
if( parent == null )
c.setDropTarget( null );
else
new DropTarget(c, dropListener);
});
if( c.getParent() != null )
new DropTarget(c, dropListener);
if( c instanceof Container )
{
Container cont = (Container) c;
for(Component cp : cont.getComponents())
makeDropTarget(cp );
}
}
/**
* Creates a new DropTarget given the <code>Component</code>
* to associate itself with, an <code>int</code> representing
* the default acceptable action(s) to
* support, a <code>DropTargetListener</code>
* to handle event processing, a <code>boolean</code> indicating
* if the <code>DropTarget</code> is currently accepting drops, and
* a <code>FlavorMap</code> to use (or null for the default <CODE>FlavorMap</CODE>).
* <P>
* The Component will receive drops only if it is enabled.
* @param c The <code>Component</code> with which this <code>DropTarget</code> is associated
* @param ops The default acceptable actions for this <code>DropTarget</code>
* @param dtl The <code>DropTargetListener</code> for this <code>DropTarget</code>
* @param act Is the <code>DropTarget</code> accepting drops.
* @param fm The <code>FlavorMap</code> to use, or null for the default <CODE>FlavorMap</CODE>
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public DropTarget(Component c, int ops, DropTargetListener dtl,
boolean act, FlavorMap fm)
throws HeadlessException
{
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
component = c;
setDefaultActions(ops);
if (dtl != null) try {
addDropTargetListener(dtl);
} catch (TooManyListenersException tmle) {
// do nothing!
}
if (c != null) {
c.setDropTarget(this);
setActive(act);
}
if (fm != null) {
flavorMap = fm;
} else {
flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
}
SwingDropTarget(Component c) {
super(c, COPY_OR_MOVE | LINK, null);
try {
// addDropTargetListener is overridden
// we specifically need to add to the superclass
super.addDropTargetListener(getDropTargetListener());
} catch (TooManyListenersException tmle) {}
}
public void addTestListener(TestListener listener) throws TooManyListenersException {
if (listener != null) {
if (this.listener != null) {
throw new TooManyListenersException();
}
this.listener = listener;
}
}
public void addTestListener(TestListener listener) throws TooManyListenersException {
if (listener != null) {
if (this.listener != null) {
throw new TooManyListenersException();
}
this.listener = listener;
}
}
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
if (cbcsrl != null && !cbcsrl.equals(bcsrl))
throw new TooManyListenersException();
requestors.put(requestor, bcsrl);
}
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = requestors.get(requestor);
if (cbcsrl != null && !cbcsrl.equals(bcsrl))
throw new TooManyListenersException();
requestors.put(requestor, bcsrl);
}
void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
if (cbcsrl != null && !cbcsrl.equals(bcsrl))
throw new TooManyListenersException();
requestors.put(requestor, bcsrl);
}
public void addTestListener(TestListener listener) throws TooManyListenersException {
if (listener != null) {
if (this.listener != null) {
throw new TooManyListenersException();
}
this.listener = listener;
}
}
SwingDropTarget(Component c) {
super(c, COPY_OR_MOVE | LINK, null);
try {
// addDropTargetListener is overridden
// we specifically need to add to the superclass
super.addDropTargetListener(getDropTargetListener());
} catch (TooManyListenersException tmle) {}
}
public void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
// Since the super class only supports one DropTargetListener,
// and we add one from the constructor, we always add to the
// extended list.
if (listenerList == null) {
listenerList = new EventListenerList();
}
listenerList.add(DropTargetListener.class, dtl);
}
SwingDropTarget(Component c) {
super(c, COPY_OR_MOVE | LINK, null);
try {
// addDropTargetListener is overridden
// we specifically need to add to the superclass
super.addDropTargetListener(getDropTargetListener());
} catch (TooManyListenersException tmle) {}
}
public SerialRXTXComm(CommPortIdentifier portIdentifier, Layer3Base layer3) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, TooManyListenersException{
if (portIdentifier.isCurrentlyOwned()) {
throw new IOException("Port is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(),
TIME_OUT);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
inStream = serialPort.getInputStream();
outStream = serialPort.getOutputStream();
new SerialReceiver().start();
/*serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true);*/
} else {
throw new IOException("This is not a serial port!.");
}
}
this.layer2 = new Layer2Serial(this, layer3);
}
/**
* Adds a new <code>DropTargetListener</code> (UNICAST SOURCE).
* <P>
* @param dtl The new <code>DropTargetListener</code>
* <P>
* @throws TooManyListenersException if a
* <code>DropTargetListener</code> is already added to this
* <code>DropTarget</code>.
*/
public synchronized void addDropTargetListener(DropTargetListener dtl) throws TooManyListenersException {
if (dtl == null) return;
if (equals(dtl)) throw new IllegalArgumentException("DropTarget may not be its own Listener");
if (dtListener == null)
dtListener = dtl;
else
throw new TooManyListenersException();
}