Set<Instance> adds = new HashSet<Instance>();
Set<Instance> removes = new HashSet<Instance>();
Map<Instance, Instance> replaces = new HashMap<Instance, Instance>();
for (Component comp : repl.getAdditions()) {
if (comp.getFactory() instanceof Pin) {
Instance in = Instance.getInstanceFor(comp);
boolean added = pins.add(in);
if (added) {
comp.addComponentListener(myComponentListener);
in.getAttributeSet().addAttributeListener(myComponentListener);
adds.add(in);
}
}
}
for (Component comp : repl.getRemovals()) {
if (comp.getFactory() instanceof Pin) {
Instance in = Instance.getInstanceFor(comp);
boolean removed = pins.remove(in);
if (removed) {
comp.removeComponentListener(myComponentListener);
in.getAttributeSet().removeAttributeListener(myComponentListener);
Collection<Component> rs = repl.getComponentsReplacing(comp);
if (rs.isEmpty()) {
removes.add(in);
} else {
Component r = rs.iterator().next();
Instance rin = Instance.getInstanceFor(r);
adds.remove(rin);
replaces.put(in, rin);
}
}
}