Skip to content

Commit ccffceb

Browse files
committed
...
1 parent d23265f commit ccffceb

File tree

6 files changed

+104
-14
lines changed

6 files changed

+104
-14
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.yccheok.jstock.gui;
2121

2222
import java.awt.Component;
23-
import java.util.ArrayList;
24-
import java.util.Arrays;
2523
import javax.swing.AbstractListModel;
2624
import javax.swing.BorderFactory;
2725
import javax.swing.JLabel;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@
346346
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem12ActionPerformed"/>
347347
</Events>
348348
</MenuItem>
349+
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem18">
350+
<Properties>
351+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
352+
<ResourceString bundle="org/yccheok/jstock/data/gui.properties" key="MainFrame_Export" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
353+
</Property>
354+
</Properties>
355+
<Events>
356+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jMenuItem18ActionPerformed"/>
357+
</Events>
358+
</MenuItem>
349359
<MenuItem class="javax.swing.JPopupMenu$Separator" name="jSeparator6">
350360
</MenuItem>
351361
<MenuItem class="javax.swing.JMenuItem" name="jMenuItem13">

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

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void init() {
115115
initComponents();
116116

117117
createLookAndFeelMenuItems();
118-
createCountryMenuItems();
118+
rebuildCountryMenuItems(true);
119119

120120
createStockIndicatorEditor();
121121
createIndicatorScannerJPanel();
@@ -406,6 +406,7 @@ private void initComponents() {
406406
jMenuItem3 = new javax.swing.JMenuItem();
407407
jMenuItem16 = new javax.swing.JMenuItem();
408408
jMenuItem12 = new javax.swing.JMenuItem();
409+
jMenuItem18 = new javax.swing.JMenuItem();
409410
jSeparator6 = new javax.swing.JPopupMenu.Separator();
410411
jMenuItem13 = new javax.swing.JMenuItem();
411412
jMenuItem14 = new javax.swing.JMenuItem();
@@ -738,6 +739,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
738739
}
739740
});
740741
jMenu2.add(jMenuItem12);
742+
743+
jMenuItem18.setText(bundle.getString("MainFrame_Export")); // NOI18N
744+
jMenuItem18.addActionListener(new java.awt.event.ActionListener() {
745+
public void actionPerformed(java.awt.event.ActionEvent evt) {
746+
jMenuItem18ActionPerformed(evt);
747+
}
748+
});
749+
jMenu2.add(jMenuItem18);
741750
jMenu2.add(jSeparator6);
742751

743752
jMenuItem13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/16x16/smile2.png"))); // NOI18N
@@ -1674,6 +1683,20 @@ private void jRadioButtonMenuItem6ActionPerformed(java.awt.event.ActionEvent evt
16741683
private void jMenu6MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenu6MenuSelected
16751684
initRecentCountryMenuItems();
16761685
}//GEN-LAST:event_jMenu6MenuSelected
1686+
1687+
private void jMenuItem18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem18ActionPerformed
1688+
File file = Utils.promptSaveZippedJFileChooser("jstock.zip");
1689+
1690+
if (file == null) {
1691+
return;
1692+
}
1693+
1694+
file = SaveToCloudJDialog.getJStockZipFile(file.getAbsolutePath());
1695+
1696+
if (file != null) {
1697+
JOptionPane.showMessageDialog(null, MessagesBundle.getString("info_message_export_successfully"));
1698+
}
1699+
}//GEN-LAST:event_jMenuItem18ActionPerformed
16771700

