You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/03/26 00:12:17 UTC

svn commit: r758461 [20/47] - in /incubator/pivot/branches: ./ 1.1/ 1.1/charts-test/ 1.1/charts-test/src/ 1.1/charts-test/src/pivot/ 1.1/charts-test/src/pivot/charts/ 1.1/charts-test/src/pivot/charts/test/ 1.1/charts/ 1.1/charts/lib/ 1.1/charts/src/ 1....

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ExpanderListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ExpanderListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ExpanderListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ExpanderListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.util.Vote;
+
+/**
+ * Expander listener list.
+ *
+ * @author tvolkert
+ */
+public interface ExpanderListener {
+    /**
+     * Called when an expander's title has changed.
+     *
+     * @param expander
+     * @param previousTitle
+     */
+    public void titleChanged(Expander expander, String previousTitle);
+
+    /**
+     * Called to preview an expanded change event.
+     *
+     * @param expander
+     */
+    public Vote previewExpandedChange(Expander expander);
+
+    /**
+     * Called when an expanded change event has been vetoed.
+     *
+     * @param expander
+     * @param reason
+     */
+    public void expandedChangeVetoed(Expander expander, Vote reason);
+
+    /**
+     * Called when an expander's expanded state has changed.
+     *
+     * @param expander
+     */
+    public void expandedChanged(Expander expander);
+
+    /**
+     * Called when an expander's content component has changed.
+     *
+     * @param expander
+     * @param previousContent
+     */
+    public void contentChanged(Expander expander, Component previousContent);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPane.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPane.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPane.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPane.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.util.ListenerList;
+
+/**
+ * Container that arranges components in a line, either vertically or
+ * horizontally.
+ *
+ * @author gbrown
+ */
+public class FlowPane extends Container {
+    private static class FlowPaneListenerList extends ListenerList<FlowPaneListener>
+        implements FlowPaneListener {
+        public void orientationChanged(FlowPane flowPane) {
+            for (FlowPaneListener listener : this) {
+                listener.orientationChanged(flowPane);
+            }
+        }
+    }
+
+    private Orientation orientation = null;
+    private FlowPaneListenerList flowPaneListeners = new FlowPaneListenerList();
+
+    public FlowPane() {
+        this(Orientation.HORIZONTAL);
+    }
+
+    public FlowPane(Orientation orientation) {
+        this.orientation = orientation;
+
+        installSkin(FlowPane.class);
+    }
+
+    public Orientation getOrientation() {
+        return orientation;
+    }
+
+    public void setOrientation(Orientation orientation) {
+        if (this.orientation != orientation) {
+            this.orientation = orientation;
+            flowPaneListeners.orientationChanged(this);
+        }
+    }
+
+    public void setOrientation(String orientation) {
+        setOrientation(Orientation.decode(orientation));
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPaneListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPaneListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPaneListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FlowPaneListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Flow pane listener interface.
+ *
+ * @author gbrown
+ */
+public interface FlowPaneListener {
+    /**
+     * Called when a flow pane's orientation has changed.
+     *
+     * @param flowPane
+     */
+    public void orientationChanged(FlowPane flowPane);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FocusTraversalPolicy.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FocusTraversalPolicy.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FocusTraversalPolicy.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FocusTraversalPolicy.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Defines the order in which components will receive focus during focus
+ * traversal.
+ *
+ * @author gbrown
+ */
+public interface FocusTraversalPolicy {
+    /**
+     * Returns the next focus destination according to this traversal policy.
+     *
+     * @param container
+     * The container to which the traversal policy applies.
+     *
+     * @param component
+     * The component from which focus is being transferred. If <tt>null</tt>,
+     * implementations should return the first component for a forward
+     * traversal and the last component for a backward traversal.
+     *
+     * @param direction
+     * The direction in which to transfer focus.
+     *
+     * @return
+     * The component to focus, or <tt>null</tt> if there are no more components
+     * in the given direction or next component cannot be determined.
+     */
+    Component getNextComponent(Container container, Component component, Direction direction);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Form.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Form.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Form.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Form.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,524 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import java.util.Iterator;
+import pivot.collections.ArrayList;
+import pivot.collections.Dictionary;
+import pivot.collections.Sequence;
+import pivot.serialization.JSONSerializer;
+import pivot.util.ImmutableIterator;
+import pivot.util.ListenerList;
+
+/**
+ * A container that arranges field components in a form layout. Each field has
+ * an optional text label associated with it and may be flagged as requiring
+ * attention using one of several flag types and an optional flag message (for
+ * use during form validation, for example).
+ * <p>
+ * TODO Add a label alignment attribute (vertical).
+ *
+ * @author gbrown
+ */
+public class Form extends Container {
+    /**
+     * Class representing a menu section. A section is a grouping of menu
+     * items within a menu.
+     *
+     * @author gbrown
+     */
+    public static class Section implements Sequence<Component>, Iterable<Component> {
+        private Form form = null;
+        private String heading = null;
+        private ArrayList<Component> fields = new ArrayList<Component>();
+
+        public Form getForm() {
+            return form;
+        }
+
+        private void setForm(Form form) {
+            this.form = form;
+        }
+
+        public String getHeading() {
+            return heading;
+        }
+
+        public void setHeading(String heading) {
+            String previousHeading = this.heading;
+            if (previousHeading != heading) {
+                this.heading = heading;
+
+                if (form != null) {
+                    form.formListeners.sectionHeadingChanged(this);
+                }
+            }
+        }
+
+        public int add(Component field) {
+            int index = getLength();
+            insert(field, index);
+
+            return index;
+        }
+
+        public void insert(Component field, int index) {
+            fields.insert(field, index);
+
+            if (form != null) {
+                form.add(field);
+                form.formListeners.fieldInserted(this, index);
+            }
+
+            field.setAttributes(new FormAttributes(this));
+        }
+
+        public Component update(int index, Component field) {
+            throw new UnsupportedOperationException();
+        }
+
+        public int remove(Component field) {
+            int index = fields.indexOf(field);
+            if (index != -1) {
+                remove(index, 1);
+            }
+
+            return index;
+        }
+
+        public Sequence<Component> remove(int index, int count) {
+            Sequence<Component> removed = fields.remove(index, count);
+
+            for (int i = 0, n = removed.getLength(); i < n; i++) {
+                Component field = removed.get(i);
+                field.setAttributes(null);
+
+                if (form != null) {
+                    form.remove(field);
+                }
+            }
+
+            if (form != null) {
+                form.formListeners.fieldsRemoved(this, index, removed);
+            }
+
+            return removed;
+        }
+
+        public Component get(int index) {
+            return fields.get(index);
+        }
+
+        public int indexOf(Component field) {
+            return fields.indexOf(field);
+        }
+
+        public int getLength() {
+            return fields.getLength();
+        }
+
+        public Iterator<Component> iterator() {
+            return new ImmutableIterator<Component>(fields.iterator());
+        }
+    }
+
+    /**
+     * Section sequence implementation.
+     *
+     * @author gbrown
+     */
+    public final class SectionSequence implements Sequence<Section>, Iterable<Section> {
+        private SectionSequence() {
+        }
+
+        public int add(Section section) {
+            int index = getLength();
+            insert(section, index);
+
+            return index;
+        }
+
+        public void insert(Section section, int index) {
+            if (section.getForm() != null) {
+                throw new IllegalArgumentException("section already has a form.");
+            }
+
+            sections.insert(section, index);
+            section.setForm(Form.this);
+
+            for (int i = 0, n = section.getLength(); i < n; i++) {
+                Form.this.add(section.get(i));
+            }
+
+            formListeners.sectionInserted(Form.this, index);
+        }
+
+        public Section update(int index, Section section) {
+            throw new UnsupportedOperationException();
+        }
+
+        public int remove(Section section) {
+            int index = sections.indexOf(section);
+            if (index != -1) {
+                remove(index, 1);
+            }
+
+            return index;
+        }
+
+        public Sequence<Section> remove(int index, int count) {
+            Sequence<Section> removed = sections.remove(index, count);
+
+            for (int i = 0, n = removed.getLength(); i < n; i++) {
+                Section section = removed.get(i);
+
+                section.setForm(null);
+
+                for (Component field : section) {
+                    Form.this.remove(field);
+                }
+            }
+
+            formListeners.sectionsRemoved(Form.this, index, removed);
+
+            return removed;
+        }
+
+        public Section get(int index) {
+            return sections.get(index);
+        }
+
+        public int indexOf(Section item) {
+            return sections.indexOf(item);
+        }
+
+        public int getLength() {
+            return sections.getLength();
+        }
+
+        public Iterator<Section> iterator() {
+            return new ImmutableIterator<Section>(sections.iterator());
+        }
+    }
+
+    /**
+     * Defines form field attributes.
+     *
+     * @author gbrown
+     */
+    protected static class FormAttributes extends Attributes {
+        private Section section = null;
+        private String name = null;
+        private Flag flag = null;
+
+        protected FormAttributes(Section section) {
+            this.section = section;
+        }
+
+        public Section getSection() {
+            return section;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            String previousName = this.name;
+            this.name = name;
+
+            Component component = getComponent();
+            Form form = (Form)component.getParent();
+            if (form != null) {
+                form.formAttributeListeners.nameChanged(form, component, previousName);
+            }
+        }
+
+        public Flag getFlag() {
+            return flag;
+        }
+
+        public void setFlag(Flag flag) {
+            Flag previousFlag = this.flag;
+            this.flag = flag;
+
+            Component component = getComponent();
+            Form form = (Form)component.getParent();
+            if (form != null) {
+                form.formAttributeListeners.flagChanged(form, component, previousFlag);
+            }
+        }
+    }
+
+    /**
+     * Represents an message alert associated with a form field.
+     *
+     * @author gbrown
+     */
+    public static class Flag {
+        /**
+         * The flag's message type.
+         */
+        private MessageType messageType = null;
+
+        /**
+         * The flag message. May be <tt>null</tt>.
+         */
+        private String message = null;
+
+        public static final String MESSAGE_TYPE_KEY = "messageType";
+        public static final String MESSAGE_KEY = "message";
+
+        /**
+         * Creates a new flag with the given message type and no message.
+         *
+         * @param messageType
+         * The type of the flag.
+         */
+        public Flag(MessageType messageType) {
+            this(messageType, null);
+        }
+
+        public Flag(String flag) {
+            this(JSONSerializer.parseMap(flag));
+        }
+
+        public Flag(Dictionary<String, ?> flag) {
+            this(MessageType.decode((String)flag.get(MESSAGE_TYPE_KEY)),
+                (String)flag.get(MESSAGE_KEY));
+        }
+
+        /**
+         * Creates a new flag with the given type and message.
+         *
+         * @param messageType
+         * The type of the flag.
+         *
+         * @param message
+         * The message text associated with the flag, or <tt>null</tt> for
+         * no message.
+         */
+        public Flag(MessageType messageType, String message) {
+            if (messageType == null) {
+                throw new IllegalArgumentException("messageType is null.");
+            }
+
+            this.messageType = messageType;
+            this.message = message;
+        }
+
+        /**
+         * Returns the flag's message type.
+         *
+         * @return
+         * The message type of the flag.
+         */
+        public MessageType getMessageType() {
+            return messageType;
+        }
+
+        /**
+         * Returns the flag message.
+         *
+         * @return
+         * The message text associated with the flag, or <tt>null</tt> if
+         * there is no message.
+         */
+        public String getMessage() {
+            return message;
+        }
+    }
+
+    /**
+     * Form listener list.
+     *
+     * @author gbrown
+     */
+    private static class FormListenerList extends ListenerList<FormListener>
+        implements FormListener {
+        public void sectionInserted(Form form, int index) {
+            for (FormListener listener : this) {
+                listener.sectionInserted(form, index);
+            }
+        }
+
+        public void sectionsRemoved(Form form, int index, Sequence<Section> removed) {
+            for (FormListener listener : this) {
+                listener.sectionsRemoved(form, index, removed);
+            }
+        }
+
+        public void sectionHeadingChanged(Form.Section section) {
+            for (FormListener listener : this) {
+                listener.sectionHeadingChanged(section);
+            }
+        }
+
+        public void fieldInserted(Section section, int index) {
+            for (FormListener listener : this) {
+                listener.fieldInserted(section, index);
+            }
+        }
+
+        public void fieldsRemoved(Section section, int index, Sequence<Component> fields) {
+            for (FormListener listener : this) {
+                listener.fieldsRemoved(section, index, fields);
+            }
+        }
+    }
+
+    /**
+     * Form attribute listener list.
+     */
+    private static class FormAttributeListenerList extends ListenerList<FormAttributeListener>
+        implements FormAttributeListener {
+        public void nameChanged(Form form, Component component, String previousName) {
+            for (FormAttributeListener listener : this) {
+                listener.nameChanged(form, component, previousName);
+            }
+        }
+
+        public void flagChanged(Form form, Component component, Form.Flag previousFlag) {
+            for (FormAttributeListener listener : this) {
+                listener.flagChanged(form, component, previousFlag);
+            }
+        }
+    }
+
+    private ArrayList<Section> sections = new ArrayList<Section>();
+    private SectionSequence sectionSequence = new SectionSequence();
+
+    private FormListenerList formListeners = new FormListenerList();
+    private FormAttributeListenerList formAttributeListeners = new FormAttributeListenerList();
+
+    /**
+     * Creates a new form.
+     */
+    public Form() {
+        super();
+
+        installSkin(Form.class);
+    }
+
+    /**
+     * Returns the form's field sequence.
+     *
+     * @return
+     * The form's field sequence.
+     */
+    public SectionSequence getSections() {
+        return sectionSequence;
+    }
+
+    /**
+     * Returns the number of fields that are flagged with a given flag type.
+     *
+     * @param messageType
+     * The message type to count, or <tt>null</tt> to return the count of all
+     * flagged fields regardless of message type.
+     */
+    public int getFlaggedFieldCount(MessageType messageType) {
+        int count = 0;
+
+        for (Section section : sections) {
+            for (Component field : section) {
+                Flag flag = getFlag(field);
+
+                if (flag != null
+                   && (messageType == null
+                       || flag.getMessageType() == messageType)) {
+                    count++;
+                }
+            }
+        }
+
+        return count;
+    }
+
+    @Override
+    public Sequence<Component> remove(int index, int count) {
+        for (int i = index, n = index + count; i < n; i++) {
+            Component component = get(i);
+            if (component.getAttributes() != null) {
+                throw new UnsupportedOperationException();
+            }
+        }
+
+        // Call the base method to remove the components
+        return super.remove(index, count);
+    }
+
+    /**
+     * Returns the form listener list.
+     *
+     * @return
+     * The form listener list.
+     */
+    public ListenerList<FormListener> getFormListeners() {
+        return formListeners;
+    }
+
+    /**
+     * Returns the form attribute listener list.
+     *
+     * @return
+     * The form attribute listener list.
+     */
+    public ListenerList<FormAttributeListener> getFormAttributeListeners() {
+        return formAttributeListeners;
+    }
+
+    public static Section getSection(Component component) {
+        FormAttributes formAttributes = (FormAttributes)component.getAttributes();
+        return (formAttributes == null) ? null : formAttributes.getSection();
+    }
+
+    public static String getName(Component component) {
+        FormAttributes formAttributes = (FormAttributes)component.getAttributes();
+        return (formAttributes == null) ? null : formAttributes.getName();
+    }
+
+    public static void setName(Component component, String name) {
+        FormAttributes formAttributes = (FormAttributes)component.getAttributes();
+        if (formAttributes == null) {
+            throw new IllegalStateException();
+        }
+
+        formAttributes.setName(name);
+    }
+
+    public static Flag getFlag(Component component) {
+        FormAttributes formAttributes = (FormAttributes)component.getAttributes();
+        return (formAttributes == null) ? null : formAttributes.getFlag();
+    }
+
+    public static void setFlag(Component component, Flag flag) {
+        FormAttributes formAttributes = (FormAttributes)component.getAttributes();
+        if (formAttributes == null) {
+            throw new IllegalStateException();
+        }
+
+        formAttributes.setFlag(flag);
+    }
+
+    public static final void setFlag(Component component, String flag) {
+        if (flag == null) {
+            throw new IllegalArgumentException("flag is null.");
+        }
+
+        setFlag(component, new Flag(flag));
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormAttributeListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormAttributeListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormAttributeListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormAttributeListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Form attribute listener interface.
+ *
+ * @author gbrown
+ */
+public interface FormAttributeListener {
+    /**
+     * Called when a fields's name attribute has changed.
+     *
+     * @param form
+     * @param field
+     * @param previousName
+     */
+    public void nameChanged(Form form, Component field, String previousName);
+
+    /**
+     * Called when a field's flag attribute has changed.
+     *
+     * @param form
+     * @param field
+     * @param previousFlag
+     */
+    public void flagChanged(Form form, Component field, Form.Flag previousFlag);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/FormListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.collections.Sequence;
+
+/**
+ * Form listener interface.
+ *
+ * @author gbrown
+ */
+public interface FormListener {
+    /**
+     * Called when a form section has been inserted.
+     *
+     * @param form
+     * @param index
+     */
+    public void sectionInserted(Form form, int index);
+
+    /**
+     * Called when form sections have been removed.
+     *
+     * @param form
+     * @param index
+     * @param removed
+     */
+    public void sectionsRemoved(Form form, int index, Sequence<Form.Section> removed);
+
+    /**
+     * Called when a form section's heading has changed.
+     *
+     * @param section
+     */
+    public void sectionHeadingChanged(Form.Section section);
+
+    /**
+     * Called when a form field has been inserted.
+     *
+     * @param section
+     * @param index
+     */
+    public void fieldInserted(Form.Section section, int index);
+
+    /**
+     * Called when forms fields items have been removed.
+     *
+     * @param section
+     * @param index
+     * @param fields
+     */
+    public void fieldsRemoved(Form.Section section, int index, Sequence<Component> fields);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Frame.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Frame.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Frame.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Frame.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Container class representing a decorated frame window.
+ *
+ * @author gbrown
+ */
+public class Frame extends Window {
+    public Frame() {
+        this(null, null);
+    }
+
+    public Frame(String title) {
+        this(title, null);
+    }
+
+    public Frame(Component content) {
+        this(null, content);
+    }
+
+    public Frame(String title, Component content) {
+        super(content, false);
+
+        setTitle(title);
+        installSkin(Frame.class);
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/HorizontalAlignment.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/HorizontalAlignment.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/HorizontalAlignment.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/HorizontalAlignment.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Enumeration representing horizontal alignment values.
+ *
+ * @author gbrown
+ */
+public enum HorizontalAlignment {
+    RIGHT,
+    LEFT,
+    CENTER,
+    JUSTIFY;
+
+    public static HorizontalAlignment decode(String value) {
+        return valueOf(value.toUpperCase());
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageView.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageView.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageView.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import java.net.URL;
+import pivot.util.ListenerList;
+import pivot.wtk.media.Image;
+
+/**
+ * Component that displays an image.
+ * <p>
+ * TODO Load images asynchronously in setImage()?
+ *
+ * @author gbrown
+ */
+public class ImageView extends Component {
+    private static class ImageViewListenerList extends ListenerList<ImageViewListener>
+        implements ImageViewListener {
+        public void imageChanged(ImageView imageView, Image previousImage) {
+            for (ImageViewListener listener : this) {
+                listener.imageChanged(imageView, previousImage);
+            }
+        }
+    }
+
+    private Image image = null;
+
+    private ImageViewListenerList imageViewListeners = new ImageViewListenerList();
+
+    /**
+     * Creates an empty image view.
+     */
+    public ImageView() {
+        this(null);
+    }
+
+    /**
+     * Creates an image view with the given image.
+     *
+     * @param image
+     * The initial image to set, or <tt>null</tt> for no image.
+     */
+    public ImageView(Image image) {
+        setImage(image);
+
+        installSkin(ImageView.class);
+    }
+
+    /**
+     * Returns the image view's current image.
+     *
+     * @return
+     * The current image, or <tt>null</tt> if no image is set.
+     */
+    public Image getImage() {
+        return image;
+    }
+
+    /**
+     * Sets the image view's current image.
+     *
+     * @param image
+     * The image to set, or <tt>null</tt> for no image.
+     */
+    public void setImage(Image image) {
+        Image previousImage = this.image;
+
+        if (previousImage != image) {
+            this.image = image;
+            imageViewListeners.imageChanged(this, previousImage);
+        }
+    }
+
+    /**
+     * Sets the image view's current image by URL.
+     *
+     * @param image
+     * The location of the image to set.
+     */
+    public void setImage(URL image) {
+        if (image == null) {
+            throw new IllegalArgumentException("image is null.");
+        }
+
+        setImage(Image.load(image));
+    }
+
+    /**
+     * Sets the image view's current image by resource name.
+     *
+     * @param image
+     * The resource name of the image to set.
+     */
+    public void setImage(String image) {
+        if (image == null) {
+            throw new IllegalArgumentException("image is null.");
+        }
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        setImage(classLoader.getResource(image));
+    }
+
+    /**
+     * Returns the image view listener list.
+     *
+     * @return
+     * The image view listener list.
+     */
+    public ListenerList<ImageViewListener> getImageViewListeners() {
+        return imageViewListeners;
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageViewListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageViewListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageViewListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ImageViewListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.wtk.media.Image;
+
+/**
+ * Image view listener interface.
+ *
+ * @author gbrown
+ */
+public interface ImageViewListener {
+    /**
+     * Called when an image view's image has changed.
+     *
+     * @param imageView
+     * @param previousImage
+     */
+    public void imageChanged(ImageView imageView, Image previousImage);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Insets.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Insets.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Insets.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Insets.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.collections.Dictionary;
+
+/**
+ * Class representing the insets of an object.
+ *
+ * @author gbrown
+ */
+public class Insets {
+    public int top = 0;
+    public int left = 0;
+    public int bottom = 0;
+    public int right = 0;
+
+    public static final String TOP_KEY = "top";
+    public static final String LEFT_KEY = "left";
+    public static final String BOTTOM_KEY = "bottom";
+    public static final String RIGHT_KEY = "right";
+
+    public Insets() {
+    }
+
+    public Insets(int inset) {
+        top = inset;
+        left = inset;
+        bottom = inset;
+        right = inset;
+    }
+
+    public Insets(Dictionary<String, ?> insets) {
+        if (insets == null) {
+            throw new IllegalArgumentException("insets is null.");
+        }
+
+        if (insets.containsKey(TOP_KEY)) {
+            top = ((Number)insets.get(TOP_KEY)).intValue();
+        }
+
+        if (insets.containsKey(LEFT_KEY)) {
+            left = ((Number)insets.get(LEFT_KEY)).intValue();
+        }
+
+        if (insets.containsKey(BOTTOM_KEY)) {
+            bottom = ((Number)insets.get(BOTTOM_KEY)).intValue();
+        }
+
+        if (insets.containsKey(RIGHT_KEY)) {
+            right = ((Number)insets.get(RIGHT_KEY)).intValue();
+        }
+    }
+
+    public Insets(int top, int left, int bottom, int right) {
+        this.top = top;
+        this.left = left;
+        this.bottom = bottom;
+        this.right = right;
+    }
+
+    public Insets(Insets insets) {
+        if (insets == null) {
+            throw new IllegalArgumentException("insets is null.");
+        }
+
+        this.top = insets.top;
+        this.left = insets.left;
+        this.bottom = insets.bottom;
+        this.right = insets.right;
+    }
+
+    public boolean equals(Object object) {
+        boolean equals = false;
+
+        if (object instanceof Insets) {
+            Insets insets = (Insets)object;
+            equals = (top == insets.top
+                && left == insets.left
+                && bottom == insets.bottom
+                && right == insets.right);
+        }
+
+        return equals;
+    }
+
+    public String toString() {
+        return getClass().getName() + " [" + top + ", " + left + ", "
+            + bottom + ", " + right + "]";
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Keyboard.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Keyboard.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Keyboard.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Keyboard.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,307 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import java.awt.event.KeyEvent;
+import java.lang.reflect.Field;
+
+/**
+ * Class representing the system keyboard.
+ *
+ * @author gbrown
+ */
+public final class Keyboard {
+    /**
+     * Enumeration representing keyboard modifiers.
+     *
+     * @author gbrown
+     */
+    public enum Modifier {
+        SHIFT,
+        CTRL,
+        ALT,
+        META;
+
+        public int getMask() {
+            return 1 << ordinal();
+        }
+
+        public boolean isSelected(int modifiers) {
+            return ((modifiers & getMask()) > 0);
+        }
+
+        public static Modifier decode(String value) {
+            return valueOf(value.toUpperCase());
+        }
+    }
+
+    /**
+     * Enumeration representing key locations.
+     *
+     * @author gbrown
+     */
+    public enum KeyLocation {
+        STANDARD,
+        LEFT,
+        RIGHT,
+        KEYPAD;
+
+        public static KeyLocation decode(String value) {
+            return valueOf(value.toUpperCase());
+        }
+    }
+
+    /**
+     * Represents a keystroke, a combination of a keycode and modifier flags.
+     *
+     * @author gbrown
+     */
+    public static final class KeyStroke {
+        private int keyCode = KeyCode.UNDEFINED;
+        private int modifiers = 0x00;
+
+        public KeyStroke(int keyCode, int modifiers) {
+            this.keyCode = keyCode;
+            this.modifiers = modifiers;
+        }
+
+        public int getKeyCode() {
+            return keyCode;
+        }
+
+        public int getModifiers() {
+            return modifiers;
+        }
+
+        @Override
+        public boolean equals(Object object) {
+            boolean equals = false;
+
+            if (object instanceof KeyStroke) {
+                KeyStroke keyStroke = (KeyStroke)object;
+                equals = (this.keyCode == keyStroke.keyCode
+                    && this.modifiers == keyStroke.modifiers);
+            }
+
+            return equals;
+        }
+
+        @Override
+        public int hashCode() {
+            // NOTE Key codes are currently defined as 16-bit values, so
+            // shifting by 4 bits to append the modifiers should be OK.
+            // However, if Sun changes the key code values in the future,
+            // this may no longer be safe.
+            int hashCode = keyCode << 4 | modifiers;
+            return hashCode;
+        }
+
+        @Override
+        public String toString() {
+            int awtModifiers = 0x00;
+
+            if (Modifier.META.isSelected(modifiers)) {
+                awtModifiers |= KeyEvent.META_DOWN_MASK;
+            }
+
+            if (Modifier.CTRL.isSelected(modifiers)) {
+                awtModifiers |= KeyEvent.CTRL_DOWN_MASK;
+            }
+
+            if (Modifier.ALT.isSelected(modifiers)) {
+                awtModifiers |= KeyEvent.ALT_DOWN_MASK;
+            }
+
+            if (Modifier.SHIFT.isSelected(modifiers)) {
+                awtModifiers |= KeyEvent.SHIFT_DOWN_MASK;
+            }
+
+            return KeyEvent.getModifiersExText(awtModifiers)
+                + KeyEvent.getKeyText(keyCode);
+        }
+
+        public static KeyStroke decode(String value) {
+            if (value == null) {
+                throw new IllegalArgumentException("value is null.");
+            }
+
+            int keyCode = KeyCode.UNDEFINED;
+            int modifiers = 0x00;
+
+            String[] keys = value.split("-");
+            for (int i = 0, n = keys.length; i < n; i++) {
+                if (i < n - 1) {
+                    // Modifier
+                    Modifier modifier = Modifier.decode(keys[i]);
+                    modifiers |= modifier.getMask();
+                } else {
+                    // Keycode
+                    try {
+                        Field keyCodeField = KeyCode.class.getField(keys[i].toUpperCase());
+                        keyCode = (Integer)keyCodeField.get(null);
+                    } catch(Exception exception) {
+                        throw new IllegalArgumentException(exception);
+                    }
+                }
+            }
+
+            return new KeyStroke(keyCode, modifiers);
+        }
+    }
+
+    /**
+     * Contains a set of key code constants that are common to all locales.
+     *
+     * @author gbrown
+     */
+    public static final class KeyCode {
+        public static final int A = KeyEvent.VK_A;
+        public static final int B = KeyEvent.VK_B;
+        public static final int C = KeyEvent.VK_C;
+        public static final int D = KeyEvent.VK_D;
+        public static final int E = KeyEvent.VK_E;
+        public static final int F = KeyEvent.VK_F;
+        public static final int G = KeyEvent.VK_G;
+        public static final int H = KeyEvent.VK_H;
+        public static final int I = KeyEvent.VK_I;
+        public static final int J = KeyEvent.VK_J;
+        public static final int K = KeyEvent.VK_K;
+        public static final int L = KeyEvent.VK_L;
+        public static final int M = KeyEvent.VK_M;
+        public static final int N = KeyEvent.VK_N;
+        public static final int O = KeyEvent.VK_O;
+        public static final int P = KeyEvent.VK_P;
+        public static final int Q = KeyEvent.VK_Q;
+        public static final int R = KeyEvent.VK_R;
+        public static final int S = KeyEvent.VK_S;
+        public static final int T = KeyEvent.VK_T;
+        public static final int U = KeyEvent.VK_U;
+        public static final int V = KeyEvent.VK_V;
+        public static final int W = KeyEvent.VK_W;
+        public static final int X = KeyEvent.VK_X;
+        public static final int Y = KeyEvent.VK_Y;
+        public static final int Z = KeyEvent.VK_Z;
+
+        public static final int N0 = KeyEvent.VK_0;
+        public static final int N1 = KeyEvent.VK_1;
+        public static final int N2 = KeyEvent.VK_2;
+        public static final int N3 = KeyEvent.VK_3;
+        public static final int N4 = KeyEvent.VK_4;
+        public static final int N5 = KeyEvent.VK_5;
+        public static final int N6 = KeyEvent.VK_6;
+        public static final int N7 = KeyEvent.VK_7;
+        public static final int N8 = KeyEvent.VK_8;
+        public static final int N9 = KeyEvent.VK_9;
+
+        public static final int TAB = KeyEvent.VK_TAB;
+        public static final int SPACE = KeyEvent.VK_SPACE;
+        public static final int ENTER = KeyEvent.VK_ENTER;
+        public static final int ESCAPE = KeyEvent.VK_ESCAPE;
+        public static final int BACKSPACE = KeyEvent.VK_BACK_SPACE;
+        public static final int DELETE = KeyEvent.VK_DELETE;
+
+        public static final int UP = KeyEvent.VK_UP;
+        public static final int DOWN = KeyEvent.VK_DOWN;
+        public static final int LEFT = KeyEvent.VK_LEFT;
+        public static final int RIGHT = KeyEvent.VK_RIGHT;
+
+        public static final int PAGE_UP = KeyEvent.VK_PAGE_UP;
+        public static final int PAGE_DOWN = KeyEvent.VK_PAGE_DOWN;
+
+        public static final int KEYPAD_0 = KeyEvent.VK_NUMPAD0;
+        public static final int KEYPAD_1 = KeyEvent.VK_NUMPAD1;
+        public static final int KEYPAD_2 = KeyEvent.VK_NUMPAD2;
+        public static final int KEYPAD_3 = KeyEvent.VK_NUMPAD3;
+        public static final int KEYPAD_4 = KeyEvent.VK_NUMPAD4;
+        public static final int KEYPAD_5 = KeyEvent.VK_NUMPAD5;
+        public static final int KEYPAD_6 = KeyEvent.VK_NUMPAD6;
+        public static final int KEYPAD_7 = KeyEvent.VK_NUMPAD7;
+        public static final int KEYPAD_8 = KeyEvent.VK_NUMPAD8;
+        public static final int KEYPAD_9 = KeyEvent.VK_NUMPAD9;
+        public static final int KEYPAD_UP = KeyEvent.VK_KP_UP;
+        public static final int KEYPAD_DOWN = KeyEvent.VK_KP_DOWN;
+        public static final int KEYPAD_LEFT = KeyEvent.VK_KP_LEFT;
+        public static final int KEYPAD_RIGHT = KeyEvent.VK_KP_RIGHT;
+
+        public static final int F1 = KeyEvent.VK_F1;
+        public static final int F2 = KeyEvent.VK_F2;
+        public static final int F3 = KeyEvent.VK_F3;
+        public static final int F4 = KeyEvent.VK_F4;
+        public static final int F5 = KeyEvent.VK_F5;
+        public static final int F6 = KeyEvent.VK_F6;
+        public static final int F7 = KeyEvent.VK_F7;
+        public static final int F8 = KeyEvent.VK_F8;
+        public static final int F9 = KeyEvent.VK_F9;
+        public static final int F10 = KeyEvent.VK_F10;
+        public static final int F11 = KeyEvent.VK_F11;
+        public static final int F12 = KeyEvent.VK_F12;
+
+        public static final int UNDEFINED = KeyEvent.VK_UNDEFINED;
+    }
+
+    private static int modifiers = 0;
+
+    /**
+     * Returns a bitfield representing the keyboard modifiers that are
+     * currently pressed.
+     */
+    public static int getModifiers() {
+        return modifiers;
+    }
+
+    protected static void setModifiers(int modifiers) {
+        Keyboard.modifiers = modifiers;
+    }
+
+    /**
+     * Tests the pressed state of a modifier.
+     *
+     * @param modifier
+     *
+     * @return
+     * <tt>true</tt> if the modifier is pressed; <tt>false</tt>, otherwise.
+     */
+    public static boolean isPressed(Modifier modifier) {
+        return modifier.isSelected(getModifiers());
+    }
+
+    /**
+     * Returns the current drop action.
+     *
+     * @return
+     * The drop action corresponding to the currently pressed modifier keys,
+     * or <tt>null</tt> if no modifiers are pressed.
+     */
+    public static DropAction getDropAction() {
+        // TODO Return an appropriate action for OS
+        // Windows: no modifier - move; control - copy; control-shift - link
+        // Mac OSX: no modifier - move; option - copy; option-command - link
+
+        DropAction dropAction = null;
+
+        if (isPressed(Modifier.CTRL)
+            && isPressed(Modifier.SHIFT)) {
+            dropAction = DropAction.LINK;
+        } else if (isPressed(Modifier.CTRL)) {
+            dropAction = DropAction.COPY;
+        } else {
+            dropAction = DropAction.MOVE;
+        }
+
+        return dropAction;
+    }
+}
+

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Label.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Label.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Label.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/Label.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.collections.Dictionary;
+import pivot.util.ListenerList;
+
+/**
+ * Component that displays a string of text.
+ *
+ * @author gbrown
+ */
+public class Label extends Component {
+    private static class LabelListenerList extends ListenerList<LabelListener>
+        implements LabelListener {
+        public void textChanged(Label label, String previousText) {
+            for (LabelListener listener : this) {
+                listener.textChanged(label, previousText);
+            }
+        }
+
+        public void textKeyChanged(Label label, String previousTextKey) {
+            for (LabelListener listener : this) {
+                listener.textKeyChanged(label, previousTextKey);
+            }
+        }
+    }
+
+    private String text = null;
+    private String textKey = null;
+    private LabelListenerList labelListeners = new LabelListenerList();
+
+    public Label() {
+        this(null);
+    }
+
+    public Label(String text) {
+        this.text = text;
+
+        installSkin(Label.class);
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public void setText(String text) {
+        String previousText = this.text;
+        this.text = text;
+        labelListeners.textChanged(this, previousText);
+    }
+
+    /**
+     * Returns the label's text key.
+     *
+     * @return
+     * The text key, or <tt>null</tt> if no text key is set.
+     */
+    public String getTextKey() {
+        return textKey;
+    }
+
+    /**
+     * Sets the label's text key.
+     *
+     * @param textKey
+     * The text key, or <tt>null</tt> to clear the binding.
+     */
+    public void setTextKey(String textKey) {
+        String previousTextKey = this.textKey;
+
+        if ((previousTextKey != null
+            && textKey != null
+            && !previousTextKey.equals(textKey))
+            || previousTextKey != textKey) {
+            this.textKey = textKey;
+            labelListeners.textKeyChanged(this, previousTextKey);
+        }
+    }
+
+    @Override
+    public void load(Dictionary<String, ?> context) {
+        if (textKey != null
+            && context.containsKey(textKey)) {
+            Object value = context.get(textKey);
+            if (value != null) {
+            	value = value.toString();
+            }
+
+        	setText((String)value);
+        }
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void store(Dictionary<String, ?> context) {
+        if (textKey != null) {
+            ((Dictionary<String, String>)context).put(textKey, getText());
+        }
+    }
+
+    public ListenerList<LabelListener> getLabelListeners() {
+        return labelListeners;
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LabelListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LabelListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LabelListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LabelListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * Label listener interface.
+ *
+ * @author gbrown
+ */
+public interface LabelListener {
+    /**
+     * Called when a label's text has changed.
+     *
+     * @param label
+     * @param previousText
+     */
+    public void textChanged(Label label, String previousText);
+
+    /**
+     * Called when a label's text key has changed.
+     *
+     * @param label
+     * @param previousTextKey
+     */
+    public void textKeyChanged(Label label, String previousTextKey);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LinkButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LinkButton.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LinkButton.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/LinkButton.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.wtk.content.LinkButtonDataRenderer;
+
+/**
+ * Button component that resembles an HTML hyperlink.
+ *
+ * @author gbrown
+ */
+public class LinkButton extends Button {
+    private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new LinkButtonDataRenderer();
+
+    public LinkButton() {
+        this(null);
+    }
+
+    public LinkButton(Object buttonData) {
+        super(buttonData);
+        setDataRenderer(DEFAULT_DATA_RENDERER);
+
+        installSkin(LinkButton.class);
+    }
+
+    @Override
+    public void setToggleButton(boolean toggleButton) {
+        throw new UnsupportedOperationException("Link buttons cannot be toggle buttons.");
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButton.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButton.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButton.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButton.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.collections.ArrayList;
+import pivot.collections.List;
+import pivot.collections.Dictionary;
+import pivot.serialization.JSONSerializer;
+import pivot.util.ListenerList;
+import pivot.wtk.content.ListButtonDataRenderer;
+import pivot.wtk.content.ListViewItemRenderer;
+
+/**
+ * Component that allows a user to select one of several list options. The
+ * options are hidden until the user pushes the button.
+ *
+ * @author gbrown
+ */
+public class ListButton extends Button {
+    /**
+     * List button listener list.
+     *
+     * @author gbrown
+     */
+    private static class ListButtonListenerList extends ListenerList<ListButtonListener>
+        implements ListButtonListener {
+        public void listDataChanged(ListButton listButton, List<?> previousListData) {
+            for (ListButtonListener listener : this) {
+                listener.listDataChanged(listButton, previousListData);
+            }
+        }
+
+        public void itemRendererChanged(ListButton listButton, ListView.ItemRenderer previousItemRenderer) {
+            for (ListButtonListener listener : this) {
+                listener.itemRendererChanged(listButton, previousItemRenderer);
+            }
+        }
+
+        public void selectedItemKeyChanged(ListButton listButton, String previousSelectedItemKey) {
+            for (ListButtonListener listener : this) {
+                listener.selectedItemKeyChanged(listButton, previousSelectedItemKey);
+            }
+        }
+    }
+
+    /**
+     * List button selection listener list.
+     *
+     * @author gbrown
+     */
+    private static class ListButtonSelectionListenerList extends ListenerList<ListButtonSelectionListener>
+        implements ListButtonSelectionListener {
+        public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex) {
+            for (ListButtonSelectionListener listener : this) {
+                listener.selectedIndexChanged(listButton, previousSelectedIndex);
+            }
+        }
+    }
+
+    private List<?> listData;
+    private ListView.ItemRenderer itemRenderer = null;
+    private int selectedIndex = -1;
+    private String selectedItemKey = null;
+
+    private ListButtonListenerList listButtonListeners = new ListButtonListenerList();
+    private ListButtonSelectionListenerList listButtonSelectionListeners = new ListButtonSelectionListenerList();
+
+    private static final Button.DataRenderer DEFAULT_DATA_RENDERER = new ListButtonDataRenderer();
+    private static final ListView.ItemRenderer DEFAULT_ITEM_RENDERER = new ListViewItemRenderer();
+
+    /**
+     * Creates an empty list button.
+     */
+    public ListButton() {
+        this(new ArrayList<Object>());
+    }
+
+    /**
+     * Creates a list button with the given button data and an empty list.
+     *
+     * @param buttonData
+     */
+    public ListButton(Object buttonData) {
+        this(buttonData, new ArrayList<Object>());
+    }
+
+    /**
+     * Creates a list button with no button data and the given list data.
+     * @param listData
+     */
+    public ListButton(List<?> listData) {
+        this(null, listData);
+    }
+
+    /**
+     * Creates a list button with the given button and list data.
+     *
+     * @param buttonData
+     * @param listData
+     */
+    public ListButton(Object buttonData, List<?> listData) {
+        super(buttonData);
+
+        setDataRenderer(DEFAULT_DATA_RENDERER);
+        setItemRenderer(DEFAULT_ITEM_RENDERER);
+        setListData(listData);
+
+        installSkin(ListButton.class);
+    }
+
+    /**
+     * @throws UnsupportedOperationException
+     * This method is not supported by ListButton.
+     */
+    @Override
+    public void setToggleButton(boolean toggleButton) {
+        throw new UnsupportedOperationException("List buttons cannot be toggle buttons.");
+    }
+
+    /**
+     * Returns the list data associated with this list button.
+     *
+     * @return
+     * The list data.
+     */
+    public List<?> getListData() {
+        return listData;
+    }
+
+    /**
+     * Sets the list button's list data.
+     *
+     * @param listData
+     * The list data to be presented by the list button.
+     */
+    @SuppressWarnings("unchecked")
+    public void setListData(List<?> listData) {
+        if (listData == null) {
+            throw new IllegalArgumentException("listData is null.");
+        }
+
+        List<?> previousListData = this.listData;
+
+        if (previousListData != listData) {
+            if (previousListData != null) {
+                setSelectedIndex(-1);
+            }
+
+            // Update the list data and fire change event
+            this.listData = listData;
+            listButtonListeners.listDataChanged(this, previousListData);
+        }
+    }
+
+    /**
+     * Sets the list button's list data.
+     *
+     * @param listData
+     * The list data to be presented by the list button as a JSON array.
+     */
+    public void setListData(String listData) {
+        if (listData == null) {
+            throw new IllegalArgumentException("listData is null.");
+        }
+
+        setListData(JSONSerializer.parseList(listData));
+    }
+
+    /**
+     * Returns the renderer used to display items in the list.
+     *
+     * @return
+     * The item renderer instance.
+     */
+    public ListView.ItemRenderer getItemRenderer() {
+        return itemRenderer;
+    }
+
+    /**
+     * Sets the renderer used to display items in the list.
+     * <p>
+     * Use {@link #setDataRenderer(pivot.wtk.Button.DataRenderer)} to define
+     * the renderer used to draw the button data.
+     *
+     * @param itemRenderer
+     * The item renderer instance.
+     */
+    public void setItemRenderer(ListView.ItemRenderer itemRenderer) {
+        ListView.ItemRenderer previousItemRenderer = this.itemRenderer;
+
+        if (previousItemRenderer != itemRenderer) {
+            this.itemRenderer = itemRenderer;
+            listButtonListeners.itemRendererChanged(this, previousItemRenderer);
+        }
+    }
+
+    /**
+     * Returns the current selection.
+     *
+     * @return
+     * The index of the currently selected list item, or <tt>-1</tt> if
+     * nothing is selected.
+     */
+    public int getSelectedIndex() {
+        return selectedIndex;
+    }
+
+    /**
+     * Sets the selection.
+     *
+     * @param selectedIndex
+     * The index of the list item to select, or <tt>-1</tt> to clear the
+     * selection.
+     */
+    public void setSelectedIndex(int selectedIndex) {
+        int previousSelectedIndex = this.selectedIndex;
+
+        if (previousSelectedIndex != selectedIndex) {
+            this.selectedIndex = selectedIndex;
+            listButtonSelectionListeners.selectedIndexChanged(this, previousSelectedIndex);
+        }
+    }
+
+    public Object getSelectedItem() {
+        int index = getSelectedIndex();
+        Object item = null;
+
+        if (index >= 0) {
+            item = listData.get(index);
+        }
+
+        return item;
+    }
+
+    @SuppressWarnings("unchecked")
+    public void setSelectedItem(Object item) {
+        if (item == null) {
+            throw new IllegalArgumentException("item is null");
+        }
+
+        int index = ((List<Object>)listData).indexOf(item);
+        if (index == -1) {
+            throw new IllegalArgumentException("\"" + item + "\" is not a valid selection.");
+        }
+
+        setSelectedIndex(index);
+    }
+
+    public String getSelectedItemKey() {
+        return selectedItemKey;
+    }
+
+    public void setSelectedItemKey(String selectedItemKey) {
+        String previousSelectedItemKey = this.selectedItemKey;
+        this.selectedItemKey = selectedItemKey;
+        listButtonListeners.selectedItemKeyChanged(this, previousSelectedItemKey);
+    }
+
+    @Override
+    public void load(Dictionary<String, ?> context) {
+        if (selectedItemKey != null
+            && context.containsKey(selectedItemKey)) {
+            Object item = context.get(selectedItemKey);
+            setSelectedItem(item);
+        }
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void store(Dictionary<String, ?> context) {
+        if (selectedItemKey != null) {
+            Object item = getSelectedItem();
+            ((Dictionary<String, Object>)context).put(selectedItemKey, item);
+        }
+    }
+
+    /**
+     * Returns the list button listener list.
+     */
+    public ListenerList<ListButtonListener> getListButtonListeners() {
+        return listButtonListeners;
+    }
+
+    /**
+     * Returns the list button selection listener list.
+     */
+    public ListenerList<ListButtonSelectionListener> getListButtonSelectionListeners() {
+        return listButtonSelectionListeners;
+    }
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+import pivot.collections.List;
+
+/**
+ * List button listener list interface.
+ *
+ * @author gbrown
+ */
+public interface ListButtonListener {
+    /**
+     * Called when a list button's list data has changed.
+     *
+     * @param listButton
+     * @param previousListData
+     */
+    public void listDataChanged(ListButton listButton, List<?> previousListData);
+
+    /**
+     * Called when a list button's item renderer has changed.
+     *
+     * @param listButton
+     * @param previousItemRenderer
+     */
+    public void itemRendererChanged(ListButton listButton, ListView.ItemRenderer previousItemRenderer);
+
+    /**
+     * Called when a list button's selected value key has changed.
+     *
+     * @param listButton
+     * @param previousSelectedItemKey
+     */
+    public void selectedItemKeyChanged(ListButton listButton, String previousSelectedItemKey);
+}

Added: incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonSelectionListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonSelectionListener.java?rev=758461&view=auto
==============================================================================
--- incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonSelectionListener.java (added)
+++ incubator/pivot/branches/1.1/wtk/src/pivot/wtk/ListButtonSelectionListener.java Wed Mar 25 23:08:38 2009
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2008 VMware, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk;
+
+/**
+ * List button selection listener interface.
+ *
+ * @author gbrown
+ */
+public interface ListButtonSelectionListener {
+    /**
+     * Called when a list button's selected index has changed.
+     *
+     * @param listButton
+     * @param previousSelectedIndex
+     */
+    public void selectedIndexChanged(ListButton listButton, int previousSelectedIndex);
+}