aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/CustomComponent.java
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2007-11-19 14:03:05 +0000
committerMarc Englund <marc.englund@itmill.com>2007-11-19 14:03:05 +0000
commitf2e3722df9676436680afc0f1991e91e1696fb99 (patch)
tree6f255ff78abaf96f1e71a1f2c9ecd3b66647f4a2 /src/com/itmill/toolkit/ui/CustomComponent.java
parent93291f532db9d545cf2a8dd98e2671f27cd197b0 (diff)
downloadvaadin-framework-f2e3722df9676436680afc0f1991e91e1696fb99.tar.gz
vaadin-framework-f2e3722df9676436680afc0f1991e91e1696fb99.zip
MASS REFORMAT.
According to http://toolkit.intra.itmill.com/trac/itmilltoolkit/wiki/CodingConventions svn changeset:2864/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/ui/CustomComponent.java')
-rw-r--r--src/com/itmill/toolkit/ui/CustomComponent.java915
1 files changed, 465 insertions, 450 deletions
diff --git a/src/com/itmill/toolkit/ui/CustomComponent.java b/src/com/itmill/toolkit/ui/CustomComponent.java
index 786fdae539..3f63ff4806 100644
--- a/src/com/itmill/toolkit/ui/CustomComponent.java
+++ b/src/com/itmill/toolkit/ui/CustomComponent.java
@@ -29,7 +29,6 @@
package com.itmill.toolkit.ui;
import java.util.Collection;
-import java.util.HashSet;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
@@ -57,454 +56,470 @@ import com.itmill.toolkit.terminal.VariableOwner;
*/
public class CustomComponent implements Component {
- /**
- * The root component implementing the custom component.
- */
- private Component root = null;
-
- /**
- * The visibility of the component.
- */
- private boolean visible = true;
-
- /**
- * The parent of the component.
- */
- private Component parent = null;
-
- /**
- * Type of the component.
- */
- private String componentType = null;
-
- /**
- * List of repaint request listeners or null if not listened at all.
- */
- private LinkedList repaintRequestListeners = null;
-
- /**
- * Are all the repaint listeners notified about recent changes ?
- */
- private boolean repaintRequestListenersNotified = false;
-
- /**
- * Constructs a new custom component.
- *
- * <p>
- * The component is implemented by wrapping the methods of the composition
- * root component given as parameter. The composition root must be set
- * before the component can be used.
- * </p>
- */
- public CustomComponent() {
- }
-
- /**
- * Constructs a new custom component.
- *
- * <p>
- * The component is implemented by wrapping the methods of the composition
- * root component given as parameter. The composition root must not be null
- * and can not be changed after the composition.
- * </p>
- *
- * @param compositionRoot
- * the root of the composition component tree.
- */
- public CustomComponent(Component compositionRoot) {
- setCompositionRoot(compositionRoot);
- }
-
- /**
- * Returns the composition root.
- *
- * @return the Component Composition root.
- */
- protected final Component getCompositionRoot() {
- return root;
- }
-
- /**
- * Sets the compositions root.
- * <p>
- * The composition root must be set to non-null value before the component
- * can be used. The composition root can only be set once.
- * </p>
- *
- * @param compositionRoot
- * the root of the composition component tree.
- */
- protected final void setCompositionRoot(Component compositionRoot) {
- if (compositionRoot != root && root != null)
- root.setParent(null);
- this.root = compositionRoot;
- if (root != null)
- root.setParent(this);
- }
-
- /* Basic component features ------------------------------------------ */
-
- /**
- * Notifies the component that it is connected to an application.
- *
- * @see com.itmill.toolkit.ui.Component#attach()
- */
- public void attach() {
- if (root != null) {
- root.attach();
- requestRepaint();
- }
- }
-
- /**
- * Notifies the component that it is detached from the application.
- *
- * @see com.itmill.toolkit.ui.Component#detach()
- */
- public void detach() {
- if (root != null)
- root.detach();
- }
-
- /**
- * Gets the component's parent application
- *
- * @see com.itmill.toolkit.ui.Component#getApplication()
- */
- public Application getApplication() {
- if (parent == null)
- return null;
- return parent.getApplication();
- }
-
- /**
- * The caption of the custom component is by default the caption of the root
- * component, or null if the root is not set.
- *
- * @see com.itmill.toolkit.ui.Component#getCaption()
- */
- public String getCaption() {
- if (root == null)
- return null;
- return root.getCaption();
- }
-
- /**
- * The icon of the custom component is by default the icon of the root
- * component, or null if the root is not set.
- *
- * @see com.itmill.toolkit.ui.Component#getIcon()
- */
- public Resource getIcon() {
- if (root == null)
- return null;
- return root.getIcon();
- }
-
- /**
- * The icon of the custom component is by default the locale of the parent
- * or null if the parent is not set.
- *
- * @see com.itmill.toolkit.ui.Component#getLocale()
- */
- public Locale getLocale() {
- if (parent == null)
- return null;
- return parent.getLocale();
- }
-
- /**
- * Gets the visual parent of the component.
- *
- * @see com.itmill.toolkit.ui.Component#getParent()
- */
- public Component getParent() {
- return parent;
- }
-
- /**
- * Custom component does not implement custom styles by default and this
- * function returns null.
- *
- * @see com.itmill.toolkit.ui.Component#getStyle()
- */
- public String getStyleName() {
- return null;
- }
-
- /**
- * Gets the component's parent window.
- *
- * @see com.itmill.toolkit.ui.Component#getWindow()
- */
- public Window getWindow() {
- if (parent == null)
- return null;
- return parent.getWindow();
- }
-
- /**
- * Custom component is always enabled by default.
- *
- * @see com.itmill.toolkit.ui.Component#isEnabled()
- */
- public boolean isEnabled() {
- return true;
- }
-
- /**
- * Custom component is by default in the non-immediate mode. The
- * immediateness of the custom component is defined by the components it is
- * composed of.
- *
- * @see com.itmill.toolkit.terminal.VariableOwner#isImmediate()
- */
- public boolean isImmediate() {
- return false;
- }
-
- /**
- * The custom components are not readonly by default.
- *
- * @see com.itmill.toolkit.ui.Component#isReadOnly()
- */
- public boolean isReadOnly() {
- return false;
- }
-
- /**
- * Tests if the component is visible or not.
- *
- * @see com.itmill.toolkit.ui.Component#isVisible()
- */
- public boolean isVisible() {
- return visible;
- }
-
- /* Documentation copied from interface */
- public void requestRepaint() {
-
- // The effect of the repaint request is identical to case where a
- // child requests repaint
- childRequestedRepaint(null);
- }
-
- /* Documentation copied from interface */
- public void childRequestedRepaint(Collection alreadyNotified) {
-
- // Notify listeners only once
- if (!repaintRequestListenersNotified) {
-
- // Notify the listeners
- if (repaintRequestListeners != null
- && !repaintRequestListeners.isEmpty()) {
- Object[] listeners = repaintRequestListeners.toArray();
- RepaintRequestEvent event = new RepaintRequestEvent(this);
- for (int i = 0; i < listeners.length; i++) {
- if (alreadyNotified == null)
- alreadyNotified = new LinkedList();
- if (!alreadyNotified.contains(listeners[i])) {
- ((RepaintRequestListener) listeners[i])
- .repaintRequested(event);
- alreadyNotified.add(listeners[i]);
- }
- }
- }
-
- repaintRequestListenersNotified = true;
-
- // Notify the parent
- Component parent = getParent();
- if (parent != null)
- parent.childRequestedRepaint(alreadyNotified);
-
- }
- }
-
- /* Documentation copied from interface */
- public void addListener(RepaintRequestListener listener) {
- if (repaintRequestListeners == null)
- repaintRequestListeners = new LinkedList();
- if (!repaintRequestListeners.contains(listener)) {
- repaintRequestListeners.add(listener);
- }
- }
-
- /* Documentation copied from interface */
- public void removeListener(RepaintRequestListener listener) {
- if (repaintRequestListeners != null) {
- repaintRequestListeners.remove(listener);
- if (repaintRequestListeners.isEmpty())
- repaintRequestListeners = null;
- }
- }
-
- /**
- * The custom component is allways enabled by default.
- */
- public void setEnabled(boolean enabled) {
- }
-
- /**
- * Sets the component's parent component.
- *
- * @see com.itmill.toolkit.ui.Component#setParent(com.itmill.toolkit.ui.Component)
- */
- public void setParent(Component parent) {
-
- // If the parent is not changed, dont do nothing
- if (parent == this.parent)
- return;
-
- // Sends the detach event if the component have been connected to a
- // window
- if (getApplication() != null) {
- detach();
- this.parent = null;
- }
-
- // Connects to new parent
- this.parent = parent;
-
- // Sends the attach event if connected to a window
- if (getApplication() != null)
- attach();
- }
-
- /**
- * Sets the component's to read-only mode to the specified state.
- *
- * @see com.itmill.toolkit.ui.Component#setReadOnly(boolean)
- */
- public void setReadOnly(boolean readOnly) {
- }
-
- /**
- * Custom component does not implement custom styles by default.
- *
- * @see com.itmill.toolkit.ui.Component#setStyle(java.lang.String)
- */
- public void setStyleName(String style) {
- }
-
- /**
- * Sets the components visibility status.
- *
- * @see com.itmill.toolkit.ui.Component#setVisible(boolean)
- */
- public void setVisible(boolean visible) {
- this.visible = visible;
- }
-
- /* Documented in super interface */
- public void requestRepaintRequests() {
- repaintRequestListenersNotified = false;
- }
-
- /* Documented in super interface */
- public void paint(PaintTarget target) throws PaintException {
- if (root == null)
- throw new IllegalStateException("Composition root must be set to"
- + " non-null value before the " + getClass().getName()
- + " can be painted");
-
- if (isVisible()) {
- String type = getComponentType();
- if (type != null) {
- if (!target.startTag(this, "component")) {
- target.addAttribute("type", type);
- root.paint(target);
- }
- target.endTag("component");
- } else
- root.paint(target);
- }
- repaintRequestListenersNotified = false;
- }
-
- /**
- * Called when one or more variables handled by the implementing class are
- * changed.
- *
- * @see com.itmill.toolkit.terminal.VariableOwner#changeVariables(java.lang.Object,
- * java.util.Map)
- */
- public void changeVariables(Object source, Map variables) {
- }
-
- /* Dependency -framework is deprecated */
- public void dependsOn(VariableOwner depended) {
- }
-
- public void removeDirectDependency(VariableOwner depended) {
- }
-
- public Set getDirectDependencies() {
- return null;
- }
-
- /* Event functions are not implemented by default -------------------- */
-
- /**
- * Custom component does not implement any component events by default.
- *
- * @param listener
- * the listener to add.
- */
- public void addListener(Component.Listener listener) {
- }
-
- /**
- * Custom component does not implement any component events by default.
- *
- * @param listener
- * the listener to remove.
- */
- public void removeListener(Component.Listener listener) {
- }
-
- /**
- * Gets the component type.
- *
- * The component type is textual type of the component. This is included in
- * the UIDL as component tag attribute. If the component type is null
- * (default), the component tag is not included in the UIDL at all.
- *
- * @return the component type.
- */
- public String getComponentType() {
- return componentType;
- }
-
- /**
- * Sets the component type.
- *
- * The component type is textual type of the component. This is included in
- * the UIDL as component tag attribute. If the component type is null
- * (default), the component tag is not included in the UIDL at all.
- *
- * @param componentType
- * the componentType to set.
- */
- public void setComponentType(String componentType) {
- this.componentType = componentType;
- }
-
- /**
- * Custom component does not implement custom styles by default.
- *
- * @see com.itmill.toolkit.ui.Component#getStyle()
- */
- public void addStyleName(String style) {
- }
-
- /**
- * Custom component does not implement custom styles by default.
- *
- * @see com.itmill.toolkit.ui.Component#getStyle()
- */
- public void removeStyleName(String style) {
-
- }
+ /**
+ * The root component implementing the custom component.
+ */
+ private Component root = null;
+
+ /**
+ * The visibility of the component.
+ */
+ private boolean visible = true;
+
+ /**
+ * The parent of the component.
+ */
+ private Component parent = null;
+
+ /**
+ * Type of the component.
+ */
+ private String componentType = null;
+
+ /**
+ * List of repaint request listeners or null if not listened at all.
+ */
+ private LinkedList repaintRequestListeners = null;
+
+ /**
+ * Are all the repaint listeners notified about recent changes ?
+ */
+ private boolean repaintRequestListenersNotified = false;
+
+ /**
+ * Constructs a new custom component.
+ *
+ * <p>
+ * The component is implemented by wrapping the methods of the composition
+ * root component given as parameter. The composition root must be set
+ * before the component can be used.
+ * </p>
+ */
+ public CustomComponent() {
+ }
+
+ /**
+ * Constructs a new custom component.
+ *
+ * <p>
+ * The component is implemented by wrapping the methods of the composition
+ * root component given as parameter. The composition root must not be null
+ * and can not be changed after the composition.
+ * </p>
+ *
+ * @param compositionRoot
+ * the root of the composition component tree.
+ */
+ public CustomComponent(Component compositionRoot) {
+ setCompositionRoot(compositionRoot);
+ }
+
+ /**
+ * Returns the composition root.
+ *
+ * @return the Component Composition root.
+ */
+ protected final Component getCompositionRoot() {
+ return root;
+ }
+
+ /**
+ * Sets the compositions root.
+ * <p>
+ * The composition root must be set to non-null value before the component
+ * can be used. The composition root can only be set once.
+ * </p>
+ *
+ * @param compositionRoot
+ * the root of the composition component tree.
+ */
+ protected final void setCompositionRoot(Component compositionRoot) {
+ if (compositionRoot != root && root != null) {
+ root.setParent(null);
+ }
+ root = compositionRoot;
+ if (root != null) {
+ root.setParent(this);
+ }
+ }
+
+ /* Basic component features ------------------------------------------ */
+
+ /**
+ * Notifies the component that it is connected to an application.
+ *
+ * @see com.itmill.toolkit.ui.Component#attach()
+ */
+ public void attach() {
+ if (root != null) {
+ root.attach();
+ requestRepaint();
+ }
+ }
+
+ /**
+ * Notifies the component that it is detached from the application.
+ *
+ * @see com.itmill.toolkit.ui.Component#detach()
+ */
+ public void detach() {
+ if (root != null) {
+ root.detach();
+ }
+ }
+
+ /**
+ * Gets the component's parent application
+ *
+ * @see com.itmill.toolkit.ui.Component#getApplication()
+ */
+ public Application getApplication() {
+ if (parent == null) {
+ return null;
+ }
+ return parent.getApplication();
+ }
+
+ /**
+ * The caption of the custom component is by default the caption of the root
+ * component, or null if the root is not set.
+ *
+ * @see com.itmill.toolkit.ui.Component#getCaption()
+ */
+ public String getCaption() {
+ if (root == null) {
+ return null;
+ }
+ return root.getCaption();
+ }
+
+ /**
+ * The icon of the custom component is by default the icon of the root
+ * component, or null if the root is not set.
+ *
+ * @see com.itmill.toolkit.ui.Component#getIcon()
+ */
+ public Resource getIcon() {
+ if (root == null) {
+ return null;
+ }
+ return root.getIcon();
+ }
+
+ /**
+ * The icon of the custom component is by default the locale of the parent
+ * or null if the parent is not set.
+ *
+ * @see com.itmill.toolkit.ui.Component#getLocale()
+ */
+ public Locale getLocale() {
+ if (parent == null) {
+ return null;
+ }
+ return parent.getLocale();
+ }
+
+ /**
+ * Gets the visual parent of the component.
+ *
+ * @see com.itmill.toolkit.ui.Component#getParent()
+ */
+ public Component getParent() {
+ return parent;
+ }
+
+ /**
+ * Custom component does not implement custom styles by default and this
+ * function returns null.
+ *
+ * @see com.itmill.toolkit.ui.Component#getStyle()
+ */
+ public String getStyleName() {
+ return null;
+ }
+
+ /**
+ * Gets the component's parent window.
+ *
+ * @see com.itmill.toolkit.ui.Component#getWindow()
+ */
+ public Window getWindow() {
+ if (parent == null) {
+ return null;
+ }
+ return parent.getWindow();
+ }
+
+ /**
+ * Custom component is always enabled by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#isEnabled()
+ */
+ public boolean isEnabled() {
+ return true;
+ }
+
+ /**
+ * Custom component is by default in the non-immediate mode. The
+ * immediateness of the custom component is defined by the components it is
+ * composed of.
+ *
+ * @see com.itmill.toolkit.terminal.VariableOwner#isImmediate()
+ */
+ public boolean isImmediate() {
+ return false;
+ }
+
+ /**
+ * The custom components are not readonly by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ /**
+ * Tests if the component is visible or not.
+ *
+ * @see com.itmill.toolkit.ui.Component#isVisible()
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /* Documentation copied from interface */
+ public void requestRepaint() {
+
+ // The effect of the repaint request is identical to case where a
+ // child requests repaint
+ childRequestedRepaint(null);
+ }
+
+ /* Documentation copied from interface */
+ public void childRequestedRepaint(Collection alreadyNotified) {
+
+ // Notify listeners only once
+ if (!repaintRequestListenersNotified) {
+
+ // Notify the listeners
+ if (repaintRequestListeners != null
+ && !repaintRequestListeners.isEmpty()) {
+ Object[] listeners = repaintRequestListeners.toArray();
+ RepaintRequestEvent event = new RepaintRequestEvent(this);
+ for (int i = 0; i < listeners.length; i++) {
+ if (alreadyNotified == null) {
+ alreadyNotified = new LinkedList();
+ }
+ if (!alreadyNotified.contains(listeners[i])) {
+ ((RepaintRequestListener) listeners[i])
+ .repaintRequested(event);
+ alreadyNotified.add(listeners[i]);
+ }
+ }
+ }
+
+ repaintRequestListenersNotified = true;
+
+ // Notify the parent
+ Component parent = getParent();
+ if (parent != null) {
+ parent.childRequestedRepaint(alreadyNotified);
+ }
+
+ }
+ }
+
+ /* Documentation copied from interface */
+ public void addListener(RepaintRequestListener listener) {
+ if (repaintRequestListeners == null) {
+ repaintRequestListeners = new LinkedList();
+ }
+ if (!repaintRequestListeners.contains(listener)) {
+ repaintRequestListeners.add(listener);
+ }
+ }
+
+ /* Documentation copied from interface */
+ public void removeListener(RepaintRequestListener listener) {
+ if (repaintRequestListeners != null) {
+ repaintRequestListeners.remove(listener);
+ if (repaintRequestListeners.isEmpty()) {
+ repaintRequestListeners = null;
+ }
+ }
+ }
+
+ /**
+ * The custom component is allways enabled by default.
+ */
+ public void setEnabled(boolean enabled) {
+ }
+
+ /**
+ * Sets the component's parent component.
+ *
+ * @see com.itmill.toolkit.ui.Component#setParent(com.itmill.toolkit.ui.Component)
+ */
+ public void setParent(Component parent) {
+
+ // If the parent is not changed, dont do nothing
+ if (parent == this.parent) {
+ return;
+ }
+
+ // Sends the detach event if the component have been connected to a
+ // window
+ if (getApplication() != null) {
+ detach();
+ this.parent = null;
+ }
+
+ // Connects to new parent
+ this.parent = parent;
+
+ // Sends the attach event if connected to a window
+ if (getApplication() != null) {
+ attach();
+ }
+ }
+
+ /**
+ * Sets the component's to read-only mode to the specified state.
+ *
+ * @see com.itmill.toolkit.ui.Component#setReadOnly(boolean)
+ */
+ public void setReadOnly(boolean readOnly) {
+ }
+
+ /**
+ * Custom component does not implement custom styles by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#setStyle(java.lang.String)
+ */
+ public void setStyleName(String style) {
+ }
+
+ /**
+ * Sets the components visibility status.
+ *
+ * @see com.itmill.toolkit.ui.Component#setVisible(boolean)
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ }
+
+ /* Documented in super interface */
+ public void requestRepaintRequests() {
+ repaintRequestListenersNotified = false;
+ }
+
+ /* Documented in super interface */
+ public void paint(PaintTarget target) throws PaintException {
+ if (root == null) {
+ throw new IllegalStateException("Composition root must be set to"
+ + " non-null value before the " + getClass().getName()
+ + " can be painted");
+ }
+
+ if (isVisible()) {
+ String type = getComponentType();
+ if (type != null) {
+ if (!target.startTag(this, "component")) {
+ target.addAttribute("type", type);
+ root.paint(target);
+ }
+ target.endTag("component");
+ } else {
+ root.paint(target);
+ }
+ }
+ repaintRequestListenersNotified = false;
+ }
+
+ /**
+ * Called when one or more variables handled by the implementing class are
+ * changed.
+ *
+ * @see com.itmill.toolkit.terminal.VariableOwner#changeVariables(java.lang.Object,
+ * java.util.Map)
+ */
+ public void changeVariables(Object source, Map variables) {
+ }
+
+ /* Dependency -framework is deprecated */
+ public void dependsOn(VariableOwner depended) {
+ }
+
+ public void removeDirectDependency(VariableOwner depended) {
+ }
+
+ public Set getDirectDependencies() {
+ return null;
+ }
+
+ /* Event functions are not implemented by default -------------------- */
+
+ /**
+ * Custom component does not implement any component events by default.
+ *
+ * @param listener
+ * the listener to add.
+ */
+ public void addListener(Component.Listener listener) {
+ }
+
+ /**
+ * Custom component does not implement any component events by default.
+ *
+ * @param listener
+ * the listener to remove.
+ */
+ public void removeListener(Component.Listener listener) {
+ }
+
+ /**
+ * Gets the component type.
+ *
+ * The component type is textual type of the component. This is included in
+ * the UIDL as component tag attribute. If the component type is null
+ * (default), the component tag is not included in the UIDL at all.
+ *
+ * @return the component type.
+ */
+ public String getComponentType() {
+ return componentType;
+ }
+
+ /**
+ * Sets the component type.
+ *
+ * The component type is textual type of the component. This is included in
+ * the UIDL as component tag attribute. If the component type is null
+ * (default), the component tag is not included in the UIDL at all.
+ *
+ * @param componentType
+ * the componentType to set.
+ */
+ public void setComponentType(String componentType) {
+ this.componentType = componentType;
+ }
+
+ /**
+ * Custom component does not implement custom styles by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#getStyle()
+ */
+ public void addStyleName(String style) {
+ }
+
+ /**
+ * Custom component does not implement custom styles by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#getStyle()
+ */
+ public void removeStyleName(String style) {
+
+ }
}