Skip to content

Commit cc23ff3

Browse files
committed
Better search.
1 parent e2b8fb1 commit cc23ff3

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

src/org/yccheok/jstock/engine/MatchType.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ public MatchType(String t, String n, String e, String id) {
4343
}
4444

4545
public Code getCode() {
46-
if (this.e.equals("NSE")) {
46+
if ("NSE".equals(e)) {
4747
return Code.newInstance(this.t + ".N");
48-
} else if (this.e.equals("BOM")) {
48+
} else if ("BOM".equals(e)) {
4949
return Code.newInstance(this.t + ".B");
50+
} else if (this.e == null || this.e.isEmpty()) {
51+
return Code.newInstance(this.t);
5052
}
5153
return Code.newInstance(this.e + ":" + this.t);
5254
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JStock - Free Stock Market Software
3-
* Copyright (C) 2011 Yan Cheng CHEOK <[email protected]>
3+
* Copyright (C) 2015 Yan Cheng Cheok <[email protected]>
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -353,14 +353,28 @@ private Observer<AjaxGoogleSearchEngineMonitor, MatchSetType> getGoogleMonitorOb
353353
return new Observer<AjaxGoogleSearchEngineMonitor, MatchSetType>() {
354354

355355
@Override
356-
public void update(final AjaxGoogleSearchEngineMonitor subject, final MatchSetType arg) {
356+
public void update(final AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) {
357+
// Can we further enhance our search result?
358+
if (arg.Match.isEmpty()) {
359+
StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query);
360+
if (stockInfo != null) {
361+
MatchType matchType = new MatchType(stockInfo.code.toString(), stockInfo.symbol.toString(), null, null);
362+
List<MatchType> matchTypes = new ArrayList<>();
363+
matchTypes.add(matchType);
364+
MatchSetType matchSetType = MatchSetType.newInstance(arg.Query, matchTypes);
365+
arg = matchSetType;
366+
}
367+
}
368+
369+
final MatchSetType _arg = arg;
370+
357371
if (SwingUtilities.isEventDispatchThread()) {
358-
_update(subject, arg);
372+
_update(subject, _arg);
359373
} else {
360374
SwingUtilities.invokeLater(new Runnable() {
361375
@Override
362376
public void run() {
363-
_update(subject, arg);
377+
_update(subject, _arg);
364378
}
365379
});
366380
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* JStock - Free Stock Market Software
3-
* Copyright (C) 2011 Yan Cheng CHEOK <[email protected]>
3+
* Copyright (C) 2015 Yan Cheng Cheok <[email protected]>
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -555,14 +555,28 @@ private Observer<AjaxGoogleSearchEngineMonitor, MatchSetType> getGoogleMonitorOb
555555
return new Observer<AjaxGoogleSearchEngineMonitor, MatchSetType>() {
556556

557557
@Override
558-
public void update(final AjaxGoogleSearchEngineMonitor subject, final MatchSetType arg) {
558+
public void update(final AjaxGoogleSearchEngineMonitor subject, MatchSetType arg) {
559+
// Can we further enhance our search result?
560+
if (arg.Match.isEmpty()) {
561+
StockInfo stockInfo = ajaxStockInfoSearchEngine.search(arg.Query);
562+
if (stockInfo != null) {
563+
MatchType matchType = new MatchType(stockInfo.code.toString(), stockInfo.symbol.toString(), null, null);
564+
List<MatchType> matchTypes = new ArrayList<>();
565+
matchTypes.add(matchType);
566+
MatchSetType matchSetType = MatchSetType.newInstance(arg.Query, matchTypes);
567+
arg = matchSetType;
568+
}
569+
}
570+
571+
final MatchSetType _arg = arg;
572+
559573
if (SwingUtilities.isEventDispatchThread()) {
560-
_update(subject, arg);
574+
_update(subject, _arg);
561575
} else {
562576
SwingUtilities.invokeLater(new Runnable() {
563577
@Override
564578
public void run() {
565-
_update(subject, arg);
579+
_update(subject, _arg);
566580
}
567581
});
568582
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
123123
final MatchType result = (MatchType)value;
124124
jLabel1.setText(result.t);
125125
jLabel2.setText(result.n);
126-
jLabel3.setText(result.e);
126+
127+
if (result.e == null) {
128+
jLabel3.setVisible(false);
129+
} else {
130+
jLabel3.setVisible(true);
131+
jLabel3.setText(result.e);
132+
}
133+
127134
return this;
128135
}
129136
}

0 commit comments

Comments
 (0)