KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chart2d > HorizontalTextListArea


1 /**
2  * Chart2D, a java library for drawing two dimensional charts.
3  * Copyright (C) 2001 Jason J. Simas
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * The author of this library may be contacted at:
19  * E-mail: jjsimas@users.sourceforge.net
20  * Street Address: J J Simas, 887 Tico Road, Ojai, CA 93023-3555 USA
21  */

22
23
24 package net.sourceforge.chart2d;
25
26
27 import java.awt.*;
28
29
30 /**
31  * A set of text labels layed out horizontally with bullets on either the top or
32  * bottom of the labels. The bullets can be layed out so that they are aligned
33  * with the center of each label, or aligned with the middle of the space
34  * between each label (horizontally). It
35  * was designed to be used for making a x axes for a chart program. But there
36  * may be
37  * other uses for a horizontal bulleted text list. Adjustments include
38  * bullets/no bullets, labels/no labels, bullet sizes, bullet colors, labels
39  * font color, size, style, and type; plus it allows for all the functionality
40  * of the the bordered area class including borders, spacing within borders,
41  * auto horizontal and vertical justification, auto sizing, and auto growing and
42  * shrinking of components.<br>
43  * Note: This class does not accept null values. Pass zero length arrays or
44  * empty strings instead.
45  */

