1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
365 counter++) {
366 if(paths[counter] != null) {
367 if (uniquePaths.get(paths[counter]) == null) {
368 validCount++;
369 if(cPaths == null)
370 cPaths = new Vector<PathPlaceHolder>();
371 cPaths.addElement(new PathPlaceHolder
372 (paths[counter], true));
373 uniquePaths.put(paths[counter], Boolean.TRUE);
374 lastPaths.put(paths[counter], Boolean.TRUE);
375 }
376 leadPath = paths[counter];
377 }
378 }
379
380 if(leadPath == null) {
381 leadPath = beginLeadPath;
382 }
383
384 if(validCount > 0) {
385 TreePath newSelection[] = new TreePath[oldCount +
386 validCount];
387
388 /* And build the new selection. */
389 if(oldCount > 0)
390 System.arraycopy(selection, 0, newSelection, 0,
391 oldCount);
392 if(validCount != paths.length) {
393 /* Some of the paths in paths are already in
394 the selection. */
395 Enumeration<TreePath> newPaths = lastPaths.keys();
396
397 counter = oldCount;
398 while (newPaths.hasMoreElements()) {
399 newSelection[counter++] = newPaths.nextElement();
400 }
401 }
402 else {
403 System.arraycopy(paths, 0, newSelection, oldCount,
404 validCount);
405 }
884 * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and
885 * more than one TreePath is selected, the selection is reset to
886 * contain the first path currently selected.
887 */
888 protected void insureRowContinuity() {
889 if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION &&
890 selection != null && rowMapper != null) {
891 DefaultListSelectionModel lModel = listSelectionModel;
892 int min = lModel.getMinSelectionIndex();
893
894 if(min != -1) {
895 for(int counter = min,
896 maxCounter = lModel.getMaxSelectionIndex();
897 counter <= maxCounter; counter++) {
898 if(!lModel.isSelectedIndex(counter)) {
899 if(counter == min) {
900 clearSelection();
901 }
902 else {
903 TreePath[] newSel = new TreePath[counter - min];
904 int selectionIndex[] = rowMapper.getRowsForPaths(selection);
905 // find the actual selection pathes corresponded to the
906 // rows of the new selection
907 for (int i = 0; i < selectionIndex.length; i++) {
908 if (selectionIndex[i]<counter) {
909 newSel[selectionIndex[i]-min] = selection[i];
910 }
911 }
912 setSelectionPaths(newSel);
913 break;
914 }
915 }
916 }
917 }
918 }
919 else if(selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION &&
920 selection != null && selection.length > 1) {
921 setSelectionPath(selection[0]);
922 }
923 }
924
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
365 counter++) {
366 if(paths[counter] != null) {
367 if (uniquePaths.get(paths[counter]) == null) {
368 validCount++;
369 if(cPaths == null)
370 cPaths = new Vector<PathPlaceHolder>();
371 cPaths.addElement(new PathPlaceHolder
372 (paths[counter], true));
373 uniquePaths.put(paths[counter], Boolean.TRUE);
374 lastPaths.put(paths[counter], Boolean.TRUE);
375 }
376 leadPath = paths[counter];
377 }
378 }
379
380 if(leadPath == null) {
381 leadPath = beginLeadPath;
382 }
383
384 if(validCount > 0) {
385 TreePath[] newSelection = new TreePath[oldCount +
386 validCount];
387
388 /* And build the new selection. */
389 if(oldCount > 0)
390 System.arraycopy(selection, 0, newSelection, 0,
391 oldCount);
392 if(validCount != paths.length) {
393 /* Some of the paths in paths are already in
394 the selection. */
395 Enumeration<TreePath> newPaths = lastPaths.keys();
396
397 counter = oldCount;
398 while (newPaths.hasMoreElements()) {
399 newSelection[counter++] = newPaths.nextElement();
400 }
401 }
402 else {
403 System.arraycopy(paths, 0, newSelection, oldCount,
404 validCount);
405 }
884 * If the selection mode is <code>SINGLE_TREE_SELECTION</code> and
885 * more than one TreePath is selected, the selection is reset to
886 * contain the first path currently selected.
887 */
888 protected void insureRowContinuity() {
889 if(selectionMode == TreeSelectionModel.CONTIGUOUS_TREE_SELECTION &&
890 selection != null && rowMapper != null) {
891 DefaultListSelectionModel lModel = listSelectionModel;
892 int min = lModel.getMinSelectionIndex();
893
894 if(min != -1) {
895 for(int counter = min,
896 maxCounter = lModel.getMaxSelectionIndex();
897 counter <= maxCounter; counter++) {
898 if(!lModel.isSelectedIndex(counter)) {
899 if(counter == min) {
900 clearSelection();
901 }
902 else {
903 TreePath[] newSel = new TreePath[counter - min];
904 int[] selectionIndex = rowMapper.getRowsForPaths(selection);
905 // find the actual selection pathes corresponded to the
906 // rows of the new selection
907 for (int i = 0; i < selectionIndex.length; i++) {
908 if (selectionIndex[i]<counter) {
909 newSel[selectionIndex[i]-min] = selection[i];
910 }
911 }
912 setSelectionPaths(newSel);
913 break;
914 }
915 }
916 }
917 }
918 }
919 else if(selectionMode == TreeSelectionModel.SINGLE_TREE_SELECTION &&
920 selection != null && selection.length > 1) {
921 setSelectionPath(selection[0]);
922 }
923 }
924
|