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

  1. package asp.wizard;
  2.  
  3. import asp.netobjects.nfx.util.ExceptionHandler;
  4. import asp.netobjects.nfx.util.ExternalError;
  5. import asp.netobjects.nfx.util.InternalError;
  6. import asp.util.ResourceUtil;
  7. import asp.wizard.util.UiUtil;
  8. import com.sun.java.swing.JDialog;
  9. import com.sun.java.swing.JFrame;
  10. import com.sun.java.swing.JOptionPane;
  11. import java.awt.Component;
  12. import java.awt.Container;
  13. import java.awt.Dialog;
  14. import java.awt.Dimension;
  15. import java.util.Hashtable;
  16.  
  17. public class AspWizardExceptionHandler implements ExceptionHandler {
  18.    public static final int INTERNAL_ERROR_MESSAGE = -2;
  19.    private static Hashtable _msgTypeToTitle;
  20.    private Container _parent;
  21.    // $FF: synthetic field
  22.    static Class class$asp$wizard$AspWizard;
  23.  
  24.    public AspWizardExceptionHandler(Container parent) {
  25.       this._parent = parent;
  26.    }
  27.  
  28.    public void handleException(Throwable t) {
  29.       String title = "";
  30.       String formatted = UiUtil.formatDialogText(t.getMessage());
  31.       if (t instanceof ExternalError) {
  32.          title = getTitle(0);
  33.       }
  34.  
  35.       if (t instanceof InternalError) {
  36.          title = getTitle(-2);
  37.       }
  38.  
  39.       showMessageDialog(this._parent, formatted, title, 0);
  40.    }
  41.  
  42.    private static String getTitle(int msgType) {
  43.       Integer msgTypeInt = new Integer(msgType);
  44.       String result = (String)_msgTypeToTitle.get(msgTypeInt);
  45.       if (result == null) {
  46.          result = "";
  47.       }
  48.  
  49.       return result;
  50.    }
  51.  
  52.    public static void showMessage(int msgType, String msg) {
  53.       String formatted = UiUtil.formatDialogText(msg);
  54.       showMessageDialog((Component)null, formatted, getTitle(msgType), msgType);
  55.    }
  56.  
  57.    public static void showMessage(int msgType, String msg, Component parent) {
  58.       String formatted = UiUtil.formatDialogText(msg);
  59.       showMessageDialog(parent, formatted, getTitle(msgType), msgType);
  60.    }
  61.  
  62.    private static void showMessageDialog(Component parent, String message, String title, int messageType) {
  63.       JOptionPane pane = new JOptionPane(message, messageType, -1);
  64.       JDialog dlg = pane.createDialog((Component)(parent == null ? new JFrame() : parent), title);
  65.       Dimension size = ((Component)dlg).getSize();
  66.       size.width += 5;
  67.       ((Component)dlg).setSize(size);
  68.       ((Dialog)dlg).show();
  69.    }
  70.  
  71.    // $FF: synthetic method
  72.    static Class class$(String class$) {
  73.       try {
  74.          return Class.forName(class$);
  75.       } catch (ClassNotFoundException forName) {
  76.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  77.       }
  78.    }
  79.  
  80.    static {
  81.       String resBase = "asp.wizard.res";
  82.       Class ownerClass = class$asp$wizard$AspWizard != null ? class$asp$wizard$AspWizard : (class$asp$wizard$AspWizard = class$("asp.wizard.AspWizard"));
  83.       _msgTypeToTitle = new Hashtable();
  84.       _msgTypeToTitle.put(new Integer(-2), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.internalerror"));
  85.       _msgTypeToTitle.put(new Integer(0), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.error"));
  86.       _msgTypeToTitle.put(new Integer(1), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.information"));
  87.       _msgTypeToTitle.put(new Integer(2), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.warning"));
  88.       _msgTypeToTitle.put(new Integer(3), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.question"));
  89.       _msgTypeToTitle.put(new Integer(-1), ResourceUtil.getResourceString(resBase, ownerClass, "exceptionhandler.title.plainmessage"));
  90.    }
  91. }
  92.