home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / WizardSummaryPanel.java < prev    next >
Text File  |  1998-11-24  |  5KB  |  146 lines

  1. package com.symantec.itools.frameworks.wizard;
  2.  
  3. import java.awt.*;
  4. import java.util.Enumeration;
  5. import java.util.Vector;
  6. import com.sun.java.swing.JScrollPane;
  7. import com.symantec.itools.swing.JWrappingLabel;
  8. import com.sun.java.swing.JTable;
  9. import com.sun.java.swing.table.*;
  10. import com.symantec.itools.swing.models.StringTableModel;
  11. import com.symantec.itools.util.ResourceBundleAdapter;
  12. import java.util.ResourceBundle;
  13.  
  14. /**
  15.  * @author Symantec Internet Tools Division
  16.  * @version 2.0
  17.  * @since VCafe 3.0
  18.  */
  19.  
  20. public class WizardSummaryPanel
  21.     extends WizardPanel
  22. {
  23.     protected ResourceBundleAdapter resourceBundle;
  24.     protected com.sun.java.swing.JScrollPane scrollPane = new com.sun.java.swing.JScrollPane();
  25.     protected com.sun.java.swing.JTable summaryTbl = new com.sun.java.swing.JTable();
  26.     protected com.symantec.itools.swing.models.StringTableModel summaryTblModel = new com.symantec.itools.swing.models.StringTableModel();
  27.     protected com.symantec.itools.swing.JWrappingLabel label;
  28.  
  29.     protected static ResourceBundle defaultResourceBundle;
  30.     static
  31.     {
  32.         try
  33.         {
  34.             defaultResourceBundle = ResourceBundle.getBundle("com.symantec.itools.frameworks.wizard.WizardResource");
  35.         }
  36.         catch(Throwable ex)
  37.         {
  38.             ex.printStackTrace();
  39.         }
  40.     }
  41.     protected final static int MIN_ROWS = 14;
  42.     
  43.     public WizardSummaryPanel()
  44.     { 
  45.         this(defaultResourceBundle);
  46.     }
  47.     
  48.     public WizardSummaryPanel(ResourceBundle bundle)
  49.     {
  50.         resourceBundle = new ResourceBundleAdapter(bundle);
  51.         label = new com.symantec.itools.swing.JWrappingLabel(resourceBundle.getString("SP_Description"));
  52.         setLayout(null);
  53.         setSize(444,349);
  54.         label.setBounds(20,15,250,22);
  55.         add(label);
  56.         add(scrollPane, "South");
  57.         scrollPane.setBounds(20,40,430,260);
  58.         summaryTbl.setModel(summaryTblModel);
  59.         summaryTblModel.setEditable(false);
  60.         summaryTblModel.setColumnHeaders(resourceBundle.getString("SP_Option") + "," + resourceBundle.getString("SP_Choice"));
  61.         scrollPane.getViewport().add(summaryTbl);
  62.         summaryTbl.setBounds(20,40,430,260);
  63.         summaryTbl.setColumnSelectionAllowed(false);
  64.         summaryTbl.setRowSelectionAllowed(false);
  65.         summaryTbl.setCellSelectionEnabled(false);
  66.         summaryTbl.setEnabled(false);
  67.       summaryTbl.getTableHeader().setReorderingAllowed(false);
  68.     }
  69.     
  70.     public String getPanelTitle()
  71.     {
  72.         return resourceBundle.getString("SP_Title");
  73.     }
  74.  
  75.  
  76.     /**
  77.      * Called by controller before the panel is displayed.
  78.      * Only current panel is called.
  79.      * @since VCafe 3.0
  80.      */
  81.     public void entering()
  82.     {
  83.         Vector   summaries;
  84.         Vector   summariesData;
  85.         String[] data;
  86.         
  87.         summaries     = controller.getWizardSummary();
  88.         summariesData = new Vector();
  89.  
  90.         // Put summaries into summaryContainerPanel
  91.         int max = summaries.size();
  92.         for(int i = 0; i < max; i++)
  93.         {
  94.             WizardSummary summary = (WizardSummary)summaries.elementAt(i);
  95.             addWizardSummary(summary, summariesData);
  96.         }
  97.         addPadRows(summariesData);
  98.         
  99.         controller.getWizard().setNextEnabled(false);
  100.         data = new String[summariesData.size()];
  101.         summariesData.copyInto(data);
  102.         summaryTblModel.setItems(data);
  103.         
  104.         //summaryTbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  105.         
  106.         TableColumn keyColumn, valueColumn;
  107.         TableColumnModel columnModel = summaryTbl.getColumnModel();
  108.         keyColumn = columnModel.getColumn(0);
  109.         valueColumn = columnModel.getColumn(1);
  110.         valueColumn.setWidth(400);
  111.         keyColumn.setWidth(200);
  112.     }
  113.     
  114.     protected void addWizardSummary(WizardSummary summary, Vector data)
  115.     {
  116.         boolean hasSummaries = false;
  117.         for(Enumeration e = summary.getSummaryItems(); e.hasMoreElements();)
  118.         {
  119.             addWizardSummaryItem((WizardSummary.Item)e.nextElement(), data);
  120.             hasSummaries = true;
  121.         }
  122.         if (hasSummaries) {
  123.             data.addElement(",");
  124.         }
  125.     }
  126.     
  127.     protected void addWizardSummaryItem(WizardSummary.Item item, Vector data)
  128.     {
  129.         String key = item.getKey().replace(',', ' ');      // note: commas not allowed currently
  130.         if (key == null)
  131.              key = "";
  132.         String val = item.getValue().replace(',', ' ');
  133.         if (val == null)
  134.              val = "";
  135.         data.addElement(key + ',' + val);
  136.     }
  137.     
  138.     protected void addPadRows(Vector data)
  139.     {
  140.         int rowCount = data.size();
  141.         while (rowCount < MIN_ROWS) {
  142.             data.addElement(",");
  143.             rowCount++;
  144.         }
  145.     }
  146. }