46 final class HorizontalTextListArea extends TextListArea {
47
48
49   private boolean labelsExistence = true;
50   private TextArea[] labels;
51   private String JavaDoc[] labelStrings;
52
53   private boolean bulletsExistence = true;
54   private Rectangle[] bullets;
55   private Dimension bulletsSizeModel;
56   private int bulletsAlignment;
57   private int bulletsRelation;
58   private Color[] bulletColors;
59   private boolean bulletsOutline;
60   private Color bulletsOutlineColor;
61
62   private boolean betweenLabelsGapExistence;
63   private int betweenLabelsGapThicknessModel;
64   private boolean betweenBulletsGapExistence;
65   private int betweenBulletsGapThicknessModel;
66   private boolean betweenBulletsAndLabelsGapExistence;
67   private int betweenBulletsAndLabelsGapThicknessModel;
68   private boolean customizeSpaceMinWidth;
69   private int customSpaceMinWidth;
70
71   private boolean resetHorizontalTextListAreaModel;
72   private boolean allowSelfSize;
73   private boolean needsUpdate;
74
75
76   /**
77    * Constructs a new horizontal text list area with its default values.
78    */

79   HorizontalTextListArea() {
80
81     labels = new TextArea[0];
82     bullets = new Rectangle[0];
83     bulletColors = new Color[0];
84
85     setLabels (new String JavaDoc[0]);
86     setBulletColors (new Color[0]);
87     setBulletsSizeModel (new Dimension (9, 9));
88     setBulletsOutline (true);
89     setBulletsOutlineColor (Color.black);
90     setBetweenLabelsGapExistence (true);
91     setBetweenLabelsGapThicknessModel (3);
92     setBetweenBulletsGapExistence (true);
93     setBetweenBulletsGapThicknessModel (3);
94     setBetweenBulletsAndLabelsGapExistence (true);
95     setBetweenBulletsAndLabelsGapThicknessModel (3);
96     setBulletsAlignment (CENTERED);
97     setBulletsRelation (TOP);
98
99     setAllowSelfSize (true);
100     resetHorizontalTextListAreaModel (true);
101     needsUpdate = true;
102     customizeSpaceMinWidth = false;
103   }
104
105
106   /**
107    * Allows this text list area to determine its minimum size and reset its own
108    * size. This is useful when you want the component to be able to figure out
109    * its minimum size, but not always to set itself to that miniumum size.
110    * @param allow If true, then the component can reset its own minimum size.
111    * This is only relevant when auto minimum sizing is enabled.
112    */

113   final void setAllowSelfSize (boolean allow) {
114
115     needsUpdate = true;
116     allowSelfSize = allow;
117   }
118
119
120   /**
121    * Specifies the text for the labels. This value cannot be null; however,
122    * a zero or greater length array is fine.
123    * @param labels An array of the strings to be used for the labels.
124    */

125   final void setLabels (String JavaDoc[] labels) {
126
127     needsUpdate = true;
128     labelStrings = labels;
129   }
130
131
132   /**
133    * Allows for outside specification of the size of the text list.
134    * This method was introduced as an afterthought.
135    * It's used by LBChartArea for feeding back the size of the graph area.
136    * @param customize True if you want to customize the space width.
137    * @param width The custom space width (if the boolean is true).
138    */

139   final void setCustomSpaceMinWidth (boolean customize, int width) {
140
141     needsUpdate = true;
142     customizeSpaceMinWidth = customize;
143     customSpaceMinWidth = width;
144   }
145
146
147   /**
148    * Specifies the model size (width and height) of the bullets. A ratio based
149    * on maximum size / model size will be applied to this to find the actual
150    * bullet size -- when auto sizing the model maximum size is disabled.
151    * Otherwise, the actual size will be this size.
152    * @param model The model size of a bullet.
153    */

154   final void setBulletsSizeModel (Dimension model) {
155
156     needsUpdate = true;
157     bulletsSizeModel = model;
158   }
159
160
161   /**
162    * The horizontal alignment of the bullets respective to the labels. The
163    * bullets can either be place in line with each label, or in in line with
164    * the middle of the space between each label. That is, bullets can be
165    * centered in the middle of the label, or placed between each label.
166    * @param alignment The alignment for the bullets.
167    * Possible values are CENTERED and BETWEEN.
168    */

169   final void setBulletsAlignment (int alignment) {
170
171     needsUpdate = true;
172     bulletsAlignment = alignment;
173   }
174
175
176   /**
177    * Specifies the vertical relation of the bullets to the labels. The bullets
178    * can either be placed along the top of the labels or along the bottom.
179    * @param relation The vertical relation of the bullets.
180    * Possible values are TOP and BOTTOM.
181    */

182   final void setBulletsRelation (int relation) {
183
184     needsUpdate = true;
185     bulletsRelation = relation;
186   }
187
188
189   /**
190    * Specifies the colors of the bullets. Each bullet can have a different
191    * color so an array must be passed. The number of colors must be equal to
192    * the number of bullets. If the bullets alignment is between the labels and
193    * the lables do exist, then there should be one bullet less than the number
194    * of labels. If the bullets alignment is centered and the labels do exist,
195    * then there should be the same number of bullets as labels. Otherwise,
196    * choose any number of bullets. Number of bullets is set by setting the
197    * bullet colors. The number of bullets always equals the number of colors.
198    * @param colors An array filled with a color for each bullet. The first
199    * bullet from left to right gets the lowest order color in the array.
200    */

201   final void setBulletColors (Color[] colors) {
202
203     needsUpdate = true;
204     bulletColors = colors;
205   }
206
207
208   /**
209    * Specifies whether the bullets should have a small black outline.
210    * Outline is 1 pixel on all sides, at all times, and is black.
211    * Outlien is included in size of bullet.
212    * @param outline If true, then the outline will exist.
213    */

214   final void setBulletsOutline (boolean outline) {
215
216     needsUpdate = true;
217     bulletsOutline = outline;
218   }
219
220
221   /**
222    * Specifies the color of the bullets outline.
223    * @param color The outline color.
224    */

225   final void setBulletsOutlineColor (Color color) {
226
227     bulletsOutlineColor = color;
228   }
229
230
231   /**
232    * Specifies whether the <b>minimum</b> amount of space between each label,
233    * the gap, shall be enforced. If the gap does not exist, then it will
234    * not be included in calculations.
235    * @param existence The existence of the gap. If true, then it exists.
236    */

237   final void setBetweenLabelsGapExistence (boolean existence) {
238
239     needsUpdate = true;
240     betweenLabelsGapExistence = existence;
241   }
242
243
244   /**
245    * Specifies the model <b>minimum</b> thickness of the gap between the labels.
246    * @param model The model minimum thickness of the gap.
247    * Note: The gap may end up being more depending on sizing properties.
248    */

249   final void setBetweenLabelsGapThicknessModel (int model) {
250
251     needsUpdate = true;
252     betweenLabelsGapThicknessModel = model;
253   }
254
255
256   /**
257    * Specifies the existence of a minimum gap between each bullets. If the gap
258    * doesn't exist, then it will not be included in calculations.
259    * @param existence The existence of the minimum gap. If true, then the gap
260    * does exist.
261    */

262   final void setBetweenBulletsGapExistence (boolean existence) {
263
264     needsUpdate = true;
265     betweenBulletsGapExistence = existence;
266   }
267
268
269   /**
270    * Specifies the model <b>minimum</b> thickness of the gap between each
271    * bullet.
272    * @param model The model minimum thickness of the gap.
273    * Note: The gap may end up being more depending on sizing properties.
274    */

275   final void setBetweenBulletsGapThicknessModel (int model) {
276
277     needsUpdate = true;
278     betweenBulletsGapThicknessModel = model;
279   }
280
281
282   /**
283    * Specifies the existence of a minimum gap between the labels and the
284    * bullets. If the gap doesn't exist, then it will not be included in
285    * calculations.
286    * @param boolean The existence of the minimum gap. If true, then the gap
287    * does exist.
288    */

289   final void setBetweenBulletsAndLabelsGapExistence (boolean existence) {
290
291     needsUpdate = true;
292     betweenBulletsAndLabelsGapExistence = existence;
293   }
294
295
296   /**
297    * Specifies the model <b>minimum</b> thickness of the gap between the labels
298    * and the bullets.
299    * @param model The model minimum thickness of the gap.
300    * Note: The gap may end up being more depending on sizing properties.
301    */

302   final void setBetweenBulletsAndLabelsGapThicknessModel (int model) {
303
304     needsUpdate = true;
305     betweenBulletsAndLabelsGapThicknessModel = model;
306   }
307
308
309   /**
310    * Returns the label strings of this text list.
311    * @return The label strings.
312    */

313   final String JavaDoc[] getLabelStrings() {
314
315     return labelStrings;
316   }
317
318
319   /**
320    * Returns the labels. This is useful if other components
321    * need to be aligned exactly with the label's location or should be the
322    * exact same size.
323    * @param g2D The graphics context used for calculations.
324    * @return The array of TextArea's which are the labels.
325    */

326   final TextArea[] getLabels (Graphics2D g2D) {
327
328     updateHorizontalTextListArea (g2D);
329     return labels;
330   }
331
332
333   /**
334    * Returns the model thickness of the minimum gap between bullets.
335    * @return int The model thickness.
336    */

337   final int getBetweenBulletsGapThicknessModel() {
338
339     return betweenBulletsGapThicknessModel;
340   }
341
342
343   /**
344    * Returns the model thickness of the minimum gap between labels.
345    * @return The model thickness.
346    */

347   final int getBetweenLabelsGapThicknessModel() {
348
349     return betweenLabelsGapThicknessModel;
350   }
351
352
353   /**
354    * Returns the model <b>minimum</b> thickness of the gap between the labels
355    * and the bullets.
356    * @return The model minimum thickness of the gap.
357    */

358   final int getBetweenBulletsAndLabelsGapThicknessModel() {
359
360     return betweenBulletsAndLabelsGapThicknessModel;
361   }
362
363
364   /**
365    * Returns the bounds for each bullet. This is useful if other components
366    * need to be aligned exactly with the bullet's location or should be the
367    * exact same size.
368    * @param g2D The graphics context used for calculations.
369    * @return The array of rectangles which bound each bullet.
370    */

371   final Rectangle[] getBullets (Graphics2D g2D) {
372
373     updateHorizontalTextListArea (g2D);
374     return bullets;
375   }
376
377
378   /**
379    * Returns the model size of the bullets.
380    * @return The size.
381    */

382   final Dimension getBulletsSizeModel() {
383
384     return bulletsSizeModel;
385   }
386
387
388   /**
389    * Returns the horizontal alignment of the bullets respective to the labels.
390    * The bullets can either be place in line with each label, or in in line with
391    * the middle of the space between each label. That is, bullets can be
392    * centered in the middle of the label, or placed between each label.
393    * Possible values are CENTERED and BETWEEN.
394    * @return int The alignment for the bullets [CENTERED or BETWEEN].
395    */

396   final int getBulletsAlignment() {
397
398     return bulletsAlignment;
399   }
400
401
402   /**
403    * Specifies whether the bullets should have a small outline.
404    * Outline is 1 pixel on all sides, at all times, and is black.
405    * Outline is included in size of bullet.
406    * @return outline If true, then the outline will exist.
407    */

408   final boolean getBulletsOutline() {
409
410     return bulletsOutline;
411   }
412
413
414   /**
415    * Specifies the color of the bullets outline.
416    * @return color The outline color.
417    */

418   final Color getBulletsOutlineColor() {
419
420     return bulletsOutlineColor;
421   }
422
423
424   /**
425    * Returns the number of bullets this text list has. Calculates it each time.
426    * @return The number of bullets of this text list.
427    */

428   public int getNumBullets() {
429     int numBullets = bulletsExistence && labelsExistence ?
430       (bulletsAlignment == CENTERED ?
431       labelStrings.length : labelStrings.length - 1) : 0;
432     return (numBullets > 0 ? numBullets : 0);
433   }
434
435
436   /**
437    * Indicates whether some property of this class has changed.
438    * @return True if some property has changed.
439    */

440   final boolean getHorizontalTextListAreaNeedsUpdate() {
441
442     return (needsUpdate || getFontAreaNeedsUpdate());
443   }
444
445
446   /**
447    * Updates all variables. First updates the variables of its parent class,
448    * then updates its own variables.
449    * @param g2D The graphics context used for calculations.
450    */

451   final void updateHorizontalTextListArea (Graphics2D g2D) {
452
453     if (getHorizontalTextListAreaNeedsUpdate()) {
454       updateFontArea ();
455       update (g2D);
456     }
457     needsUpdate = false;
458   }
459
460
461   /**
462    * Resets the model for this class. The model is used for shrinking and
463    * growing of its components based on the maximum size of this class. If this
464    * method is called, then the next time the maximum size is set, this classes
465    * model maximum size will be made equal to the new maximum size. Effectively
466    * what this does is ensure that whenever this objects maximum size is equal
467    * to the one given, then all of the components will take on their default
468    * model sizes. Note: This is only useful when auto model max sizing is
469    * disabled.
470    * @param reset True causes the max model size to be set upon the next max
471    * sizing.
472    */

473   final void resetHorizontalTextListAreaModel (boolean reset) {
474
475     needsUpdate = true;
476     resetFontAreaModel (reset);
477   }
478
479
480   /**
481    * Paints all the components of this class. First all variables are updated.
482    * @param g2D The graphics context for calculations and painting.
483    */

484   final void paintComponent (Graphics2D g2D) {
485
486     updateHorizontalTextListArea (g2D);
487     super.paintComponent (g2D);
488
489     Color oldColor = g2D.getColor();
490
491     int num = labelsExistence ? labels.length : 0;
492     for (int i = 0; i < num; ++i) {
493       labels[i].paintComponent (g2D);
494     }
495
496     num = bulletsExistence ? bullets.length : 0;
497     for (int i = 0; i < num; ++i) {
498
499       g2D.setColor (bulletColors[i]);
500       g2D.fill (bullets[i]);
501
502       if (bulletsOutline) {
503         g2D.setColor (bulletsOutlineColor);
504         g2D.draw (bullets[i]);
505       }
506     }
507
508     g2D.setColor (oldColor);
509   }
510
511
512   private void update (Graphics2D g2D) {
513
514     int numLabels = labelsExistence ? labelStrings.length : 0;
515     labels = new TextArea[numLabels];
516     int numBullets = getNumBullets();
517     bullets = new Rectangle[numBullets];
518
519     int numBulletGaps = bulletsAlignment == CENTERED ?
520       (numBullets - 1) : (numBullets + 1);
521     int requiredNumBulletsForGaps = bulletsAlignment == CENTERED ? 2 : 1;
522     int requiredNumBulletsForSpacing = bulletsAlignment == CENTERED ?
523       numBullets : (numBullets + 1);
524
525     int betweenBulletsAndLabelsGapThickness = 0;
526     int availableHeight = getSpaceSize (MAX).height;
527     if (betweenBulletsAndLabelsGapExistence && labelsExistence) {
528       betweenBulletsAndLabelsGapThickness = applyRatio (
529         betweenBulletsAndLabelsGapThicknessModel, getRatio (HEIGHT));
530       betweenBulletsAndLabelsGapThickness =
531         betweenBulletsAndLabelsGapThickness <= availableHeight ?
532         betweenBulletsAndLabelsGapThickness : availableHeight;
533       availableHeight -= betweenBulletsAndLabelsGapThickness;
534     }
535
536     int availableWidthForLabels = getSpaceSize (MAX).width;
537     int availableWidthForBullets = getSpaceSize (MAX).width;
538     int betweenLabelsGapThickness = 0;
539     if (betweenLabelsGapExistence && numLabels > 1) {
540       betweenLabelsGapThickness =
541        applyRatio (betweenLabelsGapThicknessModel, getRatio (WIDTH));
542       betweenLabelsGapThickness = betweenLabelsGapThickness <=
543         (availableWidthForLabels / (numLabels - 1)) ?
544         betweenLabelsGapThickness :
545         (availableWidthForLabels / (numLabels - 1));
546       availableWidthForLabels -=
547         ((numLabels - 1) * betweenLabelsGapThickness);
548     }
549
550     int betweenBulletsGapThickness = 0;
551     if (betweenBulletsGapExistence && numBullets >= requiredNumBulletsForGaps) {
552       betweenBulletsGapThickness =
553         applyRatio (betweenBulletsGapThicknessModel, getRatio (WIDTH));
554       betweenBulletsGapThickness = betweenBulletsGapThickness <=
555         (availableWidthForBullets / numBulletGaps) ?
556         betweenBulletsGapThickness :
557         (availableWidthForBullets / numBulletGaps);
558       availableWidthForBullets -=
559         (numBulletGaps * betweenBulletsGapThickness);
560     }
561
562     int bulletsWidth = 0;
563     int bulletsHeight = 0;
564     if (bulletsExistence) {
565       if (numBullets > 0) {
566         bulletsWidth = applyRatio (bulletsSizeModel.width, getRatio (WIDTH));
567         bulletsWidth = bulletsWidth <=
568           (availableWidthForBullets / requiredNumBulletsForSpacing) ?
569           bulletsWidth :
570           (availableWidthForBullets / requiredNumBulletsForSpacing);
571         bulletsHeight = applyRatio (bulletsSizeModel.height, getRatio (HEIGHT));
572         bulletsHeight =
573           bulletsHeight <= availableHeight ? bulletsHeight : availableHeight;
574       }
575       if (bulletsWidth <= 0 || bulletsHeight <= 0) {
576         bulletsWidth = 0;
577         bulletsHeight = 0;
578       }
579       else {
580         availableHeight -= bulletsHeight;
581       }
582     }
583
584     int labelsWidth = 0;
585     int labelsHeight = 0;
586     if (labelsExistence && numLabels > 0) {
587       labelsWidth = availableWidthForLabels / numLabels;
588       labelsHeight = availableHeight;
589     }
590
591     for (int i = 0; i < numLabels; ++i) {
592       labels[i] = new TextArea();
593       labels[i].setCustomRatio (WIDTH, true, getRatio (WIDTH));
594       labels[i].setCustomRatio (HEIGHT, true, getRatio (HEIGHT));
595       labels[i].setAutoSizes (true, false);
596       labels[i].setSize (MAX, new Dimension (labelsWidth, labelsHeight));
597       labels[i].setBorderExistence (false);
598       labels[i].setGapExistence (false);
599       labels[i].setBackgroundExistence (false);
600       labels[i].setText (labelStrings[i]);
601       labels[i].setFontName(getFontName());
602       labels[i].setFontStyle(getFontStyle());
603       labels[i].setFontPointModel(getFontPointModel());
604       labels[i].setFontColor(getFontColor());
605     }
606
607     int greatestLabelWidth = 0;
608     int smallestLabelWidth = Integer.MAX_VALUE;
609     int greatestLabelHeight = 0;
610     for (int i = 0; i < numLabels; ++i) {
611       labels[i].updateTextArea (g2D);
612       int thisLabelWidth = labels[i].getSize (MIN).width;
613       greatestLabelWidth = thisLabelWidth > greatestLabelWidth ?
614         thisLabelWidth : greatestLabelWidth;
615       smallestLabelWidth = thisLabelWidth < smallestLabelWidth ?
616         thisLabelWidth : smallestLabelWidth;
617       int thisLabelHeight = labels[i].getSize (MIN).height;
618       greatestLabelHeight = thisLabelHeight > greatestLabelHeight ?
619         thisLabelHeight : greatestLabelHeight;
620     }
621
622     if (smallestLabelWidth > 0) {
623       labelsWidth = greatestLabelWidth;
624       labelsHeight = greatestLabelHeight;
625     }
626     else {
627       labelsWidth = 0;
628       labelsHeight = 0;
629       betweenLabelsGapThickness = 0;
630       for (int i = 0; i < numLabels; ++i) {
631         labels[i].setSize (MAX, new Dimension());
632       }
633
634       betweenBulletsAndLabelsGapThickness = 0;
635       availableHeight = getSpaceSize (MAX).height;
636       bulletsWidth = 0;
637       bulletsHeight = 0;
638       if (bulletsExistence && numBullets > 0) {
639         bulletsWidth = applyRatio (bulletsSizeModel.width, getRatio (WIDTH));
640         bulletsWidth = bulletsWidth <=
641           (availableWidthForBullets / requiredNumBulletsForSpacing) ?
642           bulletsWidth :
643           (availableWidthForBullets / requiredNumBulletsForSpacing);
644         bulletsHeight = applyRatio (bulletsSizeModel.height, getRatio (HEIGHT));
645         bulletsHeight =
646           bulletsHeight <= availableHeight ? bulletsHeight : availableHeight;
647       }
648       if (bulletsWidth <= 0 || bulletsHeight <= 0) {
649         bulletsWidth = 0;
650         bulletsHeight = 0;
651         betweenBulletsGapThickness = 0;
652       }
653     }
654
655     if (!getAutoSize (MIN) && allowSelfSize) {
656       int possibleMinSpaceWidthLabels =
657         numLabels * labelsWidth + (numLabels - 1) * betweenLabelsGapThickness;
658       int possibleMinSpaceWidthBullets =
659         requiredNumBulletsForSpacing * bulletsWidth +
660         numBulletGaps * betweenBulletsGapThickness;
661       int minSpaceWidth =
662         possibleMinSpaceWidthLabels > possibleMinSpaceWidthBullets ?
663         possibleMinSpaceWidthLabels : possibleMinSpaceWidthBullets;
664       minSpaceWidth =
665         customizeSpaceMinWidth && customSpaceMinWidth > minSpaceWidth ?
666         customSpaceMinWidth : minSpaceWidth;
667       int minSpaceHeight =
668         bulletsHeight + betweenBulletsAndLabelsGapThickness + labelsHeight;
669       setSpaceSize (MIN,
670         new Dimension (minSpaceWidth, minSpaceHeight));
671     }
672
673     int numComps = numLabels;
674     float compWidth = getSpaceSize (MIN).width / (float)numComps;
675     int x = getSpaceSizeLocation (MIN).x;
676     int y = getSpaceSizeLocation (MIN).y;
677     int labelsX = 0, labelsY = 0, bulletsX = 0, bulletsY = 0;
678     for (int i = 0; i < numComps; ++i) {
679
680       labels[i].setAutoJustifys (false, false);
681       if (bulletsRelation == TOP) {
682         labelsY = y + bulletsHeight + betweenBulletsAndLabelsGapThickness;
683         bulletsY = y;
684       }
685       else {
686         labelsY = y + labelsHeight - labels[i].getSpaceSize(MIN).height;
687         bulletsY = y + labelsHeight + betweenBulletsAndLabelsGapThickness;
688       }
689       labelsX = (int)(x + i * compWidth +
690         (compWidth - labels[i].getSpaceSize (MIN).width) / 2f);
691       labels[i].setSpaceSizeLocation (MIN, new Point (labelsX, labelsY));
692       if (i < numBullets) {
693         if (bulletsAlignment == CENTERED) {
694           bulletsX =
695             (int)(x + i * compWidth + (compWidth - bulletsWidth) / 2f);
696         }
697         else {
698           bulletsX =
699             (int)(x + (i + 1) * compWidth - bulletsWidth / 2f);
700         }
701         bullets[i] = new Rectangle();
702         bullets[i].setLocation (bulletsX, bulletsY);
703         bullets[i].setSize (bulletsWidth, bulletsHeight);
704       }
705     }
706   }
707 }
Popular Tags