-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.ui;
@Override
public void addComponent(Component c) {
components.add(c);
- super.addComponent(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/*
@Override
public void removeComponent(Component c) {
components.remove(c);
+ componentToCoordinates.remove(c);
super.removeComponent(c);
requestRepaint();
}
* layout.
*/
public ComponentPosition getPosition(Component component) {
- if (componentToCoordinates.containsKey(component)) {
+ if (component.getParent() != this) {
+ return null;
+ } else if (componentToCoordinates.containsKey(component)) {
return componentToCoordinates.get(component);
} else {
ComponentPosition coords = new ComponentPosition();
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
*/
@Override
public void addComponent(Component c) {
- super.addComponent(c);
components.add(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
* the component to be added.
*/
public void addComponentAsFirst(Component c) {
- super.addComponent(c);
components.addFirst(c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
* in and after the position are shifted forwards.
*/
public void addComponent(Component c, int index) {
- super.addComponent(c);
components.add(index, c);
- requestRepaint();
+ try {
+ super.addComponent(c);
+ requestRepaint();
+ } catch (IllegalArgumentException e) {
+ components.remove(c);
+ throw e;
+ }
}
/**
*/
@Override
public void removeComponent(Component c) {
- super.removeComponent(c);
components.remove(c);
componentToAlignment.remove(c);
componentToExpandRatio.remove(c);
+ super.removeComponent(c);
requestRepaint();
}
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
// Checks that newItem does not overlap with existing items
checkExistingOverlaps(area);
- // first attemt to add to super
- super.addComponent(component);
-
// Inserts the component to right place at the list
// Respect top-down, left-right ordering
// component.setParent(this);
components.addLast(component);
}
+ // Attempt to add to super
+ try {
+ super.addComponent(component);
+ } catch (IllegalArgumentException e) {
+ areas.remove(area);
+ components.remove(component);
+ throw e;
+ }
+
// update cursor position, if it's within this area; use first position
// outside this area, even if it's occupied
if (cursorX >= column1 && cursorX <= column2 && cursorY >= row1
return;
}
- super.removeComponent(component);
-
Area area = null;
for (final Iterator i = areas.iterator(); area == null && i.hasNext();) {
final Area a = (Area) i.next();
componentToAlignment.remove(component);
+ super.removeComponent(component);
+
requestRepaint();
}