X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2Finternal%2Fawt%2FRecursiveContainerListener.java;h=b799f0257b96f94a421488228032d09dabf30eca;hb=HEAD;hp=4e561f7cd7d2c9fed38889b161d261e95d98dc11;hpb=ac5f1da15cc639da880fea86a7b828c8fa2e1b7e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/RecursiveContainerListener.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/RecursiveContainerListener.java index 4e561f7cd..b799f0257 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/RecursiveContainerListener.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/internal/awt/RecursiveContainerListener.java @@ -1,101 +1,101 @@ -/******************************************************************************* - * Copyright (c) 2007 SAS Institute. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * SAS Institute - initial API and implementation - *******************************************************************************/ -package org.simantics.utils.ui.internal.awt; - -import java.awt.Component; -import java.awt.Container; -import java.awt.EventQueue; -import java.awt.event.ContainerEvent; -import java.awt.event.ContainerListener; - -class RecursiveContainerListener implements ContainerListener { - private final ContainerListener listener; - - RecursiveContainerListener(ContainerListener listener) { - assert listener != null; - - this.listener = listener; - } - - private void handleAdd(Container source, Component c) { - assert source != null; - assert c != null; - assert listener != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - // System.out.println("Listening to: " + c); - listener.componentAdded(new ContainerEvent(source, ContainerEvent.COMPONENT_ADDED, c)); - if (c instanceof Container) { - ((Container)c).addContainerListener(this); - } - } - - private void handleRemove(Container source, Component c) { - assert source != null; - assert c != null; - assert listener != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - // System.out.println("Stopped Listening to: " + c); - listener.componentRemoved(new ContainerEvent(source, ContainerEvent.COMPONENT_REMOVED, c)); - if (c instanceof Container) { - ((Container)c).removeContainerListener(this); - } - } - - private void handleAllAdds(Container source, Component child) { - assert source != null; - assert child != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - if (child instanceof Container) { - Container container = (Container)child; - Component[] children = container.getComponents(); - for (int i = 0; i < children.length; i++) { - handleAllAdds(container, children[i]); - } - } - handleAdd(source, child); - } - - private void handleAllRemoves(Container source, Component child) { - assert source != null; - assert child != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - if (child instanceof Container) { - Container container = (Container)child; - Component[] children = container.getComponents(); - for (int i = 0; i < children.length; i++) { - handleAllRemoves(container, children[i]); - } - } - handleRemove(source, child); - - } - - public void componentAdded(ContainerEvent e) { - assert e != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - Container source = (Container)e.getSource(); - handleAllAdds(source, e.getChild()); - } - - public void componentRemoved(ContainerEvent e) { - assert e != null; - assert EventQueue.isDispatchThread(); // On AWT event thread - - Container source = (Container)e.getSource(); - handleAllRemoves(source, e.getChild()); - } -} - +/******************************************************************************* + * Copyright (c) 2007 SAS Institute. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * SAS Institute - initial API and implementation + *******************************************************************************/ +package org.simantics.utils.ui.internal.awt; + +import java.awt.Component; +import java.awt.Container; +import java.awt.EventQueue; +import java.awt.event.ContainerEvent; +import java.awt.event.ContainerListener; + +class RecursiveContainerListener implements ContainerListener { + private final ContainerListener listener; + + RecursiveContainerListener(ContainerListener listener) { + assert listener != null; + + this.listener = listener; + } + + private void handleAdd(Container source, Component c) { + assert source != null; + assert c != null; + assert listener != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + // System.out.println("Listening to: " + c); + listener.componentAdded(new ContainerEvent(source, ContainerEvent.COMPONENT_ADDED, c)); + if (c instanceof Container) { + ((Container)c).addContainerListener(this); + } + } + + private void handleRemove(Container source, Component c) { + assert source != null; + assert c != null; + assert listener != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + // System.out.println("Stopped Listening to: " + c); + listener.componentRemoved(new ContainerEvent(source, ContainerEvent.COMPONENT_REMOVED, c)); + if (c instanceof Container) { + ((Container)c).removeContainerListener(this); + } + } + + private void handleAllAdds(Container source, Component child) { + assert source != null; + assert child != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + if (child instanceof Container) { + Container container = (Container)child; + Component[] children = container.getComponents(); + for (int i = 0; i < children.length; i++) { + handleAllAdds(container, children[i]); + } + } + handleAdd(source, child); + } + + private void handleAllRemoves(Container source, Component child) { + assert source != null; + assert child != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + if (child instanceof Container) { + Container container = (Container)child; + Component[] children = container.getComponents(); + for (int i = 0; i < children.length; i++) { + handleAllRemoves(container, children[i]); + } + } + handleRemove(source, child); + + } + + public void componentAdded(ContainerEvent e) { + assert e != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + Container source = (Container)e.getSource(); + handleAllAdds(source, e.getChild()); + } + + public void componentRemoved(ContainerEvent e) { + assert e != null; + assert EventQueue.isDispatchThread(); // On AWT event thread + + Container source = (Container)e.getSource(); + handleAllRemoves(source, e.getChild()); + } +} +