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/16 17:36:28 UTC
svn commit: r754936 [12/38] - in /incubator/pivot/tags/v1.0.1: ./
charts-test/ charts-test/src/ charts-test/src/pivot/
charts-test/src/pivot/charts/ charts-test/src/pivot/charts/test/ charts/
charts/lib/ charts/src/ charts/src/pivot/ charts/src/pivot/c...
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_popup.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_popup.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_popup.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_popup.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<Menu xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008" xmlns="pivot.wtk">
+ <sections>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 1" styles="{popupBorderColor:'#ff0000'}">
+ <menu>
+ <Menu>
+ <sections>
+ <Menu.Section>
+ <Menu.Item action="testAction">
+ <buttonData text="Menu Item 1A" keyboardShortcut="META-A"/>
+ </Menu.Item>
+ <Menu.Item>
+ <buttonData text="Menu Item 1Ax" keyboardShortcut="CTRL-ALT-X"/>
+ </Menu.Item>
+ <Menu.Item buttonData="Menu Item 1B">
+ <menu>
+ <Menu>
+ <sections>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 1Bi"/>
+ <Menu.Item buttonData="Menu Item 1Bii"/>
+ <Menu.Item buttonData="Menu Item 1Biii"/>
+ </Menu.Section>
+ </sections>
+ </Menu>
+ </menu>
+ </Menu.Item>
+ <Menu.Item buttonData="Menu Item 1C" action="testAction"/>
+ <Menu.Item buttonData="Menu Item 1D">
+ <menu>
+ <Menu>
+ <sections>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 1Di"/>
+ <Menu.Item buttonData="Menu Item 1Dii" displayable="false"/>
+ <Menu.Item buttonData="Menu Item 1Diii"/>
+ </Menu.Section>
+ </sections>
+ </Menu>
+ </menu>
+ </Menu.Item>
+ </Menu.Section>
+ </sections>
+ </Menu>
+ </menu>
+ </Menu.Item>
+ <Menu.Item buttonData="Menu Item 2" toggleButton="true" selected="true"/>
+ </Menu.Section>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 3" toggleButton="true" group="a" selected="true"/>
+ <Menu.Item buttonData="Menu Item 4" toggleButton="true" group="a" />
+ <Menu.Item buttonData="Menu Item 5" toggleButton="true" group="a" />
+ </Menu.Section>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 6">
+ <menu>
+ <Menu>
+ <sections>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 6A"/>
+ <Menu.Item buttonData="Menu Item 6B"/>
+ </Menu.Section>
+ </sections>
+ </Menu>
+ </menu>
+ </Menu.Item>
+ <Menu.Item buttonData="Menu Item 7"/>
+ </Menu.Section>
+ </sections>
+</Menu>
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_test.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_test.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/menu_test.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<TablePane styles="{backgroundColor:'#cccac2'}"
+ xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008" xmlns="pivot.wtk">
+ <columns>
+ <TablePane.Column width="1*"/>
+ </columns>
+ <rows>
+ <TablePane.Row height="-1">
+ <wtkx:include wtkx:id="menuBar" src="menu_bar.wtkx"/>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <FlowPane>
+ <MenuButton buttonData="Menu Button">
+ <menu>
+ <Menu>
+ <sections>
+ <Menu.Section>
+ <Menu.Item buttonData="Menu Item 1" action="testAction"/>
+ <Menu.Item buttonData="Menu Item 2"/>
+ <Menu.Item buttonData="Menu Item 3"/>
+ </Menu.Section>
+ </sections>
+ </Menu>
+ </menu>
+ </MenuButton>
+ </FlowPane>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <Separator styles="{color:'#999999', padding:0}"/>
+ </TablePane.Row>
+ <TablePane.Row height="1*">
+ <Label wtkx:id="label" text="Right-click Me"
+ styles="{horizontalAlignment:'center', verticalAlignment:'center'}"/>
+ </TablePane.Row>
+ </rows>
+</TablePane>
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/panorama_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/panorama_test.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/panorama_test.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/panorama_test.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<TabPane selectedIndex="0"
+ xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008" xmlns="pivot.wtk">
+ <tabs>
+ <Label TabPane.name="Tab 1" preferredWidth="320" preferredHeight="240" text="Tab 1"/>
+ <Label TabPane.name="Tab 2" preferredWidth="320" preferredHeight="240" text="Tab 2"/>
+ <Label TabPane.name="Tab 3" preferredWidth="320" preferredHeight="240" text="Tab 3"/>
+ <Label TabPane.name="Tab 4" preferredWidth="320" preferredHeight="240" text="Tab 4"/>
+ <Label TabPane.name="Tab 5" preferredWidth="320" preferredHeight="240" text="Tab 5"/>
+ <Label TabPane.name="Tab 6" preferredWidth="320" preferredHeight="240" text="Tab 6"/>
+ <Label TabPane.name="Tab 7" preferredWidth="320" preferredHeight="240" text="Tab 7"/>
+ <Label TabPane.name="Tab 8" preferredWidth="320" preferredHeight="240" text="Tab 8"/>
+ <Label TabPane.name="Tab 9" preferredWidth="320" preferredHeight="240" text="Tab 9"/>
+ <Label TabPane.name="Tab 10" preferredWidth="320" preferredHeight="240" text="Tab 10"/>
+ </tabs>
+</TabPane>
+
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/spinner_focus_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/spinner_focus_test.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/spinner_focus_test.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/spinner_focus_test.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<FlowPane styles="{verticalAlignment:'center'}"
+ xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008" xmlns="pivot.wtk">
+ <PushButton wtkx:id="pushButton" buttonData="Button" action="buttonAction"/>
+ <Spinner wtkx:id="spinner" preferredWidth="60"
+ spinnerData="['One', 'Two', 'Three', 'Four', 'Five']" circular="true"
+ selectedIndex="0"/>
+</FlowPane>
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/swing_adapter_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/swing_adapter_test.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/swing_adapter_test.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/swing_adapter_test.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<Frame title="Swing Adapter Test"
+ preferredWidth="480"
+ preferredHeight="360"
+ xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008"
+ xmlns:swing="javax.swing"
+ xmlns="pivot.wtk">
+ <content>
+ <FlowPane orientation="vertical"
+ styles="{horizontalAlignment:'justify', verticalAlignment:'justify'}">
+ <TabPane selectedIndex="0">
+ <tabs>
+ <SwingAdapter TabPane.name="JTextArea">
+ <swingComponent>
+ <swing:JScrollPane doubleBuffered="true">
+ <viewport>
+ <swing:JViewport>
+ <view>
+ <swing:JTextArea lineWrap="true"
+ text="Enter your greeting here..." />
+ </view>
+ </swing:JViewport>
+ </viewport>
+ </swing:JScrollPane>
+ </swingComponent>
+ </SwingAdapter>
+ <FlowPane TabPane.name="Empty" />
+ </tabs>
+ </TabPane>
+ <TextInput text="Does this compete for focus?" />
+ </FlowPane>
+ </content>
+</Frame>
Added: incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/table_pane_test.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/table_pane_test.wtkx?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/table_pane_test.wtkx (added)
+++ incubator/pivot/tags/v1.0.1/wtk-test/src/pivot/wtk/test/table_pane_test.wtkx Mon Mar 16 16:36:10 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<TablePane xmlns:wtkx="http://pivot-toolkit.org/wtkx/2008" xmlns="pivot.wtk">
+ <columns>
+ <TablePane.Column width="-1"/>
+ <TablePane.Column width="1*"/>
+ </columns>
+
+ <rows>
+ <TablePane.Row height="1*">
+ <PushButton buttonData="Hello World" TablePane.columnSpan="2"/>
+ </TablePane.Row>
+ </rows>
+</TablePane>
+
Added: incubator/pivot/tags/v1.0.1/wtk/.classpath
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/.classpath?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/.classpath (added)
+++ incubator/pivot/tags/v1.0.1/wtk/.classpath Mon Mar 16 16:36:10 2009
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/core"/>
+ <classpathentry kind="lib" path="lib/stax-1.2.0.jar"/>
+ <classpathentry kind="lib" path="lib/stax-api-1.0.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: incubator/pivot/tags/v1.0.1/wtk/.project
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/.project?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/.project (added)
+++ incubator/pivot/tags/v1.0.1/wtk/.project Mon Mar 16 16:36:10 2009
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>wtk</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: incubator/pivot/tags/v1.0.1/wtk/lib/stax-1.2.0.jar
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/lib/stax-1.2.0.jar?rev=754936&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/pivot/tags/v1.0.1/wtk/lib/stax-1.2.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/pivot/tags/v1.0.1/wtk/lib/stax-api-1.0.jar
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/lib/stax-api-1.0.jar?rev=754936&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/pivot/tags/v1.0.1/wtk/lib/stax-api-1.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/pivot/tags/v1.0.1/wtk/services/javax.xml.stream.XMLInputFactory
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/services/javax.xml.stream.XMLInputFactory?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/services/javax.xml.stream.XMLInputFactory (added)
+++ incubator/pivot/tags/v1.0.1/wtk/services/javax.xml.stream.XMLInputFactory Mon Mar 16 16:36:10 2009
@@ -0,0 +1 @@
+com.bea.xml.stream.MXParserFactory
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Accordion.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Accordion.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Accordion.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Accordion.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,318 @@
+/*
+ * 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 java.util.Iterator;
+
+import pivot.collections.ArrayList;
+import pivot.collections.Sequence;
+import pivot.util.ImmutableIterator;
+import pivot.util.ListenerList;
+import pivot.wtk.media.Image;
+
+/**
+ * Component that provides access to a set of components via selectable headers.
+ * Only one component is visible at a time.
+ * <p>
+ * TODO Add a getPanelAt() method that delegates to the skin.
+ *
+ * @author gbrown
+ */
+public class Accordion extends Container {
+ /**
+ * Defines accordion panel attributes.
+ *
+ * @author gbrown
+ */
+ protected static class AccordionAttributes extends Attributes {
+ private String name = null;
+ private Image icon = null;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ String previousName = this.name;
+ this.name = name;
+
+ Component component = getComponent();
+ Accordion accordion = (Accordion)component.getParent();
+ if (accordion != null) {
+ accordion.accordionAttributeListeners.nameChanged(accordion, component, previousName);
+ }
+ }
+
+ public Image getIcon() {
+ return icon;
+ }
+
+ public void setIcon(Image icon) {
+ Image previousIcon = this.icon;
+ this.icon = icon;
+
+ Component component = getComponent();
+ Accordion accordion = (Accordion)component.getParent();
+ if (accordion != null) {
+ accordion.accordionAttributeListeners.iconChanged(accordion, component, previousIcon);
+ }
+ }
+ }
+
+ /**
+ * Panel sequence implementation.
+ *
+ * @author gbrown
+ */
+ public final class PanelSequence implements Sequence<Component>, Iterable<Component> {
+ private PanelSequence() {
+ }
+
+ public int add(Component panel) {
+ int i = getLength();
+ insert(panel, i);
+
+ return i;
+ }
+
+ public void insert(Component panel, int index) {
+ if (panel == null) {
+ throw new IllegalArgumentException("panel is null.");
+ }
+
+ if (panel.getParent() != null) {
+ throw new IllegalArgumentException("Panel already has a parent.");
+ }
+
+ // Add the panel to the component sequence
+ Accordion.this.add(panel);
+ panels.insert(panel, index);
+
+ // Attach the attributes
+ panel.setAttributes(new AccordionAttributes());
+
+ accordionListeners.panelInserted(Accordion.this, index);
+
+ // If the selected panel's index changed as a result of
+ // this insertion, update it
+ if (selectedIndex >= index) {
+ setSelectedIndex(selectedIndex + 1);
+ }
+ }
+
+ public Component update(int index, Component panel) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int remove(Component panel) {
+ int index = indexOf(panel);
+ if (index != -1) {
+ remove(index, 1);
+ }
+
+ return index;
+ }
+
+ public Sequence<Component> remove(int index, int count) {
+ // If the selected panel is being removed, clear the selection
+ if (selectedIndex >= index
+ && selectedIndex < index + count) {
+ setSelectedIndex(-1);
+ }
+
+ // Remove the panels from the panel list
+ Sequence<Component> removed = panels.remove(index, count);
+
+ // Detach the attributes
+ for (int i = 0, n = removed.getLength(); i < n; i++) {
+ removed.get(i).setAttributes(null);
+ }
+
+ accordionListeners.panelsRemoved(Accordion.this, index, removed);
+
+ // Remove the panels from the component list
+ for (int i = 0, n = removed.getLength(); i < n; i++) {
+ Component panel = removed.get(i);
+ Accordion.this.remove(panel);
+ }
+
+ return removed;
+ }
+
+ public Component get(int index) {
+ return panels.get(index);
+ }
+
+ public int indexOf(Component panel) {
+ return panels.indexOf(panel);
+ }
+
+ public int getLength() {
+ return panels.getLength();
+ }
+
+ public Iterator<Component> iterator() {
+ return new ImmutableIterator<Component>(panels.iterator());
+ }
+ }
+
+ private static class AccordionListenerList extends ListenerList<AccordionListener>
+ implements AccordionListener {
+ public void panelInserted(Accordion accordion, int index) {
+ for (AccordionListener listener : this) {
+ listener.panelInserted(accordion, index);
+ }
+ }
+
+ public void panelsRemoved(Accordion accordion, int index, Sequence<Component> panels) {
+ for (AccordionListener listener : this) {
+ listener.panelsRemoved(accordion, index, panels);
+ }
+ }
+ }
+
+ private static class AccordionSelectionListenerList extends ListenerList<AccordionSelectionListener>
+ implements AccordionSelectionListener {
+ public void selectedIndexChanged(Accordion accordion, int previousSelectedIndex) {
+ for (AccordionSelectionListener listener : this) {
+ listener.selectedIndexChanged(accordion, previousSelectedIndex);
+ }
+ }
+ }
+
+ private static class AccordionAttributeListenerList extends ListenerList<AccordionAttributeListener>
+ implements AccordionAttributeListener {
+ public void nameChanged(Accordion accordion, Component component, String previousName) {
+ for (AccordionAttributeListener listener : this) {
+ listener.nameChanged(accordion, component, previousName);
+ }
+ }
+
+ public void iconChanged(Accordion accordion, Component component, Image previousIcon) {
+ for (AccordionAttributeListener listener : this) {
+ listener.iconChanged(accordion, component, previousIcon);
+ }
+ }
+ }
+
+ private int selectedIndex = -1;
+
+ private ArrayList<Component> panels = new ArrayList<Component>();
+ private PanelSequence panelSequence = new PanelSequence();
+
+ private AccordionListenerList accordionListeners = new AccordionListenerList();
+ private AccordionSelectionListenerList accordionSelectionListeners = new AccordionSelectionListenerList();
+ private AccordionAttributeListenerList accordionAttributeListeners = new AccordionAttributeListenerList();
+
+ public Accordion() {
+ installSkin(Accordion.class);
+ }
+
+ public int getSelectedIndex() {
+ return selectedIndex;
+ }
+
+ public void setSelectedIndex(int selectedIndex) {
+ int previousSelectedIndex = this.selectedIndex;
+
+ if (previousSelectedIndex != selectedIndex) {
+ this.selectedIndex = selectedIndex;
+ accordionSelectionListeners.selectedIndexChanged(this, previousSelectedIndex);
+ }
+ }
+
+ public PanelSequence getPanels() {
+ return panelSequence;
+ }
+
+ @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);
+ }
+
+ public ListenerList<AccordionListener> getAccordionListeners() {
+ return accordionListeners;
+ }
+
+ public ListenerList<AccordionSelectionListener> getAccordionSelectionListeners() {
+ return accordionSelectionListeners;
+ }
+
+ public ListenerList<AccordionAttributeListener> getAccordionAttributeListeners() {
+ return accordionAttributeListeners;
+ }
+
+ public static String getName(Component component) {
+ AccordionAttributes accordionAttributes = (AccordionAttributes)component.getAttributes();
+ return (accordionAttributes == null) ? null : accordionAttributes.getName();
+ }
+
+ public static void setName(Component component, String name) {
+ AccordionAttributes accordionAttributes = (AccordionAttributes)component.getAttributes();
+ if (accordionAttributes == null) {
+ throw new IllegalStateException();
+ }
+
+ accordionAttributes.setName(name);
+ }
+
+ public static Image getIcon(Component component) {
+ AccordionAttributes accordionAttributes = (AccordionAttributes)component.getAttributes();
+ return (accordionAttributes == null) ? null : accordionAttributes.getIcon();
+ }
+
+ public static void setIcon(Component component, Image icon) {
+ AccordionAttributes accordionAttributes = (AccordionAttributes)component.getAttributes();
+ if (accordionAttributes == null) {
+ throw new IllegalStateException();
+ }
+
+ accordionAttributes.setIcon(icon);
+ }
+
+ public static final void setIcon(Component component, URL icon) {
+ if (icon == null) {
+ throw new IllegalArgumentException("icon is null.");
+ }
+
+ Image iconImage = (Image)ApplicationContext.getResourceCache().get(icon);
+
+ if (iconImage == null) {
+ iconImage = Image.load(icon);
+ ApplicationContext.getResourceCache().put(icon, iconImage);
+ }
+
+ setIcon(component, iconImage);
+ }
+
+ public static final void setIcon(Component component, String icon) {
+ if (icon == null) {
+ throw new IllegalArgumentException("icon is null.");
+ }
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ setIcon(component, classLoader.getResource(icon));
+ }
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionAttributeListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionAttributeListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionAttributeListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionAttributeListener.java Mon Mar 16 16:36:10 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.media.Image;
+
+/**
+ * Accordion attribute listener interface.
+ *
+ * @author gbrown
+ */
+public interface AccordionAttributeListener {
+ /**
+ * Called when a panel's name attribute has changed.
+ *
+ * @param accordion
+ * @param component
+ * @param previousName
+ */
+ public void nameChanged(Accordion accordion, Component component, String previousName);
+
+ /**
+ * Called when a panel's icon attribute has changed.
+ *
+ * @param accordion
+ * @param component
+ * @param previousIcon
+ */
+ public void iconChanged(Accordion accordion, Component component, Image previousIcon);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionListener.java Mon Mar 16 16:36:10 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;
+
+import pivot.collections.Sequence;
+
+/**
+ * Accordion listener interface.
+ *
+ * @author gbrown
+ */
+public interface AccordionListener {
+ /**
+ * Called when a panel has been inserted into a accordion's panel sequence.
+ *
+ * @param accordion
+ * @param index
+ */
+ public void panelInserted(Accordion accordion, int index);
+
+ /**
+ * Called when a panel has been removed from an accordion's panel sequence.
+ *
+ * @param accordion
+ * @param index
+ * @param panels
+ */
+ public void panelsRemoved(Accordion accordion, int index, Sequence<Component> panels);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionSelectionListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionSelectionListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionSelectionListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AccordionSelectionListener.java Mon Mar 16 16:36:10 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;
+
+/**
+ * Accordion selection listener interface.
+ *
+ * @author gbrown
+ */
+public interface AccordionSelectionListener {
+ /**
+ * Called when an accordion's selected index has changed.
+ *
+ * @param accordion
+ * @param previousSelectedIndex
+ */
+ public void selectedIndexChanged(Accordion accordion, int previousSelectedIndex);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Action.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Action.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Action.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Action.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,148 @@
+/*
+ * 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.Dictionary;
+import pivot.collections.HashMap;
+import pivot.util.ImmutableIterator;
+import pivot.util.ListenerList;
+
+/**
+ * Abstract base class for "actions". Actions are common application
+ * behaviors generally triggered by buttons and keyboard shortcuts.
+ *
+ * @author gbrown
+ */
+public abstract class Action {
+ /**
+ * Action dictionary implementation.
+ *
+ * @author gbrown
+ */
+ public static final class ActionDictionary
+ implements Dictionary<String, Action>, Iterable<String> {
+ private ActionDictionary() {
+ }
+
+ public Action get(String id) {
+ return actions.get(id);
+ }
+
+ public Action put(String id, Action action) {
+ if (action == null) {
+ throw new IllegalArgumentException("action is null.");
+ }
+
+ Action previousAction = actions.put(id, action);
+
+ if (previousAction != null) {
+ previousAction.id = null;
+ }
+
+ action.id = id;
+
+ // TODO Fire ActionClassListener#actionAdded()/actionUpdated()
+
+ return previousAction;
+ }
+
+ public Action remove(String id) {
+ Action previousAction = actions.remove(id);
+
+ if (previousAction != null) {
+ previousAction.id = null;
+ }
+
+ // TODO Fire ActionClassListener#actionRemoved()
+
+ return previousAction;
+ }
+
+ public boolean containsKey(String id) {
+ return actions.containsKey(id);
+ }
+
+ public boolean isEmpty() {
+ return actions.isEmpty();
+ }
+
+ public Iterator<String> iterator() {
+ return new ImmutableIterator<String>(actions.iterator());
+ }
+ }
+
+ private static class ActionListenerList extends ListenerList<ActionListener>
+ implements ActionListener {
+ public void enabledChanged(Action action) {
+ for (ActionListener listener : this) {
+ listener.enabledChanged(action);
+ }
+ }
+ }
+
+ private String id;
+ private boolean enabled = true;
+
+ private ActionListenerList actionListeners = new ActionListenerList();
+
+ private static HashMap<String, Action> actions = new HashMap<String, Action>();
+ private static ActionDictionary actionDictionary = new ActionDictionary();
+
+ public Action() {
+ this(null);
+ }
+
+ public Action(String id) {
+ if (id != null) {
+ actions.put(id, this);
+ }
+ }
+
+ public String getID() {
+ return id;
+ }
+
+ /**
+ * Returns a text description of the action.
+ */
+ public abstract String getDescription();
+
+ /**
+ * Performs the action.
+ */
+ public abstract void perform();
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ if (this.enabled != enabled) {
+ this.enabled = enabled;
+ actionListeners.enabledChanged(this);
+ }
+ }
+
+ public static ActionDictionary getActions() {
+ return actionDictionary;
+ }
+
+ public ListenerList<ActionListener> getActionListeners() {
+ return actionListeners;
+ }
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ActionListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ActionListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ActionListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ActionListener.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,15 @@
+package pivot.wtk;
+
+/**
+ * Action listener interface.
+ *
+ * @author gbrown
+ */
+public interface ActionListener {
+ /**
+ * Called when an action's enabled state has changed.
+ *
+ * @param action
+ */
+ public void enabledChanged(Action action);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,170 @@
+/*
+ * 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.Sequence;
+import pivot.util.ListenerList;
+import pivot.util.Resources;
+
+/**
+ * Class representing an "alert", a dialog commonly used to perform simple
+ * user interaction.
+ *
+ * @author tvolkert
+ * @author gbrown
+ */
+public class Alert extends Dialog {
+ private static class AlertListenerList extends ListenerList<AlertListener>
+ implements AlertListener {
+ public void selectedOptionChanged(Alert alert, int previousSelectedOption) {
+ for (AlertListener listener : this) {
+ listener.selectedOptionChanged(alert, previousSelectedOption);
+ }
+ }
+ }
+
+ private MessageType type = null;
+ private String message = null;
+ private Component body = null;
+ private Sequence<?> options = null;
+ private int selectedOption = -1;
+
+ private AlertListenerList alertListeners = new AlertListenerList();
+
+ private static Resources resources = null;
+
+ static {
+ try {
+ resources = new Resources(Alert.class.getName());
+ } catch(Exception exception) {
+ throw new RuntimeException(exception);
+ }
+ }
+
+ public Alert(MessageType type, String message, Sequence<?> options) {
+ this(type, message, options, null);
+ }
+
+ public Alert(MessageType type, String message, Sequence<?> options, Component body) {
+ if (type == null) {
+ throw new IllegalArgumentException("type is null.");
+ }
+
+ if (options == null) {
+ throw new IllegalArgumentException("options is null.");
+ }
+
+ this.type = type;
+ this.message = message;
+ this.options = options;
+ this.body = body;
+
+ installSkin(Alert.class);
+ }
+
+ public MessageType getMessageType() {
+ return type;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public Object getOption(int index) {
+ return options.get(index);
+ }
+
+ public int getOptionCount() {
+ return options.getLength();
+ }
+
+ public Component getBody() {
+ return body;
+ }
+
+ public int getSelectedOption() {
+ return selectedOption;
+ }
+
+ public void setSelectedOption(int selectedOption) {
+ if (selectedOption < -1
+ || selectedOption > options.getLength() - 1) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ int previousSelectedOption = this.selectedOption;
+
+ if (selectedOption != previousSelectedOption) {
+ this.selectedOption = selectedOption;
+ alertListeners.selectedOptionChanged(this, previousSelectedOption);
+ }
+ }
+
+ public ListenerList<AlertListener> getAlertListeners() {
+ return alertListeners;
+ }
+
+ public static void alert(String message, Display display) {
+ alert(MessageType.INFO, message, display, null);
+ }
+
+ public static void alert(String message, Display display,
+ DialogStateListener dialogStateListener) {
+ alert(MessageType.INFO, message, display, dialogStateListener);
+ }
+
+ public static void alert(MessageType type, String message, Display display) {
+ alert(type, message, display, null);
+ }
+
+ public static void alert(MessageType type, String message, Display display,
+ DialogStateListener dialogStateListener) {
+ Alert alert = createAlert(type, message);
+ alert.open(display, dialogStateListener);
+ }
+
+ public static void alert(String message, Window owner) {
+ alert(MessageType.INFO, message, owner, null);
+ }
+
+ public static void alert(String message, Window owner,
+ DialogStateListener dialogStateListener) {
+ alert(MessageType.INFO, message, owner, dialogStateListener);
+ }
+
+ public static void alert(MessageType type, String message, Window owner) {
+ alert(type, message, owner, null);
+ }
+
+ public static void alert(MessageType type, String message, Window owner,
+ DialogStateListener dialogStateListener) {
+ Alert alert = createAlert(type, message);
+ alert.open(owner, dialogStateListener);
+ }
+
+ private static Alert createAlert(MessageType type, String message) {
+ List<Object> options = new ArrayList<Object>();
+ options.add(resources.get("defaultOption"));
+
+ Alert alert = new Alert(type, message, options, null);
+ alert.setTitle((String)resources.get("defaultTitle"));
+ alert.setSelectedOption(0);
+
+ return alert;
+ }
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.json
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.json?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.json (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Alert.json Mon Mar 16 16:36:10 2009
@@ -0,0 +1,3 @@
+{ defaultOption: "OK",
+ defaultTitle: "Alert"
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AlertListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AlertListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AlertListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/AlertListener.java Mon Mar 16 16:36:10 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;
+
+/**
+ * Alert listener interface.
+ *
+ * @author gbrown
+ */
+public interface AlertListener {
+ /**
+ * Called when an alert's selected option has changed.
+ *
+ * @param alert
+ * @param previousSelectedOption
+ */
+ public void selectedOptionChanged(Alert alert, int previousSelectedOption);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Application.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Application.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Application.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Application.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+/**
+ * Represents the entry point into a WTK application.
+ *
+ * @author gbrown
+ */
+public interface Application {
+ /**
+ * Called when the application is starting up.
+ *
+ * @param display
+ * The display on which this application was started.
+ *
+ * @param properties
+ * Initialization properties passed to the application.
+ */
+ public void startup(Display display, Dictionary<String, String> properties) throws Exception;
+
+ /**
+ * Called when the application is being shut down.
+ *
+ * @param optional
+ * If <tt>true</tt>, the shutdown may be canceled by returning a value of
+ * <tt>false</tt>.
+ *
+ * @return
+ * <tt>true</tt> to continue shutdown, <tt>false</tt> to cancel.
+ */
+ public boolean shutdown(boolean optional) throws Exception;
+
+ /**
+ * Called to notify the application that it is being suspended.
+ */
+ public void suspend() throws Exception;
+
+ /**
+ * Called when a suspended application has been resumed.
+ */
+ public void resume() throws Exception;
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ApplicationContext.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ApplicationContext.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/ApplicationContext.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,798 @@
+/*
+ * 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.AWTEvent;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.Toolkit;
+import java.awt.Transparency;
+import java.awt.event.ComponentEvent;
+import java.awt.event.FocusEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseWheelEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
+import pivot.collections.Dictionary;
+import pivot.collections.HashMap;
+import pivot.util.ImmutableIterator;
+
+/**
+ * Base class for application contexts.
+ * <p>
+ * TODO Fire events when entries are added to/removed from the cache?
+ *
+ * @author gbrown
+ */
+public abstract class ApplicationContext {
+ /**
+ * Resource cache dictionary implementation.
+ *
+ * @author gbrown
+ */
+ public static final class ResourceCacheDictionary
+ implements Dictionary<URL, Object>, Iterable<URL> {
+ public Object get(URL key) {
+ return resourceCache.get(key);
+ }
+
+ public Object put(URL key, Object value) {
+ return resourceCache.put(key, value);
+ }
+
+ public Object remove(URL key) {
+ return resourceCache.remove(key);
+ }
+
+ public boolean containsKey(URL key) {
+ return resourceCache.containsKey(key);
+ }
+
+ public boolean isEmpty() {
+ return resourceCache.isEmpty();
+ }
+
+ public Iterator<URL> iterator() {
+ return new ImmutableIterator<URL>(resourceCache.iterator());
+ }
+ }
+
+ /**
+ * Native AWT display host.
+ *
+ * @author gbrown
+ */
+ protected class DisplayHost extends java.awt.Container {
+ public static final long serialVersionUID = 0;
+
+ private Component focusedComponent = null;
+
+ protected DisplayHost() {
+ enableEvents(AWTEvent.COMPONENT_EVENT_MASK
+ | AWTEvent.FOCUS_EVENT_MASK
+ | AWTEvent.MOUSE_EVENT_MASK
+ | AWTEvent.MOUSE_MOTION_EVENT_MASK
+ | AWTEvent.MOUSE_WHEEL_EVENT_MASK
+ | AWTEvent.KEY_EVENT_MASK);
+
+ try {
+ System.setProperty("sun.awt.noerasebackground", "true");
+ System.setProperty("sun.awt.erasebackgroundonresize", "true");
+ } catch(SecurityException exception) {
+ }
+
+ setFocusTraversalKeysEnabled(false);
+ }
+
+ @Override
+ public void paint(Graphics graphics) {
+ // Intersect the clip region with the bounds of this component
+ // (for some reason, AWT does not do this automatically)
+ ((Graphics2D)graphics).clip(new java.awt.Rectangle(0, 0, getWidth(), getHeight()));
+
+ java.awt.Rectangle clipBounds = graphics.getClipBounds();
+ if (clipBounds != null
+ && !clipBounds.isEmpty()) {
+ try {
+ if (!paintVolatileBuffered((Graphics2D)graphics)) {
+ if (!paintBuffered((Graphics2D)graphics)) {
+ display.paint((Graphics2D)graphics);
+ dragDropManager.paint((Graphics2D)graphics);
+ }
+ }
+ } catch (RuntimeException exception) {
+ System.out.println("Exception thrown during paint(): " + exception);
+ throw exception;
+ }
+ }
+ }
+
+ /**
+ * Attempts to paint the display using an offscreen buffer.
+ *
+ * @param graphics
+ * The source graphics context.
+ *
+ * @return
+ * <tt>true</tt> if the display was painted using the offscreen
+ * buffer; <tt>false</tt>, otherwise.
+ */
+ private boolean paintBuffered(Graphics2D graphics) {
+ boolean painted = false;
+
+ // Paint the display into an offscreen buffer
+ GraphicsConfiguration gc = graphics.getDeviceConfiguration();
+ java.awt.Rectangle clipBounds = graphics.getClipBounds();
+ java.awt.image.BufferedImage bufferedImage =
+ gc.createCompatibleImage(clipBounds.width, clipBounds.height,
+ Transparency.OPAQUE);
+
+ if (bufferedImage != null) {
+ Graphics2D bufferedImageGraphics = (Graphics2D)bufferedImage.getGraphics();
+ bufferedImageGraphics.setClip(0, 0, clipBounds.width, clipBounds.height);
+ bufferedImageGraphics.translate(-clipBounds.x, -clipBounds.y);
+
+ try {
+ display.paint(bufferedImageGraphics);
+ dragDropManager.paint(bufferedImageGraphics);
+ graphics.drawImage(bufferedImage, clipBounds.x, clipBounds.y, this);
+ } finally {
+ bufferedImageGraphics.dispose();
+ }
+
+ painted = true;
+ }
+
+ return painted;
+ }
+
+ /**
+ * Attempts to paint the display using a volatile offscreen buffer.
+ *
+ * @param graphics
+ * The source graphics context.
+ *
+ * @return
+ * <tt>true</tt> if the display was painted using the offscreen
+ * buffer; <tt>false</tt>, otherwise.
+ */
+ private boolean paintVolatileBuffered(Graphics2D graphics) {
+ boolean painted = false;
+
+ // Paint the display into a volatile offscreen buffer
+ GraphicsConfiguration gc = graphics.getDeviceConfiguration();
+ java.awt.Rectangle clipBounds = graphics.getClipBounds();
+ java.awt.image.VolatileImage volatileImage =
+ gc.createCompatibleVolatileImage(clipBounds.width, clipBounds.height,
+ Transparency.OPAQUE);
+
+ // If we have a valid volatile image, attempt to paint the
+ // display to it
+ if (volatileImage != null) {
+ int valid = volatileImage.validate(getGraphicsConfiguration());
+
+ if (valid == java.awt.image.VolatileImage.IMAGE_OK
+ || valid == java.awt.image.VolatileImage.IMAGE_RESTORED) {
+ Graphics2D volatileImageGraphics = (Graphics2D)volatileImage.getGraphics();
+ volatileImageGraphics.setClip(0, 0, clipBounds.width, clipBounds.height);
+ volatileImageGraphics.translate(-clipBounds.x, -clipBounds.y);
+
+ try {
+ display.paint(volatileImageGraphics);
+ dragDropManager.paint(volatileImageGraphics);
+ graphics.drawImage(volatileImage, clipBounds.x, clipBounds.y, this);
+ } finally {
+ volatileImageGraphics.dispose();
+ }
+
+ painted = !volatileImage.contentsLost();
+ }
+ }
+
+ return painted;
+ }
+
+ @Override
+ protected void processComponentEvent(ComponentEvent event) {
+ super.processComponentEvent(event);
+
+ switch (event.getID()) {
+ case ComponentEvent.COMPONENT_RESIZED: {
+ display.setSize(getWidth(), getHeight());
+ break;
+ }
+
+ case ComponentEvent.COMPONENT_MOVED: {
+ // No-op
+ break;
+ }
+
+ case ComponentEvent.COMPONENT_SHOWN: {
+ // No-op
+ break;
+ }
+
+ case ComponentEvent.COMPONENT_HIDDEN: {
+ // No-op
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void processFocusEvent(FocusEvent event) {
+ super.processFocusEvent(event);
+
+ switch(event.getID()) {
+ case FocusEvent.FOCUS_GAINED: {
+ if (focusedComponent != null
+ && focusedComponent.isShowing()
+ && !focusedComponent.isBlocked()) {
+ focusedComponent.requestFocus(true);
+ }
+
+ break;
+ }
+
+ case FocusEvent.FOCUS_LOST: {
+ focusedComponent = Component.getFocusedComponent();
+ Component.clearFocus(true);
+
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void processMouseEvent(MouseEvent event) {
+ super.processMouseEvent(event);
+
+ // Get the event coordinates
+ int x = event.getX();
+ int y = event.getY();
+
+ // Set the Mouse button state
+ int modifierMask = event.getModifiersEx();
+ int buttonBitfield = 0x00;
+
+ if ((modifierMask & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
+ buttonBitfield |= Mouse.Button.LEFT.getMask();
+ }
+
+ if ((modifierMask & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) {
+ buttonBitfield |= Mouse.Button.MIDDLE.getMask();
+ }
+
+ if ((modifierMask & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
+ buttonBitfield |= Mouse.Button.RIGHT.getMask();
+ }
+
+ Mouse.setButtons(buttonBitfield);
+
+ // Get the button associated with this event
+ Mouse.Button button = null;
+ switch (event.getButton()) {
+ case MouseEvent.BUTTON1: {
+ button = Mouse.Button.LEFT;
+ break;
+ }
+
+ case MouseEvent.BUTTON2: {
+ button = Mouse.Button.MIDDLE;
+ break;
+ }
+
+ case MouseEvent.BUTTON3: {
+ button = Mouse.Button.RIGHT;
+ break;
+ }
+ }
+
+ // Process the event
+ switch (event.getID()) {
+ case MouseEvent.MOUSE_PRESSED: {
+ requestFocus();
+
+ display.mouseDown(button, x, y);
+ dragDropManager.mouseDown(button, x, y);
+ break;
+ }
+
+ case MouseEvent.MOUSE_RELEASED: {
+ display.mouseUp(button, x, y);
+ dragDropManager.mouseUp(button, x, y);
+ break;
+ }
+
+ case MouseEvent.MOUSE_ENTERED: {
+ display.mouseOver();
+ activeDisplayHost = this;
+ break;
+ }
+
+ case MouseEvent.MOUSE_EXITED: {
+ display.mouseOut();
+ activeDisplayHost = null;
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void processMouseMotionEvent(MouseEvent event) {
+ super.processMouseMotionEvent(event);
+
+ // Get the event coordinates
+ int x = event.getX();
+ int y = event.getY();
+
+ // Set the Mouse location state
+ Mouse.setLocation(x, y);
+
+ // Process the event
+ switch (event.getID()) {
+ case MouseEvent.MOUSE_MOVED:
+ case MouseEvent.MOUSE_DRAGGED: {
+ display.mouseMove(x, y);
+ dragDropManager.mouseMove(x, y);
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void processMouseWheelEvent(MouseWheelEvent event) {
+ super.processMouseWheelEvent(event);
+
+ // Get the event coordinates
+ int x = event.getX();
+ int y = event.getY();
+
+ // Get the scroll type
+ Mouse.ScrollType scrollType = null;
+ switch (event.getScrollType()) {
+ case MouseWheelEvent.WHEEL_BLOCK_SCROLL: {
+ scrollType = Mouse.ScrollType.BLOCK;
+ break;
+ }
+
+ case MouseWheelEvent.WHEEL_UNIT_SCROLL: {
+ scrollType = Mouse.ScrollType.UNIT;
+ break;
+ }
+ }
+
+ // Process the event
+ switch (event.getID()) {
+ case MouseEvent.MOUSE_WHEEL: {
+ display.mouseWheel(scrollType, event.getScrollAmount(),
+ event.getWheelRotation(), x, y);
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void processKeyEvent(KeyEvent event) {
+ super.processKeyEvent(event);
+
+ // Get the key location
+ Keyboard.KeyLocation keyLocation = null;
+ switch (event.getKeyLocation()) {
+ case KeyEvent.KEY_LOCATION_STANDARD: {
+ keyLocation = Keyboard.KeyLocation.STANDARD;
+ break;
+ }
+
+ case KeyEvent.KEY_LOCATION_LEFT: {
+ keyLocation = Keyboard.KeyLocation.LEFT;
+ break;
+ }
+
+ case KeyEvent.KEY_LOCATION_RIGHT: {
+ keyLocation = Keyboard.KeyLocation.RIGHT;
+ break;
+ }
+
+ case KeyEvent.KEY_LOCATION_NUMPAD: {
+ keyLocation = Keyboard.KeyLocation.KEYPAD;
+ break;
+ }
+ }
+
+ // Set Keyboard state
+ int awtModifiers = event.getModifiersEx();
+ int modifiers = 0x00;
+
+ if ((awtModifiers & KeyEvent.SHIFT_DOWN_MASK) == KeyEvent.SHIFT_DOWN_MASK) {
+ modifiers |= Keyboard.Modifier.SHIFT.getMask();
+ }
+
+ if ((awtModifiers & KeyEvent.CTRL_DOWN_MASK) == KeyEvent.CTRL_DOWN_MASK) {
+ modifiers |= Keyboard.Modifier.CTRL.getMask();
+ }
+
+ if ((awtModifiers & KeyEvent.ALT_DOWN_MASK) == KeyEvent.ALT_DOWN_MASK) {
+ modifiers |= Keyboard.Modifier.ALT.getMask();
+ }
+
+ if ((awtModifiers & KeyEvent.META_DOWN_MASK) == KeyEvent.META_DOWN_MASK) {
+ modifiers |= Keyboard.Modifier.META.getMask();
+ }
+
+ Keyboard.setModifiers(modifiers);
+
+ // Process the event
+ Component focusedComponent = Component.getFocusedComponent();
+
+ switch (event.getID()) {
+ case KeyEvent.KEY_TYPED: {
+ if (focusedComponent != null) {
+ focusedComponent.keyTyped(event.getKeyChar());
+ }
+
+ break;
+ }
+
+ case KeyEvent.KEY_PRESSED: {
+ boolean consumed = false;
+ int keyCode = event.getKeyCode();
+
+ if (focusedComponent != null) {
+ consumed = focusedComponent.keyPressed(keyCode, keyLocation);
+ }
+
+ if (!consumed) {
+ dragDropManager.keyPressed(keyCode, keyLocation);
+ }
+
+ break;
+ }
+
+ case KeyEvent.KEY_RELEASED: {
+ boolean consumed = false;
+ int keyCode = event.getKeyCode();
+
+ if (focusedComponent != null) {
+ consumed = focusedComponent.keyReleased(keyCode, keyLocation);
+ }
+
+ if (!consumed) {
+ dragDropManager.keyReleased(keyCode, keyLocation);
+ }
+
+ break;
+ }
+ }
+
+ // Consume the event
+ event.consume();
+ }
+ }
+
+ private static class IntervalTask extends TimerTask {
+ private Runnable runnable = null;
+
+ public IntervalTask(Runnable runnable) {
+ this.runnable = runnable;
+ }
+
+ public void run() {
+ queueCallback(runnable);
+ }
+ }
+
+ private static class TimeoutTask extends TimerTask {
+ private Runnable runnable = null;
+ int timeoutID = -1;
+
+ public TimeoutTask(Runnable runnable, int timeoutID) {
+ this.runnable = runnable;
+ this.timeoutID = timeoutID;
+ }
+
+ public void run() {
+ queueCallback(runnable, true);
+ clearTimeout(timeoutID);
+ }
+ }
+
+ private Display display = null;
+ private DisplayHost displayHost = null;
+ private DragDropManager dragDropManager = null;
+
+ private static DisplayHost activeDisplayHost = null;
+
+ private static HashMap<URL, Object> resourceCache = new HashMap<URL, Object>();
+ private static ResourceCacheDictionary resourceCacheDictionary = new ResourceCacheDictionary();
+
+ private static Timer timer = new Timer(true);
+ private static HashMap<Integer, TimerTask> timerTaskMap = new HashMap<Integer, TimerTask>();
+ private static int nextTimerTaskID = 0;
+
+ private static final int DEFAULT_MULTI_CLICK_INTERVAL = 400;
+ private static final int DEFAULT_CURSOR_BLINK_RATE = 600;
+ private static final String DEFAULT_THEME_CLASS_NAME = "pivot.wtk.skin.terra.TerraTheme";
+
+ protected ApplicationContext() {
+ display = new Display(this);
+ displayHost = new DisplayHost();
+ dragDropManager = new DragDropManager(this);
+
+ try {
+ // Load and instantiate the default theme, if possible
+ Class<?> themeClass = Class.forName(DEFAULT_THEME_CLASS_NAME);
+ Theme.setTheme((Theme)themeClass.newInstance());
+ } catch(Exception exception) {
+ // No-op; assume that a custom theme will be installed later
+ // by the caller
+ System.out.println("Warning: Unable to load default theme.");
+ }
+ }
+
+ protected Display getDisplay() {
+ return display;
+ }
+
+ protected DisplayHost getDisplayHost() {
+ return displayHost;
+ }
+
+ protected DragDropManager getDragDropManager() {
+ return dragDropManager;
+ }
+
+ protected void repaint(int x, int y, int width, int height) {
+ if (displayHost != null) {
+ // Ensure that the repaint call is properly bounded (some
+ // implementations of AWT do not properly clip the repaint call
+ // when x or y is negative: the negative value is converted to 0,
+ // but the width/height is not adjusted)
+ if (x < 0) {
+ width = Math.max(width + x, 0);
+ x = 0;
+ }
+
+ if (y < 0) {
+ height = Math.max(height + y, 0);
+ y = 0;
+ }
+
+ if (width > 0
+ && height > 0) {
+ displayHost.repaint(x, y, width, height);
+ }
+ }
+ }
+
+ protected Graphics2D getGraphics() {
+ Graphics2D graphics = null;
+
+ if (displayHost != null) {
+ graphics = (Graphics2D) displayHost.getGraphics();
+ }
+
+ return graphics;
+ }
+
+ /**
+ * Issues a system alert sound.
+ */
+ public static void beep() {
+ java.awt.Toolkit.getDefaultToolkit().beep();
+ }
+
+ /**
+ * Opens the given resource.
+ *
+ * @param location
+ */
+ public static void open(URL location) {
+ // TODO Remove dynamic invocation when Java 6 is supported on the Mac
+
+ try {
+ Class<?> desktopClass = Class.forName("java.awt.Desktop");
+ Method getDesktopMethod = desktopClass.getMethod("getDesktop",
+ new Class<?>[] {});
+ Method browseMethod = desktopClass.getMethod("browse",
+ new Class[] {URI.class});
+ Object desktop = getDesktopMethod.invoke(null, (Object[]) null);
+ browseMethod.invoke(desktop, location.toURI());
+ } catch (Exception exception) {
+ System.out.println("Unable to open URL in default browser.");
+ }
+ }
+
+ /**
+ * Resource properties accessor.
+ */
+ public static ResourceCacheDictionary getResourceCache() {
+ return resourceCacheDictionary;
+ }
+
+ /**
+ * Terminates the application context.
+ */
+ public static void exit() {
+ try {
+ System.exit(0);
+ } catch(SecurityException exception) {
+ System.out.println("Unable to exit application context.");
+ }
+ }
+
+ /**
+ * Schedules a task for repeated execution. The task will be executed on the
+ * UI thread.
+ *
+ * @param runnable
+ * The task to execute.
+ *
+ * @param period
+ * The interval at which the task should be executed.
+ *
+ * @return An integer ID that can be used to cancel execution of the task.
+ */
+ public static int setInterval(Runnable runnable, long period) {
+ int intervalID = nextTimerTaskID++;
+
+ IntervalTask intervalTask = new IntervalTask(runnable);
+ timerTaskMap.put(intervalID, intervalTask);
+
+ try {
+ timer.schedule(intervalTask, 0, period);
+ } catch(IllegalStateException exception) {
+ // TODO This is a workaround for an apparent bug in the Mac OSX
+ // Java Plugin, which appears to prematurely kill the timer thread.
+ // Remove this when the issue is fixed.
+ timer = new Timer(true);
+ timerTaskMap.clear();
+ timer.schedule(intervalTask, 0, period);
+ }
+
+ return intervalID;
+ }
+
+ /**
+ * Cancels execution of a scheduled task.
+ *
+ * @param intervalID
+ * The ID of the task to cancel.
+ */
+ public static void clearInterval(int intervalID) {
+ clearTimerTask(intervalID);
+ }
+
+ /**
+ * Schedules a task for execution after an elapsed time.
+ *
+ * @param runnable
+ * The task to execute.
+ *
+ * @param timeout
+ * The time after which the task should begin executing.
+ */
+ public static int setTimeout(Runnable runnable, long timeout) {
+ int timeoutID = nextTimerTaskID++;
+
+ TimeoutTask timeoutTask = new TimeoutTask(runnable, timeoutID);
+ timerTaskMap.put(timeoutID, timeoutTask);
+
+ try {
+ timer.schedule(timeoutTask, timeout);
+ } catch(IllegalStateException exception) {
+ // TODO This is a workaround for an apparent bug in the Mac OSX
+ // Java Plugin, which appears to prematurely kill the timer thread.
+ // Remove this when the issue is fixed.
+ timer = new Timer(true);
+ timerTaskMap.clear();
+ timer.schedule(timeoutTask, timeout);
+ }
+
+ return timeoutID;
+ }
+
+ /**
+ * Cancels execution of a scheduled task.
+ *
+ * @param timeoutID
+ * The ID of the task to cancel.
+ */
+ public static void clearTimeout(int timeoutID) {
+ clearTimerTask(timeoutID);
+ }
+
+ private static void clearTimerTask(int timerTaskID) {
+ TimerTask timerTask = timerTaskMap.remove(timerTaskID);
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ }
+
+ /**
+ * Queues a task to execute after all pending events have been processed and
+ * returns without waiting for the task to complete.
+ *
+ * @param runnable
+ * The runnable to execute.
+ */
+ public static void queueCallback(Runnable runnable) {
+ queueCallback(runnable, false);
+ }
+
+ /**
+ * Queues a task to execute after all pending events have been processed and
+ * optionally waits for the task to complete.
+ *
+ * @param runnable
+ * The runnable to execute.
+ *
+ * @param wait
+ * If <tt>true</tt>, does not return until the runnable has executed.
+ * Otherwise, returns immediately.
+ */
+ public static void queueCallback(Runnable runnable, boolean wait) {
+ if (wait) {
+ try {
+ java.awt.EventQueue.invokeAndWait(runnable);
+ } catch (InvocationTargetException exception) {
+ } catch (InterruptedException exception) {
+ }
+ } else {
+ java.awt.EventQueue.invokeLater(runnable);
+ }
+ }
+
+ public static int getMultiClickInterval() {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ Integer multiClickInterval = (Integer)toolkit.getDesktopProperty("awt.multiClickInterval");
+
+ if (multiClickInterval == null) {
+ multiClickInterval = DEFAULT_MULTI_CLICK_INTERVAL;
+ }
+
+ return multiClickInterval;
+ }
+
+ public static int getCursorBlinkRate() {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ Integer cursorBlinkRate = (Integer)toolkit.getDesktopProperty("awt.cursorBlinkRate");
+
+ if (cursorBlinkRate == null) {
+ cursorBlinkRate = DEFAULT_CURSOR_BLINK_RATE;
+ }
+
+ return cursorBlinkRate;
+ }
+
+ /**
+ * Gets the active display host.
+ *
+ * @deprecated
+ * This method will likely be made <tt>protected</tt> in a future release
+ */
+ @Deprecated
+ public static java.awt.Container getActiveDisplayHost() {
+ return activeDisplayHost;
+ }
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,140 @@
+/*
+ * 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;
+import pivot.util.ListenerList;
+
+/**
+ * Container that displays a border.
+ * <p>
+ * TODO Add styles to support different border styles (e.g. inset, outset) or
+ * create subclasses for these border types.
+ *
+ * @author gbrown
+ */
+@ComponentInfo(icon="Border.png")
+public class Border extends Container {
+ private static class BorderListenerList extends ListenerList<BorderListener>
+ implements BorderListener {
+ public void titleChanged(Border border, String previousTitle) {
+ for (BorderListener listener : this) {
+ listener.titleChanged(border, previousTitle);
+ }
+ }
+
+ public void contentChanged(Border border, Component previousContent) {
+ for (BorderListener listener : this) {
+ listener.contentChanged(border, previousContent);
+ }
+ }
+ }
+
+ private String title = null;
+ private Component content = null;
+ private BorderListenerList borderListeners = new BorderListenerList();
+
+ public Border() {
+ this(null);
+ }
+
+ public Border(Component content) {
+ installSkin(Border.class);
+
+ setContent(content);
+ }
+
+ /**
+ * Returns the border's title.
+ *
+ * @return
+ * The border's title, or <tt>null</tt> if no title is set.
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * Sets the border's title.
+ *
+ * @param title
+ * The new title, or <tt>null</tt> for no title.
+ */
+ public void setTitle(String title) {
+ String previousTitle = this.title;
+
+ if (previousTitle != title) {
+ this.title = title;
+ borderListeners.titleChanged(this, previousTitle);
+ }
+ }
+
+ /**
+ * Returns the border's content component.
+ *
+ * @return
+ * The border's content component, or <tt>null</tt> if the border does
+ * not have a content component.
+ */
+ public Component getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the border's content component.
+ *
+ * @param content
+ * The border's content component, or <tt>null</tt> for no content.
+ */
+ public void setContent(Component content) {
+ Component previousContent = this.content;
+
+ if (content != previousContent) {
+ this.content = null;
+
+ // Remove any previous content component
+ if (previousContent != null) {
+ remove(previousContent);
+ }
+
+ // Add the component
+ if (content != null) {
+ add(content);
+ }
+
+ this.content = content;
+
+ borderListeners.contentChanged(this, previousContent);
+ }
+ }
+
+ @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 == content) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ // Call the base method to remove the components
+ return super.remove(index, count);
+ }
+
+ public ListenerList<BorderListener> getBorderListeners() {
+ return borderListeners;
+ }
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.png
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.png?rev=754936&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Border.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/BorderListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/BorderListener.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/BorderListener.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/BorderListener.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,25 @@
+package pivot.wtk;
+
+/**
+ * Border listener interface.
+ *
+ * @author gbrown
+ *
+ */
+public interface BorderListener {
+ /**
+ * Called when a border's title has changed.
+ *
+ * @param border
+ * @param previousTitle
+ */
+ public void titleChanged(Border border, String previousTitle);
+
+ /**
+ * Called when a border's content component has changed.
+ *
+ * @param border
+ * @param previousContent
+ */
+ public void contentChanged(Border border, Component previousContent);
+}
Added: incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Bounds.java
URL: http://svn.apache.org/viewvc/incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Bounds.java?rev=754936&view=auto
==============================================================================
--- incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Bounds.java (added)
+++ incubator/pivot/tags/v1.0.1/wtk/src/pivot/wtk/Bounds.java Mon Mar 16 16:36:10 2009
@@ -0,0 +1,215 @@
+/*
+ * 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 bounds of an object.
+ *
+ * @author gbrown
+ */
+public class Bounds {
+ public int x = 0;
+ public int y = 0;
+ public int width = 0;
+ public int height = 0;
+
+ public static final String X_KEY = "x";
+ public static final String Y_KEY = "y";
+ public static final String WIDTH_KEY = "width";
+ public static final String HEIGHT_KEY = "height";
+
+ public Bounds() {
+ }
+
+ public Bounds(Dictionary<String, ?> bounds) {
+ if (bounds == null) {
+ throw new IllegalArgumentException("bounds is null.");
+ }
+
+ if (bounds.containsKey(X_KEY)) {
+ x = (Integer)bounds.get(X_KEY);
+ }
+
+ if (bounds.containsKey(Y_KEY)) {
+ y = (Integer)bounds.get(Y_KEY);
+ }
+
+ if (bounds.containsKey(WIDTH_KEY)) {
+ width = (Integer)bounds.get(WIDTH_KEY);
+ }
+
+ if (bounds.containsKey(HEIGHT_KEY)) {
+ height = (Integer)bounds.get(HEIGHT_KEY);
+ }
+ }
+
+ public Bounds(int x, int y, int width, int height) {
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ }
+
+ public Bounds(Point origin, Dimensions size) {
+ if (origin == null) {
+ throw new IllegalArgumentException("origin is null.");
+ }
+
+ if (size == null) {
+ throw new IllegalArgumentException("size is null.");
+ }
+
+ x = origin.x;
+ y = origin.y;
+ width = size.width;
+ height = size.height;
+ }
+
+ public Bounds(Bounds bounds) {
+ if (bounds == null) {
+ throw new IllegalArgumentException("bounds is null.");
+ }
+
+ x = bounds.x;
+ y = bounds.y;
+ width = bounds.width;
+ height = bounds.height;
+ }
+
+ public Bounds(java.awt.Rectangle rectangle) {
+ if (rectangle == null) {
+ throw new IllegalArgumentException("rectangle is null.");
+ }
+
+ x = rectangle.x;
+ y = rectangle.y;
+ width = rectangle.width;
+ height = rectangle.height;
+ }
+
+ public Point getLocation() {
+ return new Point(x, y);
+ }
+
+ public Dimensions getSize() {
+ return new Dimensions(width, height);
+ }
+
+ public void union(Bounds bounds) {
+ int x1 = Math.min(x, bounds.x);
+ int y1 = Math.min(y, bounds.y);
+ int x2 = Math.max(x + width, bounds.x + bounds.width);
+ int y2 = Math.max(y + height, bounds.y + bounds.height);
+
+ this.x = x1;
+ this.y = y1;
+ this.width = x2 - x1;
+ this.height = y2 - y1;
+ }
+
+ public void intersect(Bounds bounds) {
+ int x1 = Math.max(x, bounds.x);
+ int y1 = Math.max(y, bounds.y);
+ int x2 = Math.min(x + width, bounds.x + bounds.width);
+ int y2 = Math.min(y + height, bounds.y + bounds.height);
+
+ this.x = x1;
+ this.y = y1;
+ this.width = x2 - x1;
+ this.height = y2 - y1;
+ }
+
+ public void translate(int dx, int dy) {
+ this.x += dx;
+ this.y += dy;
+ }
+
+ public boolean contains(Point point) {
+ if (point == null) {
+ throw new IllegalArgumentException("point is null");
+ }
+
+ return contains(point.x, point.y);
+ }
+
+ public boolean contains(int x, int y) {
+ return (x >= this.x
+ && y >= this.y
+ && x < this.x + width
+ && y < this.y + height);
+ }
+
+ public boolean contains(Bounds bounds) {
+ if (bounds == null) {
+ throw new IllegalArgumentException("bounds is null");
+ }
+
+ return contains(bounds.x, bounds.y, bounds.width, bounds.height);
+ }
+
+ public boolean contains(int x, int y, int width, int height) {
+ return (!isEmpty()
+ && x >= this.x
+ && y >= this.y
+ && x + width <= this.x + this.width
+ && y + height <= this.y + this.height);
+ }
+
+ public boolean intersects(Bounds bounds) {
+ if (bounds == null) {
+ throw new IllegalArgumentException("bounds is null");
+ }
+
+ return intersects(bounds.x, bounds.y, bounds.width, bounds.height);
+ }
+
+ public boolean intersects(int x, int y, int width, int height) {
+ return (!isEmpty()
+ && x + width > this.x
+ && y + height > this.y
+ && x < this.x + this.width
+ && y < this.y + this.height);
+ }
+
+ public boolean isEmpty() {
+ return (width <= 0
+ || height <= 0);
+ }
+
+ public boolean equals(Object object) {
+ boolean equals = false;
+
+ if (object instanceof Bounds) {
+ Bounds bounds = (Bounds)object;
+ equals = (x == bounds.x
+ && y == bounds.y
+ && width == bounds.width
+ && height == bounds.height);
+ }
+
+ return equals;
+ }
+
+ public java.awt.Rectangle toRectangle() {
+ return new java.awt.Rectangle(x, y, width, height);
+ }
+
+ public String toString() {
+ return getClass().getName() + " [" + x + "," + y + ";" + width + "x" + height + "]";
+ }
+}