home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / AFC102 / Samples / LoanCalc / Src / LCDataPnl.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  1.9 KB  |  69 lines

  1. //
  2. // (c) 1997 Microsoft Corporation.  All rights reserved.
  3. //
  4. import com.ms.ui.*;
  5. import java.awt.Insets;
  6.  
  7. public class LCDataPnl extends UIPanel
  8. {
  9.     private UIColumnViewer cvloan;
  10.     private UIList list;
  11.  
  12.     public LCDataPnl(LCParams lp)
  13.     {
  14.         setLayout(new UIBorderLayout());
  15.  
  16.         UIText headings[] = { new UIText("Period #"), 
  17.                               new UIText("Interest Pd"),
  18.                               new UIText("Principal Pd"),
  19.                               new UIText("Loan Balance") };
  20.  
  21.         // Create payment schedule list
  22.         list = new UIList();
  23.         fillList(lp, true);
  24.  
  25.         // Create column viewer
  26.         cvloan = new UIColumnViewer(headings, list);
  27.         int widths[] = { 60, 96, 96, 100 };
  28.         cvloan.setWidths(widths);
  29.         add(cvloan, "center");
  30.     }
  31.  
  32.     // There is currently no way to just add rows to the UIList and have them
  33.     //  be laid out correctly, so after the first time fillList is called
  34.     //  the rows must be added directly to the UIColumnviewer ( although they need
  35.     //  not be contained in a UIRow component, they can just be added as an array of
  36.     //  IUIComponents).
  37.     public void fillList(LCParams lp, boolean firsttime)
  38.     {
  39.         UIText row[] = new UIText[4];
  40.  
  41.         // This will allow us to remove/add without the columnviewer repainting
  42.         //  before we are done.
  43.         list.setInvalidating(false);
  44.  
  45.         if ( !firsttime )
  46.             list.removeAll();
  47.  
  48.         int ipd, ppd;
  49.         long balance = lp.pv * 100;
  50.  
  51.         for ( int i = 1; i <= lp.n; i++ ) {
  52.             row[0] = new UIText("" + i);
  53.             ipd = (int)(balance * lp.ip);
  54.             row[1] = new UIText("" + new DNC(ipd));
  55.             ppd = lp.pmnt - ipd;
  56.             row[2] = new UIText("" + new DNC(ppd));
  57.             balance -= ppd;
  58.             row[3] = new UIText("" + new DNC(balance));
  59.             if ( firsttime )
  60.                 list.add(new UIRow(row));
  61.             else
  62.                 cvloan.add(row); // will pass on to list and layout correctly
  63.         }
  64.         list.setInvalidating(true);
  65.     }
  66.  
  67.     public Insets getInsets() { return new Insets(12, 0, 5, 5); }
  68. }
  69.