Skip to content

Commit e36afa0

Browse files
committed
Enable disable currency exchange. (UI)
1 parent b0850ab commit e36afa0

File tree

3 files changed

+86
-31
lines changed

3 files changed

+86
-31
lines changed

src/org/yccheok/jstock/gui/JStockOptions.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ public JStockOptions() {
292292

293293
private Map<Country, String> currencies = new EnumMap<Country, String>(Country.class);
294294

295-
@Deprecated
296-
private transient Map<Country, Boolean> currencyExchangeEnable = new EnumMap<Country, Boolean>(Country.class);
295+
private Map<Country, Boolean> currencyExchangeEnable = new EnumMap<Country, Boolean>(Country.class);
297296

298297
private Map<Country, Country> localCurrencyCountries = new EnumMap<Country, Country>(Country.class);
299298

@@ -430,7 +429,7 @@ public void insensitiveCopy(JStockOptions jStockOptions) {
430429

431430
this.priceSources = new EnumMap<Country, PriceSource>(jStockOptions.priceSources);
432431
this.currencies = new EnumMap<Country, String>(jStockOptions.currencies);
433-
//this.currencyExchangeEnable = new EnumMap<Country, Boolean>(jStockOptions.currencyExchangeEnable);
432+
this.currencyExchangeEnable = new EnumMap<Country, Boolean>(jStockOptions.currencyExchangeEnable);
434433
this.localCurrencyCountries = new EnumMap<Country, Country>(jStockOptions.localCurrencyCountries);
435434
//this.penceToPoundConversionEnabled = new EnumMap<Country, Boolean>(jStockOptions.penceToPoundConversionEnabled);
436435
this.fourDecimalPlacesEnabled = new EnumMap<Country, Boolean>(jStockOptions.fourDecimalPlacesEnabled);
@@ -557,7 +556,7 @@ public JStockOptions insensitiveClone() {
557556
// Perform deep copy.
558557
jStockOptions.priceSources = new EnumMap<Country, PriceSource>(this.priceSources);
559558
jStockOptions.currencies = new EnumMap<Country, String>(this.currencies);
560-
//jStockOptions.currencyExchangeEnable = new EnumMap<Country, Boolean>(this.currencyExchangeEnable);
559+
jStockOptions.currencyExchangeEnable = new EnumMap<Country, Boolean>(this.currencyExchangeEnable);
561560
jStockOptions.localCurrencyCountries = new EnumMap<Country, Country>(this.localCurrencyCountries);
562561
//jStockOptions.penceToPoundConversionEnabled = new EnumMap<Country, Boolean>(jStockOptions.penceToPoundConversionEnabled);
563562
jStockOptions.fourDecimalPlacesEnabled = new EnumMap<Country, Boolean>(jStockOptions.fourDecimalPlacesEnabled);
@@ -693,9 +692,9 @@ private Object readResolve() {
693692
this.currencies = new EnumMap<Country, String>(Country.class);
694693
}
695694

696-
//if (this.currencyExchangeEnable == null) {
697-
// this.currencyExchangeEnable = new EnumMap<Country, Boolean>(Country.class);
698-
//}
695+
if (this.currencyExchangeEnable == null) {
696+
this.currencyExchangeEnable = new EnumMap<Country, Boolean>(Country.class);
697+
}
699698

700699
if (this.localCurrencyCountries == null) {
701700
this.localCurrencyCountries = new EnumMap<Country, Country>(Country.class);
@@ -1338,6 +1337,30 @@ public void setCurrencySymbol(Country c, String s) {
13381337
this.currencies.put(c, s);
13391338
}
13401339

1340+
/**
1341+
* Returns true if currency exchange feature is enabled for country.
1342+
*
1343+
* @param c the country to get
1344+
* @return true if currency exchange feature is enabled for the country
1345+
*/
1346+
public boolean isCurrencyExchangeEnable(Country c) {
1347+
Boolean flag = this.currencyExchangeEnable.get(c);
1348+
if (flag != null) {
1349+
return flag;
1350+
}
1351+
return false;
1352+
}
1353+
1354+
/**
1355+
* Enables currency exchange feature for the country.
1356+
*
1357+
* @param country the country to set
1358+
* @param enable true to enable
1359+
*/
1360+
public void setCurrencyExchangeEnable(Country country, boolean enable) {
1361+
this.currencyExchangeEnable.put(country, enable);
1362+
}
1363+
13411364
/**
13421365
* Returns country of local currency used to purchase foreign stocks. If no
13431366
* country of local currency found for the country of foreign stocks,

src/org/yccheok/jstock/gui/OptionsSellAdvisorJPanel.form

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
1212
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="true"/>
1313
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="0"/>
14-
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,59,0,0,1,-125"/>
14+
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,75,0,0,1,-119"/>
1515
</AuxValues>
1616

1717
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
@@ -64,7 +64,7 @@
6464
<Component id="jPanel3" min="-2" max="-2" attributes="0"/>
6565
<EmptySpace type="unrelated" max="-2" attributes="0"/>
6666
<Component id="jPanel4" min="-2" max="-2" attributes="0"/>
67-
<EmptySpace max="32767" attributes="0"/>
67+
<EmptySpace pref="27" max="32767" attributes="0"/>
6868
</Group>
6969
</Group>
7070
</DimensionLayout>
@@ -140,7 +140,7 @@
140140
<Group type="102" attributes="0">
141141
<EmptySpace max="-2" attributes="0"/>
142142
<Component id="jCheckBox3" min="-2" max="-2" attributes="0"/>
143-
<EmptySpace pref="102" max="32767" attributes="0"/>
143+
<EmptySpace pref="108" max="32767" attributes="0"/>
144144
</Group>
145145
</Group>
146146
</DimensionLayout>
@@ -163,6 +163,7 @@
163163
</Properties>
164164
<AuxValues>
165165
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="false"/>
166+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="2"/>
166167
</AuxValues>
167168
</Component>
168169
</SubComponents>
@@ -181,11 +182,14 @@
181182
<Layout>
182183
<DimensionLayout dim="0">
183184
<Group type="103" groupAlignment="0" attributes="0">
184-
<Group type="102" attributes="0">
185+
<Group type="102" alignment="0" attributes="0">
185186
<EmptySpace max="-2" attributes="0"/>
186187
<Group type="103" groupAlignment="0" attributes="0">
187-
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
188-
<Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/>
188+
<Component id="jCheckBox1" alignment="0" min="-2" max="-2" attributes="0"/>
189+
<Group type="102" attributes="0">
190+
<EmptySpace min="21" pref="21" max="-2" attributes="0"/>
191+
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
192+
</Group>
189193
</Group>
190194
<EmptySpace type="unrelated" max="-2" attributes="0"/>
191195
<Group type="103" groupAlignment="0" attributes="0">
@@ -201,15 +205,15 @@
201205
<Group type="102" alignment="0" attributes="0">
202206
<EmptySpace max="-2" attributes="0"/>
203207
<Group type="103" groupAlignment="3" attributes="0">
204-
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
205-
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
208+
<Component id="jCheckBox1" alignment="3" min="-2" max="-2" attributes="0"/>
209+
<Component id="jComboBox2" alignment="3" min="-2" max="-2" attributes="0"/>
206210
</Group>
207211
<EmptySpace type="unrelated" max="-2" attributes="0"/>
208212
<Group type="103" groupAlignment="3" attributes="0">
209-
<Component id="jComboBox2" alignment="3" min="-2" max="-2" attributes="0"/>
210-
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
213+
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
214+
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
211215
</Group>
212-
<EmptySpace max="-2" attributes="0"/>
216+
<EmptySpace max="32767" attributes="0"/>
213217
</Group>
214218
</Group>
215219
</DimensionLayout>
@@ -248,12 +252,19 @@
248252
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="2"/>
249253
</AuxValues>
250254
</Component>
251-
<Component class="javax.swing.JLabel" name="jLabel3">
255+
<Component class="javax.swing.JCheckBox" name="jCheckBox1">
252256
<Properties>
253257
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
254258
<ResourceString bundle="org/yccheok/jstock/data/gui.properties" key="OptionsSellAdvisorJPanel_Currency" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
255259
</Property>
256260
</Properties>
261+
<Events>
262+
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="jCheckBox1ItemStateChanged"/>
263+
</Events>
264+
<AuxValues>
265+
<AuxValue name="JavaCodeGenerator_VariableLocal" type="java.lang.Boolean" value="false"/>
266+
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="2"/>
267+
</AuxValues>
257268
</Component>
258269
</SubComponents>
259270
</Container>

src/org/yccheok/jstock/gui/OptionsSellAdvisorJPanel.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void initComponents() {
8484
javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
8585
jComboBox1 = new javax.swing.JComboBox();
8686
jComboBox2 = new javax.swing.JComboBox();
87-
javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
87+
jCheckBox1 = new javax.swing.JCheckBox();
8888

8989
setLayout(new java.awt.BorderLayout());
9090

@@ -130,7 +130,7 @@ private void initComponents() {
130130
.addGroup(jPanel3Layout.createSequentialGroup()
131131
.addContainerGap()
132132
.addComponent(jCheckBox3)
133-
.addContainerGap(102, Short.MAX_VALUE))
133+
.addContainerGap(108, Short.MAX_VALUE))
134134
);
135135
jPanel3Layout.setVerticalGroup(
136136
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -150,7 +150,12 @@ private void initComponents() {
150150
jComboBox2.setModel(getCountryComboBoxModel());
151151
jComboBox2.setRenderer(new MyCellRenderer());
152152

153-
jLabel3.setText(bundle.getString("OptionsSellAdvisorJPanel_Currency")); // NOI18N
153+
jCheckBox1.setText(bundle.getString("OptionsSellAdvisorJPanel_Currency")); // NOI18N
154+
jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
155+
public void itemStateChanged(java.awt.event.ItemEvent evt) {
156+
jCheckBox1ItemStateChanged(evt);
157+
}
158+
});
154159

155160
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
156161
jPanel4.setLayout(jPanel4Layout);
@@ -159,8 +164,10 @@ private void initComponents() {
159164
.addGroup(jPanel4Layout.createSequentialGroup()
160165
.addContainerGap()
161166
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162-
.addComponent(jLabel2)
163-
.addComponent(jLabel3))
167+
.addComponent(jCheckBox1)
168+
.addGroup(jPanel4Layout.createSequentialGroup()
169+
.addGap(21, 21, 21)
170+
.addComponent(jLabel2)))
164171
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
165172
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166173
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
@@ -172,13 +179,13 @@ private void initComponents() {
172179
.addGroup(jPanel4Layout.createSequentialGroup()
173180
.addContainerGap()
174181
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
175-
.addComponent(jLabel2)
176-
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
182+
.addComponent(jCheckBox1)
183+
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
177184
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
178185
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
179-
.addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
180-
.addComponent(jLabel3))
181-
.addContainerGap())
186+
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
187+
.addComponent(jLabel2))
188+
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
182189
);
183190

184191
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
@@ -202,12 +209,22 @@ private void initComponents() {
202209
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
203210
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204211
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
205-
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
212+
.addContainerGap(27, Short.MAX_VALUE))
206213
);
207214

208215
add(jPanel1, java.awt.BorderLayout.CENTER);
209216
}// </editor-fold>//GEN-END:initComponents
210217

218+
private void jCheckBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jCheckBox1ItemStateChanged
219+
updateGUIState();
220+
}//GEN-LAST:event_jCheckBox1ItemStateChanged
221+
222+
// Update the GUI state of combo box, according to currency exchange enable
223+
// feature.
224+
private void updateGUIState() {
225+
jComboBox2.setEnabled(jCheckBox1.isSelected());
226+
}
227+
211228
private JFormattedTextField getPercentageJFormattedTextField() {
212229
NumberFormat format= NumberFormat.getNumberInstance();
213230
NumberFormatter formatter= new NumberFormatter(format);
@@ -302,8 +319,10 @@ public void set(JStockOptions jStockOptions) {
302319
this.jFormattedTextField1.setValue(jStockOptions.getExpectedProfitPercentage());
303320
this.jComboBox1.setSelectedItem(jStockOptions.getCurrencySymbol(jStockOptions.getCountry()));
304321
this.jComboBox2.setSelectedItem(jStockOptions.getLocalCurrencyCountry(jStockOptions.getCountry()));
322+
this.jCheckBox1.setSelected(jStockOptions.isCurrencyExchangeEnable(jStockOptions.getCountry()));
305323
this.jCheckBox3.setSelected(jStockOptions.isFourDecimalPlacesEnabled());
306324
commitEdit();
325+
updateGUIState();
307326
}
308327

309328
@Override
@@ -315,6 +334,7 @@ public boolean apply(JStockOptions jStockOptions) {
315334
jStockOptions.setCurrencySymbol(jStockOptions.getCountry(), currencySymbol);
316335
}
317336

337+
jStockOptions.setCurrencyExchangeEnable(jStockOptions.getCountry(), jCheckBox1.isSelected());
318338
jStockOptions.setLocalCurrencyCountry(jStockOptions.getCountry(), (Country)jComboBox2.getSelectedItem());
319339
jStockOptions.setFourDecimalPlacesEnabled(this.jCheckBox3.isSelected());
320340

@@ -378,7 +398,8 @@ public Component getListCellRendererComponent(
378398
private final DefaultComboBoxModel defaultCountryComboBoxModel = new DefaultComboBoxModel();
379399

380400
// Variables declaration - do not modify//GEN-BEGIN:variables
381-
javax.swing.JCheckBox jCheckBox3;
401+
private javax.swing.JCheckBox jCheckBox1;
402+
private javax.swing.JCheckBox jCheckBox3;
382403
private javax.swing.JComboBox jComboBox1;
383404
private javax.swing.JComboBox jComboBox2;
384405
private javax.swing.JFormattedTextField jFormattedTextField1;

0 commit comments

Comments
 (0)