1 /* 2 * Copyright (c) 1997, 2014, 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 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.util.Vector; 29 import java.util.Enumeration; 30 31 import javax.swing.event.*; 32 33 34 /** 35 * This class loosely implements the <code>java.util.Vector</code> 36 * API, in that it implements the 1.1.x version of 37 * <code>java.util.Vector</code>, has no collection class support, 38 * and notifies the <code>ListDataListener</code>s when changes occur. 39 * Presently it delegates to a <code>Vector</code>, 40 * in a future release it will be a real Collection implementation. 41 * <p> 42 * <strong>Warning:</strong> 43 * Serialized objects of this class will not be compatible with 44 * future Swing releases. The current serialization support is 45 * appropriate for short term storage or RMI between applications running 46 * the same version of Swing. As of 1.4, support for long term storage 47 * of all JavaBeans™ 48 * has been added to the <code>java.beans</code> package. 49 * Please see {@link java.beans.XMLEncoder}. 50 * 51 * @param <E> the type of the elements of this model 52 * 522 * <p> 523 * Throws an <code>ArrayIndexOutOfBoundsException</code> 524 * if the index was invalid. 525 * Throws an <code>IllegalArgumentException</code> if 526 * <code>fromIndex > toIndex</code>. 527 * 528 * @param fromIndex the index of the lower end of the range 529 * @param toIndex the index of the upper end of the range 530 * @see #remove(int) 531 */ 532 public void removeRange(int fromIndex, int toIndex) { 533 if (fromIndex > toIndex) { 534 throw new IllegalArgumentException("fromIndex must be <= toIndex"); 535 } 536 for(int i = toIndex; i >= fromIndex; i--) { 537 delegate.removeElementAt(i); 538 } 539 fireIntervalRemoved(this, fromIndex, toIndex); 540 } 541 542 /* 543 public void addAll(Collection c) { 544 } 545 546 public void addAll(int index, Collection c) { 547 } 548 */ 549 } | 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 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.util.Vector; 29 import java.util.Collection; 30 import java.util.Enumeration; 31 32 33 /** 34 * This class loosely implements the <code>java.util.Vector</code> 35 * API, in that it implements the 1.1.x version of 36 * <code>java.util.Vector</code>, has no collection class support, 37 * and notifies the <code>ListDataListener</code>s when changes occur. 38 * Presently it delegates to a <code>Vector</code>, 39 * in a future release it will be a real Collection implementation. 40 * <p> 41 * <strong>Warning:</strong> 42 * Serialized objects of this class will not be compatible with 43 * future Swing releases. The current serialization support is 44 * appropriate for short term storage or RMI between applications running 45 * the same version of Swing. As of 1.4, support for long term storage 46 * of all JavaBeans™ 47 * has been added to the <code>java.beans</code> package. 48 * Please see {@link java.beans.XMLEncoder}. 49 * 50 * @param <E> the type of the elements of this model 51 * 521 * <p> 522 * Throws an <code>ArrayIndexOutOfBoundsException</code> 523 * if the index was invalid. 524 * Throws an <code>IllegalArgumentException</code> if 525 * <code>fromIndex > toIndex</code>. 526 * 527 * @param fromIndex the index of the lower end of the range 528 * @param toIndex the index of the upper end of the range 529 * @see #remove(int) 530 */ 531 public void removeRange(int fromIndex, int toIndex) { 532 if (fromIndex > toIndex) { 533 throw new IllegalArgumentException("fromIndex must be <= toIndex"); 534 } 535 for(int i = toIndex; i >= fromIndex; i--) { 536 delegate.removeElementAt(i); 537 } 538 fireIntervalRemoved(this, fromIndex, toIndex); 539 } 540 541 /** 542 * Adds all of the elements present in the collection to the list. 543 * 544 * @param c the collection which contains the elements to add. 545 */ 546 public void addAll(Collection<E> c) { 547 if (c.isEmpty()) { 548 return; 549 } 550 551 int startIndex = getSize(); 552 553 delegate.addAll(c); 554 fireIntervalAdded(this, startIndex, getSize() - 1); 555 } 556 557 /** 558 * Adds all of the elements present in the collection, starting 559 * from the index specified. 560 * <p> 561 * Throws as <code>IllegalArgumentException</code> if the 562 * index is invalid. 563 * 564 * @param index the index from which to start adding elements from. 565 * @param c the collection which contains the elements to add 566 * @exception IllegalArgumentException if <code>c</code> doesn't 567 * fall in the rang of the list. 568 */ 569 public void addAll(int index, Collection<E> c) { 570 if (index < 0 || index > getSize()) { 571 throw new IllegalArgumentException( 572 "index number must be >=0 and <= number of elements in the list."); 573 } 574 if(c.isEmpty()) { 575 return; 576 } 577 578 delegate.addAll(index, c); 579 fireIntervalAdded(this, index, index + c.size() - 1); 580 } 581 } |