You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2017/12/06 19:56:43 UTC
svn commit: r1817316 - in /pivot/trunk:
tests/src/org/apache/pivot/tests/CheckedListViewTest.java
tests/src/org/apache/pivot/tests/checked_list_view_test.bxml
wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java
Author: rwhitcomb
Date: Wed Dec 6 19:56:42 2017
New Revision: 1817316
URL: http://svn.apache.org/viewvc?rev=1817316&view=rev
Log:
PIVOT-971: Update the CheckedListViewTest program to test/demo the
tri-state checkbox feature.
Add an Adapter class to ListViewItemStateListener since it now has
two methods in the interface.
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/checked_list_view_test.bxml
Modified:
pivot/trunk/tests/src/org/apache/pivot/tests/CheckedListViewTest.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java
Modified: pivot/trunk/tests/src/org/apache/pivot/tests/CheckedListViewTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/CheckedListViewTest.java?rev=1817316&r1=1817315&r2=1817316&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/CheckedListViewTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/CheckedListViewTest.java Wed Dec 6 19:56:42 2017
@@ -16,31 +16,65 @@
*/
package org.apache.pivot.tests;
+import org.apache.pivot.beans.BXML;
+import org.apache.pivot.beans.BXMLSerializer;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.Map;
import org.apache.pivot.collections.Sequence;
import org.apache.pivot.json.JSONSerializer;
import org.apache.pivot.wtk.Application;
+import org.apache.pivot.wtk.Button;
+import org.apache.pivot.wtk.ButtonPressListener;
+import org.apache.pivot.wtk.Checkbox;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.ComponentKeyListener;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Keyboard;
+import org.apache.pivot.wtk.Label;
import org.apache.pivot.wtk.ListView;
+import org.apache.pivot.wtk.ListViewItemStateListener;
import org.apache.pivot.wtk.Span;
import org.apache.pivot.wtk.Window;
public class CheckedListViewTest extends Application.Adapter {
- private Window window = null;
+
+ private String toShortString(Span span) {
+ if (span.getLength() == 1) {
+ return Integer.toString(span.start);
+ } else {
+ return String.format("%1$d-%2$d", span.normalStart(), span.normalEnd());
+ }
+ }
+
+ Window mainWindow;
+ @BXML Checkbox allowMixedStateCheckbox;
+ @BXML Checkbox showMixedAsSelectedCheckbox;
+ @BXML ListView listView;
+ @BXML Label selectedItemsLabel;
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
- final ListView listView = new ListView(
- JSONSerializer.parseList("['One', 'Two', 'Three', 'Four']"));
- listView.setSelectMode(ListView.SelectMode.MULTI);
- listView.setCheckmarksEnabled(true);
- listView.setItemChecked(0, true);
- listView.setItemChecked(2, true);
+ BXMLSerializer serializer = new BXMLSerializer();
+ mainWindow = (Window)serializer.readObject(CheckedListViewTest.class, "checked_list_view_test.bxml");
+ serializer.bind(this);
+
+ allowMixedStateCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ listView.setAllowTriStateCheckmarks(button.isSelected());
+ // Not sure why, but changing this setting clears all the checks but doesn't
+ // trigger the item state listener (it's documented, but ...)
+ selectedItemsLabel.setText("");
+ }
+ });
+
+ showMixedAsSelectedCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
+ @Override
+ public void buttonPressed(Button button) {
+ listView.setCheckmarksMixedAsChecked(button.isSelected());
+ }
+ });
listView.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
@Override
@@ -62,16 +96,42 @@ public class CheckedListViewTest extends
}
});
- window = new Window(listView);
- window.setTitle("Checked List View Test");
- window.setMaximized(true);
- window.open(display);
+ listView.getListViewItemStateListeners().add(new ListViewItemStateListener.Adapter() {
+
+ private void displayCheckedItems(ListView listView) {
+ List<?> listData = listView.getListData();
+ StringBuffer buf = new StringBuffer();
+ for (Integer i : listView.getCheckedIndexes()) {
+ if (buf.length() > 0) {
+ buf.append(",");
+ }
+ Object item = listData.get(i);
+ buf.append(item.toString());
+ }
+ selectedItemsLabel.setText(buf.toString());
+ }
+
+ @Override
+ public void itemCheckedChanged(ListView listView, int index) {
+ displayCheckedItems(listView);
+ }
+
+ @Override
+ public void itemCheckedStateChanged(ListView listView, int index) {
+ displayCheckedItems(listView);
+ }
+ });
+
+ listView.setItemChecked(0, true);
+ listView.setItemChecked(2, true);
+
+ mainWindow.open(display);
}
@Override
public boolean shutdown(boolean optional) {
- if (window != null) {
- window.close();
+ if (mainWindow != null) {
+ mainWindow.close();
}
return false;
Added: pivot/trunk/tests/src/org/apache/pivot/tests/checked_list_view_test.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/checked_list_view_test.bxml?rev=1817316&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/checked_list_view_test.bxml (added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/checked_list_view_test.bxml Wed Dec 6 19:56:42 2017
@@ -0,0 +1,48 @@
+<?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.
+-->
+
+<Window title="Checked List View Test"
+ xmlns:bxml="http://pivot.apache.org/bxml"
+ xmlns:content="org.apache.pivot.wtk.content"
+ xmlns="org.apache.pivot.wtk"
+ maximized="true">
+ <TablePane>
+ <columns>
+ <TablePane.Column width="1*"/>
+ </columns>
+ <rows>
+ <TablePane.Row height="-1">
+ <Form>
+ <Form.Section>
+ <Checkbox bxml:id="allowMixedStateCheckbox" buttonData="Allow Mixed State Checks in ListView?"/>
+ <Checkbox bxml:id="showMixedAsSelectedCheckbox" buttonData="Mixed State Show as Selected?"/>
+ </Form.Section>
+ </Form>
+ </TablePane.Row>
+ <TablePane.Row height="1*">
+ <ListView bxml:id="listView" listData="['One', 'Two', 'Three', 'Four']" selectMode="MULTI" checkmarksEnabled="true"/>
+ </TablePane.Row>
+ <TablePane.Row height="-1">
+ <BoxPane orientation="horizontal">
+ <Label text="Currently checked items:"/>
+ <Label bxml:id="selectedItemsLabel" text=""/>
+ </BoxPane>
+ </TablePane.Row>
+ </rows>
+ </TablePane>
+</Window>
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java?rev=1817316&r1=1817315&r2=1817316&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ListViewItemStateListener.java Wed Dec 6 19:56:42 2017
@@ -21,6 +21,21 @@ package org.apache.pivot.wtk;
*/
public interface ListViewItemStateListener {
/**
+ * Adapter class that provides a default implementation of these interface
+ * methods.
+ */
+ public class Adapter implements ListViewItemStateListener {
+ @Override
+ public void itemCheckedChanged(ListView listView, int index) {
+ // Do nothing
+ }
+ @Override
+ public void itemCheckedStateChanged(ListView listView, int index) {
+ // Do nothing
+ }
+ }
+
+ /**
* Called when an item's checked state has changed.
*
* @param listView The list view whose state has changed.
@@ -29,7 +44,8 @@ public interface ListViewItemStateListen
public void itemCheckedChanged(ListView listView, int index);
/**
- * Called when a tri-state item's state has changed.
+ * Called when a tri-state item's state has changed, that is, in or out
+ * of the {@link org.apache.pivot.wtk.Button.State#MIXED} state.
*
* @param listView The list view whose state has changed.
* @param index The index of the item whose tri-state has changed.