16781701
/**
16791702
* Activate specified watchlist.
@@ -2166,7 +2189,13 @@ private void initRecentCountryMenuItems() {
21662189
buttonGroup4 = new ButtonGroup();
21672190

21682191
int index = 0;
2192+
2193+
final Set<Country> countries = new HashSet<>(Utils.getSupportedStockMarketCountries());
21692194
for (final Country country : jStockOptions.getRecentCountries()) {
2195+
if (false == countries.contains(country)) {
2196+
continue;
2197+
}
2198+
21702199
final JMenuItem mi = (JRadioButtonMenuItem) jMenu6.add(new JRadioButtonMenuItem(country.humanString, country.icon), index++);
21712200

21722201
buttonGroup4.add(mi);
@@ -2187,9 +2216,15 @@ public void actionPerformed(ActionEvent e) {
21872216
}
21882217
}
21892218

2190-
public void createCountryMenuItems() {
2191-
final java.util.List<Country> countries = Utils.getSupportedStockMarketCountries();
2219+
public void rebuildCountryMenuItems(boolean useCache) {
2220+
final java.util.List<Country> countries = Utils.getSupportedStockMarketCountries(useCache);
2221+
2222+
jMenu6.removeAll();
21922223

2224+
for (Enumeration<AbstractButton> e = buttonGroup2.getElements(); e.hasMoreElements();) {
2225+
buttonGroup2.remove(e.nextElement());
2226+
}
2227+
21932228
Map<Continent, JMenu> menus = new EnumMap<>(Continent.class);
21942229
for (final Continent continent : Continent.values()) {
21952230
JMenu jMenu = new JMenu(continent.name());
@@ -2717,6 +2752,8 @@ public void reloadAfterDownloadFromCloud(JStockOptions newJStockOptions) {
27172752
Utils.updateFactoriesPriceSource();
27182753

27192754
jStockOptions.setCountry(this.getBestCountryAfterDownloadFromCloud());
2755+
2756+
rebuildCountryMenuItems(false);
27202757

27212758
/* These codes are very similar to clean up code during changing country.
27222759
*/
@@ -5166,6 +5203,7 @@ public void refreshRealTimeIndexMonitor() {
51665203
private javax.swing.JMenuItem jMenuItem15;
51675204
private javax.swing.JMenuItem jMenuItem16;
51685205
private javax.swing.JMenuItem jMenuItem17;
5206+
private javax.swing.JMenuItem jMenuItem18;
51695207
private javax.swing.JMenuItem jMenuItem2;
51705208
private javax.swing.JMenuItem jMenuItem3;
51715209
private javax.swing.JMenuItem jMenuItem4;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public JStockOptions() {
143143
this.alertSpeed = 5;
144144
this.looknFeel = null;
145145
this.alwaysOnTop = false;
146-
this.country = Country.Malaysia;
146+
this.country = Country.UnitedState;
147147
this.soundEnabled = false;
148148

149149
this.normalTextForegroundColor = DEFAULT_NORMAL_TEXT_FOREGROUND_COLOR;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private static class LastErrorCode {
514514
// We will ask user whether he want to continue to save to cloud, as we are
515515
// going to ignore his stock watchlist file(s). Returns true if user wants
516516
// to continue.
517-
private boolean promptUserToContinue(final List<Country> countryWithWatchlistFilesBeingIgnored) {
517+
private static boolean promptUserToContinue(final List<Country> countryWithWatchlistFilesBeingIgnored) {
518518
if (countryWithWatchlistFilesBeingIgnored.isEmpty()) {
519519
// No watchlist file(s) is ignored.
520520
return true;
@@ -537,13 +537,13 @@ private boolean promptUserToContinue(final List<Country> countryWithWatchlistFil
537537
final int[] choice = new int[1];
538538
choice[0] = JOptionPane.NO_OPTION;
539539
if (SwingUtilities.isEventDispatchThread()) {
540-
choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION);
540+
choice[0] = JOptionPane.showConfirmDialog(JStock.instance(), message, title, JOptionPane.YES_NO_OPTION);
541541
} else {
542542
try {
543543
SwingUtilities.invokeAndWait(new Runnable() {
544544
@Override
545545
public void run() {
546-
choice[0] = JOptionPane.showConfirmDialog(SaveToCloudJDialog.this, message, title, JOptionPane.YES_NO_OPTION);
546+
choice[0] = JOptionPane.showConfirmDialog(JStock.instance(), message, title, JOptionPane.YES_NO_OPTION);
547547
}
548548
});
549549
} catch (InterruptedException ex) {
@@ -586,7 +586,7 @@ private static List<String> getExtensions(String name) {
586586
}
587587

588588
// filename can be null, to indicate temp file.
589-
private File getJStockZipFile(final String filename) {
589+
public static File getJStockZipFile(final String filename) {
590590
// Look for "user-defined-database.xml" for all countries.
591591
final List<File> files = getUserDefinedDatabaseFiles();
592592
final List<FileEx> fileExs = new ArrayList<>();

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
import org.yccheok.jstock.engine.*;
147147
import org.yccheok.jstock.internationalization.MessagesBundle;
148148
import org.yccheok.jstock.network.Utils.Type;
149+
import org.yccheok.jstock.portfolio.PortfolioInfo;
150+
import org.yccheok.jstock.watchlist.WatchlistInfo;
149151

150152
/**
151153
*
@@ -2458,12 +2460,52 @@ private static Gson getGsonForStockInfoDatabaseMeta() {
24582460
return gson;
24592461
}
24602462

2463+
public static List<Country> getSupportedStockMarketCountries(boolean useCache) {
2464+
if (false == useCache) {
2465+
supportedStockMarketCountries.clear();
2466+
}
2467+
return getSupportedStockMarketCountries();
2468+
}
2469+
24612470
public static List<Country> getSupportedStockMarketCountries() {
2471+
if (false == supportedStockMarketCountries.isEmpty()) {
2472+
return java.util.Collections.unmodifiableList(supportedStockMarketCountries);
2473+
}
2474+
24622475
java.util.List<Country> countries = new ArrayList<>(Arrays.asList(Country.values()));
24632476
// Czech and Hungary are only for currency exchange purpose.
24642477
countries.remove(Country.Czech);
24652478
countries.remove(Country.Hungary);
2466-
return countries;
2479+
2480+
List<WatchlistInfo> watchlistInfos = org.yccheok.jstock.watchlist.Utils.getWatchlistInfos();
2481+
2482+
boolean removeMalaysia = true;
2483+
for (WatchlistInfo watchlistInfo : watchlistInfos) {
2484+
if (watchlistInfo.country == Country.Malaysia) {
2485+
removeMalaysia = false;
2486+
break;
2487+
}
2488+
}
2489+
2490+
if (removeMalaysia) {
2491+
List<PortfolioInfo> portfolioInfos = org.yccheok.jstock.portfolio.Utils.getPortfolioInfos();
2492+
2493+
for (PortfolioInfo portfolioInfo : portfolioInfos) {
2494+
if (portfolioInfo.country == Country.Malaysia) {
2495+
removeMalaysia = false;
2496+
break;
2497+
}
2498+
}
2499+
}
2500+
2501+
if (removeMalaysia) {
2502+
countries.remove(Country.Malaysia);
2503+
}
2504+
2505+
supportedStockMarketCountries.clear();
2506+
supportedStockMarketCountries.addAll(countries);
2507+
2508+
return supportedStockMarketCountries;
24672509
}
24682510

24692511
public static Map<Country, Long> loadStockInfoDatabaseMeta(String json) {
@@ -2736,11 +2778,11 @@ public ApplicationInfo(int applicationVersionID, String windowsDownloadLink, Str
27362778

27372779
////////////////////////////////////////////////////////////////////////////
27382780
////////////////////////////////////////////////////////////////////////////
2739-
private static final String ABOUT_BOX_VERSION_STRING = "1.0.7.29";
2781+
private static final String ABOUT_BOX_VERSION_STRING = "1.0.7.30";
27402782

2741-
// 1.0.7.29
2783+
// 1.0.7.30
27422784
// For About box comparision on latest version purpose.
2743-
private static final int APPLICATION_VERSION_ID = 1158;
2785+
private static final int APPLICATION_VERSION_ID = 1159;
27442786
////////////////////////////////////////////////////////////////////////////
27452787
////////////////////////////////////////////////////////////////////////////
27462788

@@ -2767,5 +2809,7 @@ public ApplicationInfo(int applicationVersionID, String windowsDownloadLink, Str
27672809
// http://stackoverflow.com/questions/1360113/is-java-regex-thread-safe
27682810
private static final Pattern googleDocTitlePattern = Pattern.compile("jstock-" + getJStockUUID() + "-checksum=([0-9]+)-date=([0-9]+)-version=([0-9]+)\\.zip", Pattern.CASE_INSENSITIVE);
27692811

2812+
private static final List<Country> supportedStockMarketCountries = new ArrayList<>();
2813+
27702814
private static final Log log = LogFactory.getLog(Utils.class);
27712815
}

0 commit comments

Comments
 (0)