OSDN Git Service

2004-01-28 Michael Koch <konqueror@gmx.de>
[pf3gnuchains/gcc-fork.git] / libjava / javax / swing / SizeSequence.java
1 /* SizeSequence.java --
2    Copyright (C) 2002 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
20
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library.  Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
25
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module.  An independent module is a module which is not derived from
33 or based on this library.  If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so.  If you do not wish to do so, delete this
36 exception statement from your version. */
37
38 package javax.swing;
39
40 /**
41  * SizeSequence
42  * @author      Andrew Selkirk
43  * @version     1.0
44  */
45 public class SizeSequence {
46
47         //-------------------------------------------------------------
48         // Variables --------------------------------------------------
49         //-------------------------------------------------------------
50
51         /**
52          * sizes
53          */
54         private int[] sizes = new int[0];
55
56
57         //-------------------------------------------------------------
58         // Initialization ---------------------------------------------
59         //-------------------------------------------------------------
60
61         /**
62          * Constructor SizeSequence
63          */
64         public SizeSequence() {
65                 sizes = new int[0];
66         } // SizeSequence()
67
68         /**
69          * Constructor SizeSequence
70          * @param numEntries TODO
71          */
72         public SizeSequence(int numEntries) {
73                 this(numEntries, 0);
74         } // SizeSequence()
75
76         /**
77          * Constructor SizeSequence
78          * @param numEntries TODO
79          * @param value TODO
80          */
81         public SizeSequence(int numEntries, int value) {
82                 insertEntries(0, numEntries, value);
83         } // SizeSequence()
84
85         /**
86          * Constructor SizeSequence
87          * @param sizes TODO
88          */
89         public SizeSequence(int[] sizes) {
90                 setSizes(sizes);
91         } // SizeSequence()
92
93
94         //-------------------------------------------------------------
95         // Methods ----------------------------------------------------
96         //-------------------------------------------------------------
97
98         /**
99          * setSize
100          * @param index TODO
101          * @param size TODO
102          */
103         public void setSize(int index, int size) {
104                 sizes[index] = size;
105         } // setSize()
106
107         /**
108          * getIndex
109          * @param position TODO
110          * @returns int
111          */
112         public int getIndex(int position) {
113                 return 0; // TODO
114         } // getIndex()
115
116         /**
117          * getSize
118          * @param index TODO
119          * @returns int
120          */
121         public int getSize(int index) {
122                 return sizes[index];
123         } // getSize()
124
125         /**
126          * setSizes
127          * @param sizes TODO
128          */
129         public void setSizes(int[] sizes) {
130         
131                 // Variables
132                 int             index;
133                 
134                 // Initialize Sizes
135                 this.sizes = new int[sizes.length];
136                 for (index = 0; index < sizes.length; index++) {
137                         this.sizes[index] = sizes[index];
138                 } // for
139
140         } // setSizes()
141
142         /**
143          * getSizes
144          * @returns int[]
145          */
146         public int[] getSizes() {
147         
148                 // Variables
149                 int[]   array;
150                 int             index;
151
152                 // Create New Array
153                 array = new int[sizes.length];
154                 for (index = 0; index < sizes.length; index++) {
155                         array[index] = sizes[index];
156                 } // for
157
158                 // Return Newly created array
159                 return array;
160
161         } // getSizes()
162
163         /**
164          * getPosition
165          * @param index TODO
166          * @returns int
167          */
168         public int getPosition(int index) {
169         
170                 // Variables
171                 int             position;
172                 int             loop;
173                 
174                 // Process Sizes
175                 position = 0;
176                 for (loop = 0; loop < index; loop++) {
177                         position += sizes[loop];
178                 } // for
179
180                 // Return Position
181                 return position;
182
183         } // getPosition()
184
185         /**
186          * insertEntries
187          * @param start TODO
188          * @param length TODO
189          * @param value TODO
190          */
191         public void insertEntries(int start, int length, int value) {
192
193                 // Variables
194                 int[]   array;
195                 int             index;
196                 int             arrayIndex;
197                 int             loop;
198
199                 // Create New Array
200                 array = new int[sizes.length + length];
201                 arrayIndex = 0;
202                 for (index = 0; index < sizes.length; index++) {
203                         if (index == start) {
204                                 for (loop = 0; loop < length; loop++) {
205                                         array[arrayIndex] = value;
206                                         arrayIndex++;
207                                 } // for
208                         } else {
209                                 array[arrayIndex] = sizes[index];
210                                 arrayIndex++;
211                         } // if
212                 } // for
213
214         } // insertEntries()
215
216         /**
217          * removeEntries
218          * @param start TODO
219          * @param length TODO
220          */
221         public void removeEntries(int start, int length) {
222
223                 // Variables
224                 int[]   array;
225                 int             index;
226                 int             arrayIndex;
227
228                 // Sanity Check
229                 if ((start + length) > sizes.length) {
230                         throw new IllegalArgumentException("Specified start/length that " +
231                                 "is greater than available sizes");
232                 } // if
233
234                 // Create New Array
235                 array = new int[sizes.length - length];
236                 arrayIndex = 0;
237                 for (index = 0; index < sizes.length; index++) {
238                         if (index == start) {
239                                 index += length - 1;
240                         } else {
241                                 array[arrayIndex] = sizes[index];
242                                 arrayIndex++;
243                         } // if
244                 } // for
245
246         } // removeEntries()
247
248
249 } // SizeSequence