Repository navigation
Expand file tree
/
Copy pathSSOptionsDialog.java
More file actions
198 lines (164 loc) · 5.08 KB
/
Copy pathSSOptionsDialog.java
File metadata and controls
198 lines (164 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//#preprocess
package com.mlhsoftware.SimplySolitaire;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
//#ifdef V47
import net.rim.device.api.ui.VirtualKeyboard;
//#endif
class SSOptionsDialog extends MainScreen
{
private ChoiceFieldManager drawThreeOption;
private ChoiceFieldManager backgroundColorOption;
private ChoiceFieldManager cardOffsetOption;
private ChoiceFieldManager redealOption;
private ChoiceFieldManager clickOption;
//private ObjectChoiceField m_CumulativeScoreOption;
private SSOptionsProperties optionProperties;
public SSOptionsDialog()
{
super( DEFAULT_MENU | DEFAULT_CLOSE | Manager.NO_VERTICAL_SCROLL );
boolean bStorm = false;
//#ifdef V47
VirtualKeyboard vKeyboard = getVirtualKeyboard();
if ( vKeyboard != null )
{
bStorm = true;
}
//#endif
//Read in the properties from the persistent store.
optionProperties = SolitaireGame.m_optionProperties;
// Build the titlebar
TitlebarManager titlebarMgr = new TitlebarManager( AppInfo.APP_NAME + " Options", false );
add( titlebarMgr );
ForegroundManager foreground = new ForegroundManager();
add( foreground );
ListStyleFieldSet infoSet = new ListStyleFieldSet();
foreground.add( infoSet );
Object[] choices1 = { "Yes", "No" };
int enableIndex = 0;
if ( !optionProperties.getDrawThree() )
{
enableIndex = 1;
}
this.drawThreeOption = new ChoiceFieldManager( "Draw Three: ", choices1, enableIndex );
infoSet.add( this.drawThreeOption );
Object[] choices4 = { "Unlimited", "1", "2" };
enableIndex = optionProperties.getRedealCount();
this.redealOption = new ChoiceFieldManager( "Redeals: ", choices4, enableIndex );
infoSet.add( this.redealOption );
Object[] choices2 = { "Green", "Gray", "Blue", "Red" };
enableIndex = optionProperties.getBackground();
this.backgroundColorOption = new ChoiceFieldManager( "Background: ", choices2, enableIndex );
infoSet.add( this.backgroundColorOption );
Object[] choices3 = { "1", "2", "3", "4" };
enableIndex = optionProperties.getCardOffset();
this.cardOffsetOption = new ChoiceFieldManager( "Card Separation: ", choices3, enableIndex );
infoSet.add( this.cardOffsetOption );
this.clickOption = null;
if ( bStorm )
{
Object[] choices5 = { "touch", "click" };
enableIndex = 0;
if ( optionProperties.getClickSelect() )
{
enableIndex = 1;
}
this.clickOption = new ChoiceFieldManager( "Select via: ", choices5, enableIndex );
infoSet.add( this.clickOption );
}
ListStyleButtonField saveBtn = new ListStyleButtonField( null, "Save Changes", null );
saveBtn.setChangeListener( new FieldChangeListener()
{
public void fieldChanged( Field field, int context )
{
OnDone();
}
} );
infoSet.add( saveBtn );
}
public boolean onClose()
{
if ( isDirty() )
{
int answer = Dialog.ask( Dialog.D_SAVE, "Save Changes?", Dialog.SAVE );
if ( answer == Dialog.SAVE )
{
OnDone();
}
else if ( answer == Dialog.DISCARD )
{
OnCancel();
}
}
else
{
OnCancel();
}
return false;
}
public void save()
{
//Get the new values from the UI controls
//and set them in optionProperties.
optionProperties.setDrawThree( this.drawThreeOption.getSelectedIndex() == 0 );
optionProperties.setBackground( this.backgroundColorOption.getSelectedIndex() );
optionProperties.setCardOffset( this.cardOffsetOption.getSelectedIndex() );
optionProperties.setRedealCount( this.redealOption.getSelectedIndex() );
if ( this.clickOption != null )
{
optionProperties.setClickSelect( this.clickOption.getSelectedIndex() == 1 );
}
//Write our changes back to the persistent store.
optionProperties.save();
//Null out our member variables so that their objects can be garbage
//collected. Note that this instance continues to be held by the
//options manager even after the user exits the options app,
//and will be re-used next time.
this.drawThreeOption = null;
this.backgroundColorOption = null;
this.cardOffsetOption = null;
optionProperties = null;
}
private void OnDone()
{
save();
close();
}
private void OnCancel()
{
close();
}
private final class OkButton extends ButtonField
{
private OkButton()
{
super( "OK", ButtonField.CONSUME_CLICK );
}
protected void fieldChangeNotify( int context )
{
if ( ( context & FieldChangeListener.PROGRAMMATIC ) == 0 )
{
save();
close();
}
}
}
/**
* This inner class simply closes our 'Learn correction' PopupScreen.
*/
private final class CancelButton extends ButtonField
{
private CancelButton()
{
super( "Cancel", ButtonField.CONSUME_CLICK );
}
protected void fieldChangeNotify( int context )
{
if ( ( context & FieldChangeListener.PROGRAMMATIC ) == 0 )
{
close();
}
}
}
}