Skip to content

Commit 1f73c80

Browse files
committed
Experiment with new UI idea.
1 parent 75daf35 commit 1f73c80

File tree

3 files changed

+96
-42
lines changed

3 files changed

+96
-42
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,12 @@ public boolean openAsStatements(Statements statements, File file) {
562562
return true;
563563
}
564564
}
565-
this.buyTreeTable.setTreeTableModel(new BuyPortfolioTreeTableModelEx());
566565

566+
this.buyTreeTable.setTreeTableModel(new BuyPortfolioTreeTableModelEx());
567+
final BuyPortfolioTreeTableModelEx buyPortfolioTreeTableModel = (BuyPortfolioTreeTableModelEx)buyTreeTable.getTreeTableModel();
568+
buyPortfolioTreeTableModel.bind(this.portfolioRealTimeInfo);
569+
buyPortfolioTreeTableModel.bind(this);
570+
567571
Map<String, String> metadatas = statements.getMetadatas();
568572
for (Transaction transaction : transactions) {
569573
final Code code = transaction.getStock().code;
@@ -579,12 +583,7 @@ public boolean openAsStatements(Statements statements, File file) {
579583
// Only shows necessary columns.
580584
initGUIOptions();
581585

582-
SwingUtilities.invokeLater(new Runnable() {
583-
@Override
584-
public void run() {
585-
expandTreeTable(buyTreeTable);
586-
}
587-
});
586+
expandTreeTable(buyTreeTable);
588587

589588
updateRealTimeStockMonitorAccordingToPortfolioTreeTableModels();
590589
updateExchangeRateMonitorAccordingToPortfolioTreeTableModels();
@@ -719,8 +718,12 @@ public void run() {
719718
return true;
720719
}
721720
}
721+
722722
this.sellTreeTable.setTreeTableModel(new SellPortfolioTreeTableModelEx());
723-
723+
final SellPortfolioTreeTableModelEx sellPortfolioTreeTableModel = (SellPortfolioTreeTableModelEx)sellTreeTable.getTreeTableModel();
724+
sellPortfolioTreeTableModel.bind(this.portfolioRealTimeInfo);
725+
sellPortfolioTreeTableModel.bind(this);
726+
724727
Map<String, String> metadatas = statements.getMetadatas();
725728

726729
for (Transaction transaction : transactions) {
@@ -2079,6 +2082,7 @@ private boolean initCSVPortfolio() {
20792082
return false;
20802083
}
20812084
}
2085+
20822086
if (openAsCSVFile(sellPortfolioFile) == false) {
20832087
// If CSV file is not there, consider this as empty record. This is
20842088
// because in createEmptyPortfolio, we only create portfolio-real-time-info.json,
@@ -2088,6 +2092,7 @@ private boolean initCSVPortfolio() {
20882092
return false;
20892093
}
20902094
}
2095+
20912096
if (openAsCSVFile(dividendSummaryFile) == false) {
20922097
// If CSV file is not there, consider this as empty record. This is
20932098
// because in createEmptyPortfolio, we only create portfolio-real-time-info.json,
@@ -2106,13 +2111,6 @@ private boolean initCSVPortfolio() {
21062111
return false;
21072112
}
21082113
}
2109-
2110-
final BuyPortfolioTreeTableModelEx buyPortfolioTreeTableModel = (BuyPortfolioTreeTableModelEx)buyTreeTable.getTreeTableModel();
2111-
final SellPortfolioTreeTableModelEx sellPortfolioTreeTableModel = (SellPortfolioTreeTableModelEx)sellTreeTable.getTreeTableModel();
2112-
buyPortfolioTreeTableModel.bind(_portfolioRealTimeInfo);
2113-
sellPortfolioTreeTableModel.bind(_portfolioRealTimeInfo);
2114-
buyPortfolioTreeTableModel.bind(this);
2115-
sellPortfolioTreeTableModel.bind(this);
21162114

21172115
refershGUIAfterInitPortfolio(
21182116
(BuyPortfolioTreeTableModelEx)PortfolioManagementJPanel.this.buyTreeTable.getTreeTableModel(),
@@ -3032,7 +3030,7 @@ public boolean shouldDisplayCurrencyInfoForValue() {
30323030
if (false == isCurrencyExchangeEnable) {
30333031
return false;
30343032
}
3035-
return this.getCurrencyPairs().size() > 1;
3033+
return !this.getCurrencyPairs().isEmpty();
30363034
}
30373035

30383036
private static final Log log = LogFactory.getLog(PortfolioManagementJPanel.class);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* JStock - Free Stock Market Software
3+
* Copyright (C) 2015 Yan Cheng Cheok <[email protected]>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
package org.yccheok.jstock.gui.treetable;
21+
22+
import org.yccheok.jstock.engine.currency.Currency;
23+
24+
/**
25+
*
26+
* @author yccheok
27+
*/
28+
public class DoubleWithCurrency extends org.yccheok.jstock.engine.Pair<Double, Currency> {
29+
public static DoubleWithCurrency create(Double _double, Currency currency) {
30+
return new DoubleWithCurrency(_double, currency);
31+
}
32+
33+
public DoubleWithCurrency(Double _double, Currency currency) {
34+
super(_double, currency);
35+
}
36+
37+
public Double Double() {
38+
return this.first;
39+
}
40+
41+
public Currency currency() {
42+
return this.second;
43+
}
44+
}

src/org/yccheok/jstock/gui/treetable/SellPortfolioTreeTableModelEx.java

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,14 @@ public Object getValueAt(Object node, int column) {
287287

288288
if (transactionSummary.getChildCount() <= 0) return null;
289289

290-
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, ((Transaction)transactionSummary.getChildAt(0)).getStock().code);
290+
final Code code = ((Transaction)transactionSummary.getChildAt(0)).getStock().code;
291291

292+
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, code);
293+
294+
final boolean shouldDisplayCurrencyInfoForValue = this.portfolioManagementJPanel.shouldDisplayCurrencyInfoForValue();
295+
296+
final Currency stockCurrency = shouldDisplayCurrencyInfoForValue ? org.yccheok.jstock.portfolio.Utils.getStockCurrency(portfolioRealTimeInfo, code) : null;
297+
292298
switch(column) {
293299
case 0:
294300
return ((Transaction)transactionSummary.getChildAt(0)).getStock().symbol;
@@ -313,45 +319,45 @@ public Object getValueAt(Object node, int column) {
313319
case 5:
314320
if (shouldConvertPenceToPound == false) {
315321
if (isFeeCalculationEnabled) {
316-
return transactionSummary.getNetTotal();
322+
return DoubleWithCurrency.create(transactionSummary.getNetTotal(), stockCurrency);
317323
} else {
318-
return transactionSummary.getTotal();
324+
return DoubleWithCurrency.create(transactionSummary.getTotal(), stockCurrency);
319325
}
320326
} else {
321327
if (isFeeCalculationEnabled) {
322-
return transactionSummary.getNetTotal() / 100.0;
328+
return DoubleWithCurrency.create(transactionSummary.getNetTotal() / 100.0, stockCurrency);
323329
} else {
324-
return transactionSummary.getTotal() / 100.0;
330+
return DoubleWithCurrency.create(transactionSummary.getTotal() / 100.0, stockCurrency);
325331
}
326332
}
327333

328334
case 6:
329335
if (shouldConvertPenceToPound == false) {
330336
if (isFeeCalculationEnabled) {
331-
return transactionSummary.getNetReferenceTotal();
337+
return DoubleWithCurrency.create(transactionSummary.getNetReferenceTotal(), stockCurrency);
332338
} else {
333-
return transactionSummary.getReferenceTotal();
339+
return DoubleWithCurrency.create(transactionSummary.getReferenceTotal(), stockCurrency);
334340
}
335341
} else {
336342
if (isFeeCalculationEnabled) {
337-
return transactionSummary.getNetReferenceTotal() / 100.0;
343+
return DoubleWithCurrency.create(transactionSummary.getNetReferenceTotal() / 100.0, stockCurrency);
338344
} else {
339-
return transactionSummary.getReferenceTotal() / 100.0;
345+
return DoubleWithCurrency.create(transactionSummary.getReferenceTotal() / 100.0, stockCurrency);
340346
}
341347
}
342348

343349
case 7:
344350
if (shouldConvertPenceToPound == false) {
345351
if (isFeeCalculationEnabled) {
346-
return getNetGainLossValue(transactionSummary);
352+
return DoubleWithCurrency.create(getNetGainLossValue(transactionSummary), stockCurrency);
347353
} else {
348-
return getGainLossValue(transactionSummary);
354+
return DoubleWithCurrency.create(getGainLossValue(transactionSummary), stockCurrency);
349355
}
350356
} else {
351357
if (isFeeCalculationEnabled) {
352-
return getNetGainLossValue(transactionSummary) / 100.0;
358+
return DoubleWithCurrency.create(getNetGainLossValue(transactionSummary) / 100.0, stockCurrency);
353359
} else {
354-
return getGainLossValue(transactionSummary) / 100.0;
360+
return DoubleWithCurrency.create(getGainLossValue(transactionSummary) / 100.0, stockCurrency);
355361
}
356362
}
357363

@@ -379,8 +385,14 @@ public Object getValueAt(Object node, int column) {
379385
if (node instanceof Transaction) {
380386
final Transaction transaction = (Transaction)node;
381387

382-
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, transaction.getStock().code);
388+
final Code code = transaction.getStock().code;
383389

390+
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, code);
391+
392+
final boolean shouldDisplayCurrencyInfoForValue = this.portfolioManagementJPanel.shouldDisplayCurrencyInfoForValue();
393+
394+
final Currency stockCurrency = shouldDisplayCurrencyInfoForValue ? org.yccheok.jstock.portfolio.Utils.getStockCurrency(portfolioRealTimeInfo, code) : null;
395+
384396
switch(column) {
385397
case 0:
386398
return (transaction).getStock().symbol;
@@ -400,45 +412,45 @@ public Object getValueAt(Object node, int column) {
400412
case 5:
401413
if (shouldConvertPenceToPound == false) {
402414
if (isFeeCalculationEnabled) {
403-
return transaction.getNetTotal();
415+
return DoubleWithCurrency.create(transaction.getNetTotal(), stockCurrency);
404416
} else {
405-
return transaction.getTotal();
417+
return DoubleWithCurrency.create(transaction.getTotal(), stockCurrency);
406418
}
407419
} else {
408420
if (isFeeCalculationEnabled) {
409-
return transaction.getNetTotal() / 100.0;
421+
return DoubleWithCurrency.create(transaction.getNetTotal() / 100.0, stockCurrency);
410422
} else {
411-
return transaction.getTotal() / 100.0;
423+
return DoubleWithCurrency.create(transaction.getTotal() / 100.0, stockCurrency);
412424
}
413425
}
414426

415427
case 6:
416428
if (shouldConvertPenceToPound == false) {
417429
if (isFeeCalculationEnabled) {
418-
return transaction.getNetReferenceTotal();
430+
return DoubleWithCurrency.create(transaction.getNetReferenceTotal(), stockCurrency);
419431
} else {
420-
return transaction.getReferenceTotal();
432+
return DoubleWithCurrency.create(transaction.getReferenceTotal(), stockCurrency);
421433
}
422434
} else {
423435
if (isFeeCalculationEnabled) {
424-
return transaction.getNetReferenceTotal() / 100.0;
436+
return DoubleWithCurrency.create(transaction.getNetReferenceTotal() / 100.0, stockCurrency);
425437
} else {
426-
return transaction.getReferenceTotal() / 100.0;
438+
return DoubleWithCurrency.create(transaction.getReferenceTotal() / 100.0, stockCurrency);
427439
}
428440
}
429441

430442
case 7:
431443
if (shouldConvertPenceToPound == false) {
432444
if (isFeeCalculationEnabled) {
433-
return getNetGainLossValue(transaction);
445+
return DoubleWithCurrency.create(getNetGainLossValue(transaction), stockCurrency);
434446
} else {
435-
return getGainLossValue(transaction);
447+
return DoubleWithCurrency.create(getGainLossValue(transaction), stockCurrency);
436448
}
437449
} else {
438450
if (isFeeCalculationEnabled) {
439-
return getNetGainLossValue(transaction) / 100.0;
451+
return DoubleWithCurrency.create(getNetGainLossValue(transaction) / 100.0, stockCurrency);
440452
} else {
441-
return getGainLossValue(transaction) / 100.0;
453+
return DoubleWithCurrency.create(getGainLossValue(transaction) / 100.0, stockCurrency);
442454
}
443455
}
444456

0 commit comments

Comments
 (0)