blob: c624abb4b6e2ae12f2fc02b6f9687ba9d32fb380 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you 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.
-->
<document id="menu-buttons">
<properties>
<title>Menu Buttons</title>
</properties>
<body>
<p>
Menu buttons are similar to <a href="list-buttons.html">list buttons</a>, but provide
access to "drop-down" menus rather than list views. They are often used in toolbars,
but can be placed anywhere within an application's user interface.
</p>
<p>
The following sample application demonstrates the use of a menu button. Selecting an
option from the menu button on the left adds the corresponding component type to the
content area on the right:
</p>
<application class="org.apache.pivot.wtk.ScriptApplication"
width="360" height="240">
<libraries>
<library>core</library>
<library>wtk</library>
<library>wtk-terra</library>
<library>tutorials</library>
</libraries>
<startup-properties>
<src>/org/apache/pivot/tutorials/menus/menu_buttons.bxml</src>
</startup-properties>
</application>
<p>
The BXML source for the application is as follows:
</p>
<source type="xml" location="org/apache/pivot/tutorials/menus/menu_buttons.bxml">
<![CDATA[
<menus:MenuButtons title="Menu Buttons" maximized="true"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns:content="org.apache.pivot.wtk.content"
xmlns:menus="org.apache.pivot.tutorials.menus"
xmlns="org.apache.pivot.wtk">
<Border styles="{padding:8}">
<TablePane styles="{horizontalSpacing:4}">
<columns>
<TablePane.Column width="-1"/>
<TablePane.Column width="1*"/>
</columns>
<TablePane.Row height="1*">
<BoxPane orientation="vertical">
<MenuButton buttonData="Add Component">
<Menu>
<Menu.Section>
<Menu.Item buttonData="Push Button" action="addPushButton"/>
<Menu.Item buttonData="Checkbox" action="addCheckbox"/>
<Menu.Item buttonData="Radio Button" action="addRadioButton"/>
</Menu.Section>
</Menu>
</MenuButton>
</BoxPane>
<Border>
<ScrollPane>
<BoxPane bxml:id="componentBoxPane" orientation="vertical"
styles="{padding:4, spacing:4}"/>
</ScrollPane>
</Border>
</TablePane.Row>
</TablePane>
</Border>
</menus:MenuButtons>
]]>
</source>
<p>
Like the previous example, it defines a set of menu items that are associated with
named actions. The Java source, which defines the actions, is shown below:
</p>
<source type="java" location="org/apache/pivot/tutorials/menus/MenuButtons.java">
<![CDATA[
package org.apache.pivot.tutorials.menus;
import java.net.URL;
import org.apache.pivot.beans.Bindable;
import org.apache.pivot.collections.Map;
import org.apache.pivot.util.Resources;
import org.apache.pivot.wtk.Action;
import org.apache.pivot.wtk.BoxPane;
import org.apache.pivot.wtk.Checkbox;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.PushButton;
import org.apache.pivot.wtk.RadioButton;
import org.apache.pivot.wtk.Window;
public class MenuButtons extends Window implements Bindable {
private BoxPane componentBoxPane = null;
public MenuButtons() {
Action.getNamedActions().put("addPushButton", new Action() {
@Override
public void perform(Component source) {
componentBoxPane.add(new PushButton("Push button"));
}
});
Action.getNamedActions().put("addCheckbox", new Action() {
@Override
public void perform(Component source) {
componentBoxPane.add(new Checkbox("Checkbox"));
}
});
Action.getNamedActions().put("addRadioButton", new Action() {
@Override
public void perform(Component source) {
componentBoxPane.add(new RadioButton("Radio button"));
}
});
}
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
componentBoxPane = (BoxPane)namespace.get("componentBoxPane");
}
}
]]>
</source>
</body>
</document>