1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
12 import java
.util
.Objects
;
13 import java
.util
.Random
;
14 import javax
.microedition
.lcdui
.Font
;
15 import javax
.microedition
.lcdui
.Image
;
16 import javax
.microedition
.lcdui
.List
;
19 * This stores information about a single list item.
23 public final class ListItem
34 /** Is this enabled? */
35 public boolean enabled
;
37 /** Is this selected? */
38 public boolean selected
;
41 * Initializes the given list item.
43 * @param __label The label.
44 * @param __image The image.
45 * @param __font The font.
46 * @param __enabled Is this enabled?
47 * @param __selected Is this selected?
48 * @throws NullPointerException If there is no label.
51 public ListItem(String __label
, Image __image
, Font __font
,
52 boolean __enabled
, boolean __selected
)
53 throws NullPointerException
56 throw new NullPointerException("NARG");
61 this.enabled
= __enabled
;
62 this.selected
= __selected
;
70 public boolean equals(Object __o
)
75 if (!(__o
instanceof ListItem
))
78 ListItem o
= (ListItem
)__o
;
79 return this.hashCode() == o
.hashCode() &&
80 this.enabled
== o
.enabled
&&
81 this.selected
== o
.selected
&&
82 Objects
.equals(this.label
, o
.label
) &&
83 Objects
.equals(this.image
, o
.image
) &&
84 Objects
.equals(this.font
, o
.font
);
96 rv ^
= (this.selected ?
0x8000_
0000 : 0x4000_
0000);
97 rv ^
= (this.enabled ?
0x0800_
0000 : 0x0400_
0000);
98 rv ^
= (this.label
!= null ?
99 (this.label
.hashCode() | 0x0080_
0000) : 0x0040_
0000);
100 rv ^
= (this.image
!= null ?
101 (this.image
.hashCode() | 0x0008_
0000) : 0x0004_
0000);
102 rv ^
= (this.font
!= null ?
103 (this.font
.hashCode() | 0x0000_
8000) : 0x0000_
4000);
109 * Sets the given list item.
111 * @param __list The list to set.
112 * @param __dx The index to set.
113 * @throws NullPointerException On null arguments.
116 public final void into(List __list
, int __dx
)
117 throws NullPointerException
120 throw new NullPointerException("NARG");
122 __list
.set(__dx
, this.label
, this.image
);
123 __list
.setFont(__dx
, this.font
);
124 __list
.setSelectedIndex(__dx
, this.selected
);
125 __list
.setEnabled(__dx
, this.enabled
);
129 * Returns information on the given list item.
131 * @param __list The list to get from.
132 * @param __dx The index to read.
133 * @return The resulting list item.
134 * @throws NullPointerException On null arguments.
137 public static ListItem
of(List __list
, int __dx
)
138 throws NullPointerException
141 throw new NullPointerException("NARG");
143 return new ListItem(__list
.getString(__dx
),
144 __list
.getImage(__dx
),
145 __list
.getFont(__dx
),
146 __list
.isEnabled(__dx
),
147 __list
.isSelected(__dx
));
151 * Returns a randomized item.
153 * @param __rand The randomized source.
154 * @return A newly randomized list item.
155 * @throws NullPointerException On null arguments.
158 public static ListItem
random(Random __rand
)
159 throws NullPointerException
162 throw new NullPointerException("NARG");
166 switch (__rand
.nextInt(3))
168 case 0: face
= Font
.FACE_MONOSPACE
; break;
169 case 1: face
= Font
.FACE_PROPORTIONAL
; break;
170 default: face
= Font
.FACE_SYSTEM
; break;
175 switch (__rand
.nextInt(4))
177 case 0: style
= Font
.STYLE_BOLD
; break;
178 case 1: style
= Font
.STYLE_ITALIC
; break;
179 case 2: style
= Font
.STYLE_PLAIN
; break;
180 default: style
= Font
.STYLE_UNDERLINED
; break;
185 switch (__rand
.nextInt(3))
187 case 0: size
= Font
.SIZE_LARGE
; break;
188 case 1: size
= Font
.SIZE_MEDIUM
; break;
189 default: size
= Font
.SIZE_SMALL
; break;
193 Character
.toString((char)('a' + __rand
.nextInt(25))),
194 Image
.createImage(1 + __rand
.nextInt(16),
195 1 + __rand
.nextInt(16)),
196 Font
.getFont(face
, style
, size
),
197 __rand
.nextBoolean(), __rand
.nextBoolean());