Author: gbrown
Date: Fri May 14 15:45:29 2010
New Revision: 944323
URL: http://svn.apache.org/viewvc?rev=944323&view=rev
Log:
Resolve issue PIVOT-474 for ListView and TableView; fix repaint logic when
selection changes in ListView and TableView (previous logic was repainting more
than necessary).
Added:
pivot/trunk/tests/src/org/apache/pivot/tests/list_selection_test.wtkx
pivot/trunk/tests/src/org/apache/pivot/tests/table_selection_test.wtkx
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
Added: pivot/trunk/tests/src/org/apache/pivot/tests/list_selection_test.wtkx
URL:
http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/list_selection_test.wtkx?rev=944323&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/list_selection_test.wtkx
(added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/list_selection_test.wtkx Fri
May 14 15:45:29 2010
@@ -0,0 +1,29 @@
+<?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="List Selection Test" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <ScrollPane horizontalScrollBarPolicy="fill"
verticalScrollBarPolicy="fill_to_capacity">
+ <view>
+ <ListView listData="[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3,
4, 5, 6, 7, 8, 9]" selectMode="multi"/>
+ </view>
+ </ScrollPane>
+ </content>
+</Window>
Added: pivot/trunk/tests/src/org/apache/pivot/tests/table_selection_test.wtkx
URL:
http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/table_selection_test.wtkx?rev=944323&view=auto
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/table_selection_test.wtkx
(added)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/table_selection_test.wtkx Fri
May 14 15:45:29 2010
@@ -0,0 +1,57 @@
+<?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="Table Selection Test" maximized="true"
+ xmlns:wtkx="http://pivot.apache.org/wtkx"
+ xmlns="org.apache.pivot.wtk">
+ <content>
+ <ScrollPane horizontalScrollBarPolicy="fill"
verticalScrollBarPolicy="fill_to_capacity">
+ <view>
+ <TableView selectMode="multi">
+ <columns>
+ <TableView.Column name="a" width="1*"/>
+ </columns>
+ <tableData
xmlns:collections="org.apache.pivot.collections">
+ <collections:ArrayList>
+ <collections:HashMap a="0"/>
+ <collections:HashMap a="1"/>
+ <collections:HashMap a="2"/>
+ <collections:HashMap a="3"/>
+ <collections:HashMap a="4"/>
+ <collections:HashMap a="5"/>
+ <collections:HashMap a="6"/>
+ <collections:HashMap a="7"/>
+ <collections:HashMap a="8"/>
+ <collections:HashMap a="9"/>
+ <collections:HashMap a="0"/>
+ <collections:HashMap a="1"/>
+ <collections:HashMap a="2"/>
+ <collections:HashMap a="3"/>
+ <collections:HashMap a="4"/>
+ <collections:HashMap a="5"/>
+ <collections:HashMap a="6"/>
+ <collections:HashMap a="7"/>
+ <collections:HashMap a="8"/>
+ <collections:HashMap a="9"/>
+ </collections:ArrayList>
+ </tableData>
+ </TableView>
+ </view>
+ </ScrollPane>
+ </content>
+</Window>
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=944323&r1=944322&r2=944323&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
Fri May 14 15:45:29 2010
@@ -70,6 +70,8 @@ public class TerraListViewSkin extends C
private ArrayList<Integer> itemBoundaries = null;
private int fixedItemHeight;
+ private boolean validateSelection = false;
+
private static final Checkbox CHECKBOX = new Checkbox();
static {
@@ -253,6 +255,26 @@ public class TerraListViewSkin extends C
+ checkboxPadding.bottom), fixedItemHeight);
}
}
+
+ if (validateSelection) {
+ // Ensure that the selection is visible
+ Sequence<Span> selectedRanges = listView.getSelectedRanges();
+
+ if (selectedRanges.getLength() > 0) {
+ int rangeStart = selectedRanges.get(0).start;
+ int rangeEnd = selectedRanges.get(selectedRanges.getLength() -
1).end;
+
+ Bounds selectionBounds = getItemBounds(rangeStart);
+ selectionBounds =
selectionBounds.union(getItemBounds(rangeEnd));
+
+ Bounds visibleSelectionBounds =
listView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ listView.scrollAreaToVisible(selectionBounds);
+ }
+ }
+ }
+
+ validateSelection = false;
}
@Override
@@ -965,8 +987,6 @@ public class TerraListViewSkin extends C
} else {
listView.setSelectedIndex(index);
}
-
- listView.scrollAreaToVisible(getItemBounds(index));
}
consumed = true;
@@ -989,8 +1009,6 @@ public class TerraListViewSkin extends C
} else {
listView.setSelectedIndex(index);
}
-
- listView.scrollAreaToVisible(getItemBounds(index));
}
consumed = true;
@@ -1056,7 +1074,6 @@ public class TerraListViewSkin extends C
if (first == character) {
listView.setSelectedIndex(i);
- listView.scrollAreaToVisible(getItemBounds(i));
consumed = true;
break;
}
@@ -1158,10 +1175,18 @@ public class TerraListViewSkin extends C
// List view selection detail events
@Override
public void selectedRangeAdded(ListView listView, int rangeStart, int
rangeEnd) {
- // Repaint the area containing the added selection
if (listView.isValid()) {
- repaintComponent(0, getItemY(rangeStart),
- getWidth(), getItemY(rangeEnd) + getItemHeight(rangeEnd));
+ Bounds selectionBounds = getItemBounds(rangeStart);
+ selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
+ repaintComponent(selectionBounds);
+
+ // Ensure that the selection is visible
+ Bounds visibleSelectionBounds =
listView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ listView.scrollAreaToVisible(selectionBounds);
+ }
+ } else {
+ validateSelection = true;
}
}
@@ -1169,35 +1194,43 @@ public class TerraListViewSkin extends C
public void selectedRangeRemoved(ListView listView, int rangeStart, int
rangeEnd) {
// Repaint the area containing the removed selection
if (listView.isValid()) {
- repaintComponent(0, getItemY(rangeStart),
- getWidth(), getItemY(rangeEnd) + getItemHeight(rangeEnd));
+ Bounds selectionBounds = getItemBounds(rangeStart);
+ selectionBounds = selectionBounds.union(getItemBounds(rangeEnd));
+ repaintComponent(selectionBounds);
}
}
@Override
- @SuppressWarnings("unchecked")
public void selectedRangesChanged(ListView listView, Sequence<Span>
previousSelectedRanges) {
- List<Object> listData = (List<Object>)listView.getListData();
-
- // Repaint only the area that changed (intersection of previous and
new selection)
- int rangeStart = 0;
- int rangeEnd = listData.getLength() - 1;
- for (int i = 0; i < previousSelectedRanges.getLength(); i++) {
- Span span = previousSelectedRanges.get(i);
- rangeStart = Math.min(rangeStart, span.start);
- rangeEnd = Math.max(rangeEnd, span.end);
- }
-
- Sequence<Span> newSelectedRanges = listView.getSelectedRanges();
- for (int i = 0; i < newSelectedRanges.getLength(); i++) {
- Span span = newSelectedRanges.get(i);
- rangeStart = Math.min(rangeStart, span.start);
- rangeEnd = Math.max(rangeEnd, span.end);
- }
-
if (listView.isValid()) {
- repaintComponent(0, getItemY(rangeStart),
- getWidth(), getItemY(rangeEnd) + getItemHeight(rangeEnd));
+ // Repaint the area occupied by the previous selection
+ if (previousSelectedRanges.getLength() > 0) {
+ int rangeStart = previousSelectedRanges.get(0).start;
+ int rangeEnd =
previousSelectedRanges.get(previousSelectedRanges.getLength() - 1).end;
+
+ Bounds previousSelectionBounds = getItemBounds(rangeStart);
+ previousSelectionBounds =
previousSelectionBounds.union(getItemBounds(rangeEnd));
+ repaintComponent(previousSelectionBounds);
+ }
+
+ // Repaint the area occupied by the current selection
+ Sequence<Span> selectedRanges = listView.getSelectedRanges();
+ if (selectedRanges.getLength() > 0) {
+ int rangeStart = selectedRanges.get(0).start;
+ int rangeEnd = selectedRanges.get(selectedRanges.getLength() -
1).end;
+
+ Bounds selectionBounds = getItemBounds(rangeStart);
+ selectionBounds =
selectionBounds.union(getItemBounds(rangeEnd));
+ repaintComponent(selectionBounds);
+
+ // Ensure that the selection is visible
+ Bounds visibleSelectionBounds =
listView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ listView.scrollAreaToVisible(selectionBounds);
+ }
+ }
+ } else {
+ validateSelection = true;
}
}
}
Modified:
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL:
http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=944323&r1=944322&r2=944323&view=diff
==============================================================================
---
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
(original)
+++
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
Fri May 14 15:45:29 2010
@@ -84,6 +84,8 @@ public class TerraTableViewSkin extends
private int highlightedIndex = -1;
private int editIndex = -1;
+ private boolean validateSelection = false;
+
public TerraTableViewSkin() {
TerraTheme theme = (TerraTheme)Theme.getTheme();
font = theme.getFont();
@@ -277,6 +279,26 @@ public class TerraTableViewSkin extends
} else {
fixedRowHeight = calculateFixedRowHeight(tableView);
}
+
+ if (validateSelection) {
+ // Ensure that the selection is visible
+ Sequence<Span> selectedRanges = tableView.getSelectedRanges();
+
+ if (selectedRanges.getLength() > 0) {
+ int rangeStart = selectedRanges.get(0).start;
+ int rangeEnd = selectedRanges.get(selectedRanges.getLength() -
1).end;
+
+ Bounds selectionBounds = getRowBounds(rangeStart);
+ selectionBounds =
selectionBounds.union(getRowBounds(rangeEnd));
+
+ Bounds visibleSelectionBounds =
tableView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ tableView.scrollAreaToVisible(selectionBounds);
+ }
+ }
+ }
+
+ validateSelection = false;
}
/**
@@ -513,6 +535,7 @@ public class TerraTableViewSkin extends
} else {
rowHeight = fixedRowHeight;
}
+
return rowHeight;
}
@@ -1273,8 +1296,6 @@ public class TerraTableViewSkin extends
} else {
tableView.setSelectedIndex(index);
}
-
- tableView.scrollAreaToVisible(getRowBounds(index));
}
consumed = true;
@@ -1297,8 +1318,6 @@ public class TerraTableViewSkin extends
} else {
tableView.setSelectedIndex(index);
}
-
- tableView.scrollAreaToVisible(getRowBounds(index));
}
consumed = true;
@@ -1468,10 +1487,18 @@ public class TerraTableViewSkin extends
// Table view selection detail events
@Override
public void selectedRangeAdded(TableView tableView, int rangeStart, int
rangeEnd) {
- // Repaint the area containing the added selection
if (tableView.isValid()) {
- repaintComponent(0, getRowY(rangeStart),
- getWidth(), getRowY(rangeEnd) + getRowHeight(rangeEnd));
+ Bounds selectionBounds = getRowBounds(rangeStart);
+ selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
+ repaintComponent(selectionBounds);
+
+ // Ensure that the selection is visible
+ Bounds visibleSelectionBounds =
tableView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ tableView.scrollAreaToVisible(selectionBounds);
+ }
+ } else {
+ validateSelection = true;
}
}
@@ -1479,35 +1506,45 @@ public class TerraTableViewSkin extends
public void selectedRangeRemoved(TableView tableView, int rangeStart, int
rangeEnd) {
// Repaint the area containing the removed selection
if (tableView.isValid()) {
- repaintComponent(0, getRowY(rangeStart),
- getWidth(), getRowY(rangeEnd) + getRowHeight(rangeEnd));
+ Bounds selectionBounds = getRowBounds(rangeStart);
+ selectionBounds = selectionBounds.union(getRowBounds(rangeEnd));
+ repaintComponent(selectionBounds);
}
}
@Override
public void selectedRangesChanged(TableView tableView, Sequence<Span>
previousSelectedRanges) {
- List<?> tableData = tableView.getTableData();
+ if (tableView.isValid()) {
+ // Repaint the area occupied by the previous selection
+ if (previousSelectedRanges.getLength() > 0) {
+ int rangeStart = previousSelectedRanges.get(0).start;
+ int rangeEnd =
previousSelectedRanges.get(previousSelectedRanges.getLength() - 1).end;
- // Repaint only the area that changed (intersection of previous
- // and new selection)
- int rangeStart = 0;
- int rangeEnd = tableData.getLength() - 1;
- for (int i = 0; i < previousSelectedRanges.getLength(); i++) {
- Span span = previousSelectedRanges.get(i);
- rangeStart = Math.min(rangeStart, span.start);
- rangeEnd = Math.max(rangeEnd, span.end);
- }
+ Bounds previousSelectionBounds = getRowBounds(rangeStart);
+ previousSelectionBounds =
previousSelectionBounds.union(getRowBounds(rangeEnd));
- Sequence<Span> newSelectedRanges = tableView.getSelectedRanges();
- for (int i = 0; i < newSelectedRanges.getLength(); i++) {
- Span span = newSelectedRanges.get(i);
- rangeStart = Math.min(rangeStart, span.start);
- rangeEnd = Math.max(rangeEnd, span.end);
- }
+ repaintComponent(previousSelectionBounds);
+ }
- if (tableView.isValid()) {
- repaintComponent(0, getRowY(rangeStart),
- getWidth(), getRowY(rangeEnd) + getRowY(rangeEnd));
+ // Repaint the area occupied by the current selection
+ Sequence<Span> selectedRanges = tableView.getSelectedRanges();
+ if (selectedRanges.getLength() > 0) {
+ int rangeStart = selectedRanges.get(0).start;
+ int rangeEnd = selectedRanges.get(selectedRanges.getLength() -
1).end;
+
+ Bounds selectionBounds = getRowBounds(rangeStart);
+ selectionBounds =
selectionBounds.union(getRowBounds(rangeEnd));
+
+ repaintComponent(selectionBounds);
+
+ // Ensure that the selection is visible
+ Bounds visibleSelectionBounds =
tableView.getVisibleArea(selectionBounds);
+ if (visibleSelectionBounds.height < selectionBounds.height) {
+ tableView.scrollAreaToVisible(selectionBounds);
+ }
+ }
+ } else {
+ validateSelection = true;
}
}
}