home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / oxygen.app / Contents / Resources / Java / jh.jar / javax / help / DefaultHelpBroker.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-06-24  |  11.5 KB  |  556 lines

  1. package javax.help;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Component;
  5. import java.awt.Dialog;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.IllegalComponentStateException;
  9. import java.awt.MenuItem;
  10. import java.awt.Point;
  11. import java.awt.Window;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.KeyEvent;
  15. import java.awt.event.KeyListener;
  16. import java.awt.event.WindowListener;
  17. import java.lang.reflect.Constructor;
  18. import java.lang.reflect.InvocationTargetException;
  19. import java.lang.reflect.Method;
  20. import java.net.URL;
  21. import java.util.Enumeration;
  22. import java.util.Locale;
  23. import javax.help.Map.ID;
  24. import javax.swing.AbstractButton;
  25. import javax.swing.JComponent;
  26. import javax.swing.JDialog;
  27. import javax.swing.JFrame;
  28. import javax.swing.KeyStroke;
  29.  
  30. public class DefaultHelpBroker implements HelpBroker, KeyListener {
  31.    protected HelpSet helpset = null;
  32.    protected JFrame frame = null;
  33.    protected JHelp jhelp = null;
  34.    protected Locale locale = null;
  35.    protected Font font = null;
  36.    protected JDialog dialog = null;
  37.    protected Window ownerWindow = null;
  38.    protected boolean modallyActivated = false;
  39.    static boolean on1dot1 = true;
  40.    private int HELP_WIDTH = 645;
  41.    private int HELP_HEIGHT = 495;
  42.    // $FF: renamed from: dl java.awt.event.WindowListener
  43.    WindowListener field_0;
  44.    boolean modalDeactivated = true;
  45.    protected ActionListener displayHelpFromFocus;
  46.    protected ActionListener displayHelpFromSource;
  47.    private static final boolean debug = false;
  48.    // $FF: synthetic field
  49.    static Class class$java$awt$Dialog;
  50.    // $FF: synthetic field
  51.    static Class class$javax$swing$JDialog;
  52.    // $FF: synthetic field
  53.    static Class class$java$awt$Frame;
  54.    // $FF: synthetic field
  55.    static Class class$java$awt$Window;
  56.  
  57.    public DefaultHelpBroker(HelpSet var1) {
  58.       this.setHelpSet(var1);
  59.    }
  60.  
  61.    public DefaultHelpBroker() {
  62.    }
  63.  
  64.    public HelpSet getHelpSet() {
  65.       return this.helpset;
  66.    }
  67.  
  68.    public void setHelpSet(HelpSet var1) {
  69.       if (var1 != null && this.helpset != var1) {
  70.          if (this.jhelp != null) {
  71.             DefaultHelpModel var2 = new DefaultHelpModel(var1);
  72.             this.jhelp.setModel(var2);
  73.          }
  74.  
  75.          this.helpset = var1;
  76.       }
  77.  
  78.    }
  79.  
  80.    public Locale getLocale() {
  81.       return this.locale == null ? Locale.getDefault() : this.locale;
  82.    }
  83.  
  84.    public void setLocale(Locale var1) {
  85.       this.locale = var1;
  86.       if (this.jhelp != null) {
  87.          this.jhelp.setLocale(this.locale);
  88.       }
  89.  
  90.    }
  91.  
  92.    public Font getFont() {
  93.       this.createHelpWindow();
  94.       return this.font == null ? this.jhelp.getFont() : this.font;
  95.    }
  96.  
  97.    public void setFont(Font var1) {
  98.       this.font = var1;
  99.       if (this.jhelp != null) {
  100.          this.jhelp.setFont(this.font);
  101.       }
  102.  
  103.    }
  104.  
  105.    public void setCurrentView(String var1) {
  106.       this.createHelpWindow();
  107.       JHelpNavigator var2 = null;
  108.  
  109.       for(Enumeration var3 = this.jhelp.getHelpNavigators(); var3.hasMoreElements(); var2 = null) {
  110.          var2 = (JHelpNavigator)var3.nextElement();
  111.          if (var2.getNavigatorName().equals(var1)) {
  112.             break;
  113.          }
  114.       }
  115.  
  116.       if (var2 == null) {
  117.          throw new IllegalArgumentException("Invalid view name");
  118.       } else {
  119.          this.jhelp.setCurrentNavigator(var2);
  120.       }
  121.    }
  122.  
  123.    public String getCurrentView() {
  124.       this.createHelpWindow();
  125.       return this.jhelp.getCurrentNavigator().getNavigatorName();
  126.    }
  127.  
  128.    public void initPresentation() {
  129.       this.createHelpWindow();
  130.    }
  131.  
  132.    public void setDisplayed(boolean var1) {
  133.       debug("setDisplayed");
  134.       this.createHelpWindow();
  135.       if (this.modallyActivated) {
  136.          if (var1) {
  137.             this.dialog.show();
  138.          } else {
  139.             this.dialog.hide();
  140.          }
  141.       } else {
  142.          this.frame.setVisible(var1);
  143.  
  144.          try {
  145.             Class[] var2 = new Class[]{Integer.TYPE};
  146.             Method var3 = (class$java$awt$Frame == null ? (class$java$awt$Frame = class$("java.awt.Frame")) : class$java$awt$Frame).getMethod("setState", var2);
  147.             if (var3 != null) {
  148.                Object[] var4 = new Object[]{new Integer(0)};
  149.                var3.invoke(this.frame, var4);
  150.             }
  151.          } catch (NoSuchMethodError var6) {
  152.          } catch (NoSuchMethodException var7) {
  153.          } catch (InvocationTargetException var8) {
  154.          } catch (IllegalAccessException var9) {
  155.          }
  156.       }
  157.  
  158.    }
  159.  
  160.    public boolean isDisplayed() {
  161.       if (this.modallyActivated) {
  162.          return this.dialog != null ? this.dialog.isShowing() : false;
  163.       } else if (this.frame != null) {
  164.          if (!this.frame.isVisible()) {
  165.             return false;
  166.          } else {
  167.             try {
  168.                Method var1 = (class$java$awt$Frame == null ? (class$java$awt$Frame = class$("java.awt.Frame")) : class$java$awt$Frame).getMethod("getState", (Class[])null);
  169.                if (var1 != null) {
  170.                   int var2 = (Integer)var1.invoke(this.frame, (Object[])null);
  171.                   if (var2 == 0) {
  172.                      return true;
  173.                   }
  174.  
  175.                   return false;
  176.                }
  177.             } catch (NoSuchMethodError var5) {
  178.             } catch (NoSuchMethodException var6) {
  179.             } catch (InvocationTargetException var7) {
  180.             } catch (IllegalAccessException var8) {
  181.             }
  182.  
  183.             return true;
  184.          }
  185.       } else {
  186.          return false;
  187.       }
  188.    }
  189.  
  190.    public void setLocation(Point var1) throws UnsupportedOperationException {
  191.       this.createHelpWindow();
  192.       if (this.modallyActivated) {
  193.          this.dialog.setLocation(var1);
  194.       } else {
  195.          this.frame.setLocation(var1);
  196.       }
  197.  
  198.    }
  199.  
  200.    public Point getLocation() throws UnsupportedOperationException {
  201.       if (this.jhelp == null) {
  202.          throw new IllegalComponentStateException("presentation not displayed");
  203.       } else {
  204.          if (this.modallyActivated) {
  205.             if (this.dialog != null) {
  206.                return this.dialog.getLocation();
  207.             }
  208.          } else if (this.frame != null) {
  209.             return this.frame.getLocation();
  210.          }
  211.  
  212.          return null;
  213.       }
  214.    }
  215.  
  216.    public void setSize(Dimension var1) throws UnsupportedOperationException {
  217.       this.HELP_WIDTH = var1.width;
  218.       this.HELP_HEIGHT = var1.height;
  219.       this.createHelpWindow();
  220.       if (this.modallyActivated) {
  221.          this.dialog.setSize(var1);
  222.          this.dialog.validate();
  223.       } else {
  224.          this.frame.setSize(var1);
  225.          this.frame.validate();
  226.       }
  227.  
  228.    }
  229.  
  230.    public Dimension getSize() throws UnsupportedOperationException {
  231.       if (this.jhelp == null) {
  232.          throw new IllegalComponentStateException("presentation not displayed");
  233.       } else {
  234.          if (this.modallyActivated) {
  235.             if (this.dialog != null) {
  236.                return this.dialog.getSize();
  237.             }
  238.          } else if (this.frame != null) {
  239.             return this.frame.getSize();
  240.          }
  241.  
  242.          return null;
  243.       }
  244.    }
  245.  
  246.    public void setViewDisplayed(boolean var1) {
  247.       this.createHelpWindow();
  248.       this.jhelp.setNavigatorDisplayed(var1);
  249.    }
  250.  
  251.    public boolean isViewDisplayed() {
  252.       this.createHelpWindow();
  253.       return this.jhelp.isNavigatorDisplayed();
  254.    }
  255.  
  256.    public void setCurrentID(String var1) throws BadIDException {
  257.       try {
  258.          this.setCurrentID(ID.create(var1, this.helpset));
  259.       } catch (InvalidHelpSetContextException var3) {
  260.          new Error("internal error?");
  261.       }
  262.  
  263.    }
  264.  
  265.    public void setCurrentID(Map.ID var1) throws InvalidHelpSetContextException {
  266.       debug("setCurrentID");
  267.       this.createJHelp();
  268.       this.jhelp.getModel().setCurrentID(var1);
  269.    }
  270.  
  271.    public Map.ID getCurrentID() {
  272.       return this.jhelp != null ? this.jhelp.getModel().getCurrentID() : null;
  273.    }
  274.  
  275.    public void setCurrentURL(URL var1) {
  276.       this.createHelpWindow();
  277.       this.jhelp.getModel().setCurrentURL(var1);
  278.       if (this.modallyActivated) {
  279.          this.dialog.setVisible(true);
  280.          this.dialog.show();
  281.       } else {
  282.          this.frame.setVisible(true);
  283.          this.frame.show();
  284.       }
  285.  
  286.    }
  287.  
  288.    public URL getCurrentURL() {
  289.       return this.jhelp.getModel().getCurrentURL();
  290.    }
  291.  
  292.    public void enableHelpKey(Component var1, String var2, HelpSet var3) {
  293.       if (var2 == null) {
  294.          throw new NullPointerException("id");
  295.       } else {
  296.          CSH.setHelpIDString(var1, var2);
  297.          if (var3 != null) {
  298.             CSH.setHelpSet(var1, var3);
  299.          }
  300.  
  301.          if (var1 instanceof JComponent) {
  302.             JComponent var4 = (JComponent)var1;
  303.             var4.registerKeyboardAction(this.getDisplayHelpFromFocus(), KeyStroke.getKeyStroke(156, 0), 1);
  304.             var4.registerKeyboardAction(this.getDisplayHelpFromFocus(), KeyStroke.getKeyStroke(112, 0), 1);
  305.          } else {
  306.             var1.addKeyListener(this);
  307.          }
  308.  
  309.       }
  310.    }
  311.  
  312.    public void keyTyped(KeyEvent var1) {
  313.    }
  314.  
  315.    public void keyPressed(KeyEvent var1) {
  316.    }
  317.  
  318.    public void keyReleased(KeyEvent var1) {
  319.       int var2 = var1.getKeyCode();
  320.       if (var2 == 112 || var2 == 156) {
  321.          ActionListener var3 = this.getDisplayHelpFromFocus();
  322.          var3.actionPerformed(new ActionEvent(var1.getComponent(), 1001, (String)null));
  323.       }
  324.  
  325.    }
  326.  
  327.    public void enableHelp(Component var1, String var2, HelpSet var3) {
  328.       if (var2 == null) {
  329.          throw new NullPointerException("id");
  330.       } else {
  331.          CSH.setHelpIDString(var1, var2);
  332.          if (var3 != null) {
  333.             CSH.setHelpSet(var1, var3);
  334.          }
  335.  
  336.       }
  337.    }
  338.  
  339.    public void enableHelp(MenuItem var1, String var2, HelpSet var3) {
  340.       if (var2 == null) {
  341.          throw new NullPointerException("id");
  342.       } else {
  343.          CSH.setHelpIDString(var1, var2);
  344.          if (var3 != null) {
  345.             CSH.setHelpSet(var1, var3);
  346.          }
  347.  
  348.       }
  349.    }
  350.  
  351.    public void enableHelpOnButton(Component var1, String var2, HelpSet var3) {
  352.       if (!(var1 instanceof AbstractButton) && !(var1 instanceof Button)) {
  353.          throw new IllegalArgumentException("Invalid Component");
  354.       } else if (var2 == null) {
  355.          throw new NullPointerException("id");
  356.       } else {
  357.          CSH.setHelpIDString(var1, var2);
  358.          if (var3 != null) {
  359.             CSH.setHelpSet(var1, var3);
  360.          }
  361.  
  362.          if (var1 instanceof AbstractButton) {
  363.             AbstractButton var4 = (AbstractButton)var1;
  364.             var4.addActionListener(this.getDisplayHelpFromSource());
  365.          } else if (var1 instanceof Button) {
  366.             Button var5 = (Button)var1;
  367.             var5.addActionListener(this.getDisplayHelpFromSource());
  368.          }
  369.  
  370.       }
  371.    }
  372.  
  373.    public void enableHelpOnButton(MenuItem var1, String var2, HelpSet var3) {
  374.       if (var1 == null) {
  375.          throw new IllegalArgumentException("Invalid Component");
  376.       } else if (var2 == null) {
  377.          throw new NullPointerException("id");
  378.       } else {
  379.          CSH.setHelpIDString(var1, var2);
  380.          if (var3 != null) {
  381.             CSH.setHelpSet(var1, var3);
  382.          }
  383.  
  384.          var1.addActionListener(this.getDisplayHelpFromSource());
  385.       }
  386.    }
  387.  
  388.    protected ActionListener getDisplayHelpFromFocus() {
  389.       if (this.displayHelpFromFocus == null) {
  390.          this.displayHelpFromFocus = new CSH.DisplayHelpFromFocus(this);
  391.       }
  392.  
  393.       return this.displayHelpFromFocus;
  394.    }
  395.  
  396.    protected ActionListener getDisplayHelpFromSource() {
  397.       if (this.displayHelpFromSource == null) {
  398.          this.displayHelpFromSource = new CSH.DisplayHelpFromSource(this);
  399.       }
  400.  
  401.       return this.displayHelpFromSource;
  402.    }
  403.  
  404.    public void setActivationWindow(Window var1) {
  405.       if (var1 != null && var1 instanceof Dialog) {
  406.          Dialog var2 = (Dialog)var1;
  407.          if (var2.isModal()) {
  408.             this.ownerWindow = var1;
  409.             this.modallyActivated = true;
  410.          } else {
  411.             this.ownerWindow = null;
  412.             this.modallyActivated = false;
  413.          }
  414.       } else {
  415.          this.ownerWindow = null;
  416.          this.modallyActivated = false;
  417.       }
  418.  
  419.    }
  420.  
  421.    private synchronized void createJHelp() {
  422.       debug("createJHelp");
  423.       if (this.jhelp == null) {
  424.          this.jhelp = new JHelp(this.helpset);
  425.          if (this.font != null) {
  426.             this.jhelp.setFont(this.font);
  427.          }
  428.  
  429.          if (this.locale != null) {
  430.             this.jhelp.setLocale(this.locale);
  431.          }
  432.       }
  433.  
  434.    }
  435.  
  436.    private synchronized void createHelpWindow() {
  437.       debug("createHelpWindow");
  438.       Point var1 = null;
  439.       Dimension var2 = null;
  440.       JDialog var3 = null;
  441.       this.createJHelp();
  442.       String var4 = this.helpset.getTitle();
  443.       if (this.modallyActivated) {
  444.          Window var5 = null;
  445.  
  446.          try {
  447.             Method var6 = (class$java$awt$Window == null ? (class$java$awt$Window = class$("java.awt.Window")) : class$java$awt$Window).getMethod("getOwner", (Class[])null);
  448.             if (var6 != null && this.dialog != null) {
  449.                var5 = (Window)var6.invoke(this.dialog, (Object[])null);
  450.             }
  451.          } catch (NoSuchMethodError var10) {
  452.          } catch (NoSuchMethodException var11) {
  453.          } catch (InvocationTargetException var12) {
  454.          } catch (IllegalAccessException var13) {
  455.          }
  456.  
  457.          if (this.dialog == null || var5 != this.ownerWindow || this.modalDeactivated) {
  458.             if (this.frame != null) {
  459.                var1 = this.frame.getLocation();
  460.                var2 = this.frame.getSize();
  461.                this.frame.dispose();
  462.             }
  463.  
  464.             if (this.dialog != null) {
  465.                var1 = this.dialog.getLocation();
  466.                var2 = this.dialog.getSize();
  467.                var3 = this.dialog;
  468.             }
  469.  
  470.             if (on1dot1) {
  471.                this.dialog = new JDialog();
  472.                this.dialog.setTitle(var4);
  473.             } else {
  474.                this.dialog = new JDialog((Dialog)this.ownerWindow, var4);
  475.                this.field_0 = new 1(this);
  476.                debug("adding windowlistener");
  477.                this.ownerWindow.addWindowListener(this.field_0);
  478.                this.modalDeactivated = false;
  479.             }
  480.  
  481.             if (var2 != null) {
  482.                this.dialog.setSize(var2);
  483.             } else {
  484.                this.dialog.setSize(this.HELP_WIDTH, this.HELP_HEIGHT);
  485.             }
  486.  
  487.             if (var1 != null) {
  488.                this.dialog.setLocation(var1);
  489.             }
  490.  
  491.             this.dialog.getContentPane().add(this.jhelp);
  492.             if (var3 != null) {
  493.                var3.dispose();
  494.             }
  495.          }
  496.       } else {
  497.          if (this.frame == null) {
  498.             this.frame = new JFrame(var4);
  499.             2 var14 = new 2(this);
  500.             this.frame.addWindowListener(var14);
  501.          }
  502.  
  503.          if (this.dialog != null) {
  504.             var1 = this.dialog.getLocation();
  505.             var2 = this.dialog.getSize();
  506.             this.dialog.dispose();
  507.             this.dialog = null;
  508.             this.ownerWindow = null;
  509.          }
  510.  
  511.          if (var2 != null) {
  512.             this.frame.setSize(var2);
  513.          } else {
  514.             this.frame.setSize(this.HELP_WIDTH, this.HELP_HEIGHT);
  515.          }
  516.  
  517.          if (var1 != null) {
  518.             this.frame.setLocation(var1);
  519.          }
  520.  
  521.          this.frame.getContentPane().add(this.jhelp);
  522.          this.frame.setTitle(this.helpset.getTitle());
  523.       }
  524.  
  525.    }
  526.  
  527.    private static void debug(Object var0) {
  528.    }
  529.  
  530.    // $FF: synthetic method
  531.    static Class class$(String var0) {
  532.       try {
  533.          return Class.forName(var0);
  534.       } catch (ClassNotFoundException var2) {
  535.          throw new NoClassDefFoundError(var2.getMessage());
  536.       }
  537.    }
  538.  
  539.    // $FF: synthetic method
  540.    static void access$000(Object var0) {
  541.       debug(var0);
  542.    }
  543.  
  544.    static {
  545.       try {
  546.          Class[] var0 = new Class[]{class$java$awt$Dialog == null ? (class$java$awt$Dialog = class$("java.awt.Dialog")) : class$java$awt$Dialog, Boolean.TYPE};
  547.          Constructor var1 = (class$javax$swing$JDialog == null ? (class$javax$swing$JDialog = class$("javax.swing.JDialog")) : class$javax$swing$JDialog).getConstructor(var0);
  548.          on1dot1 = var1 == null;
  549.       } catch (NoSuchMethodException var2) {
  550.          on1dot1 = true;
  551.       }
  552.  
  553.       SwingHelpUtilities.installLookAndFeelDefaults();
  554.    }
  555. }
  556.