home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / netobjects / nfx / wizard / WizardView.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  7.5 KB  |  206 lines

  1. package asp.netobjects.nfx.wizard;
  2.  
  3. import asp.netobjects.nfx.ui.EtchedTopBorder;
  4. import asp.netobjects.nfx.util.ExceptionHandler;
  5. import asp.netobjects.nfx.util.ExternalError;
  6. import asp.netobjects.nfx.util.InternalError;
  7. import com.netobjects.nfc.api.NFXJDialog;
  8. import com.sun.java.swing.BorderFactory;
  9. import com.sun.java.swing.Box;
  10. import com.sun.java.swing.BoxLayout;
  11. import com.sun.java.swing.JButton;
  12. import com.sun.java.swing.JDialog;
  13. import com.sun.java.swing.JPanel;
  14. import java.awt.BorderLayout;
  15. import java.awt.CardLayout;
  16. import java.awt.Component;
  17. import java.awt.Container;
  18. import java.awt.Dialog;
  19. import java.awt.Dimension;
  20. import java.awt.Font;
  21. import java.awt.Frame;
  22. import java.awt.Insets;
  23. import java.awt.Toolkit;
  24. import java.awt.Window;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27. import java.awt.event.WindowEvent;
  28. import java.util.EventObject;
  29.  
  30. public class WizardView extends JDialog implements ActionListener {
  31.    private Wizard dmWizard;
  32.    private int dmWidth = 470;
  33.    private int dmHeight = 318;
  34.    private WizardButton dmBtnBack;
  35.    private WizardButton dmBtnNext;
  36.    private WizardButton dmBtnFinish;
  37.    private WizardButton dmBtnCancel;
  38.    private JPanel dmMainPanel;
  39.    private JPanel dmButtonPanel;
  40.    private JPanel dmPagePanel;
  41.    private CardLayout dmPagePanelCardLayout;
  42.  
  43.    public WizardView(Wizard wizard, Frame parent, String title) {
  44.       super(parent, title);
  45.       this.dmWizard = wizard;
  46.       this.dmWidth = 470;
  47.       this.dmHeight = 318;
  48.       this.createControls();
  49.    }
  50.  
  51.    public WizardView(Wizard wizard, Frame parent, String title, int width, int height) {
  52.       super(parent, title);
  53.       this.dmWizard = wizard;
  54.       this.dmWidth = width;
  55.       this.dmHeight = height;
  56.       this.createControls();
  57.    }
  58.  
  59.    private void createControls() {
  60.       ((Dialog)this).setResizable(true);
  61.       if (this instanceof NFXJDialog) {
  62.          ((Dialog)this).setModal(false);
  63.       } else if (this instanceof JDialog) {
  64.          ((Dialog)this).setModal(true);
  65.       }
  66.  
  67.       ((Component)this).setSize(this.dmWidth, this.dmHeight);
  68.       ((Component)this).setFont(new Font("Helvetica", 0, 12));
  69.       this.dmMainPanel = new JPanel();
  70.       this.dmMainPanel.setLayout(new BorderLayout());
  71.       this.dmMainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  72.       ((JDialog)this).getContentPane().add(this.dmMainPanel);
  73.       WindowListener windowListener = new WindowListener(this);
  74.       ((Window)this).addWindowListener(windowListener);
  75.       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  76.       ((Component)this).setLocation(screenSize.width / 2 - 235, screenSize.height / 2 - 159);
  77.       this.dmPagePanel = new JPanel();
  78.       this.dmPagePanelCardLayout = new CardLayout();
  79.       this.dmPagePanel.setLayout(this.dmPagePanelCardLayout);
  80.       this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
  81.       this.dmMainPanel.add(this.dmPagePanel, "Center");
  82.       this.dmButtonPanel = new JPanel();
  83.       this.dmButtonPanel.setLayout(new BoxLayout(this.dmButtonPanel, 0));
  84.       this.dmButtonPanel.setBorder(new EtchedTopBorder(1));
  85.       Insets insets = ((Container)this).getInsets();
  86.       int w = this.dmWidth - (insets.left + insets.right) - 30 - 16 - 320;
  87.       this.dmButtonPanel.add(Box.createRigidArea(new Dimension(w, 23)));
  88.       this.dmBtnCancel = new WizardButton(this, "Cancel");
  89.       this.dmBtnCancel.setMnemonic(this.dmBtnCancel.getText().charAt(0));
  90.       this.dmBtnCancel.setEnabled(true);
  91.       this.dmBtnCancel.addActionListener(this);
  92.       this.dmButtonPanel.add(this.dmBtnCancel);
  93.       this.dmButtonPanel.add(Box.createRigidArea(new Dimension(8, 23)));
  94.       this.dmBtnBack = new WizardButton(this, "< Back");
  95.       this.dmBtnBack.setMnemonic('B');
  96.       this.dmBtnBack.setEnabled(false);
  97.       this.dmBtnBack.addActionListener(this);
  98.       this.dmButtonPanel.add(this.dmBtnBack);
  99.       this.dmBtnNext = new WizardButton(this, "Next >");
  100.       this.dmBtnNext.setMnemonic(this.dmBtnNext.getText().charAt(0));
  101.       this.dmBtnNext.setEnabled(false);
  102.       this.dmBtnNext.addActionListener(this);
  103.       this.dmButtonPanel.add(this.dmBtnNext);
  104.       this.dmButtonPanel.add(Box.createRigidArea(new Dimension(8, 23)));
  105.       this.dmBtnFinish = new WizardButton(this, "Finish");
  106.       this.dmBtnFinish.setMnemonic(this.dmBtnFinish.getText().charAt(0));
  107.       this.dmBtnFinish.setEnabled(false);
  108.       this.dmBtnFinish.addActionListener(this);
  109.       this.dmButtonPanel.add(this.dmBtnFinish);
  110.       this.dmMainPanel.add("South", this.dmButtonPanel);
  111.    }
  112.  
  113.    public ExceptionHandler getExceptionHandler() {
  114.       return this.dmWizard.getExceptionHandler();
  115.    }
  116.  
  117.    public CardLayout getCardLayout() {
  118.       return this.dmPagePanelCardLayout;
  119.    }
  120.  
  121.    public JButton getBackButton() {
  122.       return this.dmBtnBack;
  123.    }
  124.  
  125.    public JButton getNextButton() {
  126.       return this.dmBtnNext;
  127.    }
  128.  
  129.    public JButton getFinishButton() {
  130.       return this.dmBtnFinish;
  131.    }
  132.  
  133.    public JButton getCancelButton() {
  134.       return this.dmBtnCancel;
  135.    }
  136.  
  137.    public void initialize() throws InternalError, ExternalError {
  138.       this.dmPagePanelCardLayout.first(this.dmPagePanel);
  139.    }
  140.  
  141.    public void addPageView(String id, WizardPageView view) {
  142.       this.dmPagePanel.add(id, view);
  143.    }
  144.  
  145.    public void removePageView(WizardPageView view) {
  146.       this.dmPagePanelCardLayout.removeLayoutComponent(view);
  147.    }
  148.  
  149.    public void showPageView(String id) {
  150.       this.dmPagePanelCardLayout.show(this.dmPagePanel, id);
  151.    }
  152.  
  153.    public void enableNext(boolean enable) {
  154.       this.dmBtnNext.setEnabled(enable);
  155.    }
  156.  
  157.    public void enablePrevious(boolean enable) {
  158.       this.dmBtnBack.setEnabled(enable);
  159.    }
  160.  
  161.    public void enableFinish(boolean enable) {
  162.       this.dmBtnFinish.setEnabled(enable);
  163.    }
  164.  
  165.    public void windowClosing(WindowEvent event) {
  166.       this.dmWizard.setOk(false);
  167.       this.dmWizard.destroy();
  168.       ((Window)this).dispose();
  169.    }
  170.  
  171.    public void actionPerformed(ActionEvent event) {
  172.       try {
  173.          Object object = ((EventObject)event).getSource();
  174.          String file = null;
  175.          if (object == this.dmBtnBack) {
  176.             this.dmWizard.previousPage();
  177.          } else if (object == this.dmBtnNext) {
  178.             this.dmWizard.nextPage();
  179.          } else {
  180.             if (object == this.dmBtnFinish) {
  181.                this.dmWizard.finish();
  182.                this.dmWizard.setOk(true);
  183.                this.dmWizard.destroy();
  184.                ((Window)this).dispose();
  185.                return;
  186.             }
  187.  
  188.             if (object == this.dmBtnCancel) {
  189.                this.dmWizard.setOk(false);
  190.                this.dmWizard.destroy();
  191.                ((Window)this).dispose();
  192.                return;
  193.             }
  194.          }
  195.       } catch (Throwable t) {
  196.          if (this.dmWizard.getExceptionHandler() != null) {
  197.             this.dmWizard.getExceptionHandler().handleException(t);
  198.             return;
  199.          }
  200.  
  201.          t.printStackTrace();
  202.       }
  203.  
  204.    }
  205. }
  206.