2929import org .yccheok .jstock .engine .currency .Currency ;
3030import org .yccheok .jstock .gui .JStockOptions ;
3131import org .yccheok .jstock .gui .JStock ;
32+ import org .yccheok .jstock .gui .PortfolioManagementJPanel ;
3233import 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
0 commit comments