diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java | 10 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractListLayout.java | 196 |
2 files changed, 206 insertions, 0 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index e8af424935..ef84d69085 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -332,6 +332,8 @@ public abstract class AbstractCommunicationManager implements private int maxInactiveInterval; + private boolean paintPhase; + private static int nextUnusedWindowSuffix = 1; /** @@ -857,6 +859,8 @@ public abstract class AbstractCommunicationManager implements Window window, boolean analyzeLayouts) throws PaintException, IOException { + paintPhase = true; + if (repaintAll) { makeAllPaintablesDirty(window); } @@ -911,6 +915,8 @@ public abstract class AbstractCommunicationManager implements outWriter.close(); + paintPhase = false; + } public void writeUidlResponce(Callback callback, boolean repaintAll, @@ -1970,6 +1976,10 @@ public abstract class AbstractCommunicationManager implements * @see com.vaadin.terminal.Paintable.RepaintRequestListener#repaintRequested(com.vaadin.terminal.Paintable.RepaintRequestEvent) */ public void repaintRequested(RepaintRequestEvent event) { + if (paintPhase) { + throw new IllegalStateException( + "Paintables shouldn't become dirty in paint phase!!"); + } final Paintable p = event.getPaintable(); if (!dirtyPaintables.contains(p)) { dirtyPaintables.add(p); diff --git a/src/com/vaadin/ui/AbstractListLayout.java b/src/com/vaadin/ui/AbstractListLayout.java new file mode 100644 index 0000000000..0b8759b1f6 --- /dev/null +++ b/src/com/vaadin/ui/AbstractListLayout.java @@ -0,0 +1,196 @@ +/* +@ITMillApache2LicenseForJavaFiles@ + */ +package com.vaadin.ui; + +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import com.vaadin.terminal.PaintException; +import com.vaadin.terminal.PaintTarget; + +/** + * Super class for layout implementations whose children have an order. Backs + * child components in a List. + * + * TODO {@link AbstractOrderedLayout} should extend this class + */ +public abstract class AbstractListLayout extends AbstractLayout { + + /** + * + * @deprecated this field should not be used directly by sub classses, use + * {@link #getComponents()} instead. + */ + @Deprecated + protected LinkedList<Component> components = new LinkedList<Component>(); + + /** + * Add a component into this container. The component is added to the right + * or under the previous component. + * + * @param c + * the component to be added. + */ + @Override + public void addComponent(Component c) { + components.add(c); + try { + super.addComponent(c); + requestRepaint(); + } catch (IllegalArgumentException e) { + components.remove(c); + throw e; + } + } + + /** + * Adds a component into this container. The component is added to the left + * or on top of the other components. + * + * @param c + * the component to be added. + */ + public void addComponentAsFirst(Component c) { + components.addFirst(c); + try { + super.addComponent(c); + requestRepaint(); + } catch (IllegalArgumentException e) { + components.remove(c); + throw e; + } + } + + /** + * Adds a component into indexed position in this container. + * + * @param c + * the component to be added. + * @param index + * the Index of the component position. The components currently + * in and after the position are shifted forwards. + */ + public void addComponent(Component c, int index) { + components.add(index, c); + try { + super.addComponent(c); + requestRepaint(); + } catch (IllegalArgumentException e) { + components.remove(c); + throw e; + } + } + + /** + * Removes the component from this container. + * + * @param c + * the component to be removed. + */ + @Override + public void removeComponent(Component c) { + components.remove(c); + super.removeComponent(c); + requestRepaint(); + } + + /** + * Gets the component container iterator for going trough all the components + * in the container. + * + * @return the Iterator of the components inside the container. + */ + public Iterator<Component> getComponentIterator() { + return components.iterator(); + } + + /** + * Gets the number of contained components. Consistent with the iterator + * returned by {@link #getComponentIterator()}. + * + * @return the number of contained components + */ + public int getComponentCount() { + return components.size(); + } + + /** + * Paints the content of this component. + * + * @param target + * the Paint Event. + * @throws PaintException + * if the paint operation failed. + */ + @Override + public void paintContent(PaintTarget target) throws PaintException { + super.paintContent(target); + paintComponents(target); + } + + protected void paintComponents(PaintTarget target) throws PaintException { + for (Component c : getComponents()) { + paintComponent(target, c); + } + } + + /** + * Gets the list of components used by this layout. + * + * @return the list of components used by this layout + */ + protected List<Component> getComponents() { + return Collections.unmodifiableList(components); + } + + protected void paintComponent(PaintTarget target, Component component) + throws PaintException { + component.paint(target); + } + + /* Documented in superclass */ + public void replaceComponent(Component oldComponent, Component newComponent) { + + // Gets the locations + int oldLocation = -1; + int newLocation = -1; + int location = 0; + for (final Iterator<Component> i = components.iterator(); i.hasNext();) { + final Component component = i.next(); + + if (component == oldComponent) { + oldLocation = location; + } + if (component == newComponent) { + newLocation = location; + } + + location++; + } + + if (oldLocation == -1) { + addComponent(newComponent); + } else if (newLocation == -1) { + removeComponent(oldComponent); + addComponent(newComponent, oldLocation); + } else { + if (oldLocation > newLocation) { + components.remove(oldComponent); + components.add(newLocation, oldComponent); + components.remove(newComponent); + components.add(oldLocation, newComponent); + } else { + components.remove(newComponent); + components.add(oldLocation, newComponent); + components.remove(oldComponent); + components.add(newLocation, oldComponent); + } + + requestRepaint(); + } + } + +} |