Skip to content

Commit 75daf35

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

File tree

3 files changed

+83
-25
lines changed

3 files changed

+83
-25
lines changed

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.yccheok.jstock.gui.portfolio.ToolTipHighlighter;
7575
import org.yccheok.jstock.gui.treetable.AbstractPortfolioTreeTableModelEx;
7676
import org.yccheok.jstock.gui.treetable.BuyPortfolioTreeTableModelEx;
77+
import org.yccheok.jstock.gui.treetable.DoubleWithCurrency;
7778
import org.yccheok.jstock.gui.treetable.SellPortfolioTreeTableModelEx;
7879
import org.yccheok.jstock.gui.treetable.SortableTreeTable;
7980
import org.yccheok.jstock.internationalization.GUIBundle;
@@ -340,7 +341,23 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
340341
if (value instanceof DoubleWrapper) {
341342
DoubleWrapper v = (DoubleWrapper)value;
342343
((JLabel)c).setText(org.yccheok.jstock.portfolio.Utils.toCurrency(v.decimalPlace, v.value));
343-
} else {
344+
} else if (value instanceof DoubleWithCurrency) {
345+
DoubleWithCurrency v = (DoubleWithCurrency)value;
346+
Currency currency = v.currency();
347+
String content = org.yccheok.jstock.portfolio.Utils.toCurrency(DecimalPlaces.Four, v.Double());
348+
if (currency == null) {
349+
((JLabel)c).setText(content);
350+
} else {
351+
String prefix = currency.toString();
352+
if (prefix.equals("GBX")) {
353+
// Special handling.
354+
prefix = "GBP";
355+
}
356+
357+
((JLabel)c).setText(prefix + " " + content);
358+
}
359+
}
360+
else {
344361
((JLabel)c).setText(org.yccheok.jstock.portfolio.Utils.toCurrency(DecimalPlaces.Four, value));
345362
}
346363
}
@@ -562,7 +579,12 @@ public boolean openAsStatements(Statements statements, File file) {
562579
// Only shows necessary columns.
563580
initGUIOptions();
564581

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

567589
updateRealTimeStockMonitorAccordingToPortfolioTreeTableModels();
568590
updateExchangeRateMonitorAccordingToPortfolioTreeTableModels();
@@ -2089,6 +2111,8 @@ private boolean initCSVPortfolio() {
20892111
final SellPortfolioTreeTableModelEx sellPortfolioTreeTableModel = (SellPortfolioTreeTableModelEx)sellTreeTable.getTreeTableModel();
20902112
buyPortfolioTreeTableModel.bind(_portfolioRealTimeInfo);
20912113
sellPortfolioTreeTableModel.bind(_portfolioRealTimeInfo);
2114+
buyPortfolioTreeTableModel.bind(this);
2115+
sellPortfolioTreeTableModel.bind(this);
20922116

20932117
refershGUIAfterInitPortfolio(
20942118
(BuyPortfolioTreeTableModelEx)PortfolioManagementJPanel.this.buyTreeTable.getTreeTableModel(),
@@ -3001,6 +3025,16 @@ public PortfolioRealTimeInfo getPortfolioRealTimeInfo() {
30013025
return this.portfolioRealTimeInfo;
30023026
}
30033027

3028+
public boolean shouldDisplayCurrencyInfoForValue() {
3029+
final JStockOptions jStockOptions = JStock.getInstance().getJStockOptions();
3030+
final Country country = jStockOptions.getCountry();
3031+
final boolean isCurrencyExchangeEnable = jStockOptions.isCurrencyExchangeEnable(country);
3032+
if (false == isCurrencyExchangeEnable) {
3033+
return false;
3034+
}
3035+
return this.getCurrencyPairs().size() > 1;
3036+
}
3037+
30043038
private static final Log log = LogFactory.getLog(PortfolioManagementJPanel.class);
30053039

30063040
private int dividerLocation = -1;

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

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.yccheok.jstock.engine.currency.Currency;
3030
import org.yccheok.jstock.gui.JStockOptions;
3131
import org.yccheok.jstock.gui.JStock;
32+
import org.yccheok.jstock.gui.PortfolioManagementJPanel;
3233
import org.yccheok.jstock.internationalization.GUIBundle;
3334

3435
/**
@@ -39,12 +40,17 @@ public class BuyPortfolioTreeTableModelEx extends AbstractPortfolioTreeTableMode
3940

4041
// Avoid NPE.
4142
private PortfolioRealTimeInfo portfolioRealTimeInfo = new PortfolioRealTimeInfo();
42-
43+
private PortfolioManagementJPanel portfolioManagementJPanel = null;
44+
4345
public void bind(PortfolioRealTimeInfo portfolioRealTimeInfo) {
4446
this.portfolioRealTimeInfo = portfolioRealTimeInfo;
4547
final Portfolio portfolio = (Portfolio)getRoot();
4648
portfolio.bind(portfolioRealTimeInfo);
4749
}
50+
51+
public void bind(PortfolioManagementJPanel portfolioManagementJPanel) {
52+
this.portfolioManagementJPanel = portfolioManagementJPanel;
53+
}
4854

4955
public BuyPortfolioTreeTableModelEx() {
5056
super(Arrays.asList(columnNames));
@@ -437,7 +443,13 @@ public Object getValueAt(Object node, int column) {
437443

438444
if (transactionSummary.getChildCount() <= 0) return null;
439445

440-
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, ((Transaction)transactionSummary.getChildAt(0)).getStock().code);
446+
final Code code = ((Transaction)transactionSummary.getChildAt(0)).getStock().code;
447+
448+
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, code);
449+
450+
final boolean shouldDisplayCurrencyInfoForValue = this.portfolioManagementJPanel.shouldDisplayCurrencyInfoForValue();
451+
452+
final Currency stockCurrency = shouldDisplayCurrencyInfoForValue ? org.yccheok.jstock.portfolio.Utils.getStockCurrency(portfolioRealTimeInfo, code) : null;
441453

442454
switch(column) {
443455
case 0:
@@ -459,37 +471,37 @@ public Object getValueAt(Object node, int column) {
459471
case 5:
460472
if (shouldConvertPenceToPound == false) {
461473
if (isFeeCalculationEnabled) {
462-
return transactionSummary.getNetTotal();
474+
return DoubleWithCurrency.create(transactionSummary.getNetTotal(), stockCurrency);
463475
} else {
464-
return transactionSummary.getTotal();
476+
return DoubleWithCurrency.create(transactionSummary.getTotal(), stockCurrency);
465477
}
466478
} else {
467479
if (isFeeCalculationEnabled) {
468-
return transactionSummary.getNetTotal() / 100.0;
480+
return DoubleWithCurrency.create(transactionSummary.getNetTotal() / 100.0, stockCurrency);
469481
} else {
470-
return transactionSummary.getTotal() / 100.0;
482+
return DoubleWithCurrency.create(transactionSummary.getTotal() / 100.0, stockCurrency);
471483
}
472484
}
473485

474486
case 6:
475487
if (shouldConvertPenceToPound == false) {
476-
return this.getCurrentValue(transactionSummary);
488+
return DoubleWithCurrency.create(this.getCurrentValue(transactionSummary), stockCurrency);
477489
} else {
478-
return this.getCurrentValue(transactionSummary) / 100.0;
490+
return DoubleWithCurrency.create(this.getCurrentValue(transactionSummary) / 100.0, stockCurrency);
479491
}
480492

481493
case 7:
482494
if (shouldConvertPenceToPound == false) {
483495
if (isFeeCalculationEnabled) {
484-
return this.getNetGainLossValue(transactionSummary);
496+
return DoubleWithCurrency.create(this.getNetGainLossValue(transactionSummary), stockCurrency);
485497
} else {
486-
return this.getGainLossValue(transactionSummary);
498+
return DoubleWithCurrency.create(this.getGainLossValue(transactionSummary), stockCurrency);
487499
}
488500
} else {
489501
if (isFeeCalculationEnabled) {
490-
return this.getNetGainLossValue(transactionSummary) / 100.0;
502+
return DoubleWithCurrency.create(this.getNetGainLossValue(transactionSummary) / 100.0, stockCurrency);
491503
} else {
492-
return this.getGainLossValue(transactionSummary) / 100.0;
504+
return DoubleWithCurrency.create(this.getGainLossValue(transactionSummary) / 100.0, stockCurrency);
493505
}
494506
}
495507

@@ -517,8 +529,14 @@ public Object getValueAt(Object node, int column) {
517529
if (node instanceof Transaction) {
518530
final Transaction transaction = (Transaction)node;
519531

520-
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, transaction.getStock().code);
532+
final Code code = transaction.getStock().code;
533+
534+
final boolean shouldConvertPenceToPound = org.yccheok.jstock.portfolio.Utils.shouldConvertPenceToPound(portfolioRealTimeInfo, code);
521535

536+
final boolean shouldDisplayCurrencyInfoForValue = this.portfolioManagementJPanel.shouldDisplayCurrencyInfoForValue();
537+
538+
final Currency stockCurrency = shouldDisplayCurrencyInfoForValue ? org.yccheok.jstock.portfolio.Utils.getStockCurrency(portfolioRealTimeInfo, code) : null;
539+
522540
switch(column) {
523541
case 0:
524542
return (transaction).getStock().symbol;
@@ -538,37 +556,37 @@ public Object getValueAt(Object node, int column) {
538556
case 5:
539557
if (shouldConvertPenceToPound == false) {
540558
if (isFeeCalculationEnabled) {
541-
return transaction.getNetTotal();
559+
return DoubleWithCurrency.create(transaction.getNetTotal(), stockCurrency);
542560
} else {
543-
return transaction.getTotal();
561+
return DoubleWithCurrency.create(transaction.getTotal(), stockCurrency);
544562
}
545563
} else {
546564
if (isFeeCalculationEnabled) {
547-
return transaction.getNetTotal() / 100.0;
565+
return DoubleWithCurrency.create(transaction.getNetTotal() / 100.0, stockCurrency);
548566
} else {
549-
return transaction.getTotal() / 100.0;
567+
return DoubleWithCurrency.create(transaction.getTotal() / 100.0, stockCurrency);
550568
}
551569
}
552570

553571
case 6:
554572
if (shouldConvertPenceToPound == false) {
555-
return this.getCurrentValue(transaction);
573+
return DoubleWithCurrency.create(this.getCurrentValue(transaction), stockCurrency);
556574
} else {
557-
return this.getCurrentValue(transaction) / 100.0;
575+
return DoubleWithCurrency.create(this.getCurrentValue(transaction) / 100.0, stockCurrency);
558576
}
559577

560578
case 7:
561579
if (shouldConvertPenceToPound == false) {
562580
if (isFeeCalculationEnabled) {
563-
return this.getNetGainLossValue(transaction);
581+
return DoubleWithCurrency.create(this.getNetGainLossValue(transaction), stockCurrency);
564582
} else {
565-
return this.getGainLossValue(transaction);
583+
return DoubleWithCurrency.create(this.getGainLossValue(transaction), stockCurrency);
566584
}
567585
} else {
568586
if (isFeeCalculationEnabled) {
569-
return this.getNetGainLossValue(transaction) / 100.0;
587+
return DoubleWithCurrency.create(this.getNetGainLossValue(transaction) / 100.0, stockCurrency);
570588
} else {
571-
return this.getGainLossValue(transaction) / 100.0;
589+
return DoubleWithCurrency.create(this.getGainLossValue(transaction) / 100.0, stockCurrency);
572590
}
573591
}
574592

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.yccheok.jstock.engine.currency.Currency;
2828
import org.yccheok.jstock.gui.JStockOptions;
2929
import org.yccheok.jstock.gui.JStock;
30+
import org.yccheok.jstock.gui.PortfolioManagementJPanel;
3031
import org.yccheok.jstock.portfolio.Contract;
3132
import org.yccheok.jstock.portfolio.Portfolio;
3233
import org.yccheok.jstock.portfolio.Transaction;
@@ -43,13 +44,18 @@ public class SellPortfolioTreeTableModelEx extends AbstractPortfolioTreeTableMod
4344

4445
// Avoid NPE.
4546
private PortfolioRealTimeInfo portfolioRealTimeInfo = new PortfolioRealTimeInfo();
47+
private PortfolioManagementJPanel portfolioManagementJPanel = null;
4648

4749
public void bind(PortfolioRealTimeInfo portfolioRealTimeInfo) {
4850
this.portfolioRealTimeInfo = portfolioRealTimeInfo;
4951
final Portfolio portfolio = (Portfolio)getRoot();
5052
portfolio.bind(portfolioRealTimeInfo);
5153
}
5254

55+
public void bind(PortfolioManagementJPanel portfolioManagementJPanel) {
56+
this.portfolioManagementJPanel = portfolioManagementJPanel;
57+
}
58+
5359
public SellPortfolioTreeTableModelEx() {
5460
super(Arrays.asList(columnNames));
5561
}

0 commit comments

Comments
 (0)